aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-06-22 23:44:03 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-06-22 23:48:41 +0200
commit4826e0a8c89e43401a3188d7a4d51cdbfd64c37a (patch)
treea16b2c52f430f87d6061d68a2366893d6bc1f32e /OpenKeychain/src/main
parent8d1dc940c4d1e864aad767e298373b02da55f556 (diff)
downloadopen-keychain-4826e0a8c89e43401a3188d7a4d51cdbfd64c37a.tar.gz
open-keychain-4826e0a8c89e43401a3188d7a4d51cdbfd64c37a.tar.bz2
open-keychain-4826e0a8c89e43401a3188d7a4d51cdbfd64c37a.zip
move select file logic into EncryptDecryptOverviewFragment
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java55
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java145
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java45
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java8
-rw-r--r--OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml30
-rw-r--r--OpenKeychain/src/main/res/values/strings.xml7
6 files changed, 63 insertions, 227 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java
index d14c8555c..4375be740 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java
@@ -17,6 +17,7 @@
package org.sufficientlysecure.keychain.ui;
+
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -33,7 +34,6 @@ 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.provider.TemporaryStorageProvider;
@@ -43,13 +43,7 @@ import org.sufficientlysecure.keychain.ui.base.BaseActivity;
public class DecryptActivity extends BaseActivity {
/* Intents */
- public static final String ACTION_DECRYPT_DATA = OpenKeychainIntents.DECRYPT_DATA;
- // TODO handle this intent
- // public static final String ACTION_DECRYPT_TEXT = OpenKeychainIntents.DECRYPT_TEXT;
- public static final String ACTION_DECRYPT_FROM_CLIPBOARD = Constants.INTENT_PREFIX + "DECRYPT_DATA_CLIPBOARD";
-
- // intern
- public static final String ACTION_DECRYPT_DATA_OPEN = Constants.INTENT_PREFIX + "DECRYPT_DATA_OPEN";
+ public static final String ACTION_DECRYPT_FROM_CLIPBOARD = "DECRYPT_DATA_CLIPBOARD";
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -86,6 +80,13 @@ public class DecryptActivity extends BaseActivity {
String action = intent.getAction();
+ if (action == null) {
+ Toast.makeText(this, "Error: No action specified!", Toast.LENGTH_LONG).show();
+ setResult(Activity.RESULT_CANCELED);
+ finish();
+ return;
+ }
+
try {
switch (action) {
@@ -93,8 +94,6 @@ public class DecryptActivity extends BaseActivity {
// When sending to Keychain Decrypt via share menu
// Binary via content provider (could also be files)
// override uri to get stream from send
- action = ACTION_DECRYPT_DATA;
-
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
uris.add(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM));
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
@@ -107,8 +106,6 @@ public class DecryptActivity extends BaseActivity {
}
case Intent.ACTION_SEND_MULTIPLE: {
- action = ACTION_DECRYPT_DATA;
-
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
@@ -122,8 +119,6 @@ public class DecryptActivity extends BaseActivity {
}
case ACTION_DECRYPT_FROM_CLIPBOARD: {
- action = ACTION_DECRYPT_DATA;
-
ClipboardManager clipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipMan.getPrimaryClip();
@@ -148,11 +143,9 @@ public class DecryptActivity extends BaseActivity {
break;
}
+ // for everything else, just work on the intent data
+ case OpenKeychainIntents.DECRYPT_DATA:
case Intent.ACTION_VIEW:
- // Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
- action = ACTION_DECRYPT_DATA;
-
- // fallthrough
default:
uris.add(intent.getData());
@@ -165,19 +158,15 @@ public class DecryptActivity extends BaseActivity {
return;
}
- if (ACTION_DECRYPT_DATA.equals(action)) {
- // Definitely need a data uri with the decrypt_data intent
- if (uris.isEmpty()) {
- Toast.makeText(this, "No data to decrypt!", Toast.LENGTH_LONG).show();
- setResult(Activity.RESULT_CANCELED);
- finish();
- }
- displayListFragment(uris);
+ // Definitely need a data uri with the decrypt_data intent
+ if (uris.isEmpty()) {
+ Toast.makeText(this, "No data to decrypt!", Toast.LENGTH_LONG).show();
+ setResult(Activity.RESULT_CANCELED);
+ finish();
return;
}
- boolean showOpenDialog = ACTION_DECRYPT_DATA_OPEN.equals(action);
- displayInputFragment(showOpenDialog);
+ displayListFragment(uris);
}
@@ -189,16 +178,6 @@ public class DecryptActivity extends BaseActivity {
return tempFile;
}
- public void displayInputFragment(boolean showOpenDialog) {
- DecryptFilesInputFragment frag = DecryptFilesInputFragment.newInstance(showOpenDialog);
-
- // Add the fragment to the 'fragment_container' FrameLayout
- // NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
- getSupportFragmentManager().beginTransaction()
- .replace(R.id.decrypt_files_fragment_container, frag)
- .commit();
- }
-
public void displayListFragment(ArrayList<Uri> inputUris) {
DecryptListFragment frag = DecryptListFragment.newInstance(inputUris);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java
deleted file mode 100644
index 93066ee32..000000000
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesInputFragment.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
- * Copyright (C) 2015 Vincent Breitmoser <look@my.amazin.horse>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.sufficientlysecure.keychain.ui;
-
-import java.util.ArrayList;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.ui.util.Notify;
-import org.sufficientlysecure.keychain.util.FileHelper;
-
-public class DecryptFilesInputFragment extends Fragment {
- public static final String ARG_URI = "uri";
- public static final String ARG_OPEN_DIRECTLY = "open_directly";
-
- private static final int REQUEST_CODE_INPUT = 0x00007003;
-
- private TextView mFilename;
- private View mDecryptButton;
-
- private Uri mInputUri = null;
-
- public static DecryptFilesInputFragment newInstance(boolean openDirectly) {
- DecryptFilesInputFragment frag = new DecryptFilesInputFragment();
-
- Bundle args = new Bundle();
- args.putBoolean(ARG_OPEN_DIRECTLY, openDirectly);
-
- frag.setArguments(args);
-
- return frag;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.decrypt_files_input_fragment, container, false);
-
- mFilename = (TextView) view.findViewById(R.id.decrypt_files_filename);
- mDecryptButton = view.findViewById(R.id.decrypt_files_action_decrypt);
- view.findViewById(R.id.decrypt_files_browse).setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- FileHelper.openDocument(DecryptFilesInputFragment.this, "*/*", REQUEST_CODE_INPUT);
- } else {
- FileHelper.openFile(DecryptFilesInputFragment.this, mInputUri, "*/*",
- REQUEST_CODE_INPUT);
- }
- }
- });
- mDecryptButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- decryptAction();
- }
- });
-
- return view;
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
-
- outState.putParcelable(ARG_URI, mInputUri);
- }
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
-
- Bundle state = savedInstanceState != null ? savedInstanceState : getArguments();
- setInputUri(state.<Uri>getParcelable(ARG_URI));
-
- // should only come from args
- if (state.getBoolean(ARG_OPEN_DIRECTLY, false)) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- FileHelper.openDocument(DecryptFilesInputFragment.this, "*/*", REQUEST_CODE_INPUT);
- } else {
- FileHelper.openFile(DecryptFilesInputFragment.this, mInputUri, "*/*", REQUEST_CODE_INPUT);
- }
- }
- }
-
- private void setInputUri(Uri inputUri) {
- if (inputUri == null) {
- mInputUri = null;
- mFilename.setText("");
- return;
- }
-
- mInputUri = inputUri;
- mFilename.setText(FileHelper.getFilename(getActivity(), mInputUri));
- }
-
- private void decryptAction() {
- if (mInputUri == null) {
- Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show();
- return;
- }
-
- DecryptActivity activity = (DecryptActivity) getActivity();
-
- ArrayList<Uri> uris = new ArrayList<>();
- uris.add(mInputUri);
- activity.displayListFragment(uris);
- }
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode != REQUEST_CODE_INPUT) {
- return;
- }
-
- if (resultCode == Activity.RESULT_OK && data != null) {
- setInputUri(data.getData());
- }
- }
-
-}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java
index 6e5589940..566ad1d67 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptDecryptOverviewFragment.java
@@ -18,8 +18,15 @@
package org.sufficientlysecure.keychain.ui;
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+
+import android.app.Activity;
import android.content.Intent;
+import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
@@ -29,16 +36,17 @@ import android.view.ViewGroup;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
-import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
+import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker;
-
-import java.util.regex.Matcher;
+import org.sufficientlysecure.keychain.util.FileHelper;
public class EncryptDecryptOverviewFragment extends Fragment {
View mClipboardIcon;
+ private static final int REQUEST_CODE_INPUT = 0x00007003;
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -74,9 +82,11 @@ public class EncryptDecryptOverviewFragment extends Fragment {
mDecryptFile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- Intent filesDecrypt = new Intent(getActivity(), DecryptActivity.class);
- filesDecrypt.setAction(DecryptActivity.ACTION_DECRYPT_DATA_OPEN);
- startActivity(filesDecrypt);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ FileHelper.openDocument(EncryptDecryptOverviewFragment.this, "*/*", REQUEST_CODE_INPUT);
+ } else {
+ FileHelper.openFile(EncryptDecryptOverviewFragment.this, null, "*/*", REQUEST_CODE_INPUT);
+ }
}
});
@@ -135,12 +145,23 @@ public class EncryptDecryptOverviewFragment extends Fragment {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- // if a result has been returned, display a notify
- if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) {
- OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
- result.createNotify(getActivity()).show();
- } else {
- super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode != REQUEST_CODE_INPUT) {
+ return;
+ }
+
+ if (resultCode == Activity.RESULT_OK && data != null) {
+ Uri uri = data.getData();
+ if (uri == null) {
+ Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR).show(this);
+ return;
+ }
+
+ Intent intent = new Intent(getActivity(), DecryptActivity.class);
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setData(uri);
+ startActivity(intent);
+
}
}
+
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
index 558ab9a85..e223217ef 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelper.java
@@ -53,7 +53,6 @@ public class FileHelper {
/**
* Checks if external storage is mounted if file is located on external storage
*
- * @param file
* @return true if storage is mounted
*/
public static boolean isStorageMounted(String file) {
@@ -70,7 +69,6 @@ public class FileHelper {
* Opens the preferred installed file manager on Android and shows a toast if no manager is
* installed.
*
- * @param fragment
* @param last default selected Uri, not supported by all file managers
* @param mimeType can be text/plain for example
* @param requestCode requestCode used to identify the result coming back from file manager to
@@ -145,7 +143,6 @@ public class FileHelper {
/**
* Opens the storage browser on Android 4.4 or later for opening a file
*
- * @param fragment
* @param mimeType can be text/plain for example
* @param multiple allow file chooser to return multiple files
* @param requestCode used to identify the result coming back from storage browser onActivityResult() in your
@@ -163,7 +160,6 @@ public class FileHelper {
/**
* Opens the storage browser on Android 4.4 or later for saving a file
*
- * @param fragment
* @param mimeType can be text/plain for example
* @param suggestedName a filename desirable for the file to be saved
* @param requestCode used to identify the result coming back from storage browser onActivityResult() in your
@@ -271,7 +267,7 @@ public class FileHelper {
}
- public static interface FileDialogCallback {
- public void onFileSelected(File file, boolean checked);
+ public interface FileDialogCallback {
+ void onFileSelected(File file, boolean checked);
}
}
diff --git a/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml b/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml
index bd640d9af..394f14a34 100644
--- a/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml
+++ b/OpenKeychain/src/main/res/layout/encrypt_decrypt_overview_fragment.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="4dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
@@ -89,31 +90,16 @@
style="?android:attr/borderlessButtonStyle"
android:orientation="horizontal"
android:paddingLeft="8dp"
- android:paddingRight="0dp">
+ android:paddingRight="0dp"
+ tools:ignore="UseCompoundDrawables">
- <LinearLayout
+ <TextView
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="0dp"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
android:layout_weight="1"
- android:paddingRight="4dp"
- android:gravity="center_vertical"
- android:orientation="vertical">
-
- <TextView
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/btn_decrypt_clipboard" />
-
- <TextView
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textColor="@color/tertiary_text_light"
- android:text="@string/btn_decrypt_and_verify"
- android:gravity="center_vertical" />
-
- </LinearLayout>
+ android:layout_gravity="center_vertical"
+ android:text="@string/btn_decrypt_clipboard" />
<ImageView
android:id="@+id/clipboard_icon"
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index a076a72fa..a48e97284 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -55,7 +55,7 @@
<string name="section_key_server">"Keyserver"</string>
<string name="section_fingerprint">"Fingerprint"</string>
<string name="section_encrypt">"Encrypt"</string>
- <string name="section_decrypt">"Decrypt"</string>
+ <string name="section_decrypt">"Decrypt / Verify"</string>
<string name="section_current_expiry">"Current expiry"</string>
<string name="section_new_expiry">"New expiry"</string>
@@ -80,9 +80,8 @@
<string name="btn_add_files">"Add file(s)"</string>
<string name="btn_share_decrypted_text">"Share decrypted text"</string>
<string name="btn_copy_decrypted_text">"Copy decrypted text"</string>
- <string name="btn_decrypt_clipboard">"Decrypt text from clipboard"</string>
- <string name="btn_decrypt_and_verify">"and verify signatures"</string>
- <string name="btn_decrypt_files">"Decrypt files"</string>
+ <string name="btn_decrypt_clipboard">"Read from clipboard"</string>
+ <string name="btn_decrypt_files">"Select input file"</string>
<string name="btn_encrypt_files">"Encrypt files"</string>
<string name="btn_encrypt_text">"Encrypt text"</string>
<string name="btn_add_email">"Add additional email address"</string>