Use key icons in import, prettify items

This commit is contained in:
Dominik Schürmann 2014-09-18 22:05:27 +02:00
parent a77c217b82
commit a454bfd701
6 changed files with 60 additions and 40 deletions

View File

@ -276,6 +276,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
mKeyIdHex = KeyFormattingUtils.convertKeyIdToHex(mKeyId);
mRevoked = key.isRevoked();
mExpired = key.isExpired();
mFingerprintHex = KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint());
mBitStrength = key.getBitStrength();
mCurveOid = key.getCurveOid();

View File

@ -31,6 +31,7 @@ import org.spongycastle.openpgp.PGPSignatureGenerator;
import org.spongycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder;
import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@ -569,6 +570,7 @@ public class PgpSignEncrypt {
SignEncryptResult result =
new SignEncryptResult(SignEncryptResult.RESULT_PENDING_NFC, log);
result.setNfcData(e.hashToSign, e.hashAlgo, e.creationTimestamp);
Log.d(Constants.TAG, "e.hashToSign"+ Hex.toHexString(e.hashToSign));
return result;
}
}

View File

@ -30,6 +30,7 @@ import org.openintents.openpgp.OpenPgpMetadata;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi;
import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.nfc.NfcActivity;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface;
@ -244,10 +245,17 @@ public class OpenPgpService extends RemoteService {
}
byte[] nfcSignedHash = data.getByteArrayExtra(OpenPgpApi.EXTRA_NFC_SIGNED_HASH);
if (nfcSignedHash != null) {
Log.d(Constants.TAG, "nfcSignedHash:" + Hex.toHexString(nfcSignedHash));
} else {
Log.d(Constants.TAG, "nfcSignedHash: null");
}
// carefully: only set if timestamp exists
Date nfcCreationDate = null;
long nfcCreationTimestamp = data.getLongExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, 0);
if (nfcCreationTimestamp != 0) {
long nfcCreationTimestamp = data.getLongExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, -1);
Log.d(Constants.TAG, "nfcCreationTimestamp: " + nfcCreationTimestamp);
if (nfcCreationTimestamp != -1) {
nfcCreationDate = new Date(nfcCreationTimestamp);
}
@ -406,8 +414,8 @@ public class OpenPgpService extends RemoteService {
byte[] nfcSignedHash = data.getByteArrayExtra(OpenPgpApi.EXTRA_NFC_SIGNED_HASH);
// carefully: only set if timestamp exists
Date nfcCreationDate = null;
long nfcCreationTimestamp = data.getLongExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, 0);
if (nfcCreationTimestamp != 0) {
long nfcCreationTimestamp = data.getLongExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, -1);
if (nfcCreationTimestamp != -1) {
nfcCreationDate = new Date(nfcCreationTimestamp);
}

View File

@ -44,8 +44,8 @@ public class SignEncryptResult extends OperationResult {
mKeyIdPassphraseNeeded = keyIdPassphraseNeeded;
}
public void setNfcData(byte[] sessionKey, int nfcAlgo, Date nfcTimestamp) {
mNfcHash = sessionKey;
public void setNfcData(byte[] nfcHash, int nfcAlgo, Date nfcTimestamp) {
mNfcHash = nfcHash;
mNfcAlgo = nfcAlgo;
mNfcTimestamp = nfcTimestamp;
}

View File

@ -21,12 +21,14 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -34,6 +36,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.ui.util.Highlighter;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import java.util.ArrayList;
import java.util.Iterator;
@ -51,7 +54,8 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
public TextView keyId;
public TextView fingerprint;
public TextView algorithm;
public TextView status;
public ImageView status;
public View userIdsDivider;
public LinearLayout userIdsList;
public CheckBox checkBox;
}
@ -114,7 +118,8 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
holder.keyId = (TextView) convertView.findViewById(R.id.subkey_item_key_id);
holder.fingerprint = (TextView) convertView.findViewById(R.id.view_key_fingerprint);
holder.algorithm = (TextView) convertView.findViewById(R.id.algorithm);
holder.status = (TextView) convertView.findViewById(R.id.status);
holder.status = (ImageView) convertView.findViewById(R.id.status);
holder.userIdsDivider = convertView.findViewById(R.id.user_ids_divider);
holder.userIdsList = (LinearLayout) convertView.findViewById(R.id.user_ids_list);
holder.checkBox = (CheckBox) convertView.findViewById(R.id.selected);
convertView.setTag(holder);
@ -159,20 +164,30 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
holder.algorithm.setText(entry.getAlgorithm());
holder.algorithm.setVisibility(View.VISIBLE);
} else {
holder.algorithm.setVisibility(View.INVISIBLE);
holder.algorithm.setVisibility(View.GONE);
}
if (entry.isRevoked()) {
holder.status.setVisibility(View.VISIBLE);
holder.status.setText(R.string.revoked);
KeyFormattingUtils.setStatusImage(getContext(), holder.status, KeyFormattingUtils.STATE_REVOKED);
// no more space for algorithm display
holder.algorithm.setVisibility(View.GONE);
} else if (entry.isExpired()) {
holder.status.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(getContext(), holder.status, KeyFormattingUtils.STATE_EXPIRED);
// no more space for algorithm display
holder.algorithm.setVisibility(View.GONE);
} else {
holder.status.setVisibility(View.GONE);
holder.algorithm.setVisibility(View.VISIBLE);
}
if (entry.getUserIds().size() == 1) {
holder.userIdsList.setVisibility(View.GONE);
holder.userIdsDivider.setVisibility(View.GONE);
} else {
holder.userIdsList.setVisibility(View.VISIBLE);
holder.userIdsDivider.setVisibility(View.VISIBLE);
// destroyLoader view from holder
holder.userIdsList.removeAllViews();

View File

@ -1,20 +1,5 @@
<!--
Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
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/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
@ -67,6 +52,14 @@
android:text="alice@example.com"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/subkey_item_key_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0xBBBBBBBBBBBBBBBB"
android:textAppearance="?android:attr/textAppearanceSmall"
android:typeface="monospace" />
</LinearLayout>
<LinearLayout
@ -76,24 +69,32 @@
android:orientation="vertical"
android:paddingLeft="4dp">
<TextView
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#e00" />
android:layout_gravity="center"
android:src="@drawable/status_signature_revoked_cutout"
android:padding="16dp" />
<TextView
android:id="@+id/algorithm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RSA"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_gravity="right" />
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/user_ids_divider"
android:layout_width="match_parent"
android:layout_height="1dip"
android:gravity="right"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/user_ids_list"
@ -101,14 +102,6 @@
android:layout_height="match_parent"
android:orientation="vertical" />
<TextView
android:id="@+id/subkey_item_key_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0xBBBBBBBBBBBBBBBB"
android:textAppearance="?android:attr/textAppearanceSmall"
android:typeface="monospace" />
<TextView
android:id="@+id/view_key_fingerprint"
android:layout_width="match_parent"
@ -116,6 +109,7 @@
android:text="0000 0000 0000 0000 0000\n0000 0000 0000 0000 0000"
android:typeface="monospace"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>