From 45a82b3c2d2f13943167ccaa84f24852aed67072 Mon Sep 17 00:00:00 2001 From: Andreas Gebhardt Date: Fri, 5 Jan 2024 19:44:19 +0100 Subject: [PATCH] Changed Checkmark Widget Color on implicit check As proposed in #615, the background is now solid color on implicit check but has a stroked checkmark instead of a full one. --- .../activities/common/views/RingView.kt | 21 ++++++++++++++----- .../widgets/views/CheckmarkWidgetView.kt | 21 ++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/RingView.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/RingView.kt index 870097800..34cbc82dc 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/RingView.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/RingView.kt @@ -58,6 +58,7 @@ class RingView : View { private var em = 0f private var text: String? private var textSize: Float + private var isStrokedTextEnabled: Boolean = false private var enableFontAwesome = false private var internalDrawingCache: Bitmap? = null private var cacheCanvas: Canvas? = null @@ -131,6 +132,10 @@ class RingView : View { invalidate() } + fun setIsStrokedTextEnabled(isStroked: Boolean) { + this.isStrokedTextEnabled = isStroked + } + override fun onDraw(canvas: Canvas) { super.onDraw(canvas) val activeCanvas: Canvas? @@ -152,19 +157,25 @@ class RingView : View { pRing!!.xfermode = XFERMODE_CLEAR } else { pRing!!.color = - backgroundColor!! + backgroundColor!! } rect!!.inset(thickness, thickness) activeCanvas.drawArc(rect!!, 0f, 360f, true, pRing!!) pRing!!.xfermode = null pRing!!.color = color pRing!!.textSize = textSize + + if (isStrokedTextEnabled){ + pRing!!.style = Paint.Style.STROKE + pRing!!.strokeWidth = textSize / 15f + } + if (enableFontAwesome) pRing!!.typeface = getFontAwesome(context) activeCanvas.drawText( - text!!, - rect!!.centerX(), - rect!!.centerY() + 0.4f * em, - pRing!! + text!!, + rect!!.centerX(), + rect!!.centerY() + 0.4f * em, + pRing!! ) } if (activeCanvas !== canvas) canvas.drawBitmap(internalDrawingCache!!, 0f, 0f, null) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetView.kt b/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetView.kt index 6515542b0..3c343464f 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetView.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetView.kt @@ -68,13 +68,13 @@ class CheckmarkWidgetView : HabitWidgetView { val fgColor: Int setShadowAlpha(0x4f) when (entryState) { - YES_MANUAL, SKIP -> { + YES_MANUAL, SKIP, YES_AUTO -> { bgColor = activeColor fgColor = res.getColor(R.attr.contrast0) backgroundPaint!!.color = bgColor frame!!.setBackgroundDrawable(background) } - YES_AUTO, NO, UNKNOWN -> { + NO, UNKNOWN -> { bgColor = res.getColor(R.attr.cardBgColor) fgColor = res.getColor(R.attr.contrast60) } @@ -87,12 +87,23 @@ class CheckmarkWidgetView : HabitWidgetView { ring.setColor(fgColor) ring.setBackgroundColor(bgColor) ring.setText(text) + ring.setIsStrokedTextEnabled(strokedTextEnabled) label.text = name label.setTextColor(fgColor) requestLayout() postInvalidate() } + private val strokedTextEnabled: Boolean + get() = if (isNumerical) { + false + } else { + when (entryState) { + YES_AUTO -> true + else -> false + } + } + private val text: String get() = if (isNumerical) { (max(0, entryValue) / 1000.0).toShortString() @@ -135,14 +146,14 @@ class CheckmarkWidgetView : HabitWidgetView { } ring.setThickness(0.03f * width) super.onMeasure( - MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) + MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) ) } private fun init() { val appComponent: HabitsApplicationComponent = - (context.applicationContext as HabitsApplication).component + (context.applicationContext as HabitsApplication).component preferences = appComponent.preferences ring = findViewById(R.id.scoreRing) as RingView label = findViewById(R.id.label) as TextView