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

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

View File

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

View File

@ -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();

View File

@ -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);
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;
}
}
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 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.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);
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);
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);
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,