diff --git a/APG-API-Lib/src/org/thialfihar/android/apg/integration/ApgIntentHelper.java b/APG-API-Lib/src/org/thialfihar/android/apg/integration/ApgIntentHelper.java index 1362412fb..d6cdc60ab 100644 --- a/APG-API-Lib/src/org/thialfihar/android/apg/integration/ApgIntentHelper.java +++ b/APG-API-Lib/src/org/thialfihar/android/apg/integration/ApgIntentHelper.java @@ -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 { diff --git a/APG/AndroidManifest.xml b/APG/AndroidManifest.xml index 6a31333fd..c29626ccf 100644 --- a/APG/AndroidManifest.xml +++ b/APG/AndroidManifest.xml @@ -364,7 +364,7 @@ android:launchMode="singleTop" android:uiOptions="splitActionBarWhenNarrow" > - + @@ -378,9 +378,10 @@ - + - + + diff --git a/APG/res/values/strings.xml b/APG/res/values/strings.xml index 6aac04808..c7d25ad44 100644 --- a/APG/res/values/strings.xml +++ b/APG/res/values/strings.xml @@ -102,6 +102,7 @@ Query Key Server Update from Server Export To Server + Share with… Share with QR Code Share with NFC Scan QR Code @@ -156,7 +157,7 @@ %s key server(s) Fingerprint: Secret Keyring: - + None Sign only @@ -321,6 +322,7 @@ Search Public Keyrings Search Secret Keyrings Filter: \"%s\" + Share keyring with… fast diff --git a/APG/src/org/thialfihar/android/apg/Id.java b/APG/src/org/thialfihar/android/apg/Id.java index d25bb24b0..db283da37 100644 --- a/APG/src/org/thialfihar/android/apg/Id.java +++ b/APG/src/org/thialfihar/android/apg/Id.java @@ -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; diff --git a/APG/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java b/APG/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java index 06bf7e7d9..7c23e6217 100644 --- a/APG/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java +++ b/APG/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java @@ -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); diff --git a/APG/src/org/thialfihar/android/apg/ui/ShareQrCodeActivity.java b/APG/src/org/thialfihar/android/apg/ui/ShareActivity.java similarity index 58% rename from APG/src/org/thialfihar/android/apg/ui/ShareQrCodeActivity.java rename to APG/src/org/thialfihar/android/apg/ui/ShareActivity.java index 7d4237b80..7fec42e47 100644 --- a/APG/src/org/thialfihar/android/apg/ui/ShareQrCodeActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/ShareActivity.java @@ -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 keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString( - this, new long[] { masterKeyId }); - // close this activity - finish(); + // get public keyring as ascii armored string + ArrayList 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)); } } - } diff --git a/APG/src/org/thialfihar/android/apg/ui/ShareNfcBeamActivity.java b/APG/src/org/thialfihar/android/apg/ui/ShareNfcBeamActivity.java index bdf5f6227..abb2d6b82 100644 --- a/APG/src/org/thialfihar/android/apg/ui/ShareNfcBeamActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/ShareNfcBeamActivity.java @@ -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 diff --git a/README.md b/README.md index 07ca28f63..e87eff98f 100644 --- a/README.md +++ b/README.md @@ -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