Skip to content

Commit

Permalink
fix bugs: setting invalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshouguo committed Apr 28, 2019
1 parent f202a80 commit 95fce81
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 624 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ android {

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

implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
implementation "com.android.support.constraint:constraint-layout:$rootProject.ext.constraintLayoutVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import com.github.ihsg.demo.util.PatternHelper
import com.github.ihsg.patternlocker.OnPatternChangeListener
import com.github.ihsg.patternlocker.PatternLockerView
import kotlinx.android.synthetic.main.activity_default_pattern_checking.*
import java.util.*

class DefaultPatternSettingActivity : AppCompatActivity() {
private var patternHelper: PatternHelper? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_default_pattern_setting)
patternIndicatorView.updateState(Arrays.asList(1, 2), false)

patternLockerView.setOnPatternChangedListener(object : OnPatternChangeListener {
override fun onStart(view: PatternLockerView) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.util.TypedValue

import com.github.ihsg.demo.R
import com.github.ihsg.demo.util.PatternHelper
import com.github.ihsg.patternlocker.DefaultLockerNormalCellView
import com.github.ihsg.patternlocker.OnPatternChangeListener
import com.github.ihsg.patternlocker.PatternLockerView
import kotlinx.android.synthetic.main.activity_default_pattern_checking.*
Expand All @@ -21,21 +22,21 @@ class SimplePatternCheckingActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_simple_pattern_checking)

this.patternIndicatorView!!.setFillColor(ContextCompat.getColor(this, R.color.color_blue))
.setNormalColor(ContextCompat.getColor(this, R.color.colorWhite))
.setHitColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
.setErrorColor(ContextCompat.getColor(this, R.color.color_red))
.setLineWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f,
resources.displayMetrics))
.buildWithDefaultStyle()

this.patternLockerView!!.setFillColor(ContextCompat.getColor(this, R.color.color_blue))
.setNormalColor(ContextCompat.getColor(this, R.color.colorWhite))
.setHitColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
.setErrorColor(ContextCompat.getColor(this, R.color.color_red))
.setLineWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5f,
resources.displayMetrics))
.buildWithDefaultStyle()
val pivStyle = (this.patternIndicatorView.normalCellView as DefaultLockerNormalCellView).styleDecorator
pivStyle.normalColor = ContextCompat.getColor(this, R.color.colorWhite)
pivStyle.fillColor = ContextCompat.getColor(this, R.color.color_blue)
pivStyle.hitColor = ContextCompat.getColor(this, R.color.colorPrimaryDark)
pivStyle.errorColor = ContextCompat.getColor(this, R.color.color_red)
pivStyle.lineWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f,
resources.displayMetrics)

val plvStyle = (this.patternLockerView.normalCellView as DefaultLockerNormalCellView).styleDecorator
plvStyle.normalColor = ContextCompat.getColor(this, R.color.colorWhite)
plvStyle.fillColor = ContextCompat.getColor(this, R.color.color_blue)
plvStyle.hitColor = ContextCompat.getColor(this, R.color.colorPrimaryDark)
plvStyle.errorColor = ContextCompat.getColor(this, R.color.color_red)
plvStyle.lineWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5f,
resources.displayMetrics)

this.patternLockerView!!.setOnPatternChangedListener(object : OnPatternChangeListener {
override fun onStart(view: PatternLockerView) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import com.github.ihsg.demo.R
import com.github.ihsg.demo.util.PatternHelper
import com.github.ihsg.patternlocker.DefaultLockerNormalCellView
import com.github.ihsg.patternlocker.OnPatternChangeListener
import com.github.ihsg.patternlocker.PatternLockerView
import kotlinx.android.synthetic.main.activity_simple_pattern_checking.*
Expand All @@ -19,12 +20,11 @@ class WholePatternCheckingActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_whole_pattern_checking)

val hitCellView = RippleLockerHitCellView()
.setHitColor(this.patternLockerView.getHitColor())
.setErrorColor(this.patternLockerView.getErrorColor())
val decorator = (this.patternLockerView.normalCellView as DefaultLockerNormalCellView).styleDecorator

this.patternLockerView.setHitCellView(hitCellView)
.build()
this.patternLockerView.hitCellView = RippleLockerHitCellView()
.setHitColor(decorator.hitColor)
.setErrorColor(decorator.errorColor)

this.patternLockerView.setOnPatternChangedListener(object : OnPatternChangeListener {
override fun onStart(view: PatternLockerView) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.support.v7.app.AppCompatActivity
import android.view.View
import com.github.ihsg.demo.R
import com.github.ihsg.demo.util.PatternHelper
import com.github.ihsg.patternlocker.DefaultLockerNormalCellView
import com.github.ihsg.patternlocker.OnPatternChangeListener
import com.github.ihsg.patternlocker.PatternLockerView
import kotlinx.android.synthetic.main.activity_simple_pattern_checking.*
Expand All @@ -20,13 +21,12 @@ class WholePatternSettingActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_whole_pattern_setting)

val hitCellView = RippleLockerHitCellView()
.setHitColor(this.patternLockerView!!.getHitColor())
.setErrorColor(this.patternLockerView!!.getErrorColor())

this.patternLockerView!!.setHitCellView(hitCellView)
.build()
val decorator = (this.patternLockerView.normalCellView as DefaultLockerNormalCellView).styleDecorator

this.patternLockerView.hitCellView = RippleLockerHitCellView()
.setHitColor(decorator.hitColor)
.setErrorColor(decorator.errorColor)

this.patternLockerView!!.setOnPatternChangedListener(object : OnPatternChangeListener {
override fun onStart(view: PatternLockerView) {}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_whole_pattern_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:layout_marginRight="50dp"
app:plv_canSkip="true"
app:plv_enableSkip="true"
app:plv_enableHapticFeedback="true"
app:plv_color="@color/color_gray"
app:plv_enableAutoClean="false"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
// versions
ext {
versionCode = 14
versionName = '2.4.5'
versionName = '2.5.0'

minSdkVersion = 15
targetSdkVersion = 28
Expand All @@ -23,7 +23,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Nov 01 10:15:42 CST 2018
#Fri Apr 19 11:09:52 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
13 changes: 11 additions & 2 deletions library/src/main/java/com/github/ihsg/patternlocker/CellBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ package com.github.ihsg.patternlocker

/**
* Created by hsg on 20/09/2017.
*
* @param id each cell id order like this:
*
* 0 1 2
* 3 4 5
* 6 7 8
*
* @param x
* @param y
* @param radius
* @param isHit
*/

class CellBean(val id: Int, val x: Float, val y: Float, val radius: Float) {
var isHit: Boolean = false

Expand All @@ -24,5 +34,4 @@ class CellBean(val id: Int, val x: Float, val y: Float, val radius: Float) {
override fun toString(): String {
return "CellBean(id=$id, x=$x, y=$y, radius=$radius, isHit=$isHit)"
}

}
22 changes: 9 additions & 13 deletions library/src/main/java/com/github/ihsg/patternlocker/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@ internal object Config {
const val defaultFreezeDuration = 1000//ms
const val defaultEnableAutoClean = true
const val defaultEnableHapticFeedback = false
const val defaultCanSkip = false
const val defaultEnableSkip = false
const val defaultEnableLogger = false

val defaultNormalColor: Int
@ColorInt
get() = Color.parseColor(DEFAULT_NORMAL_COLOR)
@ColorInt
val defaultNormalColor: Int = Color.parseColor(DEFAULT_NORMAL_COLOR)

val defaultHitColor: Int
@ColorInt
get() = Color.parseColor(DEFAULT_HIT_COLOR)
@ColorInt
val defaultHitColor: Int = Color.parseColor(DEFAULT_HIT_COLOR)

val defaultErrorColor: Int
@ColorInt
get() = Color.parseColor(DEFAULT_ERROR_COLOR)
@ColorInt
val defaultErrorColor: Int = Color.parseColor(DEFAULT_ERROR_COLOR)

val defaultFillColor: Int
@ColorInt
get() = Color.parseColor(DEFAULT_FILL_COLOR)
@ColorInt
val defaultFillColor: Int = Color.parseColor(DEFAULT_FILL_COLOR)

fun getDefaultLineWidth(resources: Resources): Float {
return convertDpToPx(DEFAULT_LINE_WIDTH.toFloat(), resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import android.support.annotation.ColorInt
* Created by hsg on 22/02/2018.
*/

class DefaultIndicatorHitCellView : IHitCellView {
@ColorInt
private var normalColor: Int = 0
@ColorInt
private var errorColor: Int = 0
class DefaultIndicatorHitCellView(val styleDecorator: DefaultStyleDecorator) : IHitCellView {

private val paint: Paint by lazy {
Config.createPaint()
}
Expand All @@ -21,26 +18,6 @@ class DefaultIndicatorHitCellView : IHitCellView {
this.paint.style = Paint.Style.FILL
}

@ColorInt
fun getNormalColor(): Int {
return normalColor
}

fun setNormalColor(@ColorInt normalColor: Int): DefaultIndicatorHitCellView {
this.normalColor = normalColor
return this
}

@ColorInt
fun getErrorColor(): Int {
return errorColor
}

fun setErrorColor(@ColorInt errorColor: Int): DefaultIndicatorHitCellView {
this.errorColor = errorColor
return this
}

override fun draw(canvas: Canvas, cellBean: CellBean, isError: Boolean) {
val saveCount = canvas.save()

Expand All @@ -52,6 +29,6 @@ class DefaultIndicatorHitCellView : IHitCellView {

@ColorInt
private fun getColor(isError: Boolean): Int {
return if (isError) this.getErrorColor() else this.getNormalColor()
return if (isError) this.styleDecorator.errorColor else this.styleDecorator.hitColor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import android.support.annotation.ColorInt
* Created by hsg on 22/02/2018.
*/

class DefaultIndicatorLinkedLineView : IIndicatorLinkedLineView {
@ColorInt
private var normalColor: Int = 0
@ColorInt
private var errorColor: Int = 0
private var lineWidth: Float = 0f
class DefaultIndicatorLinkedLineView(val styleDecorator: DefaultStyleDecorator) : IIndicatorLinkedLineView {

private val paint: Paint by lazy {
Config.createPaint()
}
Expand All @@ -23,35 +19,6 @@ class DefaultIndicatorLinkedLineView : IIndicatorLinkedLineView {
this.paint.style = Paint.Style.STROKE
}

@ColorInt
fun getNormalColor(): Int {
return normalColor
}

fun setNormalColor(@ColorInt normalColor: Int): DefaultIndicatorLinkedLineView {
this.normalColor = normalColor
return this
}

@ColorInt
fun getErrorColor(): Int {
return errorColor
}

fun setErrorColor(@ColorInt errorColor: Int): DefaultIndicatorLinkedLineView {
this.errorColor = errorColor
return this
}

fun getLineWidth(): Float {
return lineWidth
}

fun setLineWidth(lineWidth: Float): DefaultIndicatorLinkedLineView {
this.lineWidth = lineWidth
return this
}

override fun draw(canvas: Canvas, hitIndexList: List<Int>, cellBeanList: List<CellBean>, isError: Boolean) {
if (hitIndexList.isEmpty() || cellBeanList.isEmpty()) {
return
Expand All @@ -74,13 +41,13 @@ class DefaultIndicatorLinkedLineView : IIndicatorLinkedLineView {
}

this.paint.color = this.getColor(isError)
this.paint.strokeWidth = this.getLineWidth()
this.paint.strokeWidth = this.styleDecorator.lineWidth
canvas.drawPath(path, this.paint)
canvas.restoreToCount(saveCount)
}

@ColorInt
private fun getColor(isError: Boolean): Int {
return if (isError) this.getErrorColor() else this.getNormalColor()
return if (isError) this.styleDecorator.errorColor else this.styleDecorator.hitColor
}
}
Loading

0 comments on commit 95fce81

Please sign in to comment.