package com.bcc.popupwindow
import android.os.Handler
object DataManager {
class EventInfo(val packageName: String)
class DownInfo {
companion object {
const val MAX_POOL_SIZE = 50
var sPool: DownInfo? = null
var sPoolSize = 0
fun obtain(eventInfo: EventInfo): DownInfo {
val downInfo = if (sPool != null) {
val temp = sPool!!
sPool = temp.next
temp.next = null
sPoolSize--
temp
} else {
DownInfo()
}
downInfo.ofValue(eventInfo)
return downInfo
}
}
var next: DownInfo? = null
fun recycle() {
// todo 清空数据
if (sPoolSize < MAX_POOL_SIZE) {
next = sPool
sPool = this
sPoolSize++
}
}
fun ofValue(eventInfo: EventInfo) {
}
fun clearValue() {
}
}
val queue = LinkedHashMap<String, DownInfo>()
//todo ********研究一下demo回到左面 走不走刷新逻辑,这个很关键,如果走,update逻辑就会少调用很多
fun downloadReady(eventInfo: EventInfo) {
// 只任务添加
queue[eventInfo.packageName] = DownInfo.obtain(eventInfo) //todo 直接构造对象吧 不用池了
// todo 为了考虑批量的场景,如果每轮次未开始不走update也不用更新视图,不然刷新次数会爆掉
if(当前轮次已开始){ //todo 研究一下demo回到左面 走不走刷新逻辑,如果走的话,这个就不要处理了
}
}
fun downloading(eventInfo: EventInfo) { // todo
// 任务添加或更新
val downInfo = queue[eventInfo.packageName]
if (downInfo != null) {
downInfo.ofValue(eventInfo)
} else {
queue[eventInfo.packageName] = DownInfo.obtain(eventInfo) //
}
update()
// todo 展示 可以抽公共
}
private fun update() {
if (queue.size == 0){
// todo 标志着每个轮次的结束 写在控制层
}else if(当前轮次未开始){
// todo 标志着每个轮次的开始 写在控制层
}
var downloading = 0
var waiting = 0
var installing = 0
var pending = 0
queue.forEach {
// todo 计算出下载中的数量 等待中数量 安装中的数量
}
if (downloading + waiting + pending> 0) { // 都可以理解为下载中
}
}
fun downloadFail(eventInfo: EventInfo) {
// 移除任务
queue.remove(eventInfo.packageName)
update()
}
fun downloadComplete() { // todo 这里有个特殊情况 下载完成没走安装逻辑
update()
}
fun installing() {
update()
// 先看有没有下载中任务了
}
fun installComplete(eventInfo: EventInfo) {
// 移除任务
if (queue.size == 1) { // 最后一个任务
// todo 5s后移除胶囊和卡片,再处理发通知
}
queue.remove(eventInfo.packageName)
update()
}
fun installFailed(eventInfo: EventInfo) {
// 移除任务
queue.remove(eventInfo.packageName)
}
fun cancel() { // taskworkmanagr 入队列失败 会不会走cancel??
}
fun pause(eventInfo: EventInfo) {
// 移除任务
queue.remove(eventInfo.packageName)
}
fun pend() {
// 更新任务 如果队列中没有任务就不用管
}
}
object BitmapUtils {
const val interval = 60
const val sigleW = 200
const val singleH = 200
val arrayInt1 = intArrayOf(Color.RED,Color.GREEN,Color.BLUE)
val arrayInt2 = intArrayOf(Color.GREEN,Color.BLUE,Color.RED)
val arrayInt3 = intArrayOf(Color.BLUE,Color.RED,Color.GREEN)
fun draw(count :Int):Bitmap{
val bitmap = Bitmap.createBitmap(500,300,Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
val a = when(count%3){
0 -> arrayInt1
1 -> arrayInt2
2 -> arrayInt3
else -> arrayInt1
}
val arr =
repeat(3){
drawSingle(it,canvas,a)
}
return bitmap
}
fun drawSingle(index: Int, canvas: Canvas, a: IntArray) {
canvas.save()
val right = (500-index* interval)
val left = right- sigleW
canvas.clipPath(Path().apply {
addRoundRect(RectF(left.toFloat(),50f,right.toFloat(), 50f+singleH.toFloat()),30f,30f,Path.Direction.CW)
})
canvas.drawRect(RectF(left.toFloat(),50f,right.toFloat(), 50f+singleH.toFloat()), Paint().apply {
setColor(a[index])
})
canvas.restore()
}
}
随笔代码小记
于 2025-06-26 00:08:51 首次发布