Skip to content

Commit

Permalink
#21: settings-Language: Allows to set gui language. Default is (devic…
Browse files Browse the repository at this point in the history
…e language).
  • Loading branch information
k3b committed Jan 7, 2016
1 parent 2c6eb11 commit 6d3286e
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/de/k3b/android/androFotoFinder/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -83,5 +88,5 @@ public static void debugMemory(String modul, String message) {
}
}


public static Locale systemLocale = Locale.getDefault();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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 ;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
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;
import de.k3b.geo.io.GeoUri;
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";
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Dieser Vorgang kann nicht rückgängig gemacht werden."</string>
<string name="settings_image_initialImageDetailResolutionHigh_title">Verbesserte Anfangsqualität Photo-View</string>
<string name="settings_image_slideshow_intervall_title">Diashow-Intervall in Millisekunden</string>

<string name="settings_locale_title">Sprache</string>
<string name="settings_locale_os_language">(Sprache des Gerätes)</string>
<string name="settings_log_folder_title">Ordner für Log-Meldungen</string>
<string name="settings_map_selmarker_max_title">Max. Anzahl Mehrfach-Marker in der Karte</string>

Expand Down
15 changes: 14 additions & 1 deletion app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,18 @@
<item>@string/sort_order_Name_length_Ascending</item>
<item>@string/sort_order_Name_length_Descending</item>
</string-array>

<string-array name="pref_locale_names" translatable="false">
<item>@string/settings_locale_os_language</item>
<item>en english</item>
<item>de german Deutsch</item>
<item>ja japanese 日本人</item>
<item>fr french Français</item>
</string-array>
<string-array name="pref_locale_values" translatable="false">
<item></item>
<item>en</item>
<item>de</item>
<item>ja</item>
<item>fr</item>
</string-array>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ This operation cannot be reversed."</string>
<string name="settings_image_initialImageDetailResolutionHigh_title">Improve initial Photo-View quality</string>
<string name="settings_image_slideshow_intervall_title">Slide Show Interval in millisecs</string>

<string name="settings_locale_title">Language</string>
<string name="settings_locale_os_language">(device language)</string>

<string name="settings_log_folder_title">Error Log Folder</string>
<string name="settings_map_selmarker_max_title">Max. Sel-Markers in Map</string>

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
android:title="@string/settings_title"
android:key="first_category">

<ListPreference
android:key="user_locale"
android:title="@string/settings_locale_title"
android:defaultValue=""
android:entries="@array/pref_locale_names"
android:entryValues="@array/pref_locale_values"
android:negativeButtonText="@null"
android:positiveButtonText="@null" />

<CheckBoxPreference android:key="clearSelectionAfterCommand"
android:defaultValue="true"
android:title="@string/settings_multisel_clear_title"
Expand Down
1 change: 1 addition & 0 deletions wiki/History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* *NOT IMPLEMENTED* [#26 option slow-hiqh-quality-detail vs fast-lowRes](https://github.com/k3b/AndroFotoFinder/issues/26): android 5.1: does not support Thumbnails.getThumbnail(...,MediaStore.Images.Thumbnails.FULL_SCREEN_KIND,...) :-(
* TODO [#24 Prevent sleepmode while slideshow is active](https://github.com/k3b/AndroFotoFinder/issues/24)
* [#21 additional languages](https://github.com/k3b/AndroFotoFinder/issues/21)
* Settings dialog allows to set gui language
* English by k3b and mary-kate
* German by k3b and v133
* Japanese by naofum
Expand Down
1 change: 1 addition & 0 deletions wiki/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ You can reach the [Settings View](settings) via the **settings** menu of

##settings

* **Language**: Allows to set gui language. Default is (device language).
* **Clear Multi-Selection**: If checked [multi selection mode](Gallery-View#Multiselection) in [Gallery-View](Gallery-View) is canceled after a command from Actionbar or Menu
* **Max. Sel-Markers in Map**: The maximum number of **Blue selection markers** in the [Geographic-Map](geographic-map).
* Note: This value is limited for performance/memory reason.
Expand Down

0 comments on commit 6d3286e

Please sign in to comment.