Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f42d3a44 authored by Nishith  Khanna's avatar Nishith Khanna
Browse files

Merge branch 'epic44-barcode-scanner' into 'master'

Add dedicated view for QR

See merge request !73
parents 5429a42c 1ea4db3e
Loading
Loading
Loading
Loading
Loading
+64 −0
Original line number Original line 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);
        }
    }
}
+14 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RectF;
@@ -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
     *  Important to call close() when the video recording is finished, to free up any resources
     *  (e.g., supplied ParcelFileDescriptor).
     *  (e.g., supplied ParcelFileDescriptor).
     */
     */

    private OverlayQRCodeView overlayQRCodeView;
    private static class VideoFileInfo {
    private static class VideoFileInfo {
        private final ApplicationInterface.VideoMethod video_method;
        private final ApplicationInterface.VideoMethod video_method;
        private final Uri video_uri; // for VideoMethod.SAF, VideoMethod.URI or VideoMethod.MEDIASTORE
        private final Uri video_uri; // for VideoMethod.SAF, VideoMethod.URI or VideoMethod.MEDIASTORE
@@ -502,6 +505,8 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
        if (canvasView != null) {
        if (canvasView != null) {
            parent.addView(canvasView);
            parent.addView(canvasView);
        }
        }

        overlayQRCodeView = new OverlayQRCodeView(getContext());
    }
    }


	/*private void previewToCamera(float [] coords) {
	/*private void previewToCamera(float [] coords) {
@@ -4771,6 +4776,9 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
                stopVideo(false);
                stopVideo(false);
            }
            }
            this.functionalMode = FunctionalMode.QRCODE;
            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();
            int qrcodeCamId = ((MainActivity)getContext()).getBetterQRCodeCameraID();
            if (qrcodeCamId >= 0) {
            if (qrcodeCamId >= 0) {
                applicationInterface.setCameraIdPref(qrcodeCamId);
                applicationInterface.setCameraIdPref(qrcodeCamId);
@@ -4778,6 +4786,11 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
            }
            }
        } else if (this.is_qrcode()) {
        } else if (this.is_qrcode()) {
            this.functionalMode = FunctionalMode.PHOTO;
            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()) {
        } else if (this.is_photo()) {
            if (this.isOnTimer()) {
            if (this.isOnTimer()) {
                cancelTimer();
                cancelTimer();
@@ -4791,6 +4804,7 @@ public class Preview implements SurfaceHolder.Callback, TextureView.SurfaceTextu
                ((MainActivity)getContext()).setDecorFitsSystemWindows(true);
                ((MainActivity)getContext()).setDecorFitsSystemWindows(true);
                this.functionalMode = FunctionalMode.VIDEO;
                this.functionalMode = FunctionalMode.VIDEO;
            }
            }
            // nothing to do for overlayQRCodeView in this mode
        }
        }


        if (is_qrcode() != old_is_qrcode) {
        if (is_qrcode() != old_is_qrcode) {
+37 −7
Original line number Original line Diff line number Diff line
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="37dp"
    android:width="36dp"
    android:height="37dp"
    android:height="36dp"
    android:viewportWidth="37"
    android:viewportWidth="36"
    android:viewportHeight="37">
    android:viewportHeight="36">
  <group>
  <group>
    <clip-path
    <clip-path
        android:pathData="M0.201,0.394h36v36h-36z"/>
        android:pathData="M0,0h36v36h-36z"/>
    <path
    <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:fillColor="#ffffff"
        android:fillAlpha="0.25"/>
        android:fillAlpha="0.25"/>
    <path
    <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"/>
        android:fillColor="#ffffff"/>
  </group>
  </group>
</vector>
</vector>
+14 −0
Original line number Original line 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>
+9 −7
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@
    <androidx.cardview.widget.CardView
    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="72dp"
        android:layout_height="88dp"
        android:layout_marginTop="12dp"
        android:layout_marginTop="12dp"
        android:clickable="true"
        android:clickable="true"
        app:cardBackgroundColor="@color/qrcodeColorOnSurface"
        app:cardBackgroundColor="@color/qrcodeColorOnSurface"
@@ -57,9 +57,9 @@
            <androidx.constraintlayout.widget.ConstraintLayout
            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="0dp"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="16dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="16dp"
                android:layout_marginBottom="16dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/share"
                app:layout_constraintEnd_toStartOf="@+id/share"
@@ -69,7 +69,7 @@
                <TextView
                <TextView
                    android:id="@+id/title"
                    android:id="@+id/title"
                    android:layout_width="0dp"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_height="wrap_content"
                    android:singleLine="true"
                    android:singleLine="true"
                    android:textColor="@color/qrcodeColorOnSurfaceVariant"
                    android:textColor="@color/qrcodeColorOnSurfaceVariant"
                    android:textStyle="bold"
                    android:textStyle="bold"
@@ -84,8 +84,9 @@
                <TextView
                <TextView
                    android:id="@+id/data"
                    android:id="@+id/data"
                    android:layout_width="0dp"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_height="wrap_content"
                    android:singleLine="true"
                    android:maxLines="2"
                    android:ellipsize="end"
                    android:textColor="@color/qrcodeColorOnSurfaceVariant"
                    android:textColor="@color/qrcodeColorOnSurfaceVariant"
                    android:textStyle="normal"
                    android:textStyle="normal"
                    android:typeface="normal"
                    android:typeface="normal"
@@ -94,7 +95,8 @@
                    app:layout_constraintHorizontal_bias="0.5"
                    app:layout_constraintHorizontal_bias="0.5"
                    app:layout_constraintStart_toStartOf="@+id/title"
                    app:layout_constraintStart_toStartOf="@+id/title"
                    app:layout_constraintTop_toBottomOf="@+id/title"
                    app:layout_constraintTop_toBottomOf="@+id/title"
                    tools:text="URL" />
                    tools:text="URL"
                    android:breakStrategy="high_quality" />
            </androidx.constraintlayout.widget.ConstraintLayout>
            </androidx.constraintlayout.widget.ConstraintLayout>


            <ImageButton
            <ImageButton