Tweak QR code capture configuration.

fork-5.53.8
Cody Henthorne 2022-05-30 15:37:01 -04:00
rodzic 259a86b605
commit 2446792c62
5 zmienionych plików z 64 dodań i 62 usunięć

Wyświetl plik

@ -471,6 +471,7 @@
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
<activity android:name=".DeviceActivity"
android:screenOrientation="portrait"
android:label="@string/AndroidManifest__linked_devices"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -1,53 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/halfway_guideline"
android:layout_width="match_parent"
android:layout_height="1dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<org.signal.qr.QrScannerView
android:id="@+id/scanner"
android:layout_width="match_parent"
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" />
<org.thoughtcrime.securesms.components.ShapeScrim
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" />
<LinearLayout
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?android:windowBackground"
android:gravity="center"
android:orientation="vertical"
android:weightSum="2">
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">
<org.thoughtcrime.securesms.components.ShapeScrim
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/devices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_devices_white"
android:tint="@color/core_grey_25"
android:transitionName="devices" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?android:windowBackground"
android:gravity="center"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_add_fragment__scan_the_qr_code_displayed_on_the_device_to_link"
android:textColor="?android:textColorSecondary" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/devices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_devices_white"
android:tint="@color/core_grey_25"
android:transitionName="devices" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_add_fragment__scan_the_qr_code_displayed_on_the_device_to_link"
android:textColor="?android:textColorSecondary" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Wyświetl plik

@ -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...
}

Wyświetl plik

@ -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()