Implement buttons in DecryptTextFragment

This commit is contained in:
Dominik Schürmann 2014-09-23 23:38:30 +02:00
parent b9347ea9aa
commit 0143b54e9e
7 changed files with 157 additions and 70 deletions

View File

@ -208,10 +208,10 @@ public class DecryptFilesFragment extends DecryptFragment {
if (pgpResult.isPending()) { if (pgpResult.isPending()) {
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) == if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
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) == } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
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) == } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
DecryptVerifyResult.RESULT_PENDING_NFC) { DecryptVerifyResult.RESULT_PENDING_NFC) {
// TODO // TODO
@ -296,10 +296,10 @@ public class DecryptFilesFragment extends DecryptFragment {
if (pgpResult.isPending()) { if (pgpResult.isPending()) {
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) == if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
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) == } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
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) == } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
DecryptVerifyResult.RESULT_PENDING_NFC) { DecryptVerifyResult.RESULT_PENDING_NFC) {
// TODO // TODO

View File

@ -33,6 +33,7 @@ import android.widget.TextView;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.nfc.NfcActivity;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
@ -81,25 +82,51 @@ public abstract class DecryptFragment extends Fragment {
startActivityForResult(intent, RESULT_CODE_LOOKUP_KEY); startActivityForResult(intent, RESULT_CODE_LOOKUP_KEY);
} }
@Override public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
public void onActivityResult(int requestCode, int resultCode, Intent data) { public static final int REQUEST_CODE_NFC = 0x00008002;
switch (requestCode) {
case RESULT_CODE_LOOKUP_KEY: { protected void startPassphraseDialog(long subkeyId) {
if (resultCode == Activity.RESULT_OK) { Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
// TODO: generate new OpenPgpSignatureResult and display it intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
} startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
return;
} }
default: { protected void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) {
super.onActivityResult(requestCode, resultCode, data); 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) { protected void onResult(DecryptVerifyResult decryptVerifyResult) {
OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult();
@ -197,20 +224,20 @@ public abstract class DecryptFragment extends Fragment {
} }
} }
protected void showPassphraseDialog(long keyId) { // protected void showPassphraseDialog(long keyId) {
PassphraseDialogFragment.show(getActivity(), keyId, // PassphraseDialogFragment.show(getActivity(), keyId,
new Handler() { // new Handler() {
@Override // @Override
public void handleMessage(Message message) { // public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { // if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
String passphrase = // String passphrase =
message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE); // message.getData().getString(PassphraseDialogFragment.MESSAGE_DATA_PASSPHRASE);
decryptStart(passphrase); // decryptStart(passphrase);
} // }
} // }
} // }
); // );
} // }
/** /**
* Should be overridden by MessageFragment and FileFragment to start actual decryption * Should be overridden by MessageFragment and FileFragment to start actual decryption

View File

@ -17,6 +17,7 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
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.Bundle;
@ -29,20 +30,23 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; 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.Log;
import org.sufficientlysecure.keychain.util.ShareHelper;
public class DecryptTextFragment extends DecryptFragment { public class DecryptTextFragment extends DecryptFragment {
public static final String ARG_CIPHERTEXT = "ciphertext"; public static final String ARG_CIPHERTEXT = "ciphertext";
// // view // view
private TextView mMessage; private TextView mText;
// private View mDecryptButton; private View mShareButton;
// private View mDecryptFromCLipboardButton; private View mCopyButton;
//
// // model // model
private String mCiphertext; private String mCiphertext;
/** /**
@ -66,25 +70,53 @@ public class DecryptTextFragment extends DecryptFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.decrypt_text_fragment, container, false); View view = inflater.inflate(R.layout.decrypt_text_fragment, container, false);
mMessage = (TextView) view.findViewById(R.id.decrypt_text_plaintext); mText = (TextView) view.findViewById(R.id.decrypt_text_plaintext);
// mDecryptButton = view.findViewById(R.id.action_decrypt); mShareButton = view.findViewById(R.id.action_decrypt_share_plaintext);
// mDecryptFromCLipboardButton = view.findViewById(R.id.action_decrypt_from_clipboard); mCopyButton = view.findViewById(R.id.action_decrypt_copy_plaintext);
// mDecryptButton.setOnClickListener(new OnClickListener() { mShareButton.setOnClickListener(new View.OnClickListener() {
// @Override @Override
// public void onClick(View v) { public void onClick(View v) {
// decryptClicked(); startActivity(sendWithChooserExcludingEncrypt(mText.getText().toString()));
// } }
// }); });
// mDecryptFromCLipboardButton.setOnClickListener(new OnClickListener() { mCopyButton.setOnClickListener(new View.OnClickListener() {
// @Override @Override
// public void onClick(View v) { public void onClick(View v) {
// decryptFromClipboardClicked(); copyToClipboard(mText.getText().toString());
// } }
// }); });
return view; 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 @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -132,10 +164,10 @@ public class DecryptTextFragment extends DecryptFragment {
if (pgpResult.isPending()) { if (pgpResult.isPending()) {
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) == if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
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) == } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
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) == } else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
DecryptVerifyResult.RESULT_PENDING_NFC) { DecryptVerifyResult.RESULT_PENDING_NFC) {
// TODO // TODO
@ -146,8 +178,8 @@ public class DecryptTextFragment extends DecryptFragment {
byte[] decryptedMessage = returnData byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); .getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
mMessage.setText(new String(decryptedMessage)); mText.setText(new String(decryptedMessage));
mMessage.setHorizontallyScrolling(false); mText.setHorizontallyScrolling(false);
pgpResult.createNotify(getActivity()).show(); pgpResult.createNotify(getActivity()).show();
@ -171,4 +203,37 @@ public class DecryptTextFragment extends DecryptFragment {
getActivity().startService(intent); 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;
}
}
}
} }

View File

@ -10,15 +10,8 @@ public class EncryptActivity extends DrawerActivity {
public static final int REQUEST_CODE_NFC = 0x00008002; public static final int REQUEST_CODE_NFC = 0x00008002;
protected void startPassphraseDialog(long subkeyId) { protected void startPassphraseDialog(long subkeyId) {
Intent data = new Intent();
// build PendingIntent for Yubikey NFC operations
Intent intent = new Intent(this, PassphraseDialogActivity.class); 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.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE); startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
} }

View File

@ -135,7 +135,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
try { try {
CachedPublicKeyRing keyring = mProviderHelper.getCachedPublicKeyRing( CachedPublicKeyRing keyring = mProviderHelper.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingUri(signatureKey)); KeyRings.buildUnifiedKeyRingUri(signatureKey));
if(keyring.hasAnySecret()) { if (keyring.hasAnySecret()) {
setSignatureKeyId(keyring.getMasterKeyId()); setSignatureKeyId(keyring.getMasterKeyId());
mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey()); mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
} }

View File

@ -43,7 +43,7 @@
<LinearLayout <LinearLayout
android:id="@+id/action_encrypt_share_plaintext" android:id="@+id/action_decrypt_share_plaintext"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:clickable="true"
@ -57,7 +57,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight" android:minHeight="?android:attr/listPreferredItemHeight"
android:text="Share plaintext" android:text="@string/btn_add_share_decrypted_text"
android:drawableRight="@drawable/ic_action_share" android:drawableRight="@drawable/ic_action_share"
android:drawablePadding="8dp" android:drawablePadding="8dp"
android:gravity="center_vertical" android:gravity="center_vertical"
@ -72,7 +72,7 @@
android:background="?android:attr/listDivider" /> android:background="?android:attr/listDivider" />
<ImageButton <ImageButton
android:id="@+id/action_copy_plaintext" android:id="@+id/action_decrypt_copy_plaintext"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="8dp" android:padding="8dp"

View File

@ -70,6 +70,7 @@
<string name="btn_view_cert_key">"View certification key"</string> <string name="btn_view_cert_key">"View certification key"</string>
<string name="btn_create_key">"Create key"</string> <string name="btn_create_key">"Create key"</string>
<string name="btn_add_files">"Add file(s)"</string> <string name="btn_add_files">"Add file(s)"</string>
<string name="btn_add_share_decrypted_text">"Share decrypted text"</string>
<!-- menu --> <!-- menu -->
<string name="menu_preferences">"Settings"</string> <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="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="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="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 errors