-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
436 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
app/src/main/java/watermelon/tobe/view/piechart/PieChartArc1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package watermelon.tobe.view.piechart | ||
|
||
import android.animation.ValueAnimator | ||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.* | ||
import android.graphics.drawable.shapes.ArcShape | ||
import android.os.Build | ||
import android.util.AttributeSet | ||
import android.util.Log | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import androidx.core.graphics.alpha | ||
|
||
/** | ||
* description : TODO:类的作用 | ||
* author : Watermelon02 | ||
* email : [email protected] | ||
* date : 2022/7/26 14:38 | ||
*/ | ||
class PieChartArc1(context: Context?, attrs: AttributeSet?) : PieChartView(context, attrs) { | ||
private var redAlpha1 = 0 | ||
private var redAlpha2 = 0 | ||
private var redColor1 = Color.WHITE | ||
private var redColor2 = Color.WHITE | ||
private val outOfDatePaint = Paint().apply { | ||
color = PieChartViewGroup.RED | ||
style = Paint.Style.FILL | ||
} | ||
private var redAnimator1 = ValueAnimator.ofFloat(1f, 0.25f).apply { | ||
duration = 9000 | ||
repeatMode = ValueAnimator.REVERSE | ||
repeatCount = ValueAnimator.INFINITE | ||
} | ||
private var redAnimator2: ValueAnimator = ValueAnimator.ofFloat(1f, 4f).apply { | ||
duration = 4000 | ||
repeatMode = ValueAnimator.REVERSE | ||
repeatCount = ValueAnimator.INFINITE | ||
} | ||
private val circlePaint = Paint().apply { | ||
color = Color.WHITE | ||
style = Paint.Style.FILL | ||
} | ||
|
||
override fun onTouchEvent(event: MotionEvent?): Boolean { | ||
Log.d("testTag", "(PieChartView.kt:17) -> 1") | ||
return super.onTouchEvent(event) | ||
} | ||
|
||
@SuppressLint("DrawAllocation") | ||
override fun onDraw(canvas: Canvas) { | ||
super.onDraw(canvas) | ||
val radius = width / 2f | ||
outOfDatePaint.shader = LinearGradient( | ||
0f, | ||
0f, | ||
width.toFloat(), | ||
height.toFloat(), | ||
arrayOf(redColor1, redColor2).toIntArray(), | ||
null, | ||
Shader.TileMode.REPEAT | ||
) | ||
canvas.drawArc(0f, | ||
0f, | ||
width.toFloat(), | ||
width.toFloat(), | ||
0f, | ||
120f, | ||
true, | ||
outOfDatePaint) | ||
canvas.drawCircle(width / 2f, height / 2f, radius - 15, circlePaint) | ||
|
||
} | ||
|
||
override fun start() { | ||
redAnimator1.removeAllUpdateListeners() | ||
redAnimator2.removeAllUpdateListeners() | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
redAlpha1 = (PieChartViewGroup.RED.alpha * 0.8).toInt() | ||
redAlpha2 = (PieChartViewGroup.RED.alpha * 0.2).toInt() | ||
} | ||
redAnimator2.addUpdateListener { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
this.redColor2 = Color.argb( | ||
(redAlpha2 * (it.animatedValue as Float)).toInt(), | ||
Color.red(PieChartViewGroup.RED), | ||
Color.green(PieChartViewGroup.RED), | ||
Color.blue(PieChartViewGroup.RED) | ||
) | ||
} | ||
} | ||
redAnimator1.addUpdateListener { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
this.redColor1 = Color.argb( | ||
(redAlpha1 * (it.animatedValue as Float)).toInt(), | ||
Color.red(PieChartViewGroup.RED), | ||
Color.green(PieChartViewGroup.RED), | ||
Color.blue(PieChartViewGroup.RED) | ||
) | ||
invalidate() | ||
} | ||
} | ||
redAnimator1.start() | ||
redAnimator2.start() | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
app/src/main/java/watermelon/tobe/view/piechart/PieChartArc2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package watermelon.tobe.view.piechart | ||
|
||
import android.animation.ValueAnimator | ||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.* | ||
import android.os.Build | ||
import android.util.AttributeSet | ||
import android.util.Log | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import androidx.core.graphics.alpha | ||
|
||
/** | ||
* description : TODO:类的作用 | ||
* author : Watermelon02 | ||
* email : [email protected] | ||
* date : 2022/7/26 14:38 | ||
*/ | ||
class PieChartArc2(context: Context?, attrs: AttributeSet?) : PieChartView(context, attrs) { | ||
private var blueAlpha1 = 0 | ||
private var blueAlpha2 = 0 | ||
private var blueColor1 = Color.WHITE | ||
private var blueColor2 = Color.WHITE | ||
private val circlePaint = Paint().apply { | ||
color = Color.WHITE | ||
style = Paint.Style.FILL | ||
} | ||
private val notFinishedPaint = Paint().apply { | ||
color = Color.GREEN | ||
style = Paint.Style.FILL | ||
} | ||
private var blueAnimator1 = ValueAnimator.ofFloat(1f, 0.2f).apply { | ||
duration = 5000 | ||
repeatMode = ValueAnimator.REVERSE | ||
repeatCount = ValueAnimator.INFINITE | ||
} | ||
private var blueAnimator2: ValueAnimator = ValueAnimator.ofFloat(1f, 5f).apply { | ||
duration = 3000 | ||
repeatMode = ValueAnimator.REVERSE | ||
repeatCount = ValueAnimator.INFINITE | ||
} | ||
|
||
override fun onTouchEvent(event: MotionEvent?): Boolean { | ||
Log.d("testTag", "(PieChartView.kt:17) -> 2") | ||
return super.onTouchEvent(event) | ||
} | ||
|
||
@SuppressLint("DrawAllocation") | ||
override fun onDraw(canvas: Canvas) { | ||
super.onDraw(canvas) | ||
val radius = width / 2f | ||
notFinishedPaint.shader = LinearGradient( | ||
0f, | ||
0f, | ||
width.toFloat(), | ||
height.toFloat(), | ||
arrayOf(blueColor1, blueColor2).toIntArray(), | ||
null, | ||
Shader.TileMode.REPEAT | ||
) | ||
canvas.drawArc(0f, | ||
0f, | ||
width.toFloat(), | ||
width.toFloat(), | ||
120f, | ||
120f, | ||
true, | ||
notFinishedPaint) | ||
canvas.drawCircle(width / 2f, height / 2f, radius - 15, circlePaint) | ||
|
||
} | ||
|
||
override fun start() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
blueAlpha1 = (Color.BLUE.alpha * 0.8).toInt() | ||
blueAlpha2 = (Color.BLUE.alpha * 0.2).toInt() | ||
} | ||
blueAnimator1.addUpdateListener { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
this.blueColor1 = Color.argb( | ||
(blueAlpha1 * (it.animatedValue as Float)).toInt(), | ||
Color.red(PieChartViewGroup.YELLOW), | ||
Color.green(PieChartViewGroup.YELLOW), | ||
Color.blue(PieChartViewGroup.YELLOW) | ||
) | ||
} | ||
} | ||
blueAnimator2.addUpdateListener { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
this.blueColor2 = Color.argb( | ||
(blueAlpha2 * (it.animatedValue as Float)).toInt(), | ||
Color.red(PieChartViewGroup.YELLOW), | ||
Color.green(PieChartViewGroup.YELLOW), | ||
Color.blue(PieChartViewGroup.YELLOW) | ||
) | ||
} | ||
} | ||
blueAnimator1.start() | ||
blueAnimator2.start() | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
app/src/main/java/watermelon/tobe/view/piechart/PieChartArc3.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package watermelon.tobe.view.piechart | ||
|
||
import android.animation.ValueAnimator | ||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.* | ||
import android.os.Build | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import androidx.core.graphics.alpha | ||
|
||
/** | ||
* description : TODO:类的作用 | ||
* author : Watermelon02 | ||
* email : [email protected] | ||
* date : 2022/7/26 14:38 | ||
*/ | ||
class PieChartArc3(context: Context?, attrs: AttributeSet?) : PieChartView(context, attrs) { | ||
private var yellowAlpha1 = 0 | ||
private var yellowAlpha2 = 0 | ||
private var yellowColor1 = Color.WHITE | ||
private var yellowColor2 = Color.WHITE | ||
private val finishPaint = Paint().apply { | ||
color = Color.BLUE | ||
style = Paint.Style.FILL | ||
} | ||
private val circlePaint = Paint().apply { | ||
color = Color.WHITE | ||
style = Paint.Style.FILL | ||
} | ||
private var yellowAnimator1 = ValueAnimator.ofFloat(1f, 0.2f).apply { | ||
duration = 6000 | ||
repeatMode = ValueAnimator.REVERSE | ||
repeatCount = ValueAnimator.INFINITE | ||
} | ||
private var yellowAnimator2: ValueAnimator = ValueAnimator.ofFloat(1f, 5f).apply { | ||
duration = 8000 | ||
repeatMode = ValueAnimator.REVERSE | ||
repeatCount = ValueAnimator.INFINITE | ||
} | ||
|
||
@SuppressLint("DrawAllocation") | ||
override fun onDraw(canvas: Canvas) { | ||
super.onDraw(canvas) | ||
val radius = width / 2f | ||
finishPaint.shader = LinearGradient( | ||
0f, | ||
0f, | ||
width.toFloat(), | ||
height.toFloat(), | ||
arrayOf(yellowColor1, yellowColor2).toIntArray(), | ||
null, | ||
Shader.TileMode.REPEAT | ||
) | ||
canvas.drawArc(0f, 0f, width.toFloat(), width.toFloat(), 240f, 120f, true, finishPaint) | ||
canvas.drawCircle(width / 2f, height / 2f, radius - 15, circlePaint) | ||
|
||
} | ||
|
||
override fun start() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
yellowAlpha1 = (Color.GREEN.alpha * 0.8).toInt() | ||
yellowAlpha2 = (Color.GREEN.alpha * 0.2).toInt() | ||
yellowAnimator1.addUpdateListener { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
this.yellowColor1 = Color.argb( | ||
(yellowAlpha1 * (it.animatedValue as Float)).toInt(), | ||
Color.red(Color.parseColor("#FFFFFF")), | ||
Color.green(PieChartViewGroup.GREEN), | ||
Color.blue(PieChartViewGroup.GREEN) | ||
) | ||
} | ||
} | ||
yellowAnimator2.addUpdateListener { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
this.yellowColor2 = Color.argb( | ||
(yellowAlpha2 * (it.animatedValue as Float)).toInt(), | ||
Color.red(PieChartViewGroup.GREEN), | ||
Color.green(PieChartViewGroup.GREEN), | ||
Color.blue(PieChartViewGroup.GREEN) | ||
) | ||
} | ||
} | ||
yellowAnimator1.start() | ||
yellowAnimator2.start() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/watermelon/tobe/view/piechart/PieChartView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package watermelon.tobe.view.piechart | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.util.Log | ||
import android.view.MotionEvent | ||
import android.view.View | ||
|
||
/** | ||
* description : TODO:类的作用 | ||
* author : Watermelon02 | ||
* email : [email protected] | ||
* date : 2022/7/26 14:58 | ||
*/ | ||
abstract class PieChartView(context: Context?, attrs: AttributeSet?) : View(context, attrs) { | ||
val pieChartViewGroup by lazy { parent as PieChartViewGroup } | ||
|
||
abstract fun start() | ||
} |
Oops, something went wrong.