Make CheckmarkWidget resizable; remove fixed aspect ratio

This commit is contained in:
2021-05-23 11:49:49 -05:00
parent b33dd2a994
commit 88f8581acc
2 changed files with 3 additions and 10 deletions

View File

@@ -120,14 +120,7 @@ class CheckmarkWidgetView : HabitWidgetView {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val width = MeasureSpec.getSize(widthMeasureSpec)
val height = MeasureSpec.getSize(heightMeasureSpec)
var w = width.toFloat()
var h = width * 1.25f
val scale = min(width / w, height / h)
w *= scale
h *= scale
val newWidthMeasureSpec = MeasureSpec.makeMeasureSpec(w.toInt(), MeasureSpec.EXACTLY)
val newHeightMeasureSpec = MeasureSpec.makeMeasureSpec(h.toInt(), MeasureSpec.EXACTLY)
var textSize = 0.15f * h
var textSize = 0.15f * height
val maxTextSize = getDimension(context, R.dimen.smallerTextSize)
textSize = min(textSize, maxTextSize)
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
@@ -137,7 +130,7 @@ class CheckmarkWidgetView : HabitWidgetView {
ring.setTextSize(textSize)
}
ring.setThickness(0.15f * textSize)
super.onMeasure(newWidthMeasureSpec, newHeightMeasureSpec)
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
private fun init() {

View File

@@ -23,7 +23,7 @@
android:minWidth="40dp"
android:initialLayout="@layout/widget_wrapper"
android:previewImage="@drawable/widget_preview_checkmark"
android:resizeMode="none"
android:resizeMode="vertical|horizontal"
android:updatePeriodMillis="3600000"
android:configure="org.isoron.uhabits.widgets.activities.HabitPickerDialog"
android:widgetCategory="home_screen">