Skip to content

Commit

Permalink
Small tweaks to CheckmarkWidget padding and aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Aug 21, 2021
1 parent edeabb6 commit 2a5725f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.isoron.uhabits.utils.PaletteUtils.getAndroidTestColor
import org.isoron.uhabits.utils.StyledResources
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt

class CheckmarkWidgetView : HabitWidgetView {
var activeColor: Int = 0
Expand Down Expand Up @@ -118,19 +119,25 @@ class CheckmarkWidgetView : HabitWidgetView {
get() = R.layout.widget_checkmark

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val width = MeasureSpec.getSize(widthMeasureSpec)
val height = MeasureSpec.getSize(heightMeasureSpec)
var textSize = 0.15f * height
val maxTextSize = getDimension(context, R.dimen.smallerTextSize)
textSize = min(textSize, maxTextSize)
var width = MeasureSpec.getSize(widthMeasureSpec)
var height = MeasureSpec.getSize(heightMeasureSpec)
if (height >= width) {
height = min(height, (width * 1.5).roundToInt())
} else {
width = min(width, height)
}
val textSize = min(0.2f * width, getDimension(context, R.dimen.smallerTextSize))
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
if (isNumerical) {
ring.setTextSize(textSize * 0.75f)
ring.setTextSize(textSize * 0.9f)
} else {
ring.setTextSize(textSize)
}
ring.setThickness(0.15f * textSize)
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
ring.setThickness(0.03f * width)
super.onMeasure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
)
}

private fun init() {
Expand Down
8 changes: 4 additions & 4 deletions uhabits-android/src/main/res/layout/widget_checkmark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
android:id="@+id/scoreRing"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_weight="0.9"
habit:thickness="2"
habit:textSize="16"
habit:enableFontAwesome="true"
android:layout_marginTop="8dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"/>
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"/>

<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_weight="0.1"
android:textSize="12sp"
android:textColor="@color/white"
android:layout_marginLeft="6dp"
Expand Down

0 comments on commit 2a5725f

Please sign in to comment.