Merge pull request #418 from Ullas-Aithal/feature/394
Added auto theme selection for Android 10 devices
This commit is contained in:
commit
c5a6cef250
6 changed files with 72 additions and 11 deletions
|
@ -482,6 +482,7 @@ public class MainActivity extends BaseActivity
|
|||
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_card_layout)) ||
|
||||
key.equals(getString(R.string.settings_key_theme_mode))) ||
|
||||
key.equals(getString(R.string.settings_key_hide_global_timeout)) ||
|
||||
key.equals(getString(R.string.settings_key_hide_issuer))) {
|
||||
recreateActivity = true;
|
||||
|
|
|
@ -149,7 +149,8 @@ public class SettingsActivity extends BaseActivity
|
|||
if (key.equals(getString(R.string.settings_key_theme)) ||
|
||||
key.equals(getString(R.string.settings_key_lang)) ||
|
||||
key.equals(getString(R.string.settings_key_special_features)) ||
|
||||
key.equals(getString(R.string.settings_key_backup_location))) {
|
||||
key.equals(getString(R.string.settings_key_backup_location)) ||
|
||||
key.equals(getString(R.string.settings_key_theme_mode))) {
|
||||
recreate();
|
||||
} else if(key.equals(getString(R.string.settings_key_encryption))) {
|
||||
if (settings.getEncryption() != EncryptionType.PASSWORD) {
|
||||
|
@ -297,6 +298,7 @@ public class SettingsActivity extends BaseActivity
|
|||
|
||||
public static class SettingsFragment extends PreferenceFragment {
|
||||
private PreferenceCategory catSecurity;
|
||||
PreferenceCategory catUI;
|
||||
|
||||
private Settings settings;
|
||||
private ListPreference encryption;
|
||||
|
@ -307,6 +309,8 @@ public class SettingsActivity extends BaseActivity
|
|||
private OpenPgpAppPreference pgpProvider;
|
||||
private EditTextPreference pgpEncryptionKey;
|
||||
private OpenPgpKeyPreference pgpSigningKey;
|
||||
ListPreference themeMode;
|
||||
ListPreference theme;
|
||||
|
||||
public void encryptionChangeWithDialog(final EncryptionType encryptionType) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
@ -378,7 +382,10 @@ public class SettingsActivity extends BaseActivity
|
|||
|
||||
// Authentication
|
||||
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));
|
||||
themeMode = (ListPreference) findPreference(getString(R.string.settings_key_theme_mode));
|
||||
theme = (ListPreference) findPreference(getString(R.string.settings_key_theme));
|
||||
|
||||
encryption.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
|
@ -496,11 +503,21 @@ public class SettingsActivity extends BaseActivity
|
|||
});
|
||||
|
||||
builder.create().show();
|
||||
|
||||
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,7 +24,9 @@ package org.shadowice.flocke.andotp.Utilities;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Base64;
|
||||
|
||||
|
@ -347,16 +349,34 @@ public class Settings {
|
|||
}
|
||||
|
||||
public int getTheme() {
|
||||
String themeName = getString(R.string.settings_key_theme, R.string.settings_default_theme);
|
||||
|
||||
int theme = R.style.AppTheme_NoActionBar;
|
||||
String themeMode = getString(R.string.settings_key_theme_mode, R.string.settings_default_theme_mode);
|
||||
|
||||
if (themeName.equals("light")) {
|
||||
theme = R.style.AppTheme_NoActionBar;
|
||||
} else if (themeName.equals("dark")) {
|
||||
theme = R.style.AppTheme_Dark_NoActionBar;
|
||||
} else if (themeName.equals("black")) {
|
||||
theme = R.style.AppTheme_Black_NoActionBar;
|
||||
//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")) {
|
||||
theme = R.style.AppTheme_NoActionBar;
|
||||
} else if (themeName.equals("dark")) {
|
||||
theme = R.style.AppTheme_Dark_NoActionBar;
|
||||
} else if (themeName.equals("black")) {
|
||||
theme = R.style.AppTheme_Black_NoActionBar;
|
||||
}
|
||||
}
|
||||
|
||||
return theme;
|
||||
|
|
|
@ -23,8 +23,10 @@
|
|||
<string name="settings_key_block_autofill" translatable="false">pref_block_autofill</string>
|
||||
<string name="settings_key_auto_unlock_after_autofill" translatable="false">pref_auto_unlock_after_autofill</string>
|
||||
|
||||
<string name="settings_key_cat_ui" translatable="false">perf_cat_ui</string>
|
||||
<string name="settings_key_lang" translatable="false">pref_lang</string>
|
||||
<string name="settings_key_locale" translatable="false">pref_locale</string> <!-- Deprecated -->
|
||||
<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_label_size" translatable="false">pref_label_size_sp</string>
|
||||
<string name="settings_key_card_layout" translatable="false">pref_card_layout</string>
|
||||
|
@ -77,6 +79,7 @@
|
|||
<integer name="settings_default_auth_inactivity_delay">30</integer>
|
||||
<string name="settings_default_encryption" translatable="false">keystore</string>
|
||||
<string name="settings_default_lang" translatable="false">system</string>
|
||||
<string name="settings_default_theme_mode" translatable="false">auto</string>
|
||||
<string name="settings_default_theme" translatable="false">light</string>
|
||||
<integer name="settings_default_label_size">18</integer>
|
||||
<string name="settings_default_label_display" translatable="false">truncate</string>
|
||||
|
@ -173,6 +176,11 @@
|
|||
<item>zh_TW</item>
|
||||
</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">
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="settings_title_auto_unlock_after_autofill">Unlock automatically after autofill</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_card_layout">Card layout</string>
|
||||
<string name="settings_title_label_size">Label font size</string>
|
||||
|
@ -209,6 +210,11 @@
|
|||
<item>Issuer</item>
|
||||
<item>Tags</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="settings_entries_theme_mode">
|
||||
<item>Auto</item>
|
||||
<item>Manual</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="settings_entries_auto_backup_password_enc">
|
||||
<item>Off</item>
|
||||
|
|
|
@ -83,7 +83,8 @@
|
|||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_category_title_ui">
|
||||
android:title="@string/settings_category_title_ui"
|
||||
android:key="@string/settings_key_cat_ui">
|
||||
|
||||
<ListPreference
|
||||
android:key="@string/settings_key_lang"
|
||||
|
@ -93,6 +94,14 @@
|
|||
android:entryValues="@array/settings_values_lang"
|
||||
android:defaultValue="@string/settings_default_lang" />
|
||||
|
||||
<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
|
||||
android:key="@string/settings_key_theme"
|
||||
android:title="@string/settings_title_theme"
|
||||
|
|
Loading…
Reference in a new issue