mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 03:02:15 -05:00
fix qr code scanning, implement basic scanning of fingerprint only
This commit is contained in:
parent
1bac2849b8
commit
88aa439ea7
@ -320,6 +320,7 @@
|
||||
<string name="import_qr_code_start_with_one">Please start with QR Code with ID 1</string>
|
||||
<string name="import_qr_code_wrong">QR Code malformed! Please try again!</string>
|
||||
<string name="import_qr_code_finished">QR Code scanning finished!</string>
|
||||
<string name="import_qr_code_too_short_fingerprint">Fingerprint contained in this QR Code is too short (< 16 characters)</string>
|
||||
<string name="import_qr_scan_button">Scan QR Code with \'Barcode Scanner\'</string>
|
||||
<string name="import_nfc_text">To receive keys via NFC, the device needs to be unlocked.</string>
|
||||
<string name="import_nfc_help_button">Help</string>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2013-2014 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
|
||||
@ -18,9 +18,11 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import android.content.Intent;
|
||||
@ -35,7 +37,6 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
public class ImportKeysQrCodeFragment extends Fragment {
|
||||
@ -75,7 +76,7 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// scan using xzing's Barcode Scanner
|
||||
new IntentIntegrator(getActivity()).initiateScan();
|
||||
new IntentIntegratorSupportV4(ImportKeysQrCodeFragment.this).initiateScan();
|
||||
}
|
||||
});
|
||||
|
||||
@ -92,21 +93,59 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode & 0xFFFF) {
|
||||
case IntentIntegrator.REQUEST_CODE: {
|
||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode,
|
||||
data);
|
||||
case IntentIntegratorSupportV4.REQUEST_CODE: {
|
||||
IntentResult scanResult = IntentIntegratorSupportV4.parseActivityResult(requestCode,
|
||||
resultCode, data);
|
||||
if (scanResult != null && scanResult.getFormatName() != null) {
|
||||
|
||||
Log.d(Constants.TAG, scanResult.getContents());
|
||||
Log.d(Constants.TAG, "scanResult content: " + scanResult.getContents());
|
||||
|
||||
String[] parts = scanResult.getContents().split(",");
|
||||
|
||||
if (parts.length != 3) {
|
||||
Toast.makeText(getActivity(), R.string.import_qr_code_wrong, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
// look if it's fingerprint only
|
||||
if (scanResult.getContents().toLowerCase(Locale.ENGLISH).startsWith("openpgp4fpr")) {
|
||||
importFingerprint(scanResult.getContents().toLowerCase(Locale.ENGLISH));
|
||||
return;
|
||||
}
|
||||
|
||||
// look if it is the whole key
|
||||
String[] parts = scanResult.getContents().split(",");
|
||||
if (parts.length == 3) {
|
||||
importParts(parts);
|
||||
return;
|
||||
}
|
||||
|
||||
// fail...
|
||||
Toast.makeText(getActivity(), R.string.import_qr_code_wrong, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void importParts(String[] parts) {
|
||||
int counter = Integer.valueOf(parts[0]);
|
||||
int size = Integer.valueOf(parts[1]);
|
||||
String content = parts[2];
|
||||
@ -124,8 +163,8 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
}
|
||||
|
||||
if (mScannedContent == null || counter > mScannedContent.length) {
|
||||
Toast.makeText(getActivity(), R.string.import_qr_code_start_with_one,
|
||||
Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getActivity(), R.string.import_qr_code_start_with_one, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -152,8 +191,8 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
missingString += String.valueOf(m + 1);
|
||||
}
|
||||
|
||||
String missingText = getResources().getQuantityString(
|
||||
R.plurals.import_qr_code_missing, missing.size(), missingString);
|
||||
String missingText = getResources().getQuantityString(R.plurals.import_qr_code_missing,
|
||||
missing.size(), missingString);
|
||||
mText.setText(missingText);
|
||||
|
||||
// finished!
|
||||
@ -167,13 +206,4 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -66,23 +66,19 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
|
||||
+ "LOOK_UP_KEY_ID_AND_RETURN";
|
||||
|
||||
public static final String EXTRA_KEY_ID = "key_id";
|
||||
public static final String EXTRA_FINGERPRINT = "fingerprint";
|
||||
|
||||
public static final String RESULT_EXTRA_TEXT = "text";
|
||||
|
||||
private ListView mList;
|
||||
|
||||
private EditText mQuery;
|
||||
|
||||
private Button mSearch;
|
||||
private Spinner mKeyServer;
|
||||
|
||||
private KeyInfoListAdapter mAdapter;
|
||||
|
||||
private Spinner mKeyServer;
|
||||
|
||||
private int mQueryType;
|
||||
|
||||
private String mQueryString;
|
||||
|
||||
private long mQueryId;
|
||||
|
||||
private volatile List<KeyInfo> mSearchResult;
|
||||
@ -168,6 +164,12 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
|
||||
mQuery.setText(query);
|
||||
search(query);
|
||||
}
|
||||
String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT);
|
||||
if (fingerprint != null) {
|
||||
fingerprint = "0x" + fingerprint;
|
||||
mQuery.setText(fingerprint);
|
||||
search(fingerprint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2012 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
|
||||
/**
|
||||
* IntentIntegrator for the V4 Android compatibility package.
|
||||
*
|
||||
* @author Lachezar Dobrev
|
||||
*/
|
||||
public final class IntentIntegratorSupportV4 extends IntentIntegrator {
|
||||
|
||||
private final Fragment fragment;
|
||||
|
||||
/**
|
||||
* @param fragment
|
||||
* Fragment to handle activity response.
|
||||
*/
|
||||
public IntentIntegratorSupportV4(Fragment fragment) {
|
||||
super(fragment.getActivity());
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startActivityForResult(Intent intent, int code) {
|
||||
fragment.startActivityForResult(intent, code);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user