From 511cc4af9f7e9c9a0282a7b256f0503b8c8fe246 Mon Sep 17 00:00:00 2001 From: Dominik Date: Wed, 12 Sep 2012 16:03:39 +0200 Subject: [PATCH] better definition of intent filters to open from file managers --- org_apg/AndroidManifest.xml | 144 ++++++++++-------- org_apg/res/values/strings.xml | 7 +- .../android/apg/ui/DecryptActivity.java | 59 ++++--- .../android/apg/ui/EncryptActivity.java | 8 +- .../android/apg/ui/KeyListActivity.java | 9 +- 5 files changed, 130 insertions(+), 97 deletions(-) diff --git a/org_apg/AndroidManifest.xml b/org_apg/AndroidManifest.xml index 2fdbd5e45..fe1bffaee 100644 --- a/org_apg/AndroidManifest.xml +++ b/org_apg/AndroidManifest.xml @@ -18,10 +18,31 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + @@ -205,7 +259,7 @@ - + @@ -227,47 +281,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - Version: - Import key (only locally) Import, Sign, and upload key Scan qr code again Finish + + APG: Decrypt File + APG: Import Key + APG: Encrypt + APG: Decrypt + \ No newline at end of file diff --git a/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java index b2463c5ac..e9b26935c 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java @@ -251,26 +251,39 @@ public class DecryptActivity extends SherlockFragmentActivity { mSource.showNext(); } + boolean decryptImmediately = false; + mIntent = getIntent(); + + // handled separately from other actions as it uses mIntent.setAction() if (Intent.ACTION_VIEW.equals(mIntent.getAction())) { - Uri uri = mIntent.getData(); - try { - InputStream attachment = getContentResolver().openInputStream(uri); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - byte bytes[] = new byte[1 << 16]; - int length; - while ((length = attachment.read(bytes)) > 0) { - byteOut.write(bytes, 0, length); - } - byteOut.close(); - String data = new String(byteOut.toByteArray()); - mMessage.setText(data); - } catch (FileNotFoundException e) { - // ignore, then - } catch (IOException e) { - // ignore, then - } - } else if (ACTION_DECRYPT.equals(mIntent.getAction())) { + + // TODO: old implementation of ACTION_VIEW. Is this used in K9? + + // Uri uri = mIntent.getData(); + // try { + // InputStream attachment = getContentResolver().openInputStream(uri); + // ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + // byte bytes[] = new byte[1 << 16]; + // int length; + // while ((length = attachment.read(bytes)) > 0) { + // byteOut.write(bytes, 0, length); + // } + // byteOut.close(); + // String data = new String(byteOut.toByteArray()); + // mMessage.setText(data); + // } catch (FileNotFoundException e) { + // // ignore, then + // } catch (IOException e) { + // // ignore, then + // } + + // same as ACTION_DECRYPT_FILE but decrypt it immediately + mIntent.setAction(ACTION_DECRYPT_FILE); + decryptImmediately = true; + } + + if (ACTION_DECRYPT.equals(mIntent.getAction())) { Log.d(Constants.TAG, "Apg Intent DECRYPT startet"); Bundle extras = mIntent.getExtras(); if (extras == null) { @@ -317,10 +330,7 @@ public class DecryptActivity extends SherlockFragmentActivity { mReplyTo = extras.getString(EXTRA_REPLY_TO); mSubject = extras.getString(EXTRA_SUBJECT); } else if (ACTION_DECRYPT_FILE.equals(mIntent.getAction())) { - mInputFilename = mIntent.getDataString(); - if ("file".equals(mIntent.getScheme())) { - mInputFilename = Uri.decode(mInputFilename.substring(7)); - } + mInputFilename = mIntent.getData().getPath(); mFilename.setText(mInputFilename); guessOutputFilename(); mSource.setInAnimation(null); @@ -420,8 +430,9 @@ public class DecryptActivity extends SherlockFragmentActivity { updateSource(); - if (mSource.getCurrentView().getId() == R.id.sourceMessage - && (mMessage.getText().length() > 0 || mData != null || mContentUri != null)) { + if (decryptImmediately + || (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText() + .length() > 0 || mData != null || mContentUri != null))) { decryptClicked(); } } diff --git a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java index 831f33273..a65f2fc72 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java @@ -432,11 +432,9 @@ public class EncryptActivity extends SherlockFragmentActivity { mSource.showNext(); } } else if (ACTION_ENCRYPT_FILE.equals(mIntent.getAction())) { - if ("file".equals(mIntent.getScheme())) { - mInputFilename = Uri.decode(mIntent.getDataString().replace("file://", "")); - mFilename.setText(mInputFilename); - guessOutputFilename(); - } + mInputFilename = mIntent.getData().getPath(); + mFilename.setText(mInputFilename); + guessOutputFilename(); mSource.setInAnimation(null); mSource.setOutAnimation(null); while (mSource.getCurrentView().getId() != R.id.sourceFile) { diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java index f992862a0..c77e8b01b 100644 --- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java +++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java @@ -44,7 +44,6 @@ import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteQueryBuilder; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -143,9 +142,15 @@ public class KeyListActivity extends SherlockFragmentActivity { mListAdapter = new KeyListAdapter(this, searchString); mList.setAdapter(mListAdapter); + // handled separately from other actions as it uses intent.setAction() + if (Intent.ACTION_VIEW.equals(intent.getAction())) { + // same as ACTION_IMPORT invoked from a file manager + intent.setAction(ACTION_IMPORT); + } + if (ACTION_IMPORT.equals(intent.getAction())) { if ("file".equals(intent.getScheme()) && intent.getDataString() != null) { - mImportFilename = Uri.decode(intent.getDataString().replace("file://", "")); + mImportFilename = intent.getData().getPath(); } else { mImportData = intent.getStringExtra(EXTRA_TEXT); }