diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7d3f09121..e57515bcd 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -199,5 +199,6 @@ + diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index a610cad95..ad53b44f5 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -278,4 +278,9 @@ Private Schlüssel suchen Filter: \"%s\" + + schnell + langsam + sehr langsam + diff --git a/res/values/strings.xml b/res/values/strings.xml index 26068a317..85d7d4b77 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -255,5 +255,10 @@ Search Secret Keys Filter: \"%s\" + + fast + slow + very slow + diff --git a/src/org/thialfihar/android/apg/DecryptActivity.java b/src/org/thialfihar/android/apg/DecryptActivity.java index 85be8c80b..98480bbf7 100644 --- a/src/org/thialfihar/android/apg/DecryptActivity.java +++ b/src/org/thialfihar/android/apg/DecryptActivity.java @@ -209,6 +209,10 @@ public class DecryptActivity extends BaseActivity { mInputFilename = mIntent.getDataString().replace("file://", ""); mFilename.setText(mInputFilename); guessOutputFilename(); + } else if ("content".equals(mIntent.getScheme())) { + mInputFilename = mIntent.getDataString(); + mFilename.setText(mInputFilename); + guessOutputFilename(); } mSource.setInAnimation(null); mSource.setOutAnimation(null); @@ -363,12 +367,14 @@ public class DecryptActivity extends BaseActivity { return; } - File file = new File(mInputFilename); - if (!file.exists() || !file.isFile()) { - Toast.makeText(this, getString(R.string.errorMessage, - getString(R.string.error_fileNotFound)), - Toast.LENGTH_SHORT).show(); - return; + if (mInputFilename.startsWith("file")) { + File file = new File(mInputFilename); + if (!file.exists() || !file.isFile()) { + Toast.makeText(this, getString(R.string.errorMessage, + getString(R.string.error_fileNotFound)), + Toast.LENGTH_SHORT).show(); + return; + } } } @@ -388,7 +394,11 @@ public class DecryptActivity extends BaseActivity { try { InputStream in; if (mDecryptTarget == Id.target.file) { - in = new FileInputStream(mInputFilename); + if (mInputFilename.startsWith("file")) { + in = new FileInputStream(mInputFilename); + } else { + in = getContentResolver().openInputStream(Uri.parse(mInputFilename)); + } } else { in = new ByteArrayInputStream(mMessage.getText().toString().getBytes()); } @@ -403,7 +413,11 @@ public class DecryptActivity extends BaseActivity { // look at the file/message again to check whether there's // symmetric encryption data in there if (mDecryptTarget == Id.target.file) { - in = new FileInputStream(mInputFilename); + if (mInputFilename.startsWith("file")) { + in = new FileInputStream(mInputFilename); + } else { + in = getContentResolver().openInputStream(Uri.parse(mInputFilename)); + } } else { in = new ByteArrayInputStream(mMessage.getText().toString().getBytes()); } @@ -488,10 +502,22 @@ public class DecryptActivity extends BaseActivity { out = new ByteArrayOutputStream(); size = messageData.getBytes().length; } else { - in = new PositionAwareInputStream(new FileInputStream(mInputFilename)); + if (mInputFilename.startsWith("content")) { + InputStream tmp = getContentResolver().openInputStream(Uri.parse(mInputFilename)); + size = 0; + long n = 0; + byte dummy[] = new byte[0x10000]; + while ((n = tmp.read(dummy)) > 0) { + size += n; + } + in = new PositionAwareInputStream( + getContentResolver().openInputStream(Uri.parse(mInputFilename))); + } else { + in = new PositionAwareInputStream(new FileInputStream(mInputFilename)); + File file = new File(mInputFilename); + size = file.length(); + } out = new FileOutputStream(mOutputFilename); - File file = new File(mInputFilename); - size = file.length(); } if (mSignedOnly) { diff --git a/src/org/thialfihar/android/apg/EncryptActivity.java b/src/org/thialfihar/android/apg/EncryptActivity.java index e0a38f061..f4fa6ae74 100644 --- a/src/org/thialfihar/android/apg/EncryptActivity.java +++ b/src/org/thialfihar/android/apg/EncryptActivity.java @@ -203,10 +203,11 @@ public class EncryptActivity extends BaseActivity { mFileCompression = (Spinner) findViewById(R.id.fileCompression); Choice[] choices = new Choice[] { - new Choice(Id.choice.compression.none, getString(R.string.choice_none)), - new Choice(Id.choice.compression.zip, "ZIP"), - new Choice(Id.choice.compression.bzip2, "BZIP2"), - new Choice(Id.choice.compression.zlib, "ZLIB"), + new Choice(Id.choice.compression.none, getString(R.string.choice_none) + + " (" + getString(R.string.fast) + ")"), + new Choice(Id.choice.compression.zip, "ZIP (" + getString(R.string.fast) + ")"), + new Choice(Id.choice.compression.zlib, "ZLIB (" + getString(R.string.fast) + ")"), + new Choice(Id.choice.compression.bzip2, "BZIP2 (" + getString(R.string.very_slow) + ")"), }; ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, choices); @@ -470,12 +471,14 @@ public class EncryptActivity extends BaseActivity { return; } - File file = new File(mInputFilename); - if (!file.exists() || !file.isFile()) { - Toast.makeText(this, getString(R.string.errorMessage, - getString(R.string.error_fileNotFound)), - Toast.LENGTH_SHORT).show(); - return; + if (!mInputFilename.startsWith("content")) { + File file = new File(mInputFilename); + if (!file.exists() || !file.isFile()) { + Toast.makeText(this, getString(R.string.errorMessage, + getString(R.string.error_fileNotFound)), + Toast.LENGTH_SHORT).show(); + return; + } } } @@ -576,11 +579,22 @@ public class EncryptActivity extends BaseActivity { } } - in = new FileInputStream(mInputFilename); + if (mInputFilename.startsWith("content")) { + in = getContentResolver().openInputStream(Uri.parse(mInputFilename)); + size = 0; + long n = 0; + byte dummy[] = new byte[0x10000]; + while ((n = in.read(dummy)) > 0) { + size += n; + } + in = getContentResolver().openInputStream(Uri.parse(mInputFilename)); + } else { + in = new FileInputStream(mInputFilename); + File file = new File(mInputFilename); + size = file.length(); + } out = new FileOutputStream(mOutputFilename); - File file = new File(mInputFilename); - size = file.length(); useAsciiArmour = mAsciiArmour.isChecked(); compressionId = ((Choice) mFileCompression.getSelectedItem()).getId(); } else { diff --git a/src/org/thialfihar/android/apg/PreferencesActivity.java b/src/org/thialfihar/android/apg/PreferencesActivity.java index 3f3a709a9..7e89e40a7 100644 --- a/src/org/thialfihar/android/apg/PreferencesActivity.java +++ b/src/org/thialfihar/android/apg/PreferencesActivity.java @@ -18,6 +18,7 @@ package org.thialfihar.android.apg; import org.bouncycastle2.bcpg.HashAlgorithmTags; import org.bouncycastle2.openpgp.PGPEncryptedData; +import org.thialfihar.android.apg.utils.Choice; import android.os.Bundle; import android.preference.CheckBoxPreference; @@ -118,12 +119,16 @@ public class PreferencesActivity extends PreferenceActivity { mMessageCompression = (IntegerListPreference) findPreference(Constants.pref.default_message_compression); valueIds = new int[] { - Id.choice.compression.none, Id.choice.compression.zip, - Id.choice.compression.bzip2, Id.choice.compression.zlib, + Id.choice.compression.none, + Id.choice.compression.zip, + Id.choice.compression.zlib, + Id.choice.compression.bzip2, }; entries = new String[] { - getString(R.string.choice_none), "ZIP", - "BZIP2", "ZLIB", + getString(R.string.choice_none) + " (" + getString(R.string.fast) + ")", + "ZIP (" + getString(R.string.fast) + ")", + "ZLIB (" + getString(R.string.fast) + ")", + "BZIP2 (" + getString(R.string.very_slow) + ")", }; values = new String[valueIds.length]; for (int i = 0; i < values.length; ++i) {