mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
use uris for clipboard data if available in DecryptActivity
This commit is contained in:
parent
09da00d800
commit
22246afa4b
@ -22,6 +22,9 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -32,9 +35,7 @@ import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
||||
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
|
||||
@ -87,7 +88,6 @@ public class DecryptActivity extends BaseActivity {
|
||||
|
||||
try {
|
||||
|
||||
// TODO handle ACTION_DECRYPT_FROM_CLIPBOARD
|
||||
switch (action) {
|
||||
case Intent.ACTION_SEND: {
|
||||
// When sending to Keychain Decrypt via share menu
|
||||
@ -124,9 +124,25 @@ public class DecryptActivity extends BaseActivity {
|
||||
case ACTION_DECRYPT_FROM_CLIPBOARD: {
|
||||
action = ACTION_DECRYPT_DATA;
|
||||
|
||||
CharSequence clipboardText = ClipboardReflection.getClipboardText(this);
|
||||
String text = PgpHelper.getPgpContent(clipboardText);
|
||||
Uri uri = readToTempFile(text);
|
||||
ClipboardManager clipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = clipMan.getPrimaryClip();
|
||||
|
||||
// check if data is available as uri
|
||||
Uri uri = null;
|
||||
for (int i = 0; i < clip.getItemCount(); i++) {
|
||||
ClipData.Item item = clip.getItemAt(i);
|
||||
Uri itemUri = item.getUri();
|
||||
if (itemUri != null) {
|
||||
uri = itemUri;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, coerce to text (almost always possible) and work from there
|
||||
if (uri == null) {
|
||||
String text = clip.getItemAt(0).coerceToText(this).toString();
|
||||
uri = readToTempFile(text);
|
||||
}
|
||||
uris.add(uri);
|
||||
|
||||
break;
|
||||
|
@ -51,7 +51,6 @@ import android.widget.TextView;
|
||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpConstants;
|
||||
@ -422,9 +421,8 @@ public class EncryptFilesFragment
|
||||
}
|
||||
|
||||
ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
// ClipData clip = ClipData.newUri(getActivity().getContentResolver(),
|
||||
// getString(R.string.label_clip_title), mOutputUris.get(0));
|
||||
ClipData clip = new ClipData(getString(R.string.label_clip_title),
|
||||
// make available as application/pgp-encrypted
|
||||
new String[] { "text/plain" },
|
||||
new ClipData.Item(mOutputUris.get(0))
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user