Add Dynamic colors option for Android 12 or above (#8)

* Dynamic color for android 12 or above @Ishan09811
This commit is contained in:
Ishan09811 2024-02-18 02:55:48 +05:30 committed by GitHub
parent b685cb8b13
commit 6ee1a39fb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 4 deletions

View file

@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import com.google.android.material.color.DynamicColors;
import com.google.android.material.color.DynamicColorsOptions;
import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
@ -30,6 +32,11 @@ public class PandroidApplication extends Application {
if (GlobalConfig.get(GlobalConfig.KEY_LOGGER_SERVICE)) {
startService(new Intent(this, LoggerService.class));
}
if (GlobalConfig.get(GlobalConfig.KEY_DYNAMIC_COLORS)) {
DynamicColorsOptions dynamicColorsOptions = new DynamicColorsOptions.Builder()
.build();
DynamicColors.applyToActivitiesIfAvailable(this, dynamicColorsOptions);
}
}
public static int getThemeId() {

View file

@ -3,6 +3,8 @@ package com.panda3ds.pandroid.app.preferences;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.preference.SwitchPreference;
import com.google.android.material.color.DynamicColors;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.BaseActivity;
@ -23,5 +25,23 @@ public class AppearancePreferences extends BasePreferenceFragment {
GlobalConfig.set(GlobalConfig.KEY_APP_THEME, (int) value);
return false;
});
setItemClick("dynamic_colors", pref -> GlobalConfig.set(GlobalConfig.KEY_DYNAMIC_COLORS, ((SwitchPreference) pref).isChecked()));
refresh();
}
@Override
public void onResume() {
super.onResume();
refresh();
}
private void refresh() {
((SwitchPreference) findPreference("dynamic_colors")).setChecked(GlobalConfig.get(GlobalConfig.KEY_DYNAMIC_COLORS));
if (!DynamicColors.isDynamicColorAvailable()) {
((SwitchPreference) findPreference("dynamic_colors")).setEnabled(false);
}
}
}
}

View file

@ -20,6 +20,7 @@ public class GlobalConfig {
public static final Key<Boolean> KEY_SHADER_JIT = new Key<>("emu.shader_jit", false);
public static final Key<Boolean> KEY_SHOW_PERFORMANCE_OVERLAY = new Key<>("dev.performanceOverlay", false);
public static final Key<Boolean> KEY_DYNAMIC_COLORS = new Key<>("app.dynamic_colors", false);
public static final Key<Boolean> KEY_LOGGER_SERVICE = new Key<>("dev.loggerService", false);
public static final Key<Integer> KEY_APP_THEME = new Key<>("app.theme", THEME_ANDROID);
public static final Key<Boolean> KEY_SCREEN_GAMEPAD_VISIBLE = new Key<>("app.screen_gamepad.visible", true);

View file

@ -34,6 +34,9 @@
<string name="light">Light</string>
<string name="dark">Dark</string>
<string name="black">Black</string>
<string name="colors">Colors</string>
<string name="pref_dynamic_colors_title">Use Dynamic Colors</string>
<string name="pref_dynamic_colors_summary">Dynamic colors will be used.</string>
<!-- Game Menu -->
<string name="actions">Actions</string>
<string name="exit">Exit</string>
@ -56,8 +59,8 @@
<string name="pref_performance_monitor_summary">Show overlay with fps, memory, etc.</string>
<string name="pref_logger_service_title">Logger</string>
<string name="pref_logger_service_summary">Store application logs to file.</string>
<string name="graphics">Graphics</string>
<string name="pref_shader_jit_title">Shader JIT</string>
<string name="pref_shader_jit_summary">Use shader recompiler.</string>
<string name="graphics">Graphics</string>
<string name="loading">Loading</string>
</resources>

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.panda3ds.pandroid.view.preferences.SingleSelectionPreferences
app:key="theme"
app:title="@string/theme"
@ -11,4 +13,16 @@
<Preference app:title="@string/black"/>
</com.panda3ds.pandroid.view.preferences.SingleSelectionPreferences>
</PreferenceScreen>
<PreferenceCategory
app:iconSpaceReserved="false"
app:title="@string/colors">
<SwitchPreference
android:key="dynamic_colors"
app:title="@string/pref_dynamic_colors_title"
app:summary="@string/pref_dynamic_colors_summary"
app:iconSpaceReserved="false"/>
</PreferenceCategory>
</PreferenceScreen>