diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-10-21 22:33:46 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-10-21 22:33:46 +0200 |
commit | 477a189c3f11e4863bc771ab7cbe9e39f8ae154b (patch) | |
tree | 4b04729e11d81982b1c438223657868bd68a8153 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui | |
parent | 97ca5091c237ff185a1a5651ff54752a3e49adc3 (diff) | |
parent | 7eb9f5d5cfb3e735076ea019013f89ca60ed5804 (diff) | |
download | open-keychain-477a189c3f11e4863bc771ab7cbe9e39f8ae154b.tar.gz open-keychain-477a189c3f11e4863bc771ab7cbe9e39f8ae154b.tar.bz2 open-keychain-477a189c3f11e4863bc771ab7cbe9e39f8ae154b.zip |
Merge branch 'master' of github.com:open-keychain/open-keychain
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
3 files changed, 69 insertions, 6 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java index a5f9dc885..c7ad4bd65 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -322,6 +322,29 @@ public class DecryptListFragment Uri uri = mCurrentInputUri; mCurrentInputUri = null; + Activity activity = getActivity(); + + boolean isSingleInput = mInputDataResults.isEmpty() && mPendingInputUris.isEmpty(); + if (isSingleInput) { + + // there is always at least one mMetadata object, so we know this is >= 1 already + boolean isSingleMetadata = result.mMetadata.size() == 1; + OpenPgpMetadata metadata = result.mMetadata.get(0); + boolean isText = "text/plain".equals(metadata.getMimeType()); + boolean isOverSized = metadata.getOriginalSize() > Constants.TEXT_LENGTH_LIMIT; + + if (isSingleMetadata && isText && !isOverSized) { + Intent displayTextIntent = new Intent(activity, DisplayTextActivity.class) + .setDataAndType(result.mOutputUris.get(0), "text/plain") + .putExtra(DisplayTextActivity.EXTRA_RESULT, result.mDecryptVerifyResult) + .putExtra(DisplayTextActivity.EXTRA_METADATA, metadata); + activity.startActivity(displayTextIntent); + activity.finish(); + return; + } + + } + mInputDataResults.put(uri, result); processResult(uri); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java index 4bcca09f1..2fa1aa1c2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DisplayTextActivity.java @@ -28,9 +28,12 @@ import android.support.v4.app.Fragment; import android.widget.Toast; import org.openintents.openpgp.OpenPgpMetadata; +import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.ui.base.BaseActivity; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.FileHelper; public class DisplayTextActivity extends BaseActivity { @@ -73,6 +76,11 @@ public class DisplayTextActivity extends BaseActivity { } if (plaintext != null) { + if (plaintext.length() > Constants.TEXT_LENGTH_LIMIT) { + plaintext = plaintext.substring(0, Constants.TEXT_LENGTH_LIMIT); + Notify.create(this, R.string.snack_text_too_long, Style.WARN).show(); + } + loadFragment(plaintext, result); } else { Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); 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..201465b52 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,38 @@ 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, R.string.toast_wrong_mimetype, 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, R.string.toast_no_text, Toast.LENGTH_LONG).show(); + finish(); + return; + } + if (sharedText != null) { + if (sharedText.length() > Constants.TEXT_LENGTH_LIMIT) { + sharedText = sharedText.substring(0, Constants.TEXT_LENGTH_LIMIT); + Notify.create(this, R.string.snack_shared_text_too_long, Style.WARN).show(); + } + // 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); |