diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-10-21 21:55:15 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-10-21 21:55:15 +0200 |
commit | a4b99ae3506545a675918bb3f182b9b142e6654b (patch) | |
tree | 72c53dd3d5e07136ea1f8387b9044e7e00d152c7 /OpenKeychain/src | |
parent | d149bfd3dbc1010d661b81e72e442c4d4f7b9fa0 (diff) | |
download | open-keychain-a4b99ae3506545a675918bb3f182b9b142e6654b.tar.gz open-keychain-a4b99ae3506545a675918bb3f182b9b142e6654b.tar.bz2 open-keychain-a4b99ae3506545a675918bb3f182b9b142e6654b.zip |
encrypttext: handle input via Intent.EXTRA_STREAM in addition to Intent.EXTRA_TEXT
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java index a849cdf12..6a7955fc5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java @@ -18,14 +18,22 @@ package org.sufficientlysecure.keychain.ui; + +import java.io.IOException; + import android.app.Activity; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; -import android.view.View; +import android.widget.Toast; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; +import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.Log; public class EncryptTextActivity extends EncryptActivity { @@ -57,14 +65,34 @@ public class EncryptTextActivity extends EncryptActivity { // When sending to OpenKeychain Encrypt via share menu if ("text/plain".equals(type)) { - String sharedText = extras.getString(Intent.EXTRA_TEXT); - if (sharedText != null) { - // handle like normal text encryption, override action and extras to later - // executeServiceMethod ACTION_ENCRYPT_TEXT in main actions - extras.putString(EXTRA_TEXT, sharedText); + Toast.makeText(this, "Wrong data type, expected text!", Toast.LENGTH_LONG).show(); + finish(); + return; + } + + String sharedText; + if (extras.containsKey(Intent.EXTRA_TEXT)) { + sharedText = extras.getString(Intent.EXTRA_TEXT); + } else if (extras.containsKey(Intent.EXTRA_STREAM)) { + try { + sharedText = FileHelper.readTextFromUri(this, extras.<Uri>getParcelable(Intent.EXTRA_STREAM), null); + } catch (IOException e) { + Toast.makeText(this, R.string.error_preparing_data, Toast.LENGTH_LONG).show(); + finish(); + return; } + } else { + Toast.makeText(this, "No text in shared data!", Toast.LENGTH_LONG).show(); + finish(); + return; + } + if (sharedText != null) { + // handle like normal text encryption, override action and extras to later + // executeServiceMethod ACTION_ENCRYPT_TEXT in main actions + extras.putString(EXTRA_TEXT, sharedText); } + } String textData = extras.getString(EXTRA_TEXT); |