aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-12 14:58:47 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-12 18:55:28 +0200
commit80f5d8ea5cce52ba9050b373e9cc5f3897ac691a (patch)
tree6c32284e431471ef10b96f96cb1f314f32f7079e
parentApplication: use preferences from compat libs (diff)
downloadwireguard-android-80f5d8ea5cce52ba9050b373e9cc5f3897ac691a.tar.xz
wireguard-android-80f5d8ea5cce52ba9050b373e9cc5f3897ac691a.zip
Activity: make dark/night theme follow system on Q
-rw-r--r--app/src/main/java/com/wireguard/android/Application.java10
-rw-r--r--app/src/main/java/com/wireguard/android/activity/SettingsActivity.java6
-rw-r--r--app/src/main/java/com/wireguard/android/activity/ThemeChangeAwareActivity.java7
3 files changed, 17 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/Application.java b/app/src/main/java/com/wireguard/android/Application.java
index 7bc07d6..1ffaa25 100644
--- a/app/src/main/java/com/wireguard/android/Application.java
+++ b/app/src/main/java/com/wireguard/android/Application.java
@@ -115,9 +115,13 @@ public class Application extends android.app.Application {
toolsInstaller = new ToolsInstaller(getApplicationContext());
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
- AppCompatDelegate.setDefaultNightMode(
- sharedPreferences.getBoolean("dark_theme", false) ?
- AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ AppCompatDelegate.setDefaultNightMode(
+ sharedPreferences.getBoolean("dark_theme", false) ?
+ AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
+ } else {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
+ }
tunnelManager = new TunnelManager(new FileConfigStore(getApplicationContext()));
tunnelManager.onCreate();
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
index 475c579..89ba0c1 100644
--- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
@@ -6,6 +6,7 @@
package com.wireguard.android.activity;
import android.content.pm.PackageManager;
+import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
@@ -91,13 +92,16 @@ public class SettingsActivity extends ThemeChangeAwareActivity {
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
addPreferencesFromResource(R.xml.preferences);
+ final PreferenceScreen screen = getPreferenceScreen();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
+ screen.removePreference(getPreferenceManager().findPreference("dark_theme"));
+
final Preference wgQuickOnlyPrefs[] = {
getPreferenceManager().findPreference("tools_installer"),
getPreferenceManager().findPreference("restore_on_boot")
};
for (final Preference pref : wgQuickOnlyPrefs)
pref.setVisible(false);
- final PreferenceScreen screen = getPreferenceScreen();
Application.getBackendAsync().thenAccept(backend -> {
for (final Preference pref : wgQuickOnlyPrefs) {
if (backend instanceof WgQuickBackend)
diff --git a/app/src/main/java/com/wireguard/android/activity/ThemeChangeAwareActivity.java b/app/src/main/java/com/wireguard/android/activity/ThemeChangeAwareActivity.java
index 0309722..977f64e 100644
--- a/app/src/main/java/com/wireguard/android/activity/ThemeChangeAwareActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/ThemeChangeAwareActivity.java
@@ -7,6 +7,7 @@ package com.wireguard.android.activity;
import android.content.SharedPreferences;
import android.content.res.Resources;
+import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@@ -55,12 +56,14 @@ public abstract class ThemeChangeAwareActivity extends AppCompatActivity impleme
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Application.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
+ Application.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onDestroy() {
- Application.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
+ Application.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}