aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CacheDetailActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CacheDetailActivity.java')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java129
1 files changed, 71 insertions, 58 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index de754b9..847d04c 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -7,6 +7,7 @@ import cgeo.geocaching.apps.cache.GeneralAppsFactory;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
+import cgeo.geocaching.connector.gc.GCParser;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
@@ -15,7 +16,6 @@ import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.geopoint.HumanDistance;
import cgeo.geocaching.geopoint.IConversion;
import cgeo.geocaching.network.HtmlImage;
-import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.ui.DecryptTextClickListener;
import cgeo.geocaching.ui.Formatter;
@@ -39,6 +39,8 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
@@ -219,9 +221,9 @@ public class CacheDetailActivity extends AbstractActivity {
String uriQuery = uri.getQuery();
if (uriQuery != null) {
- Log.i(Settings.tag, "Opening URI: " + uriHost + uriPath + "?" + uriQuery);
+ Log.i("Opening URI: " + uriHost + uriPath + "?" + uriQuery);
} else {
- Log.i(Settings.tag, "Opening URI: " + uriHost + uriPath);
+ Log.i("Opening URI: " + uriHost + uriPath);
}
if (uriHost.contains("geocaching.com")) {
@@ -580,7 +582,7 @@ public class CacheDetailActivity extends AbstractActivity {
cache.openInBrowser(this);
return true;
} else if (menuItem == MENU_CACHES_AROUND) {
- cachesAround();
+ cgeocaches.startActivityCachesAround(this, cache.getCoords());
return true;
} else if (menuItem == MENU_CALENDAR) {
addToCalendarWithIntent();
@@ -607,7 +609,7 @@ public class CacheDetailActivity extends AbstractActivity {
private class LoadCacheHandler extends CancellableHandler {
@Override
public void handleRegularMessage(final Message msg) {
- if (cgBase.UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
+ if (UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
updateStatusMsg((String) msg.obj);
} else {
if (search == null) {
@@ -743,7 +745,7 @@ public class CacheDetailActivity extends AbstractActivity {
cacheDistanceView.setText(dist.toString());
cacheDistanceView.bringToFront();
} catch (Exception e) {
- Log.w(Settings.tag, "Failed to update location.");
+ Log.w("Failed to update location.");
}
}
}
@@ -773,25 +775,43 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- search = cgBase.searchByGeocode(geocode, StringUtils.isBlank(geocode) ? guid : null, 0, false, handler);
+ search = cgCache.searchByGeocode(geocode, StringUtils.isBlank(geocode) ? guid : null, 0, false, handler);
handler.sendMessage(Message.obtain());
}
}
/**
- * Starts activity to search for caches near this cache.
+ * Indicates whether the specified action can be used as an intent. This
+ * method queries the package manager for installed packages that can
+ * respond to an intent with the specified action. If no suitable package is
+ * found, this method returns false.
*
- * Also finishes this activity.
+ * @param context
+ * The application's environment.
+ * @param action
+ * The Intent action to check for availability.
+ * @param uri
+ * The Intent URI to check for availability.
+ *
+ * @return True if an Intent with the specified action can be sent and
+ * responded to, false otherwise.
*/
- private void cachesAround() {
- cgeocaches.startActivityCachesAround(this, cache.getCoords());
-
- finish();
+ private static boolean isIntentAvailable(Context context, String action, Uri uri) {
+ final PackageManager packageManager = context.getPackageManager();
+ final Intent intent;
+ if (uri == null) {
+ intent = new Intent(action);
+ } else {
+ intent = new Intent(action, uri);
+ }
+ List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ return list.size() > 0;
}
private void addToCalendarWithIntent() {
- final boolean calendarAddOnAvailable = cgBase.isIntentAvailable(this, ICalendar.INTENT, Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST));
+ final boolean calendarAddOnAvailable = isIntentAvailable(this, ICalendar.INTENT, Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST));
if (calendarAddOnAvailable) {
final Parameters params = new Parameters(
@@ -832,25 +852,6 @@ public class CacheDetailActivity extends AbstractActivity {
}
/**
- * Creates a {@link List} of all coordinates (cache and waypoints) for the current cache.
- *
- * @return A {@link List} of all coordinates
- */
- public List<IWaypoint> getCoordinates() {
- List<IWaypoint> coordinates = new ArrayList<IWaypoint>();
-
- // cache
- coordinates.add(cache);
-
- // waypoints
- if (cache.hasWaypoints()) {
- coordinates.addAll(cache.getWaypoints());
- }
-
- return coordinates;
- }
-
- /**
* Tries to navigate to the {@link cgCache} of this activity.
*/
private void startDefaultNavigation() {
@@ -1038,7 +1039,7 @@ public class CacheDetailActivity extends AbstractActivity {
((ViewPager) container).addView(view, 0);
}
} catch (Exception e) {
- Log.e(Settings.tag, "ViewPagerAdapter.instantiateItem ", e);
+ Log.e("ViewPagerAdapter.instantiateItem ", e);
}
return view;
@@ -1157,7 +1158,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
/**
- * lazy-creates the layout holding the icons of the chaches attributes
+ * lazy-creates the layout holding the icons of the caches attributes
* and makes it visible
*/
private void showAttributeIcons(LinearLayout attribBox, int parentWidth) {
@@ -1175,7 +1176,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
/**
- * lazy-creates the layout holding the discriptions of the chaches attributes
+ * lazy-creates the layout holding the descriptions of the caches attributes
* and makes it visible
*/
private void showAttributeDescriptions(LinearLayout attribBox) {
@@ -1457,7 +1458,7 @@ public class CacheDetailActivity extends AbstractActivity {
if (cache.getHiddenDate() != null) {
long time = cache.getHiddenDate().getTime();
if (time > 0) {
- String dateString = cgBase.formatFullDate(time);
+ String dateString = Formatter.formatFullDate(time);
if (cache.isEventCache()) {
dateString = DateUtils.formatDateTime(cgeoapplication.getInstance().getBaseContext(), time, DateUtils.FORMAT_SHOW_WEEKDAY) + ", " + dateString;
}
@@ -1556,7 +1557,7 @@ public class CacheDetailActivity extends AbstractActivity {
private class StoreCacheHandler extends CancellableHandler {
@Override
public void handleRegularMessage(Message msg) {
- if (cgBase.UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
+ if (UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
updateStatusMsg((String) msg.obj);
} else {
storeThread = null;
@@ -1574,7 +1575,7 @@ public class CacheDetailActivity extends AbstractActivity {
private class RefreshCacheHandler extends CancellableHandler {
@Override
public void handleRegularMessage(Message msg) {
- if (cgBase.UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
+ if (UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
updateStatusMsg((String) msg.obj);
} else {
refreshThread = null;
@@ -1658,7 +1659,7 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- cgBase.refreshCache(CacheDetailActivity.this, cache.getGeocode(), cache.getListId(), handler);
+ cache.refresh(CacheDetailActivity.this, cache.getListId(), handler);
handler.sendEmptyMessage(0);
}
@@ -1688,7 +1689,7 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- cgBase.dropCache(cache, handler);
+ cache.drop(handler);
}
}
@@ -1744,7 +1745,7 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- handler.sendEmptyMessage(cgBase.addToWatchlist(cache));
+ handler.sendEmptyMessage(GCParser.addToWatchlist(cache));
}
}
@@ -1758,7 +1759,7 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- handler.sendEmptyMessage(cgBase.removeFromWatchlist(cache));
+ handler.sendEmptyMessage(GCParser.removeFromWatchlist(cache));
}
}
@@ -1845,9 +1846,7 @@ public class CacheDetailActivity extends AbstractActivity {
private class PreviewMapTask extends AsyncTask<Void, Void, BitmapDrawable> {
@Override
- protected BitmapDrawable doInBackground(Void... params) {
- BitmapDrawable image = null;
-
+ protected BitmapDrawable doInBackground(Void... parameters) {
try {
final String latlonMap = cache.getCoords().format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA);
@@ -1858,15 +1857,15 @@ public class CacheDetailActivity extends AbstractActivity {
final int height = (int) (110 * metrics.density);
// TODO move this code to StaticMapProvider and use its constant values
- final String markerUrl = Network.urlencode_rfc3986("http://cgeo.carnero.cc/_markers/my_location_mdpi.png");
+ final String markerUrl = "http://cgeo.carnero.cc/_markers/my_location_mdpi.png";
final HtmlImage mapGetter = new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), false, 0, false);
- image = mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?zoom=15&size=" + width + "x" + height + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7Cshadow:false%7C" + latlonMap + "&sensor=false");
+ final Parameters params = new Parameters("zoom", "15", "size", width + "x" + height, "maptype", "roadmap", "markers", "icon:" + markerUrl + "|shadow:false|" + latlonMap, "sensor", "false");
+ return mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?" + params);
} catch (Exception e) {
- Log.w(Settings.tag, "CacheDetailActivity.PreviewMapTask", e);
+ Log.w("CacheDetailActivity.PreviewMapTask", e);
+ return null;
}
-
- return image;
}
@Override
@@ -2190,7 +2189,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
}
- view.setAdapter(new ArrayAdapter<cgLog>(CacheDetailActivity.this, R.layout.cacheview_logs_item, cache.getLogs(allLogs)) {
+ view.setAdapter(new ArrayAdapter<LogEntry>(CacheDetailActivity.this, R.layout.cacheview_logs_item, cache.getLogs(allLogs)) {
final UserActionsClickListener userActionsClickListener = new UserActionsClickListener();
final DecryptTextClickListener decryptTextClickListener = new DecryptTextClickListener();
@@ -2206,10 +2205,10 @@ public class CacheDetailActivity extends AbstractActivity {
rowView.setTag(holder);
}
- final cgLog log = getItem(position);
+ final LogEntry log = getItem(position);
if (log.date > 0) {
- holder.date.setText(cgBase.formatShortDate(log.date));
+ holder.date.setText(Formatter.formatShortDate(log.date));
holder.date.setVisibility(View.VISIBLE);
} else {
holder.date.setVisibility(View.GONE);
@@ -2239,10 +2238,10 @@ public class CacheDetailActivity extends AbstractActivity {
}
// images
- if (CollectionUtils.isNotEmpty(log.logImages)) {
+ if (log.hasLogImages()) {
List<String> titles = new ArrayList<String>(5);
- for (cgImage image : log.logImages) {
+ for (cgImage image : log.getLogImages()) {
if (StringUtils.isNotBlank(image.getTitle())) {
titles.add(image.getTitle());
}
@@ -2256,7 +2255,7 @@ public class CacheDetailActivity extends AbstractActivity {
holder.images.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- cgeoimages.startActivityLogImages(CacheDetailActivity.this, cache.getGeocode(), new ArrayList<cgImage>(log.logImages));
+ cgeoimages.startActivityLogImages(CacheDetailActivity.this, cache.getGeocode(), new ArrayList<cgImage>(log.getLogImages()));
}
});
} else {
@@ -2368,7 +2367,7 @@ public class CacheDetailActivity extends AbstractActivity {
// info
final List<String> infoTextList = new ArrayList<String>(3);
- if (WaypointType.ALL_TYPES_EXCEPT_OWN.containsKey(wpt.getWaypointType())) {
+ if (WaypointType.ALL_TYPES_EXCEPT_OWN.contains(wpt.getWaypointType())) {
infoTextList.add(wpt.getWaypointType().getL10n());
}
if (cgWaypoint.PREFIX_OWN.equalsIgnoreCase(wpt.getPrefix())) {
@@ -2506,4 +2505,18 @@ public class CacheDetailActivity extends AbstractActivity {
return view;
}
}
+
+ public static void startActivity(final Context context, final String geocode, final String cacheName) {
+ final Intent cachesIntent = new Intent(context, CacheDetailActivity.class);
+ cachesIntent.putExtra("geocode", geocode);
+ cachesIntent.putExtra("name", cacheName);
+ context.startActivity(cachesIntent);
+ }
+
+ public static void startActivityGuid(final Context context, final String guid, final String cacheName) {
+ final Intent cacheIntent = new Intent(context, CacheDetailActivity.class);
+ cacheIntent.putExtra("guid", guid);
+ cacheIntent.putExtra("name", cacheName);
+ context.startActivity(cacheIntent);
+ }
}