Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a circle style #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ protected void onCreate(Bundle savedInstanceState) {
mPatternLockView.setInputEnabled(true);
mPatternLockView.addPatternLockListener(mPatternLockViewListener);

mPatternLockView.setCircleRadius((int) getResources().getDimension(R.dimen.pattern_lock_dot_circle_size));
mPatternLockView.setShowCircleEnable(true);

RxPatternLockView.patternComplete(mPatternLockView)
.subscribe(new Consumer<PatternLockCompleteEvent>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,26 @@ public class PatternLockView extends View {
private int mDotSelectedSize;
private int mDotAnimationDuration;
private int mPathEndAnimationDuration;
private int mCircleRadius = 0; // Radius of the circle
private boolean mShowCircleEnable = false; // enable draw a circle

public int getCircleRadius() {
return mCircleRadius;
}

public void setCircleRadius(int circleRadius) {
mCircleRadius = circleRadius;
initView();
invalidate();
}

public boolean isShowCircleEnable() {
return mShowCircleEnable;
}

public void setShowCircleEnable(boolean showCircleEnable) {
mShowCircleEnable = showCircleEnable;
}
private Paint mDotPaint;
private Paint mPathPaint;

Expand Down Expand Up @@ -191,6 +210,10 @@ public PatternLockView(Context context, AttributeSet attrs) {
DEFAULT_DOT_ANIMATION_DURATION);
mPathEndAnimationDuration = typedArray.getInt(R.styleable.PatternLockView_pathEndAnimationDuration,
DEFAULT_PATH_END_ANIMATION_DURATION);
mCircleRadius = (int) typedArray.getDimension(R.styleable.PatternLockView_circleRadius,
ResourceUtils.getDimensionInPx(getContext(), R.dimen.pattern_lock_dot_circle_size));
mShowCircleEnable = typedArray.getBoolean(R.styleable.PatternLockView_showCircleEnable,
false);
} finally {
typedArray.recycle();
}
Expand Down Expand Up @@ -360,6 +383,9 @@ protected void onDraw(Canvas canvas) {
}
canvas.drawPath(currentPath, mPathPaint);
}
// Draw a circle outside the dot
if (isShowCircleEnable())
canvas.drawCircle(centerX, centerY, mCircleRadius, mPathPaint);
lastX = centerX;
lastY = centerY;
}
Expand All @@ -374,6 +400,9 @@ protected void onDraw(Canvas canvas) {
mPathPaint.setAlpha((int) (calculateLastSegmentAlpha(
mInProgressX, mInProgressY, lastX, lastY) * 255f));
canvas.drawPath(currentPath, mPathPaint);
// Draw a circle outside the dot
if (isShowCircleEnable())
canvas.drawCircle(lastX, lastY, mCircleRadius, mPathPaint);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions patternlockview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
<attr name="wrongStateColor" format="color"/>
<attr name="dotAnimationDuration" format="integer"/>
<attr name="pathEndAnimationDuration" format="integer"/>
<attr name="circleRadius" format="dimension"/>
<attr name="showCircleEnable" format="boolean"/>
</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions patternlockview/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<dimen name="pattern_lock_path_width">3dp</dimen>
<dimen name="pattern_lock_dot_size">10dp</dimen>
<dimen name="pattern_lock_dot_selected_size">24dp</dimen>
<dimen name="pattern_lock_dot_circle_size">20dp</dimen>
</resources>