fixed OrbotRequiredDialogActivity not finishing, orbot install dialog style
This commit is contained in:
@@ -122,19 +122,7 @@ public class CreateYubiKeyImportFragment
|
||||
mNextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
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);
|
||||
}
|
||||
importKey();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -201,7 +189,7 @@ public class CreateYubiKeyImportFragment
|
||||
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()), parcelableProxy);
|
||||
}
|
||||
|
||||
public void importKey(ParcelableProxy parcelableProxy) {
|
||||
public void importKey() {
|
||||
|
||||
ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
|
||||
keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null));
|
||||
|
||||
@@ -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 String keyserver;
|
||||
@@ -424,19 +424,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
|
||||
mSignatureLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity())
|
||||
.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);
|
||||
}
|
||||
lookupUnknownKey(signatureKeyId);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -68,7 +68,15 @@ public class OrbotRequiredDialogActivity extends FragmentActivity {
|
||||
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)
|
||||
.getProxyPrefs(),
|
||||
OrbotRequiredDialogActivity.this)) {
|
||||
@@ -76,7 +84,6 @@ public class OrbotRequiredDialogActivity extends FragmentActivity {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.sufficientlysecure.keychain.ui.dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
@@ -42,6 +43,7 @@ public class OrbotStartDialogFragment extends DialogFragment {
|
||||
private static final String ARG_MIDDLE_BUTTON = "middleButton";
|
||||
|
||||
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) {
|
||||
Bundle args = new Bundle();
|
||||
@@ -77,6 +79,15 @@ public class OrbotStartDialogFragment extends DialogFragment {
|
||||
builder.setNegativeButton(R.string.orbot_start_dialog_cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
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
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper;
|
||||
public class PreferenceInstallDialogFragment extends DialogFragment {
|
||||
|
||||
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"
|
||||
@@ -69,6 +70,6 @@ public class PreferenceInstallDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(),
|
||||
MESSAGE_MIDDLE_CLICKED);
|
||||
MESSAGE_MIDDLE_CLICKED, MESSAGE_DIALOG_DISMISSED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.ui.util.InstallDialogFragmentHelper;
|
||||
public class SupportInstallDialogFragment extends DialogFragment {
|
||||
|
||||
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"
|
||||
@@ -70,6 +71,6 @@ public class SupportInstallDialogFragment extends DialogFragment {
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
return InstallDialogFragmentHelper.getInstallDialogFromArgs(getArguments(), getActivity(),
|
||||
MESSAGE_MIDDLE_CLICKED);
|
||||
MESSAGE_MIDDLE_CLICKED, MESSAGE_DIALOG_DISMISSED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
@@ -53,7 +55,8 @@ public class InstallDialogFragmentHelper {
|
||||
}
|
||||
|
||||
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 int title = args.getInt(ARG_TITLE);
|
||||
@@ -62,7 +65,12 @@ public class InstallDialogFragmentHelper {
|
||||
final String installPath = args.getString(ARG_INSTALL_PATH);
|
||||
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);
|
||||
|
||||
@@ -70,7 +78,15 @@ public class InstallDialogFragmentHelper {
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
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);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Message msg = new Message();
|
||||
Message msg = Message.obtain();
|
||||
msg.what = messengerMiddleButtonClicked;
|
||||
try {
|
||||
messenger.send(msg);
|
||||
|
||||
@@ -149,22 +149,30 @@ public class OrbotHelper {
|
||||
* @param fragmentActivity
|
||||
* @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,
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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(
|
||||
new Messenger(ignoreTorHandler),
|
||||
@@ -174,6 +182,20 @@ public class OrbotHelper {
|
||||
return false;
|
||||
} 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),
|
||||
middleButton)
|
||||
.show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotStartDialog");
|
||||
@@ -183,4 +205,18 @@ public class OrbotHelper {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user