diff options
-rw-r--r-- | main/res/layout/simple_list_item_1.xml | 26 | ||||
-rw-r--r-- | main/src/cgeo/calendar/ICalendar.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 29 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/CachePopup.java | 9 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/WaypointPopup.java | 9 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java | 53 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 72 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeopoint.java | 7 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/oc/OkapiClient.java | 1 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/geopoint/Geopoint.java | 2 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/files/GPXParserTest.java | 3 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/files/LocParserTest.java | 3 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java | 1 |
15 files changed, 88 insertions, 133 deletions
diff --git a/main/res/layout/simple_list_item_1.xml b/main/res/layout/simple_list_item_1.xml deleted file mode 100644 index 039b0c1..0000000 --- a/main/res/layout/simple_list_item_1.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2006 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<TextView xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@android:id/text1" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceLarge" - android:gravity="center_vertical" - android:paddingLeft="6dip" - android:minHeight="?android:attr/listPreferredItemHeight" - android:textColor="?text_color" -/> diff --git a/main/src/cgeo/calendar/ICalendar.java b/main/src/cgeo/calendar/ICalendar.java index bc08ef4..856de1a 100644 --- a/main/src/cgeo/calendar/ICalendar.java +++ b/main/src/cgeo/calendar/ICalendar.java @@ -1,6 +1,8 @@ package cgeo.calendar; public interface ICalendar { + static final String CALENDAR_ADDON_URI = "market://details?id=cgeo.calendar"; + static final String INTENT = "cgeo.calendar.RESERVE"; static final String URI_SCHEME = "add"; diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index afa1dad..15c4909 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -122,8 +122,6 @@ public class CacheDetailActivity extends AbstractActivity { private static final int CONTEXT_MENU_WAYPOINT_CACHES_AROUND = 1239; private static final int CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION = 1240; - private static final String CALENDAR_ADDON_URI = "market://details?id=cgeo.calendar"; - private cgCache cache; private final Progress progress = new Progress(); private SearchResult search; @@ -495,7 +493,7 @@ public class CacheDetailActivity extends AbstractActivity { case CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION: { final cgWaypoint waypoint = cache.getWaypoint(index); if (waypoint != null) { - NavigationAppFactory.startDefaultNavigationApplication(this, null, waypoint, null); + NavigationAppFactory.startDefaultNavigationApplication(1, this, waypoint); } } break; @@ -812,7 +810,7 @@ public class CacheDetailActivity extends AbstractActivity { .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(CALENDAR_ADDON_URI)); + intent.setData(Uri.parse(ICalendar.CALENDAR_ADDON_URI)); startActivity(intent); } }) @@ -830,26 +828,14 @@ public class CacheDetailActivity extends AbstractActivity { * Tries to navigate to the {@link cgCache} of this activity. */ private void startDefaultNavigation() { - if (cache == null || cache.getCoords() == null) { - showToast(res.getString(R.string.err_location_unknown)); - return; - } - - //TODO: previously this used also the search argument "search". check if still needed - NavigationAppFactory.startDefaultNavigationApplication(this, cache, null, null); + NavigationAppFactory.startDefaultNavigationApplication(1, this, cache); } /** * Tries to navigate to the {@link cgCache} of this activity. */ private void startDefaultNavigation2() { - if (cache == null || cache.getCoords() == null) { - showToast(res.getString(R.string.err_location_unknown)); - return; - } - - //TODO: previously this used also the search argument "search". check if still needed - NavigationAppFactory.startDefaultNavigationApplication2(this, cache, null, null); + NavigationAppFactory.startDefaultNavigationApplication(2, this, cache); } /** @@ -2312,13 +2298,13 @@ public class CacheDetailActivity extends AbstractActivity { wpNavView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - NavigationAppFactory.startDefaultNavigationApplication(CacheDetailActivity.this, null, wpt, null); + NavigationAppFactory.startDefaultNavigationApplication(1, CacheDetailActivity.this, wpt); } }); wpNavView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - NavigationAppFactory.startDefaultNavigationApplication2(CacheDetailActivity.this, null, wpt, null); + NavigationAppFactory.startDefaultNavigationApplication(2, CacheDetailActivity.this, wpt); return true; } }); @@ -2376,8 +2362,7 @@ public class CacheDetailActivity extends AbstractActivity { view = (ListView) getLayoutInflater().inflate(R.layout.cacheview_inventory, null); - // TODO: Switch back to Android-resource and delete copied one - view.setAdapter(new ArrayAdapter<cgTrackable>(CacheDetailActivity.this, R.layout.simple_list_item_1, cache.getInventory())); + view.setAdapter(new ArrayAdapter<cgTrackable>(CacheDetailActivity.this, android.R.layout.simple_list_item_1, cache.getInventory())); view.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java index 91c27c6..569aad1 100644 --- a/main/src/cgeo/geocaching/CachePopup.java +++ b/main/src/cgeo/geocaching/CachePopup.java @@ -232,12 +232,7 @@ public class CachePopup extends AbstractPopupActivity { @Override protected void navigateTo() { - if (cache == null || cache.getCoords() == null) { - showToast(res.getString(R.string.err_location_unknown)); - return; - } - - NavigationAppFactory.startDefaultNavigationApplication(this, cache, null, null); + NavigationAppFactory.startDefaultNavigationApplication(1, this, cache); } /** @@ -249,7 +244,7 @@ public class CachePopup extends AbstractPopupActivity { showToast(res.getString(R.string.cache_coordinates_no)); return; } - NavigationAppFactory.startDefaultNavigationApplication2(this, cache, null, null); + NavigationAppFactory.startDefaultNavigationApplication(2, this, cache); finish(); } diff --git a/main/src/cgeo/geocaching/WaypointPopup.java b/main/src/cgeo/geocaching/WaypointPopup.java index 87ac04e..7fbfe10 100644 --- a/main/src/cgeo/geocaching/WaypointPopup.java +++ b/main/src/cgeo/geocaching/WaypointPopup.java @@ -79,12 +79,7 @@ public class WaypointPopup extends AbstractPopupActivity { @Override protected void navigateTo() { - if (waypoint == null || waypoint.getCoords() == null) { - showToast(res.getString(R.string.err_location_unknown)); - return; - } - - NavigationAppFactory.startDefaultNavigationApplication(this, null, waypoint, null); + NavigationAppFactory.startDefaultNavigationApplication(1, this, waypoint); } /** @@ -96,7 +91,7 @@ public class WaypointPopup extends AbstractPopupActivity { showToast(res.getString(R.string.cache_coordinates_no)); return; } - NavigationAppFactory.startDefaultNavigationApplication2(this, null, waypoint, null); + NavigationAppFactory.startDefaultNavigationApplication(2, this, waypoint); finish(); } diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 903dbd4..50520ac 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -4,6 +4,8 @@ import cgeo.geocaching.R; import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.apps.AbstractAppFactory; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.Log; @@ -163,10 +165,10 @@ public final class NavigationAppFactory extends AbstractAppFactory { * Adds the installed navigation tools to the given menu. * Use {@link #onMenuItemSelected(MenuItem, Activity, cgCache)} on * selection event to start the selected navigation tool. - * + * * <b>Only use this way if {@link #showNavigationMenu(Activity, cgCache, cgWaypoint, Geopoint, boolean, boolean)} is * not suitable for the given usecase.</b> - * + * * @param menu */ public static void addMenuItems(final Menu menu, final cgCache cache) { @@ -229,27 +231,54 @@ public final class NavigationAppFactory extends AbstractAppFactory { /** * Starts the default navigation tool if correctly set and installed or the compass app as default fallback. * + * @param defaultNavigation + * * @param activity * @param cache - * @param waypoint - * @param destination */ - public static void startDefaultNavigationApplication(Activity activity, cgCache cache, - cgWaypoint waypoint, final Geopoint destination) { - invokeApp(activity, cache, waypoint, destination, getDefaultNavigationApplication()); + public static void startDefaultNavigationApplication(int defaultNavigation, Activity activity, cgCache cache) { + if (cache == null || cache.getCoords() == null) { + ActivityMixin.showToast(activity, cgeoapplication.getInstance().getString(R.string.err_location_unknown)); + return; + } + + invokeApp(activity, cache, null, null, getDefaultNavigationApplication(defaultNavigation)); + } + + private static NavigationApp getDefaultNavigationApplication(int defaultNavigation) { + if (defaultNavigation == 2) { + return getNavigationAppFromSetting(Settings.getDefaultNavigationTool2()); + } + return getNavigationAppFromSetting(Settings.getDefaultNavigationTool()); } /** - * Starts the second default navigation tool if correctly set and installed or the compass app as default fallback. + * Starts the default navigation tool if correctly set and installed or the compass app as default fallback. * * @param activity - * @param cache * @param waypoint + */ + public static void startDefaultNavigationApplication(int defaultNavigation, Activity activity, cgWaypoint waypoint) { + if (waypoint == null || waypoint.getCoords() == null) { + ActivityMixin.showToast(activity, cgeoapplication.getInstance().getString(R.string.err_location_unknown)); + return; + } + invokeApp(activity, null, waypoint, null, getDefaultNavigationApplication(defaultNavigation)); + } + + /** + * Starts the default navigation tool if correctly set and installed or the compass app as default fallback. + * + * @param activity * @param destination */ - public static void startDefaultNavigationApplication2(Activity activity, cgCache cache, - cgWaypoint waypoint, final Geopoint destination) { - invokeApp(activity, cache, waypoint, destination, getNavigationAppFromSetting(Settings.getDefaultNavigationTool2())); + public static void startDefaultNavigationApplication(int defaultNavigation, Activity activity, final Geopoint destination) { + if (destination == null) { + ActivityMixin.showToast(activity, cgeoapplication.getInstance().getString(R.string.err_location_unknown)); + return; + } + + invokeApp(activity, null, null, destination, getDefaultNavigationApplication(defaultNavigation)); } /** diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 1bc4126..1d545a9 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -858,57 +858,35 @@ public class cgData { return false; } - /** Cache stored in DB with listId >= 1 */ - // TODO Simply like getCacheDescription() + /** is cache stored in one of the lists (not only temporary) */ public boolean isOffline(String geocode, String guid) { + if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) { + return false; + } init(); - Cursor cursor; - long listId = StoredList.TEMPORARY_LIST_ID; - try { + final SQLiteStatement listId; + final String value; if (StringUtils.isNotBlank(geocode)) { - cursor = databaseRO.query( - dbTableCaches, - new String[] { "reason" }, - "geocode = ?", - new String[] { geocode }, - null, - null, - null, - "1"); - } else if (StringUtils.isNotBlank(guid)) { - cursor = databaseRO.query( - dbTableCaches, - new String[] { "reason" }, - "guid = ? ", - new String[] { guid }, - null, - null, - null, - "1"); - } else { - return false; + listId = getStatementListIdFromGeocode(); + value = geocode; } - - if (cursor != null) { - final int cnt = cursor.getCount(); - int index; - - if (cnt > 0) { - cursor.moveToFirst(); - - index = cursor.getColumnIndex("reason"); - listId = cursor.getLong(index); - } - - cursor.close(); + else { + listId = getStatementListIdFromGuid(); + value = guid; } + synchronized (listId) { + listId.bindString(1, value); + return listId.simpleQueryForLong() != StoredList.TEMPORARY_LIST_ID; + } + } catch (SQLiteDoneException e) { + // Do nothing, it only means we have no information on the cache } catch (Exception e) { - Log.e("cgData.isOffline: " + e.toString()); + Log.e("cgData.isOffline", e); } - return listId >= StoredList.STANDARD_LIST_ID; + return false; } public String getGeocodeForGuid(String guid) { @@ -955,11 +933,11 @@ public class cgData { /** * Save/store a cache to the CacheCache - * + * * @param cache * the Cache to save in the CacheCache/DB * @param saveFlags - * + * * @return true = cache saved successfully to the CacheCache/DB */ public boolean saveCache(cgCache cache, EnumSet<LoadFlags.SaveFlag> saveFlags) { @@ -2837,6 +2815,14 @@ public class cgData { return getStatement("descriptionFromGeocode", "SELECT description FROM " + dbTableCaches + " WHERE geocode = ?"); } + private SQLiteStatement getStatementListIdFromGeocode() { + return getStatement("listFromGeocode", "SELECT reason FROM " + dbTableCaches + " WHERE geocode = ?"); + } + + private SQLiteStatement getStatementListIdFromGuid() { + return getStatement("listFromGeocode", "SELECT reason FROM " + dbTableCaches + " WHERE guid = ?"); + } + private SQLiteStatement getStatementCacheId() { return getStatement("cacheIdFromGeocode", "SELECT cacheid FROM " + dbTableCaches + " WHERE geocode = ?"); } diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index db63114..4292fef 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -1086,7 +1086,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object final int id = item.getItemId(); switch (id) { case MENU_DEFAULT_NAVIGATION: - NavigationAppFactory.startDefaultNavigationApplication(this, cache, null, null); + NavigationAppFactory.startDefaultNavigationApplication(1, this, cache); break; case MENU_NAVIGATION: NavigationAppFactory.showNavigationMenu(this, cache, null, null); diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java index 084e909..0c3c991 100644 --- a/main/src/cgeo/geocaching/cgeopoint.java +++ b/main/src/cgeo/geocaching/cgeopoint.java @@ -447,12 +447,7 @@ public class cgeopoint extends AbstractActivity implements IObserver<IGeoData> { } private void navigateTo(Geopoint geopoint) { - if (geopoint == null) { - showToast(res.getString(R.string.err_location_unknown)); - return; - } - - NavigationAppFactory.startDefaultNavigationApplication(this, null, null, geopoint); + NavigationAppFactory.startDefaultNavigationApplication(1, this, geopoint); } private void cachesAround() { diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java index 46214cc..0212a64 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java @@ -246,7 +246,6 @@ final public class OkapiClient { private static void setLocation(final cgCache cache, final String location) { final String latitude = StringUtils.substringBefore(location, "|"); final String longitude = StringUtils.substringAfter(location, "|"); - // FIXME: the next line should be a setter at cgCache cache.setCoords(new Geopoint(latitude, longitude)); } diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index c8bf2f4..e083f58 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -88,7 +88,7 @@ public abstract class GPXParser extends FileParser { /** * Parser result. Maps geocode to cache. */ - private final Map<String, cgCache> result = new HashMap<String, cgCache>(500); + private final Map<String, cgCache> result = new HashMap<String, cgCache>(100); private ProgressInputStream progressStream; private final class UserDataListener implements EndTextElementListener { diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java index 9d76ae3..26c80d6 100644 --- a/main/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java @@ -359,8 +359,6 @@ public final class Geopoint implements ICoordinates, Parcelable { return null; } - //FIXME: this interface implementation is totally confusing as it returns the class itself. - // it can therefore be removed completely (and any invocation of it) without any disadvantages @Override public Geopoint getCoords() { return this; diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index 47975c9..00e0447 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -193,13 +193,12 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { } } - // TODO: may need to sort by geocode when a test imports more than one cache return new ArrayList<cgCache>(caches); } public static void testParseDateWithFractionalSeconds() { // was experienced in GSAK file - String dateString = "2011-08-13T02:52:18.103Z"; + final String dateString = "2011-08-13T02:52:18.103Z"; try { GPXParser.parseDate(dateString); } catch (ParseException e) { diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java index 7e7a1be..5170577 100644 --- a/tests/src/cgeo/geocaching/files/LocParserTest.java +++ b/tests/src/cgeo/geocaching/files/LocParserTest.java @@ -14,7 +14,7 @@ import java.util.List; public class LocParserTest extends AbstractResourceInstrumentationTestCase { private List<cgCache> readLoc(int resourceId) throws IOException, ParserException { - LocParser parser = new LocParser(1); + final LocParser parser = new LocParser(1); Collection<cgCache> caches = null; final InputStream instream = getResourceStream(resourceId); try { @@ -25,7 +25,6 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { instream.close(); } - // TODO: may need to sort by geocode when a test imports more than one cache return new ArrayList<cgCache>(caches); } diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java index e07a518..ab5c290 100644 --- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java +++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java @@ -21,7 +21,6 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument try { ins.close(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } return result; |