Skip to content

Commit

Permalink
添加allowRepeat属性
Browse files Browse the repository at this point in the history
  • Loading branch information
ooftf committed Jan 5, 2018
1 parent c8bfe7d commit ea20742
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ patternLock.onSlideListener = object : OnSlideListener {
|nomalLineColor|正常状态下连线颜色|#00FFFF|
|errorLineColor|错误状态下连线颜色|#FF0000|
|lineWidth|连线宽度|8dp|
|allowRepeat|是否允许点被重复选中|false|
## PatternLock方法
|方法名|描述|
|---|---|
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:gravity="center"
tools:context="com.ooftf.patternlock.MainActivity">
<com.ooftf.pattern.PatternLock
app:allowRepeat="true"
android:id="@+id/patternLock"
android:padding="18dp"
android:background="@color/colorPrimary"
Expand Down
4 changes: 3 additions & 1 deletion lib/src/main/java/com/ooftf/pattern/PatternLock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PatternLock : View {
internal var currentY: Float = 0.toFloat()
internal var touching = false
internal var iconSize = 0f
private var allowRepeat = false
/**
* 错误状态下线的颜色
*/
Expand Down Expand Up @@ -72,6 +73,7 @@ class PatternLock : View {
paintLine.strokeWidth = attributes.getDimension(R.styleable.PatternLock_lineWidth, dip2px(context, 8f).toFloat())
nomalColor = attributes.getColor(R.styleable.PatternLock_nomalLineColor, Color.parseColor("#00FFFF"));
errorColor = attributes.getColor(R.styleable.PatternLock_errorLineColor, Color.parseColor("#FF0000"));
allowRepeat = attributes.getBoolean(R.styleable.PatternLock_allowRepeat,false)
}

private fun initPoint() {
Expand Down Expand Up @@ -146,7 +148,7 @@ class PatternLock : View {

internal fun intersectPoint(currentX: Float, currentY: Float) {
points.filter { it.isIntersect(currentX, currentY) }
.filter { !selectedPoints.contains(it) }
.filter { allowRepeat||!selectedPoints.contains(it)}
.forEach {
it.state = PointState.SELECT
selectedPoints.add(it)
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<attr name="errorLineColor" format="color"/>
<attr name="lineWidth" format="dimension"/>
<attr name="iconSize" format="dimension"/>
<attr name="allowRepeat" format="boolean"/>
</declare-styleable>

</resources>

0 comments on commit ea20742

Please sign in to comment.