Skip to content

Commit

Permalink
play-services-core: Use M3 theme on Android 12+ devices
Browse files Browse the repository at this point in the history
* Also use primary and accent color from system

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
Change-Id: Id0d2f0b4d990c99b9a930198e747cb78caa1c86c
  • Loading branch information
theimpulson committed Dec 7, 2023
1 parent 81d31f7 commit 72bb0f5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
Expand Up @@ -27,7 +27,7 @@
android:paddingStart="56dp"
android:paddingLeft="56dp"
android:textAppearance="?attr/textAppearanceListItem"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textColor="@android:color/white"
tools:text="Enabled" />

<androidx.appcompat.widget.SwitchCompat
Expand All @@ -36,7 +36,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@null"
app:thumbTint="?android:attr/textColorPrimaryInverse"
app:trackTint="?android:attr/textColorSecondaryInverse"
app:thumbTint="@android:color/white"
app:trackTint="@android:color/darker_gray"
tools:checked="true" />
</LinearLayout>
</LinearLayout>
3 changes: 3 additions & 0 deletions play-services-core/build.gradle
Expand Up @@ -75,6 +75,9 @@ dependencies {
implementation "androidx.preference:preference-ktx:$preferenceVersion"
implementation "androidx.webkit:webkit:$webkitVersion"

// Material Components
implementation 'com.google.android.material:material:1.9.0'

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
Expand Down
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_checked="true" />
<item android:color="@android:color/darker_gray"/>
</selector>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Derived from https://github.com/androidx/androidx/blob/8cb282cc/preference/preference/res/layout/preference_widget_switch_compat.xml -->
<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:focusable="false"
app:thumbTint="@color/preference_material_switch_color" />
13 changes: 13 additions & 0 deletions play-services-core/src/main/res/values-night-v31/themes.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.App" parent="Theme.Base.M3">
<item name="colorPrimary">@android:color/system_accent1_200</item>
<item name="colorAccent">@android:color/system_accent1_200</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar">false</item>
<item name="android:statusBarColor">?android:colorBackground</item>
<item name="android:navigationBarColor">?android:colorBackground</item>
</style>

</resources>
13 changes: 13 additions & 0 deletions play-services-core/src/main/res/values-v31/themes.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.App" parent="Theme.Base.M3">
<item name="colorPrimary">@android:color/system_accent1_500</item>
<item name="colorAccent">@android:color/system_accent1_500</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:statusBarColor">?android:colorBackground</item>
<item name="android:navigationBarColor">?android:colorBackground</item>
</style>

</resources>
15 changes: 14 additions & 1 deletion play-services-core/src/main/res/values/themes.xml
Expand Up @@ -19,7 +19,11 @@
<!-- Base application theme -->
<style name="Theme.Base" parent="Theme.AppCompat.DayNight.NoActionBar" />

<!-- Application theme (overrideable per API levels as required) -->
<style name="Theme.Base.M3" parent="Theme.Material3.DayNight.NoActionBar">
<item name="preferenceTheme">@style/Theme.PreferenceThemeOverlay.M3</item>
</style>

<!-- Application theme (< API23) -->
<style name="Theme.App" parent="Theme.Base" />

<style name="Theme.LoginBlue" parent="Theme.LoginBlue.Base" />
Expand All @@ -29,4 +33,13 @@
<item name="colorPrimaryDark">@color/login_blue_theme_primary_dark</item>
<item name="colorAccent">@color/login_blue_theme_accent</item>
</style>

<!-- Preference theme -->
<style name="Theme.PreferenceThemeOverlay.M3" parent="@style/PreferenceThemeOverlay">
<item name="switchPreferenceCompatStyle">@style/Theme.SwitchPreference.M3</item>
</style>

<style name="Theme.SwitchPreference.M3" parent="@style/Preference.SwitchPreferenceCompat.Material">
<item name="widgetLayout">@layout/preference_material_switch</item>
</style>
</resources>

0 comments on commit 72bb0f5

Please sign in to comment.