mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Remove base32 TODOs - base64 is just as good.
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@@ -23,9 +24,9 @@ import org.briarproject.R;
|
|||||||
import org.briarproject.android.ActivityComponent;
|
import org.briarproject.android.ActivityComponent;
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.android.api.AndroidExecutor;
|
||||||
import org.briarproject.android.fragment.BaseEventFragment;
|
import org.briarproject.android.fragment.BaseEventFragment;
|
||||||
import org.briarproject.android.view.CameraView;
|
|
||||||
import org.briarproject.android.util.QrCodeDecoder;
|
import org.briarproject.android.util.QrCodeDecoder;
|
||||||
import org.briarproject.android.util.QrCodeUtils;
|
import org.briarproject.android.util.QrCodeUtils;
|
||||||
|
import org.briarproject.android.view.CameraView;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
import org.briarproject.api.event.KeyAgreementAbortedEvent;
|
import org.briarproject.api.event.KeyAgreementAbortedEvent;
|
||||||
import org.briarproject.api.event.KeyAgreementFailedEvent;
|
import org.briarproject.api.event.KeyAgreementFailedEvent;
|
||||||
@@ -49,16 +50,16 @@ import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
|||||||
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
|
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
|
||||||
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
||||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
public class ShowQrCodeFragment extends BaseEventFragment
|
public class ShowQrCodeFragment extends BaseEventFragment
|
||||||
implements QrCodeDecoder.ResultCallback {
|
implements QrCodeDecoder.ResultCallback {
|
||||||
|
|
||||||
public static final String TAG = "ShowQrCodeFragment";
|
private static final String TAG = ShowQrCodeFragment.class.getName();
|
||||||
|
private static final Logger LOG = Logger.getLogger(TAG);
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(ShowQrCodeFragment.class.getName());
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected KeyAgreementTaskFactory keyAgreementTaskFactory;
|
protected KeyAgreementTaskFactory keyAgreementTaskFactory;
|
||||||
@@ -225,8 +226,8 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
statusView.setVisibility(View.INVISIBLE);
|
statusView.setVisibility(INVISIBLE);
|
||||||
cameraView.setVisibility(View.VISIBLE);
|
cameraView.setVisibility(VISIBLE);
|
||||||
gotRemotePayload = false;
|
gotRemotePayload = false;
|
||||||
cameraView.startConsumer();
|
cameraView.startConsumer();
|
||||||
startListening();
|
startListening();
|
||||||
@@ -234,11 +235,10 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
|
|
||||||
private void qrCodeScanned(String content) {
|
private void qrCodeScanned(String content) {
|
||||||
try {
|
try {
|
||||||
// TODO use Base32
|
|
||||||
Payload remotePayload = payloadParser.parse(
|
Payload remotePayload = payloadParser.parse(
|
||||||
Base64.decode(content, 0));
|
Base64.decode(content, 0));
|
||||||
cameraView.setVisibility(View.INVISIBLE);
|
cameraView.setVisibility(INVISIBLE);
|
||||||
statusView.setVisibility(View.VISIBLE);
|
statusView.setVisibility(VISIBLE);
|
||||||
status.setText(R.string.connecting_to_device);
|
status.setText(R.string.connecting_to_device);
|
||||||
task.connectAndRunProtocol(remotePayload);
|
task.connectAndRunProtocol(remotePayload);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -269,11 +269,12 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
listener.runOnUiThread(new Runnable() {
|
listener.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// TODO use Base32
|
|
||||||
String input = Base64.encodeToString(
|
String input = Base64.encodeToString(
|
||||||
payloadEncoder.encode(localPayload), 0);
|
payloadEncoder.encode(localPayload), 0);
|
||||||
qrCode.setImageBitmap(
|
Bitmap bitmap =
|
||||||
QrCodeUtils.createQrCode((Context) listener, input));
|
QrCodeUtils.createQrCode((Context) listener, input);
|
||||||
|
if (bitmap == null) return;
|
||||||
|
qrCode.setImageBitmap(bitmap);
|
||||||
// Simple fade-in animation
|
// Simple fade-in animation
|
||||||
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
|
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
|
||||||
anim.setDuration(200);
|
anim.setDuration(200);
|
||||||
|
|||||||
@@ -2,16 +2,20 @@ package org.briarproject.android.util;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static android.graphics.Bitmap.Config.ARGB_8888;
|
||||||
|
import static android.graphics.Color.BLACK;
|
||||||
|
import static android.graphics.Color.WHITE;
|
||||||
|
import static com.google.zxing.BarcodeFormat.QR_CODE;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
public class QrCodeUtils {
|
public class QrCodeUtils {
|
||||||
@@ -19,6 +23,7 @@ public class QrCodeUtils {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(QrCodeUtils.class.getName());
|
Logger.getLogger(QrCodeUtils.class.getName());
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Bitmap createQrCode(Context context, String input) {
|
public static Bitmap createQrCode(Context context, String input) {
|
||||||
// Get narrowest screen dimension
|
// Get narrowest screen dimension
|
||||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
@@ -26,24 +31,21 @@ public class QrCodeUtils {
|
|||||||
try {
|
try {
|
||||||
// Generate QR code
|
// Generate QR code
|
||||||
final BitMatrix encoded = new QRCodeWriter().encode(
|
final BitMatrix encoded = new QRCodeWriter().encode(
|
||||||
input, BarcodeFormat.QR_CODE, smallestDimen, smallestDimen);
|
input, QR_CODE, smallestDimen, smallestDimen);
|
||||||
// Convert QR code to Bitmap
|
// Convert QR code to Bitmap
|
||||||
int width = encoded.getWidth();
|
int width = encoded.getWidth();
|
||||||
int height = encoded.getHeight();
|
int height = encoded.getHeight();
|
||||||
int[] pixels = new int[width * height];
|
int[] pixels = new int[width * height];
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
pixels[y * width + x] =
|
pixels[y * width + x] = encoded.get(x, y) ? BLACK : WHITE;
|
||||||
encoded.get(x, y) ? Color.BLACK : Color.WHITE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bitmap qr = Bitmap.createBitmap(width, height,
|
Bitmap qr = Bitmap.createBitmap(width, height, ARGB_8888);
|
||||||
Bitmap.Config.ARGB_8888);
|
|
||||||
qr.setPixels(pixels, 0, width, 0, 0, width, height);
|
qr.setPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
return qr;
|
return qr;
|
||||||
} catch (WriterException e) {
|
} catch (WriterException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
LOG.log(WARNING, e.toString(), e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user