diff --git a/README.md b/README.md index f19e816..07392ea 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ frameVisible frameThickness frameCornersSize frameCornersRadius +frameCornersCapRounded frameAspectRatioWidth frameAspectRatioHeight frameSize diff --git a/src/main/java/com/budiyev/android/codescanner/CodeScannerView.java b/src/main/java/com/budiyev/android/codescanner/CodeScannerView.java index f0505fc..8888d54 100644 --- a/src/main/java/com/budiyev/android/codescanner/CodeScannerView.java +++ b/src/main/java/com/budiyev/android/codescanner/CodeScannerView.java @@ -59,6 +59,7 @@ public final class CodeScannerView extends ViewGroup { private static final boolean DEFAULT_FLASH_BUTTON_VISIBLE = true; private static final boolean DEFAULT_MASK_VISIBLE = true; private static final boolean DEFAULT_FRAME_VISIBLE = true; + private static final boolean DEFAULT_FRAME_CORNERS_CAP_ROUNDED = false; private static final int DEFAULT_MASK_COLOR = 0x77000000; private static final int DEFAULT_FRAME_COLOR = Color.WHITE; private static final int DEFAULT_AUTO_FOCUS_BUTTON_COLOR = Color.WHITE; @@ -164,6 +165,7 @@ private void initialize(@NonNull final Context context, @Nullable final Attribut setFrameThickness(Math.round(DEFAULT_FRAME_THICKNESS_DP * density)); setFrameCornersSize(Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * density)); setFrameCornersRadius(Math.round(DEFAULT_FRAME_CORNERS_RADIUS_DP * density)); + setFrameCornersCapRounded(DEFAULT_FRAME_CORNERS_CAP_ROUNDED); setFrameSize(DEFAULT_FRAME_SIZE); setFrameVerticalBias(DEFAULT_FRAME_VERTICAL_BIAS); setAutoFocusButtonColor(DEFAULT_AUTO_FOCUS_BUTTON_COLOR); @@ -204,6 +206,9 @@ private void initialize(@NonNull final Context context, @Nullable final Attribut setFrameCornersRadius( a.getDimensionPixelOffset(R.styleable.CodeScannerView_frameCornersRadius, Math.round(DEFAULT_FRAME_CORNERS_RADIUS_DP * density))); + setFrameCornersCapRounded( + a.getBoolean(R.styleable.CodeScannerView_frameCornersCapRounded, + DEFAULT_FRAME_CORNERS_CAP_ROUNDED)); setFrameAspectRatio(a.getFloat(R.styleable.CodeScannerView_frameAspectRatioWidth, DEFAULT_FRAME_ASPECT_RATIO_WIDTH), a.getFloat(R.styleable.CodeScannerView_frameAspectRatioHeight, @@ -538,6 +543,24 @@ public void setFrameCornersRadius(@Px final int radius) { mViewFinderView.setFrameCornersRadius(radius); } + /** + * Whether if frame corners cap is currently rounded + * + * @see #setFrameVisible + */ + public boolean isFrameCornersCapRounded() { + return mViewFinderView.isFrameCornersCapRounded(); + } + + /** + * Set whether frame corners cap is rounded or not + * + * @param rounded Rounded cap + */ + public void setFrameCornersCapRounded(final boolean rounded) { + mViewFinderView.setFrameCornersCapRounded(rounded); + } + /** * Get current frame size * diff --git a/src/main/java/com/budiyev/android/codescanner/ViewFinderView.java b/src/main/java/com/budiyev/android/codescanner/ViewFinderView.java index 57cbb58..0032e46 100644 --- a/src/main/java/com/budiyev/android/codescanner/ViewFinderView.java +++ b/src/main/java/com/budiyev/android/codescanner/ViewFinderView.java @@ -263,6 +263,15 @@ void setFrameThickness(@Px final int thickness) { } } + boolean isFrameCornersCapRounded() { + return mFramePaint.getStrokeCap() == Paint.Cap.ROUND; + } + + void setFrameCornersCapRounded(final boolean rounded) { + mFramePaint.setStrokeCap(rounded ? Paint.Cap.ROUND : Paint.Cap.BUTT); + invalidate(); + } + @Px int getFrameCornersSize() { return mFrameCornersSize; diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml index 19e20e3..530b686 100644 --- a/src/main/res/values/attrs.xml +++ b/src/main/res/values/attrs.xml @@ -8,6 +8,7 @@ +