fixed OrbotRequiredDialogActivity not finishing, orbot install dialog style

This commit is contained in:
Adithya Abraham Philip
2015-07-03 09:27:46 +05:30
parent 89f017aa9c
commit aca106e808
8 changed files with 112 additions and 44 deletions

View File

@@ -122,19 +122,7 @@ public class CreateYubiKeyImportFragment
mNextButton.setOnClickListener(new View.OnClickListener() { mNextButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
importKey();
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs();
Runnable ignoreTor = new Runnable() {
@Override
public void run() {
importKey(new ParcelableProxy(null, -1, null));
}
};
if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs,
getActivity())) {
importKey(proxyPrefs.parcelableProxy);
}
} }
}); });
} }
@@ -201,7 +189,7 @@ public class CreateYubiKeyImportFragment
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), parcelableProxy); Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), parcelableProxy);
} }
public void importKey(ParcelableProxy parcelableProxy) { public void importKey() {
ArrayList<ParcelableKeyRing> keyList = new ArrayList<>(); ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null)); keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null));

View File

@@ -133,7 +133,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
} }
} }
private void lookupUnknownKey(long unknownKeyId, ParcelableProxy parcelableProxy) { private void lookupUnknownKey(long unknownKeyId) {
final ArrayList<ParcelableKeyRing> keyList; final ArrayList<ParcelableKeyRing> keyList;
final String keyserver; final String keyserver;
@@ -424,19 +424,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
mSignatureLayout.setOnClickListener(new View.OnClickListener() { mSignatureLayout.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) lookupUnknownKey(signatureKeyId);
.getProxyPrefs();
Runnable ignoreTor = new Runnable() {
@Override
public void run() {
lookupUnknownKey(signatureKeyId, new ParcelableProxy(null, -1, null));
}
};
if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs,
getActivity())) {
lookupUnknownKey(signatureKeyId, proxyPrefs.parcelableProxy);
}
} }
}); });

View File

@@ -68,7 +68,15 @@ public class OrbotRequiredDialogActivity extends FragmentActivity {
finish(); finish();
} }
}; };
if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor,
Runnable dialogDismissed = new Runnable() {
@Override
public void run() {
finish();
}
};
if (OrbotHelper.putOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, dialogDismissed,
Preferences.getPreferences(OrbotRequiredDialogActivity.this) Preferences.getPreferences(OrbotRequiredDialogActivity.this)
.getProxyPrefs(), .getProxyPrefs(),
OrbotRequiredDialogActivity.this)) { OrbotRequiredDialogActivity.this)) {
@@ -76,7 +84,6 @@ public class OrbotRequiredDialogActivity extends FragmentActivity {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel); intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish();
} }
} }
}); });

View File

@@ -18,6 +18,7 @@
package org.sufficientlysecure.keychain.ui.dialog; package org.sufficientlysecure.keychain.ui.dialog;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
@@ -42,6 +43,7 @@ public class OrbotStartDialogFragment extends DialogFragment {
private static final String ARG_MIDDLE_BUTTON = "middleButton"; private static final String ARG_MIDDLE_BUTTON = "middleButton";
public static final int MESSAGE_MIDDLE_BUTTON = 1; public static final int MESSAGE_MIDDLE_BUTTON = 1;
public static final int MESSAGE_DIALOG_DISMISSED = 2; // for either cancel or enable pressed
public static OrbotStartDialogFragment newInstance(Messenger messenger, int title, int message, int middleButton) { public static OrbotStartDialogFragment newInstance(Messenger messenger, int title, int message, int middleButton) {
Bundle args = new Bundle(); Bundle args = new Bundle();
@@ -77,6 +79,15 @@ public class OrbotStartDialogFragment extends DialogFragment {
builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() { builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Message msg = Message.obtain();
msg.what = MESSAGE_DIALOG_DISMISSED;
try {
messenger.send(msg);
} catch (RemoteException e) {
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
} catch (NullPointerException e) {
Log.w(Constants.TAG, "Messenger is null!", e);
}
} }
}); });
@@ -85,6 +96,16 @@ public class OrbotStartDialogFragment extends DialogFragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
getActivity().startActivityForResult(OrbotHelper.getOrbotStartIntent(), 1); getActivity().startActivityForResult(OrbotHelper.getOrbotStartIntent(), 1);
Message msg = Message.obtain();
msg.what = MESSAGE_DIALOG_DISMISSED;
try {
messenger.send(msg);
} catch (RemoteException e) {
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
} catch (NullPointerException e) {
Log.w(Constants.TAG, "Messenger is null!", e);
}
} }
}); });

View File

@@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper;
public class PreferenceInstallDialogFragment extends DialogFragment { public class PreferenceInstallDialogFragment extends DialogFragment {
public static final int MESSAGE_MIDDLE_CLICKED = 1; public static final int MESSAGE_MIDDLE_CLICKED = 1;
public static final int MESSAGE_DIALOG_DISMISSED = 2;
/** /**
* Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install"
@@ -69,6 +70,6 @@ public class PreferenceInstallDialogFragment extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(),
MESSAGE_MIDDLE_CLICKED); MESSAGE_MIDDLE_CLICKED, MESSAGE_DIALOG_DISMISSED);
} }
} }

View File

@@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper;
public class SupportInstallDialogFragment extends DialogFragment { public class SupportInstallDialogFragment extends DialogFragment {
public static final int MESSAGE_MIDDLE_CLICKED = 1; public static final int MESSAGE_MIDDLE_CLICKED = 1;
public static final int MESSAGE_DIALOG_DISMISSED = 2;
/** /**
* Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install"
@@ -70,6 +71,6 @@ public class SupportInstallDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(), return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(),
MESSAGE_MIDDLE_CLICKED); MESSAGE_MIDDLE_CLICKED, MESSAGE_DIALOG_DISMISSED);
} }
} }

View File

@@ -26,6 +26,8 @@ import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.view.ContextThemeWrapper;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
@@ -53,7 +55,8 @@ public class InstallDialogFragmentHelper {
} }
public static AlertDialog getInstallDialogFromArgs(Bundle args, final Activity activity, public static AlertDialog getInstallDialogFromArgs(Bundle args, final Activity activity,
final int messengerMiddleButtonClicked) { final int messengerMiddleButtonClicked,
final int messengerDialogDimissed) {
final Messenger messenger = args.getParcelable(ARG_MESSENGER); final Messenger messenger = args.getParcelable(ARG_MESSENGER);
final int title = args.getInt(ARG_TITLE); final int title = args.getInt(ARG_TITLE);
@@ -62,7 +65,12 @@ public class InstallDialogFragmentHelper {
final String installPath = args.getString(ARG_INSTALL_PATH); final String installPath = args.getString(ARG_INSTALL_PATH);
final boolean useMiddleButton = args.getBoolean(ARG_USE_MIDDLE_BUTTON); final boolean useMiddleButton = args.getBoolean(ARG_USE_MIDDLE_BUTTON);
CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(activity); // if the dialog is displayed from the application class, design is missing.
// hack to get holo design (which is not automatically applied due to activity's
// Theme.NoDisplay)
ContextThemeWrapper theme = new ContextThemeWrapper(activity,
R.style.Theme_AppCompat_Light_Dialog);
CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme);
builder.setTitle(title).setMessage(message); builder.setTitle(title).setMessage(message);
@@ -70,7 +78,15 @@ public class InstallDialogFragmentHelper {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Message msg = Message.obtain();
msg.what = messengerDialogDimissed;
try {
messenger.send(msg);
} catch (RemoteException e) {
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
} catch (NullPointerException e) {
Log.w(Constants.TAG, "Messenger is null!", e);
}
} }
}); });
@@ -81,6 +97,16 @@ public class InstallDialogFragmentHelper {
Uri uri = Uri.parse(installPath); Uri uri = Uri.parse(installPath);
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent); activity.startActivity(intent);
Message msg = Message.obtain();
msg.what = messengerDialogDimissed;
try {
messenger.send(msg);
} catch (RemoteException e) {
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
} catch (NullPointerException e) {
Log.w(Constants.TAG, "Messenger is null!", e);
}
} }
} }
); );
@@ -90,7 +116,7 @@ public class InstallDialogFragmentHelper {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Message msg = new Message(); Message msg = Message.obtain();
msg.what = messengerMiddleButtonClicked; msg.what = messengerMiddleButtonClicked;
try { try {
messenger.send(msg); messenger.send(msg);

View File

@@ -149,22 +149,30 @@ public class OrbotHelper {
* @param fragmentActivity * @param fragmentActivity
* @return true if Tor is not enabled or Tor is enabled and Orbot is installed and running, else false * @return true if Tor is not enabled or Tor is enabled and Orbot is installed and running, else false
*/ */
public static boolean putOrbotInRequiredState(int middleButton, final Runnable middleButtonRunnable, public static boolean putOrbotInRequiredState(final int middleButton,
final Runnable middleButtonRunnable,
final Runnable dialogDismissRunnable,
Preferences.ProxyPrefs proxyPrefs, Preferences.ProxyPrefs proxyPrefs,
FragmentActivity fragmentActivity) { FragmentActivity fragmentActivity) {
Handler ignoreTorHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// every message received by this handler will mean the middle button was pressed
middleButtonRunnable.run();
}
};
if (!proxyPrefs.torEnabled) { if (!proxyPrefs.torEnabled) {
return true; return true;
} }
if (!OrbotHelper.isOrbotInstalled(fragmentActivity)) { if (!OrbotHelper.isOrbotInstalled(fragmentActivity)) {
Handler ignoreTorHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SupportInstallDialogFragment.MESSAGE_MIDDLE_CLICKED:
middleButtonRunnable.run();
break;
case SupportInstallDialogFragment.MESSAGE_DIALOG_DISMISSED:
dialogDismissRunnable.run();
break;
}
}
};
OrbotHelper.getInstallDialogFragmentWithThirdButton( OrbotHelper.getInstallDialogFragmentWithThirdButton(
new Messenger(ignoreTorHandler), new Messenger(ignoreTorHandler),
@@ -174,6 +182,20 @@ public class OrbotHelper {
return false; return false;
} else if (!OrbotHelper.isOrbotRunning()) { } else if (!OrbotHelper.isOrbotRunning()) {
Handler ignoreTorHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case OrbotStartDialogFragment.MESSAGE_MIDDLE_BUTTON:
middleButtonRunnable.run();
break;
case OrbotStartDialogFragment.MESSAGE_DIALOG_DISMISSED:
dialogDismissRunnable.run();
break;
}
}
};
OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler), OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler),
middleButton) middleButton)
.show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotStartDialog"); .show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotStartDialog");
@@ -183,4 +205,18 @@ public class OrbotHelper {
return true; return true;
} }
} }
public static boolean putOrbotInRequiredState(final int middleButton,
final Runnable middleButtonRunnable,
Preferences.ProxyPrefs proxyPrefs,
FragmentActivity fragmentActivity) {
Runnable emptyRunnable = new Runnable() {
@Override
public void run() {
}
};
return putOrbotInRequiredState(middleButton, middleButtonRunnable, emptyRunnable,
proxyPrefs, fragmentActivity);
}
} }