Added auto theme selection for Android 10 devices
This commit is contained in:
parent
4f76f6a01d
commit
b37ab71e95
6 changed files with 74 additions and 12 deletions
|
@ -387,7 +387,8 @@ public class MainActivity extends BaseActivity
|
||||||
key.equals(getString(R.string.settings_key_enable_screenshot)) ||
|
key.equals(getString(R.string.settings_key_enable_screenshot)) ||
|
||||||
key.equals(getString(R.string.settings_key_tag_functionality)) ||
|
key.equals(getString(R.string.settings_key_tag_functionality)) ||
|
||||||
key.equals(getString(R.string.settings_key_label_highlight_token)) ||
|
key.equals(getString(R.string.settings_key_label_highlight_token)) ||
|
||||||
key.equals(getString(R.string.settings_key_card_layout))) {
|
key.equals(getString(R.string.settings_key_card_layout)) ||
|
||||||
|
key.equals(getString(R.string.settings_key_theme_mode))) {
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
|
@ -123,7 +124,8 @@ public class SettingsActivity extends BaseActivity
|
||||||
|
|
||||||
if (key.equals(getString(R.string.settings_key_theme)) ||
|
if (key.equals(getString(R.string.settings_key_theme)) ||
|
||||||
key.equals(getString(R.string.settings_key_locale)) ||
|
key.equals(getString(R.string.settings_key_locale)) ||
|
||||||
key.equals(getString(R.string.settings_key_special_features))) {
|
key.equals(getString(R.string.settings_key_special_features)) ||
|
||||||
|
key.equals(getString(R.string.settings_key_theme_mode))) {
|
||||||
recreate();
|
recreate();
|
||||||
} else if(key.equals(getString(R.string.settings_key_encryption))) {
|
} else if(key.equals(getString(R.string.settings_key_encryption))) {
|
||||||
if (settings.getEncryption() != EncryptionType.PASSWORD) {
|
if (settings.getEncryption() != EncryptionType.PASSWORD) {
|
||||||
|
@ -240,6 +242,7 @@ public class SettingsActivity extends BaseActivity
|
||||||
|
|
||||||
public static class SettingsFragment extends PreferenceFragment {
|
public static class SettingsFragment extends PreferenceFragment {
|
||||||
PreferenceCategory catSecurity;
|
PreferenceCategory catSecurity;
|
||||||
|
PreferenceCategory catUI;
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
ListPreference encryption;
|
ListPreference encryption;
|
||||||
|
@ -249,6 +252,8 @@ public class SettingsActivity extends BaseActivity
|
||||||
OpenPgpAppPreference pgpProvider;
|
OpenPgpAppPreference pgpProvider;
|
||||||
EditTextPreference pgpEncryptionKey;
|
EditTextPreference pgpEncryptionKey;
|
||||||
OpenPgpKeyPreference pgpSigningKey;
|
OpenPgpKeyPreference pgpSigningKey;
|
||||||
|
ListPreference themeMode;
|
||||||
|
ListPreference theme;
|
||||||
|
|
||||||
public void encryptionChangeWithDialog(final EncryptionType encryptionType) {
|
public void encryptionChangeWithDialog(final EncryptionType encryptionType) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
@ -292,7 +297,10 @@ public class SettingsActivity extends BaseActivity
|
||||||
|
|
||||||
// Authentication
|
// Authentication
|
||||||
catSecurity = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_security));
|
catSecurity = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_security));
|
||||||
|
catUI = (PreferenceCategory) findPreference(getString(R.string.settings_key_cat_ui));
|
||||||
encryption = (ListPreference) findPreference(getString(R.string.settings_key_encryption));
|
encryption = (ListPreference) findPreference(getString(R.string.settings_key_encryption));
|
||||||
|
themeMode = (ListPreference) findPreference(getString(R.string.settings_key_theme_mode));
|
||||||
|
theme = (ListPreference) findPreference(getString(R.string.settings_key_theme));
|
||||||
|
|
||||||
encryption.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
encryption.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -395,11 +403,21 @@ public class SettingsActivity extends BaseActivity
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//Remove Theme Mode selection option for devices below Android 10. Disable theme selection if Theme Mode is set auto
|
||||||
|
//TODO: 29 needs to be replaced with VERSION_CODE.Q when compileSdk and targetSdk is updated to 29
|
||||||
|
if(Build.VERSION.SDK_INT < 29) {
|
||||||
|
catUI.removePreference(themeMode);
|
||||||
|
} else {
|
||||||
|
if(sharedPref.getString(getString(R.string.settings_key_theme_mode),getString(R.string.settings_default_theme_mode)).equals("auto")) {
|
||||||
|
theme.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
theme.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ package org.shadowice.flocke.andotp.Utilities;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
|
@ -332,9 +334,26 @@ public class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTheme() {
|
public int getTheme() {
|
||||||
String themeName = getString(R.string.settings_key_theme, R.string.settings_default_theme);
|
|
||||||
|
|
||||||
int theme = R.style.AppTheme_NoActionBar;
|
int theme = R.style.AppTheme_NoActionBar;
|
||||||
|
String themeMode = getString(R.string.settings_key_theme_mode, R.string.settings_default_theme_mode);
|
||||||
|
|
||||||
|
//TODO: 29 needs to be replaced with VERSION_CODE.Q when compileSdk and targetSdk is updated to 29
|
||||||
|
if(Build.VERSION.SDK_INT >= 29 && themeMode.equals("auto")){
|
||||||
|
switch (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
|
||||||
|
//Dark Mode
|
||||||
|
case Configuration.UI_MODE_NIGHT_YES:
|
||||||
|
theme = R.style.AppTheme_Dark_NoActionBar;
|
||||||
|
break;
|
||||||
|
//Light Mode / Undefined mode / Default mode
|
||||||
|
case Configuration.UI_MODE_NIGHT_NO:
|
||||||
|
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||||
|
default:
|
||||||
|
theme = R.style.AppTheme_NoActionBar;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
String themeName = getString(R.string.settings_key_theme, R.string.settings_default_theme);
|
||||||
|
|
||||||
if (themeName.equals("light")) {
|
if (themeName.equals("light")) {
|
||||||
theme = R.style.AppTheme_NoActionBar;
|
theme = R.style.AppTheme_NoActionBar;
|
||||||
|
@ -343,6 +362,7 @@ public class Settings {
|
||||||
} else if (themeName.equals("black")) {
|
} else if (themeName.equals("black")) {
|
||||||
theme = R.style.AppTheme_Black_NoActionBar;
|
theme = R.style.AppTheme_Black_NoActionBar;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
<string name="settings_key_panic" translatable="false">pref_panic</string>
|
<string name="settings_key_panic" translatable="false">pref_panic</string>
|
||||||
<string name="settings_key_relock_screen_off" translatable="false">pref_relock_screen_off</string>
|
<string name="settings_key_relock_screen_off" translatable="false">pref_relock_screen_off</string>
|
||||||
|
|
||||||
|
<string name="settings_key_cat_ui" translatable="false">perf_cat_ui</string>
|
||||||
<string name="settings_key_lang" translatable="false">pref_lang</string> <!-- Deprecated -->
|
<string name="settings_key_lang" translatable="false">pref_lang</string> <!-- Deprecated -->
|
||||||
<string name="settings_key_locale" translatable="false">pref_locale</string>
|
<string name="settings_key_locale" translatable="false">pref_locale</string>
|
||||||
|
<string name="settings_key_theme_mode" translatable="false">perf_theme_mode</string>
|
||||||
<string name="settings_key_theme" translatable="false">pref_theme</string>
|
<string name="settings_key_theme" translatable="false">pref_theme</string>
|
||||||
<string name="settings_key_label_size" translatable="false">pref_label_size_sp</string>
|
<string name="settings_key_label_size" translatable="false">pref_label_size_sp</string>
|
||||||
<string name="settings_key_card_layout" translatable="false">pref_card_layout</string>
|
<string name="settings_key_card_layout" translatable="false">pref_card_layout</string>
|
||||||
|
@ -59,6 +61,7 @@
|
||||||
<integer name="settings_default_tap_to_reveal_timeout">30</integer>
|
<integer name="settings_default_tap_to_reveal_timeout">30</integer>
|
||||||
<string name="settings_default_encryption" translatable="false">keystore</string>
|
<string name="settings_default_encryption" translatable="false">keystore</string>
|
||||||
<string name="settings_default_locale" translatable="false">system</string>
|
<string name="settings_default_locale" translatable="false">system</string>
|
||||||
|
<string name="settings_default_theme_mode" translatable="false">auto</string>
|
||||||
<string name="settings_default_theme" translatable="false">light</string>
|
<string name="settings_default_theme" translatable="false">light</string>
|
||||||
<integer name="settings_default_label_size">18</integer>
|
<integer name="settings_default_label_size">18</integer>
|
||||||
<string name="settings_default_card_layout" translatable="false">default</string>
|
<string name="settings_default_card_layout" translatable="false">default</string>
|
||||||
|
@ -131,6 +134,11 @@
|
||||||
<item>zh_TW</item>
|
<item>zh_TW</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="settings_values_theme_mode" translatable="false">
|
||||||
|
<item>auto</item>
|
||||||
|
<item>manual</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="settings_values_theme" translatable="false">
|
<string-array name="settings_values_theme" translatable="false">
|
||||||
<item>light</item>
|
<item>light</item>
|
||||||
<item>dark</item>
|
<item>dark</item>
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<string name="settings_title_relock_screen_off">Re-lock on screen off</string>
|
<string name="settings_title_relock_screen_off">Re-lock on screen off</string>
|
||||||
|
|
||||||
<string name="settings_title_lang">Language</string>
|
<string name="settings_title_lang">Language</string>
|
||||||
|
<string name="settings_title_theme_mode">Theme Mode</string>
|
||||||
<string name="settings_title_theme">Theme</string>
|
<string name="settings_title_theme">Theme</string>
|
||||||
<string name="settings_title_card_layout">Card layout</string>
|
<string name="settings_title_card_layout">Card layout</string>
|
||||||
<string name="settings_title_label_size">Label font size</string>
|
<string name="settings_title_label_size">Label font size</string>
|
||||||
|
@ -167,6 +168,11 @@
|
||||||
<item>Tags</item>
|
<item>Tags</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="settings_entries_theme_mode">
|
||||||
|
<item>Auto</item>
|
||||||
|
<item>Manual</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="settings_entries_theme">
|
<string-array name="settings_entries_theme">
|
||||||
<item>Light theme</item>
|
<item>Light theme</item>
|
||||||
<item>Dark theme</item>
|
<item>Dark theme</item>
|
||||||
|
|
|
@ -51,7 +51,8 @@
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/settings_category_title_ui">
|
android:title="@string/settings_category_title_ui"
|
||||||
|
android:key="@string/settings_key_cat_ui">
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="@string/settings_key_locale"
|
android:key="@string/settings_key_locale"
|
||||||
|
@ -61,6 +62,14 @@
|
||||||
android:entryValues="@array/settings_values_locale"
|
android:entryValues="@array/settings_values_locale"
|
||||||
android:defaultValue="@string/settings_default_locale" />
|
android:defaultValue="@string/settings_default_locale" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="@string/settings_key_theme_mode"
|
||||||
|
android:title="@string/settings_title_theme_mode"
|
||||||
|
android:summary="%s"
|
||||||
|
android:entries="@array/settings_entries_theme_mode"
|
||||||
|
android:entryValues="@array/settings_values_theme_mode"
|
||||||
|
android:defaultValue="@string/settings_default_theme_mode" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="@string/settings_key_theme"
|
android:key="@string/settings_key_theme"
|
||||||
android:title="@string/settings_title_theme"
|
android:title="@string/settings_title_theme"
|
||||||
|
|
Loading…
Reference in a new issue