diff options
author | Thialfihar <thialfihar@gmail.com> | 2010-05-09 13:29:30 +0000 |
---|---|---|
committer | Thialfihar <thialfihar@gmail.com> | 2010-05-09 13:29:30 +0000 |
commit | 73888622f4d4d73c80cf877444dade3cf9470831 (patch) | |
tree | ff9cf653f1e7962e033b09c385768b7dcce5ef58 | |
parent | 2e1aad0f81c1511c741b391b4d8254f92ba56271 (diff) | |
download | open-keychain-73888622f4d4d73c80cf877444dade3cf9470831.tar.gz open-keychain-73888622f4d4d73c80cf877444dade3cf9470831.tar.bz2 open-keychain-73888622f4d4d73c80cf877444dade3cf9470831.zip |
added a button to encrypt to clipboard, change log and about window got their own layout now with proper linkification
-rw-r--r-- | res/layout/encrypt_message.xml | 12 | ||||
-rw-r--r-- | res/layout/info.xml | 15 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/DecryptFileActivity.java | 2 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/DecryptMessageActivity.java | 3 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/EncryptMessageActivity.java | 63 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/Id.java | 5 | ||||
-rw-r--r-- | src/org/thialfihar/android/apg/MainActivity.java | 84 |
8 files changed, 122 insertions, 65 deletions
diff --git a/res/layout/encrypt_message.xml b/res/layout/encrypt_message.xml index 3f0b7c2d6..4fc804dda 100644 --- a/res/layout/encrypt_message.xml +++ b/res/layout/encrypt_message.xml @@ -107,10 +107,18 @@ style="@android:style/ButtonBar"> <Button + android:id="@+id/btn_encrypt_to_clipboard" + android:text="@string/btn_encrypt_to_clipboard" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1"/> + + <Button android:id="@+id/btn_send" android:text="@string/btn_send" - android:layout_width="fill_parent" - android:layout_height="wrap_content"/> + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1"/> </LinearLayout> diff --git a/res/layout/info.xml b/res/layout/info.xml new file mode 100644 index 000000000..ab9e99a5b --- /dev/null +++ b/res/layout/info.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<ScrollView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:fillViewport="true" + android:padding="5dip"> + + <TextView + android:id="@+id/message" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:textColor="#ffffffff" + android:autoLink="all"/> +</ScrollView> diff --git a/res/values/strings.xml b/res/values/strings.xml index ab5b08ab6..d8365f2e6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -33,7 +33,8 @@ <string name="section_userIds">User IDs</string> <string name="section_keys">Keys</string> - <string name="btn_send">Send via Email</string> + <string name="btn_encrypt_to_clipboard">Encrypt To Clipboard</string> + <string name="btn_send">Encrypt And Email</string> <string name="btn_encrypt">Encrypt</string> <string name="btn_decrypt">Decrypt</string> <string name="btn_verify">Verify</string> 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, |