aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui
diff options
context:
space:
mode:
authormar-v-in <github@rvin.mooo.com>2014-07-02 00:34:21 +0200
committermar-v-in <github@rvin.mooo.com>2014-07-02 00:34:21 +0200
commit93eae114eac566a9ed2da6275c147b66ca480305 (patch)
treefed3c5614807522dc7a5ddce9bea40c061444fee /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui
parent35647734104471a6d35bc26a77682dd5531dd5e3 (diff)
downloadopen-keychain-93eae114eac566a9ed2da6275c147b66ca480305.tar.gz
open-keychain-93eae114eac566a9ed2da6275c147b66ca480305.tar.bz2
open-keychain-93eae114eac566a9ed2da6275c147b66ca480305.zip
Encrypt/Decrypt UI work
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java5
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java11
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivityInterface.java1
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java24
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java48
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java17
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java59
7 files changed, 99 insertions, 66 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
index 430f85b6f..520ef7567 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java
@@ -29,7 +29,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
-import android.widget.ImageButton;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
@@ -52,7 +51,6 @@ public class DecryptFileFragment extends DecryptFragment {
// view
private TextView mFilename;
private CheckBox mDeleteAfter;
- private ImageButton mBrowse;
private View mDecryptButton;
// model
@@ -67,10 +65,9 @@ public class DecryptFileFragment extends DecryptFragment {
View view = inflater.inflate(R.layout.decrypt_file_fragment, container, false);
mFilename = (TextView) view.findViewById(R.id.decrypt_file_filename);
- mBrowse = (ImageButton) view.findViewById(R.id.decrypt_file_browse);
mDeleteAfter = (CheckBox) view.findViewById(R.id.decrypt_file_delete_after_decryption);
mDecryptButton = view.findViewById(R.id.decrypt_file_action_decrypt);
- mBrowse.setOnClickListener(new View.OnClickListener() {
+ view.findViewById(R.id.decrypt_file_browse).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Constants.KITKAT) {
FileHelper.openDocument(DecryptFileFragment.this, "*/*", REQUEST_CODE_INPUT);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
index e93a63cc8..c77fe9ab8 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java
@@ -70,6 +70,7 @@ public class EncryptActivity extends DrawerActivity implements
// model used by message and file fragments
private long mEncryptionKeyIds[] = null;
+ private String mEncryptionUserIds[] = null;
private long mSigningKeyId = Constants.key.none;
private String mPassphrase;
private String mPassphraseAgain;
@@ -85,6 +86,11 @@ public class EncryptActivity extends DrawerActivity implements
}
@Override
+ public void onEncryptionUserSelected(String[] encryptionUserIds) {
+ mEncryptionUserIds = encryptionUserIds;
+ }
+
+ @Override
public void onPassphraseUpdate(String passphrase) {
mPassphrase = passphrase;
}
@@ -110,6 +116,11 @@ public class EncryptActivity extends DrawerActivity implements
}
@Override
+ public String[] getEncryptionUsers() {
+ return mEncryptionUserIds;
+ }
+
+ @Override
public String getPassphrase() {
return mPassphrase;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivityInterface.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivityInterface.java
index 0786b3a16..ca2ee3b55 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivityInterface.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivityInterface.java
@@ -23,6 +23,7 @@ public interface EncryptActivityInterface {
public long getSignatureKey();
public long[] getEncryptionKeys();
+ public String[] getEncryptionUsers();
public String getPassphrase();
public String getPassphraseAgain();
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java
index 51963e963..be845f05e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java
@@ -59,12 +59,15 @@ public class EncryptAsymmetricFragment extends Fragment {
// model
private long mSecretKeyId = Constants.key.none;
private long mEncryptionKeyIds[] = null;
+ private String mEncryptionUserIds[] = null;
// Container Activity must implement this interface
public interface OnAsymmetricKeySelection {
public void onSigningKeySelected(long signingKeyId);
public void onEncryptionKeysSelected(long[] encryptionKeyIds);
+
+ public void onEncryptionUserSelected(String[] encryptionUserIds);
}
@Override
@@ -91,6 +94,13 @@ public class EncryptAsymmetricFragment extends Fragment {
updateView();
}
+ private void setEncryptionUserIds(String[] encryptionUserIds) {
+ mEncryptionUserIds = encryptionUserIds;
+ // update key selection in EncryptActivity
+ mKeySelectionListener.onEncryptionUserSelected(encryptionUserIds);
+ updateView();
+ }
+
/**
* Inflate the layout for this fragment
*/
@@ -159,12 +169,14 @@ public class EncryptAsymmetricFragment extends Fragment {
if (preselectedEncryptionKeyIds != null) {
Vector<Long> goodIds = new Vector<Long>();
- for (int i = 0; i < preselectedEncryptionKeyIds.length; ++i) {
+ Vector<String> goodUserIds = new Vector<String>();
+ for (long preselectedId : preselectedEncryptionKeyIds) {
try {
- long id = providerHelper.getCachedPublicKeyRing(
- KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(
- preselectedEncryptionKeyIds[i])
- ).getMasterKeyId();
+ CachedPublicKeyRing ring = providerHelper.getCachedPublicKeyRing(
+ KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(preselectedId));
+ long id = ring.getMasterKeyId();
+ ring.getSplitPrimaryUserId();
+ goodUserIds.add(ring.getPrimaryUserId());
goodIds.add(id);
} catch (PgpGeneralException e) {
Log.e(Constants.TAG, "key not found!", e);
@@ -176,6 +188,7 @@ public class EncryptAsymmetricFragment extends Fragment {
keyIds[i] = goodIds.get(i);
}
setEncryptionKeyIds(keyIds);
+ setEncryptionUserIds(goodUserIds.toArray(new String[goodUserIds.size()]));
}
}
}
@@ -249,6 +262,7 @@ public class EncryptAsymmetricFragment extends Fragment {
Bundle bundle = data.getExtras();
setEncryptionKeyIds(bundle
.getLongArray(SelectPublicKeyActivity.RESULT_EXTRA_MASTER_KEY_IDS));
+ setEncryptionUserIds(bundle.getStringArray(SelectPublicKeyActivity.RESULT_EXTRA_USER_IDS));
}
break;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
index 2fabeb82c..3111e5c3e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
@@ -33,12 +33,13 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;
-import android.widget.ImageButton;
import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.pgp.KeyRing;
+import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
@@ -50,6 +51,8 @@ import org.sufficientlysecure.keychain.util.Choice;
import org.sufficientlysecure.keychain.util.Log;
import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
public class EncryptFileFragment extends Fragment {
public static final String ARG_URI = "uri";
@@ -65,8 +68,7 @@ public class EncryptFileFragment extends Fragment {
private Spinner mFileCompression = null;
private TextView mFilename = null;
private CheckBox mDeleteAfter = null;
- private CheckBox mShareAfter = null;
- private ImageButton mBrowse = null;
+ private View mShareFile;
private View mEncryptFile;
// model
@@ -94,13 +96,19 @@ public class EncryptFileFragment extends Fragment {
mEncryptFile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- encryptClicked();
+ encryptClicked(false);
+ }
+ });
+ mShareFile = view.findViewById(R.id.action_encrypt_share);
+ mShareFile.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ encryptClicked(true);
}
});
mFilename = (TextView) view.findViewById(R.id.filename);
- mBrowse = (ImageButton) view.findViewById(R.id.btn_browse);
- mBrowse.setOnClickListener(new View.OnClickListener() {
+ view.findViewById(R.id.btn_browse).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Constants.KITKAT) {
FileHelper.openDocument(EncryptFileFragment.this, "*/*", REQUEST_CODE_INPUT);
@@ -136,7 +144,6 @@ public class EncryptFileFragment extends Fragment {
}
mDeleteAfter = (CheckBox) view.findViewById(R.id.deleteAfterEncryption);
- mShareAfter = (CheckBox) view.findViewById(R.id.shareAfterEncryption);
mAsciiArmor = (CheckBox) view.findViewById(R.id.asciiArmor);
mAsciiArmor.setChecked(Preferences.getPreferences(getActivity()).getDefaultAsciiArmor());
@@ -181,7 +188,7 @@ public class EncryptFileFragment extends Fragment {
}
}
- private void encryptClicked() {
+ private void encryptClicked(boolean share) {
if (mInputUri == null) {
AppMsg.makeText(getActivity(), R.string.no_file_selected, AppMsg.STYLE_ALERT).show();
return;
@@ -236,10 +243,17 @@ public class EncryptFileFragment extends Fragment {
}
}
- showOutputFileDialog();
+ if (share) {
+ String targetName = FileHelper.getFilename(getActivity(), mInputUri) +
+ (mAsciiArmor.isChecked() ? ".asc" : ".gpg");
+ mOutputUri = TemporaryStorageProvider.createFile(getActivity(), targetName);
+ encryptStart(true);
+ } else {
+ showOutputFileDialog();
+ }
}
- private void encryptStart() {
+ private void encryptStart(final boolean share) {
if (mInputUri == null || mOutputUri == null) {
throw new IllegalStateException("Something went terribly wrong if this happens!");
}
@@ -300,11 +314,21 @@ public class EncryptFileFragment extends Fragment {
setInputUri(null);
}
- if (mShareAfter.isChecked()) {
+ if (share) {
// Share encrypted file
Intent sendFileIntent = new Intent(Intent.ACTION_SEND);
sendFileIntent.setType("*/*");
sendFileIntent.putExtra(Intent.EXTRA_STREAM, mOutputUri);
+ if (!mEncryptInterface.isModeSymmetric() && mEncryptInterface.getEncryptionUsers() != null) {
+ Set<String> users = new HashSet<String>();
+ for (String user : mEncryptInterface.getEncryptionUsers()) {
+ String[] userId = KeyRing.splitUserId(user);
+ if (userId[1] != null) {
+ users.add(userId[1]);
+ }
+ }
+ sendFileIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
+ }
startActivity(Intent.createChooser(sendFileIntent,
getString(R.string.title_share_file)));
}
@@ -336,7 +360,7 @@ public class EncryptFileFragment extends Fragment {
// This happens after output file was selected, so start our operation
if (resultCode == Activity.RESULT_OK && data != null) {
mOutputUri = data.getData();
- encryptStart();
+ encryptStart(false);
}
return;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java
index 8a6103b16..e4f63089f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptMessageFragment.java
@@ -36,12 +36,17 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.helper.Preferences;
+import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
public class EncryptMessageFragment extends Fragment {
public static final String ARG_TEXT = "text";
@@ -235,7 +240,17 @@ public class EncryptMessageFragment extends Fragment {
// Type is set to text/plain so that encrypted messages can
// be sent with Whatsapp, Hangouts, SMS etc...
sendIntent.setType("text/plain");
-
+ Log.d(Constants.TAG, "encrypt to:" + Arrays.toString(mEncryptInterface.getEncryptionUsers()));
+ if (!mEncryptInterface.isModeSymmetric() && mEncryptInterface.getEncryptionUsers() != null) {
+ Set<String> users = new HashSet<String>();
+ for (String user : mEncryptInterface.getEncryptionUsers()) {
+ String[] userId = KeyRing.splitUserId(user);
+ if (userId[1] != null) {
+ users.add(userId[1]);
+ }
+ }
+ sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
+ }
sendIntent.putExtra(Intent.EXTRA_TEXT, output);
startActivity(Intent.createChooser(sendIntent,
getString(R.string.title_share_with)));
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java
index f9111d885..27ce4faee 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java
@@ -25,6 +25,7 @@ import android.provider.DocumentsContract;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
+import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.FileHelper;
@@ -53,8 +54,8 @@ public class DeleteFileDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final FragmentActivity activity = getActivity();
- final Uri deleteUri = getArguments().containsKey(ARG_DELETE_URI) ? getArguments().<Uri>getParcelable(ARG_DELETE_URI) : null;
- String deleteFilename = FileHelper.getFilename(getActivity(), deleteUri);
+ final Uri deleteUri = getArguments().getParcelable(ARG_DELETE_URI);
+ final String deleteFilename = FileHelper.getFilename(getActivity(), deleteUri);
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
@@ -69,53 +70,23 @@ public class DeleteFileDialogFragment extends DialogFragment {
public void onClick(DialogInterface dialog, int id) {
dismiss();
+ // We can not securely delete Uris, so just use usual delete on them
if (Constants.KITKAT) {
- // We can not securely delete Documents, so just use usual delete on them
- if (DocumentsContract.deleteDocument(getActivity().getContentResolver(), deleteUri)) return;
- }
-
- // TODO!!! We can't delete files from Uri without trying to find it's real path
-
- /*
- // Send all information needed to service to edit key in other thread
- Intent intent = new Intent(activity, KeychainIntentService.class);
-
- // fill values for this action
- Bundle data = new Bundle();
-
- intent.setAction(KeychainIntentService.ACTION_DELETE_FILE_SECURELY);
- intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
-
- ProgressDialogFragment deletingDialog = ProgressDialogFragment.newInstance(
- getString(R.string.progress_deleting_securely),
- ProgressDialog.STYLE_HORIZONTAL,
- false,
- null);
-
- // Message is received after deleting is done in KeychainIntentService
- KeychainIntentServiceHandler saveHandler =
- new KeychainIntentServiceHandler(activity, deletingDialog) {
- public void handleMessage(Message message) {
- // handle messages by standard KeychainIntentHandler first
- super.handleMessage(message);
-
- if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
- Toast.makeText(activity, R.string.file_delete_successful,
- Toast.LENGTH_SHORT).show();
- }
+ if (DocumentsContract.deleteDocument(getActivity().getContentResolver(), deleteUri)) {
+ Toast.makeText(getActivity(), R.string.file_delete_successful, Toast.LENGTH_SHORT).show();
+ return;
}
- };
+ }
- // Create a new Messenger for the communication back
- Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
+ if (getActivity().getContentResolver().delete(deleteUri, null, null) > 0) {
+ Toast.makeText(getActivity(), R.string.file_delete_successful, Toast.LENGTH_SHORT).show();
+ return;
+ }
- // show progress dialog
- deletingDialog.show(activity.getSupportFragmentManager(), "deletingDialog");
+ Toast.makeText(getActivity(), getActivity().getString(R.string.error_file_delete_failed, deleteFilename), Toast.LENGTH_SHORT).show();
- // start service with intent
- activity.startService(intent);
- */
+ // TODO: We can't delete that file...
+ // If possible we should find out if deletion is possible before even showing the option to do so.
}
});
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {