Skip to content

Commit

Permalink
Show date in DayDream
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Dec 27, 2024
1 parent d743b07 commit cd206af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mobile/src/main/java/org/openhab/habdroid/ui/DayDream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import android.graphics.Rect
import android.os.Handler
import android.os.Looper
import android.service.dreams.DreamService
import android.text.format.DateFormat
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextClock
import android.widget.TextView
import java.util.Locale
import kotlin.coroutines.CoroutineContext
import kotlin.random.Random
import kotlin.time.Duration.Companion.minutes
Expand Down Expand Up @@ -65,12 +68,20 @@ class DayDream : DreamService(), CoroutineScope {
textView = findViewById(R.id.text)
wrapper = findViewById(R.id.wrapper)
container = findViewById(R.id.container)
setupDateView()

launch {
item?.let { listenForTextItem(it) }
}
}

private fun setupDateView() {
val dateView: TextClock = findViewById(R.id.date)
val pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "EEEE, MMMM d, yyyy")
dateView.format12Hour = pattern
dateView.format24Hour = pattern
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
moveTextIfRequired()
Expand Down
14 changes: 14 additions & 0 deletions mobile/src/main/res/layout/daydream.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="sans-serif-light"
android:textAppearance="@style/TextAppearance.Material3.DisplayLarge" />

<TextClock
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:fontFamily="sans-serif-light"
android:textAppearance="@style/TextAppearance.Material3.DisplaySmall"
tools:format12Hour="EEEE, MMMM d, yyyy"
tools:format24Hour="EEEE, MMMM d, yyyy" />

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="64dp"
android:fontFamily="sans-serif-light"
android:textAppearance="@style/TextAppearance.Material3.DisplayMedium"
tools:text="Temperature: 19 °C" />
</LinearLayout>
Expand Down

0 comments on commit cd206af

Please sign in to comment.