diff options
Diffstat (limited to 'main/src')
14 files changed, 89 insertions, 52 deletions
diff --git a/main/src/cgeo/geocaching/SearchResult.java b/main/src/cgeo/geocaching/SearchResult.java index bac9c23..e7c9a88 100644 --- a/main/src/cgeo/geocaching/SearchResult.java +++ b/main/src/cgeo/geocaching/SearchResult.java @@ -22,10 +22,10 @@ import java.util.Set; public class SearchResult implements Parcelable { final private Set<String> geocodes; - public StatusCode error = null; + private StatusCode error = null; private String url = ""; public String[] viewstates = null; - public int totalCnt = 0; + private int totalCnt = 0; final public static Parcelable.Creator<SearchResult> CREATOR = new Parcelable.Creator<SearchResult>() { public SearchResult createFromParcel(Parcel in) { @@ -47,19 +47,24 @@ public class SearchResult implements Parcelable { this.error = searchResult.error; this.url = searchResult.url; this.viewstates = searchResult.viewstates; - this.totalCnt = searchResult.totalCnt; + this.setTotal(searchResult.getTotal()); } else { this.geocodes = new HashSet<String>(); } } - public SearchResult(final Set<String> geocodes) { + public SearchResult(final Set<String> geocodes, final int total) { if (geocodes == null) { this.geocodes = new HashSet<String>(); } else { this.geocodes = new HashSet<String>(geocodes.size()); this.geocodes.addAll(geocodes); } + this.setTotal(total); + } + + public SearchResult(final Set<String> geocodes) { + this(geocodes, geocodes == null ? 0 : geocodes.size()); } public SearchResult(final Parcel in) { @@ -73,7 +78,7 @@ public class SearchResult implements Parcelable { viewstates = new String[length]; in.readStringArray(viewstates); } - totalCnt = in.readInt(); + setTotal(in.readInt()); } @Override @@ -87,7 +92,7 @@ public class SearchResult implements Parcelable { out.writeInt(viewstates.length); out.writeStringArray(viewstates); } - out.writeInt(totalCnt); + out.writeInt(getTotal()); } @Override @@ -135,6 +140,10 @@ public class SearchResult implements Parcelable { return totalCnt; } + public void setTotal(int totalCnt) { + this.totalCnt = totalCnt; + } + /** * @param excludeDisabled * @param excludeMine diff --git a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java index 46105cd..1ccf8dc 100644 --- a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java +++ b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java @@ -37,6 +37,10 @@ public abstract class AbstractLocusApp extends AbstractApp { super(getString(R.string.caches_map_locus), INTENT); } + protected AbstractLocusApp(final String text, final String intent) { + super(text, intent); + } + @Override public boolean isInstalled(Context context) { return LocusUtils.isLocusAvailable(context); @@ -52,7 +56,7 @@ public abstract class AbstractLocusApp extends AbstractApp { * @param activity * @author koem */ - protected static boolean showInLocus(final List<? extends Object> objectsToShow, final boolean withCacheWaypoints, + protected static boolean showInLocus(final List<? extends Object> objectsToShow, final boolean withCacheWaypoints, final boolean export, final Activity activity) { if (objectsToShow == null || objectsToShow.isEmpty()) { return false; @@ -78,13 +82,13 @@ public abstract class AbstractLocusApp extends AbstractApp { } if (pd.getPoints().size() <= 1000) { - DisplayData.sendData(activity, pd, false); + DisplayData.sendData(activity, pd, export); } else { final ArrayList<PointsData> data = new ArrayList<PointsData>(); data.add(pd); DisplayData.sendDataCursor(activity, data, "content://" + LocusDataStorageProvider.class.getCanonicalName().toLowerCase(), - false); + export); } return true; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/LocusApp.java b/main/src/cgeo/geocaching/apps/cache/navi/LocusApp.java index 260d933..c867373 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/LocusApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/LocusApp.java @@ -34,7 +34,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { points.add(waypoint); } - return showInLocus(points, true, activity); + return showInLocus(points, true, false, activity); } } diff --git a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java index fd19353..2d73885 100644 --- a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java @@ -27,7 +27,8 @@ public final class CacheListAppFactory extends AbstractAppFactory { if (ArrayUtils.isEmpty(apps)) { apps = new CacheListApp[] { new InternalCacheListMap(), - new LocusCacheListApp() }; + new LocusCacheListApp(false), + new LocusCacheListApp(true) }; } return apps; } diff --git a/main/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java b/main/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java index 0c5455c..1b50861 100644 --- a/main/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java +++ b/main/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java @@ -1,5 +1,6 @@ package cgeo.geocaching.apps.cachelist; +import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; @@ -8,11 +9,19 @@ import cgeo.geocaching.apps.AbstractLocusApp; import org.apache.commons.collections.CollectionUtils; import android.app.Activity; +import android.content.Intent; import java.util.List; class LocusCacheListApp extends AbstractLocusApp implements CacheListApp { + private boolean export; + + public LocusCacheListApp(boolean export) { + super(getString(export ? R.string.caches_map_locus_export : R.string.caches_map_locus), Intent.ACTION_VIEW); + this.export = export; + } + /** * show caches in Locus * @@ -25,7 +34,7 @@ class LocusCacheListApp extends AbstractLocusApp implements CacheListApp { return false; } - showInLocus(cacheList, false, activity); + showInLocus(cacheList, false, export, activity); return true; } diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 0d39608..66354e8 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -300,7 +300,7 @@ public class cgBase { try { String result = BaseUtils.getMatch(page, GCConstants.PATTERN_SEARCH_TOTALCOUNT, false, 1, null, true); if (null != result) { - searchResult.totalCnt = Integer.parseInt(result); + searchResult.setTotal(Integer.parseInt(result)); } } catch (NumberFormatException e) { Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache count"); @@ -347,7 +347,7 @@ public class cgBase { if (coordinates.contains("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) { Log.i(Settings.tag, "User has not agreed to the license agreement. Can\'t download .loc file."); - searchResult.error = StatusCode.UNAPPROVED_LICENSE; + searchResult.setError(StatusCode.UNAPPROVED_LICENSE); return searchResult; } @@ -401,23 +401,23 @@ public class cgBase { final SearchResult searchResult = new SearchResult(); if (page.contains("Cache is Unpublished") || page.contains("you cannot view this cache listing until it has been published")) { - searchResult.error = StatusCode.UNPUBLISHED_CACHE; + searchResult.setError(StatusCode.UNPUBLISHED_CACHE); return searchResult; } if (page.contains("Sorry, the owner of this listing has made it viewable to Premium Members only.")) { - searchResult.error = StatusCode.PREMIUM_ONLY; + searchResult.setError(StatusCode.PREMIUM_ONLY); return searchResult; } if (page.contains("has chosen to make this cache listing visible to Premium Members only.")) { - searchResult.error = StatusCode.PREMIUM_ONLY; + searchResult.setError(StatusCode.PREMIUM_ONLY); return searchResult; } final String cacheName = Html.fromHtml(BaseUtils.getMatch(page, GCConstants.PATTERN_NAME, true, "")).toString(); if ("An Error Has Occurred".equalsIgnoreCase(cacheName)) { - searchResult.error = StatusCode.UNKNOWN_ERROR; + searchResult.setError(StatusCode.UNKNOWN_ERROR); return searchResult; } @@ -769,7 +769,7 @@ public class cgBase { // last check for necessary cache conditions if (StringUtils.isBlank(cache.getGeocode())) { - searchResult.error = StatusCode.UNKNOWN_ERROR; + searchResult.setError(StatusCode.UNKNOWN_ERROR); return searchResult; } @@ -1308,7 +1308,7 @@ public class cgBase { } // save to application - search.setError(searchResult.error); + search.setError(searchResult.getError()); search.setViewstates(searchResult.viewstates); for (String geocode : searchResult.getGeocodes()) { search.addGeocode(geocode); diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index e2b39d8..fb0cfd4 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -294,9 +294,7 @@ public class cgeoapplication extends Application { /** {@link cgData#loadBatchOfStoredGeocodes(boolean, Geopoint, CacheType, int)} */ public SearchResult getBatchOfStoredCaches(final boolean detailedOnly, final Geopoint coords, final CacheType cacheType, final int listId) { final Set<String> geocodes = storage.loadBatchOfStoredGeocodes(detailedOnly, coords, cacheType, listId); - final SearchResult search = new SearchResult(geocodes); - search.totalCnt = getAllStoredCachesCount(true, cacheType, listId); - return search; + return new SearchResult(geocodes, getAllStoredCachesCount(true, cacheType, listId)); } /** {@link cgData#loadHistoryOfSearchedLocations()} */ @@ -306,10 +304,7 @@ public class cgeoapplication extends Application { public SearchResult getHistoryOfCaches(final boolean detailedOnly, final CacheType cacheType) { final Set<String> geocodes = storage.loadBatchOfHistoricGeocodes(detailedOnly, cacheType); - final SearchResult search = new SearchResult(geocodes); - - search.totalCnt = getAllHistoricCachesCount(); - return search; + return new SearchResult(geocodes, getAllHistoricCachesCount()); } /** {@link cgData#loadCachedInViewport(Long, Long, Long, Long, CacheType)} */ diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 21ecb5e..70d1b85 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -727,7 +727,7 @@ public class cgeocaches extends AbstractListActivity { // refresh standard list if it has changed (new caches downloaded) if (type == CacheListType.OFFLINE && listId >= StoredList.STANDARD_LIST_ID && search != null) { SearchResult newSearch = cgBase.searchByStored(coords, cacheType, listId); - if (newSearch != null && newSearch.totalCnt != search.totalCnt) { + if (newSearch != null && newSearch.getTotal() != search.getTotal()) { refreshCurrentList(); } } diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java index 409f837..344ff6a 100644 --- a/main/src/cgeo/geocaching/compatibility/Compatibility.java +++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java @@ -14,6 +14,8 @@ import android.view.Display; import android.view.Surface; import android.widget.EditText; +import java.lang.reflect.Method; + public final class Compatibility { private final static int sdkVersion = Integer.parseInt(Build.VERSION.SDK); @@ -23,7 +25,16 @@ public final class Compatibility { private final static AndroidLevel8Interface level8; private final static AndroidLevel11Interface level11; + private static Method overridePendingTransitionMethod = null; + static { + if (isLevel5) { + try { + overridePendingTransitionMethod = Activity.class.getMethod("overridePendingTransition", Integer.TYPE, Integer.TYPE); + } catch (Exception e) { + Log.e(Settings.tag, "cannot get overridePendingTransition", e); + } + } if (isLevel8) { level8 = new AndroidLevel8(); } @@ -89,15 +100,23 @@ public final class Compatibility { } } + private static void overridePendingTransition(final Activity activity, int enterAnim, int exitAnim) { + try { + overridePendingTransitionMethod.invoke(activity, enterAnim, exitAnim); + } catch (Exception e) { + Log.e(Settings.tag, "cannot call overridePendingTransition", e); + } + } + public static void restartActivity(AbstractActivity activity) { final Intent intent = activity.getIntent(); if (isLevel5) { - activity.overridePendingTransition(0, 0); + overridePendingTransition(activity, 0, 0); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); } activity.finish(); if (isLevel5) { - activity.overridePendingTransition(0, 0); + overridePendingTransition(activity, 0, 0); } activity.startActivity(intent); } diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index 1c57508..d0c49eb 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -117,12 +117,12 @@ public class GCConnector extends AbstractConnector { } else { search.addGeocode(geocode); } - search.error = StatusCode.NO_ERROR; + search.setError(StatusCode.NO_ERROR); return search; } Log.e(Settings.tag, "cgeoBase.searchByGeocode: No data from server"); - search.error = StatusCode.COMMUNICATION_ERROR; + search.setError(StatusCode.COMMUNICATION_ERROR); return search; } diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index 9c3ab4a..de1e8e2 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -4,10 +4,12 @@ import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgImage; import cgeo.geocaching.cgLog; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.GeopointFormatter; @@ -28,6 +30,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.EnumSet; import java.util.List; import java.util.Locale; @@ -75,13 +78,7 @@ final public class OkapiClient { return null; } - final cgCache cache = parseCache(data); - - long time = new Date().getTime(); - cache.setUpdated(time); - cache.setDetailedUpdate(time); - - return cache; + return parseCache(data); } public static List<cgCache> getCachesAround(final Geopoint center, IConnector connector) { @@ -177,6 +174,12 @@ final public class OkapiClient { cache.setLogs(parseLogs(response.getJSONArray(CACHE_LATEST_LOGS))); cache.setHidden(parseDate(response.getString(CACHE_HIDDEN))); + cache.setUpdated(System.currentTimeMillis()); + cache.setDetailedUpdate(cache.getUpdated()); + cache.setDetailed(true); + + // save full detailed caches + cgeoapplication.getInstance().saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); } catch (JSONException e) { Log.e(Settings.tag, "OkapiClient.parseCache", e); } diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 579c080..46cb481 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -255,8 +255,8 @@ public abstract class GPXParser extends FileParser { public void start(Attributes attrs) { try { if (attrs.getIndex("lat") > -1 && attrs.getIndex("lon") > -1) { - cache.setCoords(new Geopoint(new Double(attrs.getValue("lat")), - new Double(attrs.getValue("lon")))); + cache.setCoords(new Geopoint(Double.valueOf(attrs.getValue("lat")), + Double.valueOf(attrs.getValue("lon")))); } } catch (Exception e) { Log.w(Settings.tag, "Failed to parse waypoint's latitude and/or longitude."); diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index fd1bf13..08be66a 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -779,11 +779,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto ActivityMixin.invalidateOptionsMenu(activity); return true; case MENU_AS_LIST: { - final SearchResult searchResult = new SearchResult(); - search.totalCnt = caches.size(); - for (cgCache cache : caches) { - searchResult.addCache(cache); - } cgeocaches.startActivityMap(activity, search); return true; } @@ -1208,7 +1203,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto search = ConnectorFactory.searchByViewport(viewport, tokens); if (search != null) { downloaded = true; - if (search.error == StatusCode.NOT_LOGGED_IN) { + if (search.getError() == StatusCode.NOT_LOGGED_IN) { Login.login(); tokens = null; } else { diff --git a/main/src/com/viewpagerindicator/TitlePageIndicator.java b/main/src/com/viewpagerindicator/TitlePageIndicator.java index 17ec2bd..49b158a 100644 --- a/main/src/com/viewpagerindicator/TitlePageIndicator.java +++ b/main/src/com/viewpagerindicator/TitlePageIndicator.java @@ -89,7 +89,7 @@ public class TitlePageIndicator extends View implements PageIndicator { private boolean mBoldText; private int mColorText; private int mColorSelected; - private Path mPath; + private Path mPath = new Path(); private final Paint mPaintFooterLine; private IndicatorStyle mFooterIndicatorStyle; private final Paint mPaintFooterIndicator; @@ -405,7 +405,7 @@ public class TitlePageIndicator extends View implements PageIndicator { } //Draw the footer line - mPath = new Path(); + mPath.reset(); mPath.moveTo(0, height - mFooterLineHeight / 2f); mPath.lineTo(width, height - mFooterLineHeight / 2f); mPath.close(); @@ -413,7 +413,7 @@ public class TitlePageIndicator extends View implements PageIndicator { switch (mFooterIndicatorStyle) { case Triangle: - mPath = new Path(); + mPath.reset(); mPath.moveTo(halfWidth, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.lineTo(halfWidth + mFooterIndicatorHeight, height - mFooterLineHeight); mPath.lineTo(halfWidth - mFooterIndicatorHeight, height - mFooterLineHeight); @@ -427,7 +427,7 @@ public class TitlePageIndicator extends View implements PageIndicator { } RectF underlineBounds = bounds.get(page); - mPath = new Path(); + mPath.reset(); mPath.moveTo(underlineBounds.left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight); mPath.lineTo(underlineBounds.right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight); mPath.lineTo(underlineBounds.right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight); @@ -501,7 +501,9 @@ public class TitlePageIndicator extends View implements PageIndicator { mIsDragging = false; mActivePointerId = INVALID_POINTER; - if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); + if (mViewPager.isFakeDragging()) { + mViewPager.endFakeDrag(); + } break; case MotionEventCompat.ACTION_POINTER_DOWN: { |
