Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="dual" />

<application
android:name=".AWApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:roundIcon="@mipmap/aw_launcher_round"
Expand Down
16 changes: 16 additions & 0 deletions mobile/src/main/java/net/activitywatch/android/AWApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.activitywatch.android

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate

class AWApplication : Application() {
override fun onCreate() {
super.onCreate()
// Follow the OS dark/light setting from process start so that:
// - WebView correctly reports prefers-color-scheme: dark when system is dark
// - The initial chrome (applyWebUiChrome in MainActivity) matches the system
// Without this, Theme.AppCompat.Light keeps the Activity in light mode and
// WebView always sees prefers-color-scheme: light (aw-android#300).
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
4 changes: 4 additions & 0 deletions mobile/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Do not override default_text_color here. Native Auth/Sync/Onboarding
keep light chrome via applySafeWindowInsets(); a night white text
color would be unreadable on that background (aw-android#301 P1). -->

<!-- Widget theme colors (dark mode overrides) -->
<color name="widget_background">#2A2A2A</color>
<color name="widget_text_primary">#FFFFFF</color>
Expand Down
7 changes: 5 additions & 2 deletions mobile/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Base application theme. DayNight lets Android WebView see the correct
prefers-color-scheme value when the user chooses "System" in aw-webui.
The AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM call in AWApplication
ensures the mode is set before any Activity starts. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.activitywatch.android

import androidx.appcompat.app.AppCompatDelegate
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test
import java.io.File

class AWApplicationTest {
@Test
fun applicationClassExists() {
// AWApplication must exist; Application.onCreate sets MODE_NIGHT_FOLLOW_SYSTEM
// so that WebView reports the correct prefers-color-scheme from the very first
// frame (aw-android#300).
val clazz = AWApplication::class.java
val superClass = clazz.superclass
assertEquals("android.app.Application", superClass?.name)
}

@Test
fun modeNightFollowSystemConstantValue() {
// Sanity-check that the constant we rely on is stable across AppCompat versions.
assertEquals(-1, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
Comment thread
TimeToBuildBob marked this conversation as resolved.

@Test
fun nightColorsDoNotOverrideDefaultTextColor() {
// Native screens stay on light chrome. White night text would be
// unreadable there (Greptile P1 on aw-android#301).
val night = File("src/main/res/values-night/colors.xml").readText()
assertFalse(night.contains("name=\"default_text_color\""))
}
}
Loading