aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo
diff options
context:
space:
mode:
authorPortree-Kid <keith.paterson@gmx.de>2012-05-04 22:25:08 +0200
committerPortree-Kid <keith.paterson@gmx.de>2012-05-04 22:35:56 +0200
commit38fe38b63637879685bbaa5f443a55bba8e72f1d (patch)
tree24bfbc197a07fe0b526161fc4d263f884d2bd9a4 /main/src/cgeo
parentcbf5731ebda7399920f37876df2772d4ffe57563 (diff)
downloadcgeo-38fe38b63637879685bbaa5f443a55bba8e72f1d.zip
cgeo-38fe38b63637879685bbaa5f443a55bba8e72f1d.tar.gz
cgeo-38fe38b63637879685bbaa5f443a55bba8e72f1d.tar.bz2
Refactoring Popups. Added Superclass
Diffstat (limited to 'main/src/cgeo')
-rw-r--r--main/src/cgeo/geocaching/AbstractPopupActivity.java389
-rw-r--r--main/src/cgeo/geocaching/CachePopup.java360
-rw-r--r--main/src/cgeo/geocaching/WaypointPopup.java394
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java646
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java4
5 files changed, 799 insertions, 994 deletions
diff --git a/main/src/cgeo/geocaching/AbstractPopupActivity.java b/main/src/cgeo/geocaching/AbstractPopupActivity.java
new file mode 100644
index 0000000..acb1b37
--- /dev/null
+++ b/main/src/cgeo/geocaching/AbstractPopupActivity.java
@@ -0,0 +1,389 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.gcvote.GCVote;
+import cgeo.geocaching.gcvote.GCVoteRating;
+import cgeo.geocaching.geopoint.HumanDistance;
+import cgeo.geocaching.utils.Log;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.graphics.Rect;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnLongClickListener;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public abstract class AbstractPopupActivity extends AbstractActivity {
+
+ private static final int MENU_CACHES_AROUND = 5;
+ private static final int MENU_NAVIGATION = 3;
+ private static final int MENU_DEFAULT_NAVIGATION = 2;
+ private static final int MENU_SHOW_IN_BROWSER = 7;
+ protected static final String EXTRA_GEOCODE = "geocode";
+
+ protected class UpdateLocation extends GeoObserver {
+
+ @Override
+ protected void updateLocation(final IGeoData geo) {
+ try {
+ if (geo.getCoords() != null && cache != null && cache.getCoords() != null) {
+ cacheDistance.setText(HumanDistance.getHumanDistance(geo.getCoords().distanceTo(cache.getCoords())));
+ cacheDistance.bringToFront();
+ }
+ } catch (Exception e) {
+ Log.w("Failed to UpdateLocation location.");
+ }
+ }
+ }
+
+ protected LayoutInflater inflater = null;
+ protected cgCache cache = null;
+ protected TextView cacheDistance = null;
+ private GeoObserver geoUpdate = new UpdateLocation();
+
+ protected String geocode = null;
+
+ private Handler ratingHandler = new Handler() {
+
+ @Override
+ public void handleMessage(Message msg) {
+ try {
+ final Bundle data = msg.getData();
+
+ setRating(data.getFloat("rating"), data.getInt("votes"));
+ } catch (Exception e) {
+ // nothing
+ }
+ }
+ };
+ private int layout;
+
+ public AbstractPopupActivity(String helpTopic, int layout) {
+ super(helpTopic);
+ this.layout = layout;
+ }
+
+ protected void aquireGCVote() {
+ if (Settings.isRatingWanted() && cache.supportsGCVote()) {
+ (new Thread() {
+
+ @Override
+ public void run() {
+ GCVoteRating rating = GCVote.getRating(cache.getGuid(), geocode);
+
+ if (rating == null) {
+ return;
+ }
+
+ Message msg = Message.obtain();
+ Bundle bundle = new Bundle();
+ bundle.putFloat("rating", rating.getRating());
+ bundle.putInt("votes", rating.getVotes());
+ msg.setData(bundle);
+
+ ratingHandler.sendMessage(msg);
+ }
+ }).start();
+ }
+ }
+
+ protected RelativeLayout createCacheState() {
+ RelativeLayout itemLayout;
+ TextView itemName;
+ TextView itemValue;
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+
+ itemName.setText(res.getString(R.string.cache_status));
+
+ final StringBuilder state = new StringBuilder();
+ if (cache.isFound()) {
+ if (state.length() > 0) {
+ state.append(", ");
+ }
+ state.append(res.getString(R.string.cache_status_found));
+ }
+ if (cache.isArchived()) {
+ if (state.length() > 0) {
+ state.append(", ");
+ }
+ state.append(res.getString(R.string.cache_status_archived));
+ }
+ if (cache.isDisabled()) {
+ if (state.length() > 0) {
+ state.append(", ");
+ }
+ state.append(res.getString(R.string.cache_status_disabled));
+ }
+ if (cache.isPremiumMembersOnly()) {
+ if (state.length() > 0) {
+ state.append(", ");
+ }
+ state.append(res.getString(R.string.cache_status_premium));
+ }
+
+ itemValue.setText(state.toString());
+ return itemLayout;
+ }
+
+ protected RelativeLayout createDifficulty() {
+ RelativeLayout itemLayout;
+ TextView itemName;
+ TextView itemValue;
+ LinearLayout itemStars;
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+ itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
+
+ itemName.setText(res.getString(R.string.cache_difficulty));
+ itemValue.setText(String.format("%.1f", cache.getDifficulty()) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
+ for (int i = 0; i <= 4; i++) {
+ ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
+ if ((cache.getDifficulty() - i) >= 1.0) {
+ star.setImageResource(R.drawable.star_on);
+ } else if ((cache.getDifficulty() - i) > 0.0) {
+ star.setImageResource(R.drawable.star_half);
+ } else {
+ star.setImageResource(R.drawable.star_off);
+ }
+ itemStars.addView(star);
+ }
+ return itemLayout;
+ }
+
+ protected RelativeLayout createTerrain() {
+ RelativeLayout itemLayout;
+ TextView itemName;
+ TextView itemValue;
+ LinearLayout itemStars;
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+ itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
+
+ itemName.setText(res.getString(R.string.cache_terrain));
+ itemValue.setText(String.format("%.1f", cache.getTerrain()) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
+ for (int i = 0; i <= 4; i++) {
+ ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
+ if ((cache.getTerrain() - i) >= 1.0) {
+ star.setImageResource(R.drawable.star_on);
+ } else if ((cache.getTerrain() - i) > 0.0) {
+ star.setImageResource(R.drawable.star_half);
+ } else {
+ star.setImageResource(R.drawable.star_off);
+ }
+ itemStars.addView(star);
+ }
+ return itemLayout;
+ }
+
+ @Override
+ public void goManual(View view) {
+ super.goManual(view);
+ finish();
+ }
+
+ protected void init() {
+ app.setAction(geocode);
+
+ cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+
+ if (cache == null) {
+ showToast(res.getString(R.string.err_detail_cache_find));
+
+ finish();
+ return;
+ }
+
+ if (CacheType.UNKNOWN == cache.getType()) {
+ Set<String> geocodes = new HashSet<String>();
+ geocodes.add(geocode);
+ SearchResult search = ConnectorFactory.searchByGeocodes(geocodes);
+ cache = search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
+ }
+ inflater = getLayoutInflater();
+ geocode = cache.getGeocode().toUpperCase();
+
+ }
+
+ protected abstract void cachesAround();
+
+ protected abstract void logOffline(int menuItem);
+
+ protected abstract void logVisit();
+
+ protected abstract void navigateTo();
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // set layout
+ setTheme(R.style.transparent);
+ setContentView(layout);
+ setTitle(res.getString(R.string.detail));
+
+ // get parameters
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ geocode = extras.getString(EXTRA_GEOCODE);
+ }
+
+ if (StringUtils.isBlank(geocode)) {
+ showToast(res.getString(R.string.err_detail_cache_find));
+
+ finish();
+ return;
+ }
+
+ ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation);
+ defaultNavigationImageView.setOnLongClickListener(new OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ startDefaultNavigation2();
+ return true;
+ }
+ });
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(0, MENU_DEFAULT_NAVIGATION, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()).setIcon(R.drawable.ic_menu_compass); // default navigation tool
+ menu.add(0, MENU_NAVIGATION, 0, res.getString(R.string.cache_menu_navigate)).setIcon(R.drawable.ic_menu_mapmode);
+ addVisitMenu(menu, cache);
+ menu.add(0, MENU_CACHES_AROUND, 0, res.getString(R.string.cache_menu_around)).setIcon(R.drawable.ic_menu_rotate); // caches around
+ menu.add(0, MENU_SHOW_IN_BROWSER, 0, res.getString(R.string.cache_menu_browser)).setIcon(R.drawable.ic_menu_info_details); // browser
+
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ final int menuItem = item.getItemId();
+
+ switch (menuItem) {
+ case MENU_DEFAULT_NAVIGATION:
+ navigateTo();
+ break;
+ case MENU_NAVIGATION:
+ showNavigationMenu();
+ break;
+ case MENU_CACHES_AROUND:
+ cachesAround();
+ break;
+ case MENU_LOG_VISIT:
+ logVisit();
+ break;
+ case MENU_SHOW_IN_BROWSER:
+ showInBrowser();
+ break;
+ default:
+ logOffline(menuItem);
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onPause() {
+ app.deleteGeoObserver(geoUpdate);
+ super.onPause();
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+
+ try {
+ if (cache != null && cache.getCoords() != null) {
+ menu.findItem(MENU_DEFAULT_NAVIGATION).setVisible(true);
+ menu.findItem(MENU_NAVIGATION).setVisible(true);
+ menu.findItem(MENU_CACHES_AROUND).setVisible(true);
+ } else {
+ menu.findItem(MENU_DEFAULT_NAVIGATION).setVisible(false);
+ menu.findItem(MENU_NAVIGATION).setVisible(false);
+ menu.findItem(MENU_CACHES_AROUND).setVisible(false);
+ }
+
+ menu.findItem(MENU_LOG_VISIT).setEnabled(Settings.isLogin());
+ } catch (Exception e) {
+ // nothing
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ init();
+ app.addGeoObserver(geoUpdate);
+ }
+
+ @Override
+ public boolean onTouchEvent(final MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_UP) {
+ final Rect r = new Rect(0, 0, 0, 0);
+ getWindow().getDecorView().getHitRect(r);
+ if (!r.contains((int) event.getX(), (int) event.getY())) {
+ finish();
+ return true;
+ }
+ }
+ return super.onTouchEvent(event);
+ }
+
+ protected void setRating(float rating, int votes) {
+ if (rating <= 0) {
+ return;
+ }
+
+ RelativeLayout itemLayout;
+ TextView itemName;
+ TextView itemValue;
+ LinearLayout itemStars;
+ LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
+
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+ itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
+
+ itemName.setText(res.getString(R.string.cache_rating));
+ itemValue.setText(String.format("%.1f", rating) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
+ itemStars.addView(createStarRating(rating, 5, this), 1);
+
+ if (votes > 0) {
+ final TextView itemAddition = (TextView) itemLayout.findViewById(R.id.addition);
+ itemAddition.setText("(" + votes + ")");
+ itemAddition.setVisibility(View.VISIBLE);
+ }
+ detailsList.addView(itemLayout);
+ }
+
+ protected abstract void showInBrowser();
+
+ protected abstract void showNavigationMenu();
+
+ protected abstract void startDefaultNavigation2();
+
+}
diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java
new file mode 100644
index 0000000..4a965f8
--- /dev/null
+++ b/main/src/cgeo/geocaching/CachePopup.java
@@ -0,0 +1,360 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.enumerations.CacheSize;
+import cgeo.geocaching.enumerations.LogType;
+import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.Log;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Message;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+public class CachePopup extends AbstractPopupActivity {
+ private ProgressDialog storeDialog = null;
+ private ProgressDialog dropDialog = null;
+ private CancellableHandler storeCacheHandler = new CancellableHandler() {
+
+ @Override
+ public void handleRegularMessage(Message msg) {
+ try {
+ if (storeDialog != null) {
+ storeDialog.dismiss();
+ }
+
+ finish();
+ return;
+ } catch (Exception e) {
+ showToast(res.getString(R.string.err_store));
+
+ Log.e("cgeopopup.storeCacheHandler: " + e.toString());
+ }
+
+ if (storeDialog != null) {
+ storeDialog.dismiss();
+ }
+ init();
+ }
+ };
+ private Handler dropCacheHandler = new Handler() {
+
+ @Override
+ public void handleMessage(Message msg) {
+ try {
+ if (dropDialog != null) {
+ dropDialog.dismiss();
+ }
+
+ finish();
+ return;
+ } catch (Exception e) {
+ showToast(res.getString(R.string.err_drop));
+
+ Log.e("cgeopopup.dropCacheHandler: " + e.toString());
+ }
+
+ if (dropDialog != null) {
+ dropDialog.dismiss();
+ }
+ init();
+ }
+ };
+
+ public CachePopup() {
+ super("c:geo-cache-info", R.layout.popup);
+ }
+
+ @Override
+ protected void logOffline(final int menuItem) {
+ cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
+ }
+
+ @Override
+ protected void showInBrowser() {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode())));
+ }
+
+ @Override
+ protected void logVisit() {
+ cache.logVisit(this);
+ finish();
+ }
+
+ @Override
+ protected void showNavigationMenu() {
+ NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, cache, null, null);
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+ try {
+ RelativeLayout itemLayout;
+ TextView itemName;
+ TextView itemValue;
+
+ if (StringUtils.isNotBlank(cache.getName())) {
+ setTitle(cache.getName());
+ } else {
+ setTitle(geocode.toUpperCase());
+ }
+
+ LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
+ detailsList.removeAllViews();
+
+ // actionbar icon
+ ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cache.getType().markerId), null, null, null);
+
+ // cache type
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+
+ itemName.setText(res.getString(R.string.cache_type));
+
+ String cacheType = cache.getType().getL10n();
+ String cacheSize = cache.getSize() != CacheSize.UNKNOWN ? " (" + cache.getSize().getL10n() + ")" : "";
+ itemValue.setText(cacheType + cacheSize);
+ detailsList.addView(itemLayout);
+
+ // gc-code
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+
+ itemName.setText(res.getString(R.string.cache_geocode));
+ itemValue.setText(cache.getGeocode().toUpperCase());
+ detailsList.addView(itemLayout);
+
+ // cache state
+ if (cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) {
+ itemLayout = createCacheState();
+ detailsList.addView(itemLayout);
+ }
+
+ // distance
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+
+ itemName.setText(res.getString(R.string.cache_distance));
+ itemValue.setText("--");
+ detailsList.addView(itemLayout);
+ cacheDistance = itemValue;
+
+ // difficulty
+ if (cache.getDifficulty() > 0f) {
+ itemLayout = createDifficulty();
+ detailsList.addView(itemLayout);
+ }
+
+ // terrain
+ if (cache.getTerrain() > 0f) {
+ itemLayout = createTerrain();
+ detailsList.addView(itemLayout);
+ }
+
+ // rating
+ if (cache.getRating() > 0) {
+ setRating(cache.getRating(), cache.getVotes());
+ } else {
+ aquireGCVote();
+ }
+
+ // more details
+ Button buttonMore = (Button) findViewById(R.id.more_details);
+ buttonMore.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ Intent cachesIntent = new Intent(CachePopup.this, CacheDetailActivity.class);
+ cachesIntent.putExtra(EXTRA_GEOCODE, geocode.toUpperCase());
+ startActivity(cachesIntent);
+
+ finish();
+ }
+ });
+
+ ((LinearLayout) findViewById(R.id.offline_box)).setVisibility(View.VISIBLE);
+
+ // offline use
+ final TextView offlineText = (TextView) findViewById(R.id.offline_text);
+ final Button offlineRefresh = (Button) findViewById(R.id.offline_refresh);
+ final Button offlineStore = (Button) findViewById(R.id.offline_store);
+
+ if (cache.getListId() > 0) {
+ long diff = (System.currentTimeMillis() / (60 * 1000)) - (cache.getDetailedUpdate() / (60 * 1000)); // minutes
+
+ String ago;
+ if (diff < 15) {
+ ago = res.getString(R.string.cache_offline_time_mins_few);
+ } else if (diff < 50) {
+ ago = res.getString(R.string.cache_offline_time_about) + " " + diff + " " + res.getString(R.string.cache_offline_time_mins);
+ } else if (diff < 90) {
+ ago = res.getString(R.string.cache_offline_time_about) + " " + res.getString(R.string.cache_offline_time_hour);
+ } else if (diff < (48 * 60)) {
+ ago = res.getString(R.string.cache_offline_time_about) + " " + (diff / 60) + " " + res.getString(R.string.cache_offline_time_hours);
+ } else {
+ ago = res.getString(R.string.cache_offline_time_about) + " " + (diff / (24 * 60)) + " " + res.getString(R.string.cache_offline_time_days);
+ }
+
+ offlineText.setText(res.getString(R.string.cache_offline_stored) + "\n" + ago);
+
+ offlineRefresh.setVisibility(View.VISIBLE);
+ offlineRefresh.setEnabled(true);
+ offlineRefresh.setOnClickListener(new storeCache());
+
+ offlineStore.setText(res.getString(R.string.cache_offline_drop));
+ offlineStore.setEnabled(true);
+ offlineStore.setOnClickListener(new dropCache());
+ } else {
+ offlineText.setText(res.getString(R.string.cache_offline_not_ready));
+
+ offlineRefresh.setVisibility(View.GONE);
+ offlineRefresh.setEnabled(false);
+ offlineRefresh.setOnTouchListener(null);
+ offlineRefresh.setOnClickListener(null);
+
+ offlineStore.setText(res.getString(R.string.cache_offline_store));
+ offlineStore.setEnabled(true);
+ offlineStore.setOnClickListener(new storeCache());
+ }
+ } catch (Exception e) {
+ Log.e("cgeopopup.init: " + e.toString());
+ }
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ init();
+ }
+
+ @Override
+ protected void navigateTo() {
+ if (cache == null || cache.getCoords() == null) {
+ showToast(res.getString(R.string.err_location_unknown));
+ return;
+ }
+
+ NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, cache, null, null);
+ }
+
+ @Override
+ protected void cachesAround() {
+ if (cache == null || cache.getCoords() == null) {
+ showToast(res.getString(R.string.err_location_unknown));
+ return;
+ }
+
+ cgeocaches.startActivityCachesAround(this, cache.getCoords());
+
+ finish();
+ }
+
+ private class storeCache implements View.OnClickListener {
+
+ @Override
+ public void onClick(View arg0) {
+ if (dropDialog != null && dropDialog.isShowing()) {
+ showToast("Still removing this cache.");
+ return;
+ }
+
+ storeDialog = ProgressDialog.show(CachePopup.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true);
+ storeDialog.setCancelable(false);
+ Thread thread = new storeCacheThread(storeCacheHandler);
+ thread.start();
+ }
+ }
+
+ private class storeCacheThread extends Thread {
+
+ final private CancellableHandler handler;
+
+ public storeCacheThread(final CancellableHandler handler) {
+ this.handler = handler;
+ }
+
+ @Override
+ public void run() {
+ cache.store(handler);
+ invalidateOptionsMenuCompatible();
+ }
+ }
+
+ private class dropCache implements View.OnClickListener {
+
+ @Override
+ public void onClick(View arg0) {
+ if (storeDialog != null && storeDialog.isShowing()) {
+ showToast("Still saving this cache.");
+ return;
+ }
+
+ dropDialog = ProgressDialog.show(CachePopup.this, res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true);
+ dropDialog.setCancelable(false);
+ Thread thread = new dropCacheThread(dropCacheHandler);
+ thread.start();
+ }
+ }
+
+ private class dropCacheThread extends Thread {
+
+ private Handler handler = null;
+
+ public dropCacheThread(Handler handlerIn) {
+ handler = handlerIn;
+ }
+
+ @Override
+ public void run() {
+ cache.drop(handler);
+ }
+ }
+
+ /**
+ * @param view
+ * unused here but needed since this method is referenced from XML layout
+ */
+ public void goDefaultNavigation(View view) {
+ if (cache == null || cache.getCoords() == null) {
+ showToast(res.getString(R.string.cache_coordinates_no));
+ return;
+ }
+ NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, cache, null, null);
+ finish();
+ }
+
+ /**
+ * Tries to navigate to the {@link cgCache} of this activity.
+ */
+ @Override
+ protected void startDefaultNavigation2() {
+ if (cache == null || cache.getCoords() == null) {
+ showToast(res.getString(R.string.cache_coordinates_no));
+ return;
+ }
+ NavigationAppFactory.startDefaultNavigationApplication2(app.currentGeo(), this, cache, null, null);
+ finish();
+ }
+
+ public static void startActivity(final Context context, final String geocode) {
+ final Intent popupIntent = new Intent(context, CachePopup.class);
+ popupIntent.putExtra(EXTRA_GEOCODE, geocode);
+ context.startActivity(popupIntent);
+ }
+}
diff --git a/main/src/cgeo/geocaching/WaypointPopup.java b/main/src/cgeo/geocaching/WaypointPopup.java
index 4478361..f7ec6e2 100644
--- a/main/src/cgeo/geocaching/WaypointPopup.java
+++ b/main/src/cgeo/geocaching/WaypointPopup.java
@@ -1,220 +1,50 @@
package cgeo.geocaching;
-import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
-import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.enumerations.CacheSize;
-import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.gcvote.GCVote;
-import cgeo.geocaching.gcvote.GCVoteRating;
-import cgeo.geocaching.geopoint.HumanDistance;
import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Configuration;
-import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.View.OnLongClickListener;
import android.widget.Button;
-import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
-import java.util.HashSet;
-import java.util.Set;
-
-public class WaypointPopup extends AbstractActivity {
-
- private static final String EXTRA_GEOCODE = "geocode";
+public class WaypointPopup extends AbstractPopupActivity {
private static final String EXTRA_WAYPOINT_ID = "waypoint_id";
- private LayoutInflater inflater = null;
- private int waypoint_id = 0;
- private String geocode = null;
- private cgCache cache = null;
+ private int waypointId = 0;
private cgWaypoint waypoint = null;
- private UpdateLocation geoUpdate = new UpdateLocation();
- private TextView cacheDistance = null;
- private Handler ratingHandler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
- try {
- final Bundle data = msg.getData();
-
- setRating(data.getFloat("rating"), data.getInt("votes"));
- } catch (Exception e) {
- // nothing
- }
- }
- };
-
- private class UpdateLocation extends GeoObserver {
-
- @Override
- public void updateLocation(final IGeoData geo) {
- try {
- if (geo.getCoords() != null && cache != null && cache.getCoords() != null) {
- cacheDistance.setText(HumanDistance.getHumanDistance(geo.getCoords().distanceTo(cache.getCoords())));
- cacheDistance.bringToFront();
- }
- } catch (Exception e) {
- Log.w("Failed to UpdateLocation location.");
- }
- }
- }
public WaypointPopup() {
- super("c:geo-waypoint-info");
+ super("c:geo-waypoint-info", R.layout.waypoint_popup);
}
@Override
- public void onCreate(Bundle savedInstanceState) {
+ public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- // set layout
- setTheme(R.style.transparent);
- setContentView(R.layout.waypoint_popup);
- setTitle(res.getString(R.string.detail));
-
// get parameters
- Bundle extras = getIntent().getExtras();
+ final Bundle extras = getIntent().getExtras();
if (extras != null) {
- geocode = extras.getString(EXTRA_GEOCODE);
- waypoint_id = extras.getInt(EXTRA_WAYPOINT_ID);
- }
-
- if (StringUtils.isBlank(geocode)) {
- showToast(res.getString(R.string.err_detail_cache_find));
-
- finish();
- return;
+ waypointId = extras.getInt(EXTRA_WAYPOINT_ID);
}
-
- ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation);
- defaultNavigationImageView.setOnLongClickListener(new OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- startDefaultNavigation2();
- return true;
- }
- });
-
}
@Override
- public boolean onTouchEvent(final MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_UP) {
- final Rect r = new Rect(0, 0, 0, 0);
- getWindow().getDecorView().getHitRect(r);
- if (!r.contains((int) event.getX(), (int) event.getY())) {
- finish();
- return true;
- }
- }
- return super.onTouchEvent(event);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, 2, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()).setIcon(android.R.drawable.ic_menu_compass); // default navigation tool
- menu.add(0, 3, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode);
- addVisitMenu(menu, cache);
- menu.add(0, 5, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around
- menu.add(0, 7, 0, res.getString(R.string.cache_menu_browser)).setIcon(android.R.drawable.ic_menu_info_details); // browser
-
- return true;
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- super.onPrepareOptionsMenu(menu);
-
- try {
- if (cache != null && cache.getCoords() != null) {
- menu.findItem(2).setVisible(true);
- menu.findItem(3).setVisible(true);
- menu.findItem(5).setVisible(true);
- } else {
- menu.findItem(2).setVisible(false);
- menu.findItem(3).setVisible(false);
- menu.findItem(5).setVisible(false);
- }
-
- menu.findItem(MENU_LOG_VISIT).setEnabled(Settings.isLogin());
- } catch (Exception e) {
- // nothing
- }
-
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- final int menuItem = item.getItemId();
-
- switch (menuItem) {
- case 2:
- navigateTo();
- break;
- case 3:
- NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, cache, null, null);
- break;
- case 5:
- cachesAround();
- break;
- case MENU_LOG_VISIT:
- cache.logVisit(this);
- finish();
- break;
- case 7:
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode())));
- break;
- default:
- cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
- }
-
- return true;
- }
-
- private void init() {
- app.setAction(geocode);
-
- cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
- waypoint = app.loadWaypoint(waypoint_id);
- if (cache == null) {
- showToast(res.getString(R.string.err_detail_cache_find));
-
- finish();
- return;
- }
-
- if (CacheType.UNKNOWN == cache.getType()) {
- Set<String> geocodes = new HashSet<String>();
- geocodes.add(geocode);
- SearchResult search = ConnectorFactory.searchByGeocodes(geocodes);
- cache = search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
- }
-
+ protected void init() {
+ super.init();
+ waypoint = app.loadWaypoint(waypointId);
try {
RelativeLayout itemLayout;
TextView itemName;
TextView itemValue;
- LinearLayout itemStars;
if (StringUtils.isNotBlank(waypoint.getName())) {
setTitle(waypoint.getName());
@@ -222,9 +52,6 @@ public class WaypointPopup extends AbstractActivity {
setTitle(waypoint.getGeocode().toUpperCase());
}
- inflater = getLayoutInflater();
- geocode = cache.getGeocode().toUpperCase();
-
// actionbar icon
((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(waypoint.getWaypointType().markerId), null, null, null);
@@ -246,6 +73,7 @@ public class WaypointPopup extends AbstractActivity {
Button buttonEdit = (Button) findViewById(R.id.edit);
buttonEdit.setOnClickListener(new OnClickListener() {
+ @Override
public void onClick(View arg0) {
Intent editIntent = new Intent(WaypointPopup.this, cgeowaypointadd.class);
editIntent.putExtra("waypoint", waypoint.getId());
@@ -255,7 +83,7 @@ public class WaypointPopup extends AbstractActivity {
});
//Start filling cache details
- LinearLayout cacheDetailsList = (LinearLayout) findViewById(R.id.cache_details_list);
+ LinearLayout cacheDetailsList = (LinearLayout) findViewById(R.id.details_list);
cacheDetailsList.removeAllViews();
// Cache name
@@ -290,39 +118,7 @@ public class WaypointPopup extends AbstractActivity {
// cache state
if (cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.cache_status));
-
- final StringBuilder state = new StringBuilder();
- if (cache.isFound()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_found));
- }
- if (cache.isArchived()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_archived));
- }
- if (cache.isDisabled()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_disabled));
- }
- if (cache.isPremiumMembersOnly()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_premium));
- }
-
- itemValue.setText(state.toString());
+ itemLayout = createCacheState();
cacheDetailsList.addView(itemLayout);
}
@@ -334,52 +130,17 @@ public class WaypointPopup extends AbstractActivity {
itemName.setText(res.getString(R.string.cache_distance));
itemValue.setText("--");
- cacheDetailsList.addView(itemLayout);
cacheDistance = itemValue;
-
+ cacheDetailsList.addView(itemLayout);
// difficulty
if (cache.getDifficulty() > 0f) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
- itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
-
- itemName.setText(res.getString(R.string.cache_difficulty));
- itemValue.setText(String.format("%.1f", cache.getDifficulty()) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
- for (int i = 0; i <= 4; i++) {
- ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
- if ((cache.getDifficulty() - i) >= 1.0) {
- star.setImageResource(R.drawable.star_on);
- } else if ((cache.getDifficulty() - i) > 0.0) {
- star.setImageResource(R.drawable.star_half);
- } else {
- star.setImageResource(R.drawable.star_off);
- }
- itemStars.addView(star);
- }
+ itemLayout = createDifficulty();
cacheDetailsList.addView(itemLayout);
}
// terrain
if (cache.getTerrain() > 0f) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
- itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
-
- itemName.setText(res.getString(R.string.cache_terrain));
- itemValue.setText(String.format("%.1f", cache.getTerrain()) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
- for (int i = 0; i <= 4; i++) {
- ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
- if ((cache.getTerrain() - i) >= 1.0) {
- star.setImageResource(R.drawable.star_on);
- } else if ((cache.getTerrain() - i) > 0.0) {
- star.setImageResource(R.drawable.star_half);
- } else {
- star.setImageResource(R.drawable.star_off);
- }
- itemStars.addView(star);
- }
+ itemLayout = createTerrain();
cacheDetailsList.addView(itemLayout);
}
@@ -387,33 +148,14 @@ public class WaypointPopup extends AbstractActivity {
if (cache.getRating() > 0) {
setRating(cache.getRating(), cache.getVotes());
} else {
- if (Settings.isRatingWanted() && cache.supportsGCVote()) {
- (new Thread() {
-
- @Override
- public void run() {
- GCVoteRating rating = GCVote.getRating(cache.getGuid(), geocode);
-
- if (rating == null) {
- return;
- }
-
- Message msg = Message.obtain();
- Bundle bundle = new Bundle();
- bundle.putFloat("rating", rating.getRating());
- bundle.putInt("votes", rating.getVotes());
- msg.setData(bundle);
-
- ratingHandler.sendMessage(msg);
- }
- }).start();
- }
+ aquireGCVote();
}
// more details
Button buttonMore = (Button) findViewById(R.id.more_details);
buttonMore.setOnClickListener(new OnClickListener() {
+ @Override
public void onClick(View arg0) {
Intent cachesIntent = new Intent(WaypointPopup.this, CacheDetailActivity.class);
cachesIntent.putExtra(EXTRA_GEOCODE, geocode.toUpperCase());
@@ -429,36 +171,7 @@ public class WaypointPopup extends AbstractActivity {
}
@Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
-
- init();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- app.addGeoObserver(geoUpdate);
- init();
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- }
-
- @Override
- public void onStop() {
- super.onStop();
- }
-
- @Override
- public void onPause() {
- app.deleteGeoObserver(geoUpdate);
- super.onPause();
- }
-
- private void navigateTo() {
+ protected void navigateTo() {
if (waypoint == null || waypoint.getCoords() == null) {
showToast(res.getString(R.string.err_location_unknown));
return;
@@ -467,7 +180,8 @@ public class WaypointPopup extends AbstractActivity {
NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, null, waypoint, null);
}
- private void cachesAround() {
+ @Override
+ protected void cachesAround() {
if (waypoint == null || waypoint.getCoords() == null) {
showToast(res.getString(R.string.err_location_unknown));
return;
@@ -478,40 +192,12 @@ public class WaypointPopup extends AbstractActivity {
finish();
}
- private void setRating(float rating, int votes) {
- if (rating <= 0) {
- return;
- }
-
- RelativeLayout itemLayout;
- TextView itemName;
- TextView itemValue;
- LinearLayout itemStars;
- LinearLayout detailsList = (LinearLayout) findViewById(R.id.cache_details_list);
-
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
- itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
-
- itemName.setText(res.getString(R.string.cache_rating));
- itemValue.setText(String.format("%.1f", rating) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
- itemStars.addView(createStarRating(rating, 5, this), 1);
-
- if (votes > 0) {
- final TextView itemAddition = (TextView) itemLayout.findViewById(R.id.addition);
- itemAddition.setText("(" + votes + ")");
- itemAddition.setVisibility(View.VISIBLE);
- }
- detailsList.addView(itemLayout);
- }
-
/**
* @param view
* unused here but needed since this method is referenced from XML layout
*/
- public void goDefaultNavigation(View view) {
- if (cache == null || cache.getCoords() == null) {
+ public void goDefaultNavigation(final View view) {
+ if (waypoint == null || waypoint.getCoords() == null) {
showToast(res.getString(R.string.cache_coordinates_no));
return;
}
@@ -522,25 +208,41 @@ public class WaypointPopup extends AbstractActivity {
/**
* Tries to navigate to the {@link cgCache} of this activity.
*/
- private void startDefaultNavigation2() {
- if (cache == null || cache.getCoords() == null) {
+ @Override
+ protected void startDefaultNavigation2() {
+ if (waypoint == null || waypoint.getCoords() == null) {
showToast(res.getString(R.string.cache_coordinates_no));
return;
}
- NavigationAppFactory.startDefaultNavigationApplication2(app.currentGeo(), this, cache, null, null);
+ NavigationAppFactory.startDefaultNavigationApplication2(app.currentGeo(), this, null, waypoint, null);
finish();
}
+ public static void startActivity(final Context context, final int waypointId, final String geocode) {
+ final Intent popupIntent = new Intent(context, WaypointPopup.class);
+ popupIntent.putExtra(EXTRA_WAYPOINT_ID, waypointId);
+ popupIntent.putExtra(EXTRA_GEOCODE, geocode);
+ context.startActivity(popupIntent);
+ }
+
+ @Override
+ protected void logOffline(int menuItem) {
+ cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
+ }
+
@Override
- public void goManual(View view) {
- super.goManual(view);
+ protected void logVisit() {
+ cache.logVisit(this);
finish();
}
- public static void startActivity(final Context context, int id, final String geocode) {
- final Intent popupIntent = new Intent(context, WaypointPopup.class);
- popupIntent.putExtra(EXTRA_WAYPOINT_ID, id);
- popupIntent.putExtra(EXTRA_GEOCODE, geocode);
- context.startActivity(popupIntent);
+ @Override
+ protected void showInBrowser() {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode())));
+ }
+
+ @Override
+ protected void showNavigationMenu() {
+ NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, null, waypoint, null);
}
}
diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java
deleted file mode 100644
index dd9be5b..0000000
--- a/main/src/cgeo/geocaching/cgeopopup.java
+++ /dev/null
@@ -1,646 +0,0 @@
-package cgeo.geocaching;
-
-import cgeo.geocaching.activity.AbstractActivity;
-import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
-import cgeo.geocaching.connector.ConnectorFactory;
-import cgeo.geocaching.enumerations.CacheSize;
-import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.enumerations.LoadFlags;
-import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.gcvote.GCVote;
-import cgeo.geocaching.gcvote.GCVoteRating;
-import cgeo.geocaching.geopoint.HumanDistance;
-import cgeo.geocaching.utils.CancellableHandler;
-import cgeo.geocaching.utils.Log;
-
-import org.apache.commons.lang3.StringUtils;
-
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.graphics.Rect;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.View.OnLongClickListener;
-import android.widget.Button;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class cgeopopup extends AbstractActivity {
-
- private LayoutInflater inflater = null;
- private String geocode = null;
- private cgCache cache = null;
- private GeoObserver geoUpdate = new UpdateLocation();
- private ProgressDialog storeDialog = null;
- private ProgressDialog dropDialog = null;
- private TextView cacheDistance = null;
- private Handler ratingHandler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
- try {
- final Bundle data = msg.getData();
-
- setRating(data.getFloat("rating"), data.getInt("votes"));
- } catch (Exception e) {
- // nothing
- }
- }
- };
- private CancellableHandler storeCacheHandler = new CancellableHandler() {
-
- @Override
- public void handleRegularMessage(Message msg) {
- try {
- if (storeDialog != null) {
- storeDialog.dismiss();
- }
-
- finish();
- return;
- } catch (Exception e) {
- showToast(res.getString(R.string.err_store));
-
- Log.e("cgeopopup.storeCacheHandler: " + e.toString());
- }
-
- if (storeDialog != null) {
- storeDialog.dismiss();
- }
- init();
- }
- };
- private Handler dropCacheHandler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
- try {
- if (dropDialog != null) {
- dropDialog.dismiss();
- }
-
- finish();
- return;
- } catch (Exception e) {
- showToast(res.getString(R.string.err_drop));
-
- Log.e("cgeopopup.dropCacheHandler: " + e.toString());
- }
-
- if (dropDialog != null) {
- dropDialog.dismiss();
- }
- init();
- }
- };
-
- public cgeopopup() {
- super("c:geo-cache-info");
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // set layout
- setTheme(R.style.transparent);
- setContentView(R.layout.popup);
- setTitle(res.getString(R.string.detail));
-
- // get parameters
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
- geocode = extras.getString("geocode");
- }
-
- if (StringUtils.isBlank(geocode)) {
- showToast(res.getString(R.string.err_detail_cache_find));
-
- finish();
- return;
- }
-
- ImageView defaultNavigationImageView = (ImageView) findViewById(R.id.defaultNavigation);
- defaultNavigationImageView.setOnLongClickListener(new OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- startDefaultNavigation2();
- return true;
- }
- });
-
- }
-
- @Override
- public boolean onTouchEvent(final MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_UP) {
- final Rect r = new Rect(0, 0, 0, 0);
- getWindow().getDecorView().getHitRect(r);
- if (!r.contains((int) event.getX(), (int) event.getY())) {
- finish();
- return true;
- }
- }
- return super.onTouchEvent(event);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, 2, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()).setIcon(R.drawable.ic_menu_compass); // default navigation tool
- menu.add(0, 3, 0, res.getString(R.string.cache_menu_navigate)).setIcon(R.drawable.ic_menu_mapmode);
- addVisitMenu(menu, cache);
- menu.add(0, 5, 0, res.getString(R.string.cache_menu_around)).setIcon(R.drawable.ic_menu_rotate); // caches around
- menu.add(0, 7, 0, res.getString(R.string.cache_menu_browser)).setIcon(R.drawable.ic_menu_info_details); // browser
-
- return true;
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- super.onPrepareOptionsMenu(menu);
-
- try {
- if (cache != null && cache.getCoords() != null) {
- menu.findItem(2).setVisible(true);
- menu.findItem(3).setVisible(true);
- menu.findItem(5).setVisible(true);
- } else {
- menu.findItem(2).setVisible(false);
- menu.findItem(3).setVisible(false);
- menu.findItem(5).setVisible(false);
- }
-
- menu.findItem(MENU_LOG_VISIT).setEnabled(Settings.isLogin());
- } catch (Exception e) {
- // nothing
- }
-
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- final int menuItem = item.getItemId();
-
- switch (menuItem) {
- case 2:
- navigateTo();
- break;
- case 3:
- NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, cache, null, null);
- break;
- case 5:
- cachesAround();
- break;
- case MENU_LOG_VISIT:
- cache.logVisit(this);
- finish();
- break;
- case 7:
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode())));
- break;
- default:
- cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
- }
-
- return true;
- }
-
- private void init() {
- app.setAction(geocode);
-
- cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
-
- if (cache == null) {
- showToast(res.getString(R.string.err_detail_cache_find));
-
- finish();
- return;
- }
-
- if ( CacheType.UNKNOWN == cache.getType() ) {
- Set<String> geocodes = new HashSet<String>();
- geocodes.add(geocode);
- SearchResult search = ConnectorFactory.searchByGeocodes(geocodes);
- cache = search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
- }
-
- try {
- RelativeLayout itemLayout;
- TextView itemName;
- TextView itemValue;
- LinearLayout itemStars;
-
- if (StringUtils.isNotBlank(cache.getName())) {
- setTitle(cache.getName());
- } else {
- setTitle(geocode.toUpperCase());
- }
-
- inflater = getLayoutInflater();
- geocode = cache.getGeocode().toUpperCase();
-
- LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
- detailsList.removeAllViews();
-
- // actionbar icon
- ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cache.getType().markerId), null, null, null);
-
- // cache type
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.cache_type));
-
- String cacheType = cache.getType().getL10n();
- String cacheSize = cache.getSize() != CacheSize.UNKNOWN ? " (" + cache.getSize().getL10n() + ")" : "";
- itemValue.setText(cacheType + cacheSize);
- detailsList.addView(itemLayout);
-
- // gc-code
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.cache_geocode));
- itemValue.setText(cache.getGeocode().toUpperCase());
- detailsList.addView(itemLayout);
-
- // cache state
- if (cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.cache_status));
-
- final StringBuilder state = new StringBuilder();
- if (cache.isFound()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_found));
- }
- if (cache.isArchived()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_archived));
- }
- if (cache.isDisabled()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_disabled));
- }
- if (cache.isPremiumMembersOnly()) {
- if (state.length() > 0) {
- state.append(", ");
- }
- state.append(res.getString(R.string.cache_status_premium));
- }
-
- itemValue.setText(state.toString());
- detailsList.addView(itemLayout);
- }
-
- // distance
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.cache_distance));
- itemValue.setText("--");
- detailsList.addView(itemLayout);
- cacheDistance = itemValue;
-
- // difficulty
- if (cache.getDifficulty() > 0f) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
- itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
-
- itemName.setText(res.getString(R.string.cache_difficulty));
- itemValue.setText(String.format("%.1f", cache.getDifficulty()) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
- for (int i = 0; i <= 4; i++) {
- ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
- if ((cache.getDifficulty() - i) >= 1.0) {
- star.setImageResource(R.drawable.star_on);
- } else if ((cache.getDifficulty() - i) > 0.0) {
- star.setImageResource(R.drawable.star_half);
- } else {
- star.setImageResource(R.drawable.star_off);
- }
- itemStars.addView(star);
- }
- detailsList.addView(itemLayout);
- }
-
- // terrain
- if (cache.getTerrain() > 0f) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
- itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
-
- itemName.setText(res.getString(R.string.cache_terrain));
- itemValue.setText(String.format("%.1f", cache.getTerrain()) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
- for (int i = 0; i <= 4; i++) {
- ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
- if ((cache.getTerrain() - i) >= 1.0) {
- star.setImageResource(R.drawable.star_on);
- } else if ((cache.getTerrain() - i) > 0.0) {
- star.setImageResource(R.drawable.star_half);
- } else {
- star.setImageResource(R.drawable.star_off);
- }
- itemStars.addView(star);
- }
- detailsList.addView(itemLayout);
- }
-
- // rating
- if (cache.getRating() > 0) {
- setRating(cache.getRating(), cache.getVotes());
- } else {
- if (Settings.isRatingWanted() && cache.supportsGCVote()) {
- (new Thread() {
-
- @Override
- public void run() {
- GCVoteRating rating = GCVote.getRating(cache.getGuid(), geocode);
-
- if (rating == null) {
- return;
- }
-
- Message msg = Message.obtain();
- Bundle bundle = new Bundle();
- bundle.putFloat("rating", rating.getRating());
- bundle.putInt("votes", rating.getVotes());
- msg.setData(bundle);
-
- ratingHandler.sendMessage(msg);
- }
- }).start();
- }
- }
-
- // more details
- Button buttonMore = (Button) findViewById(R.id.more_details);
- buttonMore.setOnClickListener(new OnClickListener() {
-
- public void onClick(View arg0) {
- Intent cachesIntent = new Intent(cgeopopup.this, CacheDetailActivity.class);
- cachesIntent.putExtra("geocode", geocode.toUpperCase());
- startActivity(cachesIntent);
-
- finish();
- }
- });
-
- ((LinearLayout) findViewById(R.id.offline_box)).setVisibility(View.VISIBLE);
-
- // offline use
- final TextView offlineText = (TextView) findViewById(R.id.offline_text);
- final Button offlineRefresh = (Button) findViewById(R.id.offline_refresh);
- final Button offlineStore = (Button) findViewById(R.id.offline_store);
-
- if (cache.getListId() > 0) {
- long diff = (System.currentTimeMillis() / (60 * 1000)) - (cache.getDetailedUpdate() / (60 * 1000)); // minutes
-
- String ago;
- if (diff < 15) {
- ago = res.getString(R.string.cache_offline_time_mins_few);
- } else if (diff < 50) {
- ago = res.getString(R.string.cache_offline_time_about) + " " + diff + " " + res.getString(R.string.cache_offline_time_mins);
- } else if (diff < 90) {
- ago = res.getString(R.string.cache_offline_time_about) + " " + res.getString(R.string.cache_offline_time_hour);
- } else if (diff < (48 * 60)) {
- ago = res.getString(R.string.cache_offline_time_about) + " " + (diff / 60) + " " + res.getString(R.string.cache_offline_time_hours);
- } else {
- ago = res.getString(R.string.cache_offline_time_about) + " " + (diff / (24 * 60)) + " " + res.getString(R.string.cache_offline_time_days);
- }
-
- offlineText.setText(res.getString(R.string.cache_offline_stored) + "\n" + ago);
-
- offlineRefresh.setVisibility(View.VISIBLE);
- offlineRefresh.setEnabled(true);
- offlineRefresh.setOnClickListener(new storeCache());
-
- offlineStore.setText(res.getString(R.string.cache_offline_drop));
- offlineStore.setEnabled(true);
- offlineStore.setOnClickListener(new dropCache());
- } else {
- offlineText.setText(res.getString(R.string.cache_offline_not_ready));
-
- offlineRefresh.setVisibility(View.GONE);
- offlineRefresh.setEnabled(false);
- offlineRefresh.setOnTouchListener(null);
- offlineRefresh.setOnClickListener(null);
-
- offlineStore.setText(res.getString(R.string.cache_offline_store));
- offlineStore.setEnabled(true);
- offlineStore.setOnClickListener(new storeCache());
- }
- } catch (Exception e) {
- Log.e("cgeopopup.init: " + e.toString());
- }
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
-
- init();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- init();
- app.addGeoObserver(geoUpdate);
- }
-
- @Override
- public void onPause() {
- app.deleteGeoObserver(geoUpdate);
- super.onPause();
- }
-
- private class UpdateLocation extends GeoObserver {
-
- @Override
- protected void updateLocation(final IGeoData geo) {
- try {
- if (geo.getCoords() != null && cache != null && cache.getCoords() != null) {
- cacheDistance.setText(HumanDistance.getHumanDistance(geo.getCoords().distanceTo(cache.getCoords())));
- cacheDistance.bringToFront();
- }
- } catch (Exception e) {
- Log.w("Failed to UpdateLocation location.");
- }
- }
- }
-
- private void navigateTo() {
- if (cache == null || cache.getCoords() == null) {
- showToast(res.getString(R.string.err_location_unknown));
- return;
- }
-
- NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, cache, null, null);
- }
-
- private void cachesAround() {
- if (cache == null || cache.getCoords() == null) {
- showToast(res.getString(R.string.err_location_unknown));
- return;
- }
-
- cgeocaches.startActivityCachesAround(this, cache.getCoords());
-
- finish();
- }
-
- private class storeCache implements View.OnClickListener {
-
- public void onClick(View arg0) {
- if (dropDialog != null && dropDialog.isShowing()) {
- showToast("Still removing this cache.");
- return;
- }
-
- storeDialog = ProgressDialog.show(cgeopopup.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true);
- storeDialog.setCancelable(false);
- Thread thread = new storeCacheThread(storeCacheHandler);
- thread.start();
- }
- }
-
- private class storeCacheThread extends Thread {
-
- final private CancellableHandler handler;
-
- public storeCacheThread(final CancellableHandler handler) {
- this.handler = handler;
- }
-
- @Override
- public void run() {
- cache.store(handler);
- invalidateOptionsMenuCompatible();
- }
- }
-
- private class dropCache implements View.OnClickListener {
-
- public void onClick(View arg0) {
- if (storeDialog != null && storeDialog.isShowing()) {
- showToast("Still saving this cache.");
- return;
- }
-
- dropDialog = ProgressDialog.show(cgeopopup.this, res.getString(R.string.cache_dialog_offline_drop_title), res.getString(R.string.cache_dialog_offline_drop_message), true);
- dropDialog.setCancelable(false);
- Thread thread = new dropCacheThread(dropCacheHandler);
- thread.start();
- }
- }
-
- private class dropCacheThread extends Thread {
-
- private Handler handler = null;
-
- public dropCacheThread(Handler handlerIn) {
- handler = handlerIn;
- }
-
- @Override
- public void run() {
- cache.drop(handler);
- }
- }
-
- private void setRating(float rating, int votes) {
- if (rating <= 0) {
- return;
- }
-
- RelativeLayout itemLayout;
- TextView itemName;
- TextView itemValue;
- LinearLayout itemStars;
- LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
-
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_layout, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
- itemStars = (LinearLayout) itemLayout.findViewById(R.id.stars);
-
- itemName.setText(res.getString(R.string.cache_rating));
- itemValue.setText(String.format("%.1f", rating) + ' ' + res.getString(R.string.cache_rating_of) + " 5");
- itemStars.addView(createStarRating(rating, 5, this), 1);
-
- if (votes > 0) {
- final TextView itemAddition = (TextView) itemLayout.findViewById(R.id.addition);
- itemAddition.setText("(" + votes + ")");
- itemAddition.setVisibility(View.VISIBLE);
- }
- detailsList.addView(itemLayout);
- }
-
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void goDefaultNavigation(View view) {
- if (cache == null || cache.getCoords() == null) {
- showToast(res.getString(R.string.cache_coordinates_no));
- return;
- }
- NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, cache, null, null);
- finish();
- }
-
- /**
- * Tries to navigate to the {@link cgCache} of this activity.
- */
- private void startDefaultNavigation2() {
- if (cache == null || cache.getCoords() == null) {
- showToast(res.getString(R.string.cache_coordinates_no));
- return;
- }
- NavigationAppFactory.startDefaultNavigationApplication2(app.currentGeo(), this, cache, null, null);
- finish();
- }
-
- @Override
- public void goManual(View view) {
- super.goManual(view);
- finish();
- }
-
- public static void startActivity(final Context context, final String geocode) {
- final Intent popupIntent = new Intent(context, cgeopopup.class);
- popupIntent.putExtra("geocode", geocode);
- context.startActivity(popupIntent);
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index c94c014..4def934 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.maps;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.Settings;
import cgeo.geocaching.WaypointPopup;
-import cgeo.geocaching.cgeopopup;
+import cgeo.geocaching.CachePopup;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
@@ -228,7 +228,7 @@ public class CachesOverlay extends AbstractItemizedOverlay {
if (StringUtils.isNotBlank(coordinate.getCoordType()) && coordinate.getCoordType().equalsIgnoreCase("cache") && StringUtils.isNotBlank(coordinate.getGeocode())) {
CGeoMap.markCacheAsDirty(coordinate.getGeocode());
- cgeopopup.startActivity(context, coordinate.getGeocode());
+ CachePopup.startActivity(context, coordinate.getGeocode());
} else if (coordinate.getCoordType() != null && coordinate.getCoordType().equalsIgnoreCase("waypoint") && coordinate.getId() > 0) {
CGeoMap.markCacheAsDirty(coordinate.getGeocode());
WaypointPopup.startActivity(context, coordinate.getId(), coordinate.getGeocode());