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

Commit 10d648af authored by cosmohsieh's avatar cosmohsieh
Browse files

Fix inconsistent border width in QR code scanning camera

1) Fix border width become larger in the corner.
2) Correct border width

Bug: 127654782
Test: manual
Change-Id: I792ac571b5c59d14af82848698d76cb59a2f4249
parent aa0d851e
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ public class QrDecorateView extends View {
    final private Paint mBackgroundPaint;
    final private Paint mBackgroundPaint;


    final private float mRadius;
    final private float mRadius;
    final private float mInnerRidus;


    private Bitmap mMaskBitmap;
    private Bitmap mMaskBitmap;
    private Canvas mMaskCanvas;
    private Canvas mMaskCanvas;
@@ -73,6 +74,9 @@ public class QrDecorateView extends View {
        mFocused = false;
        mFocused = false;
        mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CORNER_RADIUS,
        mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CORNER_RADIUS,
                getResources().getDisplayMetrics());
                getResources().getDisplayMetrics());
        // Inner radius needs to minus stroke width for keeping the width of border consistent.
        mInnerRidus = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                CORNER_RADIUS - CORNER_STROKE_WIDTH, getResources().getDisplayMetrics());


        mCornerColor = context.getResources().getColor(R.color.qr_corner_line_color);
        mCornerColor = context.getResources().getColor(R.color.qr_corner_line_color);
        mFocusedCornerColor = context.getResources().getColor(R.color.qr_focused_corner_line_color);
        mFocusedCornerColor = context.getResources().getColor(R.color.qr_focused_corner_line_color);
@@ -111,7 +115,7 @@ public class QrDecorateView extends View {
        // Draw outer corner.
        // Draw outer corner.
        mMaskCanvas.drawRoundRect(mOuterFrame, mRadius, mRadius, mStrokePaint);
        mMaskCanvas.drawRoundRect(mOuterFrame, mRadius, mRadius, mStrokePaint);
        // Draw inner transparent corner.
        // Draw inner transparent corner.
        mMaskCanvas.drawRoundRect(mInnerFrame, mRadius, mRadius, mTransparentPaint);
        mMaskCanvas.drawRoundRect(mInnerFrame, mInnerRidus, mInnerRidus, mTransparentPaint);


        canvas.drawBitmap(mMaskBitmap, 0, 0, mBackgroundPaint);
        canvas.drawBitmap(mMaskBitmap, 0, 0, mBackgroundPaint);
        super.onDraw(canvas);
        super.onDraw(canvas);
@@ -123,7 +127,7 @@ public class QrDecorateView extends View {
        final float cornerLineLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
        final float cornerLineLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                CORNER_LINE_LENGTH, getResources().getDisplayMetrics()) / 2;
                CORNER_LINE_LENGTH, getResources().getDisplayMetrics()) / 2;
        final float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
        final float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                CORNER_STROKE_WIDTH, getResources().getDisplayMetrics()) / 2;
                CORNER_STROKE_WIDTH, getResources().getDisplayMetrics());


        mOuterFrame = new RectF(centralX - cornerLineLength, centralY - cornerLineLength,
        mOuterFrame = new RectF(centralX - cornerLineLength, centralY - cornerLineLength,
                centralX + cornerLineLength, centralY + cornerLineLength);
                centralX + cornerLineLength, centralY + cornerLineLength);
@@ -131,7 +135,7 @@ public class QrDecorateView extends View {
                mOuterFrame.right - strokeWidth, mOuterFrame.bottom - strokeWidth);
                mOuterFrame.right - strokeWidth, mOuterFrame.bottom - strokeWidth);
    }
    }


    // Draws green lines if focued. Otherwise, draws white lines.
    // Draws green lines if focused. Otherwise, draws white lines.
    public void setFocused(boolean focused) {
    public void setFocused(boolean focused) {
        mFocused = focused;
        mFocused = focused;
        invalidate();
        invalidate();