aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java45
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java127
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java58
3 files changed, 137 insertions, 93 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
index 99f959035..4971c535c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java
@@ -30,20 +30,21 @@ import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
import java.io.BufferedInputStream;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
public class ImportKeysListLoader
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
- public static class FileHasNoContent extends Exception {
-
+ public static class NoValidKeysException extends Exception {
}
- public static class NonPgpPart extends Exception {
+ public static class NonPgpPartException extends Exception {
private int mCount;
- public NonPgpPart(int count) {
+ public NonPgpPartException(int count) {
this.mCount = count;
}
@@ -67,7 +68,6 @@ public class ImportKeysListLoader
@Override
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
-
// This has already been loaded! nvm any further, just return
if (mEntryListWrapper != null) {
return mEntryListWrapper;
@@ -119,9 +119,6 @@ public class ImportKeysListLoader
* @return
*/
private void generateListOfKeyrings(InputData inputData) {
-
- boolean isEmpty = true;
-
PositionAwareInputStream progressIn = new PositionAwareInputStream(
inputData.getInputStream());
@@ -130,27 +127,23 @@ public class ImportKeysListLoader
// armor blocks
BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);
try {
-
- // read all available blocks... (asc files can contain many blocks with BEGIN END)
- while (bufferedInput.available() > 0) {
- // TODO: deal with non-keyring objects?
- List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput);
- for(UncachedKeyRing key : rings) {
- ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
- mData.add(item);
- mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded()));
- isEmpty = false;
- }
+ // parse all keyrings
+ Iterator<UncachedKeyRing> it = UncachedKeyRing.fromStream(bufferedInput);
+ while (it.hasNext()) {
+ UncachedKeyRing ring = it.next();
+ ImportKeysListEntry item = new ImportKeysListEntry(getContext(), ring);
+ mData.add(item);
+ mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(ring.getEncoded()));
}
- } catch (Exception e) {
- Log.e(Constants.TAG, "Exception on parsing key file!", e);
- mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
- }
+ } catch (IOException e) {
+ Log.e(Constants.TAG, "IOException on parsing key file! Return NoValidKeysException!", e);
- if (isEmpty) {
- Log.e(Constants.TAG, "File has no content!", new FileHasNoContent());
+ NoValidKeysException e1 = new NoValidKeysException();
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
- (mData, new FileHasNoContent());
+ (mData, e1);
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "Other Exception on parsing key file!", e);
+ mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java
index 02b1f31e2..e5dbebe01 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java
@@ -32,14 +32,15 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
+import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import java.util.Date;
public class SubkeysAdapter extends CursorAdapter {
private LayoutInflater mInflater;
+ private SaveKeyringParcel mSaveKeyringParcel;
private boolean hasAnySecret;
-
private ColorStateList mDefaultTextColor;
public static final String[] SUBKEYS_PROJECTION = new String[]{
@@ -71,10 +72,21 @@ public class SubkeysAdapter extends CursorAdapter {
private static final int INDEX_EXPIRY = 11;
private static final int INDEX_FINGERPRINT = 12;
- public SubkeysAdapter(Context context, Cursor c, int flags) {
+ public SubkeysAdapter(Context context, Cursor c, int flags,
+ SaveKeyringParcel saveKeyringParcel) {
super(context, c, flags);
mInflater = LayoutInflater.from(context);
+ mSaveKeyringParcel = saveKeyringParcel;
+ }
+
+ public SubkeysAdapter(Context context, Cursor c, int flags) {
+ this(context, c, flags, null);
+ }
+
+ public long getKeyId(int position) {
+ mCursor.moveToPosition(position);
+ return mCursor.getLong(INDEX_KEY_ID);
}
@Override
@@ -94,79 +106,94 @@ public class SubkeysAdapter extends CursorAdapter {
@Override
public void bindView(View view, Context context, Cursor cursor) {
- TextView keyId = (TextView) view.findViewById(R.id.keyId);
- TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
- TextView keyExpiry = (TextView) view.findViewById(R.id.keyExpiry);
- ImageView masterKeyIcon = (ImageView) view.findViewById(R.id.ic_masterKey);
- ImageView certifyIcon = (ImageView) view.findViewById(R.id.ic_certifyKey);
- ImageView encryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey);
- ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey);
- ImageView revokedKeyIcon = (ImageView) view.findViewById(R.id.ic_revokedKey);
-
- String keyIdStr = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(INDEX_KEY_ID));
+ TextView vKeyId = (TextView) view.findViewById(R.id.keyId);
+ TextView vKeyDetails = (TextView) view.findViewById(R.id.keyDetails);
+ TextView vKeyExpiry = (TextView) view.findViewById(R.id.keyExpiry);
+ ImageView vMasterKeyIcon = (ImageView) view.findViewById(R.id.ic_masterKey);
+ ImageView vCertifyIcon = (ImageView) view.findViewById(R.id.ic_certifyKey);
+ ImageView vEncryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey);
+ ImageView vSignIcon = (ImageView) view.findViewById(R.id.ic_signKey);
+ ImageView vRevokedKeyIcon = (ImageView) view.findViewById(R.id.ic_revokedKey);
+ ImageView vEditImage = (ImageView) view.findViewById(R.id.edit_image);
+
+ long keyId = cursor.getLong(INDEX_KEY_ID);
+ String keyIdStr = PgpKeyHelper.convertKeyIdToHex(keyId);
String algorithmStr = PgpKeyHelper.getAlgorithmInfo(
context,
cursor.getInt(INDEX_ALGORITHM),
cursor.getInt(INDEX_KEY_SIZE)
);
- keyId.setText(keyIdStr);
+ vKeyId.setText(keyIdStr);
// may be set with additional "stripped" later on
if (hasAnySecret && cursor.getInt(INDEX_HAS_SECRET) == 0) {
- keyDetails.setText(algorithmStr + ", " +
+ vKeyDetails.setText(algorithmStr + ", " +
context.getString(R.string.key_stripped));
} else {
- keyDetails.setText(algorithmStr);
+ vKeyDetails.setText(algorithmStr);
}
// Set icons according to properties
- masterKeyIcon.setVisibility(cursor.getInt(INDEX_RANK) == 0 ? View.VISIBLE : View.INVISIBLE);
- certifyIcon.setVisibility(cursor.getInt(INDEX_CAN_CERTIFY) != 0 ? View.VISIBLE : View.GONE);
- encryptIcon.setVisibility(cursor.getInt(INDEX_CAN_ENCRYPT) != 0 ? View.VISIBLE : View.GONE);
- signIcon.setVisibility(cursor.getInt(INDEX_CAN_SIGN) != 0 ? View.VISIBLE : View.GONE);
+ vMasterKeyIcon.setVisibility(cursor.getInt(INDEX_RANK) == 0 ? View.VISIBLE : View.INVISIBLE);
+ vCertifyIcon.setVisibility(cursor.getInt(INDEX_CAN_CERTIFY) != 0 ? View.VISIBLE : View.GONE);
+ vEncryptIcon.setVisibility(cursor.getInt(INDEX_CAN_ENCRYPT) != 0 ? View.VISIBLE : View.GONE);
+ vSignIcon.setVisibility(cursor.getInt(INDEX_CAN_SIGN) != 0 ? View.VISIBLE : View.GONE);
+
+ boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
+
+ // for edit key
+ if (mSaveKeyringParcel != null) {
+ boolean revokeThisSubkey = (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId));
- boolean valid = true;
- if (cursor.getInt(INDEX_IS_REVOKED) > 0) {
- revokedKeyIcon.setVisibility(View.VISIBLE);
+ if (revokeThisSubkey) {
+ if (!isRevoked) {
+ isRevoked = true;
+ }
+ }
- valid = false;
+ vEditImage.setVisibility(View.VISIBLE);
} else {
- keyId.setTextColor(mDefaultTextColor);
- keyDetails.setTextColor(mDefaultTextColor);
- keyExpiry.setTextColor(mDefaultTextColor);
+ vEditImage.setVisibility(View.GONE);
+ }
- revokedKeyIcon.setVisibility(View.GONE);
+ if (isRevoked) {
+ vRevokedKeyIcon.setVisibility(View.VISIBLE);
+ } else {
+ vKeyId.setTextColor(mDefaultTextColor);
+ vKeyDetails.setTextColor(mDefaultTextColor);
+ vKeyExpiry.setTextColor(mDefaultTextColor);
+
+ vRevokedKeyIcon.setVisibility(View.GONE);
}
+ boolean isExpired;
if (!cursor.isNull(INDEX_EXPIRY)) {
Date expiryDate = new Date(cursor.getLong(INDEX_EXPIRY) * 1000);
+ isExpired = expiryDate.before(new Date());
- valid = valid && expiryDate.after(new Date());
- keyExpiry.setText(
- context.getString(R.string.label_expiry) + ": " +
- DateFormat.getDateFormat(context).format(expiryDate)
- );
+ vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": "
+ + DateFormat.getDateFormat(context).format(expiryDate));
} else {
- keyExpiry.setText(
- context.getString(R.string.label_expiry) + ": " +
- context.getString(R.string.none)
- );
+ isExpired = false;
+
+ vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none));
}
// if key is expired or revoked, strike through text
- if (!valid) {
- keyId.setText(OtherHelper.strikeOutText(keyId.getText()));
- keyDetails.setText(OtherHelper.strikeOutText(keyDetails.getText()));
- keyExpiry.setText(OtherHelper.strikeOutText(keyExpiry.getText()));
+ boolean isInvalid = isRevoked || isExpired;
+ if (isInvalid) {
+ vKeyId.setText(OtherHelper.strikeOutText(vKeyId.getText()));
+ vKeyDetails.setText(OtherHelper.strikeOutText(vKeyDetails.getText()));
+ vKeyExpiry.setText(OtherHelper.strikeOutText(vKeyExpiry.getText()));
}
- keyId.setEnabled(valid);
- keyDetails.setEnabled(valid);
- keyExpiry.setEnabled(valid);
+ vKeyId.setEnabled(!isInvalid);
+ vKeyDetails.setEnabled(!isInvalid);
+ vKeyExpiry.setEnabled(!isInvalid);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- View view = mInflater.inflate(R.layout.view_key_keys_item, null);
+ View view = mInflater.inflate(R.layout.view_key_subkey_item, null);
if (mDefaultTextColor == null) {
TextView keyId = (TextView) view.findViewById(R.id.keyId);
mDefaultTextColor = keyId.getTextColors();
@@ -177,13 +204,21 @@ public class SubkeysAdapter extends CursorAdapter {
// Disable selection of items, http://stackoverflow.com/a/4075045
@Override
public boolean areAllItemsEnabled() {
- return false;
+ if (mSaveKeyringParcel == null) {
+ return false;
+ } else {
+ return super.areAllItemsEnabled();
+ }
}
// Disable selection of items, http://stackoverflow.com/a/4075045
@Override
public boolean isEnabled(int position) {
- return false;
+ if (mSaveKeyringParcel == null) {
+ return false;
+ } else {
+ return super.isEnabled(position);
+ }
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java
index d729648e5..c8b74da2e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java
@@ -19,6 +19,8 @@ package org.sufficientlysecure.keychain.ui.adapter;
import android.content.Context;
import android.database.Cursor;
+import android.graphics.PorterDuff;
+import android.graphics.Typeface;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,9 +42,7 @@ import java.util.ArrayList;
public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemClickListener {
private LayoutInflater mInflater;
-
private final ArrayList<Boolean> mCheckStates;
-
private SaveKeyringParcel mSaveKeyringParcel;
public static final String[] USER_IDS_PROJECTION = new String[]{
@@ -60,7 +60,6 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
private static final int INDEX_IS_PRIMARY = 4;
private static final int INDEX_IS_REVOKED = 5;
-
public UserIdsAdapter(Context context, Cursor c, int flags, boolean showCheckBoxes,
SaveKeyringParcel saveKeyringParcel) {
super(context, c, flags);
@@ -134,15 +133,18 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
// for edit key
if (mSaveKeyringParcel != null) {
- boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.changePrimaryUserId != null);
- boolean changeThisPrimaryUserId = (mSaveKeyringParcel.changePrimaryUserId != null
- && mSaveKeyringParcel.changePrimaryUserId.equals(userId));
- boolean revokeThisUserId = (mSaveKeyringParcel.revokeUserIds.contains(userId));
+ boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null);
+ boolean changeThisPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null
+ && mSaveKeyringParcel.mChangePrimaryUserId.equals(userId));
+ boolean revokeThisUserId = (mSaveKeyringParcel.mRevokeUserIds.contains(userId));
+ // only if primary user id will be changed
+ // (this is not triggered if the user id is currently the primary one)
if (changeAnyPrimaryUserId) {
- // change all user ids, only this one should be primary
+ // change _all_ primary user ids and set new one to true
isPrimary = changeThisPrimaryUserId;
}
+
if (revokeThisUserId) {
if (!isRevoked) {
isRevoked = true;
@@ -156,7 +158,10 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
if (isRevoked) {
// set revocation icon (can this even be primary?)
- vVerified.setImageResource(R.drawable.key_certify_revoke);
+ vVerified.setImageResource(R.drawable.status_signature_revoked_cutout);
+ vVerified.setColorFilter(
+ mContext.getResources().getColor(R.color.bg_gray),
+ PorterDuff.Mode.SRC_IN);
// disable and strike through text for revoked user ids
vName.setEnabled(false);
@@ -170,22 +175,33 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
vAddress.setEnabled(true);
vComment.setEnabled(true);
- // verified: has been verified
- // isPrimary: show small star icon for primary user ids
- int verified = cursor.getInt(INDEX_VERIFIED);
- switch (verified) {
+ if (isPrimary) {
+ vName.setTypeface(null, Typeface.BOLD);
+ vAddress.setTypeface(null, Typeface.BOLD);
+ } else {
+ vName.setTypeface(null, Typeface.NORMAL);
+ vAddress.setTypeface(null, Typeface.NORMAL);
+ }
+
+ int isVerified = cursor.getInt(INDEX_VERIFIED);
+ switch (isVerified) {
case Certs.VERIFIED_SECRET:
- vVerified.setImageResource(isPrimary
- ? R.drawable.key_certify_primary_ok_depth0
- : R.drawable.key_certify_ok_depth0);
+ vVerified.setImageResource(R.drawable.status_signature_verified_cutout);
+ vVerified.setColorFilter(
+ mContext.getResources().getColor(R.color.android_green_light),
+ PorterDuff.Mode.SRC_IN);
break;
case Certs.VERIFIED_SELF:
- vVerified.setImageResource(isPrimary
- ? R.drawable.key_certify_primary_ok_self
- : R.drawable.key_certify_ok_self);
+ vVerified.setImageResource(R.drawable.status_signature_unverified_cutout);
+ vVerified.setColorFilter(
+ mContext.getResources().getColor(R.color.bg_gray),
+ PorterDuff.Mode.SRC_IN);
break;
default:
- vVerified.setImageResource(R.drawable.key_certify_error);
+ vVerified.setImageResource(R.drawable.status_signature_invalid_cutout);
+ vVerified.setColorFilter(
+ mContext.getResources().getColor(R.color.android_red_light),
+ PorterDuff.Mode.SRC_IN);
break;
}
}
@@ -233,7 +249,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- View view = mInflater.inflate(R.layout.view_key_userids_item, null);
+ View view = mInflater.inflate(R.layout.view_key_user_id_item, null);
// only need to do this once ever, since mShowCheckBoxes is final
view.findViewById(R.id.checkBox).setVisibility(mCheckStates != null ? View.VISIBLE : View.GONE);
return view;