Loading app/src/main/java/net/sourceforge/opencamera/preview/OverlayQRCodeView.java 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2024 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package net.sourceforge.opencamera.preview; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.view.View; import androidx.core.content.ContextCompat; import foundation.e.camera.R; public class OverlayQRCodeView extends View { private Drawable qrcode; // Do not draw the additional resource if something goes wrong private boolean isValid = true; public OverlayQRCodeView(Context context) { super(context); init(); } private void init() { qrcode = ContextCompat.getDrawable(this.getContext(), R.drawable.scan_area); DisplayMetrics displayMetrics =this.getContext().getResources().getDisplayMetrics(); final int screenWidth = displayMetrics.widthPixels; final int screenHeight = displayMetrics.heightPixels; final int left = (screenWidth - qrcode.getIntrinsicWidth()) / 2; final int top = (screenHeight - qrcode.getIntrinsicHeight()) / 2; final int right = left + qrcode.getIntrinsicWidth(); final int bottom = top + qrcode.getIntrinsicHeight(); if (left <= 0 || top <= 0 || right <= 0 || bottom <= 0) { isValid = false; } else { qrcode.setBounds(left, top, right, bottom); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isValid) { qrcode.draw(canvas); } } } app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +14 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; Loading Loading @@ -226,6 +227,8 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu * Important to call close() when the video recording is finished, to free up any resources * (e.g., supplied ParcelFileDescriptor). */ private OverlayQRCodeView overlayQRCodeView; private static class VideoFileInfo { private final ApplicationInterface.VideoMethod video_method; private final Uri video_uri; // for VideoMethod.SAF, VideoMethod.URI or VideoMethod.MEDIASTORE Loading Loading @@ -502,6 +505,8 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu if (canvasView != null) { parent.addView(canvasView); } overlayQRCodeView = new OverlayQRCodeView(getContext()); } /*private void previewToCamera(float [] coords) { Loading Loading @@ -4771,6 +4776,9 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu stopVideo(false); } this.functionalMode = FunctionalMode.QRCODE; final Activity activity = (Activity) Preview.this.getContext(); final FrameLayout rootLayout = activity.findViewById(android.R.id.content); rootLayout.addView(overlayQRCodeView); int qrcodeCamId = ((MainActivity)getContext()).getBetterQRCodeCameraID(); if (qrcodeCamId >= 0) { applicationInterface.setCameraIdPref(qrcodeCamId); Loading @@ -4778,6 +4786,11 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu } } else if (this.is_qrcode()) { this.functionalMode = FunctionalMode.PHOTO; final Activity activity = (Activity) Preview.this.getContext(); final FrameLayout rootLayout = activity.findViewById(android.R.id.content); if (overlayQRCodeView.getParent() != null) { rootLayout.removeView(overlayQRCodeView); } } else if (this.is_photo()) { if (this.isOnTimer()) { cancelTimer(); Loading @@ -4791,6 +4804,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu ((MainActivity)getContext()).setDecorFitsSystemWindows(true); this.functionalMode = FunctionalMode.VIDEO; } // nothing to do for overlayQRCodeView in this mode } if (is_qrcode() != old_is_qrcode) { Loading app/src/main/res/drawable/ic_switch_qrcode.xml +37 −7 Original line number Diff line number Diff line <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="37dp" android:height="37dp" android:viewportWidth="37" android:viewportHeight="37"> android:width="36dp" android:height="36dp" android:viewportWidth="36" android:viewportHeight="36"> <group> <clip-path android:pathData="M0.201,0.394h36v36h-36z"/> android:pathData="M0,0h36v36h-36z"/> <path android:pathData="M18.201,18.394m-18,0a18,18 0,1 1,36 0a18,18 0,1 1,-36 0" android:pathData="M18,18m-18,0a18,18 0,1 1,36 0a18,18 0,1 1,-36 0" android:fillColor="#ffffff" android:fillAlpha="0.25"/> <path android:pathData="M21,27H19V25H21V27ZM19,20H17V25H19V20ZM27,18H25V22H27V18ZM25,16H23V18H25V16ZM13,18H11V20H13V18ZM11,16H9V18H11V16ZM18,11H20V9H18V11ZM10.5,10.5V13.5H13.5V10.5H10.5ZM15,15H9V9H15V15ZM10.5,22.5V25.5H13.5V22.5H10.5ZM15,27H9V21H15V27ZM22.5,10.5V13.5H25.5V10.5H22.5ZM27,15H21V9H27V15ZM25,25V22H21V24H23V27H27V25H25ZM23,18H19V20H23V18ZM19,16H13V18H15V20H17V18H19V16ZM20,15V13H18V11H16V15H20ZM12.75,11.25H11.25V12.75H12.75V11.25ZM12.75,23.25H11.25V24.75H12.75V23.25ZM24.75,11.25H23.25V12.75H24.75V11.25Z" android:pathData="M9,17H17V9H9V17ZM11,11H15V15H11V11Z" android:fillColor="#ffffff"/> <path android:pathData="M9,27H17V19H9V27ZM11,21H15V25H11V21Z" android:fillColor="#ffffff"/> <path android:pathData="M19,9V17H27V9H19ZM25,15H21V11H25V15Z" android:fillColor="#ffffff"/> <path android:pathData="M27,25H25V27H27V25Z" android:fillColor="#ffffff"/> <path android:pathData="M21,19H19V21H21V19Z" android:fillColor="#ffffff"/> <path android:pathData="M23,21H21V23H23V21Z" android:fillColor="#ffffff"/> <path android:pathData="M21,23H19V25H21V23Z" android:fillColor="#ffffff"/> <path android:pathData="M23,25H21V27H23V25Z" android:fillColor="#ffffff"/> <path android:pathData="M25,23H23V25H25V23Z" android:fillColor="#ffffff"/> <path android:pathData="M25,19H23V21H25V19Z" android:fillColor="#ffffff"/> <path android:pathData="M27,21H25V23H27V21Z" android:fillColor="#ffffff"/> </group> </vector> app/src/main/res/drawable/scan_area.xml 0 → 100644 +14 −0 Original line number Diff line number Diff line <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="192dp" android:height="192dp" android:viewportWidth="192" android:viewportHeight="192"> <group> <clip-path android:pathData="M0,0h192v192h-192z"/> <path android:pathData="M0,21.33V48H13.33V22.33C13.33,17.36 17.36,13.33 22.33,13.33H48V0H21.33C9.6,0 0,9.6 0,21.33ZM13.33,144H0V170.67C0,182.4 9.6,192 21.33,192H48V178.67H22.33C17.36,178.67 13.33,174.64 13.33,169.67V144ZM178.67,169.67C178.67,174.64 174.64,178.67 169.67,178.67H144V192H170.67C182.4,192 192,182.4 192,170.67V144H178.67V169.67ZM170.67,0H144V13.33H169.67C174.64,13.33 178.67,17.36 178.67,22.33V48H192V21.33C192,9.6 182.4,0 170.67,0Z" android:fillColor="#ffffff" android:fillAlpha="0.8"/> </group> </vector> app/src/main/res/layout/qr_bottom_sheet_dialog.xml +9 −7 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ <androidx.cardview.widget.CardView android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="72dp" android:layout_height="88dp" android:layout_marginTop="12dp" android:clickable="true" app:cardBackgroundColor="@color/qrcodeColorOnSurface" Loading Loading @@ -57,9 +57,9 @@ <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="16dp" android:layout_marginStart="8dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:layout_marginEnd="8dp" android:layout_marginBottom="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/share" Loading @@ -69,7 +69,7 @@ <TextView android:id="@+id/title" android:layout_width="0dp" android:layout_height="0dp" android:layout_height="wrap_content" android:singleLine="true" android:textColor="@color/qrcodeColorOnSurfaceVariant" android:textStyle="bold" Loading @@ -84,8 +84,9 @@ <TextView android:id="@+id/data" android:layout_width="0dp" android:layout_height="0dp" android:singleLine="true" android:layout_height="wrap_content" android:maxLines="2" android:ellipsize="end" android:textColor="@color/qrcodeColorOnSurfaceVariant" android:textStyle="normal" android:typeface="normal" Loading @@ -94,7 +95,8 @@ app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/title" app:layout_constraintTop_toBottomOf="@+id/title" tools:text="URL" /> tools:text="URL" android:breakStrategy="high_quality" /> </androidx.constraintlayout.widget.ConstraintLayout> <ImageButton Loading Loading
app/src/main/java/net/sourceforge/opencamera/preview/OverlayQRCodeView.java 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2024 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package net.sourceforge.opencamera.preview; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.view.View; import androidx.core.content.ContextCompat; import foundation.e.camera.R; public class OverlayQRCodeView extends View { private Drawable qrcode; // Do not draw the additional resource if something goes wrong private boolean isValid = true; public OverlayQRCodeView(Context context) { super(context); init(); } private void init() { qrcode = ContextCompat.getDrawable(this.getContext(), R.drawable.scan_area); DisplayMetrics displayMetrics =this.getContext().getResources().getDisplayMetrics(); final int screenWidth = displayMetrics.widthPixels; final int screenHeight = displayMetrics.heightPixels; final int left = (screenWidth - qrcode.getIntrinsicWidth()) / 2; final int top = (screenHeight - qrcode.getIntrinsicHeight()) / 2; final int right = left + qrcode.getIntrinsicWidth(); final int bottom = top + qrcode.getIntrinsicHeight(); if (left <= 0 || top <= 0 || right <= 0 || bottom <= 0) { isValid = false; } else { qrcode.setBounds(left, top, right, bottom); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isValid) { qrcode.draw(canvas); } } }
app/src/main/java/net/sourceforge/opencamera/preview/Preview.java +14 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; Loading Loading @@ -226,6 +227,8 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu * Important to call close() when the video recording is finished, to free up any resources * (e.g., supplied ParcelFileDescriptor). */ private OverlayQRCodeView overlayQRCodeView; private static class VideoFileInfo { private final ApplicationInterface.VideoMethod video_method; private final Uri video_uri; // for VideoMethod.SAF, VideoMethod.URI or VideoMethod.MEDIASTORE Loading Loading @@ -502,6 +505,8 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu if (canvasView != null) { parent.addView(canvasView); } overlayQRCodeView = new OverlayQRCodeView(getContext()); } /*private void previewToCamera(float [] coords) { Loading Loading @@ -4771,6 +4776,9 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu stopVideo(false); } this.functionalMode = FunctionalMode.QRCODE; final Activity activity = (Activity) Preview.this.getContext(); final FrameLayout rootLayout = activity.findViewById(android.R.id.content); rootLayout.addView(overlayQRCodeView); int qrcodeCamId = ((MainActivity)getContext()).getBetterQRCodeCameraID(); if (qrcodeCamId >= 0) { applicationInterface.setCameraIdPref(qrcodeCamId); Loading @@ -4778,6 +4786,11 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu } } else if (this.is_qrcode()) { this.functionalMode = FunctionalMode.PHOTO; final Activity activity = (Activity) Preview.this.getContext(); final FrameLayout rootLayout = activity.findViewById(android.R.id.content); if (overlayQRCodeView.getParent() != null) { rootLayout.removeView(overlayQRCodeView); } } else if (this.is_photo()) { if (this.isOnTimer()) { cancelTimer(); Loading @@ -4791,6 +4804,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu ((MainActivity)getContext()).setDecorFitsSystemWindows(true); this.functionalMode = FunctionalMode.VIDEO; } // nothing to do for overlayQRCodeView in this mode } if (is_qrcode() != old_is_qrcode) { Loading
app/src/main/res/drawable/ic_switch_qrcode.xml +37 −7 Original line number Diff line number Diff line <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="37dp" android:height="37dp" android:viewportWidth="37" android:viewportHeight="37"> android:width="36dp" android:height="36dp" android:viewportWidth="36" android:viewportHeight="36"> <group> <clip-path android:pathData="M0.201,0.394h36v36h-36z"/> android:pathData="M0,0h36v36h-36z"/> <path android:pathData="M18.201,18.394m-18,0a18,18 0,1 1,36 0a18,18 0,1 1,-36 0" android:pathData="M18,18m-18,0a18,18 0,1 1,36 0a18,18 0,1 1,-36 0" android:fillColor="#ffffff" android:fillAlpha="0.25"/> <path android:pathData="M21,27H19V25H21V27ZM19,20H17V25H19V20ZM27,18H25V22H27V18ZM25,16H23V18H25V16ZM13,18H11V20H13V18ZM11,16H9V18H11V16ZM18,11H20V9H18V11ZM10.5,10.5V13.5H13.5V10.5H10.5ZM15,15H9V9H15V15ZM10.5,22.5V25.5H13.5V22.5H10.5ZM15,27H9V21H15V27ZM22.5,10.5V13.5H25.5V10.5H22.5ZM27,15H21V9H27V15ZM25,25V22H21V24H23V27H27V25H25ZM23,18H19V20H23V18ZM19,16H13V18H15V20H17V18H19V16ZM20,15V13H18V11H16V15H20ZM12.75,11.25H11.25V12.75H12.75V11.25ZM12.75,23.25H11.25V24.75H12.75V23.25ZM24.75,11.25H23.25V12.75H24.75V11.25Z" android:pathData="M9,17H17V9H9V17ZM11,11H15V15H11V11Z" android:fillColor="#ffffff"/> <path android:pathData="M9,27H17V19H9V27ZM11,21H15V25H11V21Z" android:fillColor="#ffffff"/> <path android:pathData="M19,9V17H27V9H19ZM25,15H21V11H25V15Z" android:fillColor="#ffffff"/> <path android:pathData="M27,25H25V27H27V25Z" android:fillColor="#ffffff"/> <path android:pathData="M21,19H19V21H21V19Z" android:fillColor="#ffffff"/> <path android:pathData="M23,21H21V23H23V21Z" android:fillColor="#ffffff"/> <path android:pathData="M21,23H19V25H21V23Z" android:fillColor="#ffffff"/> <path android:pathData="M23,25H21V27H23V25Z" android:fillColor="#ffffff"/> <path android:pathData="M25,23H23V25H25V23Z" android:fillColor="#ffffff"/> <path android:pathData="M25,19H23V21H25V19Z" android:fillColor="#ffffff"/> <path android:pathData="M27,21H25V23H27V21Z" android:fillColor="#ffffff"/> </group> </vector>
app/src/main/res/drawable/scan_area.xml 0 → 100644 +14 −0 Original line number Diff line number Diff line <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="192dp" android:height="192dp" android:viewportWidth="192" android:viewportHeight="192"> <group> <clip-path android:pathData="M0,0h192v192h-192z"/> <path android:pathData="M0,21.33V48H13.33V22.33C13.33,17.36 17.36,13.33 22.33,13.33H48V0H21.33C9.6,0 0,9.6 0,21.33ZM13.33,144H0V170.67C0,182.4 9.6,192 21.33,192H48V178.67H22.33C17.36,178.67 13.33,174.64 13.33,169.67V144ZM178.67,169.67C178.67,174.64 174.64,178.67 169.67,178.67H144V192H170.67C182.4,192 192,182.4 192,170.67V144H178.67V169.67ZM170.67,0H144V13.33H169.67C174.64,13.33 178.67,17.36 178.67,22.33V48H192V21.33C192,9.6 182.4,0 170.67,0Z" android:fillColor="#ffffff" android:fillAlpha="0.8"/> </group> </vector>
app/src/main/res/layout/qr_bottom_sheet_dialog.xml +9 −7 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ <androidx.cardview.widget.CardView android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="72dp" android:layout_height="88dp" android:layout_marginTop="12dp" android:clickable="true" app:cardBackgroundColor="@color/qrcodeColorOnSurface" Loading Loading @@ -57,9 +57,9 @@ <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="16dp" android:layout_marginStart="8dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:layout_marginEnd="8dp" android:layout_marginBottom="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/share" Loading @@ -69,7 +69,7 @@ <TextView android:id="@+id/title" android:layout_width="0dp" android:layout_height="0dp" android:layout_height="wrap_content" android:singleLine="true" android:textColor="@color/qrcodeColorOnSurfaceVariant" android:textStyle="bold" Loading @@ -84,8 +84,9 @@ <TextView android:id="@+id/data" android:layout_width="0dp" android:layout_height="0dp" android:singleLine="true" android:layout_height="wrap_content" android:maxLines="2" android:ellipsize="end" android:textColor="@color/qrcodeColorOnSurfaceVariant" android:textStyle="normal" android:typeface="normal" Loading @@ -94,7 +95,8 @@ app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="@+id/title" app:layout_constraintTop_toBottomOf="@+id/title" tools:text="URL" /> tools:text="URL" android:breakStrategy="high_quality" /> </androidx.constraintlayout.widget.ConstraintLayout> <ImageButton Loading