When resetting, restart camera if we've stopped it.

This commit is contained in:
akwizgran
2018-03-20 11:58:40 +00:00
parent 54b0bb6084
commit 53f85d4b71

View File

@@ -205,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;
@@ -219,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();
} }
@@ -262,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))
@@ -326,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());
}
}); });
} }