QR Code import works now
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/import_qrcode_button"
|
android:id="@+id/import_qrcode_button"
|
||||||
@@ -10,4 +10,16 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/menu_importFromQrCode" />
|
android:text="@string/menu_importFromQrCode" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/import_qrcode_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/import_qrcode_progress"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:progress="0" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -354,6 +354,9 @@
|
|||||||
<string name="import_sign_and_upload">Import, Sign, and upload selected keys</string>
|
<string name="import_sign_and_upload">Import, Sign, and upload selected keys</string>
|
||||||
<string name="import_finish">Finish</string>
|
<string name="import_finish">Finish</string>
|
||||||
<string name="import_from_clipboard">Import from Clipboard</string>
|
<string name="import_from_clipboard">Import from Clipboard</string>
|
||||||
|
<string name="import_qr_code_missing">Missing QR Codes: %1$s</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>
|
||||||
|
|
||||||
<!-- Intent labels -->
|
<!-- Intent labels -->
|
||||||
<string name="intent_decrypt_file">OpenPGP: Decrypt File</string>
|
<string name="intent_decrypt_file">OpenPGP: Decrypt File</string>
|
||||||
|
|||||||
@@ -17,7 +17,11 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -27,8 +31,10 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.zxing.integration.android.IntentIntegrator;
|
|
||||||
import com.google.zxing.integration.android.IntentIntegratorSupportV4;
|
import com.google.zxing.integration.android.IntentIntegratorSupportV4;
|
||||||
import com.google.zxing.integration.android.IntentResult;
|
import com.google.zxing.integration.android.IntentResult;
|
||||||
|
|
||||||
@@ -36,6 +42,10 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
|||||||
|
|
||||||
private ImportKeysActivity mImportActivity;
|
private ImportKeysActivity mImportActivity;
|
||||||
private Button mButton;
|
private Button mButton;
|
||||||
|
private TextView mText;
|
||||||
|
private ProgressBar mProgress;
|
||||||
|
|
||||||
|
private String[] scannedContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
@@ -57,6 +67,9 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
|||||||
View view = inflater.inflate(R.layout.import_keys_qr_code_fragment, container, false);
|
View view = inflater.inflate(R.layout.import_keys_qr_code_fragment, container, false);
|
||||||
|
|
||||||
mButton = (Button) view.findViewById(R.id.import_qrcode_button);
|
mButton = (Button) view.findViewById(R.id.import_qrcode_button);
|
||||||
|
mText = (TextView) view.findViewById(R.id.import_qrcode_text);
|
||||||
|
mProgress = (ProgressBar) view.findViewById(R.id.import_qrcode_progress);
|
||||||
|
|
||||||
mButton.setOnClickListener(new OnClickListener() {
|
mButton.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,28 +92,65 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case IntentIntegrator.REQUEST_CODE: {
|
case IntentIntegratorSupportV4.REQUEST_CODE: {
|
||||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode,
|
IntentResult scanResult = IntentIntegratorSupportV4.parseActivityResult(requestCode,
|
||||||
data);
|
resultCode, data);
|
||||||
if (scanResult != null && scanResult.getFormatName() != null) {
|
if (scanResult != null && scanResult.getFormatName() != null) {
|
||||||
|
|
||||||
// mScannedContent = scanResult.getContents();
|
Log.d(Constants.TAG, scanResult.getContents());
|
||||||
|
|
||||||
mImportActivity.loadCallback(scanResult.getContents().getBytes(), null);
|
String[] parts = scanResult.getContents().split(",");
|
||||||
|
|
||||||
// mImportData = scanResult.getContents().getBytes();
|
if (parts.length != 3) {
|
||||||
// mImportFilename = null;
|
Toast.makeText(getActivity(), R.string.import_qr_code_wrong, Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// mContentView.setText(mScannedContent);
|
int counter = Integer.valueOf(parts[0]);
|
||||||
// String[] bits = scanResult.getContents().split(",");
|
int size = Integer.valueOf(parts[1]);
|
||||||
// if (bits.length != 2) {
|
String content = parts[2];
|
||||||
// return; // dont know how to handle this. Not a valid code
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// long keyId = Long.parseLong(bits[0]);
|
|
||||||
// String expectedFingerprint = bits[1];
|
|
||||||
|
|
||||||
// importAndSign(keyId, expectedFingerprint);
|
Log.d(Constants.TAG, "" + counter);
|
||||||
|
Log.d(Constants.TAG, "" + size);
|
||||||
|
Log.d(Constants.TAG, "" + content);
|
||||||
|
|
||||||
|
// first qr code -> setup
|
||||||
|
if (counter == 0) {
|
||||||
|
scannedContent = new String[size];
|
||||||
|
mProgress.setMax(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save scanned content
|
||||||
|
scannedContent[counter] = content;
|
||||||
|
|
||||||
|
// get missing numbers
|
||||||
|
ArrayList<Integer> missing = new ArrayList<Integer>();
|
||||||
|
for (int i = 0; i < scannedContent.length; i++) {
|
||||||
|
if (scannedContent[i] == null) {
|
||||||
|
missing.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update progress and text
|
||||||
|
mProgress.setProgress(scannedContent.length - missing.size());
|
||||||
|
String missingString = "";
|
||||||
|
for (int m : missing) {
|
||||||
|
if (!missingString.equals(""))
|
||||||
|
missingString += ", ";
|
||||||
|
missingString += String.valueOf(m + 1);
|
||||||
|
}
|
||||||
|
mText.setText(getString(R.string.import_qr_code_missing, missingString));
|
||||||
|
|
||||||
|
// finished!
|
||||||
|
if (missing.size() == 0) {
|
||||||
|
mText.setText(R.string.import_qr_code_finished);
|
||||||
|
String result = "";
|
||||||
|
for (String in : scannedContent) {
|
||||||
|
result += in;
|
||||||
|
}
|
||||||
|
mImportActivity.loadCallback(result.getBytes(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -112,5 +162,4 @@ public class ImportKeysQrCodeFragment extends Fragment {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,14 +66,14 @@ public class ShareActivity extends SherlockFragmentActivity {
|
|||||||
startActivity(Intent.createChooser(sendIntent,
|
startActivity(Intent.createChooser(sendIntent,
|
||||||
getResources().getText(R.string.shareKeyringWith)));
|
getResources().getText(R.string.shareKeyringWith)));
|
||||||
} else if (ACTION_SHARE_KEYRING_WITH_QR_CODE.equals(action)) {
|
} else if (ACTION_SHARE_KEYRING_WITH_QR_CODE.equals(action)) {
|
||||||
// use barcode scanner integration library
|
|
||||||
// TODO: old new IntentIntegrator(this).shareText(keyringArmored.get(0));
|
|
||||||
ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored
|
ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored
|
||||||
.get(0));
|
.get(0));
|
||||||
dialog.show(getSupportFragmentManager(), "qrCodeShareDialog");
|
dialog.show(getSupportFragmentManager(), "qrCodeShareDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
// close this activity
|
// close this activity
|
||||||
|
// TODO: finish() would also close dialog...
|
||||||
|
// integrate this into new KeyViewActivity when ready
|
||||||
// finish();
|
// finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class ShareQrCodeDialogFragment extends SherlockDialogFragment {
|
|||||||
|
|
||||||
// start with first
|
// start with first
|
||||||
mCounter = 0;
|
mCounter = 0;
|
||||||
mImage.setImageBitmap(QrCodeUtils.getQRCodeBitmap(mContentList.get(mCounter), QR_CODE_SIZE));
|
updateQrCode();
|
||||||
|
|
||||||
// OnClickListener are set in onResume to prevent automatic dismissing of Dialogs
|
// OnClickListener are set in onResume to prevent automatic dismissing of Dialogs
|
||||||
// http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked
|
// http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked
|
||||||
|
|||||||
Reference in New Issue
Block a user