added a button to encrypt to clipboard, change log and about window got their own layout now with proper linkification

This commit is contained in:
Thialfihar 2010-05-09 13:29:30 +00:00
parent 2e1aad0f81
commit 73888622f4
8 changed files with 120 additions and 63 deletions

View file

@ -106,11 +106,19 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@android:style/ButtonBar"> 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 <Button
android:id="@+id/btn_send" android:id="@+id/btn_send"
android:text="@string/btn_send" android:text="@string/btn_send"
android:layout_width="fill_parent" android:layout_width="0dip"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout> </LinearLayout>

15
res/layout/info.xml Normal file
View file

@ -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>

View file

@ -33,7 +33,8 @@
<string name="section_userIds">User IDs</string> <string name="section_userIds">User IDs</string>
<string name="section_keys">Keys</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_encrypt">Encrypt</string>
<string name="btn_decrypt">Decrypt</string> <string name="btn_decrypt">Decrypt</string>
<string name="btn_verify">Verify</string> <string name="btn_verify">Verify</string>

View file

@ -141,7 +141,7 @@ public class DecryptFileActivity extends BaseActivity {
try { try {
setSecretKeyId(Apg.getDecryptionKeyId(in)); setSecretKeyId(Apg.getDecryptionKeyId(in));
if (getSecretKeyId() == 0) { if (getSecretKeyId() == 0) {
throw new Apg.GeneralException("no suitable keys found"); throw new Apg.GeneralException("no suitable secret key found");
} }
mAssumeSymmetricEncryption = false; mAssumeSymmetricEncryption = false;
} catch (Apg.NoAsymmetricEncryptionException e) { } catch (Apg.NoAsymmetricEncryptionException e) {

View file

@ -150,6 +150,9 @@ public class DecryptMessageActivity extends BaseActivity {
try { try {
ByteArrayInputStream in = new ByteArrayInputStream(messageData.getBytes()); ByteArrayInputStream in = new ByteArrayInputStream(messageData.getBytes());
setSecretKeyId(Apg.getDecryptionKeyId(in)); setSecretKeyId(Apg.getDecryptionKeyId(in));
if (getSecretKeyId() == 0) {
throw new Apg.GeneralException("no suitable secret key found");
}
showDialog(Id.dialog.pass_phrase); showDialog(Id.dialog.pass_phrase);
} catch (IOException e) { } catch (IOException e) {
error = e.getLocalizedMessage(); error = e.getLocalizedMessage();

View file

@ -34,6 +34,7 @@ import org.bouncycastle2.util.Strings;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.text.ClipboardManager;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
@ -50,11 +51,14 @@ public class EncryptMessageActivity extends BaseActivity {
private EditText mMessage = null; private EditText mMessage = null;
private Button mSelectKeysButton = null; private Button mSelectKeysButton = null;
private Button mEncryptButton = null;
private Button mSendButton = null; private Button mSendButton = null;
private CheckBox mSign = null; private CheckBox mSign = null;
private TextView mMainUserId = null; private TextView mMainUserId = null;
private TextView mMainUserIdRest = null; private TextView mMainUserIdRest = null;
private int mEncryptTarget;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -62,6 +66,7 @@ public class EncryptMessageActivity extends BaseActivity {
mMessage = (EditText) findViewById(R.id.message); mMessage = (EditText) findViewById(R.id.message);
mSelectKeysButton = (Button) findViewById(R.id.btn_selectEncryptKeys); mSelectKeysButton = (Button) findViewById(R.id.btn_selectEncryptKeys);
mEncryptButton = (Button) findViewById(R.id.btn_encrypt_to_clipboard);
mSendButton = (Button) findViewById(R.id.btn_send); mSendButton = (Button) findViewById(R.id.btn_send);
mSign = (CheckBox) findViewById(R.id.sign); mSign = (CheckBox) findViewById(R.id.sign);
mMainUserId = (TextView) findViewById(R.id.main_user_id); 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() { mSendButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -150,7 +162,17 @@ public class EncryptMessageActivity extends BaseActivity {
updateView(); updateView();
} }
private void encryptClicked() {
mEncryptTarget = Id.target.clipboard;
if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) {
showDialog(Id.dialog.pass_phrase);
} else {
encryptStart();
}
}
private void sendClicked() { private void sendClicked() {
mEncryptTarget = Id.target.email;
if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) { if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) {
showDialog(Id.dialog.pass_phrase); showDialog(Id.dialog.pass_phrase);
} else { } else {
@ -322,19 +344,36 @@ public class EncryptMessageActivity extends BaseActivity {
return; return;
} else { } else {
String message = data.getString("message"); String message = data.getString("message");
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); switch (mEncryptTarget) {
emailIntent.setType("text/plain; charset=utf-8"); case Id.target.clipboard: {
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (mSubject != null) { clip.setText(message);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, Toast.makeText(this, "Successfully encrypted to clipboard.",
mSubject); 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;
}
} }
if (mSendTo != null) {
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { mSendTo });
}
EncryptMessageActivity.this.
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} }
} }
} }

View file

@ -103,4 +103,9 @@ public final class Id {
public static final int no_master_key = -2; public static final int no_master_key = -2;
public static final int updated = 1; public static final int updated = 1;
} }
public static final class target {
public static final int clipboard = 0x21070001;
public static final int email = 0x21070002;
}
} }

View file

@ -24,6 +24,7 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList;
import android.database.Cursor; import android.database.Cursor;
import android.database.SQLException; import android.database.SQLException;
import android.net.Uri; import android.net.Uri;
@ -175,31 +176,19 @@ public class MainActivity extends BaseActivity {
AlertDialog.Builder alert = new AlertDialog.Builder(this); AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("About " + Apg.FULL_VERSION); alert.setTitle("About " + Apg.FULL_VERSION);
ScrollView scrollView = new ScrollView(this);
TextView message = new TextView(this);
SpannableString info = LayoutInflater inflater =
new SpannableString("This is an attempt to bring OpenPGP to Android. " + (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
"It is far from complete, but more features are " + View layout = inflater.inflate(R.layout.info, null);
"planned (see website).\n" + TextView message = (TextView) layout.findViewById(R.id.message);
"\n" + message.setText("This is an attempt to bring OpenPGP to Android. " +
"Feel free to send bug reports, suggestions, feature " + "It is far from complete, but more features are planned (see website).\n\n" +
"requests, feedback, photographs.\n" + "Feel free to send bug reports, suggestions, feature requests, feedback, " +
"\n" + "photographs.\n\n" +
"mail: thi@thialfihar.org\n" + "mail: thi@thialfihar.org\n" +
"site: http://apg.thialfihar.org\n" + "site: http://apg.thialfihar.org\n\n" +
"\n" + "This software is provided \"as is\", without warranty of any kind.");
"This software is provided \"as is\", without " + alert.setView(layout);
"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);
alert.setPositiveButton(android.R.string.ok, alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@ -215,30 +204,27 @@ public class MainActivity extends BaseActivity {
AlertDialog.Builder alert = new AlertDialog.Builder(this); AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Changes " + Apg.FULL_VERSION); alert.setTitle("Changes " + Apg.FULL_VERSION);
ScrollView scrollView = new ScrollView(this); LayoutInflater inflater =
TextView message = new TextView(this); (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.info, null);
TextView message = (TextView) layout.findViewById(R.id.message);
SpannableString info = message.setText("Read the warnings!\n\n" +
new SpannableString("Read the warnings!\n\n" + "Changes:\n" +
"Changes:\n" + "* encrypt to clipboard\n" +
"\n" + "\n" +
"WARNING: be careful editing your existing keys, as they " + "WARNING: be careful editing your existing keys, as they " +
"WILL be stripped of certificates right now.\n" + "WILL be stripped of certificates right now.\n" +
"WARNING: key creation/editing doesn't support all " + "\n" +
"GPG features yet. In particular: " + "WARNING: key creation/editing doesn't support all " +
"key cross-certification is NOT supported, so signing " + "GPG features yet. In particular: " +
"with those keys will get a warning when the signature is " + "key cross-certification is NOT supported, so signing " +
"checked.\n" + "with those keys will get a warning when the signature is " +
"\n" + "checked.\n" +
"I hope APG continues to be useful to you, please send " + "\n" +
"bug reports, feature wishes, feedback."); "I hope APG continues to be useful to you, please send " +
message.setText(info); "bug reports, feature wishes, feedback.");
// 5dip padding alert.setView(layout);
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);
alert.setCancelable(false); alert.setCancelable(false);
alert.setPositiveButton(android.R.string.ok, alert.setPositiveButton(android.R.string.ok,