mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
Colorize fingerprint
This commit is contained in:
parent
50d9908baf
commit
059e57c5d0
@ -87,7 +87,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the actual PGPPublicKeyRing object from the database blob based on the maserKeyId
|
* Retrieves the actual PGPPublicKeyRing object from the database blob based on the masterKeyId
|
||||||
*/
|
*/
|
||||||
public static PGPPublicKeyRing getPGPPublicKeyRingByMasterKeyId(Context context,
|
public static PGPPublicKeyRing getPGPPublicKeyRingByMasterKeyId(Context context,
|
||||||
long masterKeyId) {
|
long masterKeyId) {
|
||||||
@ -110,11 +110,8 @@ public class ProviderHelper {
|
|||||||
*/
|
*/
|
||||||
public static PGPPublicKey getPGPPublicKeyByKeyId(Context context, long keyId) {
|
public static PGPPublicKey getPGPPublicKeyByKeyId(Context context, long keyId) {
|
||||||
PGPPublicKeyRing keyRing = getPGPPublicKeyRingByKeyId(context, keyId);
|
PGPPublicKeyRing keyRing = getPGPPublicKeyRingByKeyId(context, keyId);
|
||||||
if (keyRing == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return keyRing.getPublicKey(keyId);
|
return (keyRing == null)? null : keyRing.getPublicKey(keyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,11 +146,8 @@ public class ProviderHelper {
|
|||||||
*/
|
*/
|
||||||
public static PGPSecretKey getPGPSecretKeyByKeyId(Context context, long keyId) {
|
public static PGPSecretKey getPGPSecretKeyByKeyId(Context context, long keyId) {
|
||||||
PGPSecretKeyRing keyRing = getPGPSecretKeyRingByKeyId(context, keyId);
|
PGPSecretKeyRing keyRing = getPGPSecretKeyRingByKeyId(context, keyId);
|
||||||
if (keyRing == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return keyRing.getSecretKey(keyId);
|
return (keyRing == null) ? null : keyRing.getSecretKey(keyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,13 +19,17 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -257,10 +261,10 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
// FALLBACK for old database entries
|
// FALLBACK for old database entries
|
||||||
fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri);
|
fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri);
|
||||||
}
|
}
|
||||||
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true);
|
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true)
|
||||||
fingerprint = fingerprint.replace(" ", "\n");
|
.replace(" ", "\n");
|
||||||
|
|
||||||
mFingerprint.setText(fingerprint);
|
mFingerprint.setText(colorizeFingerprint(fingerprint));
|
||||||
}
|
}
|
||||||
|
|
||||||
mKeysAdapter.swapCursor(data);
|
mKeysAdapter.swapCursor(data);
|
||||||
@ -271,6 +275,24 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SpannableStringBuilder colorizeFingerprint(String fingerprint) {
|
||||||
|
SpannableStringBuilder sb = new SpannableStringBuilder(fingerprint);
|
||||||
|
ForegroundColorSpan fcs = new ForegroundColorSpan(Color.BLACK);
|
||||||
|
|
||||||
|
// for each 4 characters of the fingerprint + 1 space
|
||||||
|
for (int i = 0; i < fingerprint.length(); i += 5) {
|
||||||
|
String fourChars = fingerprint.substring(i, Math.min(i + 4, fingerprint.length()));
|
||||||
|
|
||||||
|
// Create a foreground color by converting the 4 fingerprint chars to an int hashcode
|
||||||
|
// and then converting that int to hex to use as a color
|
||||||
|
fcs = new ForegroundColorSpan(
|
||||||
|
Color.parseColor(String.format("#%06X", (0xFFFFFF & fourChars.hashCode()))));
|
||||||
|
sb.setSpan(fcs, i, Math.min(i+4, fingerprint.length()), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
|
* This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
|
||||||
* We need to make sure we are no longer using it.
|
* We need to make sure we are no longer using it.
|
||||||
|
Loading…
Reference in New Issue
Block a user