mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
Generic share of keyring via Android Intent SEND, renaming of own share intents
This commit is contained in:
parent
049dc908f8
commit
d515b26796
@ -81,8 +81,11 @@ public class ApgIntentHelper {
|
||||
/**
|
||||
* Share actions
|
||||
*/
|
||||
public static final String ACTION_SHARE_WITH_QR_CODE = APG_INTENT_PREFIX + "SHARE_WITH_QR_CODE";
|
||||
public static final String ACTION_SHARE_WITH_NFC = APG_INTENT_PREFIX + "SHARE_WITH_NFC";
|
||||
public static final String ACTION_SHARE_KEYRING = APG_INTENT_PREFIX + "SHARE_KEYRING";
|
||||
public static final String ACTION_SHARE_KEYRING_WITH_QR_CODE = APG_INTENT_PREFIX
|
||||
+ "SHARE_KEYRING_WITH_QR_CODE";
|
||||
public static final String ACTION_SHARE_KEYRING_WITH_NFC = APG_INTENT_PREFIX
|
||||
+ "SHARE_KEYRING_WITH_NFC";
|
||||
|
||||
// used by SHARE_WITH_QR_CODE and SHARE_WITH_NFC
|
||||
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||
@ -168,7 +171,7 @@ public class ApgIntentHelper {
|
||||
* @return true when activity was found and executed successfully
|
||||
*/
|
||||
public boolean shareWithQrCode(long masterKeyId) {
|
||||
Intent intent = new Intent(ACTION_SHARE_WITH_QR_CODE);
|
||||
Intent intent = new Intent(ACTION_SHARE_KEYRING_WITH_QR_CODE);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||
try {
|
||||
@ -186,7 +189,7 @@ public class ApgIntentHelper {
|
||||
* @return true when activity was found and executed successfully
|
||||
*/
|
||||
public boolean shareWithNfc(long masterKeyId) {
|
||||
Intent intent = new Intent(ACTION_SHARE_WITH_NFC);
|
||||
Intent intent = new Intent(ACTION_SHARE_KEYRING_WITH_NFC);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||
try {
|
||||
|
@ -364,7 +364,7 @@
|
||||
android:launchMode="singleTop"
|
||||
android:uiOptions="splitActionBarWhenNarrow" >
|
||||
<intent-filter>
|
||||
<action android:name="org.thialfihar.android.apg.intent.SHARE_WITH_NFC" />
|
||||
<action android:name="org.thialfihar.android.apg.intent.SHARE_KEYRING_WITH_NFC" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
@ -378,9 +378,10 @@
|
||||
<data android:mimeType="application/org.thialfihar.android.apg" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="org.thialfihar.android.apg.ui.ShareQrCodeActivity" >
|
||||
<activity android:name="org.thialfihar.android.apg.ui.ShareActivity" >
|
||||
<intent-filter>
|
||||
<action android:name="org.thialfihar.android.apg.intent.SHARE_WITH_QR_CODE" />
|
||||
<action android:name="org.thialfihar.android.apg.intent.SHARE_KEYRING" />
|
||||
<action android:name="org.thialfihar.android.apg.intent.SHARE_KEYRING_WITH_QR_CODE" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
@ -102,6 +102,7 @@
|
||||
<string name="menu_keyServer">Query Key Server</string>
|
||||
<string name="menu_updateKey">Update from Server</string>
|
||||
<string name="menu_exportKeyToServer">Export To Server</string>
|
||||
<string name="menu_share">Share with…</string>
|
||||
<string name="menu_shareQrCode">Share with QR Code</string>
|
||||
<string name="menu_shareNfc">Share with NFC</string>
|
||||
<string name="menu_scanQRCode">Scan QR Code</string>
|
||||
@ -156,7 +157,7 @@
|
||||
<string name="nKeyServers">%s key server(s)</string>
|
||||
<string name="fingerprint">Fingerprint:</string>
|
||||
<string name="secretKeyring">Secret Keyring:</string>
|
||||
|
||||
|
||||
<!-- choice_lowerCase: capitalized first word, no punctuation -->
|
||||
<string name="choice_none">None</string>
|
||||
<string name="choice_signOnly">Sign only</string>
|
||||
@ -321,6 +322,7 @@
|
||||
<string name="hint_publicKeys">Search Public Keyrings</string>
|
||||
<string name="hint_secretKeys">Search Secret Keyrings</string>
|
||||
<string name="filterInfo">Filter: \"%s\"</string>
|
||||
<string name="shareKeyringWith">Share keyring with…</string>
|
||||
|
||||
<!-- misc -->
|
||||
<string name="fast">fast</string>
|
||||
|
@ -35,9 +35,10 @@ public final class Id {
|
||||
public static final int edit = 0x21070003;
|
||||
public static final int update = 0x21070004;
|
||||
public static final int exportToServer = 0x21070005;
|
||||
public static final int share_qr_code = 0x21070006;
|
||||
public static final int share_nfc = 0x21070007;
|
||||
public static final int signKey = 0x21070008;
|
||||
public static final int share = 0x21070006;
|
||||
public static final int share_qr_code = 0x21070007;
|
||||
public static final int share_nfc = 0x21070008;
|
||||
public static final int signKey = 0x21070009;
|
||||
|
||||
public static final class option {
|
||||
public static final int new_pass_phrase = 0x21070001;
|
||||
|
@ -76,8 +76,9 @@ public class KeyListPublicFragment extends KeyListFragment implements
|
||||
menu.add(0, Id.menu.update, 1, R.string.menu_updateKey);
|
||||
menu.add(0, Id.menu.signKey, 2, R.string.menu_signKey);
|
||||
menu.add(0, Id.menu.exportToServer, 3, R.string.menu_exportKeyToServer);
|
||||
menu.add(0, Id.menu.share_qr_code, 6, R.string.menu_shareQrCode);
|
||||
menu.add(0, Id.menu.share_nfc, 7, R.string.menu_shareNfc);
|
||||
menu.add(0, Id.menu.share, 6, R.string.menu_share);
|
||||
menu.add(0, Id.menu.share_qr_code, 7, R.string.menu_shareQrCode);
|
||||
menu.add(0, Id.menu.share_nfc, 8, R.string.menu_shareNfc);
|
||||
|
||||
}
|
||||
|
||||
@ -142,9 +143,9 @@ public class KeyListPublicFragment extends KeyListFragment implements
|
||||
// get master key id using row id
|
||||
long masterKeyId = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
|
||||
|
||||
Intent qrCodeIntent = new Intent(mKeyListActivity, ShareQrCodeActivity.class);
|
||||
qrCodeIntent.setAction(ShareQrCodeActivity.ACTION_SHARE_WITH_QR_CODE);
|
||||
qrCodeIntent.putExtra(ShareQrCodeActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||
Intent qrCodeIntent = new Intent(mKeyListActivity, ShareActivity.class);
|
||||
qrCodeIntent.setAction(ShareActivity.ACTION_SHARE_KEYRING_WITH_QR_CODE);
|
||||
qrCodeIntent.putExtra(ShareActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
|
||||
startActivityForResult(qrCodeIntent, 0);
|
||||
|
||||
return true;
|
||||
@ -154,12 +155,23 @@ public class KeyListPublicFragment extends KeyListFragment implements
|
||||
long masterKeyId2 = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
|
||||
|
||||
Intent nfcIntent = new Intent(mKeyListActivity, ShareNfcBeamActivity.class);
|
||||
nfcIntent.setAction(ShareNfcBeamActivity.ACTION_SHARE_WITH_NFC);
|
||||
nfcIntent.setAction(ShareNfcBeamActivity.ACTION_SHARE_KEYRING_WITH_NFC);
|
||||
nfcIntent.putExtra(ShareNfcBeamActivity.EXTRA_MASTER_KEY_ID, masterKeyId2);
|
||||
startActivityForResult(nfcIntent, 0);
|
||||
|
||||
return true;
|
||||
|
||||
case Id.menu.share:
|
||||
// get master key id using row id
|
||||
long masterKeyId3 = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
|
||||
|
||||
Intent shareIntent = new Intent(mKeyListActivity, ShareActivity.class);
|
||||
shareIntent.setAction(ShareActivity.ACTION_SHARE_KEYRING);
|
||||
shareIntent.putExtra(ShareActivity.EXTRA_MASTER_KEY_ID, masterKeyId3);
|
||||
startActivityForResult(shareIntent, 0);
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
|
||||
|
@ -19,6 +19,7 @@ package org.thialfihar.android.apg.ui;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.provider.ProviderHelper;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
@ -27,9 +28,10 @@ import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class ShareQrCodeActivity extends SherlockFragmentActivity {
|
||||
public static final String ACTION_SHARE_WITH_QR_CODE = Constants.INTENT_PREFIX
|
||||
+ "SHARE_WITH_QR_CODE";
|
||||
public class ShareActivity extends SherlockFragmentActivity {
|
||||
public static final String ACTION_SHARE_KEYRING = Constants.INTENT_PREFIX + "SHARE_KEYRING";
|
||||
public static final String ACTION_SHARE_KEYRING_WITH_QR_CODE = Constants.INTENT_PREFIX
|
||||
+ "SHARE_KEYRING_WITH_QR_CODE";
|
||||
|
||||
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||
|
||||
@ -48,18 +50,25 @@ public class ShareQrCodeActivity extends SherlockFragmentActivity {
|
||||
extras = new Bundle();
|
||||
}
|
||||
|
||||
if (ACTION_SHARE_WITH_QR_CODE.equals(action)) {
|
||||
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
||||
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
||||
|
||||
// get public keyring as ascii armored string
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(
|
||||
this, new long[] { masterKeyId });
|
||||
// close this activity
|
||||
finish();
|
||||
// get public keyring as ascii armored string
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
||||
new long[] { masterKeyId });
|
||||
|
||||
// close this activity
|
||||
finish();
|
||||
|
||||
if (ACTION_SHARE_KEYRING.equals(action)) {
|
||||
// let user choose application
|
||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, keyringArmored.get(0));
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(Intent.createChooser(sendIntent,
|
||||
getResources().getText(R.string.shareKeyringWith)));
|
||||
} else if (ACTION_SHARE_KEYRING_WITH_QR_CODE.equals(action)) {
|
||||
// use barcode scanner integration library
|
||||
new IntentIntegrator(this).shareText(keyringArmored.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -54,7 +54,8 @@ import android.text.method.LinkMovementMethod;
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public class ShareNfcBeamActivity extends SherlockFragmentActivity implements
|
||||
CreateNdefMessageCallback, OnNdefPushCompleteCallback {
|
||||
public static final String ACTION_SHARE_WITH_NFC = Constants.INTENT_PREFIX + "SHARE_WITH_NFC";
|
||||
public static final String ACTION_SHARE_KEYRING_WITH_NFC = Constants.INTENT_PREFIX
|
||||
+ "SHARE_KEYRING_WITH_NFC";
|
||||
|
||||
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||
|
||||
@ -96,7 +97,7 @@ public class ShareNfcBeamActivity extends SherlockFragmentActivity implements
|
||||
extras = new Bundle();
|
||||
}
|
||||
|
||||
if (ACTION_SHARE_WITH_NFC.equals(action)) {
|
||||
if (ACTION_SHARE_KEYRING_WITH_NFC.equals(action)) {
|
||||
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
||||
|
||||
// get public keyring as byte array
|
||||
|
@ -83,8 +83,9 @@ Android primitives to exchange data: Intent, Intent with return values, Send (al
|
||||
* IMPORT_FROM_FILE
|
||||
* IMPORT_FROM_QR_CODE
|
||||
* IMPORT_FROM_NFC
|
||||
* SHARE_WITH_QR_CODE
|
||||
* SHARE_WITH_NFC
|
||||
* SHARE_KEYRING
|
||||
* SHARE_KEYRING_WITH_QR_CODE
|
||||
* SHARE_KEYRING_WITH_NFC
|
||||
* EDIT_KEY
|
||||
* SELECT_PUBLIC_KEYS
|
||||
* SELECT_SECRET_KEY
|
||||
|
Loading…
Reference in New Issue
Block a user