diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-04-21 11:27:29 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-04-21 11:27:29 +0200 |
| commit | fb453e599fed716636b6056739f17e318d55d25c (patch) | |
| tree | 0b50af7331b93c5abca433a582f16521de7e0f6c /main/src | |
| parent | 47ae07d7cec5d0a4e3a6b6f7bc79f03ef055716e (diff) | |
| download | cgeo-fb453e599fed716636b6056739f17e318d55d25c.zip cgeo-fb453e599fed716636b6056739f17e318d55d25c.tar.gz cgeo-fb453e599fed716636b6056739f17e318d55d25c.tar.bz2 | |
refactorings
* always use CacheAttribute for attribute strings
* avoid concatenation in append
* use SparseArray instead of maps
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/CacheCache.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 21 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoimages.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/enumerations/CacheAttribute.java | 12 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/export/FieldnoteExport.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 12 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/MapProviderFactory.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheListAdapter.java | 13 |
10 files changed, 43 insertions, 43 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java index 41380fa..cce1943 100644 --- a/main/src/cgeo/geocaching/CacheCache.java +++ b/main/src/cgeo/geocaching/CacheCache.java @@ -106,7 +106,7 @@ public class CacheCache { return StringUtils.join(cachesCache.keySet(), ' '); } - private class CacheRemoveHandler implements RemoveHandler<cgCache> { + private static class CacheRemoveHandler implements RemoveHandler<cgCache> { @Override public void onRemove(cgCache removed) { diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 7a74dbc..92df3be 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1217,11 +1217,6 @@ public class CacheDetailActivity extends AbstractActivity { noAttributeIconsFound = true; for (String attributeName : cache.getAttributes()) { - boolean strikethru = attributeName.endsWith("_no"); - // cut off _yes / _no - if (attributeName.endsWith("_no") || attributeName.endsWith("_yes")) { - attributeName = attributeName.substring(0, attributeName.lastIndexOf('_')); - } // check if another attribute icon fits in this row attributeRow.measure(0, 0); int rowWidth = attributeRow.getMeasuredWidth(); @@ -1233,7 +1228,8 @@ public class CacheDetailActivity extends AbstractActivity { rows.addView(attributeRow); } - CacheAttribute attrib = CacheAttribute.getByGcRawName(attributeName); + final boolean strikethru = !CacheAttribute.isEnabled(attributeName); + final CacheAttribute attrib = CacheAttribute.getByGcRawName(CacheAttribute.trimAttributeName(attributeName)); if (attrib != CacheAttribute.UNKNOWN) { noAttributeIconsFound = false; Drawable d = res.getDrawable(attrib.drawableId); @@ -1275,18 +1271,11 @@ public class CacheDetailActivity extends AbstractActivity { final List<String> attributes = cache.getAttributes(); for (String attributeName : attributes) { - boolean negated = attributeName.endsWith("_no"); - // cut off _yes / _no - if (attributeName.endsWith("_no") || attributeName.endsWith("_yes")) { - attributeName = attributeName.substring(0, attributeName.lastIndexOf('_')); - } + final boolean enabled = CacheAttribute.isEnabled(attributeName); // search for a translation of the attribute - CacheAttribute attrib = CacheAttribute.getByGcRawName(attributeName); + CacheAttribute attrib = CacheAttribute.getByGcRawName(CacheAttribute.trimAttributeName(attributeName)); if (attrib != CacheAttribute.UNKNOWN) { - String translated = res.getString(negated ? attrib.stringIdNo : attrib.stringIdYes); - if (StringUtils.isNotBlank(translated)) { - attributeName = translated; - } + attributeName = attrib.getL10n(enabled); } if (buffer.length() > 0) { buffer.append('\n'); diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index c70b19f..71e9849 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -3096,8 +3096,7 @@ public class cgData { query.append(i > 0 ? ", " : "").append(dbTableWaypoints).append('.').append(WAYPOINT_COLUMNS[i]).append(' '); } query.append(" FROM ").append(dbTableWaypoints).append(", ").append(dbTableCaches).append(" WHERE ").append(dbTableWaypoints).append("._id == ").append(dbTableCaches).append("._id and ").append(where); - Cursor cursor = databaseRO.rawQuery( - query.toString(), null); + Cursor cursor = databaseRO.rawQuery(query.toString(), null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java index bac0cad..10b8b21 100644 --- a/main/src/cgeo/geocaching/cgeoimages.java +++ b/main/src/cgeo/geocaching/cgeoimages.java @@ -19,6 +19,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.text.Html; +import android.util.SparseArray; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; @@ -34,7 +35,6 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; public class cgeoimages extends AbstractActivity { @@ -51,7 +51,7 @@ public class cgeoimages extends AbstractActivity { private LinearLayout imagesView = null; private int count = 0; private int countDone = 0; - private final HashMap<Integer, cgImage> images = new HashMap<Integer, cgImage>(); + private final SparseArray<cgImage> images = new SparseArray<cgImage>(); private BitmapDrawable currentDrawable; private cgImage currentImage; diff --git a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java index 459c829..4a502fb 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java +++ b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java @@ -3,6 +3,8 @@ package cgeo.geocaching.enumerations; import cgeo.geocaching.R; import cgeo.geocaching.cgeoapplication; +import org.apache.commons.lang3.StringUtils; + import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -76,9 +78,9 @@ public enum CacheAttribute { FRONTYARD(65, "frontyard", R.drawable.attribute_frontyard, R.string.attribute_frontyard_yes, R.string.attribute_frontyard_no), TEAMWORK(66, "teamwork", R.drawable.attribute_teamwork, R.string.attribute_teamwork_yes, R.string.attribute_teamwork_no); - public static final String INTERNAL_PRE = "attribute_"; - public static final String INTERNAL_YES = "_yes"; - public static final String INTERNAL_NO = "_no"; + private static final String INTERNAL_PRE = "attribute_"; + private static final String INTERNAL_YES = "_yes"; + private static final String INTERNAL_NO = "_no"; public final int id; public final String gcRawName; @@ -131,4 +133,8 @@ public enum CacheAttribute { } return attributeName.replace(INTERNAL_PRE, "").replace(INTERNAL_YES, "").replace(INTERNAL_NO, "").trim(); } + + public static boolean isEnabled(final String attributeName) { + return !StringUtils.endsWithIgnoreCase(attributeName, INTERNAL_NO); + } } diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java index 05fb828..50cc620 100644 --- a/main/src/cgeo/geocaching/export/FieldnoteExport.java +++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java @@ -161,7 +161,7 @@ class FieldnoteExport extends AbstractExport { } } - fieldNoteBuffer.append("\n"); + fieldNoteBuffer.append('\n'); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { exportLocation.mkdirs(); diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index 2c833a2..90ff7a0 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -1,8 +1,8 @@ package cgeo.geocaching.export; +import cgeo.geocaching.LogEntry; import cgeo.geocaching.R; import cgeo.geocaching.cgCache; -import cgeo.geocaching.LogEntry; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.activity.Progress; @@ -90,8 +90,8 @@ class GpxExport extends AbstractExport { } gpx.append("<wpt "); - gpx.append("lat=\"" + cache.getCoords().getLatitude() + "\" "); - gpx.append("lon=\"" + cache.getCoords().getLongitude() + "\">"); + gpx.append("lat=\"").append(cache.getCoords().getLatitude()).append("\" "); + gpx.append("lon=\"").append(cache.getCoords().getLongitude()).append("\">"); gpx.append("<time>"); gpx.append(StringEscapeUtils.escapeXml(dateFormatZ.format(cache.getHiddenDate()))); @@ -114,8 +114,8 @@ class GpxExport extends AbstractExport { gpx.append("</type>"); gpx.append("<groundspeak:cache "); - gpx.append("available=\"" + (!cache.isDisabled() ? "True" : "False")); - gpx.append("\" archived=\"" + (cache.isArchived() ? "True" : "False") + "\" "); + gpx.append("available=\"").append(!cache.isDisabled() ? "True" : "False"); + gpx.append("\" archived=\"").append(cache.isArchived() ? "True" : "False").append("\" "); gpx.append("xmlns:groundspeak=\"http://www.groundspeak.com/cache/1/0/1\">"); gpx.append("<groundspeak:name>"); @@ -144,7 +144,7 @@ class GpxExport extends AbstractExport { for (String attribute : cache.getAttributes()) { final CacheAttribute attr = CacheAttribute.getByGcRawName(CacheAttribute.trimAttributeName(attribute)); - final boolean enabled = attribute.endsWith(CacheAttribute.INTERNAL_YES); + final boolean enabled = CacheAttribute.isEnabled(attribute); gpx.append("<groundspeak:attribute id=\""); gpx.append(attr.id); diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 42f12a9..0e43e78 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -54,6 +54,7 @@ import android.graphics.drawable.LayerDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.util.SparseArray; import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; @@ -66,10 +67,8 @@ import android.widget.TextView; import android.widget.ViewSwitcher.ViewFactory; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; @@ -163,7 +162,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto private static final int[][] INSET_USERMODIFIEDCOORDS = { { 21, 28, 0, 0 }, { 19, 25, 0, 0 } }; // bottom right, 12x12 / 26x26 private static final int[][] INSET_PERSONALNOTE = { { 0, 28, 21, 0 }, { 0, 25, 19, 0 } }; // bottom left, 12x12 / 26x26 - private static Map<Integer, LayerDrawable> overlaysCache = new HashMap<Integer, LayerDrawable>(); + private static SparseArray<LayerDrawable> overlaysCache = new SparseArray<LayerDrawable>(); private int cachesCnt = 0; /** List of caches in the viewport */ private final LeastRecentlyUsedSet<cgCache> caches = new LeastRecentlyUsedSet<cgCache>(MAX_CACHES); @@ -1414,7 +1413,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } - private abstract class DoRunnable implements Runnable { + private static abstract class DoRunnable implements Runnable { final protected Viewport viewport; diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java index c7c85f5..3509209 100644 --- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java +++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java @@ -16,15 +16,21 @@ public class MapProviderFactory { private static MapProviderFactory instance = null; - private MapProvider[] mapProviders; + private final MapProvider[] mapProviders; private SortedMap<Integer, String> mapSources; private MapProviderFactory() { // add GoogleMapProvider only if google api is available in order to support x86 android emulator + boolean googleMaps = true; try { Class.forName("com.google.android.maps.MapActivity"); - mapProviders = new MapProvider[] { new GoogleMapProvider(GOOGLEMAP_BASEID), new MapsforgeMapProvider(MFMAP_BASEID) }; } catch (ClassNotFoundException e) { + googleMaps = false; + } + if (googleMaps) { + mapProviders = new MapProvider[] { new GoogleMapProvider(GOOGLEMAP_BASEID), new MapsforgeMapProvider(MFMAP_BASEID) }; + } + else { mapProviders = new MapProvider[] { new MapsforgeMapProvider(MFMAP_BASEID) }; } diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 54f4505..2735a94 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -28,6 +28,7 @@ import android.text.Spannable; import android.text.Spanned; import android.text.style.StrikethroughSpan; import android.util.DisplayMetrics; +import android.util.SparseArray; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -46,10 +47,8 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Set; public class CacheListAdapter extends ArrayAdapter<cgCache> { @@ -66,7 +65,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private boolean sort = true; private int checked = 0; private boolean selectMode = false; - final private static Map<Integer, Drawable> gcIconDrawables = new HashMap<Integer, Drawable>(); + final private static SparseArray<Drawable> gcIconDrawables = new SparseArray<Drawable>(); final private Set<CompassMiniView> compasses = new LinkedHashSet<CompassMiniView>(); final private Set<DistanceView> distances = new LinkedHashSet<DistanceView>(); final private int[] ratingBcgs = new int[3]; @@ -613,11 +612,13 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private static Drawable getCacheIcon(cgCache cache) { int hashCode = getIconHashCode(cache.getType(), cache.hasUserModifiedCoords() || cache.hasFinalDefined()); - if (!gcIconDrawables.containsKey(hashCode)) { - // fallback to mystery icon - hashCode = getIconHashCode(CacheType.MYSTERY, cache.hasUserModifiedCoords() || cache.hasFinalDefined()); + Drawable drawable = gcIconDrawables.get(hashCode); + if (drawable != null) { + return drawable; } + // fallback to mystery icon + hashCode = getIconHashCode(CacheType.MYSTERY, cache.hasUserModifiedCoords() || cache.hasFinalDefined()); return gcIconDrawables.get(hashCode); } |
