|
|
@@ -4,10 +4,14 @@ import android.content.Context
|
|
|
import android.graphics.Canvas
|
|
|
import android.graphics.Color
|
|
|
import android.graphics.Paint
|
|
|
+import android.os.Build
|
|
|
import android.util.AttributeSet
|
|
|
import android.view.View
|
|
|
+import android.view.WindowManager
|
|
|
import androidx.annotation.ColorInt
|
|
|
+import androidx.core.content.ContextCompat
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
+import com.adealink.frame.log.Log
|
|
|
import com.adealink.weparty.R
|
|
|
import com.adealink.weparty.commonui.ripple.lifecyle.RippleLifecycle
|
|
|
import com.adealink.weparty.commonui.ripple.lifecyle.RippleLifecycleAdapter
|
|
|
@@ -58,6 +62,8 @@ class RippleView : View {
|
|
|
private var circleCount: Int = 5
|
|
|
private var circleStyle: Paint.Style = Paint.Style.FILL
|
|
|
private var speed: Float = 0.5f
|
|
|
+
|
|
|
+ private var duration: Int = 200
|
|
|
private var circleStrokeWidth: Float = 3f
|
|
|
|
|
|
|
|
|
@@ -81,8 +87,8 @@ class RippleView : View {
|
|
|
circleCount = array.getInt(indexedValue, 2)
|
|
|
}
|
|
|
|
|
|
- R.styleable.RippleView_ripple_circle_speed -> {
|
|
|
- speed = array.getFloat(indexedValue, speed)
|
|
|
+ R.styleable.RippleView_ripple_circle_duration -> {
|
|
|
+ duration = array.getInt(indexedValue, duration)
|
|
|
}
|
|
|
|
|
|
R.styleable.RippleView_ripple_circle_stroke_width -> {
|
|
|
@@ -135,9 +141,34 @@ class RippleView : View {
|
|
|
//circleMaxRadius = (width / 2 - circleStrokeWidth).toInt()
|
|
|
// circleCenterX = width / 2f
|
|
|
// circleCenterY = height / 2f
|
|
|
+ circleList.clear()
|
|
|
circleList.add(RippleCircle(circleMinRadius, MAX_ALPHA))
|
|
|
}
|
|
|
|
|
|
+ private fun initSpeed() {
|
|
|
+ val refreshRate = getDisplayRefreshRate(context)
|
|
|
+ val refreshInterval = 1000f / refreshRate
|
|
|
+ val refreshCount = duration / refreshInterval
|
|
|
+ speed = (circleMaxRadius() - circleMinRadius) / refreshCount
|
|
|
+ }
|
|
|
+
|
|
|
+ private var refreshRate: Int = 0
|
|
|
+ fun getDisplayRefreshRate(context: Context): Int {
|
|
|
+ if (refreshRate != 0) {
|
|
|
+ return refreshRate
|
|
|
+ }
|
|
|
+ val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
+ context.display.refreshRate
|
|
|
+ } else {
|
|
|
+ ContextCompat.getSystemService(
|
|
|
+ context,
|
|
|
+ WindowManager::class.java
|
|
|
+ )?.defaultDisplay?.refreshRate ?: 60f
|
|
|
+ }
|
|
|
+ refreshRate = display.toInt()
|
|
|
+ return refreshRate
|
|
|
+ }
|
|
|
+
|
|
|
private fun circleMaxRadius(): Int {
|
|
|
return (width / 2 - circleStrokeWidth).toInt()
|
|
|
}
|
|
|
@@ -201,6 +232,7 @@ class RippleView : View {
|
|
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
|
super.onSizeChanged(w, h, oldw, oldh)
|
|
|
initCircle()
|
|
|
+ initSpeed()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -265,7 +297,7 @@ class RippleView : View {
|
|
|
return
|
|
|
}
|
|
|
val minMeet = (circleMaxRadius() - circleMinRadius) / circleCount
|
|
|
- val add = circleList.last().radius > minMeet + circleMinRadius
|
|
|
+ val add = circleList.last().radius > (minMeet + circleMinRadius)
|
|
|
if (add) {
|
|
|
circleList.add(RippleCircle(circleMinRadius, MAX_ALPHA))
|
|
|
}
|