parent
dba01564c9
commit
d2475a2e9b
@ -39,7 +39,6 @@
|
||||
<color name="settings_color_accent">@color/blue</color>
|
||||
<color name="settings_color_primary">#333</color>
|
||||
<color name="settings_color_primary_dark">#222</color>
|
||||
<color name="badge">@color/cardview_light_background</color>
|
||||
|
||||
<color name="fake_card_resting_color">#222222</color>
|
||||
<color name="fake_card_elevated_color">#282828</color>
|
||||
|
||||
@ -5,16 +5,13 @@ import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.AdaptiveIconDrawable
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator
|
||||
import de.mm20.launcher2.badges.Badge
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import de.mm20.launcher2.ktx.toRectF
|
||||
@ -72,12 +69,6 @@ class LauncherIconView : View, KoinComponent {
|
||||
invalidate()
|
||||
}
|
||||
|
||||
var badge: Badge? = null
|
||||
set(value) {
|
||||
field = value
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private val iconObserver: (LauncherIcon) -> Unit = {
|
||||
foregroundScale = it.foregroundScale
|
||||
backgroundScale = it.backgroundScale
|
||||
@ -152,11 +143,6 @@ class LauncherIconView : View, KoinComponent {
|
||||
isFilterBitmap = true
|
||||
}
|
||||
|
||||
private val badgePaint = Paint().apply {
|
||||
color = ContextCompat.getColor(context, R.color.badge)
|
||||
isAntiAlias = true
|
||||
}
|
||||
|
||||
private val badgeTextPaint = Paint().apply {
|
||||
color = ContextCompat.getColor(context, R.color.badge_text)
|
||||
isAntiAlias = true
|
||||
@ -442,53 +428,6 @@ class LauncherIconView : View, KoinComponent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val badgeSize = drawRect.width() * 0.30f
|
||||
badgeRect.left = drawRect.right - badgeSize
|
||||
badgeRect.top = drawRect.bottom - badgeSize
|
||||
badgeRect.right = drawRect.right.toFloat()
|
||||
badgeRect.bottom = drawRect.bottom.toFloat()
|
||||
|
||||
val badge = badge ?: return
|
||||
val badgeNumber = badge.number
|
||||
val badgeProgress = badge.progress
|
||||
val badgeIcon = badge.icon ?: badge.iconRes?.let { ContextCompat.getDrawable(context, it) }
|
||||
|
||||
badgePaint.color = icon?.badgeColor ?: 0
|
||||
canvas.drawOval(badgeRect, badgeShadowPaint)
|
||||
canvas.drawOval(badgeRect, badgePaint)
|
||||
|
||||
badgeProgress?.let {
|
||||
canvas.drawArc(badgeRect, 270f, it * 360, true, badgeProgressPaint)
|
||||
}
|
||||
badgeIcon?.let {
|
||||
it.setBounds(
|
||||
(drawRect.right - badgeSize * 0.9f).toInt(),
|
||||
(drawRect.bottom - badgeSize * 0.9f).toInt(),
|
||||
(drawRect.right - badgeSize * 0.1f).toInt(),
|
||||
(drawRect.bottom - badgeSize * 0.1f).toInt()
|
||||
)
|
||||
it.setBounds(
|
||||
badgeRect.left.roundToInt(),
|
||||
badgeRect.top.roundToInt(),
|
||||
badgeRect.right.roundToInt(),
|
||||
badgeRect.bottom.roundToInt()
|
||||
)
|
||||
it.draw(canvas)
|
||||
return
|
||||
}
|
||||
badgeNumber?.takeIf { it in 1..99 }?.let {
|
||||
val text = it.toString()
|
||||
val textSize = (1f - 0.1f - text.length * 0.1f) * badgeSize
|
||||
badgeTextPaint.textSize = textSize
|
||||
badgeTextPaint.getTextBounds(text, 0, text.length, textBounds)
|
||||
canvas.drawText(
|
||||
it.toString(),
|
||||
badgeRect.centerX(),
|
||||
badgeRect.centerY() - textBounds.exactCenterY(),
|
||||
badgeTextPaint
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private var longClicked = false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user