Merge pull request #418 from Ullas-Aithal/feature/394

Added auto theme selection for Android 10 devices
This commit is contained in:
Jakob Nixdorf 2021-03-12 07:02:57 +01:00 committed by GitHub
commit c5a6cef250
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 11 deletions

View file

@ -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_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))) ||
key.equals(getString(R.string.settings_key_hide_global_timeout)) || key.equals(getString(R.string.settings_key_hide_global_timeout)) ||
key.equals(getString(R.string.settings_key_hide_issuer))) { key.equals(getString(R.string.settings_key_hide_issuer))) {
recreateActivity = true; recreateActivity = true;

View file

@ -149,7 +149,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_lang)) || key.equals(getString(R.string.settings_key_lang)) ||
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_backup_location))) { key.equals(getString(R.string.settings_key_backup_location)) ||
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) {
@ -297,6 +298,7 @@ public class SettingsActivity extends BaseActivity
public static class SettingsFragment extends PreferenceFragment { public static class SettingsFragment extends PreferenceFragment {
private PreferenceCategory catSecurity; private PreferenceCategory catSecurity;
PreferenceCategory catUI;
private Settings settings; private Settings settings;
private ListPreference encryption; private ListPreference encryption;
@ -307,6 +309,8 @@ public class SettingsActivity extends BaseActivity
private OpenPgpAppPreference pgpProvider; private OpenPgpAppPreference pgpProvider;
private EditTextPreference pgpEncryptionKey; private EditTextPreference pgpEncryptionKey;
private OpenPgpKeyPreference pgpSigningKey; private 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());
@ -378,7 +382,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
@ -496,11 +503,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);
}
}
} }
} }
} }

View file

@ -24,7 +24,9 @@ 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.net.Uri; import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Base64; import android.util.Base64;
@ -347,9 +349,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;
@ -358,6 +377,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;
} }

View file

@ -23,8 +23,10 @@
<string name="settings_key_block_autofill" translatable="false">pref_block_autofill</string> <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_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_lang" translatable="false">pref_lang</string>
<string name="settings_key_locale" translatable="false">pref_locale</string> <!-- Deprecated --> <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_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>
@ -77,6 +79,7 @@
<integer name="settings_default_auth_inactivity_delay">30</integer> <integer name="settings_default_auth_inactivity_delay">30</integer>
<string name="settings_default_encryption" translatable="false">keystore</string> <string name="settings_default_encryption" translatable="false">keystore</string>
<string name="settings_default_lang" translatable="false">system</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> <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_label_display" translatable="false">truncate</string> <string name="settings_default_label_display" translatable="false">truncate</string>
@ -173,6 +176,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>

View file

@ -24,6 +24,7 @@
<string name="settings_title_auto_unlock_after_autofill">Unlock automatically after autofill</string> <string name="settings_title_auto_unlock_after_autofill">Unlock automatically after autofill</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>
@ -210,6 +211,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_auto_backup_password_enc"> <string-array name="settings_entries_auto_backup_password_enc">
<item>Off</item> <item>Off</item>
<item>New Entries</item> <item>New Entries</item>

View file

@ -83,7 +83,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_lang" android:key="@string/settings_key_lang"
@ -93,6 +94,14 @@
android:entryValues="@array/settings_values_lang" android:entryValues="@array/settings_values_lang"
android:defaultValue="@string/settings_default_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 <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"