intent to create a new key

This commit is contained in:
Dominik 2012-04-12 15:23:00 +02:00
parent dfa4e084dd
commit 1a33f4d886
17 changed files with 139 additions and 58 deletions

View File

@ -75,7 +75,13 @@
android:name=".ui.EditKeyActivity" android:name=".ui.EditKeyActivity"
android:configChanges="keyboardHidden|orientation|keyboard" android:configChanges="keyboardHidden|orientation|keyboard"
android:label="@string/title_editKey" android:label="@string/title_editKey"
android:uiOptions="splitActionBarWhenNarrow" /> android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter>
<action android:name="org.apg.intent.EDIT_KEY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity <activity
android:name=".ui.SelectPublicKeyListActivity" android:name=".ui.SelectPublicKeyListActivity"
android:configChanges="keyboardHidden|orientation|keyboard" android:configChanges="keyboardHidden|orientation|keyboard"

View File

@ -62,26 +62,4 @@
</ScrollView> </ScrollView>
<!-- <LinearLayout -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:orientation="horizontal" -->
<!-- style="@android:style/ButtonBar"> -->
<!-- <Button -->
<!-- android:id="@+id/btn_save" -->
<!-- android:layout_width="0dip" -->
<!-- android:layout_height="fill_parent" -->
<!-- android:layout_weight="1" -->
<!-- android:text="@string/btn_save"/> -->
<!-- <Button -->
<!-- android:id="@+id/btn_discard" -->
<!-- android:layout_width="0dip" -->
<!-- android:layout_height="fill_parent" -->
<!-- android:layout_weight="1" -->
<!-- android:text="@string/btn_doNotSave"/> -->
<!-- </LinearLayout> -->
</LinearLayout> </LinearLayout>

View File

@ -125,6 +125,7 @@ public class Apg {
public static final String GENERATE_SIGNATURE = "org.apg.intent.GENERATE_SIGNATURE"; public static final String GENERATE_SIGNATURE = "org.apg.intent.GENERATE_SIGNATURE";
public static final String EXPORT_KEY_TO_SERVER = "org.apg.intent.EXPORT_KEY_TO_SERVER"; public static final String EXPORT_KEY_TO_SERVER = "org.apg.intent.EXPORT_KEY_TO_SERVER";
public static final String IMPORT_FROM_QR_CODE = "org.apg.intent.IMPORT_FROM_QR_CODE"; public static final String IMPORT_FROM_QR_CODE = "org.apg.intent.IMPORT_FROM_QR_CODE";
public static final String EDIT_KEY = "org.apg.intent.EDIT_KEY";
} }
public static final String EXTRA_TEXT = "text"; public static final String EXTRA_TEXT = "text";
@ -153,7 +154,7 @@ public class Apg {
public static final String EXTRA_ASCII_ARMOUR = "asciiArmour"; public static final String EXTRA_ASCII_ARMOUR = "asciiArmour";
public static final String EXTRA_BINARY = "binary"; public static final String EXTRA_BINARY = "binary";
public static final String EXTRA_KEY_SERVERS = "keyServers"; public static final String EXTRA_KEY_SERVERS = "keyServers";
public static final String EXTRA_EXPECTED_FINGERPRINT = "org.apg.EXPECTED_FINGERPRINT"; public static final String EXTRA_EXPECTED_FINGERPRINT = "expectedFingerprint";
public static final String AUTHORITY = DataProvider.AUTHORITY; public static final String AUTHORITY = DataProvider.AUTHORITY;

View File

@ -31,6 +31,7 @@ import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPPublicKeyRing; import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.apg.R; import org.apg.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
@ -249,6 +250,12 @@ public class DecryptActivity extends BaseActivity {
Log.d(Constants.TAG, "got extras"); Log.d(Constants.TAG, "got extras");
} }
// disable home button on actionbar because this activity is run from another app
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
mData = extras.getByteArray(Apg.EXTRA_DATA); mData = extras.getByteArray(Apg.EXTRA_DATA);
String textData = null; String textData = null;
if (mData == null) { if (mData == null) {

View File

@ -28,6 +28,7 @@ import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.apg.R; import org.apg.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
@ -36,6 +37,7 @@ import android.app.Dialog;
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.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -53,6 +55,7 @@ import java.security.SignatureException;
import java.util.Vector; import java.util.Vector;
public class EditKeyActivity extends BaseActivity { public class EditKeyActivity extends BaseActivity {
private Intent mIntent = null;
private PGPSecretKeyRing mKeyRing = null; private PGPSecretKeyRing mKeyRing = null;
@ -66,12 +69,10 @@ public class EditKeyActivity extends BaseActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(1, Id.menu.option.cancel, 0, R.string.btn_doNotSave) menu.add(1, Id.menu.option.cancel, 0, R.string.btn_doNotSave).setShowAsAction(
// .setIcon(R.drawable.ic_menu_search_holo_light) MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menu.add(1, Id.menu.option.save, 1, R.string.btn_save).setShowAsAction(
menu.add(1, Id.menu.option.save, 1, R.string.btn_save) MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
// .setIcon(R.drawable.ic_suggestions_add)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true; return true;
} }
@ -128,6 +129,26 @@ public class EditKeyActivity extends BaseActivity {
} }
} }
// Catch Intents opened from other apps
mIntent = getIntent();
if (Apg.Intent.EDIT_KEY.equals(mIntent.getAction())) {
Bundle extras = mIntent.getExtras();
if (extras == null) {
extras = new Bundle();
}
// disable home button on actionbar because this activity is run from another app
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
// if userId is given, prefill the fields
if (extras.containsKey(Apg.EXTRA_USER_IDS)) {
userIds.add(extras.getString(Apg.EXTRA_USER_IDS));
}
}
mChangePassPhrase = (Button) findViewById(R.id.btn_change_pass_phrase); mChangePassPhrase = (Button) findViewById(R.id.btn_change_pass_phrase);
mChangePassPhrase.setOnClickListener(new OnClickListener() { mChangePassPhrase.setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
@ -135,12 +156,7 @@ public class EditKeyActivity extends BaseActivity {
} }
}); });
// mSaveButton = (Button) findViewById(R.id.btn_save); // Build layout based on given userIds and keys
// mDiscardButton = (Button) findViewById(R.id.btn_discard);
// mSaveButton.setOnClickListener(this);
// mDiscardButton.setOnClickListener(this);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout container = (LinearLayout) findViewById(R.id.container); LinearLayout container = (LinearLayout) findViewById(R.id.container);

View File

@ -33,6 +33,7 @@ import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.apg.R; import org.apg.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
@ -125,15 +126,12 @@ public class EncryptActivity extends BaseActivity {
if (mEncryptToClipboardEnabled) { if (mEncryptToClipboardEnabled) {
menu.add(1, Id.menu.option.encrypt_to_clipboard, 0, mEncryptToClipboardString) menu.add(1, Id.menu.option.encrypt_to_clipboard, 0, mEncryptToClipboardString)
// .setIcon(R.drawable.ic_menu_encrypt)
.setShowAsAction( .setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
} }
if (mEncryptEnabled) { if (mEncryptEnabled) {
menu.add(1, Id.menu.option.encrypt, 1, mEncryptString) menu.add(1, Id.menu.option.encrypt, 1, mEncryptString).setShowAsAction(
// .setIcon(R.drawable.ic_menu_decrypt) MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
} }
return true; return true;
@ -233,8 +231,6 @@ public class EncryptActivity 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);
// mEncryptToClipboardButton = (Button) findViewById(R.id.btn_encryptToClipboard);
mSign = (CheckBox) findViewById(R.id.sign); mSign = (CheckBox) findViewById(R.id.sign);
mMainUserId = (TextView) findViewById(R.id.mainUserId); mMainUserId = (TextView) findViewById(R.id.mainUserId);
mMainUserIdRest = (TextView) findViewById(R.id.mainUserIdRest); mMainUserIdRest = (TextView) findViewById(R.id.mainUserIdRest);
@ -317,6 +313,12 @@ public class EncryptActivity extends BaseActivity {
extras = new Bundle(); extras = new Bundle();
} }
// disable home button on actionbar because this activity is run from another app
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
if (Apg.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction()) if (Apg.Intent.ENCRYPT_AND_RETURN.equals(mIntent.getAction())
|| Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) { || Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
mReturnResult = true; mReturnResult = true;
@ -483,8 +485,6 @@ public class EncryptActivity extends BaseActivity {
mEncryptEnabled = true; mEncryptEnabled = true;
mEncryptToClipboardEnabled = false; mEncryptToClipboardEnabled = false;
// mEncryptToClipboardButton.setVisibility(View.INVISIBLE);
// mEncryptButton.setText(R.string.btn_encrypt);
break; break;
} }

View File

@ -21,6 +21,7 @@ import java.util.Vector;
import org.apg.Apg; import org.apg.Apg;
import org.apg.Id; import org.apg.Id;
import org.apg.R; import org.apg.R;
import org.apg.ui.widget.SelectPublicKeyListAdapter;
import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;

View File

@ -19,6 +19,7 @@ package org.apg.ui;
import org.apg.Apg; import org.apg.Apg;
import org.apg.Id; import org.apg.Id;
import org.apg.R; import org.apg.R;
import org.apg.ui.widget.SelectSecretKeyListAdapter;
import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apg.ui; package org.apg.ui.widget;
import java.util.Date; import java.util.Date;

View File

@ -12,7 +12,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apg.ui; package org.apg.ui.widget;
import java.util.Date; import java.util.Date;

View File

@ -40,9 +40,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
private EditText mEmail; private EditText mEmail;
private EditText mComment; private EditText mComment;
private static final Pattern EMAIL_PATTERN = Pattern.compile( // see http://www.regular-expressions.info/email.html
"^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+[.]([a-zA-Z])+([a-zA-Z])+", // RFC 2822 if we omit the syntax using double quotes and square brackets
Pattern.CASE_INSENSITIVE); private static final Pattern EMAIL_PATTERN = Pattern
.compile(
"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
Pattern.CASE_INSENSITIVE);
public static class NoNameException extends Exception { public static class NoNameException extends Exception {
static final long serialVersionUID = 0xf812773343L; static final long serialVersionUID = 0xf812773343L;

View File

@ -9,3 +9,4 @@
# Project target. # Project target.
target=android-15 target=android-15
android.library.reference.1=../org_apg_integration_lib

View File

@ -7,6 +7,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
<Button
android:id="@+id/intent_demo_create_new_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="intentDemoCreateNewKeyOnClick"
android:text="Create new key" />
<Button <Button
android:id="@+id/intent_demo_select_secret_key" android:id="@+id/intent_demo_select_secret_key"

View File

@ -54,6 +54,11 @@ public class IntentDemoActivity extends Activity {
mApgData = new ApgData(); mApgData = new ApgData();
} }
public void intentDemoCreateNewKeyOnClick(View view) {
// mApgIntentHelper.createNewKey();
mApgIntentHelper.createNewKey("dom <+491716581452@cryptocall.org>");
}
public void intentDemoSelectSecretKeyOnClick(View view) { public void intentDemoSelectSecretKeyOnClick(View view) {
mApgIntentHelper.selectSecretKey(); mApgIntentHelper.selectSecretKey();
} }

View File

@ -36,11 +36,59 @@ public class ApgIntentHelper {
} }
/** /**
* Select the signature key. * Opens APG activity to create new key
* *
* @param activity * @param userIds
* @param pgpData * value to specify prefilled values for user that should be created
* @return success or failure * @return true when user presses save, false when user presses cancel
*/
public boolean createNewKey(String userIds) {
Intent intent = new Intent(Constants.Intent.EDIT_KEY);
if (userIds != null) {
intent.putExtra(Constants.EXTRA_USER_IDS, userIds);
}
intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION);
try {
activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY);
return true;
} catch (ActivityNotFoundException e) {
activityNotFound();
return false;
}
}
/**
* Opens APG activity to create new key
*
* @return true when user presses save, false when user presses cancel
*/
public boolean createNewKey() {
return createNewKey(null);
}
/**
* Opens APG activity to edit already existing key based on keyId
*
* @param keyId
* @return true when user presses save, false when user presses cancel
*/
public boolean editKey(long keyId) {
Intent intent = new Intent(Constants.Intent.EDIT_KEY);
intent.putExtra(Constants.EXTRA_KEY_ID, keyId);
intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION);
try {
activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY);
return true;
} catch (ActivityNotFoundException e) {
activityNotFound();
return false;
}
}
/**
* Opens APG activity to select the signature key.
*
* @return true when user presses okay, false when user presses cancel
*/ */
public boolean selectSecretKey() { public boolean selectSecretKey() {
Intent intent = new Intent(Constants.Intent.SELECT_SECRET_KEY); Intent intent = new Intent(Constants.Intent.SELECT_SECRET_KEY);
@ -55,12 +103,16 @@ public class ApgIntentHelper {
} }
/** /**
* Start the encrypt activity. * Encrypts the given data by opening APGs encrypt activity. If encryptionKeys are given it
* encrypts immediately and goes back to your program after that
* *
* @param activity
* @param data * @param data
* @param pgpData * String that contains the message to be encrypted
* @return success or failure * @param encryptionKeyIds
* long[] that holds the ids of the encryption keys
* @param signatureKeyId
* id of the signature key
* @return
*/ */
public boolean encrypt(String data, long[] encryptionKeyIds, long signatureKeyId) { public boolean encrypt(String data, long[] encryptionKeyIds, long signatureKeyId) {
Intent intent = new Intent(Constants.Intent.ENCRYPT_AND_RETURN); Intent intent = new Intent(Constants.Intent.ENCRYPT_AND_RETURN);

View File

@ -49,6 +49,7 @@ public class Constants {
+ ".intent.SELECT_PUBLIC_KEYS"; + ".intent.SELECT_PUBLIC_KEYS";
public static final String SELECT_SECRET_KEY = APG_PACKAGE_NAME public static final String SELECT_SECRET_KEY = APG_PACKAGE_NAME
+ ".intent.SELECT_SECRET_KEY"; + ".intent.SELECT_SECRET_KEY";
public static final String EDIT_KEY = APG_PACKAGE_NAME + ".intent.EDIT_KEY";
} }
public static final String EXTRA_TEXT = "text"; public static final String EXTRA_TEXT = "text";
@ -62,6 +63,7 @@ public class Constants {
public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess"; public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess";
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown"; public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
public static final String EXTRA_USER_ID = "userId"; public static final String EXTRA_USER_ID = "userId";
public static final String EXTRA_USER_IDS = "userIds";
public static final String EXTRA_KEY_ID = "keyId"; public static final String EXTRA_KEY_ID = "keyId";
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds"; public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
public static final String EXTRA_SELECTION = "selection"; public static final String EXTRA_SELECTION = "selection";
@ -74,6 +76,7 @@ public class Constants {
public static final int ENCRYPT_MESSAGE = 0x21070002; public static final int ENCRYPT_MESSAGE = 0x21070002;
public static final int SELECT_PUBLIC_KEYS = 0x21070003; public static final int SELECT_PUBLIC_KEYS = 0x21070003;
public static final int SELECT_SECRET_KEY = 0x21070004; public static final int SELECT_SECRET_KEY = 0x21070004;
public static final int CREATE_NEW_KEY = 0x21070005;
// public static Pattern PGP_MESSAGE = Pattern.compile( // public static Pattern PGP_MESSAGE = Pattern.compile(
// ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); // ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL);