Activity: make dark/night theme follow system on Q
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
4a1d07b364
commit
96b44c1771
@ -115,9 +115,13 @@ public class Application extends android.app.Application {
|
|||||||
toolsInstaller = new ToolsInstaller(getApplicationContext());
|
toolsInstaller = new ToolsInstaller(getApplicationContext());
|
||||||
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
AppCompatDelegate.setDefaultNightMode(
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
sharedPreferences.getBoolean("dark_theme", false) ?
|
AppCompatDelegate.setDefaultNightMode(
|
||||||
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
|
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 = new TunnelManager(new FileConfigStore(getApplicationContext()));
|
||||||
tunnelManager.onCreate();
|
tunnelManager.onCreate();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package com.wireguard.android.activity;
|
package com.wireguard.android.activity;
|
||||||
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
@ -91,13 +92,16 @@ public class SettingsActivity extends ThemeChangeAwareActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
|
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
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[] = {
|
final Preference wgQuickOnlyPrefs[] = {
|
||||||
getPreferenceManager().findPreference("tools_installer"),
|
getPreferenceManager().findPreference("tools_installer"),
|
||||||
getPreferenceManager().findPreference("restore_on_boot")
|
getPreferenceManager().findPreference("restore_on_boot")
|
||||||
};
|
};
|
||||||
for (final Preference pref : wgQuickOnlyPrefs)
|
for (final Preference pref : wgQuickOnlyPrefs)
|
||||||
pref.setVisible(false);
|
pref.setVisible(false);
|
||||||
final PreferenceScreen screen = getPreferenceScreen();
|
|
||||||
Application.getBackendAsync().thenAccept(backend -> {
|
Application.getBackendAsync().thenAccept(backend -> {
|
||||||
for (final Preference pref : wgQuickOnlyPrefs) {
|
for (final Preference pref : wgQuickOnlyPrefs) {
|
||||||
if (backend instanceof WgQuickBackend)
|
if (backend instanceof WgQuickBackend)
|
||||||
|
@ -7,6 +7,7 @@ package com.wireguard.android.activity;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -55,12 +56,14 @@ public abstract class ThemeChangeAwareActivity extends AppCompatActivity impleme
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Application.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||||
|
Application.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
Application.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||||
|
Application.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user