Improve the camera preview in SendTransactionFragment, so that both the preview and the scan zone are squared.

This commit is contained in:
Severiano Jaramillo 2019-02-11 18:53:18 -06:00
parent 653bdbec69
commit 1e67fdf065
3 changed files with 34 additions and 26 deletions

View file

@ -351,6 +351,8 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
cameraPreview.setMaskColor(R.color.colorAccent) cameraPreview.setMaskColor(R.color.colorAccent)
cameraPreview.setResultHandler(this) cameraPreview.setResultHandler(this)
cameraPreview.startCamera() cameraPreview.startCamera()
cameraPreview.scrollY = holderCamera.width / 6
} }
private fun stopCameraPreview() { private fun stopCameraPreview() {

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="10dp" /> <corners android:radius="8dp" />
<solid android:color="#111" /> <stroke
android:width="1dp"
android:color="#888"/>
</shape> </shape>

View file

@ -136,18 +136,32 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilMemo" /> app:layout_constraintTop_toBottomOf="@id/tilMemo" />
<View <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/viewCamera" android:id="@+id/holderCamera"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="@dimen/spacing_same_topic" android:layout_marginTop="@dimen/spacing_same_topic"
android:layout_marginStart="@dimen/activity_horizontal_margin" android:layout_marginStart="@dimen/activity_horizontal_margin"
android:background="@drawable/camera_view_background" android:background="@drawable/camera_view_background"
app:layout_constraintDimensionRatio="1:1" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toBottomOf="@+id/tvScan" app:layout_constraintTop_toBottomOf="@+id/tvScan"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/cameraVerticalGuideline"/> app:layout_constraintEnd_toStartOf="@id/cameraVerticalGuideline">
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="@+id/cameraPreview"
android:layout_width="0dp"
android:layout_height="0dp"
app:squaredFinder="true"
app:borderColor="@color/colorSend"
app:layout_constraintDimensionRatio="h,3:4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabOpenCamera" android:id="@+id/fabOpenCamera"
@ -161,16 +175,6 @@
app:layout_constraintStart_toEndOf="@id/cameraVerticalGuideline" app:layout_constraintStart_toEndOf="@id/cameraVerticalGuideline"
app:layout_constraintTop_toBottomOf="@+id/tvScan"/> app:layout_constraintTop_toBottomOf="@+id/tvScan"/>
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="@+id/cameraPreview"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="w,3:4"
app:layout_constraintTop_toTopOf="@+id/viewCamera"
app:layout_constraintBottom_toBottomOf="@id/viewCamera"
app:layout_constraintStart_toStartOf="@id/viewCamera"
app:layout_constraintEnd_toEndOf="@id/viewCamera" />
<View <View
android:id="@+id/vSend" android:id="@+id/vSend"
android:layout_width="120dp" android:layout_width="120dp"
@ -178,8 +182,8 @@
android:layout_marginEnd="0dp" android:layout_marginEnd="0dp"
android:background="@drawable/send_fab_background_disabled" android:background="@drawable/send_fab_background_disabled"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/viewCamera" app:layout_constraintTop_toTopOf="@id/holderCamera"
app:layout_constraintBottom_toBottomOf="@id/viewCamera"/> app:layout_constraintBottom_toBottomOf="@id/holderCamera"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabSendTransaction" android:id="@+id/fabSendTransaction"