mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-15 13:25:06 -05:00
backport CryptoOperationFragment changes without eventbus
This commit is contained in:
parent
9b6416943b
commit
61dce088c2
@ -24,7 +24,6 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// JCenter etc.
|
// JCenter etc.
|
||||||
compile 'de.greenrobot:eventbus:2.4.0'
|
|
||||||
compile 'com.eftimoff:android-patternview:1.0.1@aar'
|
compile 'com.eftimoff:android-patternview:1.0.1@aar'
|
||||||
compile 'com.journeyapps:zxing-android-embedded:2.3.0@aar'
|
compile 'com.journeyapps:zxing-android-embedded:2.3.0@aar'
|
||||||
compile 'com.journeyapps:zxing-android-integration:2.3.0@aar'
|
compile 'com.journeyapps:zxing-android-integration:2.3.0@aar'
|
||||||
|
@ -25,9 +25,11 @@ import android.app.Service;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.operations.BaseOperation;
|
import org.sufficientlysecure.keychain.operations.BaseOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
||||||
@ -40,6 +42,7 @@ import org.sufficientlysecure.keychain.pgp.Progressable;
|
|||||||
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||||
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
@ -49,13 +52,18 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class KeychainNewService extends Service implements Progressable {
|
public class KeychainNewService extends Service implements Progressable {
|
||||||
|
|
||||||
/* extras that can be given by intent */
|
// messenger for communication (hack)
|
||||||
|
public static final String EXTRA_MESSENGER = "messenger";
|
||||||
|
|
||||||
|
// extras for operation
|
||||||
public static final String EXTRA_OPERATION_INPUT = "op_input";
|
public static final String EXTRA_OPERATION_INPUT = "op_input";
|
||||||
public static final String EXTRA_CRYPTO_INPUT = "crypto_input";
|
public static final String EXTRA_CRYPTO_INPUT = "crypto_input";
|
||||||
|
|
||||||
// this attribute can possibly merged with the one above? not sure...
|
// this attribute can possibly merged with the one above? not sure...
|
||||||
private AtomicBoolean mActionCanceled = new AtomicBoolean(false);
|
private AtomicBoolean mActionCanceled = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
ThreadLocal<Messenger> mMessenger = new ThreadLocal<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return null;
|
return null;
|
||||||
@ -66,56 +74,82 @@ public class KeychainNewService extends Service implements Progressable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(final Intent intent, int flags, int startId) {
|
public int onStartCommand(final Intent intent, int flags, int startId) {
|
||||||
EventBus bus = EventBus.getDefault();
|
|
||||||
if (!bus.isRegistered(this)) {
|
|
||||||
bus.register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
Runnable actionRunnable = new Runnable() {
|
||||||
if (extras != null) {
|
@Override
|
||||||
bus.post(extras);
|
public void run() {
|
||||||
} else {
|
// We have not been cancelled! (yet)
|
||||||
Log.e(Constants.TAG, "Extras bundle is null!");
|
mActionCanceled.set(false);
|
||||||
}
|
|
||||||
|
Bundle extras = intent.getExtras();
|
||||||
|
|
||||||
|
// Set messenger for communication (for this particular thread)
|
||||||
|
mMessenger.set(extras.<Messenger>getParcelable(EXTRA_MESSENGER));
|
||||||
|
|
||||||
|
// Input
|
||||||
|
Parcelable inputParcel = extras.getParcelable(EXTRA_OPERATION_INPUT);
|
||||||
|
CryptoInputParcel cryptoInput = extras.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
BaseOperation op;
|
||||||
|
|
||||||
|
// just for brevity
|
||||||
|
KeychainNewService outerThis = KeychainNewService.this;
|
||||||
|
if (inputParcel instanceof SignEncryptParcel) {
|
||||||
|
op = new SignEncryptOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||||
|
} else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {
|
||||||
|
op = new PgpDecryptVerify(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||||
|
} else if (inputParcel instanceof SaveKeyringParcel) {
|
||||||
|
op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||||
|
} else if (inputParcel instanceof CertifyAction) {
|
||||||
|
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked") // this is unchecked, we make sure it's the correct op above!
|
||||||
|
OperationResult result = op.execute(inputParcel, cryptoInput);
|
||||||
|
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Thread actionThread = new Thread(actionRunnable);
|
||||||
|
actionThread.start();
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void sendMessageToHandler(MessageStatus status, Integer arg2, Bundle data) {
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
EventBus.getDefault().unregister(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onEventAsync(Bundle bundle) {
|
Message msg = Message.obtain();
|
||||||
|
assert msg != null;
|
||||||
// Input
|
msg.arg1 = status.ordinal();
|
||||||
Parcelable inputParcel = bundle.getParcelable(EXTRA_OPERATION_INPUT);
|
if (arg2 != null) {
|
||||||
CryptoInputParcel cryptoInput = bundle.getParcelable(EXTRA_CRYPTO_INPUT);
|
msg.arg2 = arg2;
|
||||||
|
}
|
||||||
// Operation
|
if (data != null) {
|
||||||
BaseOperation op;
|
msg.setData(data);
|
||||||
|
|
||||||
if (inputParcel instanceof SignEncryptParcel) {
|
|
||||||
op = new SignEncryptOperation(this, new ProviderHelper(this), this, mActionCanceled);
|
|
||||||
} else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {
|
|
||||||
op = new PgpDecryptVerify(this, new ProviderHelper(this), this);
|
|
||||||
} else if (inputParcel instanceof SaveKeyringParcel) {
|
|
||||||
op = new EditKeyOperation(this, new ProviderHelper(this), this, mActionCanceled);
|
|
||||||
} else if (inputParcel instanceof CertifyAction) {
|
|
||||||
op = new CertifyOperation(this, new ProviderHelper(this), this, mActionCanceled);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") // this is unchecked, we make sure it's the correct op above!
|
try {
|
||||||
OperationResult result = op.execute(inputParcel, cryptoInput);
|
mMessenger.get().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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Result
|
private void sendMessageToHandler(MessageStatus status, OperationResult data) {
|
||||||
EventBus.getDefault().post(result);
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(OperationResult.EXTRA_RESULT, data);
|
||||||
stopSelf();
|
sendMessageToHandler(status, null, bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToHandler(MessageStatus status) {
|
||||||
|
sendMessageToHandler(status, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,9 +160,14 @@ public class KeychainNewService extends Service implements Progressable {
|
|||||||
Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
|
Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
|
||||||
+ max);
|
+ max);
|
||||||
|
|
||||||
ProgressEvent event = new ProgressEvent(message, progress, max);
|
Bundle data = new Bundle();
|
||||||
EventBus.getDefault().post(event);
|
if (message != null) {
|
||||||
|
data.putString(ServiceProgressHandler.DATA_MESSAGE, message);
|
||||||
|
}
|
||||||
|
data.putInt(ServiceProgressHandler.DATA_PROGRESS, progress);
|
||||||
|
data.putInt(ServiceProgressHandler.DATA_PROGRESS_MAX, max);
|
||||||
|
|
||||||
|
sendMessageToHandler(MessageStatus.UPDATE_PROGRESS, null, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -143,8 +182,7 @@ public class KeychainNewService extends Service implements Progressable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPreventCancel() {
|
public void setPreventCancel() {
|
||||||
// sendMessageToHandler(MessageStatus.PREVENT_CANCEL);
|
sendMessageToHandler(MessageStatus.PREVENT_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import android.os.RemoteException;
|
|||||||
import com.textuality.keybase.lib.Proof;
|
import com.textuality.keybase.lib.Proof;
|
||||||
import com.textuality.keybase.lib.prover.Prover;
|
import com.textuality.keybase.lib.prover.Prover;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.spongycastle.openpgp.PGPUtil;
|
import org.spongycastle.openpgp.PGPUtil;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package org.sufficientlysecure.keychain.service;
|
|
||||||
|
|
||||||
|
|
||||||
public class ProgressEvent {
|
|
||||||
|
|
||||||
public final String mMessage;
|
|
||||||
public final int mProgress;
|
|
||||||
public final int mMax;
|
|
||||||
|
|
||||||
public ProgressEvent(String message, int progress, int max) {
|
|
||||||
mMessage = message;
|
|
||||||
mProgress = progress;
|
|
||||||
mMax = max;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -17,8 +17,7 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.service;
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -27,7 +26,6 @@ import android.support.v4.app.FragmentManager;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -65,68 +63,58 @@ public class ServiceProgressHandler extends Handler {
|
|||||||
public static final String KEYBASE_PRESENCE_URL = "keybase_presence_url";
|
public static final String KEYBASE_PRESENCE_URL = "keybase_presence_url";
|
||||||
public static final String KEYBASE_PRESENCE_LABEL = "keybase_presence_label";
|
public static final String KEYBASE_PRESENCE_LABEL = "keybase_presence_label";
|
||||||
|
|
||||||
Activity mActivity;
|
FragmentActivity mActivity;
|
||||||
ProgressDialogFragment mProgressDialogFragment;
|
|
||||||
|
|
||||||
public ServiceProgressHandler(Activity activity) {
|
public ServiceProgressHandler(FragmentActivity activity) {
|
||||||
this.mActivity = activity;
|
mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceProgressHandler(Activity activity, ProgressDialogFragment progressDialogFragment) {
|
public void showProgressDialog() {
|
||||||
this.mActivity = activity;
|
showProgressDialog("", ProgressDialog.STYLE_SPINNER, false);
|
||||||
this.mProgressDialogFragment = progressDialogFragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceProgressHandler(Activity activity, String progressDialogMessage, int progressDialogStyle) {
|
public void showProgressDialog(
|
||||||
this(activity, progressDialogMessage, progressDialogStyle, false);
|
String progressDialogMessage, int progressDialogStyle, boolean cancelable) {
|
||||||
}
|
|
||||||
|
|
||||||
public ServiceProgressHandler(Activity activity,
|
final ProgressDialogFragment frag = ProgressDialogFragment.newInstance(
|
||||||
String progressDialogMessage,
|
|
||||||
int progressDialogStyle,
|
|
||||||
boolean cancelable) {
|
|
||||||
this.mActivity = activity;
|
|
||||||
this.mProgressDialogFragment = ProgressDialogFragment.newInstance(
|
|
||||||
progressDialogMessage,
|
progressDialogMessage,
|
||||||
progressDialogStyle,
|
progressDialogStyle,
|
||||||
cancelable);
|
cancelable);
|
||||||
}
|
|
||||||
|
|
||||||
public void showProgressDialog(FragmentActivity activity) {
|
|
||||||
if (mProgressDialogFragment == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This is a hack!, see
|
// TODO: This is a hack!, see
|
||||||
// http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
|
// http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
|
||||||
final FragmentManager manager = activity.getSupportFragmentManager();
|
final FragmentManager manager = mActivity.getSupportFragmentManager();
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mProgressDialogFragment.show(manager, "progressDialog");
|
frag.show(manager, "progressDialog");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
|
|
||||||
if (mProgressDialogFragment == null) {
|
ProgressDialogFragment progressDialogFragment =
|
||||||
// Log.e(Constants.TAG,
|
(ProgressDialogFragment) mActivity.getSupportFragmentManager()
|
||||||
// "Progress has not been updated because mProgressDialogFragment was null!");
|
.findFragmentByTag("progressDialog");
|
||||||
|
|
||||||
|
if (progressDialogFragment == null) {
|
||||||
|
Log.e(Constants.TAG, "Progress has not been updated because mProgressDialogFragment was null!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageStatus status = MessageStatus.fromInt(message.arg1);
|
MessageStatus status = MessageStatus.fromInt(message.arg1);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case OKAY:
|
case OKAY:
|
||||||
mProgressDialogFragment.dismissAllowingStateLoss();
|
progressDialogFragment.dismissAllowingStateLoss();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXCEPTION:
|
case EXCEPTION:
|
||||||
mProgressDialogFragment.dismissAllowingStateLoss();
|
progressDialogFragment.dismissAllowingStateLoss();
|
||||||
|
|
||||||
// show error from service
|
// show error from service
|
||||||
if (data.containsKey(DATA_ERROR)) {
|
if (data.containsKey(DATA_ERROR)) {
|
||||||
@ -142,13 +130,13 @@ public class ServiceProgressHandler extends Handler {
|
|||||||
|
|
||||||
// update progress from service
|
// update progress from service
|
||||||
if (data.containsKey(DATA_MESSAGE)) {
|
if (data.containsKey(DATA_MESSAGE)) {
|
||||||
mProgressDialogFragment.setProgress(data.getString(DATA_MESSAGE),
|
progressDialogFragment.setProgress(data.getString(DATA_MESSAGE),
|
||||||
data.getInt(DATA_PROGRESS), data.getInt(DATA_PROGRESS_MAX));
|
data.getInt(DATA_PROGRESS), data.getInt(DATA_PROGRESS_MAX));
|
||||||
} else if (data.containsKey(DATA_MESSAGE_ID)) {
|
} else if (data.containsKey(DATA_MESSAGE_ID)) {
|
||||||
mProgressDialogFragment.setProgress(data.getInt(DATA_MESSAGE_ID),
|
progressDialogFragment.setProgress(data.getInt(DATA_MESSAGE_ID),
|
||||||
data.getInt(DATA_PROGRESS), data.getInt(DATA_PROGRESS_MAX));
|
data.getInt(DATA_PROGRESS), data.getInt(DATA_PROGRESS_MAX));
|
||||||
} else {
|
} else {
|
||||||
mProgressDialogFragment.setProgress(data.getInt(DATA_PROGRESS),
|
progressDialogFragment.setProgress(data.getInt(DATA_PROGRESS),
|
||||||
data.getInt(DATA_PROGRESS_MAX));
|
data.getInt(DATA_PROGRESS_MAX));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +144,7 @@ public class ServiceProgressHandler extends Handler {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PREVENT_CANCEL:
|
case PREVENT_CANCEL:
|
||||||
mProgressDialogFragment.setPreventCancel(true);
|
progressDialogFragment.setPreventCancel(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -49,11 +49,7 @@ public class ConsolidateDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
private void consolidateRecovery(boolean recovery) {
|
private void consolidateRecovery(boolean recovery) {
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
|
||||||
this,
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -94,7 +90,10 @@ public class ConsolidateDialogActivity extends FragmentActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(this);
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
@ -197,11 +197,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
Intent intent = new Intent(getActivity(), KeychainService.class);
|
Intent intent = new Intent(getActivity(), KeychainService.class);
|
||||||
intent.setAction(KeychainService.ACTION_EDIT_KEYRING);
|
intent.setAction(KeychainService.ACTION_EDIT_KEYRING);
|
||||||
|
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_building_key),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -245,7 +241,8 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
Messenger messenger = new Messenger(saveHandler);
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
saveHandler.showProgressDialog(getActivity());
|
saveHandler.showProgressDialog(getString(R.string.progress_building_key),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
}
|
}
|
||||||
@ -271,11 +268,7 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
|
|
||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||||
|
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_uploading),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -301,10 +294,13 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(getActivity());
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_uploading),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -176,11 +176,7 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
|
|||||||
public void importKey() {
|
public void importKey() {
|
||||||
|
|
||||||
// Message is received after decrypting is done in KeychainService
|
// Message is received after decrypting is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -243,7 +239,10 @@ public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListe
|
|||||||
Messenger messenger = new Messenger(saveHandler);
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
saveHandler.showProgressDialog(getActivity());
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
@ -30,7 +30,6 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
|
||||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
@ -388,12 +388,7 @@ public class ImportKeysActivity extends BaseNfcActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
|
||||||
this,
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
|
||||||
true
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -435,7 +430,11 @@ public class ImportKeysActivity extends BaseNfcActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
serviceHandler.showProgressDialog(this);
|
serviceHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
@ -469,7 +468,10 @@ public class ImportKeysActivity extends BaseNfcActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
serviceHandler.showProgressDialog(this);
|
serviceHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, true
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
@ -206,12 +206,7 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
private void startImportService(ArrayList<ParcelableKeyRing> keyRings) {
|
private void startImportService(ArrayList<ParcelableKeyRing> keyRings) {
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
|
||||||
this,
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
|
||||||
true
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -273,7 +268,9 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
serviceHandler.showProgressDialog(this);
|
serviceHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, true);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
@ -572,12 +572,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
keyList.add(keyEntry);
|
keyList.add(keyEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_updating),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
|
||||||
true
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -625,7 +620,9 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
serviceHandler.showProgressDialog(getActivity());
|
serviceHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_updating),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, true);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
@ -633,11 +630,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
private void consolidate() {
|
private void consolidate() {
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -675,7 +668,9 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(getActivity());
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
@ -124,12 +124,7 @@ public class SafeSlingerActivity extends BaseActivity {
|
|||||||
final FragmentActivity activity = SafeSlingerActivity.this;
|
final FragmentActivity activity = SafeSlingerActivity.this;
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(activity) {
|
||||||
activity,
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
|
||||||
true
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -202,7 +197,10 @@ public class SafeSlingerActivity extends BaseActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(activity);
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, true
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
activity.startService(intent);
|
activity.startService(intent);
|
||||||
|
@ -108,11 +108,7 @@ public class UploadKeyActivity extends BaseActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after uploading is done in KeychainService
|
// Message is received after uploading is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
|
||||||
this,
|
|
||||||
getString(R.string.progress_uploading),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -132,7 +128,9 @@ public class UploadKeyActivity extends BaseActivity {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(this);
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_uploading),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
@ -698,9 +698,6 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
|||||||
Messenger messenger = new Messenger(serviceHandler);
|
Messenger messenger = new Messenger(serviceHandler);
|
||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
|
||||||
serviceHandler.showProgressDialog(this);
|
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
|
||||||
|
@ -360,12 +360,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
|
|||||||
mProofVerifyDetail.setVisibility(View.GONE);
|
mProofVerifyDetail.setVisibility(View.GONE);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back after proof work is done
|
// Create a new Messenger for the communication back after proof work is done
|
||||||
//
|
ServiceProgressHandler handler = new ServiceProgressHandler(getActivity()) {
|
||||||
ServiceProgressHandler handler = new ServiceProgressHandler(
|
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_verifying_signature),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -454,7 +449,10 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
handler.showProgressDialog(getActivity());
|
handler.showProgressDialog(
|
||||||
|
getString(R.string.progress_verifying_signature),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
@ -5,11 +5,13 @@ import android.app.ProgressDialog;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainNewService;
|
import org.sufficientlysecure.keychain.service.KeychainNewService;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
|
|
||||||
@ -55,6 +57,7 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
|
|||||||
// Notify was created by createCryptoInput.
|
// Notify was created by createCryptoInput.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send all information needed to service to edit key in other thread
|
// Send all information needed to service to edit key in other thread
|
||||||
@ -63,12 +66,36 @@ public abstract class CachingCryptoOperationFragment <T extends Parcelable, S ex
|
|||||||
intent.putExtra(KeychainNewService.EXTRA_OPERATION_INPUT, mCachedActionsParcel);
|
intent.putExtra(KeychainNewService.EXTRA_OPERATION_INPUT, mCachedActionsParcel);
|
||||||
intent.putExtra(KeychainNewService.EXTRA_CRYPTO_INPUT, cryptoInput);
|
intent.putExtra(KeychainNewService.EXTRA_CRYPTO_INPUT, cryptoInput);
|
||||||
|
|
||||||
showProgressFragment(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getString(R.string.progress_start),
|
@Override
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
public void handleMessage(Message message) {
|
||||||
false);
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
|
super.handleMessage(message);
|
||||||
|
|
||||||
|
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||||
|
|
||||||
|
// get returned data bundle
|
||||||
|
Bundle returnData = message.getData();
|
||||||
|
if (returnData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final OperationResult result =
|
||||||
|
returnData.getParcelable(OperationResult.EXTRA_RESULT);
|
||||||
|
|
||||||
|
onHandleResult(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_building_key),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
// start service with intent
|
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,16 +21,18 @@ package org.sufficientlysecure.keychain.ui.base;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainNewService;
|
import org.sufficientlysecure.keychain.service.KeychainNewService;
|
||||||
import org.sufficientlysecure.keychain.service.ProgressEvent;
|
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||||
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
||||||
@ -47,18 +49,6 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
||||||
public static final int REQUEST_CODE_NFC = 0x00008002;
|
public static final int REQUEST_CODE_NFC = 0x00008002;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
EventBus.getDefault().register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
EventBus.getDefault().unregister(this);
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
||||||
|
|
||||||
switch (requiredInput.mType) {
|
switch (requiredInput.mType) {
|
||||||
@ -130,22 +120,6 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showProgressFragment(String progressDialogMessage,
|
|
||||||
int progressDialogStyle,
|
|
||||||
boolean cancelable) {
|
|
||||||
|
|
||||||
if (getFragmentManager().findFragmentByTag("progressDialog") != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressDialogFragment progressDialogFragment = ProgressDialogFragment.newInstance(
|
|
||||||
progressDialogMessage, progressDialogStyle, cancelable);
|
|
||||||
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
progressDialogFragment.show(manager, "progressDialog");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract T createOperationInput();
|
protected abstract T createOperationInput();
|
||||||
|
|
||||||
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
||||||
@ -161,12 +135,36 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
intent.putExtra(KeychainNewService.EXTRA_OPERATION_INPUT, operationInput);
|
intent.putExtra(KeychainNewService.EXTRA_OPERATION_INPUT, operationInput);
|
||||||
intent.putExtra(KeychainNewService.EXTRA_CRYPTO_INPUT, cryptoInput);
|
intent.putExtra(KeychainNewService.EXTRA_CRYPTO_INPUT, cryptoInput);
|
||||||
|
|
||||||
showProgressFragment(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getString(R.string.progress_start),
|
@Override
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
public void handleMessage(Message message) {
|
||||||
false);
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
|
super.handleMessage(message);
|
||||||
|
|
||||||
|
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||||
|
|
||||||
|
// get returned data bundle
|
||||||
|
Bundle returnData = message.getData();
|
||||||
|
if (returnData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final OperationResult result =
|
||||||
|
returnData.getParcelable(OperationResult.EXTRA_RESULT);
|
||||||
|
|
||||||
|
onHandleResult(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
saveHandler.showProgressDialog(
|
||||||
|
getString(R.string.progress_building_key),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
// start service with intent
|
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -190,11 +188,9 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onCryptoOperationCancelled() {
|
protected void onCryptoOperationCancelled() {
|
||||||
dismissProgress();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") // it's an EventBus method
|
public void onHandleResult(OperationResult result) {
|
||||||
public void onEventMainThread(OperationResult result) {
|
|
||||||
|
|
||||||
if (result instanceof InputPendingResult) {
|
if (result instanceof InputPendingResult) {
|
||||||
InputPendingResult pendingResult = (InputPendingResult) result;
|
InputPendingResult pendingResult = (InputPendingResult) result;
|
||||||
@ -217,18 +213,5 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused") // it's an EventBus method
|
|
||||||
public void onEventMainThread(ProgressEvent event) {
|
|
||||||
|
|
||||||
ProgressDialogFragment progressDialogFragment =
|
|
||||||
(ProgressDialogFragment) getFragmentManager().findFragmentByTag("progressDialog");
|
|
||||||
|
|
||||||
if (progressDialogFragment == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
progressDialogFragment.setProgress(event.mMessage, event.mProgress, event.mMax);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -135,12 +135,7 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
intent.setAction(KeychainService.ACTION_DELETE);
|
intent.setAction(KeychainService.ACTION_DELETE);
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainService
|
// Message is received after importing is done in KeychainService
|
||||||
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) {
|
||||||
getActivity(),
|
|
||||||
getString(R.string.progress_deleting),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
|
||||||
true
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
@ -168,7 +163,8 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(getActivity());
|
saveHandler.showProgressDialog(getString(R.string.progress_deleting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, true);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
@ -97,10 +97,7 @@ public class ExportHelper {
|
|||||||
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
intent.putExtra(KeychainService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after exporting is done in KeychainService
|
// Message is received after exporting is done in KeychainService
|
||||||
ServiceProgressHandler exportHandler = new ServiceProgressHandler(mActivity,
|
ServiceProgressHandler exportHandler = new ServiceProgressHandler(mActivity) {
|
||||||
mActivity.getString(R.string.progress_exporting),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
@ -121,7 +118,10 @@ public class ExportHelper {
|
|||||||
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
exportHandler.showProgressDialog(mActivity);
|
exportHandler.showProgressDialog(
|
||||||
|
mActivity.getString(R.string.progress_exporting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL, false
|
||||||
|
);
|
||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
mActivity.startService(intent);
|
mActivity.startService(intent);
|
||||||
|
Loading…
Reference in New Issue
Block a user