mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 11:35:07 -05:00
intent to create a new key
This commit is contained in:
parent
dfa4e084dd
commit
1a33f4d886
@ -75,7 +75,13 @@
|
||||
android:name=".ui.EditKeyActivity"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"
|
||||
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
|
||||
android:name=".ui.SelectPublicKeyListActivity"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"
|
||||
|
@ -62,26 +62,4 @@
|
||||
|
||||
</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>
|
||||
|
@ -125,6 +125,7 @@ public class Apg {
|
||||
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 EXTRA_TEXT = "text";
|
||||
@ -153,7 +154,7 @@ public class Apg {
|
||||
public static final String EXTRA_ASCII_ARMOUR = "asciiArmour";
|
||||
public static final String EXTRA_BINARY = "binary";
|
||||
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;
|
||||
|
||||
|
@ -31,6 +31,7 @@ import org.spongycastle.openpgp.PGPException;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
@ -249,6 +250,12 @@ public class DecryptActivity extends BaseActivity {
|
||||
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);
|
||||
String textData = null;
|
||||
if (mData == null) {
|
||||
|
@ -28,6 +28,7 @@ import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
@ -36,6 +37,7 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.view.LayoutInflater;
|
||||
@ -53,6 +55,7 @@ import java.security.SignatureException;
|
||||
import java.util.Vector;
|
||||
|
||||
public class EditKeyActivity extends BaseActivity {
|
||||
private Intent mIntent = null;
|
||||
|
||||
private PGPSecretKeyRing mKeyRing = null;
|
||||
|
||||
@ -66,12 +69,10 @@ public class EditKeyActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(1, Id.menu.option.cancel, 0, R.string.btn_doNotSave)
|
||||
// .setIcon(R.drawable.ic_menu_search_holo_light)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menu.add(1, Id.menu.option.save, 1, R.string.btn_save)
|
||||
// .setIcon(R.drawable.ic_suggestions_add)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menu.add(1, Id.menu.option.cancel, 0, R.string.btn_doNotSave).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(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
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.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
@ -135,12 +156,7 @@ public class EditKeyActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
// mSaveButton = (Button) findViewById(R.id.btn_save);
|
||||
// mDiscardButton = (Button) findViewById(R.id.btn_discard);
|
||||
|
||||
// mSaveButton.setOnClickListener(this);
|
||||
// mDiscardButton.setOnClickListener(this);
|
||||
|
||||
// Build layout based on given userIds and keys
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
LinearLayout container = (LinearLayout) findViewById(R.id.container);
|
||||
|
@ -33,6 +33,7 @@ import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.apg.R;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
@ -125,15 +126,12 @@ public class EncryptActivity extends BaseActivity {
|
||||
|
||||
if (mEncryptToClipboardEnabled) {
|
||||
menu.add(1, Id.menu.option.encrypt_to_clipboard, 0, mEncryptToClipboardString)
|
||||
// .setIcon(R.drawable.ic_menu_encrypt)
|
||||
.setShowAsAction(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
if (mEncryptEnabled) {
|
||||
menu.add(1, Id.menu.option.encrypt, 1, mEncryptString)
|
||||
// .setIcon(R.drawable.ic_menu_decrypt)
|
||||
.setShowAsAction(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menu.add(1, Id.menu.option.encrypt, 1, mEncryptString).setShowAsAction(
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -233,8 +231,6 @@ public class EncryptActivity extends BaseActivity {
|
||||
|
||||
mMessage = (EditText) findViewById(R.id.message);
|
||||
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);
|
||||
mMainUserId = (TextView) findViewById(R.id.mainUserId);
|
||||
mMainUserIdRest = (TextView) findViewById(R.id.mainUserIdRest);
|
||||
@ -317,6 +313,12 @@ public class EncryptActivity extends BaseActivity {
|
||||
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())
|
||||
|| Apg.Intent.GENERATE_SIGNATURE.equals(mIntent.getAction())) {
|
||||
mReturnResult = true;
|
||||
@ -483,8 +485,6 @@ public class EncryptActivity extends BaseActivity {
|
||||
mEncryptEnabled = true;
|
||||
mEncryptToClipboardEnabled = false;
|
||||
|
||||
// mEncryptToClipboardButton.setVisibility(View.INVISIBLE);
|
||||
// mEncryptButton.setText(R.string.btn_encrypt);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import java.util.Vector;
|
||||
import org.apg.Apg;
|
||||
import org.apg.Id;
|
||||
import org.apg.R;
|
||||
import org.apg.ui.widget.SelectPublicKeyListAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
|
@ -19,6 +19,7 @@ package org.apg.ui;
|
||||
import org.apg.Apg;
|
||||
import org.apg.Id;
|
||||
import org.apg.R;
|
||||
import org.apg.ui.widget.SelectSecretKeyListAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apg.ui;
|
||||
package org.apg.ui.widget;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apg.ui;
|
||||
package org.apg.ui.widget;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -40,9 +40,12 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
||||
private EditText mEmail;
|
||||
private EditText mComment;
|
||||
|
||||
private static final Pattern EMAIL_PATTERN = Pattern.compile(
|
||||
"^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+[.]([a-zA-Z])+([a-zA-Z])+",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
// see http://www.regular-expressions.info/email.html
|
||||
// RFC 2822 if we omit the syntax using double quotes and square brackets
|
||||
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 {
|
||||
static final long serialVersionUID = 0xf812773343L;
|
||||
|
Binary file not shown.
@ -9,3 +9,4 @@
|
||||
|
||||
# Project target.
|
||||
target=android-15
|
||||
android.library.reference.1=../org_apg_integration_lib
|
||||
|
@ -7,6 +7,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
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
|
||||
android:id="@+id/intent_demo_select_secret_key"
|
||||
|
@ -54,6 +54,11 @@ public class IntentDemoActivity extends Activity {
|
||||
mApgData = new ApgData();
|
||||
}
|
||||
|
||||
public void intentDemoCreateNewKeyOnClick(View view) {
|
||||
// mApgIntentHelper.createNewKey();
|
||||
mApgIntentHelper.createNewKey("dom <+491716581452@cryptocall.org>");
|
||||
}
|
||||
|
||||
public void intentDemoSelectSecretKeyOnClick(View view) {
|
||||
mApgIntentHelper.selectSecretKey();
|
||||
}
|
||||
|
@ -36,11 +36,59 @@ public class ApgIntentHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the signature key.
|
||||
* Opens APG activity to create new key
|
||||
*
|
||||
* @param activity
|
||||
* @param pgpData
|
||||
* @return success or failure
|
||||
* @param userIds
|
||||
* value to specify prefilled values for user that should be created
|
||||
* @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() {
|
||||
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 pgpData
|
||||
* @return success or failure
|
||||
* String that contains the message to be encrypted
|
||||
* @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) {
|
||||
Intent intent = new Intent(Constants.Intent.ENCRYPT_AND_RETURN);
|
||||
|
@ -49,6 +49,7 @@ public class Constants {
|
||||
+ ".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 EXTRA_TEXT = "text";
|
||||
@ -62,6 +63,7 @@ public class Constants {
|
||||
public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess";
|
||||
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
|
||||
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_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
|
||||
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 SELECT_PUBLIC_KEYS = 0x21070003;
|
||||
public static final int SELECT_SECRET_KEY = 0x21070004;
|
||||
public static final int CREATE_NEW_KEY = 0x21070005;
|
||||
|
||||
// public static Pattern PGP_MESSAGE = Pattern.compile(
|
||||
// ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL);
|
||||
|
Loading…
Reference in New Issue
Block a user