kopia lustrzana https://github.com/ryukoposting/Signal-Android
Tweak QR code capture configuration.
rodzic
259a86b605
commit
2446792c62
|
@ -471,6 +471,7 @@
|
||||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||||
|
|
||||||
<activity android:name=".DeviceActivity"
|
<activity android:name=".DeviceActivity"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
android:label="@string/AndroidManifest__linked_devices"
|
android:label="@string/AndroidManifest__linked_devices"
|
||||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||||
|
|
||||||
|
|
|
@ -28,24 +28,17 @@ public class DeviceAddFragment extends LoggingFragment {
|
||||||
|
|
||||||
private final LifecycleDisposable lifecycleDisposable = new LifecycleDisposable();
|
private final LifecycleDisposable lifecycleDisposable = new LifecycleDisposable();
|
||||||
|
|
||||||
private LinearLayout overlay;
|
|
||||||
private ImageView devicesImage;
|
private ImageView devicesImage;
|
||||||
private ScanListener scanListener;
|
private ScanListener scanListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
|
||||||
ViewGroup container = ViewUtil.inflate(inflater, viewGroup, R.layout.device_add_fragment);
|
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);
|
QrScannerView scannerView = container.findViewById(R.id.scanner);
|
||||||
this.devicesImage = container.findViewById(R.id.devices);
|
this.devicesImage = container.findViewById(R.id.devices);
|
||||||
ViewCompat.setTransitionName(devicesImage, "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) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
container.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
container.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
|
@ -82,17 +75,6 @@ public class DeviceAddFragment extends LoggingFragment {
|
||||||
return container;
|
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() {
|
public ImageView getDevicesImage() {
|
||||||
return devicesImage;
|
return devicesImage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,61 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<FrameLayout 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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:layout_weight="1">
|
|
||||||
|
<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
|
<org.signal.qr.QrScannerView
|
||||||
android:id="@+id/scanner"
|
android:id="@+id/scanner"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent" />
|
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
|
<LinearLayout
|
||||||
android:id="@+id/overlay"
|
android:layout_width="0dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="0dp"
|
||||||
android:layout_height="match_parent"
|
android:background="?android:windowBackground"
|
||||||
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
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
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/devices"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_weight="1" />
|
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
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:text="@string/device_add_fragment__scan_the_qr_code_displayed_on_the_device_to_link"
|
||||||
android:background="?android:windowBackground"
|
android:textColor="?android:textColorSecondary" />
|
||||||
android:gravity="center"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingStart="16dp"
|
|
||||||
android:paddingEnd="16dp">
|
|
||||||
|
|
||||||
<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>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
@ -18,12 +18,21 @@ class QrProcessor {
|
||||||
|
|
||||||
private val reader = QRCodeReader()
|
private val reader = QRCodeReader()
|
||||||
|
|
||||||
|
private var previousHeight = 0
|
||||||
|
private var previousWidth = 0
|
||||||
|
|
||||||
fun getScannedData(
|
fun getScannedData(
|
||||||
data: ByteArray,
|
data: ByteArray,
|
||||||
width: Int,
|
width: Int,
|
||||||
height: Int
|
height: Int
|
||||||
): String? {
|
): String? {
|
||||||
try {
|
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 source = PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false)
|
||||||
|
|
||||||
val bitmap = BinaryBitmap(HybridBinarizer(source))
|
val bitmap = BinaryBitmap(HybridBinarizer(source))
|
||||||
|
@ -33,11 +42,11 @@ class QrProcessor {
|
||||||
return result.text
|
return result.text
|
||||||
}
|
}
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
Log.w(TAG, e)
|
Log.w(TAG, "Random null", e)
|
||||||
} catch (e: ChecksumException) {
|
} catch (e: ChecksumException) {
|
||||||
Log.w(TAG, e)
|
Log.w(TAG, "QR code read and decoded, but checksum failed", e)
|
||||||
} catch (e: FormatException) {
|
} 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) {
|
} catch (e: NotFoundException) {
|
||||||
// Thanks ZXing...
|
// Thanks ZXing...
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.camera.core.AspectRatio
|
||||||
import androidx.camera.core.Camera
|
import androidx.camera.core.Camera
|
||||||
import androidx.camera.core.CameraSelector
|
import androidx.camera.core.CameraSelector
|
||||||
import androidx.camera.core.ImageAnalysis
|
import androidx.camera.core.ImageAnalysis
|
||||||
|
@ -73,6 +74,7 @@ internal class ScannerView21 constructor(
|
||||||
val preview = Preview.Builder().build()
|
val preview = Preview.Builder().build()
|
||||||
|
|
||||||
val imageAnalysis = ImageAnalysis.Builder()
|
val imageAnalysis = ImageAnalysis.Builder()
|
||||||
|
.setTargetAspectRatio(AspectRatio.RATIO_16_9)
|
||||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue