[app] Allow using system accent color as theme color (S+) (#560)

* Compile with Android S SDK

* [app] Allow using system accent color as theme color (S+)
This commit is contained in:
tehcneko 2021-05-11 15:44:24 +08:00 committed by GitHub
parent 14b1fc555b
commit 7f539c8dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 95 additions and 12 deletions

View File

@ -29,7 +29,7 @@ plugins {
val androidTargetSdkVersion: Int by rootProject.extra
val androidMinSdkVersion: Int by rootProject.extra
val androidBuildToolsVersion: String by rootProject.extra
val androidCompileSdkVersion: Int by rootProject.extra
val androidCompileSdkVersion: String by rootProject.extra
val androidCompileNdkVersion: String by rootProject.extra
val androidSourceCompatibility: JavaVersion by rootProject.extra
val androidTargetCompatibility: JavaVersion by rootProject.extra
@ -43,7 +43,7 @@ val androidKeyAlias: String? by rootProject
val androidKeyPassword: String? by rootProject
android {
compileSdk = androidCompileSdkVersion
compileSdkPreview = androidCompileSdkVersion
ndkVersion = androidCompileNdkVersion
buildToolsVersion = androidBuildToolsVersion

View File

@ -298,6 +298,21 @@ public class SettingsActivity extends BaseActivity {
prefShowHiddenIcons.setOnPreferenceChangeListener((preference, newValue) -> Settings.Global.putInt(requireActivity().getContentResolver(),
"show_hidden_icon_apps_enabled", (boolean) newValue ? 1 : 0));
}
SwitchPreference prefFollowSystemAccent = findPreference("follow_system_accent");
if (prefFollowSystemAccent != null && (Build.VERSION.SDK_INT >= 31 || Build.VERSION.SDK_INT == 30 && Build.VERSION.PREVIEW_SDK_INT != 0)) {
if (primary_color != null) {
primary_color.setVisible(!prefFollowSystemAccent.isChecked());
}
prefFollowSystemAccent.setVisible(true);
prefFollowSystemAccent.setOnPreferenceChangeListener((preference, newValue) -> {
SettingsActivity activity = (SettingsActivity) getActivity();
if (activity != null) {
activity.restart();
}
return true;
});
}
}
@Override

View File

@ -21,6 +21,7 @@ package org.lsposed.manager.util.theme;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import androidx.annotation.ColorRes;
import androidx.annotation.StyleRes;
@ -73,6 +74,10 @@ public class ThemeUtil {
return preferences.getBoolean("black_dark_theme", false);
}
private static boolean isSystemAccent() {
return preferences.getBoolean("follow_system_accent", true);
}
public static String getNightTheme(Context context) {
if (isBlackNightTheme()
&& ResourceUtils.isNightMode(context.getResources().getConfiguration()))
@ -105,6 +110,9 @@ public class ThemeUtil {
@StyleRes
public static int getColorThemeStyleRes() {
if ((Build.VERSION.SDK_INT >= 31 || Build.VERSION.SDK_INT == 30 && Build.VERSION.PREVIEW_SDK_INT != 0) && isSystemAccent()) {
return R.style.ThemeOverlay_system;
}
Integer theme = colorThemeMap.get(getColorTheme());
if (theme == null) {
return R.style.ThemeOverlay_color_primary;

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ LSPosed is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
~
~ Copyright (C) 2021 LSPosed Contributors
-->
<resources>
<color name="system">@android:color/system_accent1_200</color>
</resources>

View File

@ -39,4 +39,5 @@
<color name="material_brown">@color/material_brown_200</color>
<color name="material_grey">@color/material_grey_200</color>
<color name="material_blue_grey">@color/material_blue_grey_200</color>
<color name="system">@color/material_blue</color>
</resources>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ This file is part of LSPosed.
~
~ LSPosed is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ LSPosed is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
~
~ Copyright (C) 2021 LSPosed Contributors
-->
<resources>
<color name="system">@android:color/system_accent1_500</color>
</resources>

View File

@ -39,4 +39,5 @@
<color name="material_brown">@color/material_brown_500</color>
<color name="material_grey">@color/material_grey_500</color>
<color name="material_blue_grey">@color/material_blue_grey_500</color>
<color name="system">@color/material_blue</color>
</resources>

View File

@ -152,6 +152,7 @@
<string name="dns_over_http_summary">Workaround DNS poisoning in some nations</string>
<string name="theme_color">Theme color</string>
<string name="theme_color_summary">Color that appears most frequently in the app</string>
<string name="theme_color_system_accent">System accent color</string>
<string name="settings_show_hidden_icon_apps_enabled">Forced display of the application launcher icon on Android 10+</string>
<string name="settings_group_system">System</string>

View File

@ -98,4 +98,8 @@
<style name="ThemeOverlay.material_blue_grey">
<item name="colorPrimary">@color/material_blue_grey</item>
</style>
<style name="ThemeOverlay.system">
<item name="colorPrimary">@color/system</item>
</style>
</resources>

View File

@ -31,6 +31,11 @@
</com.takisoft.preferencex.PreferenceCategory>
<com.takisoft.preferencex.PreferenceCategory android:title="@string/settings_group_theme">
<SwitchPreference
android:defaultValue="true"
android:key="follow_system_accent"
android:title="@string/theme_color_system_accent"
app:isPreferenceVisible="false" />
<org.lsposed.manager.util.theme.ThemeColorPreference
android:defaultValue=""
android:dialogTitle="@string/theme_color"
@ -82,14 +87,14 @@
</com.takisoft.preferencex.PreferenceCategory>
<com.takisoft.preferencex.PreferenceCategory
android:key="settings_group_system"
android:key="settings_group_system"
android:title="@string/settings_group_system"
app:isPreferenceVisible="false">
<SwitchPreference
android:defaultValue="true"
android:key="show_hidden_icon_apps_enabled"
android:title="@string/settings_show_hidden_icon_apps_enabled"
android:persistent="false"
app:isPreferenceVisible="false" />
<SwitchPreference
android:defaultValue="true"
android:key="show_hidden_icon_apps_enabled"
android:title="@string/settings_show_hidden_icon_apps_enabled"
android:persistent="false"
app:isPreferenceVisible="false" />
</com.takisoft.preferencex.PreferenceCategory>
</PreferenceScreen>

View File

@ -41,7 +41,7 @@ val verName by extra("v1.3.5")
val androidTargetSdkVersion by extra(30)
val androidMinSdkVersion by extra(27)
val androidBuildToolsVersion by extra("30.0.3")
val androidCompileSdkVersion by extra(30)
val androidCompileSdkVersion by extra("android-S")
val androidCompileNdkVersion by extra("22.1.7171670")
val androidSourceCompatibility by extra(JavaVersion.VERSION_11)
val androidTargetCompatibility by extra(JavaVersion.VERSION_11)

View File

@ -47,7 +47,7 @@ val apiCode: Int by rootProject.extra
val androidTargetSdkVersion: Int by rootProject.extra
val androidMinSdkVersion: Int by rootProject.extra
val androidBuildToolsVersion: String by rootProject.extra
val androidCompileSdkVersion: Int by rootProject.extra
val androidCompileSdkVersion: String by rootProject.extra
val androidCompileNdkVersion: String by rootProject.extra
val androidSourceCompatibility: JavaVersion by rootProject.extra
val androidTargetCompatibility: JavaVersion by rootProject.extra
@ -69,7 +69,7 @@ dependencies {
}
android {
compileSdk = androidCompileSdkVersion
compileSdkPreview = androidCompileSdkVersion
ndkVersion = androidCompileNdkVersion
buildToolsVersion = androidBuildToolsVersion