mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
Use enum instead of int constants
This commit is contained in:
parent
d61ac959a9
commit
ab877453d9
@ -4,6 +4,7 @@ package com.fsck.k9.ui.messageview;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -17,18 +18,6 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
|
|||||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||||
|
|
||||||
public class OpenPgpHeaderView extends LinearLayout {
|
public class OpenPgpHeaderView extends LinearLayout {
|
||||||
private static final int STATE_REVOKED = 1;
|
|
||||||
private static final int STATE_EXPIRED = 2;
|
|
||||||
private static final int STATE_VERIFIED = 3;
|
|
||||||
private static final int STATE_UNAVAILABLE = 4;
|
|
||||||
private static final int STATE_ENCRYPTED = 5;
|
|
||||||
private static final int STATE_NOT_ENCRYPTED = 6;
|
|
||||||
private static final int STATE_UNVERIFIED = 7;
|
|
||||||
private static final int STATE_UNKNOWN_KEY = 8;
|
|
||||||
private static final int STATE_INVALID = 9;
|
|
||||||
private static final int STATE_NOT_SIGNED = 10;
|
|
||||||
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private OpenPgpHeaderViewCallback callback;
|
private OpenPgpHeaderViewCallback callback;
|
||||||
|
|
||||||
@ -90,28 +79,28 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
setStatusImage(mContext, mResultEncryptionIcon, mResultEncryptionText, STATE_ENCRYPTED);
|
setStatusImageAndTextColor(mContext, mResultEncryptionIcon, mResultEncryptionText, CryptoState.ENCRYPTED);
|
||||||
mResultEncryptionText.setText(R.string.openpgp_result_encrypted);
|
mResultEncryptionText.setText(R.string.openpgp_result_encrypted);
|
||||||
} else {
|
} else {
|
||||||
setStatusImage(mContext, mResultEncryptionIcon, mResultEncryptionText, STATE_NOT_ENCRYPTED);
|
setStatusImageAndTextColor(mContext, mResultEncryptionIcon, mResultEncryptionText, CryptoState.NOT_ENCRYPTED);
|
||||||
mResultEncryptionText.setText(R.string.openpgp_result_not_encrypted);
|
mResultEncryptionText.setText(R.string.openpgp_result_not_encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signatureResult == null) {
|
if (signatureResult == null) {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_NOT_SIGNED);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.NOT_SIGNED);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_no_signature);
|
mResultSignatureText.setText(R.string.openpgp_result_no_signature);
|
||||||
mResultSignatureLayout.setVisibility(View.GONE);
|
mResultSignatureLayout.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
switch (signatureResult.getStatus()) {
|
switch (signatureResult.getStatus()) {
|
||||||
case OpenPgpSignatureResult.SIGNATURE_ERROR: {
|
case OpenPgpSignatureResult.SIGNATURE_ERROR: {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_INVALID);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.INVALID);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_invalid_signature);
|
mResultSignatureText.setText(R.string.openpgp_result_invalid_signature);
|
||||||
|
|
||||||
mResultSignatureLayout.setVisibility(View.GONE);
|
mResultSignatureLayout.setVisibility(View.GONE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: {
|
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_VERIFIED);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.VERIFIED);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_signature_certified);
|
mResultSignatureText.setText(R.string.openpgp_result_signature_certified);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -124,7 +113,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING: {
|
case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING: {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_UNKNOWN_KEY);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.UNKNOWN_KEY);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_signature_missing_key);
|
mResultSignatureText.setText(R.string.openpgp_result_signature_missing_key);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -137,7 +126,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: {
|
case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_UNVERIFIED);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.UNVERIFIED);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_signature_uncertified);
|
mResultSignatureText.setText(R.string.openpgp_result_signature_uncertified);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -150,7 +139,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED: {
|
case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED: {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_EXPIRED);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.EXPIRED);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_signature_expired_key);
|
mResultSignatureText.setText(R.string.openpgp_result_signature_expired_key);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -163,7 +152,7 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED: {
|
case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED: {
|
||||||
setStatusImage(mContext, mResultSignatureIcon, mResultSignatureText, STATE_REVOKED);
|
setStatusImageAndTextColor(mContext, mResultSignatureIcon, mResultSignatureText, CryptoState.REVOKED);
|
||||||
mResultSignatureText.setText(R.string.openpgp_result_signature_revoked_key);
|
mResultSignatureText.setText(R.string.openpgp_result_signature_revoked_key);
|
||||||
|
|
||||||
setUserId(signatureResult);
|
setUserId(signatureResult);
|
||||||
@ -197,111 +186,48 @@ public class OpenPgpHeaderView extends LinearLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusImage(Context context, ImageView statusIcon, TextView statusText, int state) {
|
private void setStatusImageAndTextColor(Context context, ImageView statusIcon, TextView statusText,
|
||||||
switch (state) {
|
CryptoState state) {
|
||||||
/** GREEN: everything is good **/
|
|
||||||
case STATE_VERIFIED: {
|
Drawable statusImageDrawable = context.getResources().getDrawable(state.getDrawableId());
|
||||||
statusIcon.setImageDrawable(
|
statusIcon.setImageDrawable(statusImageDrawable);
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_verified_cutout));
|
|
||||||
int color = R.color.openpgp_green;
|
int color = context.getResources().getColor(state.getColorId());
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
statusIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
PorterDuff.Mode.SRC_IN);
|
if (statusText != null) {
|
||||||
if (statusText != null) {
|
statusText.setTextColor(color);
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATE_ENCRYPTED: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_lock_closed));
|
|
||||||
int color = R.color.openpgp_green;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/** ORANGE: mostly bad... **/
|
|
||||||
case STATE_UNVERIFIED: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_unverified_cutout));
|
|
||||||
int color = R.color.openpgp_orange;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATE_UNKNOWN_KEY: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_unknown_cutout));
|
|
||||||
int color = R.color.openpgp_orange;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/** RED: really bad... **/
|
|
||||||
case STATE_REVOKED: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_revoked_cutout));
|
|
||||||
int color = R.color.openpgp_red;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATE_EXPIRED: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_expired_cutout));
|
|
||||||
int color = R.color.openpgp_red;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATE_NOT_ENCRYPTED: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_lock_open));
|
|
||||||
int color = R.color.openpgp_red;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATE_NOT_SIGNED: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_unknown_cutout));
|
|
||||||
int color = R.color.openpgp_red;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STATE_INVALID: {
|
|
||||||
statusIcon.setImageDrawable(
|
|
||||||
context.getResources().getDrawable(R.drawable.status_signature_invalid_cutout));
|
|
||||||
int color = R.color.openpgp_red;
|
|
||||||
statusIcon.setColorFilter(context.getResources().getColor(color),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
if (statusText != null) {
|
|
||||||
statusText.setTextColor(context.getResources().getColor(color));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private enum CryptoState {
|
||||||
|
VERIFIED(R.drawable.status_signature_verified_cutout, R.color.openpgp_green),
|
||||||
|
ENCRYPTED(R.drawable.status_lock_closed, R.color.openpgp_green),
|
||||||
|
|
||||||
|
UNAVAILABLE(R.drawable.status_signature_unverified_cutout, R.color.openpgp_orange),
|
||||||
|
UNVERIFIED(R.drawable.status_signature_unverified_cutout, R.color.openpgp_orange),
|
||||||
|
UNKNOWN_KEY(R.drawable.status_signature_unknown_cutout, R.color.openpgp_orange),
|
||||||
|
|
||||||
|
REVOKED(R.drawable.status_signature_revoked_cutout, R.color.openpgp_red),
|
||||||
|
EXPIRED(R.drawable.status_signature_expired_cutout, R.color.openpgp_red),
|
||||||
|
NOT_ENCRYPTED(R.drawable.status_lock_open, R.color.openpgp_red),
|
||||||
|
NOT_SIGNED(R.drawable.status_signature_unknown_cutout, R.color.openpgp_red),
|
||||||
|
INVALID(R.drawable.status_signature_invalid_cutout, R.color.openpgp_red);
|
||||||
|
|
||||||
|
private final int drawableId;
|
||||||
|
private final int colorId;
|
||||||
|
|
||||||
|
CryptoState(int drawableId, int colorId) {
|
||||||
|
this.drawableId = drawableId;
|
||||||
|
this.colorId = colorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDrawableId() {
|
||||||
|
return drawableId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorId() {
|
||||||
|
return colorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user