mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Merge branch '2131-follow-system-theme' into 'master'
Change default theme to 'follow system' instead of 'light' Closes #2131 See merge request briar/briar!1824
This commit is contained in:
@@ -27,7 +27,7 @@ class BriarAccountManager extends AndroidAccountManager {
|
|||||||
super.deleteAccount();
|
super.deleteAccount();
|
||||||
Localizer.reinitialize();
|
Localizer.reinitialize();
|
||||||
UiUtils.setTheme(appContext,
|
UiUtils.setTheme(appContext,
|
||||||
appContext.getString(R.string.pref_theme_light_value));
|
appContext.getString(R.string.pref_theme_system_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import static java.util.logging.Level.FINE;
|
|||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||||
|
import static org.briarproject.briar.android.settings.DisplayFragment.PREF_THEME;
|
||||||
|
|
||||||
public class BriarApplicationImpl extends Application
|
public class BriarApplicationImpl extends Application
|
||||||
implements BriarApplication {
|
implements BriarApplication {
|
||||||
@@ -109,11 +110,11 @@ public class BriarApplicationImpl extends Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setTheme(Context ctx, SharedPreferences prefs) {
|
private void setTheme(Context ctx, SharedPreferences prefs) {
|
||||||
String theme = prefs.getString("pref_key_theme", null);
|
String theme = prefs.getString(PREF_THEME, null);
|
||||||
if (theme == null) {
|
if (theme == null) {
|
||||||
// set default value
|
// set default value
|
||||||
theme = getString(R.string.pref_theme_light_value);
|
theme = getString(R.string.pref_theme_system_value);
|
||||||
prefs.edit().putString("pref_key_theme", theme).apply();
|
prefs.edit().putString(PREF_THEME, theme).apply();
|
||||||
}
|
}
|
||||||
// set theme
|
// set theme
|
||||||
UiUtils.setTheme(ctx, theme);
|
UiUtils.setTheme(ctx, theme);
|
||||||
|
|||||||
@@ -10,12 +10,9 @@ import org.briarproject.briar.android.util.UiUtils;
|
|||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import androidx.core.text.TextUtilsCompat;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -24,10 +21,7 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
|
||||||
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
||||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.SIGN_OUT_URI;
|
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.SIGN_OUT_URI;
|
||||||
import static org.briarproject.briar.android.settings.SettingsActivity.EXTRA_THEME_CHANGE;
|
import static org.briarproject.briar.android.settings.SettingsActivity.EXTRA_THEME_CHANGE;
|
||||||
@@ -36,10 +30,7 @@ import static org.briarproject.briar.android.settings.SettingsActivity.EXTRA_THE
|
|||||||
public class DisplayFragment extends PreferenceFragmentCompat {
|
public class DisplayFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
public static final String PREF_LANGUAGE = "pref_key_language";
|
public static final String PREF_LANGUAGE = "pref_key_language";
|
||||||
private static final String PREF_THEME = "pref_key_theme";
|
public static final String PREF_THEME = "pref_key_theme";
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
getLogger(DisplayFragment.class.getName());
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle bundle, String s) {
|
public void onCreatePreferences(Bundle bundle, String s) {
|
||||||
@@ -50,7 +41,6 @@ public class DisplayFragment extends PreferenceFragmentCompat {
|
|||||||
language.setOnPreferenceChangeListener(this::onLanguageChanged);
|
language.setOnPreferenceChangeListener(this::onLanguageChanged);
|
||||||
|
|
||||||
ListPreference theme = requireNonNull(findPreference(PREF_THEME));
|
ListPreference theme = requireNonNull(findPreference(PREF_THEME));
|
||||||
setThemeEntries(theme);
|
|
||||||
theme.setOnPreferenceChangeListener(this::onThemeChanged);
|
theme.setOnPreferenceChangeListener(this::onThemeChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,30 +81,6 @@ public class DisplayFragment extends PreferenceFragmentCompat {
|
|||||||
language.setEntryValues(entryValues.toArray(new CharSequence[0]));
|
language.setEntryValues(entryValues.toArray(new CharSequence[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLeftToRight(Locale locale) {
|
|
||||||
// TextUtilsCompat returns the wrong direction for Hebrew on some phones
|
|
||||||
String language = locale.getLanguage();
|
|
||||||
if (language.equals("iw") || language.equals("he")) return false;
|
|
||||||
int direction = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
|
|
||||||
return direction == LAYOUT_DIRECTION_LTR;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setThemeEntries(ListPreference theme) {
|
|
||||||
if (SDK_INT < 27) {
|
|
||||||
// remove System Default Theme option from preference entries
|
|
||||||
// as it is not functional on this API anyway
|
|
||||||
List<CharSequence> entries =
|
|
||||||
new ArrayList<>(Arrays.asList(theme.getEntries()));
|
|
||||||
entries.remove(getString(R.string.pref_theme_system));
|
|
||||||
theme.setEntries(entries.toArray(new CharSequence[0]));
|
|
||||||
// also remove corresponding value
|
|
||||||
List<CharSequence> values =
|
|
||||||
new ArrayList<>(Arrays.asList(theme.getEntryValues()));
|
|
||||||
values.remove(getString(R.string.pref_theme_system_value));
|
|
||||||
theme.setEntryValues(values.toArray(new CharSequence[0]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean onThemeChanged(Preference preference, Object newValue) {
|
private boolean onThemeChanged(Preference preference, Object newValue) {
|
||||||
// activate new theme
|
// activate new theme
|
||||||
FragmentActivity activity = requireActivity();
|
FragmentActivity activity = requireActivity();
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
|
|||||||
import static android.view.inputmethod.EditorInfo.IME_NULL;
|
import static android.view.inputmethod.EditorInfo.IME_NULL;
|
||||||
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_TIME;
|
|
||||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||||
@@ -349,12 +348,7 @@ public class UiUtils {
|
|||||||
} else if (theme
|
} else if (theme
|
||||||
.equals(ctx.getString(R.string.pref_theme_dark_value))) {
|
.equals(ctx.getString(R.string.pref_theme_dark_value))) {
|
||||||
setDefaultNightMode(MODE_NIGHT_YES);
|
setDefaultNightMode(MODE_NIGHT_YES);
|
||||||
} else if (theme
|
} else {
|
||||||
.equals(ctx.getString(R.string.pref_theme_auto_value))) {
|
|
||||||
// TODO remove AUTO-setting as it is deprecated
|
|
||||||
setDefaultNightMode(MODE_NIGHT_AUTO_TIME);
|
|
||||||
} else if (theme
|
|
||||||
.equals(ctx.getString(R.string.pref_theme_system_value))) {
|
|
||||||
setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
|
setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,17 +63,14 @@
|
|||||||
<string-array name="pref_theme_entries">
|
<string-array name="pref_theme_entries">
|
||||||
<item>@string/pref_theme_light</item>
|
<item>@string/pref_theme_light</item>
|
||||||
<item>@string/pref_theme_dark</item>
|
<item>@string/pref_theme_dark</item>
|
||||||
<item>@string/pref_theme_auto</item>
|
|
||||||
<item>@string/pref_theme_system</item>
|
<item>@string/pref_theme_system</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string name="pref_theme_light_value" translatable="false">light</string>
|
<string name="pref_theme_light_value" translatable="false">light</string>
|
||||||
<string name="pref_theme_dark_value" translatable="false">dark</string>
|
<string name="pref_theme_dark_value" translatable="false">dark</string>
|
||||||
<string name="pref_theme_auto_value" translatable="false">auto</string>
|
|
||||||
<string name="pref_theme_system_value" translatable="false">system</string>
|
<string name="pref_theme_system_value" translatable="false">system</string>
|
||||||
<string-array name="pref_theme_values">
|
<string-array name="pref_theme_values">
|
||||||
<item>@string/pref_theme_light_value</item>
|
<item>@string/pref_theme_light_value</item>
|
||||||
<item>@string/pref_theme_dark_value</item>
|
<item>@string/pref_theme_dark_value</item>
|
||||||
<item>@string/pref_theme_auto_value</item>
|
|
||||||
<item>@string/pref_theme_system_value</item>
|
<item>@string/pref_theme_system_value</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|||||||
@@ -546,7 +546,6 @@
|
|||||||
<string name="pref_theme_title">Theme</string>
|
<string name="pref_theme_title">Theme</string>
|
||||||
<string name="pref_theme_light">Light</string>
|
<string name="pref_theme_light">Light</string>
|
||||||
<string name="pref_theme_dark">Dark</string>
|
<string name="pref_theme_dark">Dark</string>
|
||||||
<string name="pref_theme_auto">Automatic (Daytime)</string>
|
|
||||||
<string name="pref_theme_system">System default</string>
|
<string name="pref_theme_system">System default</string>
|
||||||
|
|
||||||
<!-- Settings Connections -->
|
<!-- Settings Connections -->
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
tools:summary="System default" />
|
tools:summary="System default" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="@string/pref_theme_light_value"
|
android:defaultValue="@string/pref_theme_system_value"
|
||||||
android:entries="@array/pref_theme_entries"
|
android:entries="@array/pref_theme_entries"
|
||||||
android:entryValues="@array/pref_theme_values"
|
android:entryValues="@array/pref_theme_values"
|
||||||
android:key="pref_key_theme"
|
android:key="pref_key_theme"
|
||||||
|
|||||||
Reference in New Issue
Block a user