diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked')
6 files changed, 102 insertions, 147 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java index 8062428e3..c54d0c948 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep1Fragment.java @@ -107,10 +107,10 @@ public class LinkedIdCreateDnsStep1Fragment extends Fragment { if (uri.length() > 0) { if (checkUri(uri)) { mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_ok, 0); + R.drawable.ic_stat_retyped_ok, 0); } else { mEditDns.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_bad, 0); + R.drawable.ic_stat_retyped_bad, 0); } } else { // remove drawable if email is empty diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java index e0e6976ee..c9eca8882 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateDnsStep2Fragment.java @@ -17,6 +17,14 @@ package org.sufficientlysecure.keychain.ui.linked; + +import java.io.FileNotFoundException; +import java.io.PrintWriter; + +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -26,17 +34,14 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.TextView; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; -import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.linked.LinkedTokenResource; import org.sufficientlysecure.keychain.linked.resources.DnsResource; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; -import java.io.FileNotFoundException; -import java.io.PrintWriter; - public class LinkedIdCreateDnsStep2Fragment extends LinkedIdCreateFinalFragment { private static final int REQUEST_CODE_OUTPUT = 0x00007007; @@ -117,7 +122,20 @@ public class LinkedIdCreateDnsStep2Fragment extends LinkedIdCreateFinalFragment } private void proofToClipboard() { - ClipboardReflection.copyToClipboard(getActivity(), mResourceString); + Activity activity = getActivity(); + if (activity == null) { + return; + } + + ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipMan == null) { + Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show(); + return; + } + + ClipData clip = ClipData.newPlainText(Constants.CLIPBOARD_LABEL, mResourceString); + clipMan.setPrimaryClip(clip); + Notify.create(getActivity(), R.string.linked_text_clipboard, Notify.Style.OK).show(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java index eedc7cdd9..24499a467 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java @@ -1,12 +1,11 @@ package org.sufficientlysecure.keychain.ui.linked; -import android.app.ProgressDialog; -import android.content.Intent; + import android.graphics.PorterDuff; import android.os.AsyncTask; import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; +import android.os.Parcelable; +import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -16,20 +15,18 @@ import android.widget.TextView; import android.widget.ViewAnimator; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.linked.LinkedAttribute; +import org.sufficientlysecure.keychain.linked.LinkedTokenResource; import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; -import org.sufficientlysecure.keychain.linked.LinkedTokenResource; -import org.sufficientlysecure.keychain.linked.LinkedAttribute; -import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; -import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; -import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment.ServiceType; import org.sufficientlysecure.keychain.ui.util.Notify; + public abstract class LinkedIdCreateFinalFragment extends CryptoOperationFragment { protected LinkedIdWizard mLinkedIdWizard; @@ -169,54 +166,31 @@ public abstract class LinkedIdCreateFinalFragment extends CryptoOperationFragmen } - protected void cryptoOperation(CryptoInputParcel cryptoInput) { - + @Override + protected void cryptoOperation() { if (mVerifiedResource == null) { Notify.create(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR) .show(LinkedIdCreateFinalFragment.this); return; } - ServiceProgressHandler saveHandler = new ServiceProgressHandler( - getActivity(), - getString(R.string.progress_saving), - ProgressDialog.STYLE_HORIZONTAL, - true, ServiceType.KEYCHAIN_INTENT) { - - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); - - // handle pending messages - if (handlePendingMessage(message)) { - return; - } - - 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); - if (result == null) { - return; - } - - // if bad -> display here! - if (!result.success()) { - result.createNotify(getActivity()).show(LinkedIdCreateFinalFragment.this); - return; - } + super.cryptoOperation(); + } - getActivity().finish(); + @Override + protected void cryptoOperation(CryptoInputParcel cryptoInput) { + if (mVerifiedResource == null) { + Notify.create(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR) + .show(LinkedIdCreateFinalFragment.this); + return; + } - } - } - }; + super.cryptoOperation(cryptoInput); + } + @Nullable + @Override + public Parcelable createOperationInput() { SaveKeyringParcel skp = new SaveKeyringParcel(mLinkedIdWizard.mMasterKeyId, mLinkedIdWizard.mFingerprint); @@ -225,25 +199,22 @@ public abstract class LinkedIdCreateFinalFragment extends CryptoOperationFragmen skp.mAddUserAttribute.add(ua); - // Send all information needed to service to import key in other thread - Intent intent = new Intent(getActivity(), KeychainIntentService.class); - intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING); - - // fill values for this action - Bundle data = new Bundle(); - data.putParcelable(KeychainIntentService.EXTRA_CRYPTO_INPUT, cryptoInput); - data.putParcelable(KeychainIntentService.EDIT_KEYRING_PARCEL, skp); - intent.putExtra(KeychainIntentService.EXTRA_DATA, data); + return skp; + } - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); + @Override + public void onCryptoOperationSuccess(OperationResult result) { + // if bad -> display here! + if (!result.success()) { + result.createNotify(getActivity()).show(LinkedIdCreateFinalFragment.this); + return; + } - // show progress dialog - saveHandler.showProgressDialog(getActivity()); + getActivity().finish(); + } - // start service with intent - getActivity().startService(intent); + @Override + public void onCryptoOperationError(OperationResult result) { } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java index 7bc33c93b..8a05c35db 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep1Fragment.java @@ -103,10 +103,10 @@ public class LinkedIdCreateHttpsStep1Fragment extends Fragment { if (uri.length() > 0) { if (checkUri(uri)) { mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_ok, 0); + R.drawable.ic_stat_retyped_ok, 0); } else { mEditUri.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_bad, 0); + R.drawable.ic_stat_retyped_bad, 0); } } else { // remove drawable if email is empty diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java index 2af97fe36..22a201ba3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateHttpsStep2Fragment.java @@ -19,7 +19,6 @@ package org.sufficientlysecure.keychain.ui.linked; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.view.LayoutInflater; @@ -135,13 +134,10 @@ public class LinkedIdCreateHttpsStep2Fragment extends LinkedIdCreateFinalFragmen String targetName = "pgpkey.txt"; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - File targetFile = new File(Constants.Path.APP_DIR, targetName); - FileHelper.saveFile(this, getString(R.string.title_decrypt_to_file), - getString(R.string.specify_file_to_decrypt_to), targetFile, REQUEST_CODE_OUTPUT); - } else { - FileHelper.saveDocument(this, "text/plain", targetName, REQUEST_CODE_OUTPUT); - } + FileHelper.saveDocument(this, + targetName, Uri.fromFile(new File(Constants.Path.APP_DIR, targetName)), + "text/plain", R.string.title_decrypt_to_file, R.string.specify_file_to_decrypt_to, + REQUEST_CODE_OUTPUT); } private void saveFile(Uri uri) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java index 82aaa51c4..7007fa50c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java @@ -12,8 +12,8 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.os.Message; -import android.os.Messenger; +import android.os.Parcelable; +import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager.OnBackStackChangedListener; import android.support.v4.app.LoaderManager; @@ -31,20 +31,17 @@ import android.widget.ViewAnimator; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants.key; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult; import org.sufficientlysecure.keychain.linked.LinkedTokenResource; import org.sufficientlysecure.keychain.linked.LinkedAttribute; import org.sufficientlysecure.keychain.linked.LinkedResource; import org.sufficientlysecure.keychain.linked.UriAttribute; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; -import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.ServiceProgressHandler; -import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; @@ -58,7 +55,6 @@ import org.sufficientlysecure.keychain.ui.widget.CertListWidget; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.util.Log; - public class LinkedIdViewFragment extends CryptoOperationFragment implements LoaderManager.LoaderCallbacks<Cursor>, OnBackStackChangedListener { @@ -97,6 +93,12 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements return frag; } + public LinkedIdViewFragment() { + // IMPORTANT: the id must be unique in the ViewKeyActivity CryptoOperationHelper id namespace! + // no initial progress message -> we handle progress ourselves! + super(5, null); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -499,7 +501,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements } // get the user's passphrase for this key (if required) - mCertifyKeyId = mViewHolder.vKeySpinner.getSelectedItemId(); + mCertifyKeyId = mViewHolder.vKeySpinner.getSelectedKeyId(); if (mCertifyKeyId == key.none || mCertifyKeyId == key.symmetric) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SubtleAttentionSeeker.tintBackground(mViewHolder.vKeySpinnerContainer, 600).start(); @@ -509,11 +511,13 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements return; } + mViewHolder.setVerifyingState(mContext, VerifyState.CERTIFYING, false); cryptoOperation(); + } @Override - protected void onCryptoOperationCancelled() { + public void onCryptoOperationCancelled() { super.onCryptoOperationCancelled(); // go back to 'verified ok' @@ -521,68 +525,34 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements } + @Nullable @Override - protected void cryptoOperation(CryptoInputParcel cryptoInput) { - - if (mIsSecret) { - return; - } - - mViewHolder.setVerifyingState(mContext, VerifyState.CERTIFYING, false); - - Bundle data = new Bundle(); - { - - long masterKeyId = KeyFormattingUtils.convertFingerprintToKeyId(mFingerprint); - CertifyAction action = new CertifyAction(masterKeyId, null, - Collections.singletonList(mLinkedId.toUserAttribute())); - - // fill values for this action - CertifyActionsParcel parcel = new CertifyActionsParcel(mCertifyKeyId); - parcel.mCertifyActions.addAll(Collections.singletonList(action)); - data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel); - - data.putParcelable(KeychainIntentService.EXTRA_CRYPTO_INPUT, cryptoInput); + public Parcelable createOperationInput() { + long masterKeyId = KeyFormattingUtils.convertFingerprintToKeyId(mFingerprint); + CertifyAction action = new CertifyAction(masterKeyId, null, + Collections.singletonList(mLinkedId.toUserAttribute())); - /* if (mUploadKeyCheckbox.isChecked()) { - String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); - data.putString(KeychainIntentService.UPLOAD_KEY_SERVER, keyserver); - } */ - } - - // Send all information needed to service to sign key in other thread - Intent intent = new Intent(getActivity(), KeychainIntentService.class); - intent.setAction(KeychainIntentService.ACTION_CERTIFY_KEYRING); - intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - - // Message is received after signing is done in KeychainIntentService - ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity()) { - public void handleMessage(Message message) { - // handle messages by standard KeychainIntentServiceHandler first - super.handleMessage(message); - - // handle pending messages - if (handlePendingMessage(message)) { - return; - } - - if (message.arg1 == MessageStatus.OKAY.ordinal()) { - Bundle data = message.getData(); - CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT); - result.createNotify(getActivity()).show(); - // no need to do anything else, we will get a loader refresh! - } + // fill values for this action + CertifyActionsParcel parcel = new CertifyActionsParcel(mCertifyKeyId); + parcel.mCertifyActions.addAll(Collections.singletonList(action)); - } - }; + return parcel; + } - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); + @Override + public void onCryptoOperationSuccess(OperationResult result) { + result.createNotify(getActivity()).show(); + // no need to do anything else, we will get a loader refresh! + } - // start service with intent - getActivity().startService(intent); + @Override + public void onCryptoOperationError(OperationResult result) { + result.createNotify(getActivity()).show(); + } + @Override + public boolean onCryptoSetProgress(String msg, int progress, int max) { + return true; } } |