diff options
| author | bananeweizen <bananeweizen@gmx.de> | 2011-08-30 21:34:59 +0200 |
|---|---|---|
| committer | bananeweizen <bananeweizen@gmx.de> | 2011-08-30 21:34:59 +0200 |
| commit | 5d0ae5674e92d70e97eea7e482ff861784332f95 (patch) | |
| tree | 7b6e0f48543ea4d49abf7398aa6b4ff16230689c /src/cgeo/geocaching/cgBase.java | |
| parent | 246b7fce698c59bbfd94a8fbd88259a5681efdc1 (diff) | |
| download | cgeo-5d0ae5674e92d70e97eea7e482ff861784332f95.zip cgeo-5d0ae5674e92d70e97eea7e482ff861784332f95.tar.gz cgeo-5d0ae5674e92d70e97eea7e482ff861784332f95.tar.bz2 | |
refactoring: remove duplicate code
Diffstat (limited to 'src/cgeo/geocaching/cgBase.java')
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 126 |
1 files changed, 77 insertions, 49 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index c8a5f14..79e67b5 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -5022,9 +5022,85 @@ public class cgBase { } return out; } + + public static int getCacheIcon(final String type) { + fillIconsMap(); + Integer iconId = gcIcons.get("type_" + type); + if (iconId != null) { + return iconId; + } + // fallback to traditional if some icon type is not correct + return gcIcons.get("type_traditional"); + } + + public static int getMarkerIcon(final boolean cache, final String type, final boolean own, final boolean found, final boolean disabled) { + fillIconsMap(); + + if (wpIcons.isEmpty()) { + wpIcons.put("waypoint", R.drawable.marker_waypoint_waypoint); + wpIcons.put("flag", R.drawable.marker_waypoint_flag); + wpIcons.put("pkg", R.drawable.marker_waypoint_pkg); + wpIcons.put("puzzle", R.drawable.marker_waypoint_puzzle); + wpIcons.put("stage", R.drawable.marker_waypoint_stage); + wpIcons.put("trailhead", R.drawable.marker_waypoint_trailhead); + } + + int icon = -1; + String iconTxt = null; + + if (cache) { + if (type != null && type.length() > 0) { + if (own) { + iconTxt = type + "-own"; + } else if (found) { + iconTxt = type + "-found"; + } else if (disabled) { + iconTxt = type + "-disabled"; + } else { + iconTxt = type; + } + } else { + iconTxt = "traditional"; + } + + if (gcIcons.containsKey(iconTxt)) { + icon = gcIcons.get(iconTxt); + } else { + icon = gcIcons.get("traditional"); + } + } else { + if (type != null && type.length() > 0) { + iconTxt = type; + } else { + iconTxt = "waypoint"; + } + + if (wpIcons.containsKey(iconTxt)) { + icon = wpIcons.get(iconTxt); + } else { + icon = wpIcons.get("waypoint"); + } + } + + return icon; + } - public static int getIcon(boolean cache, String type, boolean own, boolean found, boolean disabled) { + private static void fillIconsMap() { if (gcIcons.isEmpty()) { + gcIcons.put("type_ape", R.drawable.type_ape); + gcIcons.put("type_cito", R.drawable.type_cito); + gcIcons.put("type_earth", R.drawable.type_earth); + gcIcons.put("type_event", R.drawable.type_event); + gcIcons.put("type_letterbox", R.drawable.type_letterbox); + gcIcons.put("type_locationless", R.drawable.type_locationless); + gcIcons.put("type_mega", R.drawable.type_mega); + gcIcons.put("type_multi", R.drawable.type_multi); + gcIcons.put("type_traditional", R.drawable.type_traditional); + gcIcons.put("type_virtual", R.drawable.type_virtual); + gcIcons.put("type_webcam", R.drawable.type_webcam); + gcIcons.put("type_wherigo", R.drawable.type_wherigo); + gcIcons.put("type_mystery", R.drawable.type_mystery); + gcIcons.put("type_gchq", R.drawable.type_hq); // default markers gcIcons.put("ape", R.drawable.marker_cache_ape); gcIcons.put("cito", R.drawable.marker_cache_cito); @@ -5086,54 +5162,6 @@ public class cgBase { gcIcons.put("mystery-disabled", R.drawable.marker_cache_mystery_disabled); gcIcons.put("gchq-disabled", R.drawable.marker_cache_gchq_disabled); } - - if (wpIcons.isEmpty()) { - wpIcons.put("waypoint", R.drawable.marker_waypoint_waypoint); - wpIcons.put("flag", R.drawable.marker_waypoint_flag); - wpIcons.put("pkg", R.drawable.marker_waypoint_pkg); - wpIcons.put("puzzle", R.drawable.marker_waypoint_puzzle); - wpIcons.put("stage", R.drawable.marker_waypoint_stage); - wpIcons.put("trailhead", R.drawable.marker_waypoint_trailhead); - } - - int icon = -1; - String iconTxt = null; - - if (cache) { - if (type != null && type.length() > 0) { - if (own) { - iconTxt = type + "-own"; - } else if (found) { - iconTxt = type + "-found"; - } else if (disabled) { - iconTxt = type + "-disabled"; - } else { - iconTxt = type; - } - } else { - iconTxt = "traditional"; - } - - if (gcIcons.containsKey(iconTxt)) { - icon = gcIcons.get(iconTxt); - } else { - icon = gcIcons.get("traditional"); - } - } else { - if (type != null && type.length() > 0) { - iconTxt = type; - } else { - iconTxt = "waypoint"; - } - - if (wpIcons.containsKey(iconTxt)) { - icon = wpIcons.get(iconTxt); - } else { - icon = wpIcons.get("waypoint"); - } - } - - return icon; } public static boolean runNavigation(Activity activity, Resources res, cgSettings settings, Double latitude, Double longitude) { |
