diff options
14 files changed, 79 insertions, 112 deletions
diff --git a/main/src/cgeo/geocaching/Image.java b/main/src/cgeo/geocaching/Image.java index f592fc1..5c0e4f0 100644 --- a/main/src/cgeo/geocaching/Image.java +++ b/main/src/cgeo/geocaching/Image.java @@ -31,7 +31,7 @@ public class Image implements Parcelable { } public Image(final File file) { - this("file://" + file.getAbsolutePath(), file.getName(), null); + this(FileUtils.fileToUrl(file), file.getName(), null); } public Image(final Parcel in) { @@ -46,7 +46,7 @@ public class Image implements Parcelable { } @Override - public void writeToParcel(Parcel dest, int flags) { + public void writeToParcel(final Parcel dest, final int flags) { dest.writeString(url); dest.writeString(title); dest.writeString(description); @@ -54,12 +54,12 @@ public class Image implements Parcelable { public static final Parcelable.Creator<Image> CREATOR = new Parcelable.Creator<Image>() { @Override - public Image createFromParcel(Parcel in) { + public Image createFromParcel(final Parcel in) { return new Image(in); } @Override - public Image[] newArray(int size) { + public Image[] newArray(final int size) { return new Image[size]; } }; diff --git a/main/src/cgeo/geocaching/apps/AbstractAppFactory.java b/main/src/cgeo/geocaching/apps/AbstractAppFactory.java deleted file mode 100644 index 945f7d6..0000000 --- a/main/src/cgeo/geocaching/apps/AbstractAppFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package cgeo.geocaching.apps; - -import android.view.MenuItem; - -public abstract class AbstractAppFactory { - - protected static App getAppFromMenuItem(MenuItem item, final App[] availableApps) { - final int id = item.getItemId(); - for (App app : availableApps) { - if (app.getId() == id) { - return app; - } - } - return null; - } -} diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 48fe754..32eba7e 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -5,7 +5,6 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.apps.AbstractAppFactory; import cgeo.geocaching.apps.App; import cgeo.geocaching.apps.cache.WhereYouGoApp; import cgeo.geocaching.apps.cache.navi.GoogleNavigationApp.GoogleNavigationBikeApp; @@ -25,7 +24,7 @@ import android.widget.ArrayAdapter; import java.util.ArrayList; import java.util.List; -public final class NavigationAppFactory extends AbstractAppFactory { +public final class NavigationAppFactory { private NavigationAppFactory() { // utility class diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java index 946d20e..f599611 100644 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java @@ -11,11 +11,6 @@ import android.view.WindowManager; class AndroidLevel13 implements AndroidLevel13Interface { @Override - public int getDisplayWidth() { - return getDisplaySize().x; - } - - @Override public Point getDisplaySize() { final Point dimensions = new Point(); ((WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE)) diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java index 8e2e7ec..f9fd3bc 100644 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java @@ -11,11 +11,6 @@ import android.view.WindowManager; class AndroidLevel13Emulation implements AndroidLevel13Interface { @Override - public int getDisplayWidth() { - return getDisplay().getWidth(); - } - - @Override public Point getDisplaySize() { final Display display = getDisplay(); return new Point(display.getWidth(), display.getHeight()); diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java index 6d3f3c3..b78875f 100644 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java @@ -3,7 +3,6 @@ package cgeo.geocaching.compatibility; import android.graphics.Point; interface AndroidLevel13Interface { - int getDisplayWidth(); Point getDisplaySize(); } diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java index ad16172..56e18bf 100644 --- a/main/src/cgeo/geocaching/compatibility/Compatibility.java +++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java @@ -25,10 +25,6 @@ public final class Compatibility { // utility class } - public static int getDisplayWidth() { - return LEVEL_13.getDisplayWidth(); - } - public static Point getDisplaySize() { return LEVEL_13.getDisplaySize(); } diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index 5d59613..243d84c 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -11,8 +11,8 @@ import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.GeopointFormatter.Format; import cgeo.geocaching.location.Units; import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.LiveMapStrategy.Strategy; -import cgeo.geocaching.maps.LiveMapStrategy.StrategyFlag; +import cgeo.geocaching.maps.LivemapStrategy; +import cgeo.geocaching.maps.LivemapStrategy.Flag; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.sensors.Sensors; import cgeo.geocaching.settings.Settings; @@ -110,7 +110,7 @@ public class GCMap { * Retrieved data. * @return SearchResult. Never null. */ - public static SearchResult parseMapJSON(final String data, final Tile tile, final Bitmap bitmap, final Strategy strategy) { + public static SearchResult parseMapJSON(final String data, final Tile tile, final Bitmap bitmap, final LivemapStrategy strategy) { final SearchResult searchResult = new SearchResult(); try { @@ -185,7 +185,7 @@ public class GCMap { cache.setGeocode(id); cache.setName(nameCache.get(id)); cache.setCoords(tile.getCoord(xy), tile.getZoomLevel()); - if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && bitmap != null) { + if (strategy.flags.contains(LivemapStrategy.Flag.PARSE_TILES) && bitmap != null) { for (final UTFGridPosition singlePos : singlePositions.get(id)) { if (IconDecoder.parseMapPNG(cache, bitmap, singlePos, tile.getZoomLevel())) { break; // cache parsed @@ -230,9 +230,9 @@ public class GCMap { @NonNull public static SearchResult searchByViewport(final Viewport viewport, final MapTokens tokens) { final int speed = (int) Sensors.getInstance().currentGeo().getSpeed() * 60 * 60 / 1000; // in km/h - Strategy strategy = Settings.getLiveMapStrategy(); - if (strategy == Strategy.AUTO) { - strategy = speed >= 30 ? Strategy.FAST : Strategy.DETAILED; + LivemapStrategy strategy = Settings.getLiveMapStrategy(); + if (strategy == LivemapStrategy.AUTO) { + strategy = speed >= 30 ? LivemapStrategy.FAST : LivemapStrategy.DETAILED; } final SearchResult result = searchByViewport(viewport, tokens, strategy); @@ -258,7 +258,7 @@ public class GCMap { * Strategy for data retrieval and parsing, @see Strategy */ @NonNull - private static SearchResult searchByViewport(final Viewport viewport, final MapTokens tokens, final Strategy strategy) { + private static SearchResult searchByViewport(final Viewport viewport, final MapTokens tokens, final LivemapStrategy strategy) { Log.d("GCMap.searchByViewport" + viewport.toString()); final SearchResult searchResult = new SearchResult(); @@ -267,7 +267,7 @@ public class GCMap { searchResult.setUrl(viewport.getCenter().format(Format.LAT_LON_DECMINUTE)); } - if (strategy.flags.contains(StrategyFlag.LOAD_TILES)) { + if (strategy.flags.contains(LivemapStrategy.Flag.LOAD_TILES)) { final Set<Tile> tiles = Tile.getTilesForViewport(viewport); if (Settings.isDebug()) { @@ -337,7 +337,7 @@ public class GCMap { } } - if (strategy.flags.contains(StrategyFlag.SEARCH_NEARBY) && Settings.isGCPremiumMember()) { + if (strategy.flags.contains(Flag.SEARCH_NEARBY) && Settings.isGCPremiumMember()) { final Geopoint center = viewport.getCenter(); if ((lastSearchViewport == null) || !lastSearchViewport.contains(center)) { //FIXME We don't have a RecaptchaReceiver!? diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 009e49d..b2bb8a6 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -23,7 +23,6 @@ import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.LiveMapStrategy.Strategy; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; @@ -770,22 +769,22 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } case R.id.menu_strategy_fastest: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.FASTEST); + Settings.setLiveMapStrategy(LivemapStrategy.FASTEST); return true; } case R.id.menu_strategy_fast: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.FAST); + Settings.setLiveMapStrategy(LivemapStrategy.FAST); return true; } case R.id.menu_strategy_auto: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.AUTO); + Settings.setLiveMapStrategy(LivemapStrategy.AUTO); return true; } case R.id.menu_strategy_detailed: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.DETAILED); + Settings.setLiveMapStrategy(LivemapStrategy.DETAILED); return true; } case R.id.menu_hint: diff --git a/main/src/cgeo/geocaching/maps/LiveMapStrategy.java b/main/src/cgeo/geocaching/maps/LiveMapStrategy.java deleted file mode 100644 index 16d5e8b..0000000 --- a/main/src/cgeo/geocaching/maps/LiveMapStrategy.java +++ /dev/null @@ -1,48 +0,0 @@ -package cgeo.geocaching.maps; - -import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.R; - -import java.util.EnumSet; - -/** - * Defines the strategy for the Live Map - */ -public interface LiveMapStrategy { - - public enum StrategyFlag { - LOAD_TILES, // 2x2 tiles filling the complete viewport - PARSE_TILES, // parse PNG images - SEARCH_NEARBY // searchByCoords() - } - - public enum Strategy { - FASTEST(1, EnumSet.of(StrategyFlag.LOAD_TILES), R.string.map_strategy_fastest), - FAST(2, EnumSet.of(StrategyFlag.LOAD_TILES, StrategyFlag.PARSE_TILES), R.string.map_strategy_fast), - AUTO(3, EnumSet.noneOf(StrategyFlag.class), R.string.map_strategy_auto), - DETAILED(4, EnumSet.allOf(StrategyFlag.class), R.string.map_strategy_detailed); - - public final int id; - public final EnumSet<StrategyFlag> flags; - private final int stringId; - - Strategy(int id, EnumSet<StrategyFlag> flags, int stringId) { - this.id = id; - this.flags = flags; - this.stringId = stringId; - } - - public static Strategy getById(final int id) { - for (Strategy strategy : Strategy.values()) { - if (strategy.id == id) { - return strategy; - } - } - return AUTO; - } - - public final String getL10n() { - return CgeoApplication.getInstance().getBaseContext().getResources().getString(stringId); - } - } -} diff --git a/main/src/cgeo/geocaching/maps/LivemapStrategy.java b/main/src/cgeo/geocaching/maps/LivemapStrategy.java new file mode 100644 index 0000000..c135fc8 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/LivemapStrategy.java @@ -0,0 +1,45 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.R; + +import java.util.EnumSet; + +/** + * Defines the strategy for the Live Map + */ +public enum LivemapStrategy { + FASTEST(1, EnumSet.of(Flag.LOAD_TILES), R.string.map_strategy_fastest), + FAST(2, EnumSet.of(Flag.LOAD_TILES, Flag.PARSE_TILES), R.string.map_strategy_fast), + AUTO(3, EnumSet.noneOf(Flag.class), R.string.map_strategy_auto), + DETAILED(4, EnumSet.allOf(Flag.class), R.string.map_strategy_detailed); + + public final int id; + public final EnumSet<Flag> flags; + private final int stringId; + + public enum Flag { + LOAD_TILES, // 2x2 tiles filling the complete viewport + PARSE_TILES, // parse PNG images + SEARCH_NEARBY // searchByCoords() + } + + LivemapStrategy(final int id, final EnumSet<Flag> flags, final int stringId) { + this.id = id; + this.flags = flags; + this.stringId = stringId; + } + + public static LivemapStrategy getById(final int id) { + for (final LivemapStrategy strategy : LivemapStrategy.values()) { + if (strategy.id == id) { + return strategy; + } + } + return AUTO; + } + + public final String getL10n() { + return CgeoApplication.getInstance().getBaseContext().getResources().getString(stringId); + } +} diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java index 3596d5f..1e69b44 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java @@ -33,5 +33,8 @@ public interface MapActivityImpl { boolean superOnOptionsItemSelected(MenuItem item); + /** + * called from the pseudo actionbar layout + */ public abstract void navigateUp(View view); } diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java index 0b54fe1..3d47f8b 100644 --- a/main/src/cgeo/geocaching/settings/Settings.java +++ b/main/src/cgeo/geocaching/settings/Settings.java @@ -11,8 +11,8 @@ import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.CGeoMap.MapMode; -import cgeo.geocaching.maps.LiveMapStrategy.Strategy; import cgeo.geocaching.maps.MapProviderFactory; +import cgeo.geocaching.maps.LivemapStrategy; import cgeo.geocaching.maps.google.v1.GoogleMapProvider; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapProvider; @@ -188,7 +188,7 @@ public class Settings { e.putInt(getKey(R.string.pref_lastdetailspage), prefsV0.getInt(getKey(R.string.pref_lastdetailspage), 1)); e.putInt(getKey(R.string.pref_defaultNavigationTool), prefsV0.getInt(getKey(R.string.pref_defaultNavigationTool), NavigationAppsEnum.COMPASS.id)); e.putInt(getKey(R.string.pref_defaultNavigationTool2), prefsV0.getInt(getKey(R.string.pref_defaultNavigationTool2), NavigationAppsEnum.INTERNAL_MAP.id)); - e.putInt(getKey(R.string.pref_livemapstrategy), prefsV0.getInt(getKey(R.string.pref_livemapstrategy), Strategy.AUTO.id)); + e.putInt(getKey(R.string.pref_livemapstrategy), prefsV0.getInt(getKey(R.string.pref_livemapstrategy), LivemapStrategy.AUTO.id)); e.putBoolean(getKey(R.string.pref_debug), prefsV0.getBoolean(getKey(R.string.pref_debug), false)); e.putInt(getKey(R.string.pref_livemaphintshowcount), prefsV0.getInt(getKey(R.string.pref_livemaphintshowcount), 0)); @@ -906,11 +906,11 @@ public class Settings { String.valueOf(NavigationAppsEnum.INTERNAL_MAP.id))); } - public static Strategy getLiveMapStrategy() { - return Strategy.getById(getInt(R.string.pref_livemapstrategy, Strategy.AUTO.id)); + public static LivemapStrategy getLiveMapStrategy() { + return LivemapStrategy.getById(getInt(R.string.pref_livemapstrategy, LivemapStrategy.AUTO.id)); } - public static void setLiveMapStrategy(final Strategy strategy) { + public static void setLiveMapStrategy(final LivemapStrategy strategy) { putInt(R.string.pref_livemapstrategy, strategy.id); } diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index d9716c0..cdcb55e 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -16,7 +16,7 @@ import cgeo.geocaching.list.StoredList; import cgeo.geocaching.loaders.RecaptchaReceiver; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.LiveMapStrategy.Strategy; +import cgeo.geocaching.maps.LivemapStrategy; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.test.RegExPerformanceTest; @@ -290,7 +290,7 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { // backup user settings - final Strategy strategy = Settings.getLiveMapStrategy(); + final LivemapStrategy strategy = Settings.getLiveMapStrategy(); final CacheType cacheType = Settings.getCacheType(); try { @@ -305,7 +305,7 @@ public class CgeoApplicationTest extends CGeoTestCase { final Viewport viewport = new Viewport(mockedCache, 0.003, 0.003); // check coords for DETAILED - Settings.setLiveMapStrategy(Strategy.DETAILED); + Settings.setLiveMapStrategy(LivemapStrategy.DETAILED); SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(search).isNotNull(); assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); @@ -317,7 +317,7 @@ public class CgeoApplicationTest extends CGeoTestCase { assertThat(parsedCache.isReliableLatLon()).isEqualTo(Settings.isGCPremiumMember()); // check update after switch strategy to FAST - Settings.setLiveMapStrategy(Strategy.FAST); + Settings.setLiveMapStrategy(LivemapStrategy.FAST); Tile.cache.removeFromTileCache(mockedCache); search = ConnectorFactory.searchByViewport(viewport, tokens); @@ -348,8 +348,8 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { - final Strategy strategy = Settings.getLiveMapStrategy(); - final Strategy testStrategy = Strategy.FAST; // FASTEST, FAST or DETAILED for tests + final LivemapStrategy strategy = Settings.getLiveMapStrategy(); + final LivemapStrategy testStrategy = LivemapStrategy.FAST; // FASTEST, FAST or DETAILED for tests Settings.setLiveMapStrategy(testStrategy); final CacheType cacheType = Settings.getCacheType(); @@ -374,7 +374,7 @@ public class CgeoApplicationTest extends CGeoTestCase { Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cacheFromViewport.getCoords()); assertThat(cache.getCoords().distanceTo(cacheFromViewport.getCoords()) <= 1e-3).isFalse(); // depending on the chosen strategy the coords can be reliable or not - assertThat(cacheFromViewport.isReliableLatLon()).isEqualTo(testStrategy == Strategy.DETAILED); + assertThat(cacheFromViewport.isReliableLatLon()).isEqualTo(testStrategy == LivemapStrategy.DETAILED); // premium cache cache = new GC2JVEH(); |