Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed May 24, 2022
1 parent aef2cdc commit 3f41275
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ frameVisible
frameThickness
frameCornersSize
frameCornersRadius
frameCornersCapRounded
frameAspectRatioWidth
frameAspectRatioHeight
frameSize
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/budiyev/android/codescanner/CodeScannerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<attr name="frameThickness" format="dimension"/>
<attr name="frameCornersSize" format="dimension"/>
<attr name="frameCornersRadius" format="dimension"/>
<attr name="frameCornersCapRounded" format="boolean"/>
<attr name="frameAspectRatioWidth" format="float"/>
<attr name="frameAspectRatioHeight" format="float"/>
<attr name="frameSize" format="float"/>
Expand Down

0 comments on commit 3f41275

Please sign in to comment.