Skip to content

Commit

Permalink
fix(widgets): use text sizes relative to screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Feb 25, 2024
1 parent 00de34a commit bf1e3d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dependencies {
implementation(libs.material)
implementation(libs.material.icons.extended)

implementation(libs.sdp.android)
implementation(libs.ui.viewbinding)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class VerticalClockWidget : AppWidgetProvider() {
)

val viewMapping = RemoteViews(context.packageName, R.layout.vertical_clock).apply {
setOnClickPendingIntent(R.id.container, pendingIntent)
}
setOnClickPendingIntent(R.id.container, pendingIntent)
}

val views = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
RemoteViews(viewMapping)
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/layout/digital_clock.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.Material3.DynamicColors.DayNight"
android:background="@drawable/widget_shape"
android:paddingHorizontal="30dp"
android:paddingVertical="10dp"
android:paddingHorizontal="@dimen/_10sdp"
android:paddingVertical="@dimen/_3sdp"
android:id="@+id/frameLayout"
android:gravity="center|center_vertical">

Expand All @@ -17,23 +15,26 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">

<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="EE, MMM dd"
android:format24Hour="EE, MMM dd"
android:textColor="@color/widgetSecondaryTextColor"
android:text="Today"
android:textSize="@dimen/_8sdp"
android:id="@+id/textClock" />

<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-8sp"
android:layout_marginTop="@dimen/_minus2sdp"
android:format12Hour="hh:mm"
android:format24Hour="kk:mm"
android:textColor="@color/widgetPrimaryTextColor"
android:textSize="55sp"
android:textSize="@dimen/_40sdp"
android:textStyle="bold"
android:text="12:34"
android:id="@+id/textClock2"
android:singleLine="true" />
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/res/layout/vertical_clock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
android:layout_height="match_parent"
android:theme="@style/Theme.Material3.DynamicColors.DayNight"
android:background="@drawable/widget_shape"
android:paddingHorizontal="30dp"
android:paddingVertical="10dp"
android:paddingHorizontal="@dimen/_10sdp"
android:paddingVertical="@dimen/_3sdp"
android:gravity="center|center_vertical">

<LinearLayout
Expand All @@ -21,18 +21,20 @@
android:format12Hour="EE, MMM dd"
android:format24Hour="EE, MMM dd"
android:text="Today"
android:textSize="@dimen/_8sdp"
android:textColor="@color/widgetSecondaryTextColor" />

<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-8sp"
android:layout_marginTop="@dimen/_minus2sdp"
android:layout_gravity="center"
android:format12Hour="hh"
android:format24Hour="kk"
android:text="12"
android:textStyle="bold"
android:textColor="@color/widgetPrimaryTextColor"
android:textSize="84sp" />
android:textSize="@dimen/_60sdp" />

<TextClock
android:layout_width="wrap_content"
Expand All @@ -42,8 +44,9 @@
android:format24Hour="mm"
android:text="34"
android:textColor="@color/widgetPrimaryTextColor"
android:textSize="84sp"
android:layout_marginTop="-40sp" />
android:textSize="@dimen/_60sdp"
android:textStyle="bold"
android:layout_marginTop="@dimen/_minus25sdp" />

</LinearLayout>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/xml/vertical_clock_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:description="@string/vertical_clock"
android:minWidth="180dp"
android:minHeight="120dp"
android:minWidth="120dp"
android:minHeight="70dp"
android:previewLayout="@layout/vertical_clock"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen"
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ material-icons-extended = "1.4.3"
room = "2.5.1"
androidx-appcompat = "1.6.1"
json = "1.5.1"
sdp-android = "1.0.5"

[libraries]
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
Expand All @@ -29,6 +30,7 @@ kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", v
lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" }
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
sdp-android = { module = "com.intuit.sdp:sdp-android", version.ref = "sdp-android" }
ui-viewbinding = { group = "androidx.compose.ui", name = "ui-viewbinding" }
ui = { group = "androidx.compose.ui", name = "ui" }
ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
Expand Down

0 comments on commit bf1e3d1

Please sign in to comment.