Skip to content

Commit

Permalink
fix hitCellView null && rename Config to DefaultConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshouguo committed Jun 23, 2019
1 parent 7916228 commit 739db92
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 68 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
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.ihsg.demo">

<application
Expand All @@ -9,7 +10,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class DefaultPatternCheckingActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_default_pattern_checking)


patternLockerView.linkedLineView = null
patternLockerView.hitCellView = null
patternLockerView.setOnPatternChangedListener(object : OnPatternChangeListener {
override fun onStart(view: PatternLockerView) {}

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ buildscript {
buildToolsVersion = '28.0.3'

supportLibraryVersion = '28.0.0'
constraintLayoutVersion = '1.0.2'
kotlinVersion = '1.3.21'
constraintLayoutVersion = '2.0.0-beta2'
kotlinVersion = '1.3.40'
}

repositories {
Expand All @@ -23,7 +23,7 @@ buildscript {
}

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

Expand Down
22 changes: 9 additions & 13 deletions library/src/main/java/com/github/ihsg/patternlocker/CellBean.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.github.ihsg.patternlocker

import kotlin.math.sqrt

/**
* Created by hsg on 20/09/2017.
*
* @param id each cell id order like this:
* @param id 表示该cell的编号,9个cell的编号如下:
*
* 0 1 2
* 3 4 5
* 6 7 8
*
* @param x
* @param y
* @param radius
* @param isHit
* @param x 表示该cell的x坐标(相对坐标)
* @param y 表示该cell的y坐标(相对坐标)
* @param radius 表示该cell的半径
* @param isHit 表示该cell是否被设置的标记
*/
class CellBean(val id: Int, val x: Float, val y: Float, val radius: Float) {
var isHit: Boolean = false

data class CellBean(val id: Int, val x: Float, val y: Float, val radius: Float, var isHit: Boolean = false) {
/**
* 是否触碰到该view
*
Expand All @@ -28,10 +28,6 @@ class CellBean(val id: Int, val x: Float, val y: Float, val radius: Float) {
val dx = this.x - x
val dy = this.y - y
val r = if (enableSkip) this.radius else this.radius * 1.5f
return Math.sqrt((dx * dx + dy * dy).toDouble()) <= r.toDouble()
}

override fun toString(): String {
return "CellBean(id=$id, x=$x, y=$y, radius=$radius, isHit=$isHit)"
return sqrt((dx * dx + dy * dy).toDouble()) <= r.toDouble()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.util.TypedValue
/**
* Created by hsg on 23/09/2017.
*/
internal object Config {
internal object DefaultConfig {
private const val DEFAULT_NORMAL_COLOR = "#2196F3"
private const val DEFAULT_HIT_COLOR = "#3F51B5"
private const val DEFAULT_ERROR_COLOR = "#F44336"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import android.support.annotation.ColorInt
class DefaultIndicatorHitCellView(val styleDecorator: DefaultStyleDecorator) : IHitCellView {

private val paint: Paint by lazy {
Config.createPaint()
DefaultConfig.createPaint()
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import android.support.annotation.ColorInt
class DefaultIndicatorLinkedLineView(val styleDecorator: DefaultStyleDecorator) : IIndicatorLinkedLineView {

private val paint: Paint by lazy {
Config.createPaint()
DefaultConfig.createPaint()
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import android.graphics.Paint
class DefaultIndicatorNormalCellView(val styleDecorator: DefaultStyleDecorator) : INormalCellView {

private val paint: Paint by lazy {
Config.createPaint()
DefaultConfig.createPaint()
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import android.support.annotation.ColorInt
class DefaultLockerHitCellView(val styleDecorator: DefaultStyleDecorator) : IHitCellView {

private val paint: Paint by lazy {
Config.createPaint()
DefaultConfig.createPaint()
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DefaultLockerLinkedLineView(val styleDecorator: DefaultStyleDecorator) : I
}

private val paint: Paint by lazy {
Config.createPaint()
DefaultConfig.createPaint()
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.graphics.Paint

class DefaultLockerNormalCellView(val styleDecorator: DefaultStyleDecorator) : INormalCellView {
private val paint: Paint by lazy {
Config.createPaint()
DefaultConfig.createPaint()
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.github.ihsg.patternlocker
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.util.Log
import android.view.View
import kotlin.math.min

/**
* Created by hsg on 20/09/2017.
Expand Down Expand Up @@ -52,7 +52,7 @@ class PatternIndicatorView @JvmOverloads constructor(context: Context, attrs: At
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val a = Math.min(widthMeasureSpec, heightMeasureSpec)
val a = min(widthMeasureSpec, heightMeasureSpec)
super.onMeasure(a, a)
}

Expand All @@ -70,11 +70,11 @@ class PatternIndicatorView @JvmOverloads constructor(context: Context, attrs: At
private fun initAttrs(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
val ta = context.obtainStyledAttributes(attrs, R.styleable.PatternIndicatorView, defStyleAttr, 0)

val normalColor = ta.getColor(R.styleable.PatternIndicatorView_piv_color, Config.defaultNormalColor)
val fillColor = ta.getColor(R.styleable.PatternIndicatorView_piv_fillColor, Config.defaultFillColor)
val hitColor = ta.getColor(R.styleable.PatternIndicatorView_piv_hitColor, Config.defaultHitColor)
val errorColor = ta.getColor(R.styleable.PatternIndicatorView_piv_errorColor, Config.defaultErrorColor)
val lineWidth = ta.getDimension(R.styleable.PatternIndicatorView_piv_lineWidth, Config.getDefaultLineWidth(resources))
val normalColor = ta.getColor(R.styleable.PatternIndicatorView_piv_color, DefaultConfig.defaultNormalColor)
val fillColor = ta.getColor(R.styleable.PatternIndicatorView_piv_fillColor, DefaultConfig.defaultFillColor)
val hitColor = ta.getColor(R.styleable.PatternIndicatorView_piv_hitColor, DefaultConfig.defaultHitColor)
val errorColor = ta.getColor(R.styleable.PatternIndicatorView_piv_errorColor, DefaultConfig.defaultErrorColor)
val lineWidth = ta.getDimension(R.styleable.PatternIndicatorView_piv_lineWidth, DefaultConfig.getDefaultLineWidth(resources))

ta.recycle()

Expand Down Expand Up @@ -116,18 +116,8 @@ class PatternIndicatorView @JvmOverloads constructor(context: Context, attrs: At
}

private fun drawCells(canvas: Canvas) {
if (this.hitCellView == null) {
Log.e(TAG, "drawCells(), hitCellView is null")
return
}

if (this.normalCellView == null) {
Log.e(TAG, "drawCells(), normalCellView is null")
return
}

this.cellBeanList.forEach {
if (it.isHit) {
if (it.isHit && this.hitCellView != null) {
this.hitCellView?.draw(canvas, it, this.isError)
} else {
this.normalCellView?.draw(canvas, it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.github.ihsg.patternlocker
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.util.Log
import android.view.HapticFeedbackConstants
import android.view.MotionEvent
import android.view.View
import kotlin.math.min


/**
Expand Down Expand Up @@ -126,7 +126,7 @@ class PatternLockerView @JvmOverloads constructor(context: Context, attrs: Attri


override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val a = Math.min(widthMeasureSpec, heightMeasureSpec)
val a = min(widthMeasureSpec, heightMeasureSpec)
super.onMeasure(a, a)
}

Expand Down Expand Up @@ -165,16 +165,16 @@ class PatternLockerView @JvmOverloads constructor(context: Context, attrs: Attri
private fun initAttrs(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
val ta = context.obtainStyledAttributes(attrs, R.styleable.PatternLockerView, defStyleAttr, 0)

val normalColor = ta.getColor(R.styleable.PatternLockerView_plv_color, Config.defaultNormalColor)
val hitColor = ta.getColor(R.styleable.PatternLockerView_plv_hitColor, Config.defaultHitColor)
val errorColor = ta.getColor(R.styleable.PatternLockerView_plv_errorColor, Config.defaultErrorColor)
val fillColor = ta.getColor(R.styleable.PatternLockerView_plv_fillColor, Config.defaultFillColor)
val lineWidth = ta.getDimension(R.styleable.PatternLockerView_plv_lineWidth, Config.getDefaultLineWidth(resources))
val normalColor = ta.getColor(R.styleable.PatternLockerView_plv_color, DefaultConfig.defaultNormalColor)
val hitColor = ta.getColor(R.styleable.PatternLockerView_plv_hitColor, DefaultConfig.defaultHitColor)
val errorColor = ta.getColor(R.styleable.PatternLockerView_plv_errorColor, DefaultConfig.defaultErrorColor)
val fillColor = ta.getColor(R.styleable.PatternLockerView_plv_fillColor, DefaultConfig.defaultFillColor)
val lineWidth = ta.getDimension(R.styleable.PatternLockerView_plv_lineWidth, DefaultConfig.getDefaultLineWidth(resources))

this.freezeDuration = ta.getInteger(R.styleable.PatternLockerView_plv_freezeDuration, Config.defaultFreezeDuration)
this.enableAutoClean = ta.getBoolean(R.styleable.PatternLockerView_plv_enableAutoClean, Config.defaultEnableAutoClean)
this.enableHapticFeedback = ta.getBoolean(R.styleable.PatternLockerView_plv_enableHapticFeedback, Config.defaultEnableHapticFeedback)
this.enableSkip = ta.getBoolean(R.styleable.PatternLockerView_plv_enableSkip, Config.defaultEnableSkip)
this.freezeDuration = ta.getInteger(R.styleable.PatternLockerView_plv_freezeDuration, DefaultConfig.defaultFreezeDuration)
this.enableAutoClean = ta.getBoolean(R.styleable.PatternLockerView_plv_enableAutoClean, DefaultConfig.defaultEnableAutoClean)
this.enableHapticFeedback = ta.getBoolean(R.styleable.PatternLockerView_plv_enableHapticFeedback, DefaultConfig.defaultEnableHapticFeedback)
this.enableSkip = ta.getBoolean(R.styleable.PatternLockerView_plv_enableSkip, DefaultConfig.defaultEnableSkip)

ta.recycle()

Expand All @@ -186,7 +186,7 @@ class PatternLockerView @JvmOverloads constructor(context: Context, attrs: Attri
}

private fun initData() {
Logger.enable = Config.defaultEnableLogger
Logger.enable = DefaultConfig.defaultEnableLogger
this.hitIndexList.clear()
}

Expand All @@ -210,18 +210,8 @@ class PatternLockerView @JvmOverloads constructor(context: Context, attrs: Attri
}

private fun drawCells(canvas: Canvas) {
if (this.hitCellView == null) {
Log.e(TAG, "drawCells(), hitCellView is null")
return
}

if (this.normalCellView == null) {
Log.e(TAG, "drawCells(), normalCellView is null")
return
}

this.cellBeanList.forEach {
if (it.isHit) {
if (it.isHit && this.hitCellView != null) {
this.hitCellView?.draw(canvas, it, this.isError)
} else {
this.normalCellView?.draw(canvas, it)
Expand Down

0 comments on commit 739db92

Please sign in to comment.