Added: Add support for shared day/night theming across termux apps

With this commit, activities will automatically change theme between day/night if `night-mode` `termux.properties` is not set or is set to `system` without requiring app restart.

Dialog theming will be fully added in a later commit and may currently be in an inconsistent state or have crashes.

The `uiMode` has been removed from `configChanges` of `TermuxActivity`, this may cause termux app to restart if samsung DEX mode is changed, if it does, then users should report it so that it can be fixed by re-adding the value and ignoring the change inside `TermuxActivity.onConfigurationChanged()`. The docs don't state if its necessary. Check related pull request #1446.

Running `termux-reload-settings` will also restart `TermuxActivity`, the activity data should be preserved.
This commit is contained in:
agnostic-apollo
2022-01-23 00:18:33 +05:00
parent f3f434af92
commit 6631599fb6
30 changed files with 586 additions and 140 deletions

View File

@@ -1,6 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.MaterialComponents.DayNight.TermuxPrimaryActivity" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!--
The light themes are only for day mode and must not be defined in night/theme.xml.
https://material.io/develop/android/theming/dark
-->
<!--
BaseActivity Light DarkActionBar theme.
https://github.com/material-components/material-components-android/blob/1.4.0/lib/java/com/google/android/material/theme/res/values/themes.xml#L33
-->
<style name="Theme.BaseActivity.Light.DarkActionBar" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/red_400</item>
<item name="colorPrimaryVariant">@color/red_800</item>
@@ -13,30 +22,81 @@
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="colorPrimaryDark" tools:targetApi="l">?attr/colorPrimary</item>
<!-- Text color. -->
<item name="android:textColorPrimary">@color/black</item>
<item name="android:textColorLink">@color/grey_800</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="android:textColorLink">@color/blue_link_light</item>
<!--
Dialog Themes.
These MUST be defined for the application `android:theme` so that if dialogs
are shown from non-activity context with TYPE_SYSTEM_ALERT, the correct dialog theme is
applied, otherwise exceptions like `UnsupportedOperationException: Failed to resolve attribute
at index... TypedValue` will be thrown, since ThemeOverlay would have all the activity
theme attributes defined.
-->
<item name="alertDialogTheme">@style/ThemeOverlay.BaseDialog.DayNight</item>
<item name="materialAlertDialogTheme">@style/ThemeOverlay.BaseDialog.DayNight</item>
</style>
<style name="Theme.AppCompat.TermuxReportActivity" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#FF0000</item>
<!-- BaseActivity Light NoActionBar theme. -->
<style name="Theme.BaseActivity.Light.NoActionBar" parent="Theme.BaseActivity.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.AppCompat.TermuxTextIOActivity" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#FF0000</item>
<!-- BaseActivity DayNight DarkActionBar theme. -->
<style name="Theme.BaseActivity.DayNight.DarkActionBar" parent="Theme.BaseActivity.Light.DarkActionBar"/>
<!-- BaseActivity DayNight NoActionBar theme. -->
<style name="Theme.BaseActivity.DayNight.NoActionBar" parent="Theme.BaseActivity.Light.NoActionBar"/>
<!-- BaseActivity extended classes Day NoActionBar themes. -->
<style name="Theme.MediaViewActivity.Light" parent="Theme.BaseActivity.Light.NoActionBar"/>
<style name="Theme.MarkdownViewActivity.Light" parent="Theme.MediaViewActivity.Light"/>
<!-- BaseActivity extended classes DayNight NoActionBar themes. -->
<style name="Theme.MediaViewActivity.DayNight" parent="Theme.BaseActivity.DayNight.NoActionBar"/>
<style name="Theme.MarkdownViewActivity.DayNight" parent="Theme.MediaViewActivity.DayNight"/>
<!--
BaseDialog Light theme.
https://github.com/material-components/material-components-android/blob/1.4.0/lib/java/com/google/android/material/dialog/res/values/themes.xml#L70
-->
<style name="ThemeOverlay.BaseDialog.Light" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/red_400</item>
<item name="colorPrimaryVariant">@color/red_800</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/grey_900</item>
<item name="colorSecondaryVariant">@color/black</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Surface color. -->
<item name="colorSurface">@color/design_default_color_surface</item>
<item name="colorOnSurface">@color/design_default_color_on_surface</item>
<!-- Dialog title panel style. -->
<item name="materialAlertDialogTitlePanelStyle">@style/BaseDialog.Title.Panel</item>
<!-- Dialog message text style. -->
<item name="materialAlertDialogBodyTextStyle">@style/BaseDialog.Message.Text.Light</item>
</style>
<style name="Toolbar.Title" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">14sp</item>
</style>
<!-- BaseDialog DayNight theme. -->
<style name="ThemeOverlay.BaseDialog.DayNight" parent="ThemeOverlay.BaseDialog.Light"/>
<!-- BaseDialog extended classes DayNight themes. -->
<style name="ThemeOverlay.MessageDialog.DayNight" parent="ThemeOverlay.BaseDialog.DayNight"/>
<style name="ViewDivider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:layout_marginTop">@dimen/activity_vertical_margin</item>
<item name="android:layout_marginBottom">@dimen/activity_vertical_margin</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
</resources>