diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2011-12-04 07:52:00 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2011-12-04 07:52:00 +0100 |
commit | 8a89f929f181289e7b62b8ae7ad27801c8fd9d31 (patch) | |
tree | 19bdbb4b2250460dc5fe7aa7a5c80eba6a2be1ec /main/src/cgeo | |
parent | 7e04fb8a7d057abaae17a812e4461d3f50e2ef7b (diff) | |
download | cgeo-8a89f929f181289e7b62b8ae7ad27801c8fd9d31.zip cgeo-8a89f929f181289e7b62b8ae7ad27801c8fd9d31.tar.gz cgeo-8a89f929f181289e7b62b8ae7ad27801c8fd9d31.tar.bz2 |
refactoring: more boxing/unboxing cleanup
Diffstat (limited to 'main/src/cgeo')
28 files changed, 108 insertions, 178 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 8a15ba9..4da2b71 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1135,9 +1135,9 @@ public class CacheDetailActivity extends AbstractActivity { } // rating - if (cache.getRating() != null && cache.getRating() > 0) { + if (cache.getRating() > 0) { final RelativeLayout itemLayout = addStarRating(R.string.cache_rating, cache.getRating()); - if (cache.getVotes() != null) { + if (cache.getVotes() > 0) { final TextView itemAddition = (TextView) itemLayout.findViewById(R.id.addition); itemAddition.setText("(" + cache.getVotes() + ")"); itemAddition.setVisibility(View.VISIBLE); @@ -1145,12 +1145,10 @@ public class CacheDetailActivity extends AbstractActivity { } // favourite count - if (cache.getFavouriteCnt() != null) { - addCacheDetail(R.string.cache_favourite, String.format("%d", cache.getFavouriteCnt()) + "×"); - } + addCacheDetail(R.string.cache_favourite, String.format("%d", cache.getFavoritePoints()) + "×"); // own rating - if (cache.getMyVote() != null && cache.getMyVote() > 0) { + if (cache.getMyVote() > 0) { addStarRating(R.string.cache_own_rating, cache.getMyVote()); } @@ -2016,7 +2014,7 @@ public class CacheDetailActivity extends AbstractActivity { if (cgBase.logTypes1.containsKey(log.type)) { ((TextView) rowView.findViewById(R.id.type)).setText(cgBase.logTypes1.get(log.type)); } else { - ((TextView) rowView.findViewById(R.id.type)).setText(cgBase.logTypes1.get(4)); // note if type is unknown + ((TextView) rowView.findViewById(R.id.type)).setText(cgBase.logTypes1.get(cgBase.LOG_NOTE)); // note if type is unknown } ((TextView) rowView.findViewById(R.id.author)).setText(StringEscapeUtils.unescapeHtml4(log.author)); diff --git a/main/src/cgeo/geocaching/ICache.java b/main/src/cgeo/geocaching/ICache.java index 6f87dc4..4d43e9b 100644 --- a/main/src/cgeo/geocaching/ICache.java +++ b/main/src/cgeo/geocaching/ICache.java @@ -97,7 +97,7 @@ public interface ICache extends IBasicCache { * @return number of favorite points * */ - public Integer getFavoritePoints(); + public int getFavoritePoints(); /** * @return true if the cache is on the watchlist of the user diff --git a/main/src/cgeo/geocaching/activity/ActivityMixin.java b/main/src/cgeo/geocaching/activity/ActivityMixin.java index fee0b63..6286a6b 100644 --- a/main/src/cgeo/geocaching/activity/ActivityMixin.java +++ b/main/src/cgeo/geocaching/activity/ActivityMixin.java @@ -139,7 +139,7 @@ public final class ActivityMixin { List<Integer> logTypes = cache.getPossibleLogTypes(); for (Integer logType : logTypes) { String label = cgBase.logTypes2.get(logType); - logMenu.add(1, IAbstractActivity.MENU_LOG_VISIT_OFFLINE + logType, 0, label); + logMenu.add(1, IAbstractActivity.MENU_LOG_VISIT_OFFLINE + logType.intValue(), 0, label); } logMenu.add(1, IAbstractActivity.MENU_LOG_VISIT, 0, res.getString(R.string.cache_menu_visit)); } diff --git a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java index c1691f2..e478ef1 100644 --- a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java +++ b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java @@ -121,7 +121,7 @@ public abstract class AbstractLocusApp extends AbstractApp { pg.name = cache.getName(); pg.placedBy = cache.getOwner(); if (cache.getHiddenDate() != null) { - pg.hidden = ISO8601DATE.format(cache.getHiddenDate().getTime()); + pg.hidden = ISO8601DATE.format(Long.valueOf(cache.getHiddenDate().getTime())); } int locusId = toLocusId(cache.getType()); if (locusId != NO_LOCUS_ID) { diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 8dcac64..7221549 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -672,7 +672,7 @@ public class cgBase { try { result = BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_FAVORITE, false, 1, null, true); if (null != result) { - cache.setFavouriteCnt(Integer.parseInt(result)); + cache.setFavouritePoints(Integer.parseInt(result)); } } catch (NumberFormatException e) { Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse favourite count"); @@ -999,7 +999,7 @@ public class cgBase { } // favourite - cache.setFavouriteCnt(Integer.parseInt(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_FAVORITECOUNT, true, "0"))); + cache.setFavouritePoints(Integer.parseInt(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_FAVORITECOUNT, true, "0"))); // cache size cache.setSize(CacheSize.getById(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_SIZE, true, CacheSize.NOT_CHOSEN.id).toLowerCase())); @@ -1422,7 +1422,7 @@ public class cgBase { if (cache.getHiddenDate() == null) { Log.e(Settings.tag, "hidden not parsed correctly"); } - if (cache.getFavouriteCnt() == null) { + if (cache.getFavoritePoints() < 0) { Log.e(Settings.tag, "favoriteCount not parsed correctly"); } if (cache.getSize() == null) { @@ -1602,7 +1602,6 @@ public class cgBase { trackable.setDistance(DistanceParser.parseDistance(distance, Settings.isUseMetricUnits())); } } catch (NumberFormatException e) { - trackable.setDistance(null); throw e; } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index b89563b..e2ce4cb 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -47,7 +47,7 @@ public class cgCache implements ICache { private long updated = 0; private long detailedUpdate = 0; - private Long visitedDate = null; + private long visitedDate = 0; private int reason = 0; private boolean detailed = false; private String geocode = ""; @@ -79,10 +79,10 @@ public class cgCache implements ICache { private boolean found = false; private boolean favourite = false; private boolean own = false; - private Integer favouriteCnt = null; - private Float rating = null; - private Integer votes = null; - private Float myVote = null; + private int favouritePoints = 0; + private float rating = 0; // valid ratings are larger than zero + private int votes = 0; + private float myVote = 0; // valid ratings are larger than zero private int inventoryItems = 0; private boolean onWatchlist = false; private List<String> attributes = null; @@ -116,7 +116,7 @@ public class cgCache implements ICache { detailedUpdate = updated; } - if (visitedDate == null || visitedDate == 0) { + if (visitedDate == 0) { visitedDate = other.getVisitedDate(); } if (reason == 0) { @@ -188,16 +188,16 @@ public class cgCache implements ICache { if (StringUtils.isBlank(description)) { description = other.description; } - if (favouriteCnt == null) { - favouriteCnt = other.getFavouriteCnt(); + if (favouritePoints == 0) { + favouritePoints = other.getFavoritePoints(); } - if (rating == null) { + if (rating == 0) { rating = other.getRating(); } - if (votes == null) { + if (votes == 0) { votes = other.votes; } - if (myVote == null) { + if (myVote == 0) { myVote = other.getMyVote(); } if (attributes == null) { @@ -570,8 +570,8 @@ public class cgCache implements ICache { } @Override - public Integer getFavoritePoints() { - return favouriteCnt; + public int getFavoritePoints() { + return favouritePoints; } @Override @@ -613,11 +613,11 @@ public class cgCache implements ICache { this.detailedUpdate = detailedUpdate; } - public Long getVisitedDate() { + public long getVisitedDate() { return visitedDate; } - public void setVisitedDate(Long visitedDate) { + public void setVisitedDate(long visitedDate) { this.visitedDate = visitedDate; } @@ -726,35 +726,31 @@ public class cgCache implements ICache { this.favourite = favourite; } - public Integer getFavouriteCnt() { - return favouriteCnt; + public void setFavouritePoints(int favouriteCnt) { + this.favouritePoints = favouriteCnt; } - public void setFavouriteCnt(Integer favouriteCnt) { - this.favouriteCnt = favouriteCnt; - } - - public Float getRating() { + public float getRating() { return rating; } - public void setRating(Float rating) { + public void setRating(float rating) { this.rating = rating; } - public Integer getVotes() { + public int getVotes() { return votes; } - public void setVotes(Integer votes) { + public void setVotes(int votes) { this.votes = votes; } - public Float getMyVote() { + public float getMyVote() { return myVote; } - public void setMyVote(Float myVote) { + public void setMyVote(float myVote) { this.myVote = myVote; } diff --git a/main/src/cgeo/geocaching/cgCacheListAdapter.java b/main/src/cgeo/geocaching/cgCacheListAdapter.java index 48cc5cb..5578299 100644 --- a/main/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/main/src/cgeo/geocaching/cgCacheListAdapter.java @@ -513,11 +513,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } } - if (cache.getFavouriteCnt() != null) { - holder.favourite.setText(String.format("%d", cache.getFavouriteCnt())); - } else { - holder.favourite.setText("---"); - } + holder.favourite.setText(String.format("%d", cache.getFavoritePoints())); int favoriteBack; // set default background, neither vote nor rating may be available @@ -526,8 +522,8 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } else { favoriteBack = R.drawable.favourite_background_dark; } - if (cache.getMyVote() != null) { - float myVote = cache.getMyVote(); + float myVote = cache.getMyVote(); + if (myVote > 0) { // use my own rating for display, if I have voted if (myVote >= 4) { favoriteBack = ratingBcgs[2]; } else if (myVote >= 3) { @@ -535,7 +531,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } else if (myVote > 0) { favoriteBack = ratingBcgs[0]; } - } else if (cache.getRating() != null) { + } else { float rating = cache.getRating(); if (rating >= 3.5) { favoriteBack = ratingBcgs[2]; @@ -548,7 +544,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { holder.favourite.setBackgroundResource(favoriteBack); StringBuilder cacheInfo = new StringBuilder(50); - if (historic && cache.getVisitedDate() != null) { + if (historic && cache.getVisitedDate() > 0) { cacheInfo.append(cgBase.formatTime(cache.getVisitedDate())); cacheInfo.append("; "); cacheInfo.append(cgBase.formatDate(cache.getVisitedDate())); diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 96bb811..3857df7 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -1257,7 +1257,7 @@ public class cgData { values.put("shortdesc", cache.getShortdesc()); values.put("personal_note", cache.getPersonalNote()); values.put("description", cache.getDescription()); - values.put("favourite_cnt", cache.getFavouriteCnt()); + values.put("favourite_cnt", cache.getFavoritePoints()); values.put("rating", cache.getRating()); values.put("votes", cache.getVotes()); values.put("myvote", cache.getMyVote()); @@ -1731,12 +1731,12 @@ public class cgData { return true; } - public List<Object> getBounds(Object[] geocodes) { + public List<Number> getBounds(Object[] geocodes) { init(); Cursor cursor = null; - final List<Object> viewport = new ArrayList<Object>(); + final List<Number> viewport = new ArrayList<Number>(); try { final StringBuilder where = new StringBuilder(); @@ -2101,7 +2101,7 @@ public class cgData { cache.setPersonalNote(cursor.getString(cacheColumnIndex[23])); cache.setShortdesc(cursor.getString(cacheColumnIndex[24])); // do not set cache.description ! - cache.setFavouriteCnt(cursor.getInt(cacheColumnIndex[25])); + cache.setFavouritePoints(cursor.getInt(cacheColumnIndex[25])); cache.setRating(cursor.getFloat(cacheColumnIndex[26])); cache.setVotes(cursor.getInt(cacheColumnIndex[27])); cache.setMyVote(cursor.getFloat(cacheColumnIndex[28])); diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java index edeb1b6..e008aa7 100644 --- a/main/src/cgeo/geocaching/cgGeo.java +++ b/main/src/cgeo/geocaching/cgGeo.java @@ -30,8 +30,8 @@ public class cgGeo { public LocationProviderType locationProvider = LocationProviderType.LAST; public Geopoint coordsNow = null; public Double altitudeNow = null; - public Float bearingNow = null; - public Float speedNow = null; + public float bearingNow = 0; + public float speedNow = 0; public float accuracyNow = -1f; public int satellitesVisible = 0; public int satellitesFixed = 0; diff --git a/main/src/cgeo/geocaching/cgLog.java b/main/src/cgeo/geocaching/cgLog.java index 7e81897..0a719df 100644 --- a/main/src/cgeo/geocaching/cgLog.java +++ b/main/src/cgeo/geocaching/cgLog.java @@ -4,7 +4,7 @@ import java.util.List; public class cgLog { public int id = 0; - public int type = 4; // note + public int type = cgBase.LOG_NOTE; // note public String author = ""; public String log = ""; public long date = 0; diff --git a/main/src/cgeo/geocaching/cgTrackable.java b/main/src/cgeo/geocaching/cgTrackable.java index b8c8958..95446d0 100644 --- a/main/src/cgeo/geocaching/cgTrackable.java +++ b/main/src/cgeo/geocaching/cgTrackable.java @@ -23,7 +23,7 @@ public class cgTrackable implements ILogable { private String name = ""; private String type = null; private Date released = null; - private Float distance = null; + private float distance = -1; private String origin = null; private String owner = null; private String ownerGuid = null; @@ -106,11 +106,11 @@ public class cgTrackable implements ILogable { } } - public Float getDistance() { + public float getDistance() { return distance; } - public void setDistance(Float distance) { + public void setDistance(float distance) { this.distance = distance; } diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index 525d935..d2a1766 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -49,7 +49,7 @@ public class cgeo extends AbstractActivity { private static final int SCAN_REQUEST_CODE = 1; private static final int MENU_OPEN_LIST = 100; - private Integer version = null; + private int version = 0; private cgGeo geo = null; private UpdateLocationCallback geoUpdate = new update(); private TextView navType = null; @@ -721,7 +721,7 @@ public class cgeo extends AbstractActivity { app.cleanDatabase(more); cleanupRunning = false; - if (version != null && version > 0) { + if (version > 0) { SharedPreferences.Editor edit = prefs.edit(); edit.putInt("version", version); edit.commit(); diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index cdd5b23..f75d51d 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -376,7 +376,7 @@ public class cgeoapplication extends Application { return getStorage().allDetailedThere(); } - public List<Object> getBounds(String geocode) { + public List<Number> getBounds(String geocode) { if (geocode == null) { return null; } @@ -387,7 +387,7 @@ public class cgeoapplication extends Application { return getBounds(geocodeList); } - public List<Object> getBounds(final cgSearch search) { + public List<Number> getBounds(final cgSearch search) { if (search == null) { return null; } @@ -401,7 +401,7 @@ public class cgeoapplication extends Application { return getBounds(geocodeList); } - public List<Object> getBounds(final List<String> geocodes) { + public List<Number> getBounds(final List<String> geocodes) { if (CollectionUtils.isEmpty(geocodes)) { return null; } diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index db26870..948ef0d 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -1761,13 +1761,9 @@ public class cgeocaches extends AbstractListActivity { adapter.setActualCoordinates(geo.coordsNow); } - if (!Settings.isUseCompass() || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h + if (!Settings.isUseCompass() || geo.speedNow > 5) { // use GPS when speed is higher than 18 km/h if (!Settings.isUseCompass()) { - if (geo.bearingNow != null) { - adapter.setActualHeading(geo.bearingNow); - } else { - adapter.setActualHeading(0f); - } + adapter.setActualHeading(geo.bearingNow); } if (northHeading != null) { adapter.setActualHeading(northHeading); @@ -1791,7 +1787,7 @@ public class cgeocaches extends AbstractListActivity { } northHeading = dir.directionNow; - if (northHeading != null && adapter != null && (geo == null || geo.speedNow == null || geo.speedNow <= 5)) { // use compass when speed is lower than 18 km/h) { + if (northHeading != null && adapter != null && (geo == null || geo.speedNow <= 5)) { // use compass when speed is lower than 18 km/h) { adapter.setActualHeading(northHeading); } } @@ -2426,7 +2422,7 @@ public class cgeocaches extends AbstractListActivity { @Override public void run(final Integer arg) { - switchListById(arg); + switchListById(arg.intValue()); } }); } diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java index 71227f5..a313659 100644 --- a/main/src/cgeo/geocaching/cgeonavigate.java +++ b/main/src/cgeo/geocaching/cgeonavigate.java @@ -387,12 +387,8 @@ public class cgeonavigate extends AbstractActivity { navLocation.setText(res.getString(R.string.loc_trying)); } - if (!Settings.isUseCompass() || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h - if (geo.bearingNow != null) { - northHeading = geo.bearingNow; - } else { - northHeading = 0f; - } + if (!Settings.isUseCompass() || geo.speedNow > 5) { // use GPS when speed is higher than 18 km/h + northHeading = geo.bearingNow; } } catch (Exception e) { Log.w(Settings.tag, "Failed to update location."); @@ -408,7 +404,7 @@ public class cgeonavigate extends AbstractActivity { return; } - if (geo == null || geo.speedNow == null || geo.speedNow <= 5) { // use compass when speed is lower than 18 km/h + if (geo == null || geo.speedNow <= 5) { // use compass when speed is lower than 18 km/h northHeading = dir.directionNow; } } diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java index 9b8d1bb..a7906bf 100644 --- a/main/src/cgeo/geocaching/cgeopoint.java +++ b/main/src/cgeo/geocaching/cgeopoint.java @@ -522,13 +522,10 @@ public class cgeopoint extends AbstractActivity { if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { // bearing & distance - Double bearing = null; + double bearing = 0; try { - bearing = new Double(bearingText); - } catch (Exception e) { - // probably not a number - } - if (bearing == null) { + bearing = Double.parseDouble(bearingText); + } catch (NumberFormatException e) { helpDialog(res.getString(R.string.err_point_bear_and_dist_title), res.getString(R.string.err_point_bear_and_dist)); return null; } diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java index 3071e80..dc9a842 100644 --- a/main/src/cgeo/geocaching/cgeopopup.java +++ b/main/src/cgeo/geocaching/cgeopopup.java @@ -354,7 +354,7 @@ public class cgeopopup extends AbstractActivity { } // rating - if (cache.getRating() != null && cache.getRating() > 0) { + if (cache.getRating() > 0) { setRating(cache.getRating(), cache.getVotes()); } else { if (Settings.isRatingWanted() && cache.supportsGCVote()) { @@ -602,8 +602,8 @@ public class cgeopopup extends AbstractActivity { } } - private void setRating(Float rating, Integer votes) { - if (rating == null || rating <= 0) { + private void setRating(float rating, int votes) { + if (rating <= 0) { return; } @@ -622,7 +622,7 @@ public class cgeopopup extends AbstractActivity { itemValue.setText(String.format("%.1f", rating) + ' ' + res.getString(R.string.cache_rating_of) + " 5"); itemStars.addView(cgBase.createStarRating(rating, 5, this), 1); - if (votes != null) { + if (votes > 0) { final TextView itemAddition = (TextView) itemLayout.findViewById(R.id.addition); itemAddition.setText("(" + votes + ")"); itemAddition.setVisibility(View.VISIBLE); diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java index dd0f358..05486fb 100644 --- a/main/src/cgeo/geocaching/cgeotrackable.java +++ b/main/src/cgeo/geocaching/cgeotrackable.java @@ -156,7 +156,7 @@ public class cgeotrackable extends AbstractActivity { } // trackable distance - if (trackable.getDistance() != null) { + if (trackable.getDistance() >= 0) { addDetail(R.string.trackable_distance, cgBase.getHumanDistance(trackable.getDistance())); } diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java index 8d795b0..2216ffd 100644 --- a/main/src/cgeo/geocaching/cgeowaypointadd.java +++ b/main/src/cgeo/geocaching/cgeowaypointadd.java @@ -246,10 +246,6 @@ public class cgeowaypointadd extends AbstractActivity { private class coordsListener implements View.OnClickListener { public void onClick(View arg0) { - List<Double> coords = new ArrayList<Double>(); - Double latitude = null; - Double longitude = null; - final String bearingText = ((EditText) findViewById(R.id.bearing)).getText().toString(); final String distanceText = ((EditText) findViewById(R.id.distance)).getText().toString(); final String latText = ((Button) findViewById(R.id.buttonLatitude)).getText().toString(); @@ -261,6 +257,9 @@ public class cgeowaypointadd extends AbstractActivity { return; } + double latitude; + double longitude; + if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) { try { latitude = GeopointParser.parseLatitude(latText); @@ -279,15 +278,13 @@ public class cgeowaypointadd extends AbstractActivity { longitude = geo.coordsNow.getLongitude(); } + Geopoint coords = null; if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { // bearing & distance - Double bearing = null; + double bearing = 0; try { - bearing = new Double(bearingText); - } catch (Exception e) { - // probably not a number - } - if (bearing == null) { + bearing = Double.parseDouble(bearingText); + } catch (NumberFormatException e) { helpDialog(res.getString(R.string.err_point_bear_and_dist_title), res.getString(R.string.err_point_bear_and_dist)); return; } @@ -300,27 +297,9 @@ public class cgeowaypointadd extends AbstractActivity { return; } - Double latParsed = null; - Double lonParsed = null; - - final Geopoint coordsDst = new Geopoint(latitude, longitude).project(bearing, distance); - - latParsed = coordsDst.getLatitude(); - lonParsed = coordsDst.getLongitude(); - - if (latParsed == null || lonParsed == null) { - showToast(res.getString(R.string.err_point_location_error)); - return; - } - - coords.add(0, latParsed); - coords.add(1, lonParsed); - } else if (latitude != null && longitude != null) { - coords.add(0, latitude); - coords.add(1, longitude); + coords = new Geopoint(latitude, longitude).project(bearing, distance); } else { - showToast(res.getString(R.string.err_point_location_error)); - return; + coords = new Geopoint(latitude, longitude); } String name = ((EditText) findViewById(R.id.name)).getText().toString().trim(); @@ -336,7 +315,7 @@ public class cgeowaypointadd extends AbstractActivity { waypoint.setPrefix(prefix); waypoint.setLookup(lookup); waypoint.setName(name); - waypoint.setCoords(new Geopoint(coords.get(0), coords.get(1))); + waypoint.setCoords(coords); waypoint.setNote(note); if (app.saveOwnWaypoint(id, geocode, waypoint)) { diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java index c2e6ac4..15d1924 100644 --- a/main/src/cgeo/geocaching/compatibility/Compatibility.java +++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java @@ -36,7 +36,7 @@ public final class Compatibility { } } - public static Float getDirectionNow(final Float directionNowPre, + public static float getDirectionNow(final float directionNowPre, final Activity activity) { if (isLevel8) { try { diff --git a/main/src/cgeo/geocaching/connector/AbstractConnector.java b/main/src/cgeo/geocaching/connector/AbstractConnector.java index 3ba9ae2..54f0d8f 100644 --- a/main/src/cgeo/geocaching/connector/AbstractConnector.java +++ b/main/src/cgeo/geocaching/connector/AbstractConnector.java @@ -55,7 +55,7 @@ public abstract class AbstractConnector implements IConnector { protected static boolean isNumericId(final String string) { try { - return Integer.valueOf(string) > 0; + return Integer.parseInt(string) > 0; } catch (NumberFormatException e) { } return false; diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index 279097d..f3c192d 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -147,7 +147,7 @@ final public class OkapiClient { } cache.setVotes(response.getInt(CACHE_VOTES)); - cache.setFavouriteCnt(response.getInt(CACHE_RECOMMENDATIONS)); + cache.setFavouritePoints(response.getInt(CACHE_RECOMMENDATIONS)); // not used: req_password cache.setDescription(response.getString(CACHE_DESCRIPTION)); cache.setHint(Html.fromHtml(response.getString(CACHE_HINT)).toString()); diff --git a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java index c4cfb8c..1aad335 100644 --- a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java +++ b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java @@ -54,6 +54,7 @@ public class GeopointFormatter * one of the predefined formats * @return the formatted coordinates */ + @SuppressWarnings("boxing") public static String format(final Format format, final Geopoint gp) { final double latSigned = gp.getLatitude(); diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 3999413..5798e5e 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -653,7 +653,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory } }); - Float etaTime = Float.valueOf((detailTotal * (float) 7) / 60); + float etaTime = detailTotal * 7.0f / 60.0f; if (etaTime < 0.4) { waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + res.getString(R.string.caches_eta_ltm)); } else if (etaTime < 1.5) { @@ -783,12 +783,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory } } - if (!Settings.isUseCompass() || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h - if (geo.bearingNow != null) { - overlayPosition.setHeading(geo.bearingNow); - } else { - overlayPosition.setHeading(0f); - } + if (!Settings.isUseCompass() || geo.speedNow > 5) { // use GPS when speed is higher than 18 km/h + overlayPosition.setHeading(geo.bearingNow); repaintRequired = true; } @@ -811,7 +807,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory return; } - if (overlayPosition != null && mapView != null && (geo == null || geo.speedNow == null || geo.speedNow <= 5)) { // use compass when speed is lower than 18 km/h + if (overlayPosition != null && mapView != null && (geo == null || geo.speedNow <= 5)) { // use compass when speed is lower than 18 km/h overlayPosition.setHeading(dir.directionNow); mapView.repaintRequired(overlayPosition); } @@ -1668,7 +1664,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory if (!app.isOffline(geocode, null)) { if ((System.currentTimeMillis() - last) < 1500) { try { - int delay = 1000 + ((Double) (Math.random() * 1000)).intValue() - (int) (System.currentTimeMillis() - last); + int delay = 1000 + (int) (Math.random() * 1000.0) - (int) (System.currentTimeMillis() - last); if (delay < 0) { delay = 500; } @@ -1739,7 +1735,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory alreadyCentered = true; } else if (!centered && (geocodeCenter != null || searchIntent != null)) { try { - List<Object> viewport = null; + List<Number> viewport = null; if (geocodeCenter != null) { viewport = app.getBounds(geocodeCenter); @@ -1747,32 +1743,18 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory viewport = app.getBounds(searchCenter); } - if (viewport == null) { + if (viewport == null || viewport.size() < 5) { return; } - Integer cnt = (Integer) viewport.get(0); - Integer minLat = null; - Integer maxLat = null; - Integer minLon = null; - Integer maxLon = null; - - if (viewport.get(1) != null) { - minLat = (int) ((Double) viewport.get(1) * 1e6); - } - if (viewport.get(2) != null) { - maxLat = (int) ((Double) viewport.get(2) * 1e6); - } - if (viewport.get(3) != null) { - maxLon = (int) ((Double) viewport.get(3) * 1e6); - } - if (viewport.get(4) != null) { - minLon = (int) ((Double) viewport.get(4) * 1e6); - } - - if (cnt == null || cnt <= 0 || minLat == null || maxLat == null || minLon == null || maxLon == null) { + int cnt = (Integer) viewport.get(0); + if (cnt <= 0) { return; } + int minLat = (int) ((Double) viewport.get(1) * 1e6); + int maxLat = (int) ((Double) viewport.get(2) * 1e6); + int maxLon = (int) ((Double) viewport.get(3) * 1e6); + int minLon = (int) ((Double) viewport.get(4) * 1e6); int centerLat = 0; int centerLon = 0; @@ -1788,11 +1770,9 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory centerLon = maxLon; } - if (cnt > 0) { - mapController.setCenter(mapProvider.getGeoPointBase(new Geopoint(centerLat, centerLon))); - if (Math.abs(maxLat - minLat) != 0 && Math.abs(maxLon - minLon) != 0) { - mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon)); - } + mapController.setCenter(mapProvider.getGeoPointBase(new Geopoint(centerLat, centerLon))); + if (Math.abs(maxLat - minLat) != 0 && Math.abs(maxLon - minLon) != 0) { + mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon)); } } catch (Exception e) { // nothing at all diff --git a/main/src/cgeo/geocaching/sorting/PopularityComparator.java b/main/src/cgeo/geocaching/sorting/PopularityComparator.java index 5d3507c..9fe254a 100644 --- a/main/src/cgeo/geocaching/sorting/PopularityComparator.java +++ b/main/src/cgeo/geocaching/sorting/PopularityComparator.java @@ -10,14 +10,14 @@ public class PopularityComparator extends AbstractCacheComparator { @Override protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.getFavouriteCnt() != null && cache2.getFavouriteCnt() != null; + return true; } @Override protected int compareCaches(cgCache cache1, cgCache cache2) { - if (cache1.getFavouriteCnt() < cache2.getFavouriteCnt()) { + if (cache1.getFavoritePoints() < cache2.getFavoritePoints()) { return 1; - } else if (cache2.getFavouriteCnt() < cache1.getFavouriteCnt()) { + } else if (cache2.getFavoritePoints() < cache1.getFavoritePoints()) { return -1; } return 0; diff --git a/main/src/cgeo/geocaching/sorting/RatingComparator.java b/main/src/cgeo/geocaching/sorting/RatingComparator.java index 3c0fc02..935ccd8 100644 --- a/main/src/cgeo/geocaching/sorting/RatingComparator.java +++ b/main/src/cgeo/geocaching/sorting/RatingComparator.java @@ -10,13 +10,13 @@ public class RatingComparator extends AbstractCacheComparator { @Override protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.getRating() != null && cache2.getRating() != null; + return true; } @Override protected int compareCaches(cgCache cache1, cgCache cache2) { - Float rating1 = cache1.getRating(); - Float rating2 = cache2.getRating(); + float rating1 = cache1.getRating(); + float rating2 = cache2.getRating(); // voting can be disabled for caches, then assume an average rating instead if (rating1 == 0.0) { diff --git a/main/src/cgeo/geocaching/sorting/VisitComparator.java b/main/src/cgeo/geocaching/sorting/VisitComparator.java index ba5e07f..a580f2a 100644 --- a/main/src/cgeo/geocaching/sorting/VisitComparator.java +++ b/main/src/cgeo/geocaching/sorting/VisitComparator.java @@ -10,8 +10,7 @@ public class VisitComparator extends AbstractCacheComparator { @Override protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.getVisitedDate() != null && cache1.getVisitedDate() > 0 - && cache2.getVisitedDate() != null && cache2.getVisitedDate() > 0; + return cache1.getVisitedDate() > 0 && cache2.getVisitedDate() > 0; } @Override diff --git a/main/src/cgeo/geocaching/sorting/VoteComparator.java b/main/src/cgeo/geocaching/sorting/VoteComparator.java index 2145361..82ebdd3 100644 --- a/main/src/cgeo/geocaching/sorting/VoteComparator.java +++ b/main/src/cgeo/geocaching/sorting/VoteComparator.java @@ -18,15 +18,8 @@ public class VoteComparator extends AbstractCacheComparator { @Override protected int compareCaches(cgCache cache1, cgCache cache2) { // if there is no vote available, put that cache at the end of the list - float vote1 = 0; - if (cache1.getMyVote() != null) { - vote1 = cache1.getMyVote(); - } - - float vote2 = 0; - if (cache2.getMyVote() != null) { - vote2 = cache2.getMyVote(); - } + float vote1 = cache1.getMyVote(); + float vote2 = cache2.getMyVote(); // compare if (vote1 < vote2) { |