diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util')
3 files changed, 28 insertions, 150 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ExperimentalWordConfirm.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ExperimentalWordConfirm.java deleted file mode 100644 index 43ccac24f..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ExperimentalWordConfirm.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.util; - -import android.content.Context; - -import org.spongycastle.util.Arrays; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.util.Log; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.BitSet; - -public class ExperimentalWordConfirm { - - public static String getWords(Context context, byte[] fingerprintBlob) { - ArrayList<String> words = new ArrayList<>(); - - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader( - context.getAssets().open("word_confirm_list.txt"), - "UTF-8" - )); - - String line = reader.readLine(); - while (line != null) { - words.add(line); - - line = reader.readLine(); - } - } catch (IOException e) { - throw new RuntimeException("IOException", e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException ignored) { - } - } - } - - String fingerprint = ""; - - // NOTE: 160 bit SHA-1 truncated to 156 bit - byte[] fingerprintBlobTruncated = Arrays.copyOfRange(fingerprintBlob, 0, 156 / 8); - - // TODO: implement key stretching to minimize fp length? - - // BitSet bits = BitSet.valueOf(fingerprintBlob); // min API 19 and little endian! - BitSet bits = bitSetToByteArray(fingerprintBlobTruncated); - Log.d(Constants.TAG, "bits: " + bits.toString()); - - final int CHUNK_SIZE = 13; - final int LAST_CHUNK_INDEX = fingerprintBlobTruncated.length * 8 / CHUNK_SIZE; // 12 - Log.d(Constants.TAG, "LAST_CHUNK_INDEX: " + LAST_CHUNK_INDEX); - - int from = 0; - int to = CHUNK_SIZE; - for (int i = 0; i < (LAST_CHUNK_INDEX + 1); i++) { - Log.d(Constants.TAG, "from: " + from + " to: " + to); - - BitSet setIndex = bits.get(from, to); - int wordIndex = (int) bitSetToLong(setIndex); - // int wordIndex = (int) setIndex.toLongArray()[0]; // min API 19 - - fingerprint += words.get(wordIndex); - - if (i != LAST_CHUNK_INDEX) { - // line break every 3 words - if (to % (CHUNK_SIZE * 3) == 0) { - fingerprint += "\n"; - } else { - fingerprint += " "; - } - } - - from = to; - to += CHUNK_SIZE; - } - - return fingerprint; - } - - /** - * Returns a BitSet containing the values in bytes. - * BIG ENDIAN! - */ - private static BitSet bitSetToByteArray(byte[] bytes) { - int arrayLength = bytes.length * 8; - BitSet bits = new BitSet(); - - for (int i = 0; i < arrayLength; i++) { - if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) { - bits.set(i); - } - } - return bits; - } - - private static long bitSetToLong(BitSet bits) { - long value = 0L; - for (int i = 0; i < bits.length(); ++i) { - value += bits.get(i) ? (1L << i) : 0L; - } - return value; - } -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index 8f5753dae..b9b837d71 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -28,6 +28,7 @@ import android.text.style.ForegroundColorSpan; import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import android.widget.ViewAnimator; import org.openintents.openpgp.OpenPgpDecryptionResult; import org.openintents.openpgp.OpenPgpSignatureResult; @@ -440,14 +441,15 @@ public class KeyFormattingUtils { View getSignatureLayout(); TextView getSignatureUserName(); TextView getSignatureUserEmail(); - TextView getSignatureAction(); + ViewAnimator getSignatureAction(); boolean hasEncrypt(); } @SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated - public static void setStatus(Resources resources, StatusHolder holder, DecryptVerifyResult result) { + public static void setStatus(Resources resources, StatusHolder holder, DecryptVerifyResult result, + boolean processingkeyLookup) { if (holder.hasEncrypt()) { OpenPgpDecryptionResult decryptionResult = result.getDecryptionResult(); @@ -488,7 +490,7 @@ public class KeyFormattingUtils { OpenPgpSignatureResult signatureResult = result.getSignatureResult(); int sigText, sigIcon, sigColor; - int sigActionText, sigActionIcon; + int sigActionDisplayedChild; switch (signatureResult.getResult()) { @@ -500,8 +502,7 @@ public class KeyFormattingUtils { sigColor = R.color.key_flag_gray; // won't be used, but makes compiler happy - sigActionText = 0; - sigActionIcon = 0; + sigActionDisplayedChild = -1; break; } @@ -510,8 +511,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_verified_cutout_24dp; sigColor = R.color.key_flag_green; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -520,8 +520,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_unverified_cutout_24dp; sigColor = R.color.key_flag_orange; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -530,8 +529,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_revoked_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -540,8 +538,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_expired_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -550,8 +547,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_unknown_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_Lookup; - sigActionIcon = R.drawable.ic_file_download_grey_24dp; + sigActionDisplayedChild = 1; break; } @@ -560,8 +556,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_invalid_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -571,27 +566,31 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_invalid_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + // won't be used, but makes compiler happy + sigActionDisplayedChild = -1; break; } } + // possibly switch out "Lookup" button for progress bar + if (sigActionDisplayedChild == 1 && processingkeyLookup) { + sigActionDisplayedChild = 2; + } + int sigColorRes = resources.getColor(sigColor); holder.getSignatureStatusIcon().setColorFilter(sigColorRes, PorterDuff.Mode.SRC_IN); holder.getSignatureStatusIcon().setImageDrawable(resources.getDrawable(sigIcon)); holder.getSignatureStatusText().setText(sigText); holder.getSignatureStatusText().setTextColor(sigColorRes); - if (signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE) { + if (signatureResult.getResult() != OpenPgpSignatureResult.RESULT_NO_SIGNATURE + && signatureResult.getResult() != OpenPgpSignatureResult.RESULT_INVALID_SIGNATURE) { // has a signature, thus display layouts holder.getSignatureLayout().setVisibility(View.VISIBLE); - holder.getSignatureAction().setText(sigActionText); - holder.getSignatureAction().setCompoundDrawablesWithIntrinsicBounds( - 0, 0, sigActionIcon, 0); + holder.getSignatureAction().setDisplayedChild(sigActionDisplayedChild); String userId = result.getSignatureResult().getPrimaryUserId(); KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java index 7dfd56430..71f6ecc1a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Notify.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.util.FabContainer; */ public class Notify { - public static enum Style { + public enum Style { OK (R.color.android_green_light), WARN(R.color.android_orange_light), ERROR(R.color.android_red_light); public final int mLineColor; @@ -142,6 +142,11 @@ public class Notify { return create(activity, text, LENGTH_LONG, style); } + public static Showable create(Activity activity, int textResId, Style style, + ActionListener actionListener, int actionResId) { + return create(activity, textResId, LENGTH_LONG, style, actionListener, actionResId); + } + public static Showable create(Activity activity, int textResId, int duration, Style style, ActionListener actionListener, int actionResId) { return create(activity, activity.getString(textResId), duration, style, actionListener, actionResId); |