diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java
index 5c199e4e..9958840e 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java
@@ -53,6 +53,7 @@
import de.k3b.android.util.IntentUtil;
import de.k3b.android.util.SelectedFotos;
import de.k3b.android.widget.AboutDialogPreference;
+import de.k3b.android.widget.LocalizedActivity;
import de.k3b.database.QueryParameter;
import de.k3b.io.Directory;
import de.k3b.io.DirectoryFormatter;
@@ -61,7 +62,7 @@
import de.k3b.io.IDirectory;
import de.k3b.io.IGalleryFilter;
-public class FotoGalleryActivity extends Activity implements Common,
+public class FotoGalleryActivity extends LocalizedActivity implements Common,
OnGalleryInteractionListener, DirectoryPickerFragment.OnDirectoryInteractionListener,
LocationMapFragment.OnDirectoryInteractionListener
{
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/GalleryFilterActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/GalleryFilterActivity.java
index 2ae9b5e8..f7f244b0 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/GalleryFilterActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/GalleryFilterActivity.java
@@ -48,6 +48,7 @@
import de.k3b.android.osmdroid.ZoomUtil;
import de.k3b.android.widget.AboutDialogPreference;
import de.k3b.android.widget.HistoryEditText;
+import de.k3b.android.widget.LocalizedActivity;
import de.k3b.database.QueryParameter;
import de.k3b.io.DirectoryFormatter;
import de.k3b.io.GalleryFilterParameter;
@@ -58,7 +59,7 @@
/**
* Defines a gui for global foto filter: only fotos from certain filepath, date and/or lat/lon will be visible.
*/
-public class GalleryFilterActivity extends Activity implements Common, DirectoryPickerFragment.OnDirectoryInteractionListener, LocationMapFragment.OnDirectoryInteractionListener {
+public class GalleryFilterActivity extends LocalizedActivity implements Common, DirectoryPickerFragment.OnDirectoryInteractionListener, LocationMapFragment.OnDirectoryInteractionListener {
private static final String debugPrefix = "GalF-";
public static final int resultID = 522;
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/Global.java b/app/src/main/java/de/k3b/android/androFotoFinder/Global.java
index 3e7ef29d..8f14c494 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/Global.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/Global.java
@@ -19,11 +19,15 @@
package de.k3b.android.androFotoFinder;
+import android.content.Context;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import java.io.File;
+import java.util.Locale;
+
+import de.k3b.android.widget.LocalizedActivity;
/**
* Global Settings
@@ -32,6 +36,7 @@
*/
public class Global {
public static final String LOG_CONTEXT = "k3bFoto";
+ public static final String PREF_KEY_USER_LOCALE = "user_locale";
/**
* Global.xxxxx. Non final values may be changed in SettingsActivity
@@ -83,5 +88,5 @@ public static void debugMemory(String modul, String message) {
}
}
-
+ public static Locale systemLocale = Locale.getDefault();
}
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 b32d41da..e059149a 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
@@ -24,22 +24,43 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import java.io.File;
+import de.k3b.android.widget.LocalizedActivity;
import uk.co.senab.photoview.HugeImageLoader;
import uk.co.senab.photoview.PhotoViewAttacher;
import uk.co.senab.photoview.log.LogManager;
public class SettingsActivity extends PreferenceActivity {
+ private SharedPreferences prefsInstance = null;
+ private ListPreference defaultAudioFormatPreference;
@Override
protected void onCreate(final Bundle savedInstanceState) {
+ LocalizedActivity.fixLocale(this);
super.onCreate(savedInstanceState);
this.addPreferencesFromResource(R.xml.preferences);
+ prefsInstance = PreferenceManager
+ .getDefaultSharedPreferences(this);
global2Prefs(this.getApplication());
+ defaultAudioFormatPreference =
+ (ListPreference) findPreference(Global.PREF_KEY_USER_LOCALE);
+
+ defaultAudioFormatPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ setLanguage((String) newValue);
+ SettingsActivity.super.recreate();
+ return true; // change is allowed
+ }
+ });
+
+ updateSummary();
}
@Override
@@ -49,7 +70,7 @@ public void onPause() {
}
public static void global2Prefs(Context context) {
- final SharedPreferences prefsInstance = PreferenceManager
+ SharedPreferences prefsInstance = PreferenceManager
.getDefaultSharedPreferences(context);
SharedPreferences.Editor prefs = prefsInstance.edit();
@@ -148,7 +169,7 @@ private static int getPref(SharedPreferences prefs, String key, int defaultValue
/** load value from SharedPreferences */
private static boolean getPref(SharedPreferences prefs, String key, boolean defaultValue) {
- return prefs.getBoolean(key,defaultValue);
+ return prefs.getBoolean(key, defaultValue);
/*
String def = "" + defaultValue ;
@@ -163,4 +184,22 @@ public static void show(Activity parent) {
Intent intent = new Intent(parent, SettingsActivity.class);
parent.startActivity(intent);
}
+ // This is used to show the status of some preference in the description
+ private void updateSummary() {
+ final String languageKey = prefsInstance.getString(Global.PREF_KEY_USER_LOCALE, "");
+ setLanguage(languageKey);
+ }
+
+ private void setLanguage(String languageKey) {
+ int index = defaultAudioFormatPreference.findIndexOfValue(languageKey);
+ String summary = "";
+
+ if (index >= 0) {
+ String[] names = this.getResources().getStringArray(R.array.pref_locale_names);
+ if (index < names.length) {
+ summary = names[index];
+ }
+ }
+ defaultAudioFormatPreference.setSummary(summary);
+ }
}
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java b/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java
index dce74ad3..627155df 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java
@@ -62,6 +62,7 @@
import de.k3b.android.util.SelectedFotos;
import de.k3b.android.widget.AboutDialogPreference;
import de.k3b.android.widget.Dialogs;
+import de.k3b.android.widget.LocalizedActivity;
import de.k3b.database.QueryParameter;
import de.k3b.io.GalleryFilterParameter;
import de.k3b.io.IDirectory;
@@ -72,7 +73,7 @@
* Swipe left/right to show previous/next image.
*/
-public class ImageDetailActivityViewPager extends Activity implements Common {
+public class ImageDetailActivityViewPager extends LocalizedActivity implements Common {
private static final String INSTANCE_STATE_MODIFY_COUNT = "mModifyCount";
public static final int ACTIVITY_ID = 76621;
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java
index 2ace538e..2d5ecf79 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java
@@ -45,6 +45,7 @@
import de.k3b.android.util.AndroidFileCommands;
import de.k3b.android.util.SelectedFotos;
import de.k3b.android.widget.HistoryEditText;
+import de.k3b.android.widget.LocalizedActivity;
import de.k3b.database.SelectedItems;
import de.k3b.geo.api.GeoPointDto;
import de.k3b.geo.api.IGeoPointInfo;
@@ -55,7 +56,7 @@
/**
* Defines a gui for global foto filter: only fotos from certain filepath, date and/or lat/lon will be visible.
*/
-public class GeoEditActivity extends Activity implements Common {
+public class GeoEditActivity extends LocalizedActivity implements Common {
private static final String debugPrefix = "GeoEdit-";
public static final int RESULT_ID = 524;
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java
index d720a643..14d238a9 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java
@@ -44,6 +44,7 @@
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.osmdroid.ZoomUtil;
import de.k3b.android.widget.AboutDialogPreference;
+import de.k3b.android.widget.LocalizedActivity;
import de.k3b.database.SelectedItems;
import de.k3b.geo.api.GeoPointDto;
import de.k3b.geo.api.IGeoPointInfo;
@@ -51,7 +52,7 @@
import de.k3b.io.GalleryFilterParameter;
import de.k3b.io.GeoRectangle;
-public class MapGeoPickerActivity extends Activity implements Common {
+public class MapGeoPickerActivity extends LocalizedActivity implements Common {
private static final String debugPrefix = "GalM-";
private static final String STATE_Filter = "filterMap";
private static final String STATE_LAST_GEO = "geoLastView";
diff --git a/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java b/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
new file mode 100644
index 00000000..33b9ced5
--- /dev/null
+++ b/app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
@@ -0,0 +1,47 @@
+package de.k3b.android.widget;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.os.Environment;
+import android.preference.PreferenceManager;
+
+import java.util.Locale;
+
+import de.k3b.android.androFotoFinder.Global;
+
+/**
+ * An activity that can change the locale (language) of its content.
+ *
+ * Inspired by http://stackoverflow.com/questions/13181847/change-the-locale-at-runtime
+ *
+ * Created by k3b on 07.01.2016.
+ */
+public class LocalizedActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ fixLocale(this);
+ super.onCreate(savedInstanceState);
+ }
+
+ public static void fixLocale(Context context)
+ {
+ final SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ String language = prefs.getString(Global.PREF_KEY_USER_LOCALE, "");
+ Locale locale = Global.systemLocale;
+ if ((language != null) && (!language.isEmpty())) {
+ locale = new Locale(language);
+ }
+ Locale.setDefault(locale);
+ Configuration config = new Configuration();
+ config.locale = locale;
+ Resources resources = context.getResources();
+ resources.updateConfiguration(config, resources.getDisplayMetrics());
+ // recreate();
+ }
+}
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 76d6ec17..0ad03008 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -124,6 +124,8 @@ Dieser Vorgang kann nicht rückgängig gemacht werden."
Verbesserte Anfangsqualität Photo-View
Diashow-Intervall in Millisekunden
+ Sprache
+ (Sprache des Gerätes)
Ordner für Log-Meldungen
Max. Anzahl Mehrfach-Marker in der Karte
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index b6bc47f2..4ba7adee 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -10,5 +10,18 @@
- @string/sort_order_Name_length_Ascending
- @string/sort_order_Name_length_Descending
-
+
+ - @string/settings_locale_os_language
+ - en english
+ - de german Deutsch
+ - ja japanese 日本人
+ - fr french Français
+
+
+
+ - en
+ - de
+ - ja
+ - fr
+
\ 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 1c6271fa..f5d98c8e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -135,6 +135,9 @@ This operation cannot be reversed."
Improve initial Photo-View quality
Slide Show Interval in millisecs
+ Language
+ (device language)
+
Error Log Folder
Max. Sel-Markers in Map
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index e433a318..47921513 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -5,6 +5,15 @@
android:title="@string/settings_title"
android:key="first_category">
+
+