mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Merge branch '1177-blank-viewfinder' into 'maintenance-0.16'
Backport: Show viewfinder again after connection fails See merge request akwizgran/briar!736
This commit is contained in:
@@ -9,6 +9,7 @@ import android.content.IntentFilter;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog.Builder;
|
import android.support.v7.app.AlertDialog.Builder;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
@@ -206,11 +207,14 @@ public class KeyAgreementActivity extends BriarActivity implements
|
|||||||
|
|
||||||
private void showQrCodeFragment() {
|
private void showQrCodeFragment() {
|
||||||
// FIXME #824
|
// FIXME #824
|
||||||
BaseFragment f = ShowQrCodeFragment.newInstance();
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
getSupportFragmentManager().beginTransaction()
|
if (fm.findFragmentByTag(ShowQrCodeFragment.TAG) == null) {
|
||||||
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
|
BaseFragment f = ShowQrCodeFragment.newInstance();
|
||||||
.addToBackStack(f.getUniqueTag())
|
fm.beginTransaction()
|
||||||
.commit();
|
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
|
||||||
|
.addToBackStack(f.getUniqueTag())
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkPermissions() {
|
private boolean checkPermissions() {
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
@Override
|
@Override
|
||||||
public void onPreviewFrame(byte[] data, Camera camera) {
|
public void onPreviewFrame(byte[] data, Camera camera) {
|
||||||
if (camera == this.camera) {
|
if (camera == this.camera) {
|
||||||
LOG.info("Got preview frame");
|
|
||||||
try {
|
try {
|
||||||
Size size = camera.getParameters().getPreviewSize();
|
Size size = camera.getParameters().getPreviewSize();
|
||||||
// The preview should be in NV21 format: width * height bytes of
|
// The preview should be in NV21 format: width * height bytes of
|
||||||
@@ -103,19 +102,12 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
BinaryBitmap bitmap = binarize(data, width, height, orientation);
|
BinaryBitmap bitmap = binarize(data, width, height, orientation);
|
||||||
Result result = null;
|
Result result;
|
||||||
try {
|
try {
|
||||||
result = reader.decode(bitmap);
|
result = reader.decode(bitmap);
|
||||||
long duration = System.currentTimeMillis() - now;
|
|
||||||
if (LOG.isLoggable(INFO))
|
|
||||||
LOG.info("Decoding barcode took " + duration + " ms");
|
|
||||||
} catch (ReaderException e) {
|
} catch (ReaderException e) {
|
||||||
// No barcode found
|
// No barcode found
|
||||||
long duration = System.currentTimeMillis() - now;
|
|
||||||
if (LOG.isLoggable(INFO))
|
|
||||||
LOG.info("No barcode found after " + duration + " ms");
|
|
||||||
return null;
|
return null;
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
LOG.warning("Invalid preview frame");
|
LOG.warning("Invalid preview frame");
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ import static java.util.logging.Level.WARNING;
|
|||||||
public class ShowQrCodeFragment extends BaseEventFragment
|
public class ShowQrCodeFragment extends BaseEventFragment
|
||||||
implements QrCodeDecoder.ResultCallback {
|
implements QrCodeDecoder.ResultCallback {
|
||||||
|
|
||||||
private static final String TAG = ShowQrCodeFragment.class.getName();
|
static final String TAG = ShowQrCodeFragment.class.getName();
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(TAG);
|
private static final Logger LOG = Logger.getLogger(TAG);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -204,6 +205,15 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void reset() {
|
private void reset() {
|
||||||
|
// If we've stopped the camera view, restart it
|
||||||
|
if (gotRemotePayload) {
|
||||||
|
try {
|
||||||
|
cameraView.start(getScreenRotationDegrees());
|
||||||
|
} catch (CameraException e) {
|
||||||
|
logCameraExceptionAndFinish(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
statusView.setVisibility(INVISIBLE);
|
statusView.setVisibility(INVISIBLE);
|
||||||
cameraView.setVisibility(VISIBLE);
|
cameraView.setVisibility(VISIBLE);
|
||||||
gotRemotePayload = false;
|
gotRemotePayload = false;
|
||||||
@@ -218,12 +228,17 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Remote payload is " + encoded.length + " bytes");
|
LOG.info("Remote payload is " + encoded.length + " bytes");
|
||||||
Payload remotePayload = payloadParser.parse(encoded);
|
Payload remotePayload = payloadParser.parse(encoded);
|
||||||
|
gotRemotePayload = true;
|
||||||
|
cameraView.stop();
|
||||||
cameraView.setVisibility(INVISIBLE);
|
cameraView.setVisibility(INVISIBLE);
|
||||||
statusView.setVisibility(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 (CameraException e) {
|
||||||
|
logCameraExceptionAndFinish(e);
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
// TODO show failure
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, "QR Code Invalid", e);
|
||||||
|
reset();
|
||||||
Toast.makeText(getActivity(), R.string.qr_code_invalid,
|
Toast.makeText(getActivity(), R.string.qr_code_invalid,
|
||||||
LENGTH_LONG).show();
|
LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
@@ -261,6 +276,7 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
new AsyncTask<Void, Void, Bitmap>() {
|
new AsyncTask<Void, Void, Bitmap>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
protected Bitmap doInBackground(Void... params) {
|
protected Bitmap doInBackground(Void... params) {
|
||||||
byte[] encoded = payloadEncoder.encode(payload);
|
byte[] encoded = payloadEncoder.encode(payload);
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
@@ -325,13 +341,8 @@ public class ShowQrCodeFragment extends BaseEventFragment
|
|||||||
runOnUiThreadUnlessDestroyed(() -> {
|
runOnUiThreadUnlessDestroyed(() -> {
|
||||||
LOG.info("Got result from decoder");
|
LOG.info("Got result from decoder");
|
||||||
// Ignore results until the KeyAgreementTask is ready
|
// Ignore results until the KeyAgreementTask is ready
|
||||||
if (!gotLocalPayload) {
|
if (!gotLocalPayload) return;
|
||||||
return;
|
if (!gotRemotePayload) qrCodeScanned(result.getText());
|
||||||
}
|
|
||||||
if (!gotRemotePayload) {
|
|
||||||
gotRemotePayload = true;
|
|
||||||
qrCodeScanned(result.getText());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user