import android.app.DialogFragment;
import android.app.Fragment;
import android.content.ContentResolver;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
mDialogFragment = null;
}
+ /**
+ * Sets the OnCancelListener of the dialog shown. This method can only be
+ * called after showDialog(int) and before removeDialog(int). The method
+ * does nothing otherwise.
+ */
+ protected void setOnCancelListener(DialogInterface.OnCancelListener listener) {
+ if (mDialogFragment != null) {
+ mDialogFragment.mOnCancelListener = listener;
+ }
+ }
+
+ /**
+ * Sets the OnDismissListener of the dialog shown. This method can only be
+ * called after showDialog(int) and before removeDialog(int). The method
+ * does nothing otherwise.
+ */
+ protected void setOnDismissListener(DialogInterface.OnDismissListener listener) {
+ if (mDialogFragment != null) {
+ mDialogFragment.mOnDismissListener = listener;
+ }
+ }
+
public static class SettingsDialogFragment extends DialogFragment {
private static final String KEY_DIALOG_ID = "key_dialog_id";
private static final String KEY_PARENT_FRAGMENT_ID = "key_parent_fragment_id";
private Fragment mParentFragment;
+ private DialogInterface.OnCancelListener mOnCancelListener;
+ private DialogInterface.OnDismissListener mOnDismissListener;
+
public SettingsDialogFragment() {
/* do nothing */
}
return ((DialogCreatable) mParentFragment).onCreateDialog(mDialogId);
}
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ super.onCancel(dialog);
+ if (mOnCancelListener != null) {
+ mOnCancelListener.onCancel(dialog);
+ }
+ }
+
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ super.onDismiss(dialog);
+ if (mOnDismissListener != null) {
+ mOnDismissListener.onDismiss(dialog);
+ }
+ }
public int getDialogId() {
return mDialogId;
}
}})
.setNegativeButton(R.string.cancel, null)
.setMessage(R.string.dlg_confirm_unmount_text)
- .setOnCancelListener(this)
.create();
case DLG_ERROR_UNMOUNT:
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.dlg_error_unmount_title)
.setNeutralButton(R.string.dlg_ok, null)
.setMessage(R.string.dlg_error_unmount_text)
- .setOnCancelListener(this)
.create();
}
return null;
}
+ @Override
+ protected void showDialog(int id) {
+ super.showDialog(id);
+
+ switch (id) {
+ case DLG_CONFIRM_UNMOUNT:
+ case DLG_ERROR_UNMOUNT:
+ setOnCancelListener(this);
+ break;
+ }
+ }
+
private void doUnmount(boolean force) {
// Present a toast here
Toast.makeText(getActivity(), R.string.unmount_inform_text, Toast.LENGTH_SHORT).show();
}
@Override
+ protected void showDialog(int dialogId) {
+ super.showDialog(dialogId);
+
+ setOnCancelListener(new DialogInterface.OnCancelListener() {
+ public void onCancel(DialogInterface dialog) {
+ onIdle();
+ }
+ });
+ }
+
+ @Override
public Dialog onCreateDialog (int id) {
switch (id) {
case DIALOG_CONNECT:
}
}
- private class ConnectDialog extends AlertDialog {
- public ConnectDialog(Context context) {
- super(context);
- setTitle(String.format(getString(R.string.vpn_connect_to),
- mConnectingActor.getProfile().getName()));
- setButton(DialogInterface.BUTTON_POSITIVE,
- getString(R.string.vpn_connect_button),
- VpnSettings.this);
- setButton(DialogInterface.BUTTON_NEGATIVE,
- getString(android.R.string.cancel),
- VpnSettings.this);
- setView(mConnectingActor.createConnectView());
- }
- public void onBackPressed() {
- changeState(mActiveProfile, VpnState.IDLE);
- super.onBackPressed();
- }
- }
-
private Dialog createConnectDialog() {
- return new ConnectDialog(getActivity());
+ final Activity activity = getActivity();
+ return new AlertDialog.Builder(activity)
+ .setView(mConnectingActor.createConnectView())
+ .setTitle(String.format(activity.getString(R.string.vpn_connect_to),
+ mConnectingActor.getProfile().getName()))
+ .setPositiveButton(activity.getString(R.string.vpn_connect_button),
+ this)
+ .setNegativeButton(activity.getString(android.R.string.cancel),
+ this)
+ .create();
}
private Dialog createReconnectDialog(int id) {
public void onClick(DialogInterface dialog, int w) {
onIdle();
}
- })
- .setOnCancelListener(new DialogInterface.OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- onIdle();
- }
});
}