Skip to content

Commit

Permalink
Show date in DayDream (#3842)
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma authored Dec 30, 2024
1 parent 99c01bf commit 2baddfe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@
</intent-filter>
</activity>

<!-- DayDreamPreferencesActivity only calls PreferencesActivity, so don't keep it in history -->
<activity
android:name=".ui.preference.DayDreamPreferencesActivity"
android:exported="true" />
android:exported="true"
android:noHistory="true" />
<activity
android:name=".ui.AboutActivity"
android:label="@string/about_title"
Expand Down
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 2baddfe

Please sign in to comment.