From 20963c02c0be050ea25ede27444968e880760a05 Mon Sep 17 00:00:00 2001
From: k3b <1374583+k3b@users.noreply.github.com>
Date: Thu, 30 Jan 2020 07:02:55 +0100
Subject: [PATCH] #162: Fixed Merge Error; Refactored Theme code to
UserTheme.java; THeme-change takes immediate effect
---
app/src/main/java/de/k3b/android/GuiUtil.java | 23 ----------
.../androFotoFinder/SettingsActivity.java | 13 +++---
.../java/de/k3b/android/util/UserTheme.java | 45 +++++++++++++++++++
.../widget/ActivityWithCallContext.java | 4 +-
.../k3b/android/widget/LocalizedActivity.java | 22 +++++----
app/src/main/res/values-de/strings.xml | 8 ++++
app/src/main/res/values/arrays.xml | 3 +-
app/src/main/res/values/strings.xml | 1 +
8 files changed, 77 insertions(+), 42 deletions(-)
create mode 100644 app/src/main/java/de/k3b/android/util/UserTheme.java
diff --git a/app/src/main/java/de/k3b/android/GuiUtil.java b/app/src/main/java/de/k3b/android/GuiUtil.java
index a72aa62d..61493b1a 100644
--- a/app/src/main/java/de/k3b/android/GuiUtil.java
+++ b/app/src/main/java/de/k3b/android/GuiUtil.java
@@ -19,20 +19,13 @@
package de.k3b.android;
-import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.preference.PreferenceManager;
-
-import de.k3b.android.androFotoFinder.R;
/**
* gui utils
*/
public class GuiUtil {
-
- public static final String PREF_KEY_USER_THEME = "user_theme";
-
public static String getAppVersionName(final Context context) {
try {
@@ -43,21 +36,5 @@ public static String getAppVersionName(final Context context) {
}
return null;
}
- public static void setTheme(Activity act) {
- final String theme = getTheme(act);
- switch (theme) {
- case "Light":
- act.setTheme(R.style.AppTheme_Light);
- break;
- case "Dark":
- act.setTheme(R.style.AppTheme_Dark);
- break;
- default:
- throw new RuntimeException("Invalid theme '" + theme+ "' selected");
- }
- }
- public static String getTheme(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_KEY_USER_THEME, "Light");
- }
}
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
index d464273d..f3c89807 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
@@ -39,11 +39,11 @@
import java.io.File;
import de.k3b.LibGlobal;
-import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.util.PhotoPropertiesMediaFilesScanner;
import de.k3b.android.util.PhotoPropertiesMediaFilesScannerExifInterface;
import de.k3b.android.util.PhotoPropertiesMediaFilesScannerImageMetaReader;
+import de.k3b.android.util.UserTheme;
import de.k3b.android.widget.AboutDialogPreference;
import de.k3b.android.widget.ActivityWithCallContext;
import de.k3b.android.widget.LocalizedActivity;
@@ -65,8 +65,7 @@ public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
- GuiUtil.setTheme(this); // this activity doesn't extent ActivityWithCallContext
- LocalizedActivity.fixLocale(this); // #21: Support to change locale at runtime
+ LocalizedActivity.fixThemeAndLocale(this); // #21: Support to change locale at runtime
super.onCreate(savedInstanceState);
if (Global.debugEnabled) {
@@ -96,7 +95,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});
- themePreference = (ListPreference) findPreference(GuiUtil.PREF_KEY_USER_THEME);
+ themePreference = (ListPreference) findPreference(UserTheme.PREF_KEY_USER_THEME);
themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -415,17 +414,17 @@ private void updateSummary() {
final String languageKey = prefsInstance.getString(Global.PREF_KEY_USER_LOCALE, "");
setLanguage(languageKey);
- setUserTheme(GuiUtil.getTheme(this));
+ setUserTheme(UserTheme.getThemeKey(this));
AboutDialogPreference about =
(AboutDialogPreference) findPreference("about");
about.setTitle(AboutDialogPreference.getAboutTitle(this));
}
private void setUserTheme(String newValue) {
- setPref(GuiUtil.PREF_KEY_USER_THEME, this.themePreference, R.array.pref_themes_names);
+ setPref(UserTheme.PREF_KEY_USER_THEME, this.themePreference, R.array.pref_themes_names);
+ LocalizedActivity.setMustRecreate();
}
-
// #21: Support to change locale at runtime
private void setLanguage(String languageKey) {
setPref(languageKey, defaultLocalePreference, R.array.pref_locale_names);
diff --git a/app/src/main/java/de/k3b/android/util/UserTheme.java b/app/src/main/java/de/k3b/android/util/UserTheme.java
new file mode 100644
index 00000000..44cec3cb
--- /dev/null
+++ b/app/src/main/java/de/k3b/android/util/UserTheme.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019-2020 by vinceh121
+ *
+ * This file is part of AndroFotoFinder.
+ *
+ * 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, see
+ */
+
+package de.k3b.android.util;
+
+import android.app.Activity;
+import android.content.Context;
+import android.preference.PreferenceManager;
+
+import de.k3b.android.androFotoFinder.R;
+
+/**
+ * #162: change Theme at runtime
+ */
+public class UserTheme {
+ public static final String PREF_KEY_USER_THEME = "user_theme";
+
+ public static void setTheme(Activity act) {
+ final String themeKey = getThemeKey(act);
+ int themeID = ("Dark".compareTo(themeKey) != 0)
+ ? R.style.AppTheme_Light
+ : R.style.AppTheme_Dark;
+ act.setTheme(themeID);
+ }
+
+ public static String getThemeKey(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_KEY_USER_THEME, "Light");
+ }
+}
diff --git a/app/src/main/java/de/k3b/android/widget/ActivityWithCallContext.java b/app/src/main/java/de/k3b/android/widget/ActivityWithCallContext.java
index aab6b8ba..e27dcb58 100644
--- a/app/src/main/java/de/k3b/android/widget/ActivityWithCallContext.java
+++ b/app/src/main/java/de/k3b/android/widget/ActivityWithCallContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019 by k3b.
+ * Copyright (c) 2018-2020 by k3b.
*
* This file is part of AndroFotoFinder and of ToGoZip.
*
@@ -24,7 +24,6 @@
import android.os.Bundle;
import android.util.Log;
-import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.Global;
/**
@@ -76,7 +75,6 @@ public static void addContext(String debugContext, Intent targetIntent, Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
- GuiUtil.setTheme(this); // Almost every activity extends this so use this to set theme
super.onCreate(savedInstanceState);
if (isCallContextEnabled) {
diff --git a/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java b/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
index 6ee9b8fb..0df6a22d 100644
--- a/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
+++ b/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015-2019 by k3b.
+ * Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder and of ToGoZip.
*
@@ -32,6 +32,7 @@
import java.util.Locale;
import de.k3b.android.androFotoFinder.Global;
+import de.k3b.android.util.UserTheme;
/**
* An activity that can change the locale (language) of its content.
@@ -57,17 +58,16 @@ public static void setMustRecreate() {
LocalizedActivity.currentRecreationId++;
}
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- fixLocale(this);
- super.onCreate(savedInstanceState);
- }
-
/**
* Set Activity-s locale to SharedPreferences-setting.
* Must be called before
*/
- public static void fixLocale(Context context) {
+ public static void fixThemeAndLocale(Activity context) {
+ UserTheme.setTheme(context);
+ fixLocale(context);
+ }
+
+ private static void fixLocale(Context context) {
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context);
String language = prefs.getString(Global.PREF_KEY_USER_LOCALE, "");
@@ -94,6 +94,12 @@ public static void fixLocale(Context context) {
}
}
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ fixThemeAndLocale(this);
+ super.onCreate(savedInstanceState);
+ }
+
@Override
protected void onResume() {
super.onResume();
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 3341851a..279f93d5 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -275,4 +275,12 @@ Verstecken kann über das 'Media-Scanner' Gallery-Menü rückgängig gemacht wer
What:
-->
+
+ Farbschema
+ Hell (Holo light)
+ Dunkel (Holo dark)
+
+
+ Photo.Datenbank (neu) laden
+
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 5582d55b..38386962 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -80,8 +80,9 @@
- 00000
+
- - Lgiht
+ - Light
- Dark
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 58fe7b5b..61cc68e7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -280,6 +280,7 @@ You can undo hiding by calling the mediascanner from gallery-menu."
What:
-->
+
Theme
Holo light
Holo dark