diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-09-23 23:38:30 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-09-23 23:38:30 +0200 |
commit | 0143b54e9ec2453c47baaf9e9ad4a0a14ffc08c3 (patch) | |
tree | 7deccd0966098f3d77727a361004b425ea21f5ac /OpenKeychain/src/main | |
parent | b9347ea9aa6a74f385c149fbbb977c270cb91454 (diff) | |
download | open-keychain-0143b54e9ec2453c47baaf9e9ad4a0a14ffc08c3.tar.gz open-keychain-0143b54e9ec2453c47baaf9e9ad4a0a14ffc08c3.tar.bz2 open-keychain-0143b54e9ec2453c47baaf9e9ad4a0a14ffc08c3.zip |
Implement buttons in DecryptTextFragment
Diffstat (limited to 'OpenKeychain/src/main')
7 files changed, 155 insertions, 68 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java index 875a12f4e..255e1f2aa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java @@ -208,10 +208,10 @@ public class DecryptFilesFragment extends DecryptFragment { if (pgpResult.isPending()) { if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) == DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) { - showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded()); + startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded()); } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) == DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) { - showPassphraseDialog(Constants.key.symmetric); + startPassphraseDialog(Constants.key.symmetric); } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) == DecryptVerifyResult.RESULT_PENDING_NFC) { // TODO @@ -296,10 +296,10 @@ public class DecryptFilesFragment extends DecryptFragment { if (pgpResult.isPending()) { if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) == DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) { - showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded()); + startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded()); } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) == DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) { - showPassphraseDialog(Constants.key.symmetric); + startPassphraseDialog(Constants.key.symmetric); } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) == DecryptVerifyResult.RESULT_PENDING_NFC) { // TODO diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 7298ff6d7..e19110c1f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -33,6 +33,7 @@ import android.widget.TextView; import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.nfc.NfcActivity; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -81,25 +82,51 @@ public abstract class DecryptFragment extends Fragment { startActivityForResult(intent, RESULT_CODE_LOOKUP_KEY); } - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { + public static final int REQUEST_CODE_PASSPHRASE = 0x00008001; + public static final int REQUEST_CODE_NFC = 0x00008002; - case RESULT_CODE_LOOKUP_KEY: { - if (resultCode == Activity.RESULT_OK) { - // TODO: generate new OpenPgpSignatureResult and display it - } - return; - } + protected void startPassphraseDialog(long subkeyId) { + Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class); + intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId); + startActivityForResult(intent, REQUEST_CODE_PASSPHRASE); + } - default: { - super.onActivityResult(requestCode, resultCode, data); + protected void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) { + Intent data = new Intent(); - break; - } - } + // build PendingIntent for Yubikey NFC operations + Intent intent = new Intent(getActivity(), NfcActivity.class); + intent.setAction(NfcActivity.ACTION_SIGN_HASH); + // pass params through to activity that it can be returned again later to repeat pgp operation + intent.putExtra(NfcActivity.EXTRA_DATA, data); + intent.putExtra(NfcActivity.EXTRA_PIN, pin); + + intent.putExtra(NfcActivity.EXTRA_NFC_HASH_TO_SIGN, hashToSign); + intent.putExtra(NfcActivity.EXTRA_NFC_HASH_ALGO, hashAlgo); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); + + startActivityForResult(intent, REQUEST_CODE_NFC); } +// @Override +// public void onActivityResult(int requestCode, int resultCode, Intent data) { +// switch (requestCode) { +// +// case RESULT_CODE_LOOKUP_KEY: { +// if (resultCode == Activity.RESULT_OK) { +// // TODO: generate new OpenPgpSignatureResult and display it +// } +// return; +// } +// +// default: { +// super.onActivityResult(requestCode, resultCode, data); +// +// break; +// } +// } +// } + protected void onResult(DecryptVerifyResult decryptVerifyResult) { OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); @@ -197,20 +224,20 @@ public abstract class DecryptFragment extends Fragment { } } - protected void showPassphraseDialog(long keyId) { - PassphraseDialogFragment.show(getActivity(), keyId, - new Handler() { - @Override - public void handleMessage(Message message) { - if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { - String passphrase = - message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE); - decryptStart(passphrase); - } - } - } - ); - } +// protected void showPassphraseDialog(long keyId) { +// PassphraseDialogFragment.show(getActivity(), keyId, +// new Handler() { +// @Override +// public void handleMessage(Message message) { +// if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { +// String passphrase = +// message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE); +// decryptStart(passphrase); +// } +// } +// } +// ); +// } /** * Should be overridden by MessageFragment and FileFragment to start actual decryption diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java index a7bd0825a..c51b8b766 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java @@ -17,6 +17,7 @@ package org.sufficientlysecure.keychain.ui; +import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; @@ -29,20 +30,23 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ShareHelper; public class DecryptTextFragment extends DecryptFragment { public static final String ARG_CIPHERTEXT = "ciphertext"; -// // view - private TextView mMessage; -// private View mDecryptButton; -// private View mDecryptFromCLipboardButton; -// -// // model + // view + private TextView mText; + private View mShareButton; + private View mCopyButton; + + // model private String mCiphertext; /** @@ -66,25 +70,53 @@ public class DecryptTextFragment extends DecryptFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.decrypt_text_fragment, container, false); - mMessage = (TextView) view.findViewById(R.id.decrypt_text_plaintext); -// mDecryptButton = view.findViewById(R.id.action_decrypt); -// mDecryptFromCLipboardButton = view.findViewById(R.id.action_decrypt_from_clipboard); -// mDecryptButton.setOnClickListener(new OnClickListener() { -// @Override -// public void onClick(View v) { -// decryptClicked(); -// } -// }); -// mDecryptFromCLipboardButton.setOnClickListener(new OnClickListener() { -// @Override -// public void onClick(View v) { -// decryptFromClipboardClicked(); -// } -// }); + mText = (TextView) view.findViewById(R.id.decrypt_text_plaintext); + mShareButton = view.findViewById(R.id.action_decrypt_share_plaintext); + mCopyButton = view.findViewById(R.id.action_decrypt_copy_plaintext); + mShareButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(sendWithChooserExcludingEncrypt(mText.getText().toString())); + } + }); + mCopyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + copyToClipboard(mText.getText().toString()); + } + }); return view; } + /** + * Create Intent Chooser but exclude OK's EncryptActivity. + */ + private Intent sendWithChooserExcludingEncrypt(String text) { + Intent prototype = createSendIntent(text); + String title = getString(R.string.title_share_file); + + // we don't want to encrypt the encrypted, no inception ;) + String[] blacklist = new String[]{ + Constants.PACKAGE_NAME + ".ui.DecryptTextActivity", + "org.thialfihar.android.apg.ui.DecryptActivity" + }; + + return new ShareHelper(getActivity()).createChooserExcluding(prototype, title, blacklist); + } + + private Intent createSendIntent(String text) { + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, text); + sendIntent.setType("text/plain"); + return sendIntent; + } + + private void copyToClipboard(String text) { + ClipboardReflection.copyToClipboard(getActivity(), text); + Notify.showNotify(getActivity(), R.string.text_copied_to_clipboard, Notify.Style.INFO); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -132,10 +164,10 @@ public class DecryptTextFragment extends DecryptFragment { if (pgpResult.isPending()) { if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) == DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) { - showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded()); + startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded()); } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) == DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) { - showPassphraseDialog(Constants.key.symmetric); + startPassphraseDialog(Constants.key.symmetric); } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) == DecryptVerifyResult.RESULT_PENDING_NFC) { // TODO @@ -146,8 +178,8 @@ public class DecryptTextFragment extends DecryptFragment { byte[] decryptedMessage = returnData .getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); - mMessage.setText(new String(decryptedMessage)); - mMessage.setHorizontallyScrolling(false); + mText.setText(new String(decryptedMessage)); + mText.setHorizontallyScrolling(false); pgpResult.createNotify(getActivity()).show(); @@ -171,4 +203,37 @@ public class DecryptTextFragment extends DecryptFragment { getActivity().startService(intent); } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + + case REQUEST_CODE_PASSPHRASE: { + if (resultCode == Activity.RESULT_OK && data != null) { + String passphrase = data.getStringExtra(PassphraseDialogActivity.MESSAGE_DATA_PASSPHRASE); + decryptStart(passphrase); + return; + } else { + getActivity().finish(); + } + break; + } + + case REQUEST_CODE_NFC: { + if (resultCode == Activity.RESULT_OK && data != null) { + // TODO + return; + } else { + getActivity().finish(); + } + break; + } + + default: { + super.onActivityResult(requestCode, resultCode, data); + + break; + } + } + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java index 836e7e268..0691e7a30 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java @@ -10,15 +10,8 @@ public class EncryptActivity extends DrawerActivity { public static final int REQUEST_CODE_NFC = 0x00008002; protected void startPassphraseDialog(long subkeyId) { - Intent data = new Intent(); - - // build PendingIntent for Yubikey NFC operations Intent intent = new Intent(this, PassphraseDialogActivity.class); - // pass params through to activity that it can be returned again later to repeat pgp operation intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId); - -// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivityForResult(intent, REQUEST_CODE_PASSPHRASE); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java index a508472d6..54877f676 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java @@ -135,7 +135,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi try { CachedPublicKeyRing keyring = mProviderHelper.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingUri(signatureKey)); - if(keyring.hasAnySecret()) { + if (keyring.hasAnySecret()) { setSignatureKeyId(keyring.getMasterKeyId()); mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey()); } diff --git a/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml b/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml index f6cc892d7..1c6097495 100644 --- a/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml +++ b/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml @@ -43,7 +43,7 @@ <LinearLayout - android:id="@+id/action_encrypt_share_plaintext" + android:id="@+id/action_decrypt_share_plaintext" android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true" @@ -57,7 +57,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" - android:text="Share plaintext" + android:text="@string/btn_add_share_decrypted_text" android:drawableRight="@drawable/ic_action_share" android:drawablePadding="8dp" android:gravity="center_vertical" @@ -72,7 +72,7 @@ android:background="?android:attr/listDivider" /> <ImageButton - android:id="@+id/action_copy_plaintext" + android:id="@+id/action_decrypt_copy_plaintext" android:layout_width="wrap_content" android:layout_height="match_parent" android:padding="8dp" diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index c2750df7f..36364853d 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -70,6 +70,7 @@ <string name="btn_view_cert_key">"View certification key"</string> <string name="btn_create_key">"Create key"</string> <string name="btn_add_files">"Add file(s)"</string> + <string name="btn_add_share_decrypted_text">"Share decrypted text"</string> <!-- menu --> <string name="menu_preferences">"Settings"</string> @@ -225,6 +226,7 @@ <string name="fingerprint_copied_to_clipboard">"Fingerprint has been copied to the clipboard!"</string> <string name="select_key_to_certify">"Please select a key to be used for certification!"</string> <string name="key_too_big_for_sharing">"Key is too big to be shared this way!"</string> + <string name="text_copied_to_clipboard">"Text has been copied to the clipboard!"</string> <!-- errors |