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

Commit 37dae634 authored by frankpreel's avatar frankpreel Committed by Mohammed Althaf T
Browse files

Add scan_area.xml and dedicated view.

parent a13e4b4a
Loading
Loading
Loading
Loading
+62 −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);
    }
}
+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>