diff options
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 12 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgLog.java | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCBase.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/Tile.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/enumerations/LoadFlags.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/FileList.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXImporter.java | 13 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/OtherCachersOverlay.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/Login.java | 25 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/LogTemplateProvider.java | 9 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/WhitespaceTest.java | 2 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/mock/MockedCache.java | 2 |
16 files changed, 60 insertions, 64 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 349a73f..1be9ed6 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -39,7 +39,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; @@ -326,13 +325,6 @@ public class CacheDetailActivity extends AbstractActivity { } @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - - // Maybe keyboard hidden or display orientation changed. No need for update the UI or something else. - } - - @Override public void onResume() { super.onResume(); @@ -820,7 +812,7 @@ public class CacheDetailActivity extends AbstractActivity { new AlertDialog.Builder(this) .setTitle(res.getString(R.string.addon_missing_title)) .setMessage(new StringBuilder(res.getString(R.string.helper_calendar_missing)) - .append(" ") + .append(' ') .append(res.getString(R.string.addon_download_prompt)) .toString()) .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() { @@ -2200,7 +2192,7 @@ public class CacheDetailActivity extends AbstractActivity { view = (ListView) getLayoutInflater().inflate(R.layout.cacheview_logs, null); // log count - if (cache != null && cache.getLogCounts() != null) { + if (cache.getLogCounts() != null) { boolean showLogCounter = false; final StringBuilder text = new StringBuilder(200); diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 85dc4d4..155d150 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -335,9 +335,9 @@ public class cgCache implements ICache { guid.equalsIgnoreCase(other.guid) && hint.equalsIgnoreCase(other.hint) && cacheId.equalsIgnoreCase(other.cacheId) && - direction == other.direction && - distance == other.distance && - elevation == other.elevation && + (direction != null ? direction.equals(other.direction) : null == other.direction) && + (distance != null ? distance.equals(other.distance) : null == other.distance) && + (elevation != null ? elevation.equals(other.elevation) : null == other.elevation) && nameSp == other.nameSp && rating == other.rating && votes == other.votes && @@ -1410,10 +1410,7 @@ public class cgCache implements ICache { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof cgCache)) { return false; } // just compare the geocode even if that is not what "equals" normaly does diff --git a/main/src/cgeo/geocaching/cgLog.java b/main/src/cgeo/geocaching/cgLog.java index 6bf807a..2b3568d 100644 --- a/main/src/cgeo/geocaching/cgLog.java +++ b/main/src/cgeo/geocaching/cgLog.java @@ -27,10 +27,7 @@ public class cgLog { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof cgLog)) { return false; } final cgLog otherLog = (cgLog) obj; diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index fa5ca02..21ecb5e 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -2082,7 +2082,7 @@ public class cgeocaches extends AbstractListActivity { public void run() { SimpleDateFormat fieldNoteDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - StringBuffer fieldNoteBuffer = new StringBuffer(500); + StringBuilder fieldNoteBuffer = new StringBuilder(500); // We need our own HashMap because LogType will give us localized and maybe // different strings than gc.com expects in the field note diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java index 1af41c3..bb0a06a 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCBase.java +++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; /** @@ -258,8 +259,9 @@ public class GCBase { } } - for (String id : positions.keySet()) { - List<UTFGridPosition> pos = positions.get(id); + for (Entry<String, List<UTFGridPosition>> entry : positions.entrySet()) { + String id = entry.getKey(); + List<UTFGridPosition> pos = entry.getValue(); UTFGridPosition xy = UTFGrid.getPositionInGrid(pos); cgCache cache = new cgCache(); cache.setDetailed(false); @@ -439,7 +441,7 @@ public class GCBase { cache.setDisabled(!dataObject.getBoolean("available")); cache.setArchived(dataObject.getBoolean("archived")); cache.setPremiumMembersOnly(dataObject.getBoolean("subrOnly")); - boolean li = dataObject.getBoolean("li"); // seems to be "false" always + // "li" seems to be "false" always cache.setFavoritePoints(Integer.parseInt(dataObject.getString("fp"))); JSONObject difficultyObj = dataObject.getJSONObject("difficulty"); cache.setDifficulty(Float.parseFloat(difficultyObj.getString("text"))); // 3.5 @@ -460,6 +462,8 @@ public class GCBase { result.setError(StatusCode.UNKNOWN_ERROR); } catch (ParseException e) { result.setError(StatusCode.UNKNOWN_ERROR); + } catch (NumberFormatException e) { + result.setError(StatusCode.UNKNOWN_ERROR); } return result; } diff --git a/main/src/cgeo/geocaching/connector/gc/Tile.java b/main/src/cgeo/geocaching/connector/gc/Tile.java index b76cae9..8613787 100644 --- a/main/src/cgeo/geocaching/connector/gc/Tile.java +++ b/main/src/cgeo/geocaching/connector/gc/Tile.java @@ -33,8 +33,8 @@ public class Tile { public static final int ZOOMLEVEL_MAX = 18; public static final int ZOOMLEVEL_MIN = 0; - public static final int[] NUMBER_OF_TILES = new int[ZOOMLEVEL_MAX - ZOOMLEVEL_MIN + 1]; - public static final int[] NUMBER_OF_PIXELS = new int[ZOOMLEVEL_MAX - ZOOMLEVEL_MIN + 1]; + static final int[] NUMBER_OF_TILES = new int[ZOOMLEVEL_MAX - ZOOMLEVEL_MIN + 1]; + static final int[] NUMBER_OF_PIXELS = new int[ZOOMLEVEL_MAX - ZOOMLEVEL_MIN + 1]; static { for (int z = ZOOMLEVEL_MIN; z <= ZOOMLEVEL_MAX; z++) { NUMBER_OF_TILES[z] = 1 << z; diff --git a/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java b/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java index 834cdb8..0f0b721 100644 --- a/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java +++ b/main/src/cgeo/geocaching/enumerations/LiveMapStrategy.java @@ -9,9 +9,9 @@ import java.util.EnumSet; * Defines the strategy for the Live Map * * @author blafoo - * + * */ -public class LiveMapStrategy { +public interface LiveMapStrategy { public enum StrategyFlag { LOAD_TILES, // 2x2 tiles filling the complete viewport @@ -30,7 +30,7 @@ public class LiveMapStrategy { private final int stringId; private String l10n; // not final because the locale can be changed - Strategy(int id, EnumSet<StrategyFlag> flags, int stringId) { + private Strategy(int id, EnumSet<StrategyFlag> flags, int stringId) { this.id = id; this.flags = flags; this.stringId = stringId; diff --git a/main/src/cgeo/geocaching/enumerations/LoadFlags.java b/main/src/cgeo/geocaching/enumerations/LoadFlags.java index e55a4fc..22b0e2d 100644 --- a/main/src/cgeo/geocaching/enumerations/LoadFlags.java +++ b/main/src/cgeo/geocaching/enumerations/LoadFlags.java @@ -7,7 +7,7 @@ import java.util.EnumSet; * * @author blafoo */ -public class LoadFlags { +public interface LoadFlags { public enum LoadFlag { LOAD_CACHE_BEFORE, // load from CacheCache diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java index 0c959b2..cef7b89 100644 --- a/main/src/cgeo/geocaching/files/FileList.java +++ b/main/src/cgeo/geocaching/files/FileList.java @@ -264,13 +264,13 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis setExtensions(extensions); } - private void setExtensions(String[] extensionsIn) { - for (int i = 0; i < extensionsIn.length; i++) { - String extension = extensionsIn[i]; + private void setExtensions(final String[] extensionsIn) { + extensions = extensionsIn; + for (int i = 0; i < extensions.length; i++) { + String extension = extensions[i]; if (extension.length() == 0 || extension.charAt(0) != '.') { - extensionsIn[i] = "." + extension; + extensions[i] = "." + extension; } } - extensions = extensionsIn; } } diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java index 7fb95bd..4697a62 100644 --- a/main/src/cgeo/geocaching/files/GPXImporter.java +++ b/main/src/cgeo/geocaching/files/GPXImporter.java @@ -379,7 +379,6 @@ public class GPXImporter { final private Handler importStepHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- StringBuffer buffer = null;
switch (msg.what) {
case IMPORT_STEP_START:
Message cancelMessage = importStepHandler.obtainMessage(IMPORT_STEP_CANCEL);
@@ -402,9 +401,9 @@ public class GPXImporter { case IMPORT_STEP_STATIC_MAPS_SKIPPED:
progress.dismiss();
- buffer = new StringBuffer(20);
- buffer.append(res.getString(R.string.gpx_import_static_maps_skipped)).append(", ").append(msg.arg1).append(" ").append(res.getString(R.string.gpx_import_caches_imported));
- fromActivity.helpDialog(res.getString(R.string.gpx_import_title_caches_imported), buffer.toString());
+ StringBuilder bufferSkipped = new StringBuilder(20);
+ bufferSkipped.append(res.getString(R.string.gpx_import_static_maps_skipped)).append(", ").append(msg.arg1).append(' ').append(res.getString(R.string.gpx_import_caches_imported));
+ fromActivity.helpDialog(res.getString(R.string.gpx_import_title_caches_imported), bufferSkipped.toString());
importFinished();
break;
@@ -426,9 +425,9 @@ public class GPXImporter { break;
case IMPORT_STEP_CANCELED:
- buffer = new StringBuffer(20);
- buffer.append(res.getString(R.string.gpx_import_canceled)).append(", ").append(progress.getProgress()).append(" ").append(res.getString(R.string.gpx_import_caches_imported));
- fromActivity.showShortToast(buffer.toString());
+ StringBuilder bufferCanceled = new StringBuilder(20);
+ bufferCanceled.append(res.getString(R.string.gpx_import_canceled)).append(", ").append(progress.getProgress()).append(' ').append(res.getString(R.string.gpx_import_caches_imported));
+ fromActivity.showShortToast(bufferCanceled.toString());
importFinished();
break;
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 8337c95..fd1bf13 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1151,10 +1151,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto if (search != null) { downloaded = true; + caches.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS)); } - caches.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS)); - if (live) { final boolean excludeMine = Settings.isExcludeMyCaches(); final boolean excludeDisabled = Settings.isExcludeDisabledCaches(); diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java index c65b4ba..4dd217b 100644 --- a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java +++ b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java @@ -5,7 +5,6 @@ import cgeo.geocaching.Settings; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; -import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; @@ -16,7 +15,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Canvas; -import android.graphics.Point; import android.util.Log; import java.util.ArrayList; @@ -106,12 +104,6 @@ public class OtherCachersOverlay extends AbstractItemizedOverlay { } @Override - public void drawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { - super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel); - } - - @Override public OtherCachersOverlayItemImpl createItem(int index) { try { return items.get(index); diff --git a/main/src/cgeo/geocaching/network/Login.java b/main/src/cgeo/geocaching/network/Login.java index 8db370d..7d43fa8 100644 --- a/main/src/cgeo/geocaching/network/Login.java +++ b/main/src/cgeo/geocaching/network/Login.java @@ -322,19 +322,23 @@ public abstract class Login { public static String[] getViewstates(String page) { // Get the number of viewstates. // If there is only one viewstate, __VIEWSTATEFIELDCOUNT is not present - + if (page == null) { // no network access return null; } - + int count = 1; final Matcher matcherViewstateCount = GCConstants.PATTERN_VIEWSTATEFIELDCOUNT.matcher(page); if (matcherViewstateCount.find()) { - count = Integer.parseInt(matcherViewstateCount.group(1)); + try { + count = Integer.parseInt(matcherViewstateCount.group(1)); + } catch (NumberFormatException e) { + Log.e(Settings.tag, "getViewStates", e); + } } - + String[] viewstates = new String[count]; - + // Get the viewstates int no; final Matcher matcherViewstates = GCConstants.PATTERN_VIEWSTATES.matcher(page); @@ -344,11 +348,16 @@ public abstract class Login { no = 0; } else { - no = Integer.parseInt(sno); + try { + no = Integer.parseInt(sno); + } catch (NumberFormatException e) { + Log.e(Settings.tag, "getViewStates", e); + no = 0; + } } viewstates[no] = matcherViewstates.group(2); } - + if (viewstates.length != 1 || viewstates[0] != null) { return viewstates; } @@ -382,7 +391,7 @@ public abstract class Login { static public String[] requestViewstates(final String uri, final Parameters params, boolean xContentType, boolean my) { final HttpResponse response = Network.request(uri, params, xContentType, my, false); - + return getViewstates(Network.getResponseData(response)); } diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java index da7fb86..b9bebc9 100644 --- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java +++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java @@ -9,6 +9,8 @@ import cgeo.geocaching.network.Network; import org.apache.commons.lang3.StringUtils; +import android.util.Log; + /** * provides all the available templates for logging * @@ -129,6 +131,11 @@ public class LogTemplateProvider { return -1; } - return Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "-1").replaceAll("[,.]", "")); + try { + return Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "-1").replaceAll("[,.]", "")); + } catch (NumberFormatException e) { + Log.e(Settings.tag, "parseFindCount", e); + return -1; + } } } diff --git a/tests/src/cgeo/geocaching/test/WhitespaceTest.java b/tests/src/cgeo/geocaching/test/WhitespaceTest.java index 156f773..d2d21dc 100644 --- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java +++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java @@ -27,7 +27,7 @@ public class WhitespaceTest extends AndroidTestCase { @Override protected void setUp() throws Exception { - final StringBuffer buffer = new StringBuffer(4096); + final StringBuilder buffer = new StringBuilder(4096); final InputStream is = this.getClass().getResourceAsStream("/cgeo/geocaching/test/mock/GC2CJPF.html"); final BufferedReader br = new BufferedReader(new InputStreamReader(is), 4096); diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java index 4eb60dd..61369ee 100644 --- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java +++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java @@ -59,7 +59,7 @@ public abstract class MockedCache implements ICache { final InputStream is = MockedCache.class.getResourceAsStream("/cgeo/geocaching/test/mock/" + geocode + ".html"); final BufferedReader br = new BufferedReader(new InputStreamReader(is), 150000); - final StringBuffer buffer = new StringBuffer(); + final StringBuilder buffer = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { |
