From aea11a0f6465d1af6f6f5f2b19fac9b8198414d1 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Fri, 28 Aug 2020 23:28:42 +0200 Subject: [PATCH 1/4] Customizing the MainActivity delete the import of the old SettingsActivity. --- .../java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java index c3d1f18..878beee 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java @@ -60,7 +60,6 @@ import org.secuso.privacyfriendlysudoku.game.GameDifficulty; import org.secuso.privacyfriendlysudoku.game.GameType; import org.secuso.privacyfriendlysudoku.ui.listener.IImportDialogFragmentListener; import org.secuso.privacyfriendlysudoku.ui.view.R; -import org.secuso.privacyfriendlysudoku.ui.SettingsActivity; import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentImportBoardBinding; import java.util.LinkedList; From cafb8cb10fa5db3d39021b8e4f0a698c80267960 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Sat, 29 Aug 2020 13:36:46 +0200 Subject: [PATCH 2/4] Adjusting the SettingsActivity 1.) Inserting the license 2.) Replace the PreferenceScreen with SettingsFragement 3.) Modify the method onCreatePreferences() in the class SettingsFragement to fix a bug when calling the SettingsActivity the first time the app is started. --- .../ui/SettingsActivity.java | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java index c597c5e..da9baf6 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/SettingsActivity.java @@ -1,3 +1,22 @@ +/* + * qqwing - Sudoku solver and generator + * Copyright (C) 2014 Stephen Ostermiller + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + package org.secuso.privacyfriendlysudoku.ui; import android.content.SharedPreferences; @@ -21,22 +40,23 @@ import org.secuso.privacyfriendlysudoku.ui.view.R; public class SettingsActivity extends AppCompatActivity { - private static PreferenceScreen prefScreen; + private static SettingsFragment settingsFragment; 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); + + settingsFragment.findPreference("pref_dark_mode_automatically_by_system").setEnabled(false); + settingsFragment.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)); + settingsFragment.findPreference("pref_dark_mode_automatically_by_system").setEnabled(!sharedPreferences.getBoolean("pref_dark_mode_automatically_by_battery", false)); + settingsFragment.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 )) { @@ -51,7 +71,7 @@ public class SettingsActivity extends AppCompatActivity { } } - static SharedPreferences.OnSharedPreferenceChangeListener x = new SharedPreferences.OnSharedPreferenceChangeListener() { + static SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { @@ -65,19 +85,17 @@ public class SettingsActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings_activity); + settingsFragment = new SettingsFragment(); getSupportFragmentManager() .beginTransaction() - .replace(R.id.settings, new SettingsFragment()) + .replace(R.id.settings, settingsFragment) .commit(); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } - SharedPreferences preferenceManager = PreferenceManager - .getDefaultSharedPreferences(this); - preferenceManager.registerOnSharedPreferenceChangeListener(x); } @Override @@ -92,14 +110,14 @@ public class SettingsActivity extends AppCompatActivity { public static class SettingsFragment extends PreferenceFragmentCompat { + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.pref_settings_general, rootKey); - prefScreen = getPreferenceScreen(); SharedPreferences preferenceManager = PreferenceManager .getDefaultSharedPreferences(getActivity()); + preferenceManager.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); recheckNightModeProperties(preferenceManager); - } } } \ No newline at end of file From b9e8324b273bd15a425e93a3cc5241a543f64de3 Mon Sep 17 00:00:00 2001 From: ErikWaegerle Date: Sat, 29 Aug 2020 13:43:20 +0200 Subject: [PATCH 3/4] Customize the attrs.xml/ styles.xml/ styles.xml-night Insert a new attribute "menuTextColor" to adjust colors of menu items in the Navigation Drawer in DarkMode. --- app/src/main/res/values-night/styles.xml | 1 + app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/styles.xml | 1 + 3 files changed, 3 insertions(+) diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 0988338..0234adc 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -24,6 +24,7 @@ @color/cardview_dark_background @color/colorPrimaryDark @color/colorPrimaryDark + @color/white