mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Make CheckmarkWidget resizable; remove fixed aspect ratio
This commit is contained in:
@@ -120,14 +120,7 @@ class CheckmarkWidgetView : HabitWidgetView {
|
|||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
val height = MeasureSpec.getSize(heightMeasureSpec)
|
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
var w = width.toFloat()
|
var textSize = 0.15f * height
|
||||||
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
|
|
||||||
val maxTextSize = getDimension(context, R.dimen.smallerTextSize)
|
val maxTextSize = getDimension(context, R.dimen.smallerTextSize)
|
||||||
textSize = min(textSize, maxTextSize)
|
textSize = min(textSize, maxTextSize)
|
||||||
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
||||||
@@ -137,7 +130,7 @@ class CheckmarkWidgetView : HabitWidgetView {
|
|||||||
ring.setTextSize(textSize)
|
ring.setTextSize(textSize)
|
||||||
}
|
}
|
||||||
ring.setThickness(0.15f * textSize)
|
ring.setThickness(0.15f * textSize)
|
||||||
super.onMeasure(newWidthMeasureSpec, newHeightMeasureSpec)
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun init() {
|
private fun init() {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
android:minWidth="40dp"
|
android:minWidth="40dp"
|
||||||
android:initialLayout="@layout/widget_wrapper"
|
android:initialLayout="@layout/widget_wrapper"
|
||||||
android:previewImage="@drawable/widget_preview_checkmark"
|
android:previewImage="@drawable/widget_preview_checkmark"
|
||||||
android:resizeMode="none"
|
android:resizeMode="vertical|horizontal"
|
||||||
android:updatePeriodMillis="3600000"
|
android:updatePeriodMillis="3600000"
|
||||||
android:configure="org.isoron.uhabits.widgets.activities.HabitPickerDialog"
|
android:configure="org.isoron.uhabits.widgets.activities.HabitPickerDialog"
|
||||||
android:widgetCategory="home_screen">
|
android:widgetCategory="home_screen">
|
||||||
|
|||||||
Reference in New Issue
Block a user