Skip to content
Permalink
Browse files
Merge pull request #11325 from t895/extra-dark
Android: Add black backgrounds toggle
  • Loading branch information
JosJuice committed Dec 10, 2022
2 parents 2b7b3c3 + fd7a84b commit 1fd8d47
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 24 deletions.
@@ -81,6 +81,8 @@ public enum BooleanSetting implements AbstractBooleanSetting

MAIN_SHOW_GAME_TITLES(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"ShowGameTitles", true),
MAIN_USE_BLACK_BACKGROUNDS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"UseBlackBackgrounds", false),
MAIN_JOYSTICK_REL_CENTER(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"JoystickRelCenter", true),
MAIN_PHONE_RUMBLE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
@@ -13,6 +13,7 @@
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.UserDataActivity;
import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.AbstractIntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.AbstractStringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.AdHocBooleanSetting;
@@ -414,6 +415,44 @@ public void setInt(Settings settings, int newValue)

sl.add(new SingleChoiceSetting(mContext, themeMode, R.string.change_theme_mode, 0,
R.array.themeModeEntries, R.array.themeModeValues));

AbstractBooleanSetting blackBackgrounds = new AbstractBooleanSetting()
{
@Override
public boolean isOverridden(Settings settings)
{
return BooleanSetting.MAIN_USE_BLACK_BACKGROUNDS.isOverridden(settings);
}

@Override
public boolean isRuntimeEditable()
{
return true;
}

@Override
public boolean delete(Settings settings)
{
ThemeHelper.deleteBackgroundSetting((AppCompatActivity) mView.getActivity());
return BooleanSetting.MAIN_USE_BLACK_BACKGROUNDS.delete(settings);
}

@Override
public boolean getBoolean(Settings settings)
{
return BooleanSetting.MAIN_USE_BLACK_BACKGROUNDS.getBoolean(settings);
}

@Override
public void setBoolean(Settings settings, boolean newValue)
{
BooleanSetting.MAIN_USE_BLACK_BACKGROUNDS.setBoolean(settings, newValue);
ThemeHelper.saveBackgroundSetting((AppCompatActivity) mView.getActivity(), newValue);
}
};

sl.add(new CheckBoxSetting(mContext, blackBackgrounds, R.string.use_black_backgrounds,
R.string.use_black_backgrounds_description));
}

private void addAudioSettings(ArrayList<SettingsItem> sl)
@@ -21,6 +21,7 @@
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;

import java.io.File;
@@ -79,24 +80,7 @@ private static void init(Context context)

areDirectoriesAvailable = true;

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (IntSetting.MAIN_INTERFACE_THEME.getIntGlobal() !=
preferences.getInt(ThemeHelper.CURRENT_THEME, ThemeHelper.DEFAULT))
{
preferences.edit()
.putInt(ThemeHelper.CURRENT_THEME, IntSetting.MAIN_INTERFACE_THEME.getIntGlobal())
.apply();
}

if (IntSetting.MAIN_INTERFACE_THEME_MODE.getIntGlobal() !=
preferences.getInt(ThemeHelper.CURRENT_THEME_MODE,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM))
{
preferences.edit()
.putInt(ThemeHelper.CURRENT_THEME_MODE,
IntSetting.MAIN_INTERFACE_THEME_MODE.getIntGlobal())
.apply();
}
checkThemeSettings(context);

if (wiimoteIniWritten)
{
@@ -418,6 +402,37 @@ public static boolean isWaitingForWriteAccess(Context context)
return preferLegacyUserDirectory(context) && !PermissionsHandler.hasWriteAccess(context);
}

private static void checkThemeSettings(Context context)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (IntSetting.MAIN_INTERFACE_THEME.getIntGlobal() !=
preferences.getInt(ThemeHelper.CURRENT_THEME, ThemeHelper.DEFAULT))
{
preferences.edit()
.putInt(ThemeHelper.CURRENT_THEME, IntSetting.MAIN_INTERFACE_THEME.getIntGlobal())
.apply();
}

if (IntSetting.MAIN_INTERFACE_THEME_MODE.getIntGlobal() !=
preferences.getInt(ThemeHelper.CURRENT_THEME_MODE,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM))
{
preferences.edit()
.putInt(ThemeHelper.CURRENT_THEME_MODE,
IntSetting.MAIN_INTERFACE_THEME_MODE.getIntGlobal())
.apply();
}

if (BooleanSetting.MAIN_USE_BLACK_BACKGROUNDS.getBooleanGlobal() !=
preferences.getBoolean(ThemeHelper.USE_BLACK_BACKGROUNDS, false))
{
preferences.edit()
.putBoolean(ThemeHelper.USE_BLACK_BACKGROUNDS,
BooleanSetting.MAIN_USE_BLACK_BACKGROUNDS.getBooleanGlobal())
.apply();
}
}

private static native void CreateUserDirectories();

private static native void SetSysDirectory(String path);
@@ -28,6 +28,7 @@
{
public static final String CURRENT_THEME = "current_theme";
public static final String CURRENT_THEME_MODE = "current_theme_mode";
public static final String USE_BLACK_BACKGROUNDS = "use_black_backgrounds";

public static final int DEFAULT = 0;
public static final int MONET = 1;
@@ -67,6 +68,11 @@ public static void setTheme(@NonNull AppCompatActivity activity)
break;
}

if (preferences.getBoolean(USE_BLACK_BACKGROUNDS, false))
{
activity.setTheme(R.style.ThemeOverlay_Dolphin_Dark);
}

// Since the top app bar matches the color of the status bar, devices below API 23 have to get a
// black status bar since their icons do not adapt based on background color
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
@@ -158,6 +164,24 @@ public static void deleteThemeModeKey(@NonNull AppCompatActivity activity)
setThemeMode(activity);
}

public static void saveBackgroundSetting(AppCompatActivity activity, boolean backgroundValue)
{
PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext())
.edit()
.putBoolean(USE_BLACK_BACKGROUNDS, backgroundValue)
.apply();
activity.recreate();
}

public static void deleteBackgroundSetting(AppCompatActivity activity)
{
PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext())
.edit()
.remove(USE_BLACK_BACKGROUNDS)
.apply();
activity.recreate();
}

public static void setCorrectTheme(AppCompatActivity activity)
{
int currentTheme = ((ThemeProvider) activity).getThemeId();
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ThemeOverlay.Dolphin.Dark" parent="">
<item name="colorSurface">@color/background_black</item>
<item name="android:colorBackground">@color/background_black</item>
</style>
</resources>
@@ -39,4 +39,6 @@
<color name="tv_card_unselected">#444444</color>

<color name="invalid_setting_overlay">#36ff0000</color>

<color name="background_black">#000000</color>
</resources>
@@ -197,6 +197,8 @@
<string name="show_titles_in_game_list_description">Show the title and creator below each game cover.</string>
<string name="change_theme">Change App Theme</string>
<string name="change_theme_mode">Change Theme Mode</string>
<string name="use_black_backgrounds">Use Black Backgrounds</string>
<string name="use_black_backgrounds_description">When using the dark theme, apply black backgrounds.</string>

<!-- Online Update Region Select Fragment -->
<string name="region_select_title">Please select a region</string>
@@ -39,12 +39,12 @@ bool IsSettingSaveable(const Config::Location& config_location)
// TODO: Kill the current Android controller mappings system
if (config_location.section == "Android")
{
static constexpr std::array<const char*, 13> android_setting_saveable = {
"ControlScale", "ControlOpacity", "EmulationOrientation",
"JoystickRelCenter", "LastPlatformTab", "MotionControls",
"PhoneRumble", "ShowInputOverlay", "IRMode",
"IRAlwaysRecenter", "ShowGameTitles", "InterfaceTheme",
"InterfaceThemeMode"};
static constexpr std::array<const char*, 14> android_setting_saveable = {
"ControlScale", "ControlOpacity", "EmulationOrientation",
"JoystickRelCenter", "LastPlatformTab", "MotionControls",
"PhoneRumble", "ShowInputOverlay", "IRMode",
"IRAlwaysRecenter", "ShowGameTitles", "InterfaceTheme",
"InterfaceThemeMode", "UseBlackBackgrounds"};

return std::any_of(
android_setting_saveable.cbegin(), android_setting_saveable.cend(),

0 comments on commit 1fd8d47

Please sign in to comment.