diff options
author | Stephan Merker <merker.stephan@googlemail.com> | 2012-04-18 22:40:21 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2012-04-20 10:10:18 +0200 |
commit | 65a15ca7c3634dddb5f2863965aabffc69b49541 (patch) | |
tree | d1527b53aab435d977e937f6987e7747c67c2cbb /main/src/cgeo | |
parent | 45e1a0dc358e4a02b2394ae5c140692931eed8e7 (diff) | |
download | cgeo-65a15ca7c3634dddb5f2863965aabffc69b49541.zip cgeo-65a15ca7c3634dddb5f2863965aabffc69b49541.tar.gz cgeo-65a15ca7c3634dddb5f2863965aabffc69b49541.tar.bz2 |
fix #1347: no more caching of localized texts in enums
Diffstat (limited to 'main/src/cgeo')
9 files changed, 23 insertions, 78 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 7028b32..84cc467 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -2367,7 +2367,7 @@ public class CacheDetailActivity extends AbstractActivity { // info final List<String> infoTextList = new ArrayList<String>(3); - if (WaypointType.ALL_TYPES_EXCEPT_OWN.containsKey(wpt.getWaypointType())) { + if (WaypointType.ALL_TYPES_EXCEPT_OWN.contains(wpt.getWaypointType())) { infoTextList.add(wpt.getWaypointType().getL10n()); } if (cgWaypoint.PREFIX_OWN.equalsIgnoreCase(wpt.getPrefix())) { diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index be9d6a4..86f8824 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -3,12 +3,8 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.connector.gc.Login; -import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; -import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.HumanDistance; import cgeo.geocaching.geopoint.IConversion; @@ -517,29 +513,6 @@ public class cgeo extends AbstractActivity { initialized = true; Settings.setLanguage(Settings.isUseEnglish()); - - /* - * "update" the cache size/type. For a better performance - * the resource strings are stored in the enum's. In case of a - * locale change the resource strings don't get updated automatically. - * That's why we have to do it on our own. - */ - for (CacheSize cacheSize : CacheSize.values()) { - cacheSize.setL10n(); - } - for (CacheType cacheType : CacheType.values()) { - cacheType.setL10n(); - } - for (LogType logType : LogType.values()) { - logType.setL10n(); - } - for (WaypointType waypointType : WaypointType.values()) { - waypointType.setL10n(); - } - for (Strategy strategy : Strategy.values()) { - strategy.setL10n(); - } - Settings.getLogin(); if (app.firstRun) { diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java index aece2bf..196a8b3 100644 --- a/main/src/cgeo/geocaching/cgeowaypointadd.java +++ b/main/src/cgeo/geocaching/cgeowaypointadd.java @@ -142,7 +142,10 @@ public class cgeowaypointadd extends AbstractActivity { Button addWaypoint = (Button) findViewById(R.id.add_waypoint); addWaypoint.setOnClickListener(new coordsListener()); - List<String> wayPointNames = new ArrayList<String>(WaypointType.ALL_TYPES_EXCEPT_OWN.values()); + List<String> wayPointNames = new ArrayList<String>(); + for (WaypointType wpt : WaypointType.ALL_TYPES_EXCEPT_OWN) { + wayPointNames.add(wpt.getL10n()); + } AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.name); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, wayPointNames); textView.setAdapter(adapter); @@ -214,7 +217,7 @@ public class cgeowaypointadd extends AbstractActivity { Spinner waypointTypeSelector = (Spinner) findViewById(R.id.type); - wpTypes = new ArrayList<WaypointType>(WaypointType.ALL_TYPES_EXCEPT_OWN.keySet()); + wpTypes = new ArrayList<WaypointType>(WaypointType.ALL_TYPES_EXCEPT_OWN); ArrayAdapter<WaypointType> wpAdapter = new ArrayAdapter<WaypointType>(this, android.R.layout.simple_spinner_item, wpTypes.toArray(new WaypointType[wpTypes.size()])); wpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); waypointTypeSelector.setAdapter(wpAdapter); diff --git a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java index 3dbfce5..46e198f 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java +++ b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java @@ -81,9 +81,6 @@ public enum CacheAttribute { public static final String INTERNAL_YES = "_yes"; public static final String INTERNAL_NO = "_no"; - private static final Resources res = cgeoapplication.getInstance().getResources(); - private static final String packageName = cgeoapplication.getInstance().getBaseContext().getPackageName(); - public final int id; public final String gcRawName; @@ -95,9 +92,15 @@ public enum CacheAttribute { public String getL10n(final boolean enabled) { final String attributeDescriptor = INTERNAL_PRE + gcRawName + (enabled ? INTERNAL_YES : INTERNAL_NO); - int id = res.getIdentifier(attributeDescriptor, "string", packageName); + cgeoapplication instance = cgeoapplication.getInstance(); + if (instance != null) { + Resources res = instance.getResources(); + int id = res.getIdentifier(attributeDescriptor, "string", instance.getBaseContext().getPackageName()); - return (id > 0) ? res.getString(id) : attributeDescriptor; + return (id > 0) ? res.getString(id) : attributeDescriptor; + } else { + return attributeDescriptor; + } } private final static Map<String, CacheAttribute> FIND_BY_GCRAWNAME; diff --git a/main/src/cgeo/geocaching/enumerations/CacheSize.java b/main/src/cgeo/geocaching/enumerations/CacheSize.java index 9b0a559..b20a227 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheSize.java +++ b/main/src/cgeo/geocaching/enumerations/CacheSize.java @@ -25,13 +25,11 @@ public enum CacheSize { public final String id; public final int comparable; private final int stringId; - private String l10n; // not final because the locale can be changed private CacheSize(String id, int comparable, int stringId) { this.id = id; this.comparable = comparable; this.stringId = stringId; - setL10n(); } final private static Map<String, CacheSize> FIND_BY_ID; @@ -61,12 +59,7 @@ public enum CacheSize { } public final String getL10n() { - return l10n; + return cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } - - public void setL10n() { - this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); - } - } diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java index daada06..482418e 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheType.java +++ b/main/src/cgeo/geocaching/enumerations/CacheType.java @@ -37,7 +37,6 @@ public enum CacheType { public final String pattern; public final String guid; private final int stringId; - private String l10n; // not final because the locale can be changed public final int markerId; private CacheType(String id, String pattern, String guid, int stringId, int markerId) { @@ -45,7 +44,6 @@ public enum CacheType { this.pattern = pattern; this.guid = guid; this.stringId = stringId; - setL10n(); this.markerId = markerId; } @@ -79,11 +77,7 @@ public enum CacheType { } public final String getL10n() { - return l10n; - } - - public void setL10n() { - this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(this.stringId); + return cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } public boolean isEvent() { diff --git a/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java b/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java index 0f0b721..c4782d8 100644 --- a/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java +++ b/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java @@ -28,13 +28,11 @@ public interface LiveMapStrategy { public final int id; public final EnumSet<StrategyFlag> flags; private final int stringId; - private String l10n; // not final because the locale can be changed private Strategy(int id, EnumSet<StrategyFlag> flags, int stringId) { this.id = id; this.flags = flags; this.stringId = stringId; - setL10n(); } public final static Strategy getById(final int id) { @@ -47,12 +45,7 @@ public interface LiveMapStrategy { } public final String getL10n() { - return l10n; - } - - public void setL10n() { - this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(this.stringId); + return cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } } - } diff --git a/main/src/cgeo/geocaching/enumerations/LogType.java b/main/src/cgeo/geocaching/enumerations/LogType.java index e5f854b..14be6a1 100644 --- a/main/src/cgeo/geocaching/enumerations/LogType.java +++ b/main/src/cgeo/geocaching/enumerations/LogType.java @@ -45,14 +45,12 @@ public enum LogType { public final String iconName; public final String type; private final int stringId; - private String l10n; // not final because the locale can be changed private LogType(int id, String iconName, String type, int stringId) { this.id = id; this.iconName = iconName; this.type = type; this.stringId = stringId; - setL10n(); } private final static Map<String, LogType> FIND_BY_ICONNAME; @@ -94,12 +92,6 @@ public enum LogType { } public final String getL10n() { - return l10n; + return cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } - - public void setL10n() { - this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(this.stringId); - } - } - diff --git a/main/src/cgeo/geocaching/enumerations/WaypointType.java b/main/src/cgeo/geocaching/enumerations/WaypointType.java index 78e5ceb..44004c0 100644 --- a/main/src/cgeo/geocaching/enumerations/WaypointType.java +++ b/main/src/cgeo/geocaching/enumerations/WaypointType.java @@ -5,7 +5,9 @@ import cgeo.geocaching.cgeoapplication; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; /** * Enum listing waypoint types @@ -23,13 +25,11 @@ public enum WaypointType { public final String id; public final int stringId; - private String l10n; // not final because the locale can be changed public final int markerId; private WaypointType(String id, int stringId, int markerId) { this.id = id; this.stringId = stringId; - setL10n(); this.markerId = markerId; } @@ -38,13 +38,13 @@ public enum WaypointType { * non public so that <code>null</code> handling can be handled centrally in the enum type itself */ private static final Map<String, WaypointType> FIND_BY_ID; - public static final Map<WaypointType, String> ALL_TYPES_EXCEPT_OWN = new HashMap<WaypointType, String>(); + public static final Set<WaypointType> ALL_TYPES_EXCEPT_OWN = new HashSet<WaypointType>(); static { final HashMap<String, WaypointType> mapping = new HashMap<String, WaypointType>(); for (WaypointType wt : values()) { mapping.put(wt.id, wt); if (wt != WaypointType.OWN) { - ALL_TYPES_EXCEPT_OWN.put(wt, wt.getL10n()); + ALL_TYPES_EXCEPT_OWN.add(wt); } } FIND_BY_ID = Collections.unmodifiableMap(mapping); @@ -66,15 +66,9 @@ public enum WaypointType { } public final String getL10n() { - return l10n; + return cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } - public void setL10n() { - this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(this.stringId); - if (WaypointType.ALL_TYPES_EXCEPT_OWN != null && WaypointType.ALL_TYPES_EXCEPT_OWN.containsKey(this)) { - WaypointType.ALL_TYPES_EXCEPT_OWN.put(this, this.getL10n()); - } - } @Override public final String toString() { |