improve sharing of key

This commit is contained in:
Dominik Schürmann 2014-01-19 13:42:34 +01:00
parent a966d1afa1
commit 6f1dbc2f74
3 changed files with 76 additions and 27 deletions

View File

@ -8,25 +8,43 @@
android:title="@string/menu_share">
<menu>
<item
android:id="@+id/menu_key_view_share_default"
android:id="@+id/menu_key_view_share_fingerprint_title"
android:showAsAction="never"
android:title="@string/menu_share"/>
android:title="@string/menu_share_title_fingerprint">
<menu>
<item
android:id="@+id/menu_key_view_share_default_fingerprint"
android:showAsAction="never"
android:title="@string/menu_share_default_fingerprint"/>
<item
android:id="@+id/menu_key_view_share_qr_code_fingerprint"
android:showAsAction="never"
android:title="@string/menu_share_qr_code_fingerprint"/>
</menu>
</item>
<item
android:id="@+id/menu_key_view_share_qr_code_fingerprint"
android:id="@+id/menu_key_view_share_title"
android:showAsAction="never"
android:title="@string/menu_share_qr_code_fingerprint"/>
<item
android:id="@+id/menu_key_view_share_qr_code"
android:showAsAction="never"
android:title="@string/menu_share_qr_code"/>
<item
android:id="@+id/menu_key_view_share_nfc"
android:showAsAction="never"
android:title="@string/menu_share_nfc"/>
<item
android:id="@+id/menu_key_view_share_clipboard"
android:showAsAction="never"
android:title="@string/menu_copy_to_clipboard"/>
android:title="@string/menu_share_title">
<menu>
<item
android:id="@+id/menu_key_view_share_default"
android:showAsAction="never"
android:title="@string/menu_share_default"/>
<item
android:id="@+id/menu_key_view_share_qr_code"
android:showAsAction="never"
android:title="@string/menu_share_qr_code"/>
<item
android:id="@+id/menu_key_view_share_nfc"
android:showAsAction="never"
android:title="@string/menu_share_nfc"/>
<item
android:id="@+id/menu_key_view_share_clipboard"
android:showAsAction="never"
android:title="@string/menu_copy_to_clipboard"/>
</menu>
</item>
</menu>
</item>
<item

View File

@ -84,10 +84,15 @@
<string name="menu_key_server">Import from key server</string>
<string name="menu_update_key">Update from key server</string>
<string name="menu_export_key_to_server">Upload to key server</string>
<string name="menu_share">Share with…</string>
<string name="menu_share_qr_code">Share with QR Code (whole key)</string>
<string name="menu_share_qr_code_fingerprint">Share with QR Code (fingerprint)</string>
<string name="menu_share_nfc">Share with NFC</string>
<string name="menu_share">Share</string>
<string name="menu_share_title_fingerprint">Share fingerprint…</string>
<string name="menu_share_title">Share data…</string>
<string name="menu_share_default_fingerprint">with…</string>
<string name="menu_share_default">with…</string>
<string name="menu_share_qr_code">with QR Code</string>
<string name="menu_share_qr_code_fingerprint">with QR Code</string>
<string name="menu_share_nfc">with NFC</string>
<string name="menu_copy_to_clipboard">Copy to clipboard</string>
<string name="menu_sign_key">Sign key</string>
<string name="menu_beam_preferences">Beam settings</string>
@ -211,6 +216,7 @@
<string name="key_copied_to_clipboard">Key has been copied to the clipboard!</string>
<string name="key_has_already_been_signed">Key has already been signed!</string>
<string name="select_key_to_sign">Please select a key to be used for signing!</string>
<string name="key_too_big_for_sharing">Key is too big to be shared this way!</string>
<!--
errors

View File

@ -166,8 +166,11 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN
mExportHelper.showExportKeysDialog(mDataUri, Id.type.public_key, Constants.path.APP_DIR
+ "/pubexport.asc");
return true;
case R.id.menu_key_view_share_default_fingerprint:
shareKey(mDataUri, true);
return true;
case R.id.menu_key_view_share_default:
shareKey(mDataUri);
shareKey(mDataUri, false);
return true;
case R.id.menu_key_view_share_qr_code_fingerprint:
shareKeyQrCode(mDataUri, true);
@ -435,15 +438,37 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements CreateN
startActivity(signIntent);
}
private void shareKey(Uri dataUri) {
// get public keyring as ascii armored string
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this, dataUri,
new long[] { masterKeyId });
private void shareKey(Uri dataUri, boolean fingerprintOnly) {
String content = null;
if (fingerprintOnly) {
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
// TODO: dublicated in ShareQrCodeDialog
content = "openpgp4fpr:";
String fingerprint = PgpKeyHelper.convertKeyToHex(masterKeyId);
content = content + fingerprint;
} else {
// get public keyring as ascii armored string
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this,
dataUri, new long[] { masterKeyId });
content = keyringArmored.get(0);
// Android will fail with android.os.TransactionTooLargeException if key is too big
// see http://www.lonestarprod.com/?p=34
if (content.length() >= 86389) {
Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing,
Toast.LENGTH_LONG).show();
return;
}
}
// let user choose application
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, keyringArmored.get(0));
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent,
getResources().getText(R.string.action_share_key_with)));