mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
intent to create key with default keyring
This commit is contained in:
parent
4eebeede2b
commit
30b6cc60f2
@ -78,6 +78,7 @@
|
||||
android:uiOptions="splitActionBarWhenNarrow"
|
||||
android:windowSoftInputMode="stateHidden" >
|
||||
<intent-filter>
|
||||
<action android:name="org.apg.intent.CREATE_KEY" />
|
||||
<action android:name="org.apg.intent.EDIT_KEY" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
Binary file not shown.
@ -28,6 +28,7 @@
|
||||
<string name="title_authentication">Passphrase</string>
|
||||
<string name="title_createKey">Create Key</string>
|
||||
<string name="title_editKey">Edit Key</string>
|
||||
<string name="title_createKey">Create Key</string>
|
||||
<string name="title_preferences">Preferences</string>
|
||||
<string name="title_keyServerPreference">Key Server Preference</string>
|
||||
<string name="title_changePassPhrase">Change Passphrase</string>
|
||||
|
@ -109,24 +109,27 @@ import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Apg {
|
||||
private static final String mApgPackageName = "org.apg";
|
||||
private static final String PACKAGE_NAME = "org.apg";
|
||||
private static final String INTENT_PREFIX = "org.apg.intent.";
|
||||
|
||||
public static class Intent {
|
||||
public static final String DECRYPT = "org.apg.intent.DECRYPT";
|
||||
public static final String ENCRYPT = "org.apg.intent.ENCRYPT";
|
||||
public static final String DECRYPT_FILE = "org.apg.intent.DECRYPT_FILE";
|
||||
public static final String ENCRYPT_FILE = "org.apg.intent.ENCRYPT_FILE";
|
||||
public static final String DECRYPT_AND_RETURN = "org.apg.intent.DECRYPT_AND_RETURN";
|
||||
public static final String ENCRYPT_AND_RETURN = "org.apg.intent.ENCRYPT_AND_RETURN";
|
||||
public static final String SELECT_PUBLIC_KEYS = "org.apg.intent.SELECT_PUBLIC_KEYS";
|
||||
public static final String SELECT_SECRET_KEY = "org.apg.intent.SELECT_SECRET_KEY";
|
||||
public static final String IMPORT = "org.apg.intent.IMPORT";
|
||||
public static final String LOOK_UP_KEY_ID = "org.apg.intent.LOOK_UP_KEY_ID";
|
||||
public static final String LOOK_UP_KEY_ID_AND_RETURN = "org.apg.intent.LOOK_UP_KEY_ID_AND_RETURN";
|
||||
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 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 DECRYPT = INTENT_PREFIX + "DECRYPT";
|
||||
public static final String ENCRYPT = INTENT_PREFIX + "ENCRYPT";
|
||||
public static final String DECRYPT_FILE = INTENT_PREFIX + "DECRYPT_FILE";
|
||||
public static final String ENCRYPT_FILE = INTENT_PREFIX + "ENCRYPT_FILE";
|
||||
public static final String DECRYPT_AND_RETURN = INTENT_PREFIX + "DECRYPT_AND_RETURN";
|
||||
public static final String ENCRYPT_AND_RETURN = INTENT_PREFIX + "ENCRYPT_AND_RETURN";
|
||||
public static final String SELECT_PUBLIC_KEYS = INTENT_PREFIX + "SELECT_PUBLIC_KEYS";
|
||||
public static final String SELECT_SECRET_KEY = INTENT_PREFIX + "SELECT_SECRET_KEY";
|
||||
public static final String IMPORT = INTENT_PREFIX + "IMPORT";
|
||||
public static final String LOOK_UP_KEY_ID = INTENT_PREFIX + "LOOK_UP_KEY_ID";
|
||||
public static final String LOOK_UP_KEY_ID_AND_RETURN = INTENT_PREFIX
|
||||
+ "LOOK_UP_KEY_ID_AND_RETURN";
|
||||
public static final String GENERATE_SIGNATURE = INTENT_PREFIX + "GENERATE_SIGNATURE";
|
||||
public static final String EXPORT_KEY_TO_SERVER = INTENT_PREFIX + "EXPORT_KEY_TO_SERVER";
|
||||
public static final String IMPORT_FROM_QR_CODE = INTENT_PREFIX + "IMPORT_FROM_QR_CODE";
|
||||
public static final String CREATE_KEY = INTENT_PREFIX + "CREATE_KEY";
|
||||
public static final String EDIT_KEY = INTENT_PREFIX + "EDIT_KEY";
|
||||
}
|
||||
|
||||
public static final String EXTRA_TEXT = "text";
|
||||
@ -157,6 +160,7 @@ public class Apg {
|
||||
public static final String EXTRA_KEY_SERVERS = "keyServers";
|
||||
public static final String EXTRA_EXPECTED_FINGERPRINT = "expectedFingerprint";
|
||||
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
|
||||
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
|
||||
|
||||
public static final String AUTHORITY = DataProvider.AUTHORITY;
|
||||
|
||||
@ -2187,7 +2191,7 @@ public class Apg {
|
||||
|
||||
public static boolean isReleaseVersion(Context context) {
|
||||
try {
|
||||
PackageInfo pi = context.getPackageManager().getPackageInfo(mApgPackageName, 0);
|
||||
PackageInfo pi = context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
|
||||
if (pi.versionCode % 100 == 99) {
|
||||
return true;
|
||||
} else {
|
||||
@ -2204,7 +2208,7 @@ public class Apg {
|
||||
return VERSION;
|
||||
}
|
||||
try {
|
||||
PackageInfo pi = context.getPackageManager().getPackageInfo(mApgPackageName, 0);
|
||||
PackageInfo pi = context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
|
||||
VERSION = pi.versionName;
|
||||
return VERSION;
|
||||
} catch (NameNotFoundException e) {
|
||||
|
@ -40,8 +40,10 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
@ -52,6 +54,8 @@ import android.widget.Toast;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.SignatureException;
|
||||
@ -59,6 +63,7 @@ import java.util.Vector;
|
||||
|
||||
public class EditKeyActivity extends BaseActivity {
|
||||
private Intent mIntent = null;
|
||||
private ActionBar mActionBar;
|
||||
|
||||
private PGPSecretKeyRing mKeyRing = null;
|
||||
|
||||
@ -109,60 +114,119 @@ public class EditKeyActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.edit_key);
|
||||
|
||||
mActionBar = getSupportActionBar();
|
||||
|
||||
// find views
|
||||
mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase);
|
||||
mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase);
|
||||
|
||||
Vector<String> userIds = new Vector<String>();
|
||||
Vector<PGPSecretKey> keys = new Vector<PGPSecretKey>();
|
||||
Vector<Integer> keysUsages = new Vector<Integer>();
|
||||
|
||||
Intent intent = getIntent();
|
||||
long keyId = 0;
|
||||
if (intent.getExtras() != null) {
|
||||
keyId = intent.getExtras().getLong(Apg.EXTRA_KEY_ID);
|
||||
// Catch Intents opened from other apps
|
||||
mIntent = getIntent();
|
||||
Bundle extras = mIntent.getExtras();
|
||||
if (Apg.Intent.CREATE_KEY.equals(mIntent.getAction())) {
|
||||
|
||||
mActionBar.setTitle(R.string.title_createKey);
|
||||
|
||||
mCurrentPassPhrase = "";
|
||||
|
||||
if (extras != null) {
|
||||
|
||||
// disable home button on actionbar because this activity is run from another app
|
||||
mActionBar.setDisplayShowTitleEnabled(true);
|
||||
mActionBar.setDisplayHomeAsUpEnabled(false);
|
||||
mActionBar.setHomeButtonEnabled(false);
|
||||
|
||||
// if userId is given, prefill the fields
|
||||
if (extras.containsKey(Apg.EXTRA_USER_IDS)) {
|
||||
Log.d(Constants.TAG, "UserIds are given!");
|
||||
userIds.add(extras.getString(Apg.EXTRA_USER_IDS));
|
||||
}
|
||||
|
||||
// if no passphrase is given
|
||||
if (extras.containsKey(Apg.EXTRA_NO_PASSPHRASE)) {
|
||||
boolean noPassphrase = extras.getBoolean(Apg.EXTRA_NO_PASSPHRASE);
|
||||
if (noPassphrase) {
|
||||
// check "no passphrase" checkbox and remove button
|
||||
mNoPassphrase.setChecked(true);
|
||||
mChangePassPhrase.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// generate key
|
||||
if (extras.containsKey(Apg.EXTRA_GENERATE_DEFAULT_KEYS)) {
|
||||
boolean generateDefaultKeys = extras
|
||||
.getBoolean(Apg.EXTRA_GENERATE_DEFAULT_KEYS);
|
||||
if (generateDefaultKeys) {
|
||||
|
||||
// generate a RSA 2048 key for encryption and signing!
|
||||
try {
|
||||
PGPSecretKey masterKey = Apg.createKey(this, Id.choice.algorithm.rsa,
|
||||
2048, mCurrentPassPhrase, null);
|
||||
|
||||
// add new masterKey to keys array, which is then added to view
|
||||
keys.add(masterKey);
|
||||
keysUsages.add(Id.choice.usage.sign_only);
|
||||
|
||||
PGPSecretKey subKey = Apg.createKey(this, Id.choice.algorithm.rsa,
|
||||
2048, mCurrentPassPhrase, masterKey);
|
||||
|
||||
keys.add(subKey);
|
||||
keysUsages.add(Id.choice.usage.encrypt_only);
|
||||
|
||||
// define usage of this key
|
||||
} catch (Exception e) {
|
||||
Log.e(Constants.TAG, "Creating initial key failed: +" + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else if (Apg.Intent.EDIT_KEY.equals(mIntent.getAction())) {
|
||||
|
||||
mActionBar.setTitle(R.string.title_editKey);
|
||||
|
||||
mCurrentPassPhrase = Apg.getEditPassPhrase();
|
||||
if (mCurrentPassPhrase == null) {
|
||||
mCurrentPassPhrase = "";
|
||||
}
|
||||
|
||||
if (mCurrentPassPhrase.equals("")) {
|
||||
// check "no passphrase" checkbox and remove button
|
||||
mNoPassphrase.setChecked(true);
|
||||
mChangePassPhrase.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (extras != null) {
|
||||
|
||||
if (extras.containsKey(Apg.EXTRA_KEY_ID)) {
|
||||
long keyId = mIntent.getExtras().getLong(Apg.EXTRA_KEY_ID);
|
||||
|
||||
if (keyId != 0) {
|
||||
PGPSecretKey masterKey = null;
|
||||
mKeyRing = Apg.getSecretKeyRing(keyId);
|
||||
if (mKeyRing != null) {
|
||||
masterKey = Apg.getMasterKey(mKeyRing);
|
||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
|
||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(
|
||||
mKeyRing.getSecretKeys())) {
|
||||
keys.add(key);
|
||||
keysUsages.add(-1); // get usage when view is created
|
||||
}
|
||||
}
|
||||
if (masterKey != null) {
|
||||
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
|
||||
for (String userId : new IterableIterator<String>(
|
||||
masterKey.getUserIDs())) {
|
||||
userIds.add(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
// if userId is given, prefill the fields
|
||||
if (extras.containsKey(Apg.EXTRA_NO_PASSPHRASE)) {
|
||||
boolean noPassphrase = extras.getBoolean(Apg.EXTRA_NO_PASSPHRASE);
|
||||
if (noPassphrase) {
|
||||
mCurrentPassPhrase = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase);
|
||||
mChangePassPhrase.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
showDialog(Id.dialog.new_pass_phrase);
|
||||
@ -170,7 +234,6 @@ public class EditKeyActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
// disable passphrase when no passphrase checkobox is checked!
|
||||
mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase);
|
||||
mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
@ -197,20 +260,9 @@ public class EditKeyActivity extends BaseActivity {
|
||||
container.addView(mUserIds);
|
||||
mKeys = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
|
||||
mKeys.setType(Id.type.key);
|
||||
mKeys.setKeys(keys);
|
||||
mKeys.setKeys(keys, keysUsages);
|
||||
container.addView(mKeys);
|
||||
|
||||
mCurrentPassPhrase = Apg.getEditPassPhrase();
|
||||
if (mCurrentPassPhrase == null) {
|
||||
mCurrentPassPhrase = "";
|
||||
}
|
||||
|
||||
if (mCurrentPassPhrase.equals("")) {
|
||||
// check "no passphrase" checkbox and remove button
|
||||
mNoPassphrase.setChecked(true);
|
||||
mChangePassPhrase.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
updatePassPhraseButtonText();
|
||||
}
|
||||
|
||||
|
@ -164,13 +164,13 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
|
||||
|
||||
private void createKey() {
|
||||
Apg.setEditPassPhrase("");
|
||||
Intent intent = new Intent(this, EditKeyActivity.class);
|
||||
Intent intent = new Intent(Apg.Intent.CREATE_KEY);
|
||||
startActivityForResult(intent, Id.message.create_key);
|
||||
}
|
||||
|
||||
private void editKey() {
|
||||
long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem);
|
||||
Intent intent = new Intent(this, EditKeyActivity.class);
|
||||
Intent intent = new Intent(Apg.Intent.EDIT_KEY);
|
||||
intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
|
||||
startActivityForResult(intent, Id.message.edit_key);
|
||||
}
|
||||
|
@ -59,8 +59,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
Button mExpiryDateButton;
|
||||
GregorianCalendar mExpiryDate;
|
||||
|
||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener =
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
|
||||
setExpiryDate(date);
|
||||
@ -86,15 +85,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
mExpiryDateButton = (Button) findViewById(R.id.expiry);
|
||||
mUsage = (Spinner) findViewById(R.id.usage);
|
||||
Choice choices[] = {
|
||||
new Choice(Id.choice.usage.sign_only,
|
||||
getResources().getString(R.string.choice_signOnly)),
|
||||
new Choice(Id.choice.usage.encrypt_only,
|
||||
getResources().getString(R.string.choice_encryptOnly)),
|
||||
new Choice(Id.choice.usage.sign_and_encrypt,
|
||||
getResources().getString(R.string.choice_signAndEncrypt)),
|
||||
};
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(getContext(),
|
||||
new Choice(Id.choice.usage.sign_only, getResources().getString(
|
||||
R.string.choice_signOnly)),
|
||||
new Choice(Id.choice.usage.encrypt_only, getResources().getString(
|
||||
R.string.choice_encryptOnly)),
|
||||
new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString(
|
||||
R.string.choice_signAndEncrypt)), };
|
||||
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
|
||||
android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mUsage.setAdapter(adapter);
|
||||
@ -111,15 +108,12 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
date = new GregorianCalendar();
|
||||
}
|
||||
|
||||
DatePickerDialog dialog =
|
||||
new DatePickerDialog(getContext(), mExpiryDateSetListener,
|
||||
date.get(Calendar.YEAR),
|
||||
date.get(Calendar.MONTH),
|
||||
DatePickerDialog dialog = new DatePickerDialog(getContext(),
|
||||
mExpiryDateSetListener, date.get(Calendar.YEAR), date.get(Calendar.MONTH),
|
||||
date.get(Calendar.DAY_OF_MONTH));
|
||||
dialog.setCancelable(true);
|
||||
dialog.setButton(Dialog.BUTTON_NEGATIVE,
|
||||
getContext().getString(R.string.btn_noDate),
|
||||
new DialogInterface.OnClickListener() {
|
||||
dialog.setButton(Dialog.BUTTON_NEGATIVE, getContext()
|
||||
.getString(R.string.btn_noDate), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setExpiryDate(null);
|
||||
}
|
||||
@ -131,7 +125,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
super.onFinishInflate();
|
||||
}
|
||||
|
||||
public void setValue(PGPSecretKey key, boolean isMasterKey) {
|
||||
public void setValue(PGPSecretKey key, boolean isMasterKey, int usage) {
|
||||
mKey = key;
|
||||
|
||||
mIsMasterKey = isMasterKey;
|
||||
@ -147,24 +141,24 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
Vector<Choice> choices = new Vector<Choice>();
|
||||
boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT);
|
||||
if (!isElGamalKey) {
|
||||
choices.add(new Choice(Id.choice.usage.sign_only,
|
||||
getResources().getString(R.string.choice_signOnly)));
|
||||
choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString(
|
||||
R.string.choice_signOnly)));
|
||||
}
|
||||
if (!mIsMasterKey) {
|
||||
choices.add(new Choice(Id.choice.usage.encrypt_only,
|
||||
getResources().getString(R.string.choice_encryptOnly)));
|
||||
choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString(
|
||||
R.string.choice_encryptOnly)));
|
||||
}
|
||||
if (!isElGamalKey) {
|
||||
choices.add(new Choice(Id.choice.usage.sign_and_encrypt,
|
||||
getResources().getString(R.string.choice_signAndEncrypt)));
|
||||
choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString(
|
||||
R.string.choice_signAndEncrypt)));
|
||||
}
|
||||
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(getContext(),
|
||||
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
|
||||
android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mUsage.setAdapter(adapter);
|
||||
|
||||
// Set value in choice dropdown to key
|
||||
int selectId = 0;
|
||||
if (Apg.isEncryptionKey(key)) {
|
||||
if (Apg.isSigningKey(key)) {
|
||||
@ -172,10 +166,16 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
} else {
|
||||
selectId = Id.choice.usage.encrypt_only;
|
||||
}
|
||||
} else {
|
||||
// set usage if it is predefined
|
||||
if (usage != -1) {
|
||||
selectId = usage;
|
||||
} else {
|
||||
selectId = Id.choice.usage.sign_only;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < choices.size(); ++i) {
|
||||
if (choices.get(i).getId() == selectId) {
|
||||
mUsage.setSelection(i);
|
||||
@ -194,6 +194,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
cal.setTime(Apg.getExpiryDate(key));
|
||||
setExpiryDate(cal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PGPSecretKey getValue() {
|
||||
@ -201,7 +202,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
final ViewGroup parent = (ViewGroup)getParent();
|
||||
final ViewGroup parent = (ViewGroup) getParent();
|
||||
if (v == mDeleteButton) {
|
||||
parent.removeView(this);
|
||||
if (mEditorListener != null) {
|
||||
@ -230,4 +231,5 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
public int getUsage() {
|
||||
return ((Choice) mUsage.getSelectedItem()).getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
mEditors, false);
|
||||
view.setEditorListener(SectionView.this);
|
||||
boolean isMasterKey = (mEditors.getChildCount() == 0);
|
||||
view.setValue(mNewKey, isMasterKey);
|
||||
view.setValue(mNewKey, isMasterKey, -1);
|
||||
mEditors.addView(view);
|
||||
SectionView.this.updateEditorsVisible();
|
||||
}
|
||||
@ -260,42 +260,26 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
||||
this.updateEditorsVisible();
|
||||
}
|
||||
|
||||
public void setKeys(Vector<PGPSecretKey> list) {
|
||||
public void setKeys(Vector<PGPSecretKey> list, Vector<Integer> usages) {
|
||||
if (mType != Id.type.key) {
|
||||
return;
|
||||
}
|
||||
|
||||
mEditors.removeAllViews();
|
||||
for (PGPSecretKey key : list) {
|
||||
|
||||
// go through all keys and set view based on them
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors,
|
||||
false);
|
||||
view.setEditorListener(this);
|
||||
boolean isMasterKey = (mEditors.getChildCount() == 0);
|
||||
view.setValue(key, isMasterKey);
|
||||
view.setValue(list.get(i), isMasterKey, usages.get(i));
|
||||
mEditors.addView(view);
|
||||
}
|
||||
|
||||
this.updateEditorsVisible();
|
||||
}
|
||||
|
||||
// TODO !!!
|
||||
public void createInitialKey() {
|
||||
mEditors.removeAllViews();
|
||||
|
||||
// create initial key
|
||||
// PGPSecretKey key = new PGPSecretKey();
|
||||
|
||||
// for (PGPSecretKey key : list) {
|
||||
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors, false);
|
||||
view.setEditorListener(this);
|
||||
boolean isMasterKey = (mEditors.getChildCount() == 0);
|
||||
// view.setValue(key, isMasterKey);
|
||||
mEditors.addView(view);
|
||||
// }
|
||||
|
||||
this.updateEditorsVisible();
|
||||
}
|
||||
|
||||
private void createKey() {
|
||||
mProgressDialog = new ProgressDialog(getContext());
|
||||
mProgressDialog.setMessage(getContext().getString(R.string.progress_generating));
|
||||
|
6
org_apg/src/org/apg/util/Constants.java
Normal file
6
org_apg/src/org/apg/util/Constants.java
Normal file
@ -0,0 +1,6 @@
|
||||
package org.apg.util;
|
||||
|
||||
public class Constants {
|
||||
public static final String TAG = "APG";
|
||||
|
||||
}
|
@ -56,7 +56,7 @@ public class IntentDemoActivity extends Activity {
|
||||
|
||||
public void intentDemoCreateNewKeyOnClick(View view) {
|
||||
// mApgIntentHelper.createNewKey();
|
||||
mApgIntentHelper.createNewKey("dom <+491716581452@cryptocall.org>");
|
||||
mApgIntentHelper.createNewKey("test <+491716581452@cryptocall.org>", true, true);
|
||||
}
|
||||
|
||||
public void intentDemoSelectSecretKeyOnClick(View view) {
|
||||
|
@ -26,6 +26,7 @@ import android.content.ContentUris;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ApgIntentHelper {
|
||||
@ -42,14 +43,17 @@ public class ApgIntentHelper {
|
||||
* value to specify prefilled values for user that should be created
|
||||
* @return true when activity was found and executed successfully
|
||||
*/
|
||||
public boolean createNewKey(String userIds) {
|
||||
Intent intent = new Intent(Constants.Intent.EDIT_KEY);
|
||||
public boolean createNewKey(String userIds, boolean noPassphrase, boolean generateDefaultKeys) {
|
||||
Intent intent = new Intent(Constants.Intent.CREATE_KEY);
|
||||
if (userIds != null) {
|
||||
intent.putExtra(Constants.EXTRA_USER_IDS, userIds);
|
||||
}
|
||||
intent.putExtra(Constants.EXTRA_NO_PASSPHRASE, noPassphrase);
|
||||
intent.putExtra(Constants.EXTRA_GENERATE_DEFAULT_KEYS, generateDefaultKeys);
|
||||
|
||||
intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION);
|
||||
try {
|
||||
activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY);
|
||||
activity.startActivityForResult(intent, Constants.CREATE_KEY);
|
||||
return true;
|
||||
} catch (ActivityNotFoundException e) {
|
||||
activityNotFound();
|
||||
@ -63,7 +67,7 @@ public class ApgIntentHelper {
|
||||
* @return true when activity was found and executed successfully
|
||||
*/
|
||||
public boolean createNewKey() {
|
||||
return createNewKey(null);
|
||||
return createNewKey(null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +81,7 @@ public class ApgIntentHelper {
|
||||
intent.putExtra(Constants.EXTRA_KEY_ID, keyId);
|
||||
intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION);
|
||||
try {
|
||||
activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY);
|
||||
activity.startActivityForResult(intent, Constants.EDIT_KEY);
|
||||
return true;
|
||||
} catch (ActivityNotFoundException e) {
|
||||
activityNotFound();
|
||||
|
@ -36,20 +36,19 @@ public class Constants {
|
||||
public static final Uri CONTENT_URI_PUBLIC_KEY_RING_BY_EMAILS = Uri.parse("content://"
|
||||
+ AUTHORITY + "/key_rings/public/emails/");
|
||||
|
||||
public static final String APG_INTENT_PREFIX = "org.apg.intent.";
|
||||
|
||||
public static class Intent {
|
||||
public static final String DECRYPT = APG_PACKAGE_NAME + ".intent.DECRYPT";
|
||||
public static final String ENCRYPT = APG_PACKAGE_NAME + ".intent.ENCRYPT";
|
||||
public static final String DECRYPT_FILE = APG_PACKAGE_NAME + ".intent.DECRYPT_FILE";
|
||||
public static final String ENCRYPT_FILE = APG_PACKAGE_NAME + ".intent.ENCRYPT_FILE";
|
||||
public static final String DECRYPT_AND_RETURN = APG_PACKAGE_NAME
|
||||
+ ".intent.DECRYPT_AND_RETURN";
|
||||
public static final String ENCRYPT_AND_RETURN = APG_PACKAGE_NAME
|
||||
+ ".intent.ENCRYPT_AND_RETURN";
|
||||
public static final String SELECT_PUBLIC_KEYS = APG_PACKAGE_NAME
|
||||
+ ".intent.SELECT_PUBLIC_KEYS";
|
||||
public static final String SELECT_SECRET_KEY = APG_PACKAGE_NAME
|
||||
+ ".intent.SELECT_SECRET_KEY";
|
||||
public static final String EDIT_KEY = APG_PACKAGE_NAME + ".intent.EDIT_KEY";
|
||||
public static final String DECRYPT = APG_INTENT_PREFIX + "DECRYPT";
|
||||
public static final String ENCRYPT = APG_INTENT_PREFIX + "ENCRYPT";
|
||||
public static final String DECRYPT_FILE = APG_INTENT_PREFIX + "DECRYPT_FILE";
|
||||
public static final String ENCRYPT_FILE = APG_INTENT_PREFIX + "ENCRYPT_FILE";
|
||||
public static final String DECRYPT_AND_RETURN = APG_INTENT_PREFIX + "DECRYPT_AND_RETURN";
|
||||
public static final String ENCRYPT_AND_RETURN = APG_INTENT_PREFIX + "ENCRYPT_AND_RETURN";
|
||||
public static final String SELECT_PUBLIC_KEYS = APG_INTENT_PREFIX + "SELECT_PUBLIC_KEYS";
|
||||
public static final String SELECT_SECRET_KEY = APG_INTENT_PREFIX + "SELECT_SECRET_KEY";
|
||||
public static final String CREATE_KEY = APG_INTENT_PREFIX + "CREATE_KEY";
|
||||
public static final String EDIT_KEY = APG_INTENT_PREFIX + "EDIT_KEY";
|
||||
}
|
||||
|
||||
public static final String EXTRA_TEXT = "text";
|
||||
@ -68,6 +67,8 @@ public class Constants {
|
||||
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
|
||||
public static final String EXTRA_SELECTION = "selection";
|
||||
public static final String EXTRA_MESSAGE = "message";
|
||||
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
|
||||
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
|
||||
public static final String EXTRA_INTENT_VERSION = "intentVersion";
|
||||
|
||||
public static final String INTENT_VERSION = "1";
|
||||
@ -76,7 +77,9 @@ public class Constants {
|
||||
public static final int ENCRYPT_MESSAGE = 0x21070002;
|
||||
public static final int SELECT_PUBLIC_KEYS = 0x21070003;
|
||||
public static final int SELECT_SECRET_KEY = 0x21070004;
|
||||
public static final int CREATE_NEW_KEY = 0x21070005;
|
||||
public static final int CREATE_KEY = 0x21070005;
|
||||
public static final int EDIT_KEY = 0x21070006;
|
||||
|
||||
|
||||
// public static Pattern PGP_MESSAGE = Pattern.compile(
|
||||
// ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL);
|
||||
|
Loading…
Reference in New Issue
Block a user