use uris for clipboard data if available in DecryptActivity

This commit is contained in:
Vincent Breitmoser 2015-06-20 05:29:22 +02:00
parent 09da00d800
commit 22246afa4b
2 changed files with 23 additions and 9 deletions

View File

@ -22,6 +22,9 @@ import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import android.app.Activity; import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -32,9 +35,7 @@ import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.BaseActivity;
@ -87,7 +88,6 @@ public class DecryptActivity extends BaseActivity {
try { try {
// TODO handle ACTION_DECRYPT_FROM_CLIPBOARD
switch (action) { switch (action) {
case Intent.ACTION_SEND: { case Intent.ACTION_SEND: {
// When sending to Keychain Decrypt via share menu // When sending to Keychain Decrypt via share menu
@ -124,9 +124,25 @@ public class DecryptActivity extends BaseActivity {
case ACTION_DECRYPT_FROM_CLIPBOARD: { case ACTION_DECRYPT_FROM_CLIPBOARD: {
action = ACTION_DECRYPT_DATA; action = ACTION_DECRYPT_DATA;
CharSequence clipboardText = ClipboardReflection.getClipboardText(this); ClipboardManager clipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
String text = PgpHelper.getPgpContent(clipboardText); ClipData clip = clipMan.getPrimaryClip();
Uri uri = readToTempFile(text);
// 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); uris.add(uri);
break; break;

View File

@ -51,7 +51,6 @@ import android.widget.TextView;
import org.spongycastle.bcpg.CompressionAlgorithmTags; import org.spongycastle.bcpg.CompressionAlgorithmTags;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpConstants; import org.sufficientlysecure.keychain.pgp.PgpConstants;
@ -422,9 +421,8 @@ public class EncryptFilesFragment
} }
ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); 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), ClipData clip = new ClipData(getString(R.string.label_clip_title),
// make available as application/pgp-encrypted
new String[] { "text/plain" }, new String[] { "text/plain" },
new ClipData.Item(mOutputUris.get(0)) new ClipData.Item(mOutputUris.get(0))
); );