diff options
Diffstat (limited to 'src')
5 files changed, 95 insertions, 62 deletions
diff --git a/src/org/thialfihar/android/apg/DecryptFileActivity.java b/src/org/thialfihar/android/apg/DecryptFileActivity.java index 0f8248be8..f8eeed57a 100644 --- a/src/org/thialfihar/android/apg/DecryptFileActivity.java +++ b/src/org/thialfihar/android/apg/DecryptFileActivity.java @@ -141,7 +141,7 @@ public class DecryptFileActivity extends BaseActivity { try {
setSecretKeyId(Apg.getDecryptionKeyId(in));
if (getSecretKeyId() == 0) {
- throw new Apg.GeneralException("no suitable keys found");
+ throw new Apg.GeneralException("no suitable secret key found");
}
mAssumeSymmetricEncryption = false;
} catch (Apg.NoAsymmetricEncryptionException e) {
diff --git a/src/org/thialfihar/android/apg/DecryptMessageActivity.java b/src/org/thialfihar/android/apg/DecryptMessageActivity.java index 76589016f..ea9e960e4 100644 --- a/src/org/thialfihar/android/apg/DecryptMessageActivity.java +++ b/src/org/thialfihar/android/apg/DecryptMessageActivity.java @@ -150,6 +150,9 @@ public class DecryptMessageActivity extends BaseActivity { try { ByteArrayInputStream in = new ByteArrayInputStream(messageData.getBytes()); setSecretKeyId(Apg.getDecryptionKeyId(in)); + if (getSecretKeyId() == 0) { + throw new Apg.GeneralException("no suitable secret key found"); + } showDialog(Id.dialog.pass_phrase); } catch (IOException e) { error = e.getLocalizedMessage(); diff --git a/src/org/thialfihar/android/apg/EncryptMessageActivity.java b/src/org/thialfihar/android/apg/EncryptMessageActivity.java index 6e88253a1..3e49d7c50 100644 --- a/src/org/thialfihar/android/apg/EncryptMessageActivity.java +++ b/src/org/thialfihar/android/apg/EncryptMessageActivity.java @@ -34,6 +34,7 @@ import org.bouncycastle2.util.Strings; import android.content.Intent; import android.os.Bundle; import android.os.Message; +import android.text.ClipboardManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -50,11 +51,14 @@ public class EncryptMessageActivity extends BaseActivity { private EditText mMessage = null; private Button mSelectKeysButton = null; + private Button mEncryptButton = null; private Button mSendButton = null; private CheckBox mSign = null; private TextView mMainUserId = null; private TextView mMainUserIdRest = null; + private int mEncryptTarget; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -62,6 +66,7 @@ public class EncryptMessageActivity extends BaseActivity { mMessage = (EditText) findViewById(R.id.message); mSelectKeysButton = (Button) findViewById(R.id.btn_selectEncryptKeys); + mEncryptButton = (Button) findViewById(R.id.btn_encrypt_to_clipboard); mSendButton = (Button) findViewById(R.id.btn_send); mSign = (CheckBox) findViewById(R.id.sign); mMainUserId = (TextView) findViewById(R.id.main_user_id); @@ -119,6 +124,13 @@ public class EncryptMessageActivity extends BaseActivity { } } + mEncryptButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + encryptClicked(); + } + }); + mSendButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -150,7 +162,17 @@ public class EncryptMessageActivity extends BaseActivity { updateView(); } + private void encryptClicked() { + mEncryptTarget = Id.target.clipboard; + if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) { + showDialog(Id.dialog.pass_phrase); + } else { + encryptStart(); + } + } + private void sendClicked() { + mEncryptTarget = Id.target.email; if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) { showDialog(Id.dialog.pass_phrase); } else { @@ -322,19 +344,36 @@ public class EncryptMessageActivity extends BaseActivity { return; } else { String message = data.getString("message"); - Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); - emailIntent.setType("text/plain; charset=utf-8"); - emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); - if (mSubject != null) { - emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, - mSubject); - } - if (mSendTo != null) { - emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, - new String[] { mSendTo }); + switch (mEncryptTarget) { + case Id.target.clipboard: { + ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + clip.setText(message); + Toast.makeText(this, "Successfully encrypted to clipboard.", + Toast.LENGTH_SHORT).show(); + break; + } + + case Id.target.email: { + Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); + emailIntent.setType("text/plain; charset=utf-8"); + emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); + if (mSubject != null) { + emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, + mSubject); + } + if (mSendTo != null) { + emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, + new String[] { mSendTo }); + } + EncryptMessageActivity.this. + startActivity(Intent.createChooser(emailIntent, "Send mail...")); + } + + default: { + // shouldn't happen + break; + } } - EncryptMessageActivity.this. - startActivity(Intent.createChooser(emailIntent, "Send mail...")); } } }
\ No newline at end of file diff --git a/src/org/thialfihar/android/apg/Id.java b/src/org/thialfihar/android/apg/Id.java index 7b0957050..88a6b2988 100644 --- a/src/org/thialfihar/android/apg/Id.java +++ b/src/org/thialfihar/android/apg/Id.java @@ -103,4 +103,9 @@ public final class Id { public static final int no_master_key = -2;
public static final int updated = 1;
}
+
+ public static final class target {
+ public static final int clipboard = 0x21070001;
+ public static final int email = 0x21070002;
+ }
}
diff --git a/src/org/thialfihar/android/apg/MainActivity.java b/src/org/thialfihar/android/apg/MainActivity.java index 9b1f7afa4..3a2493315 100644 --- a/src/org/thialfihar/android/apg/MainActivity.java +++ b/src/org/thialfihar/android/apg/MainActivity.java @@ -24,6 +24,7 @@ import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.res.ColorStateList; import android.database.Cursor; import android.database.SQLException; import android.net.Uri; @@ -175,31 +176,19 @@ public class MainActivity extends BaseActivity { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("About " + Apg.FULL_VERSION); - ScrollView scrollView = new ScrollView(this); - TextView message = new TextView(this); - - SpannableString info = - new SpannableString("This is an attempt to bring OpenPGP to Android. " + - "It is far from complete, but more features are " + - "planned (see website).\n" + - "\n" + - "Feel free to send bug reports, suggestions, feature " + - "requests, feedback, photographs.\n" + - "\n" + - "mail: thi@thialfihar.org\n" + - "site: http://apg.thialfihar.org\n" + - "\n" + - "This software is provided \"as is\", without " + - "warranty of any kind."); - Linkify.addLinks(info, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES); - message.setMovementMethod(LinkMovementMethod.getInstance()); - message.setText(info); - // 5dip padding - int padding = (int) (10 * getResources().getDisplayMetrics().densityDpi / 160); - message.setPadding(padding, padding, padding, padding); - message.setTextAppearance(this, android.R.style.TextAppearance_Medium); - scrollView.addView(message); - alert.setView(scrollView); + + LayoutInflater inflater = + (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View layout = inflater.inflate(R.layout.info, null); + TextView message = (TextView) layout.findViewById(R.id.message); + message.setText("This is an attempt to bring OpenPGP to Android. " + + "It is far from complete, but more features are planned (see website).\n\n" + + "Feel free to send bug reports, suggestions, feature requests, feedback, " + + "photographs.\n\n" + + "mail: thi@thialfihar.org\n" + + "site: http://apg.thialfihar.org\n\n" + + "This software is provided \"as is\", without warranty of any kind."); + alert.setView(layout); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -215,30 +204,27 @@ public class MainActivity extends BaseActivity { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Changes " + Apg.FULL_VERSION); - ScrollView scrollView = new ScrollView(this); - TextView message = new TextView(this); - - SpannableString info = - new SpannableString("Read the warnings!\n\n" + - "Changes:\n" + - "\n" + - "WARNING: be careful editing your existing keys, as they " + - "WILL be stripped of certificates right now.\n" + - "WARNING: key creation/editing doesn't support all " + - "GPG features yet. In particular: " + - "key cross-certification is NOT supported, so signing " + - "with those keys will get a warning when the signature is " + - "checked.\n" + - "\n" + - "I hope APG continues to be useful to you, please send " + - "bug reports, feature wishes, feedback."); - message.setText(info); - // 5dip padding - int padding = (int) (10 * getResources().getDisplayMetrics().densityDpi / 160); - message.setPadding(padding, padding, padding, padding); - message.setTextAppearance(this, android.R.style.TextAppearance_Medium); - scrollView.addView(message); - alert.setView(scrollView); + LayoutInflater inflater = + (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View layout = inflater.inflate(R.layout.info, null); + TextView message = (TextView) layout.findViewById(R.id.message); + + message.setText("Read the warnings!\n\n" + + "Changes:\n" + + "* encrypt to clipboard\n" + + "\n" + + "WARNING: be careful editing your existing keys, as they " + + "WILL be stripped of certificates right now.\n" + + "\n" + + "WARNING: key creation/editing doesn't support all " + + "GPG features yet. In particular: " + + "key cross-certification is NOT supported, so signing " + + "with those keys will get a warning when the signature is " + + "checked.\n" + + "\n" + + "I hope APG continues to be useful to you, please send " + + "bug reports, feature wishes, feedback."); + alert.setView(layout); alert.setCancelable(false); alert.setPositiveButton(android.R.string.ok, |