diff --git a/app/build.gradle b/app/build.gradle index ffdb524..869e152 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'androidx.preference:preference:1.1.0-rc01' testImplementation 'junit:junit:4.12' implementation 'androidx.core:core:1.2.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f4a79d3..5357839 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,15 +2,18 @@ - + + android:theme="@style/AppTheme"> + @@ -23,23 +26,19 @@ - + android:theme="@style/AppTheme.NoActionBar"> - + android:theme="@style/AppTheme.NoActionBar"> - + android:theme="@style/AppTheme.NoActionBar"> - + android:theme="@style/AppTheme.NoActionBar"> - - + + - + + - - + + + - @@ -74,6 +75,7 @@ + - * See - * Android Design: Settings for design guidelines and the Settings - * API Guide for more information on developing a Settings UI. - * - * The SettingsActivity is extended by AppCompatPreferenceActivity - * The activity is responsible for the different app settings. - */ -public class SettingsActivity extends AppCompatPreferenceActivity { + private static PreferenceScreen prefScreen; + + private static void recheckNightModeProperties(SharedPreferences sharedPreferences) { + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + + if (sharedPreferences.getBoolean("pref_dark_mode_setting", false)) { + prefScreen.findPreference("pref_dark_mode_automatically_by_system").setEnabled(false); + prefScreen.findPreference("pref_dark_mode_automatically_by_battery").setEnabled(false); + } else { + if (sharedPreferences.getBoolean("pref_dark_mode_automatically_by_battery", false) && sharedPreferences.getBoolean("pref_dark_mode_automatically_by_system", false) ) { + sharedPreferences.edit().putBoolean("pref_dark_mode_automatically_by_battery", false).commit(); + } + + prefScreen.findPreference("pref_dark_mode_automatically_by_system").setEnabled(!sharedPreferences.getBoolean("pref_dark_mode_automatically_by_battery", false)); + prefScreen.findPreference("pref_dark_mode_automatically_by_battery").setEnabled(!sharedPreferences.getBoolean("pref_dark_mode_automatically_by_system", false)); + }} + + if (sharedPreferences.getBoolean("pref_dark_mode_setting", false )) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + + } else if (sharedPreferences.getBoolean("pref_dark_mode_automatically_by_system", false)) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + } else if(sharedPreferences.getBoolean("pref_dark_mode_automatically_by_battery", false)){ + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); + } else { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + } + } + + static SharedPreferences.OnSharedPreferenceChangeListener x = new SharedPreferences.OnSharedPreferenceChangeListener() { + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals("pref_dark_mode_setting")|| key.equals("pref_dark_mode_automatically_by_system")||key.equals("pref_dark_mode_automatically_by_battery")) { + recheckNightModeProperties(sharedPreferences); + } + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setupActionBar(); - - overridePendingTransition(0, 0); - - View mainContent = findViewById(R.id.main_content); - if (mainContent != null) { - mainContent.setAlpha(0); - mainContent.animate().alpha(1).setDuration(BaseActivity.MAIN_CONTENT_FADEIN_DURATION); + setContentView(R.layout.settings_activity); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.settings, new SettingsFragment()) + .commit(); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); } - /** - * Set up the {@link android.app.ActionBar}, if the API is available. - */ SharedPreferences preferenceManager = PreferenceManager .getDefaultSharedPreferences(this); - SharedPreferences.OnSharedPreferenceChangeListener x = new SharedPreferences.OnSharedPreferenceChangeListener() { - - /** - * Case differentiation for the different Night Mode options - * @param sharedPreferences - */ - - public void recheckNightModeProperties(SharedPreferences sharedPreferences){ - if (sharedPreferences.getBoolean("pref_dark_mode_setting", false )) { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); - restartActivity(); - - } else if (sharedPreferences.getBoolean("pref_dark_mode_automatically_by_system", false)) { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); - restartActivity(); - } else if(sharedPreferences.getBoolean("pref_dark_mode_automatically_by_battery", false)){ - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); - restartActivity(); - } else { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); - restartActivity(); - } - - } - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.equals("pref_dark_mode_setting")|| key.equals("pref_dark_mode_automatically_by_system")||key.equals("pref_dark_mode_automatically_by_battery")) { - recheckNightModeProperties(sharedPreferences); - } - } - }; preferenceManager.registerOnSharedPreferenceChangeListener(x); } - - /** - * is responsible for closing and opening the activity - */ - public void restartActivity() { - Intent i = new Intent(getApplicationContext(), MainActivity.class); - recreate(); - finish(); - startActivity(i); - } - - private void setupActionBar () { - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - // Show the Up button in the action bar. - actionBar.setDisplayHomeAsUpEnabled(true); - } - } - @Override - public boolean onMenuItemSelected(int featureId, MenuItem item) { + public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { - if (!super.onMenuItemSelected(featureId, item)) { - finish(); - //NavUtils.navigateUpFromSameTask(this); - } + finish(); return true; } - return super.onMenuItemSelected(featureId, item); + return super.onOptionsItemSelected(item); } - /** - * {@inheritDoc} - */ - @Override - public boolean onIsMultiPane() { - return isXLargeTablet(this); - } - /** - * Helper method to determine if the device has an extra-large screen. For - * example, 10" tablets are extra-large. - */ - private static boolean isXLargeTablet(Context context) { - return (context.getResources().getConfiguration().screenLayout - & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; - } - - /** - * {@inheritDoc} - */ - @Override - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void onBuildHeaders(List
target) { - loadHeadersFromResource(R.xml.pref_settings_headers, target); - } - - /** - * A preference value change listener that updates the preference's summary - * to reflect its new value. - */ - private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { + public static class SettingsFragment extends PreferenceFragmentCompat { @Override - public boolean onPreferenceChange(Preference preference, Object value) { - String stringValue = value.toString(); + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.pref_settings_general, rootKey); + prefScreen = getPreferenceScreen(); + SharedPreferences preferenceManager = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + recheckNightModeProperties(preferenceManager); - if (preference instanceof ListPreference) { - // For list preferences, look up the correct display value in - // the preference's 'entries' list. - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); - - // Set the summary to reflect the new value. - preference.setSummary( - index >= 0 - ? listPreference.getEntries()[index] - : null); - - } else { - // For all other preferences, set the summary to the value's - // simple string representation. - preference.setSummary(stringValue); - } - return true; - } - }; - - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - * - * @see #sBindPreferenceSummaryToValueListener - */ - private static void bindPreferenceSummaryToValue(Preference preference) { - // Set the listener to watch for value changes. - preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - - // Trigger the listener immediately with the preference's - // current value. - sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } - - /** - * This method stops fragment injection in malicious applications. - * Make sure to deny any unknown fragments here. - */ - protected boolean isValidFragment(String fragmentName) { - return PreferenceFragment.class.getName().equals(fragmentName) - || GamePreferenceFragment.class.getName().equals(fragmentName); - } - - /** - * This fragment shows general preferences only. It is used when the - * activity is showing a two-pane settings UI. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class GamePreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_settings_general); - setHasOptionsMenu(true); - - - PreferenceManager preferenceManager = getPreferenceManager(); - SharedPreferences sp = preferenceManager.getSharedPreferences(); - - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - - if (sp.getBoolean("pref_dark_mode_setting", false)) { - //TwoStatePreference x = (TwoStatePreference) findPreference("pref_dark_mode_automatically_by_system"); - //x.setEnabled(false); - findPreference("pref_dark_mode_automatically_by_system").setEnabled(false); - findPreference("pref_dark_mode_automatically_by_battery").setEnabled(false); - } else { - if (sp.getBoolean("pref_dark_mode_automatically_by_battery", false) && sp.getBoolean("pref_dark_mode_automatically_by_system", false) ) { - sp.edit().putBoolean("pref_dark_mode_automatically_by_battery", false).commit(); - } - - findPreference("pref_dark_mode_automatically_by_system").setEnabled(!sp.getBoolean("pref_dark_mode_automatically_by_battery", false)); - findPreference("pref_dark_mode_automatically_by_battery").setEnabled(!sp.getBoolean("pref_dark_mode_automatically_by_system", false)); - } - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - - //bindPreferenceSummaryToValue(findPreference("example_text")); - //bindPreferenceSummaryToValue(findPreference("example_list")); - - } - - } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - getActivity().finish(); - //startActivity(new Intent(getActivity(), SettingsActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); } } -} +} \ No newline at end of file diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml new file mode 100644 index 0000000..de6591a --- /dev/null +++ b/app/src/main/res/layout/settings_activity.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..6cf9ed4 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,12 @@ + + + + Reply + Reply to all + + + + reply + reply_all + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fceee74..8b256bb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -178,5 +178,21 @@ Verifying… Done verifying! Verification failed: Your sudoku cannot be solved. + Settings + + + Messages + Sync + + + Your signature + Default reply action + + + Sync email periodically + Download incoming attachments + Automatically download attachments for incoming emails + + Only download attachments when manually requested