/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2016 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
- * Hochschule fuer Technik Rapperswil
+ * HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
package org.strongswan.android.ui;
-import android.app.ProgressDialog;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.ProgressBar;
import android.widget.TextView;
import org.strongswan.android.R;
private int mColorStateError;
private int mColorStateSuccess;
private Button mActionButton;
- private ProgressDialog mConnectDialog;
- private ProgressDialog mDisconnectDialog;
- private ProgressDialog mProgressDialog;
+ private ProgressBar mProgress;
private AlertDialog mErrorDialog;
private long mErrorConnectionID;
private long mDismissedConnectionID;
}
}
});
- enableActionButton(false);
+ enableActionButton(null);
+ mProgress = (ProgressBar)view.findViewById(R.id.progress);
mStateView = (TextView)view.findViewById(R.id.vpn_state);
mColorStateBase = mStateView.getCurrentTextColor();
mProfileView = (TextView)view.findViewById(R.id.vpn_profile_label);
mService.unregisterListener(this);
}
hideErrorDialog();
- hideProgressDialog();
}
@Override
return;
}
- enableActionButton(false);
mProfileNameView.setText(name);
switch (state)
{
case DISABLED:
showProfile(false);
- hideProgressDialog();
+ mProgress.setVisibility(View.GONE);
+ enableActionButton(null);
mStateView.setText(R.string.state_disabled);
mStateView.setTextColor(mColorStateBase);
break;
case CONNECTING:
showProfile(true);
- showConnectDialog(name, gateway);
+ mProgress.setVisibility(View.VISIBLE);
+ enableActionButton(getString(android.R.string.cancel));
mStateView.setText(R.string.state_connecting);
mStateView.setTextColor(mColorStateBase);
break;
case CONNECTED:
showProfile(true);
- hideProgressDialog();
- enableActionButton(true);
+ mProgress.setVisibility(View.GONE);
+ enableActionButton(getString(R.string.disconnect));
mStateView.setText(R.string.state_connected);
mStateView.setTextColor(mColorStateSuccess);
break;
case DISCONNECTING:
showProfile(true);
- showDisconnectDialog(name);
+ mProgress.setVisibility(View.VISIBLE);
+ enableActionButton(null);
mStateView.setText(R.string.state_disconnecting);
mStateView.setTextColor(mColorStateBase);
break;
{ /* we already show the dialog */
return true;
}
- hideProgressDialog();
mProfileNameView.setText(name);
showProfile(true);
- enableActionButton(false);
+ mProgress.setVisibility(View.GONE);
+ enableActionButton(null);
mStateView.setText(R.string.state_error);
mStateView.setTextColor(mColorStateError);
switch (error)
mProfileNameView.setVisibility(show ? View.VISIBLE : View.GONE);
}
- private void enableActionButton(boolean enable)
+ private void enableActionButton(String text)
{
- mActionButton.setEnabled(enable);
- mActionButton.setVisibility(enable ? View.VISIBLE : View.GONE);
- }
-
- private void hideProgressDialog()
- {
- if (mProgressDialog != null)
- {
- mProgressDialog.dismiss();
- mProgressDialog = null;
- mDisconnectDialog = mConnectDialog = null;
- }
+ mActionButton.setText(text);
+ mActionButton.setEnabled(text != null);
+ mActionButton.setVisibility(text != null ? View.VISIBLE : View.GONE);
}
private void hideErrorDialog()
updateView();
}
- private void showConnectDialog(String profile, String gateway)
- {
- if (mConnectDialog != null)
- { /* already showing the dialog */
- return;
- }
- hideProgressDialog();
- mConnectDialog = new ProgressDialog(getActivity());
- mConnectDialog.setTitle(String.format(getString(R.string.connecting_title), profile));
- mConnectDialog.setMessage(String.format(getString(R.string.connecting_message), gateway));
- mConnectDialog.setIndeterminate(true);
- mConnectDialog.setCancelable(false);
- mConnectDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
- getString(android.R.string.cancel),
- new DialogInterface.OnClickListener()
- {
- @Override
- public void onClick(DialogInterface dialog, int which)
- {
- if (mService != null)
- {
- mService.disconnect();
- }
- }
- });
- mConnectDialog.show();
- mProgressDialog = mConnectDialog;
- }
-
- private void showDisconnectDialog(String profile)
- {
- if (mDisconnectDialog != null)
- { /* already showing the dialog */
- return;
- }
- hideProgressDialog();
- mDisconnectDialog = new ProgressDialog(getActivity());
- mDisconnectDialog.setMessage(getString(R.string.state_disconnecting));
- mDisconnectDialog.setIndeterminate(true);
- mDisconnectDialog.setCancelable(false);
- mDisconnectDialog.show();
- mProgressDialog = mDisconnectDialog;
- }
-
private void showErrorDialog(int textid)
{
final List<RemediationInstruction> instructions = mService.getRemediationInstructions();