diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a1e467da0..6108ee9c7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -471,6 +471,7 @@ android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> diff --git a/app/src/main/java/org/thoughtcrime/securesms/DeviceAddFragment.java b/app/src/main/java/org/thoughtcrime/securesms/DeviceAddFragment.java index 35e31f354..e21c160f3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/DeviceAddFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/DeviceAddFragment.java @@ -28,24 +28,17 @@ public class DeviceAddFragment extends LoggingFragment { private final LifecycleDisposable lifecycleDisposable = new LifecycleDisposable(); - private LinearLayout overlay; private ImageView devicesImage; private ScanListener scanListener; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { ViewGroup container = ViewUtil.inflate(inflater, viewGroup, R.layout.device_add_fragment); - this.overlay = container.findViewById(R.id.overlay); + QrScannerView scannerView = container.findViewById(R.id.scanner); this.devicesImage = container.findViewById(R.id.devices); ViewCompat.setTransitionName(devicesImage, "devices"); - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - this.overlay.setOrientation(LinearLayout.HORIZONTAL); - } else { - this.overlay.setOrientation(LinearLayout.VERTICAL); - } - if (Build.VERSION.SDK_INT >= 21) { container.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @TargetApi(21) @@ -82,17 +75,6 @@ public class DeviceAddFragment extends LoggingFragment { return container; } - @Override - public void onConfigurationChanged(@NonNull Configuration newConfiguration) { - super.onConfigurationChanged(newConfiguration); - - if (newConfiguration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - overlay.setOrientation(LinearLayout.HORIZONTAL); - } else { - overlay.setOrientation(LinearLayout.VERTICAL); - } - } - public ImageView getDevicesImage() { return devicesImage; } diff --git a/app/src/main/res/layout/device_add_fragment.xml b/app/src/main/res/layout/device_add_fragment.xml index 5af655f51..64836f7fb 100644 --- a/app/src/main/res/layout/device_add_fragment.xml +++ b/app/src/main/res/layout/device_add_fragment.xml @@ -1,53 +1,61 @@ - - + android:layout_height="match_parent"> + + + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintBottom_toTopOf="@+id/halfway_guideline" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + android:paddingStart="16dp" + android:paddingEnd="16dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/halfway_guideline"> - + - + - - - - - - + diff --git a/qr/lib/src/main/java/org/signal/qr/QrProcessor.kt b/qr/lib/src/main/java/org/signal/qr/QrProcessor.kt index a0b645dbb..a720ec181 100644 --- a/qr/lib/src/main/java/org/signal/qr/QrProcessor.kt +++ b/qr/lib/src/main/java/org/signal/qr/QrProcessor.kt @@ -18,12 +18,21 @@ class QrProcessor { private val reader = QRCodeReader() + private var previousHeight = 0 + private var previousWidth = 0 + fun getScannedData( data: ByteArray, width: Int, height: Int ): String? { try { + if (width != previousWidth || height != previousHeight) { + Log.i(TAG, "Processing $width x $height image, data: ${data.size}") + previousWidth = width + previousHeight = height + } + val source = PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false) val bitmap = BinaryBitmap(HybridBinarizer(source)) @@ -33,11 +42,11 @@ class QrProcessor { return result.text } } catch (e: NullPointerException) { - Log.w(TAG, e) + Log.w(TAG, "Random null", e) } catch (e: ChecksumException) { - Log.w(TAG, e) + Log.w(TAG, "QR code read and decoded, but checksum failed", e) } catch (e: FormatException) { - Log.w(TAG, e) + Log.w(TAG, "Thrown when a barcode was successfully detected, but some aspect of the content did not conform to the barcodes format rules.", e) } catch (e: NotFoundException) { // Thanks ZXing... } diff --git a/qr/lib/src/main/java/org/signal/qr/ScannerView21.kt b/qr/lib/src/main/java/org/signal/qr/ScannerView21.kt index 3831fa960..e329ded1e 100644 --- a/qr/lib/src/main/java/org/signal/qr/ScannerView21.kt +++ b/qr/lib/src/main/java/org/signal/qr/ScannerView21.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.widget.FrameLayout import androidx.annotation.RequiresApi +import androidx.camera.core.AspectRatio import androidx.camera.core.Camera import androidx.camera.core.CameraSelector import androidx.camera.core.ImageAnalysis @@ -73,6 +74,7 @@ internal class ScannerView21 constructor( val preview = Preview.Builder().build() val imageAnalysis = ImageAnalysis.Builder() + .setTargetAspectRatio(AspectRatio.RATIO_16_9) .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) .build()