Fix layout, add API notes to README, register fingerprint URIs, some reformatting (sry)
This commit is contained in:
@@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@@ -35,6 +36,7 @@ import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Bundle;
|
||||
@@ -56,6 +58,8 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
public static final String ACTION_IMPORT_KEY = Constants.INTENT_PREFIX + "IMPORT_KEY";
|
||||
public static final String ACTION_IMPORT_KEY_FROM_QR_CODE = Constants.INTENT_PREFIX
|
||||
+ "IMPORT_KEY_FROM_QR_CODE";
|
||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = Constants.INTENT_PREFIX
|
||||
+ "IMPORT_KEY_FROM_KEYSERVER";
|
||||
|
||||
// Actions for internal use only:
|
||||
public static final String ACTION_IMPORT_KEY_FROM_FILE = Constants.INTENT_PREFIX
|
||||
@@ -63,24 +67,21 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
public static final String ACTION_IMPORT_KEY_FROM_NFC = Constants.INTENT_PREFIX
|
||||
+ "IMPORT_KEY_FROM_NFC";
|
||||
|
||||
// only used by IMPORT
|
||||
// only used by ACTION_IMPORT_KEY
|
||||
public static final String EXTRA_KEY_BYTES = "key_bytes";
|
||||
|
||||
// TODO: import keys from server
|
||||
// public static final String EXTRA_KEY_ID = "keyId";
|
||||
// only used by ACTION_IMPORT_KEY_FROM_KEYSERVER
|
||||
public static final String EXTRA_QUERY = "query";
|
||||
|
||||
public static final String FINGERPRINT_SCHEME = "openpgp4fpr";
|
||||
|
||||
protected boolean mDeleteAfterImport = false;
|
||||
|
||||
FileDialogFragment mFileDialog;
|
||||
ImportKeysListFragment mListFragment;
|
||||
OnNavigationListener mOnNavigationListener;
|
||||
String[] mNavigationStrings;
|
||||
|
||||
Fragment mCurrentFragment;
|
||||
|
||||
BootstrapButton mImportButton;
|
||||
|
||||
// BootstrapButton mImportSignUploadButton;
|
||||
// view
|
||||
private ImportKeysListFragment mListFragment;
|
||||
private String[] mNavigationStrings;
|
||||
private Fragment mCurrentFragment;
|
||||
private BootstrapButton mImportButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -95,21 +96,11 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
importKeys();
|
||||
}
|
||||
});
|
||||
// mImportSignUploadButton = (BootstrapButton) findViewById(R.id.import_sign_and_upload);
|
||||
// mImportSignUploadButton.setOnClickListener(new OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// signAndUploadOnClick();
|
||||
// }
|
||||
// });
|
||||
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
|
||||
setupDrawerNavigation(savedInstanceState);
|
||||
|
||||
// set actionbar without home button if called from another app
|
||||
// ActionBarHelper.setBackButton(this);
|
||||
|
||||
// set drop down navigation
|
||||
mNavigationStrings = getResources().getStringArray(R.array.import_action_list);
|
||||
Context context = getSupportActionBar().getThemedContext();
|
||||
@@ -125,6 +116,8 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
protected void handleActions(Bundle savedInstanceState, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Bundle extras = intent.getExtras();
|
||||
Uri dataUri = intent.getData();
|
||||
String scheme = intent.getScheme();
|
||||
|
||||
if (extras == null) {
|
||||
extras = new Bundle();
|
||||
@@ -139,6 +132,15 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
action = ACTION_IMPORT_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scanning a fingerprint directly with Barcode Scanner
|
||||
*/
|
||||
if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(FINGERPRINT_SCHEME)) {
|
||||
getSupportActionBar().setSelectedNavigationItem(0);
|
||||
loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[0]);
|
||||
loadFromFingerprintUri(dataUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keychain's own Actions
|
||||
*/
|
||||
@@ -160,14 +162,25 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
// directly load data
|
||||
startListFragment(savedInstanceState, importData, null);
|
||||
}
|
||||
} else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)) {
|
||||
if (!extras.containsKey(EXTRA_QUERY)) {
|
||||
Log.e(Constants.TAG, "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query' extra!");
|
||||
return;
|
||||
}
|
||||
|
||||
String query = extras.getString(EXTRA_QUERY);
|
||||
|
||||
// TODO: implement KEYSERVER!
|
||||
|
||||
} else {
|
||||
// Internal actions
|
||||
// Other actions
|
||||
startListFragment(savedInstanceState, null, null);
|
||||
|
||||
if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
|
||||
getSupportActionBar().setSelectedNavigationItem(1);
|
||||
loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]);
|
||||
} else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) {
|
||||
// also exposed in AndroidManifest
|
||||
getSupportActionBar().setSelectedNavigationItem(2);
|
||||
loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[2]);
|
||||
} else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
|
||||
@@ -239,6 +252,23 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
public void loadFromFingerprintUri(Uri dataUri) {
|
||||
String fingerprint = dataUri.toString().split(":")[1].toLowerCase(Locale.ENGLISH);
|
||||
|
||||
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
|
||||
|
||||
if (fingerprint.length() < 16) {
|
||||
Toast.makeText(this, R.string.import_qr_code_too_short_fingerprint,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent queryIntent = new Intent(this, KeyServerQueryActivity.class);
|
||||
queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
|
||||
queryIntent.putExtra(KeyServerQueryActivity.EXTRA_FINGERPRINT, fingerprint);
|
||||
startActivity(queryIntent);
|
||||
}
|
||||
|
||||
public void loadCallback(byte[] importData, String importFilename) {
|
||||
mListFragment.loadNew(importData, importFilename);
|
||||
}
|
||||
@@ -413,19 +443,6 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
|
||||
}
|
||||
}
|
||||
|
||||
public void importOnClick() {
|
||||
importKeys();
|
||||
}
|
||||
|
||||
// public void signAndUploadOnClick() {
|
||||
// // first, import!
|
||||
// // importOnClick(view);
|
||||
//
|
||||
// // TODO: implement sign and upload!
|
||||
// Toast.makeText(ImportKeysActivity.this, "Not implemented right now!", Toast.LENGTH_SHORT)
|
||||
// .show();
|
||||
// }
|
||||
|
||||
/**
|
||||
* NFC
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -101,8 +102,8 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
Log.d(Constants.TAG, "scanResult content: " + scanResult.getContents());
|
||||
|
||||
// look if it's fingerprint only
|
||||
if (scanResult.getContents().toLowerCase(Locale.ENGLISH).startsWith("openpgp4fpr")) {
|
||||
importFingerprint(scanResult.getContents().toLowerCase(Locale.ENGLISH));
|
||||
if (scanResult.getContents().toLowerCase(Locale.ENGLISH).startsWith(ImportKeysActivity.FINGERPRINT_SCHEME)) {
|
||||
importFingerprint(Uri.parse(scanResult.getContents()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,21 +129,8 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void importFingerprint(String uri) {
|
||||
String fingerprint = uri.split(":")[1];
|
||||
|
||||
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
|
||||
|
||||
if (fingerprint.length() < 16) {
|
||||
Toast.makeText(getActivity(), R.string.import_qr_code_too_short_fingerprint,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent queryIntent = new Intent(getActivity(), KeyServerQueryActivity.class);
|
||||
queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
|
||||
queryIntent.putExtra(KeyServerQueryActivity.EXTRA_FINGERPRINT, fingerprint);
|
||||
startActivity(queryIntent);
|
||||
public void importFingerprint(Uri dataUri) {
|
||||
mImportActivity.loadFromFingerprintUri(dataUri);
|
||||
}
|
||||
|
||||
private void importParts(String[] parts) {
|
||||
|
||||
@@ -32,10 +32,12 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
public class ImportKeysServerFragment extends Fragment {
|
||||
private BootstrapButton mButton;
|
||||
|
||||
String mQuery;
|
||||
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
*/
|
||||
public static ImportKeysServerFragment newInstance() {
|
||||
public static ImportKeysServerFragment newInstance(String query) {
|
||||
ImportKeysServerFragment frag = new ImportKeysServerFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ImportKeysListEntry implements Serializable {
|
||||
|
||||
this.revoked = pgpKeyRing.getPublicKey().isRevoked();
|
||||
this.fingerPrint = PgpKeyHelper.convertFingerprintToHex(pgpKeyRing.getPublicKey()
|
||||
.getFingerprint());
|
||||
.getFingerprint(), true);
|
||||
this.hexKeyId = PgpKeyHelper.convertKeyIdToHex(keyId);
|
||||
this.bitStrength = pgpKeyRing.getPublicKey().getBitStrength();
|
||||
int algorithm = pgpKeyRing.getPublicKey().getAlgorithm();
|
||||
|
||||
@@ -40,12 +40,14 @@ import android.widget.TextView;
|
||||
import com.actionbarsherlock.app.SherlockDialogFragment;
|
||||
|
||||
public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
||||
private static final String ARG_URI = "uri";
|
||||
private static final String ARG_KEY_URI = "uri";
|
||||
private static final String ARG_FINGERPRINT_ONLY = "fingerprint_only";
|
||||
|
||||
private ImageView mImage;
|
||||
private TextView mText;
|
||||
|
||||
private boolean mFingerprintOnly;
|
||||
|
||||
private ArrayList<String> mContentList;
|
||||
private int mCounter;
|
||||
|
||||
@@ -53,15 +55,11 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
||||
|
||||
/**
|
||||
* Creates new instance of this dialog fragment
|
||||
*
|
||||
* @param content
|
||||
* Content to be shared via QR Codes
|
||||
* @return
|
||||
*/
|
||||
public static ShareQrCodeDialogFragment newInstance(Uri dataUri, boolean fingerprintOnly) {
|
||||
ShareQrCodeDialogFragment frag = new ShareQrCodeDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_URI, dataUri);
|
||||
args.putParcelable(ARG_KEY_URI, dataUri);
|
||||
args.putBoolean(ARG_FINGERPRINT_ONLY, fingerprintOnly);
|
||||
|
||||
frag.setArguments(args);
|
||||
@@ -76,8 +74,8 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Activity activity = getActivity();
|
||||
|
||||
Uri dataUri = getArguments().getParcelable(ARG_URI);
|
||||
boolean fingerprintOnly = getArguments().getBoolean(ARG_FINGERPRINT_ONLY);
|
||||
Uri dataUri = getArguments().getParcelable(ARG_KEY_URI);
|
||||
mFingerprintOnly = getArguments().getBoolean(ARG_FINGERPRINT_ONLY);
|
||||
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
|
||||
|
||||
@@ -90,29 +88,31 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
||||
mImage = (ImageView) view.findViewById(R.id.share_qr_code_dialog_image);
|
||||
mText = (TextView) view.findViewById(R.id.share_qr_code_dialog_text);
|
||||
|
||||
// TODO
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||
|
||||
String content = null;
|
||||
if (fingerprintOnly) {
|
||||
if (mFingerprintOnly) {
|
||||
content = "openpgp4fpr:";
|
||||
|
||||
String fingerprint = PgpKeyHelper.convertKeyToHex(masterKeyId);
|
||||
|
||||
mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " "
|
||||
+ fingerprint);
|
||||
byte[] fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), dataUri);
|
||||
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, false);
|
||||
|
||||
mText.setText(getString(R.string.share_qr_code_dialog_fingerprint_text) + " " + fingerprint);
|
||||
content = content + fingerprint;
|
||||
|
||||
Log.d(Constants.TAG, "content: " + content);
|
||||
|
||||
alert.setPositiveButton(R.string.btn_okay, null);
|
||||
|
||||
setQrCode(content);
|
||||
} else {
|
||||
mText.setText(R.string.share_qr_code_dialog_start);
|
||||
|
||||
// TODO
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||
|
||||
|
||||
// get public keyring as ascii armored string
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||
getActivity(), dataUri, new long[] { masterKeyId });
|
||||
getActivity(), dataUri, new long[]{masterKeyId});
|
||||
|
||||
// TODO: binary?
|
||||
|
||||
@@ -122,55 +122,61 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
||||
// http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked
|
||||
alert.setPositiveButton(R.string.btn_next, null);
|
||||
alert.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
mContentList = splitString(content, 1000);
|
||||
|
||||
// start with first
|
||||
mCounter = 0;
|
||||
updatePartsQrCode();
|
||||
}
|
||||
|
||||
mContentList = splitString(content, 1000);
|
||||
|
||||
// start with first
|
||||
mCounter = 0;
|
||||
updateQrCode();
|
||||
|
||||
return alert.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
AlertDialog alertDialog = (AlertDialog) getDialog();
|
||||
final Button backButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
final Button nextButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
|
||||
backButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mCounter > 0) {
|
||||
mCounter--;
|
||||
updateQrCode();
|
||||
updateDialog(backButton, nextButton);
|
||||
} else {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!mFingerprintOnly) {
|
||||
AlertDialog alertDialog = (AlertDialog) getDialog();
|
||||
final Button backButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
final Button nextButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
|
||||
if (mCounter < mContentList.size() - 1) {
|
||||
mCounter++;
|
||||
updateQrCode();
|
||||
updateDialog(backButton, nextButton);
|
||||
} else {
|
||||
dismiss();
|
||||
backButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mCounter > 0) {
|
||||
mCounter--;
|
||||
updatePartsQrCode();
|
||||
updateDialog(backButton, nextButton);
|
||||
} else {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (mCounter < mContentList.size() - 1) {
|
||||
mCounter++;
|
||||
updatePartsQrCode();
|
||||
updateDialog(backButton, nextButton);
|
||||
} else {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateQrCode() {
|
||||
private void updatePartsQrCode() {
|
||||
// Content: <counter>,<size>,<content>
|
||||
mImage.setImageBitmap(QrCodeUtils.getQRCodeBitmap(mCounter + "," + mContentList.size()
|
||||
+ "," + mContentList.get(mCounter), QR_CODE_SIZE));
|
||||
setQrCode(mCounter + "," + mContentList.size() + "," + mContentList.get(mCounter));
|
||||
}
|
||||
|
||||
private void setQrCode(String data) {
|
||||
mImage.setImageBitmap(QrCodeUtils.getQRCodeBitmap(data, QR_CODE_SIZE));
|
||||
}
|
||||
|
||||
private void updateDialog(Button backButton, Button nextButton) {
|
||||
@@ -191,7 +197,7 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
||||
|
||||
/**
|
||||
* Split String by number of characters
|
||||
*
|
||||
*
|
||||
* @param text
|
||||
* @param size
|
||||
* @return
|
||||
|
||||
Reference in New Issue
Block a user