use status icons in public key selection

This commit is contained in:
Dominik Schürmann 2014-10-05 04:09:55 +02:00
parent d38b200b01
commit 0b9308753d
8 changed files with 45 additions and 129 deletions

View File

@ -59,7 +59,6 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.ExportHelper;
import org.sufficientlysecure.keychain.util.KeyUpdateHelper; import org.sufficientlysecure.keychain.util.KeyUpdateHelper;
import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
@ -224,7 +223,6 @@ public class KeyListFragment extends LoaderFragment
*/ */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mStickyList.setFastScrollAlwaysVisible(true); mStickyList.setFastScrollAlwaysVisible(true);
mStickyList.addHeaderView();
mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() { mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() {
@ -554,7 +552,7 @@ public class KeyListFragment extends LoaderFragment
ItemViewHolder holder = new ItemViewHolder(); ItemViewHolder holder = new ItemViewHolder();
holder.mMainUserId = (TextView) view.findViewById(R.id.mainUserId); holder.mMainUserId = (TextView) view.findViewById(R.id.mainUserId);
holder.mMainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); holder.mMainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest);
holder.mStatus = (ImageView) view.findViewById(R.id.status_image); holder.mStatus = (ImageView) view.findViewById(R.id.status_icon);
view.setTag(holder); view.setTag(holder);
return view; return view;
} }

View File

@ -42,9 +42,11 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ListFragmentWorkaround; import org.sufficientlysecure.keychain.compatibility.ListFragmentWorkaround;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.ui.adapter.SelectKeyCursorAdapter; import org.sufficientlysecure.keychain.ui.adapter.SelectKeyCursorAdapter;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import java.util.Vector; import java.util.Vector;
@ -257,9 +259,10 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
KeyRings._ID, KeyRings._ID,
KeyRings.MASTER_KEY_ID, KeyRings.MASTER_KEY_ID,
KeyRings.USER_ID, KeyRings.USER_ID,
KeyRings.EXPIRY, KeyRings.IS_EXPIRED,
KeyRings.IS_REVOKED, KeyRings.IS_REVOKED,
KeyRings.HAS_ENCRYPT, KeyRings.HAS_ENCRYPT,
KeyRings.VERIFIED,
}; };
String inMasterKeyList = null; String inMasterKeyList = null;
@ -344,7 +347,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
private class SelectPublicKeyCursorAdapter extends SelectKeyCursorAdapter { private class SelectPublicKeyCursorAdapter extends SelectKeyCursorAdapter {
private int mIndexHasEncrypt; private int mIndexHasEncrypt, mIndexIsVerified;
public SelectPublicKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) { public SelectPublicKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) {
super(context, c, flags, listView); super(context, c, flags, listView);
@ -355,6 +358,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
super.initIndex(cursor); super.initIndex(cursor);
if (cursor != null) { if (cursor != null) {
mIndexHasEncrypt = cursor.getColumnIndexOrThrow(KeyRings.HAS_ENCRYPT); mIndexHasEncrypt = cursor.getColumnIndexOrThrow(KeyRings.HAS_ENCRYPT);
mIndexIsVerified = cursor.getColumnIndexOrThrow(KeyRings.VERIFIED);
} }
} }
@ -369,12 +373,18 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
h.selected.setChecked(getListView().isItemChecked(cursor.getPosition())); h.selected.setChecked(getListView().isItemChecked(cursor.getPosition()));
boolean enabled = false; boolean enabled = false;
if((Boolean) h.status.getTag()) { if((Boolean) h.statusIcon.getTag()) {
// Check if key is viable for our purposes // Check if key is viable for our purposes
if (cursor.getInt(mIndexHasEncrypt) == 0) { if (cursor.getInt(mIndexHasEncrypt) == 0) {
h.status.setText(R.string.no_key); h.statusIcon.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_UNAVAILABLE);
enabled = false;
} else if (cursor.getInt(mIndexIsVerified) != 0) {
h.statusIcon.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_VERIFIED);
enabled = true;
} else { } else {
h.status.setText(R.string.can_encrypt); h.statusIcon.setVisibility(View.GONE);
enabled = true; enabled = true;
} }
} }

View File

@ -24,6 +24,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
@ -33,8 +34,6 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.ui.util.Highlighter; import org.sufficientlysecure.keychain.ui.util.Highlighter;
import java.util.Date;
/** /**
* Yes this class is abstract! * Yes this class is abstract!
@ -44,7 +43,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
private String mQuery; private String mQuery;
private LayoutInflater mInflater; private LayoutInflater mInflater;
protected int mIndexUserId, mIndexMasterKeyId, mIndexRevoked, mIndexExpiry; protected int mIndexUserId, mIndexMasterKeyId, mIndexIsExpiry, mIndexIsRevoked;
public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) { public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView) {
super(context, c, flags); super(context, c, flags);
@ -73,8 +72,8 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
if (cursor != null) { if (cursor != null) {
mIndexUserId = cursor.getColumnIndexOrThrow(KeyRings.USER_ID); mIndexUserId = cursor.getColumnIndexOrThrow(KeyRings.USER_ID);
mIndexMasterKeyId = cursor.getColumnIndexOrThrow(KeyRings.MASTER_KEY_ID); mIndexMasterKeyId = cursor.getColumnIndexOrThrow(KeyRings.MASTER_KEY_ID);
mIndexExpiry = cursor.getColumnIndexOrThrow(KeyRings.EXPIRY); mIndexIsExpiry = cursor.getColumnIndexOrThrow(KeyRings.IS_EXPIRED);
mIndexRevoked = cursor.getColumnIndexOrThrow(KeyRings.IS_REVOKED); mIndexIsRevoked = cursor.getColumnIndexOrThrow(KeyRings.IS_REVOKED);
} }
} }
@ -90,7 +89,8 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
public static class ViewHolderItem { public static class ViewHolderItem {
public View view; public View view;
public TextView mainUserId, mainUserIdRest, keyId, status; public TextView mainUserId, mainUserIdRest, keyId;
public ImageView statusIcon;
public CheckBox selected; public CheckBox selected;
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
@ -99,7 +99,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
mainUserId.setEnabled(enabled); mainUserId.setEnabled(enabled);
mainUserIdRest.setEnabled(enabled); mainUserIdRest.setEnabled(enabled);
keyId.setEnabled(enabled); keyId.setEnabled(enabled);
status.setEnabled(enabled); statusIcon.setEnabled(enabled);
// Sorta special: We set an item as clickable to disable it in the ListView. This works // Sorta special: We set an item as clickable to disable it in the ListView. This works
// because the list item will handle the clicks itself (which is a nop) // because the list item will handle the clicks itself (which is a nop)
@ -130,19 +130,21 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
long masterKeyId = cursor.getLong(mIndexMasterKeyId); long masterKeyId = cursor.getLong(mIndexMasterKeyId);
h.keyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(mContext, masterKeyId)); h.keyId.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(mContext, masterKeyId));
boolean enabled = true; boolean enabled;
if (cursor.getInt(mIndexRevoked) != 0) { if (cursor.getInt(mIndexIsRevoked) != 0) {
h.status.setText(R.string.revoked); h.statusIcon.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_REVOKED);
enabled = false; enabled = false;
} else if (!cursor.isNull(mIndexExpiry) } else if (cursor.getInt(mIndexIsExpiry) != 0) {
&& new Date(cursor.getLong(mIndexExpiry) * 1000).before(new Date())) { h.statusIcon.setVisibility(View.VISIBLE);
h.status.setText(R.string.expired); KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_EXPIRED);
enabled = false; enabled = false;
} else { } else {
h.status.setText(""); h.statusIcon.setVisibility(View.GONE);
enabled = true;
} }
h.status.setTag(enabled); h.statusIcon.setTag(enabled);
} }
@Override @Override
@ -153,7 +155,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
holder.mainUserId = (TextView) view.findViewById(R.id.mainUserId); holder.mainUserId = (TextView) view.findViewById(R.id.mainUserId);
holder.mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); holder.mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest);
holder.keyId = (TextView) view.findViewById(R.id.subkey_item_key_id); holder.keyId = (TextView) view.findViewById(R.id.subkey_item_key_id);
holder.status = (TextView) view.findViewById(R.id.status); holder.statusIcon = (ImageView) view.findViewById(R.id.status_icon);
holder.selected = (CheckBox) view.findViewById(R.id.selected); holder.selected = (CheckBox) view.findViewById(R.id.selected);
view.setTag(holder); view.setTag(holder);
return view; return view;

View File

@ -39,7 +39,7 @@
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/status_image" android:id="@+id/status_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"

View File

@ -17,8 +17,7 @@
android:focusable="true" android:focusable="true"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="4dp" android:paddingRight="4dp">
>
<TextView <TextView
android:id="@+id/keyspinner_key_name" android:id="@+id/keyspinner_key_name"
@ -43,7 +42,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:ellipsize="end" android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall"/> android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout> </LinearLayout>
<ImageView <ImageView
@ -53,6 +52,6 @@
android:layout_gravity="center" android:layout_gravity="center"
android:src="@drawable/status_signature_revoked_cutout" android:src="@drawable/status_signature_revoked_cutout"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp"/> android:paddingRight="16dp" />
</LinearLayout> </LinearLayout>

View File

@ -42,22 +42,16 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="0xBBBBBBBBBBBBBBB" android:text="0xBBBBBBBBBBBBBBB"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall" />
android:typeface="monospace" />
</LinearLayout> </LinearLayout>
<ImageView
<TextView android:id="@+id/status_icon"
android:gravity="right"
android:paddingLeft="4dp"
android:minWidth="90dip"
android:id="@+id/status"
android:paddingTop="4dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="expired" android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall" android:src="@drawable/status_signature_revoked_cutout"
android:textStyle="italic" android:paddingLeft="16dp"
android:layout_gravity="right" /> android:paddingRight="16dp" />
</LinearLayout> </LinearLayout>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" >
<FrameLayout
android:id="@+id/select_secret_key_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View File

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/select_secret_key_select_key_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:text="@string/api_settings_select_key"
android:drawableLeft="@drawable/ic_action_accounts"
android:background="@drawable/button_edgy"
android:textSize="14sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:orientation="vertical"
android:paddingLeft="4dp">
<!-- Has been made focusable to display error messages with setError -->
<TextView
android:id="@+id/select_secret_key_user_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:ellipsize="end"
android:visibility="gone"
android:layout_marginRight="5dip"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/select_secret_key_user_id_rest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:ellipsize="end"
android:singleLine="true"
android:layout_marginRight="5dip"
android:text=""
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/select_secret_key_master_key_hex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"
android:layout_marginRight="15dip" />
<TextView
android:id="@+id/no_key_selected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/api_settings_no_key"
android:layout_marginTop="15dp" />
</LinearLayout>
</LinearLayout>