Skip to content

Commit 18b2e13

Browse files
author
huangshouguo
committed
修复跳过中间点问题
1 parent f0177b4 commit 18b2e13

15 files changed

Lines changed: 97 additions & 96 deletions

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ android {
3535

3636
dependencies {
3737
implementation fileTree(dir: 'libs', include: ['*.jar'])
38-
// implementation project(':library')
39-
implementation "com.github.ihsg:PatternLocker:$rootProject.ext.versionName"
38+
implementation project(':library')
39+
// implementation "com.github.ihsg:PatternLocker:$rootProject.ext.versionName"
4040

4141
implementation "androidx.appcompat:appcompat:$rootProject.ext.appcompatVersion"
4242
implementation "androidx.core:core-ktx:$rootProject.ext.coreKtxVersion"

app/src/main/java/com/github/ihsg/demo/ui/whole/RippleLockerHitCellView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class RippleLockerHitCellView : IHitCellView {
5252
val saveCount = canvas.save()
5353

5454
this.paint.color = getColor(isError) and 0x14FFFFFF
55-
canvas.drawCircle(cellBean.x, cellBean.y, cellBean.radius, this.paint)
55+
canvas.drawCircle(cellBean.centerX, cellBean.centerY, cellBean.radius, this.paint)
5656

5757
this.paint.color = getColor(isError) and 0x43FFFFFF
58-
canvas.drawCircle(cellBean.x, cellBean.y, cellBean.radius * 2f / 3f, this.paint)
58+
canvas.drawCircle(cellBean.centerX, cellBean.centerY, cellBean.radius * 2f / 3f, this.paint)
5959

6060
this.paint.color = getColor(isError)
61-
canvas.drawCircle(cellBean.x, cellBean.y, cellBean.radius / 3f, this.paint)
61+
canvas.drawCircle(cellBean.centerX, cellBean.centerY, cellBean.radius / 3f, this.paint)
6262

6363
canvas.restoreToCount(saveCount)
6464
}

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
buildscript {
44
// versions
55
ext {
6-
versionCode = 20
7-
versionName = '2.5.6'
6+
versionCode = 21
7+
versionName = '2.5.7'
88

99
minSdkVersion = 15
1010
targetSdkVersion = 29
1111
compileSdkVersion = 29
1212
buildToolsVersion = '29.0.3'
1313

14-
appcompatVersion = '1.1.0'
15-
coreKtxVersion = '1.2.0'
14+
appcompatVersion = '1.2.0'
15+
coreKtxVersion = '1.3.2'
1616
constraintLayoutVersion = '1.1.3'
17-
kotlinVersion = '1.3.71'
17+
kotlinVersion = '1.4.21'
1818
}
1919

2020
repositories {
@@ -23,7 +23,7 @@ buildscript {
2323
}
2424

2525
dependencies {
26-
classpath 'com.android.tools.build:gradle:3.6.1'
26+
classpath 'com.android.tools.build:gradle:4.0.1'
2727
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
2828
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
2929

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Apr 19 11:09:52 CST 2019
1+
#Tue Dec 29 15:08:36 CST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

library/src/main/java/com/github/ihsg/patternlocker/CellBean.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,40 @@ import kotlin.math.sqrt
1111
* 3 4 5
1212
* 6 7 8
1313
*
14-
* @param x 表示该cell的x坐标(相对坐标)
15-
* @param y 表示该cell的y坐标(相对坐标)
14+
* @param x 表示该cell的x坐标(点坐标)
15+
* @param y 表示该cell的y坐标(点坐标)
16+
* x,y 点坐标编号如下:
17+
* (0,0) (1,0) (2,0)
18+
* (0,1) (1,1) (2,1)
19+
* (0,2) (1,2) (2,2)
20+
*
21+
* @param centerX 表示该cell的圆心x坐标(相对坐标)
22+
* @param centerY 表示该cell的圆心y坐标(相对坐标)
23+
* centerX, centerY 圆心坐标如下:
24+
* (radius, radius) (4radius, radius) (7radius, radius)
25+
* (radius, 4radius) (4radius, 4radius) (7radius, 4radius)
26+
* (radius, 7radius) (4radius, 7radius) (7radius, 7radius)
27+
*
1628
* @param radius 表示该cell的半径
1729
* @param isHit 表示该cell是否被设置的标记
1830
*/
19-
data class CellBean(val id: Int, val x: Float, val y: Float, val radius: Float, var isHit: Boolean = false) {
31+
data class CellBean(val id: Int,
32+
val x: Int,
33+
val y: Int,
34+
val centerX: Float,
35+
val centerY: Float,
36+
val radius: Float,
37+
var isHit: Boolean = false) {
2038
/**
2139
* 是否触碰到该view
2240
*
2341
* @param x
2442
* @param y
2543
* @return
2644
*/
27-
fun of(x: Float, y: Float, enableSkip: Boolean): Boolean {
28-
val dx = this.x - x
29-
val dy = this.y - y
30-
val r = if (enableSkip) this.radius else this.radius * 1.5f
31-
return sqrt((dx * dx + dy * dy).toDouble()) <= r.toDouble()
45+
fun of(x: Float, y: Float): Boolean {
46+
val dx = this.centerX - x
47+
val dy = this.centerY - y
48+
return sqrt((dx * dx + dy * dy)).toDouble() <= this.radius.toDouble()
3249
}
3350
}

library/src/main/java/com/github/ihsg/patternlocker/CellFactory.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ package com.github.ihsg.patternlocker
44
* Created by hsg on 20/09/2017.
55
*/
66

7-
internal class CellFactory(private val width: Int, private val height: Int) {
8-
val cellBeanList: List<CellBean> by lazy {
9-
val result = ArrayList<CellBean>()
10-
result.clear()
7+
object CellFactory {
118

12-
val pWidth = this.width / 8f
13-
val pHeight = this.height / 8f
9+
fun buildCells(width: Int, height: Int): List<CellBean> {
10+
val result = ArrayList<CellBean>()
11+
val pWidth = width / 8f
12+
val pHeight = height / 8f
1413

15-
for (i: Int in 0..2) {
16-
for (j: Int in 0..2) {
17-
val id = (i * 3 + j) % 9
18-
val x = (j * 3 + 1) * pWidth
19-
val y = (i * 3 + 1) * pHeight
20-
result.add(CellBean(id, x, y, pWidth))
21-
}
14+
for (i in 0..8) {
15+
result.add(CellBean(i,
16+
i % 3,
17+
i / 3,
18+
(i % 3 * 3 + 1) * pWidth,
19+
(i / 3 * 3 + 1) * pHeight,
20+
pWidth))
2221
}
22+
2323
Logger.d("CellFactory", "result = $result")
24-
return@lazy result
24+
25+
return result
2526
}
2627
}

library/src/main/java/com/github/ihsg/patternlocker/DefaultConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal object DefaultConfig {
4747
return paint
4848
}
4949

50-
private fun convertDpToPx(dp: Float, resources: Resources): Float {
51-
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.displayMetrics)
50+
private fun convertDpToPx(dpValue: Float, resources: Resources): Float {
51+
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, resources.displayMetrics)
5252
}
5353
}

library/src/main/java/com/github/ihsg/patternlocker/DefaultIndicatorHitCellView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ open class DefaultIndicatorHitCellView(val styleDecorator: DefaultStyleDecorator
2222
val saveCount = canvas.save()
2323

2424
this.paint.color = this.getColor(isError)
25-
canvas.drawCircle(cellBean.x, cellBean.y, cellBean.radius, this.paint)
25+
canvas.drawCircle(cellBean.centerX, cellBean.centerY, cellBean.radius, this.paint)
2626

2727
canvas.restoreToCount(saveCount)
2828
}

library/src/main/java/com/github/ihsg/patternlocker/DefaultIndicatorLinkedLineView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ open class DefaultIndicatorLinkedLineView(val styleDecorator: DefaultStyleDecora
3232
if (0 <= it && it < cellBeanList.size) {
3333
val c = cellBeanList[it]
3434
if (first) {
35-
path.moveTo(c.x, c.y)
35+
path.moveTo(c.centerX, c.centerY)
3636
first = false
3737
} else {
38-
path.lineTo(c.x, c.y)
38+
path.lineTo(c.centerX, c.centerY)
3939
}
4040
}
4141
}

library/src/main/java/com/github/ihsg/patternlocker/DefaultIndicatorNormalCellView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ open class DefaultIndicatorNormalCellView(val styleDecorator: DefaultStyleDecora
2222

2323
//outer circle
2424
this.paint.color = this.styleDecorator.normalColor
25-
canvas.drawCircle(cellBean.x, cellBean.y, cellBean.radius, this.paint)
25+
canvas.drawCircle(cellBean.centerX, cellBean.centerY, cellBean.radius, this.paint)
2626

2727
//inner circle
2828
this.paint.color = this.styleDecorator.fillColor
29-
canvas.drawCircle(cellBean.x, cellBean.y, cellBean.radius - this.styleDecorator.lineWidth, this.paint)
29+
canvas.drawCircle(cellBean.centerX, cellBean.centerY, cellBean.radius - this.styleDecorator.lineWidth, this.paint)
3030

3131
canvas.restoreToCount(saveCount)
3232
}

0 commit comments

Comments
 (0)