Skip to content

Commit

Permalink
[+]打包
Browse files Browse the repository at this point in the history
[+]视图美化用户界面,但是来不及做完了
  • Loading branch information
Watermelon02 committed Jul 26, 2022
1 parent d467047 commit 9b475a3
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 8 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ fun queryTodoList(status: Int = -1, date: String, priority: Int = 0, index: Int

因为需要满足在`添加\删除`Todo后,Service能及时更改数据,所以需要通过`Binder`实现通信。这里通过`AIDL`然后重写`Stub`的方式完成(总不能要我手写吧)

> Activity
```kotlin
//绑定启动TodoManagerService
private fun bindTodoManagerService() {
val todoManagerServiceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
BaseApp.todoManagerBinder = TodoManager.Stub.asInterface(service)
}

override fun onServiceDisconnected(name: ComponentName?) {}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
bindService(Intent(this@DateActivity, TodoManagerService::class.java),
todoManagerServiceConnection,
Context.BIND_AUTO_CREATE)
}

}
```

> Service
```kotlin
override fun onBind(intent: Intent?): IBinder {
iBinder.queryTodoList()
return iBinder
}
```

## 不足

在自定义View方面还不够熟练,浪费了很多时间,而且最后的组件间耦合度比较高。对于Flow的使用不够熟练,有许多暗病.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class UserFragment : DialogFragment() {
Editable.Factory.getInstance().newEditable(viewModel.user.value?.data?.publicName)
binding.fragmentUserTodoAccountEdit.text =
Editable.Factory.getInstance().newEditable(viewModel.user.value?.data?.username)
binding.fragmentUserAccountPieChart.start()
return AlertDialog.Builder(requireContext()).setView(binding.root).create()
}

Expand Down
106 changes: 106 additions & 0 deletions app/src/main/java/watermelon/tobe/view/piechart/PieChartArc1.kt
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 app/src/main/java/watermelon/tobe/view/piechart/PieChartArc2.kt
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 app/src/main/java/watermelon/tobe/view/piechart/PieChartArc3.kt
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 app/src/main/java/watermelon/tobe/view/piechart/PieChartView.kt
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()
}
Loading

0 comments on commit 9b475a3

Please sign in to comment.