Make CheckmarkWidget resizable; remove fixed aspect ratio

pull/933/head
Alinson S. Xavier 4 years ago
parent b33dd2a994
commit 88f8581acc
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -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() {

@ -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">

Loading…
Cancel
Save