First work on new key view toolbar
This commit is contained in:
@@ -778,13 +778,13 @@ public class KeyListFragment extends LoaderFragment
|
||||
|
||||
// Note: order is important!
|
||||
if (isRevoked) {
|
||||
KeyFormattingUtils.setStatusImage(getActivity(), h.mStatus, null, KeyFormattingUtils.STATE_REVOKED, true);
|
||||
KeyFormattingUtils.setStatusImage(getActivity(), h.mStatus, null, KeyFormattingUtils.STATE_REVOKED, R.color.bg_gray);
|
||||
h.mStatus.setVisibility(View.VISIBLE);
|
||||
h.mSlinger.setVisibility(View.GONE);
|
||||
h.mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
h.mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
} else if (isExpired) {
|
||||
KeyFormattingUtils.setStatusImage(getActivity(), h.mStatus, null, KeyFormattingUtils.STATE_EXPIRED, true);
|
||||
KeyFormattingUtils.setStatusImage(getActivity(), h.mStatus, null, KeyFormattingUtils.STATE_EXPIRED, R.color.bg_gray);
|
||||
h.mStatus.setVisibility(View.VISIBLE);
|
||||
h.mSlinger.setVisibility(View.GONE);
|
||||
h.mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray));
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.sufficientlysecure.keychain.ui;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
@@ -35,17 +36,20 @@ import android.provider.ContactsContract;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@@ -54,9 +58,9 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.widget.AspectRatioImageView;
|
||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||
import org.sufficientlysecure.keychain.util.ExportHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@@ -72,10 +76,16 @@ public class ViewKeyActivity extends BaseActivity implements
|
||||
|
||||
protected Uri mDataUri;
|
||||
|
||||
private LinearLayout mStatusLayout;
|
||||
private TextView mName;
|
||||
private TextView mStatusText;
|
||||
private ImageView mStatusImage;
|
||||
private View mStatusDivider;
|
||||
private RelativeLayout mBigToolbar;
|
||||
|
||||
private ImageButton mActionEncryptFile;
|
||||
private ImageButton mActionEncryptText;
|
||||
private ImageButton mActionVerify;
|
||||
private FloatingActionButton mFab;
|
||||
private AspectRatioImageView mPhoto;
|
||||
|
||||
// NFC
|
||||
private NfcAdapter mNfcAdapter;
|
||||
@@ -93,19 +103,18 @@ public class ViewKeyActivity extends BaseActivity implements
|
||||
mExportHelper = new ExportHelper(this);
|
||||
mProviderHelper = new ProviderHelper(this);
|
||||
|
||||
// let the actionbar look like Android's contact app
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setIcon(android.R.color.transparent);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
setTitle(null);
|
||||
|
||||
mStatusLayout = (LinearLayout) findViewById(R.id.view_key_status_layout);
|
||||
mStatusText = (TextView) findViewById(R.id.view_key_status_text);
|
||||
mName = (TextView) findViewById(R.id.view_key_name);
|
||||
mStatusText = (TextView) findViewById(R.id.view_key_status);
|
||||
mStatusImage = (ImageView) findViewById(R.id.view_key_status_image);
|
||||
mStatusDivider = findViewById(R.id.view_key_status_divider);
|
||||
mBigToolbar = (RelativeLayout) findViewById(R.id.toolbar_big);
|
||||
|
||||
|
||||
Intent intent = getIntent();
|
||||
mActionEncryptFile = (ImageButton) findViewById(R.id.view_key_action_encrypt_files);
|
||||
mActionEncryptText = (ImageButton) findViewById(R.id.view_key_action_encrypt_text);
|
||||
mActionVerify = (ImageButton) findViewById(R.id.view_key_action_verify);
|
||||
mFab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
mPhoto = (AspectRatioImageView) findViewById(R.id.view_key_photo);
|
||||
|
||||
mDataUri = getIntent().getData();
|
||||
if (mDataUri == null) {
|
||||
@@ -329,25 +338,32 @@ public class ViewKeyActivity extends BaseActivity implements
|
||||
}
|
||||
};
|
||||
|
||||
static final String[] UNIFIED_PROJECTION = new String[]{
|
||||
// These are the rows that we will retrieve.
|
||||
static final String[] PROJECTION = new String[]{
|
||||
KeychainContract.KeyRings._ID,
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID,
|
||||
KeychainContract.KeyRings.USER_ID,
|
||||
KeychainContract.KeyRings.IS_REVOKED,
|
||||
KeychainContract.KeyRings.EXPIRY,
|
||||
|
||||
KeychainContract.KeyRings.VERIFIED,
|
||||
KeychainContract.KeyRings.HAS_ANY_SECRET,
|
||||
KeychainContract.KeyRings.FINGERPRINT
|
||||
};
|
||||
static final int INDEX_UNIFIED_MASTER_KEY_ID = 1;
|
||||
static final int INDEX_UNIFIED_USER_ID = 2;
|
||||
static final int INDEX_UNIFIED_IS_REVOKED = 3;
|
||||
static final int INDEX_UNIFIED_EXPIRY = 4;
|
||||
|
||||
static final int INDEX_MASTER_KEY_ID = 1;
|
||||
static final int INDEX_USER_ID = 2;
|
||||
static final int INDEX_IS_REVOKED = 3;
|
||||
static final int INDEX_EXPIRY = 4;
|
||||
static final int INDEX_VERIFIED = 5;
|
||||
static final int INDEX_HAS_ANY_SECRET = 6;
|
||||
static final int INDEX_FINGERPRINT = 7;
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
switch (id) {
|
||||
case LOADER_ID_UNIFIED: {
|
||||
Uri baseUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
||||
return new CursorLoader(this, baseUri, UNIFIED_PROJECTION, null, null, null);
|
||||
return new CursorLoader(this, baseUri, PROJECTION, null, null, null);
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -370,36 +386,91 @@ public class ViewKeyActivity extends BaseActivity implements
|
||||
case LOADER_ID_UNIFIED: {
|
||||
if (data.moveToFirst()) {
|
||||
// get name, email, and comment from USER_ID
|
||||
String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_UNIFIED_USER_ID));
|
||||
String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
|
||||
if (mainUserId[0] != null) {
|
||||
setTitle(mainUserId[0]);
|
||||
mName.setText(mainUserId[0]);
|
||||
} else {
|
||||
setTitle(R.string.user_id_no_name);
|
||||
mName.setText(R.string.user_id_no_name);
|
||||
}
|
||||
|
||||
// get key id from MASTER_KEY_ID
|
||||
long masterKeyId = data.getLong(INDEX_UNIFIED_MASTER_KEY_ID);
|
||||
getSupportActionBar().setSubtitle(KeyFormattingUtils.beautifyKeyIdWithPrefix(this, masterKeyId));
|
||||
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(data.getBlob(INDEX_FINGERPRINT));
|
||||
|
||||
boolean isRevoked = data.getInt(INDEX_UNIFIED_IS_REVOKED) > 0;
|
||||
boolean isExpired = !data.isNull(INDEX_UNIFIED_EXPIRY)
|
||||
&& new Date(data.getLong(INDEX_UNIFIED_EXPIRY) * 1000).before(new Date());
|
||||
boolean isSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
|
||||
boolean isRevoked = data.getInt(INDEX_IS_REVOKED) > 0;
|
||||
boolean isExpired = !data.isNull(INDEX_EXPIRY)
|
||||
&& new Date(data.getLong(INDEX_EXPIRY) * 1000).before(new Date());
|
||||
boolean isVerified = data.getInt(INDEX_VERIFIED) > 0;
|
||||
|
||||
// Note: order is important
|
||||
int color;
|
||||
if (isRevoked) {
|
||||
mStatusText.setText(R.string.view_key_revoked);
|
||||
KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_REVOKED);
|
||||
mStatusDivider.setVisibility(View.VISIBLE);
|
||||
mStatusLayout.setVisibility(View.VISIBLE);
|
||||
mStatusImage.setVisibility(View.VISIBLE);
|
||||
KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_REVOKED, R.color.icons);
|
||||
color = getResources().getColor(R.color.android_red_light);
|
||||
|
||||
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
||||
mActionEncryptText.setVisibility(View.INVISIBLE);
|
||||
mActionVerify.setVisibility(View.INVISIBLE);
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
} else if (isExpired) {
|
||||
mStatusText.setText(R.string.view_key_expired);
|
||||
KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_EXPIRED);
|
||||
mStatusDivider.setVisibility(View.VISIBLE);
|
||||
mStatusLayout.setVisibility(View.VISIBLE);
|
||||
mStatusImage.setVisibility(View.VISIBLE);
|
||||
KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_EXPIRED, R.color.icons);
|
||||
color = getResources().getColor(R.color.android_red_light);
|
||||
|
||||
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
||||
mActionEncryptText.setVisibility(View.INVISIBLE);
|
||||
mActionVerify.setVisibility(View.INVISIBLE);
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
} else if (isSecret) {
|
||||
mStatusText.setText(R.string.view_key_my_key);
|
||||
mStatusImage.setVisibility(View.INVISIBLE);
|
||||
color = getResources().getColor(R.color.primary);
|
||||
|
||||
mActionEncryptFile.setVisibility(View.VISIBLE);
|
||||
mActionEncryptText.setVisibility(View.VISIBLE);
|
||||
mActionVerify.setVisibility(View.INVISIBLE);
|
||||
mFab.setVisibility(View.INVISIBLE); // TODO
|
||||
} else {
|
||||
mStatusDivider.setVisibility(View.GONE);
|
||||
mStatusLayout.setVisibility(View.GONE);
|
||||
mActionEncryptFile.setVisibility(View.VISIBLE);
|
||||
mActionEncryptText.setVisibility(View.VISIBLE);
|
||||
|
||||
if (isVerified) {
|
||||
mStatusText.setText(R.string.view_key_verified);
|
||||
mStatusImage.setVisibility(View.VISIBLE);
|
||||
KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_VERIFIED, R.color.icons);
|
||||
color = getResources().getColor(R.color.primary);
|
||||
|
||||
AsyncTask<String, Void, Bitmap> photoTask =
|
||||
new AsyncTask<String, Void, Bitmap>() {
|
||||
protected Bitmap doInBackground(String... fingerprint) {
|
||||
return ContactHelper.photoFromFingerprint(getContentResolver(), fingerprint[0]);
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap photo) {
|
||||
mPhoto.setImageBitmap(photo);
|
||||
mPhoto.setVisibility(View.VISIBLE);
|
||||
}
|
||||
};
|
||||
|
||||
photoTask.execute(fingerprint);
|
||||
|
||||
mActionVerify.setVisibility(View.INVISIBLE);
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
mStatusText.setText(R.string.view_key_unverified);
|
||||
mStatusImage.setVisibility(View.VISIBLE);
|
||||
KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, KeyFormattingUtils.STATE_UNVERIFIED, R.color.icons);
|
||||
color = getResources().getColor(R.color.android_orange_light);
|
||||
|
||||
mActionVerify.setVisibility(View.VISIBLE);
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
mToolbar.setBackgroundColor(color);
|
||||
mStatusBar.setBackgroundColor(color);
|
||||
mBigToolbar.setBackgroundColor(color);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -175,9 +175,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
}
|
||||
|
||||
if (entry.isRevoked()) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, KeyFormattingUtils.STATE_REVOKED, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, KeyFormattingUtils.STATE_REVOKED, R.color.bg_gray);
|
||||
} else if (entry.isExpired()) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, KeyFormattingUtils.STATE_EXPIRED, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, KeyFormattingUtils.STATE_EXPIRED, R.color.bg_gray);
|
||||
}
|
||||
|
||||
if (entry.isRevoked() || entry.isExpired()) {
|
||||
|
||||
@@ -133,11 +133,11 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
|
||||
boolean enabled;
|
||||
if (cursor.getInt(mIndexIsRevoked) != 0) {
|
||||
h.statusIcon.setVisibility(View.VISIBLE);
|
||||
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, KeyFormattingUtils.STATE_REVOKED, true);
|
||||
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, KeyFormattingUtils.STATE_REVOKED, R.color.bg_gray);
|
||||
enabled = false;
|
||||
} else if (cursor.getInt(mIndexIsExpiry) != 0) {
|
||||
h.statusIcon.setVisibility(View.VISIBLE);
|
||||
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, KeyFormattingUtils.STATE_EXPIRED, true);
|
||||
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, KeyFormattingUtils.STATE_EXPIRED, R.color.bg_gray);
|
||||
enabled = false;
|
||||
} else {
|
||||
h.statusIcon.setVisibility(View.GONE);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
|
||||
|
||||
if (isRevoked) {
|
||||
// set revocation icon (can this even be primary?)
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_REVOKED, true);
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_REVOKED, R.color.bg_gray);
|
||||
|
||||
// disable revoked user ids
|
||||
vName.setEnabled(false);
|
||||
@@ -184,13 +184,13 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
|
||||
int isVerified = cursor.getInt(INDEX_VERIFIED);
|
||||
switch (isVerified) {
|
||||
case Certs.VERIFIED_SECRET:
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_VERIFIED, false);
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_VERIFIED, KeyFormattingUtils.DEFAULT_COLOR);
|
||||
break;
|
||||
case Certs.VERIFIED_SELF:
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_UNVERIFIED, false);
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_UNVERIFIED, KeyFormattingUtils.DEFAULT_COLOR);
|
||||
break;
|
||||
default:
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_INVALID, false);
|
||||
KeyFormattingUtils.setStatusImage(mContext, vVerified, null, KeyFormattingUtils.STATE_INVALID, KeyFormattingUtils.DEFAULT_COLOR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,6 +377,8 @@ public class KeyFormattingUtils {
|
||||
((int) digest[2] + 256) % 256};
|
||||
}
|
||||
|
||||
public static final int DEFAULT_COLOR = -1;
|
||||
|
||||
public static final int STATE_REVOKED = 1;
|
||||
public static final int STATE_EXPIRED = 2;
|
||||
public static final int STATE_VERIFIED = 3;
|
||||
@@ -393,20 +395,22 @@ public class KeyFormattingUtils {
|
||||
}
|
||||
|
||||
public static void setStatusImage(Context context, ImageView statusIcon, TextView statusText, int state) {
|
||||
setStatusImage(context, statusIcon, statusText, state, false);
|
||||
setStatusImage(context, statusIcon, statusText, state, KeyFormattingUtils.DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status image based on constant
|
||||
*/
|
||||
public static void setStatusImage(Context context, ImageView statusIcon, TextView statusText,
|
||||
int state, boolean unobtrusive) {
|
||||
int state, int color) {
|
||||
switch (state) {
|
||||
/** GREEN: everything is good **/
|
||||
case STATE_VERIFIED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_verified_cutout));
|
||||
int color = R.color.android_green_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_green_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -417,7 +421,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_ENCRYPTED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_lock_closed));
|
||||
int color = R.color.android_green_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_green_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -429,7 +435,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_UNVERIFIED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_unverified_cutout));
|
||||
int color = R.color.android_orange_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_orange_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -440,7 +448,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_UNKNOWN_KEY: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_unknown_cutout));
|
||||
int color = R.color.android_orange_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_orange_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -452,9 +462,8 @@ public class KeyFormattingUtils {
|
||||
case STATE_REVOKED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_revoked_cutout));
|
||||
int color = R.color.android_red_light;
|
||||
if (unobtrusive) {
|
||||
color = R.color.bg_gray;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_red_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
@@ -466,9 +475,8 @@ public class KeyFormattingUtils {
|
||||
case STATE_EXPIRED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_expired_cutout));
|
||||
int color = R.color.android_red_light;
|
||||
if (unobtrusive) {
|
||||
color = R.color.bg_gray;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_red_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
@@ -480,7 +488,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_NOT_ENCRYPTED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_lock_open));
|
||||
int color = R.color.android_red_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_red_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -491,7 +501,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_NOT_SIGNED: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_unknown_cutout));
|
||||
int color = R.color.android_red_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_red_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -502,7 +514,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_INVALID: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_invalid_cutout));
|
||||
int color = R.color.android_red_light;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.android_red_light;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
@@ -514,7 +528,9 @@ public class KeyFormattingUtils {
|
||||
case STATE_UNAVAILABLE: {
|
||||
statusIcon.setImageDrawable(
|
||||
context.getResources().getDrawable(R.drawable.status_signature_invalid_cutout));
|
||||
int color = R.color.bg_gray;
|
||||
if (color == KeyFormattingUtils.DEFAULT_COLOR) {
|
||||
color = R.color.bg_gray;
|
||||
}
|
||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
if (statusText != null) {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
|
||||
/**
|
||||
* Maintains an aspect ratio based on either width or height. Disabled by default.
|
||||
*
|
||||
* from https://gist.github.com/JakeWharton/2856179
|
||||
*/
|
||||
public class AspectRatioImageView extends ImageView {
|
||||
// NOTE: These must be kept in sync with the AspectRatioImageView attributes in attrs.xml.
|
||||
public static final int MEASUREMENT_WIDTH = 0;
|
||||
public static final int MEASUREMENT_HEIGHT = 1;
|
||||
|
||||
private static final float DEFAULT_ASPECT_RATIO = 1f;
|
||||
private static final boolean DEFAULT_ASPECT_RATIO_ENABLED = false;
|
||||
private static final int DEFAULT_DOMINANT_MEASUREMENT = MEASUREMENT_WIDTH;
|
||||
|
||||
private float aspectRatio;
|
||||
private boolean aspectRatioEnabled;
|
||||
private int dominantMeasurement;
|
||||
|
||||
public AspectRatioImageView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public AspectRatioImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AspectRatioImageView);
|
||||
aspectRatio = a.getFloat(R.styleable.AspectRatioImageView_aspectRatio, DEFAULT_ASPECT_RATIO);
|
||||
aspectRatioEnabled = a.getBoolean(R.styleable.AspectRatioImageView_aspectRatioEnabled,
|
||||
DEFAULT_ASPECT_RATIO_ENABLED);
|
||||
dominantMeasurement = a.getInt(R.styleable.AspectRatioImageView_dominantMeasurement,
|
||||
DEFAULT_DOMINANT_MEASUREMENT);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
if (!aspectRatioEnabled) return;
|
||||
|
||||
int newWidth;
|
||||
int newHeight;
|
||||
switch (dominantMeasurement) {
|
||||
case MEASUREMENT_WIDTH:
|
||||
newWidth = getMeasuredWidth();
|
||||
newHeight = (int) (newWidth * aspectRatio);
|
||||
break;
|
||||
|
||||
case MEASUREMENT_HEIGHT:
|
||||
newHeight = getMeasuredHeight();
|
||||
newWidth = (int) (newHeight * aspectRatio);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("Unknown measurement with ID " + dominantMeasurement);
|
||||
}
|
||||
|
||||
setMeasuredDimension(newWidth, newHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the aspect ratio for this image view.
|
||||
*/
|
||||
public float getAspectRatio() {
|
||||
return aspectRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the aspect ratio for this image view. This will update the view instantly.
|
||||
*/
|
||||
public void setAspectRatio(float aspectRatio) {
|
||||
this.aspectRatio = aspectRatio;
|
||||
if (aspectRatioEnabled) {
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not forcing the aspect ratio is enabled.
|
||||
*/
|
||||
public boolean getAspectRatioEnabled() {
|
||||
return aspectRatioEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* set whether or not forcing the aspect ratio is enabled. This will re-layout the view.
|
||||
*/
|
||||
public void setAspectRatioEnabled(boolean aspectRatioEnabled) {
|
||||
this.aspectRatioEnabled = aspectRatioEnabled;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dominant measurement for the aspect ratio.
|
||||
*/
|
||||
public int getDominantMeasurement() {
|
||||
return dominantMeasurement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dominant measurement for the aspect ratio.
|
||||
*
|
||||
* @see #MEASUREMENT_WIDTH
|
||||
* @see #MEASUREMENT_HEIGHT
|
||||
*/
|
||||
public void setDominantMeasurement(int dominantMeasurement) {
|
||||
if (dominantMeasurement != MEASUREMENT_HEIGHT && dominantMeasurement != MEASUREMENT_WIDTH) {
|
||||
throw new IllegalArgumentException("Invalid measurement type.");
|
||||
}
|
||||
this.dominantMeasurement = dominantMeasurement;
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
@@ -101,16 +102,16 @@ public class CertifyKeySpinner extends KeySpinner {
|
||||
@Override
|
||||
boolean setStatus(Context context, Cursor cursor, ImageView statusView) {
|
||||
if (cursor.getInt(mIndexIsRevoked) != 0) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_REVOKED, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_REVOKED, R.color.bg_gray);
|
||||
return false;
|
||||
}
|
||||
if (cursor.getInt(mIndexIsExpired) != 0) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_EXPIRED, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_EXPIRED, R.color.bg_gray);
|
||||
return false;
|
||||
}
|
||||
// don't invalidate the "None" entry, which is also null!
|
||||
if (cursor.getPosition() != 0 && cursor.isNull(mIndexHasCertify)) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_UNAVAILABLE, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_UNAVAILABLE, R.color.bg_gray);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.support.v4.content.Loader;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
|
||||
@@ -83,15 +84,15 @@ public class SignKeySpinner extends KeySpinner {
|
||||
@Override
|
||||
boolean setStatus(Context context, Cursor cursor, ImageView statusView) {
|
||||
if (cursor.getInt(mIndexIsRevoked) != 0) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_REVOKED, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_REVOKED, R.color.bg_gray);
|
||||
return false;
|
||||
}
|
||||
if (cursor.getInt(mIndexIsExpired) != 0) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_EXPIRED, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_EXPIRED, R.color.bg_gray);
|
||||
return false;
|
||||
}
|
||||
if (cursor.getInt(mIndexHasSign) == 0) {
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_UNAVAILABLE, true);
|
||||
KeyFormattingUtils.setStatusImage(getContext(), statusView, null, KeyFormattingUtils.STATE_UNAVAILABLE, R.color.bg_gray);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user