Merge branch '1177-blank-viewfinder' into 'master'

Show viewfinder again after connection fails

Closes #1177

See merge request akwizgran/briar!735
This commit is contained in:
Torsten Grote
2018-03-20 13:13:14 +00:00
3 changed files with 20 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ import android.content.IntentFilter;
import android.os.Bundle;
import android.support.annotation.UiThread;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.widget.Toolbar;
@@ -206,11 +207,14 @@ public class KeyAgreementActivity extends BriarActivity implements
private void showQrCodeFragment() {
// FIXME #824
BaseFragment f = ShowQrCodeFragment.newInstance();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
.addToBackStack(f.getUniqueTag())
.commit();
FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentByTag(ShowQrCodeFragment.TAG) == null) {
BaseFragment f = ShowQrCodeFragment.newInstance();
fm.beginTransaction()
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
.addToBackStack(f.getUniqueTag())
.commit();
}
}
private boolean checkPermissions() {

View File

@@ -24,7 +24,6 @@ import java.util.logging.Logger;
import static com.google.zxing.DecodeHintType.CHARACTER_SET;
import static java.util.Collections.singletonMap;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@SuppressWarnings("deprecation")
@@ -67,7 +66,6 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (camera == this.camera) {
LOG.info("Got preview frame");
try {
Size size = camera.getParameters().getPreviewSize();
// The preview should be in NV21 format: width * height bytes of
@@ -105,20 +103,13 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
@Override
protected Void doInBackground(Void... params) {
long now = System.currentTimeMillis();
BinaryBitmap bitmap = binarize(data, width, height, orientation);
Result result;
try {
result = reader.decode(bitmap,
singletonMap(CHARACTER_SET, "ISO8859_1"));
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Decoding barcode took " + duration + " ms");
} catch (ReaderException e) {
// No barcode found
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("No barcode found after " + duration + " ms");
return null;
} catch (RuntimeException e) {
LOG.warning("Invalid preview frame");

View File

@@ -61,7 +61,8 @@ import static java.util.logging.Level.WARNING;
public class ShowQrCodeFragment extends BaseEventFragment
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 Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
@@ -207,6 +208,15 @@ public class ShowQrCodeFragment extends BaseEventFragment
@UiThread
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);
cameraView.setVisibility(VISIBLE);
gotRemotePayload = false;