mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 13:55:38 +00:00
Android: Add dark theme
This commit is contained in:
parent
59b9e4b2ef
commit
cbcb8b4b89
|
@ -9,6 +9,7 @@ import android.content.pm.PackageManager;
|
|||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
|
@ -22,6 +23,7 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
@ -40,6 +42,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
private static final int REQUEST_ADD_DIRECTORY_TO_GAME_LIST = 2;
|
||||
private static final int REQUEST_IMPORT_BIOS_IMAGE = 3;
|
||||
private static final int REQUEST_START_FILE = 4;
|
||||
private static final int REQUEST_SETTINGS = 5;
|
||||
|
||||
private GameList mGameList;
|
||||
private ListView mGameListView;
|
||||
|
@ -64,6 +67,26 @@ public class MainActivity extends AppCompatActivity {
|
|||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
}
|
||||
|
||||
private void setTheme() {
|
||||
String theme = PreferenceManager.getDefaultSharedPreferences(this).getString("Main/Theme", "follow_system");
|
||||
if (theme == null)
|
||||
return;
|
||||
|
||||
if (theme.equals("follow_system")) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
} else if (theme.equals("light")) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
} else if (theme.equals("dark")) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
setLanguage();
|
||||
setTheme();
|
||||
}
|
||||
|
||||
private boolean shouldResumeStateByDefault() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
return prefs.getBoolean("Main/SaveStateOnExit", true);
|
||||
|
@ -81,7 +104,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setLanguage();
|
||||
loadSettings();
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
|
@ -193,7 +216,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
importBIOSImage();
|
||||
} else if (id == R.id.action_settings) {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
startActivityForResult(intent, REQUEST_SETTINGS);
|
||||
return true;
|
||||
} else if (id == R.id.action_show_version) {
|
||||
showVersion();
|
||||
|
@ -287,6 +310,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
startEmulation(path, shouldResumeStateByDefault());
|
||||
}
|
||||
break;
|
||||
|
||||
case REQUEST_SETTINGS: {
|
||||
loadSettings();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
8
android/app/src/main/res/values-night/colors.xml
Normal file
8
android/app/src/main/res/values-night/colors.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#000000</color>
|
||||
<color name="colorPrimaryDark">#000000</color>
|
||||
<color name="colorAccent">#03A9F4</color>
|
||||
|
||||
<color name="black_overlay">#66000000</color>
|
||||
</resources>
|
|
@ -440,4 +440,14 @@
|
|||
<item>it-IT</item>
|
||||
<item>nl-NL</item>
|
||||
</string-array>
|
||||
<string-array name="settings_theme_entries">
|
||||
<item>Follow System</item>
|
||||
<item>Light</item>
|
||||
<item>Dark</item>
|
||||
</string-array>
|
||||
<string-array name="settings_theme_values">
|
||||
<item>follow_system</item>
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#008577</color>
|
||||
<color name="colorPrimaryDark">#00574B</color>
|
||||
<color name="colorPrimary">#6200EE</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorAccent">#D81B60</color>
|
||||
|
||||
<color name="black_overlay">#66000000</color>
|
||||
|
|
|
@ -159,4 +159,5 @@
|
|||
<string name="touchscreen_controller_stop_editing">Stop Editing</string>
|
||||
<string name="touchscreen_controller_reset_layout">Reset Layout</string>
|
||||
<string name="emulation_activity_touchscreen_controller_not_active">Touchscreen controller is not active.</string>
|
||||
<string name="settings_theme">Theme</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/design_default_color_primary</item>
|
||||
<item name="colorPrimaryDark">@color/design_default_color_primary_dark</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
|||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.DayNight" />
|
||||
|
||||
<style name="FullscreenTheme" parent="AppTheme">
|
||||
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
|
||||
|
|
|
@ -44,6 +44,14 @@
|
|||
app:defaultValue="false"
|
||||
app:summary="@string/settings_summary_pause_when_menu_opened"
|
||||
app:iconSpaceReserved="false" />
|
||||
<ListPreference
|
||||
app:key="Main/Theme"
|
||||
app:title="@string/settings_theme"
|
||||
app:entries="@array/settings_theme_entries"
|
||||
app:entryValues="@array/settings_theme_values"
|
||||
app:defaultValue="follow_system"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
<ListPreference
|
||||
app:key="Main/EmulationScreenOrientation"
|
||||
app:title="@string/settings_emulation_screen_orientation"
|
||||
|
|
Loading…
Reference in a new issue