aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-05-05 10:54:33 +0200
committerBananeweizen <bananeweizen@gmx.de>2012-05-05 10:54:33 +0200
commit90264f45bd68721666c8e9e5ff4d82611c6fcf7b (patch)
treed41b5e9367281b9e8f94dc7b9fdf151be253cc15
parent057f24b4f57dadeeba92a04c83e3bcd790e983b1 (diff)
parent38fe38b63637879685bbaa5f443a55bba8e72f1d (diff)
downloadcgeo-90264f45bd68721666c8e9e5ff4d82611c6fcf7b.zip
cgeo-90264f45bd68721666c8e9e5ff4d82611c6fcf7b.tar.gz
cgeo-90264f45bd68721666c8e9e5ff4d82611c6fcf7b.tar.bz2
Merge remote-tracking branch 'Portree-Kid/master-new8'
Conflicts: main/src/cgeo/geocaching/cgeopopup.java
-rw-r--r--main/AndroidManifest.xml8
-rw-r--r--main/res/layout/waypoint_popup.xml62
-rw-r--r--main/src/cgeo/geocaching/AbstractPopupActivity.java386
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java26
-rw-r--r--main/src/cgeo/geocaching/CachePopup.java360
-rw-r--r--main/src/cgeo/geocaching/WaypointPopup.java248
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java646
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java22
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java11
9 files changed, 1100 insertions, 669 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index b454abb..5b04cd2 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -54,7 +54,7 @@
android:resource="@xml/searchable" />
</activity>
<activity
- android:name=".cgeopopup"
+ android:name=".CachePopup"
android:label="@string/app_name"
android:theme="@style/cgeo_transparent"
android:windowSoftInputMode="stateHidden"
@@ -235,5 +235,11 @@
</activity>
<provider android:name=".apps.LocusDataStorageProvider"
android:authorities="cgeo.geocaching.apps.locusdatastorageprovider" />
+ <activity android:name="WaypointPopup"
+ android:label="@string/app_name"
+ android:theme="@style/cgeo_transparent"
+ android:windowSoftInputMode="stateHidden"
+ android:configChanges="keyboardHidden|orientation" >
+ </activity>
</application>
</manifest>
diff --git a/main/res/layout/waypoint_popup.xml b/main/res/layout/waypoint_popup.xml
new file mode 100644
index 0000000..2096a7a
--- /dev/null
+++ b/main/res/layout/waypoint_popup.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:background="?background_color_transparent" >
+ <LinearLayout style="@style/action_bar">
+ <TextView style="@style/action_bar_title" />
+ <View style="@style/action_bar_separator" />
+ <ImageView android:id="@+id/defaultNavigation"
+ style="@style/action_bar_action"
+ android:src="@drawable/actionbar_compass"
+ android:onClick="goDefaultNavigation"
+ android:longClickable="true" />
+ <View style="@style/action_bar_separator"
+ android:id="@+id/separator"
+ />
+ <ImageView style="@style/action_bar_action"
+ android:src="@drawable/actionbar_manual"
+ android:onClick="goManual" />
+ </LinearLayout>
+ <ScrollView android:id="@+id/details_list_box"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="4dip"
+ android:orientation="vertical" >
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+ <LinearLayout android:id="@+id/waypoint_details_list"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+ </LinearLayout>
+ <LinearLayout android:id="@+id/edit_box"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+ <Button style="@style/button_small"
+ android:id="@+id/edit"
+ android:text="@string/waypoint_edit" />
+ </LinearLayout>
+ <RelativeLayout style="@style/separator_horizontal_layout" >
+ <View style="@style/separator_horizontal" />
+ </RelativeLayout>
+ <LinearLayout android:id="@+id/details_list"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+ </LinearLayout>
+ <LinearLayout android:id="@+id/more_details_box"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+ <Button style="@style/button_small"
+ android:id="@+id/more_details"
+ android:text="@string/popup_more" />
+ </LinearLayout>
+ </LinearLayout>
+ </ScrollView>
+</LinearLayout> \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/AbstractPopupActivity.java b/main/src/cgeo/geocaching/AbstractPopupActivity.java
new file mode 100644
index 0000000..ad3ee80
--- /dev/null
+++ b/main/src/cgeo/geocaching/AbstractPopupActivity.java
@@ -0,0 +1,386 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.connector.gc.GCMap;
+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.Collections;
+
+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()) {
+ SearchResult search = GCMap.searchByGeocodes(Collections.singleton(geocode));
+ 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/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 7b9c147..4fded6a 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -309,11 +309,18 @@ public class CacheDetailActivity extends AbstractActivity {
});
// switch to entry page (last used or 2)
- final int entryPageIndex = Settings.isOpenLastDetailsPage() ? Settings.getLastDetailsPage() : 1;
- if (viewPagerAdapter.getCount() < entryPageIndex) {
- for (int i = 0; i <= entryPageIndex; i++) {
- // we can't switch to a page that is out of bounds, so we add null-pages
- pageOrder.add(null);
+ int entryPageIndex;
+ if (extras != null && extras.get("page") != null) {
+ entryPageIndex = extras.getInt("page");
+ }
+ else
+ {
+ entryPageIndex = Settings.isOpenLastDetailsPage() ? Settings.getLastDetailsPage() : 1;
+ if (viewPagerAdapter.getCount() < entryPageIndex) {
+ for (int i = 0; i <= entryPageIndex; i++) {
+ // we can't switch to a page that is out of bounds, so we add null-pages
+ pageOrder.add(null);
+ }
}
}
viewPager.setCurrentItem(entryPageIndex, false);
@@ -945,6 +952,13 @@ public class CacheDetailActivity extends AbstractActivity {
context.startActivity(detailIntent);
}
+ public static void startActivity(final Context context, final String geocode, final int page) {
+ final Intent detailIntent = new Intent(context, CacheDetailActivity.class);
+ detailIntent.putExtra("geocode", geocode.toUpperCase());
+ detailIntent.putExtra("page", page);
+ context.startActivity(detailIntent);
+ }
+
/**
* The ViewPagerAdapter for scrolling through pages of the CacheDetailActivity.
*/
@@ -1059,7 +1073,7 @@ public class CacheDetailActivity extends AbstractActivity {
/**
* Enum of all possible pages with methods to get the view and a title.
*/
- private enum Page {
+ public enum Page {
DETAILS(R.string.detail),
DESCRIPTION(R.string.cache_description),
LOGS(R.string.cache_logs),
diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java
new file mode 100644
index 0000000..8e563bf
--- /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.startActivityCoordinates(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
new file mode 100644
index 0000000..431dd15
--- /dev/null
+++ b/main/src/cgeo/geocaching/WaypointPopup.java
@@ -0,0 +1,248 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.enumerations.CacheSize;
+import cgeo.geocaching.enumerations.LogType;
+import cgeo.geocaching.utils.Log;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+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 WaypointPopup extends AbstractPopupActivity {
+ private static final String EXTRA_WAYPOINT_ID = "waypoint_id";
+ private int waypointId = 0;
+ private cgWaypoint waypoint = null;
+
+ public WaypointPopup() {
+ super("c:geo-waypoint-info", R.layout.waypoint_popup);
+ }
+
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // get parameters
+ final Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ waypointId = extras.getInt(EXTRA_WAYPOINT_ID);
+ }
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+ waypoint = app.loadWaypoint(waypointId);
+ try {
+ RelativeLayout itemLayout;
+ TextView itemName;
+ TextView itemValue;
+
+ if (StringUtils.isNotBlank(waypoint.getName())) {
+ setTitle(waypoint.getName());
+ } else {
+ setTitle(waypoint.getGeocode().toUpperCase());
+ }
+
+ // actionbar icon
+ ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(waypoint.getWaypointType().markerId), null, null, null);
+
+ //Start filling waypoint details
+ LinearLayout waypointDetailsList = (LinearLayout) findViewById(R.id.waypoint_details_list);
+ waypointDetailsList.removeAllViews();
+
+ //Waypoint geocode
+ 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(waypoint.getPrefix().toUpperCase() + waypoint.getGeocode().toUpperCase().substring(2));
+ waypointDetailsList.addView(itemLayout);
+
+ // Edit Button
+ 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());
+ startActivity(editIntent);
+ restartActivity();
+ }
+ });
+
+ //Start filling cache details
+ LinearLayout cacheDetailsList = (LinearLayout) findViewById(R.id.details_list);
+ cacheDetailsList.removeAllViews();
+
+ // Cache name
+ itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
+ itemName = (TextView) itemLayout.findViewById(R.id.name);
+ itemValue = (TextView) itemLayout.findViewById(R.id.value);
+ itemValue.setLines(1);
+ itemName.setText(res.getString(R.string.cache_name));
+
+ itemValue.setText(cache.getName());
+ cacheDetailsList.addView(itemLayout);
+
+ // 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);
+ cacheDetailsList.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());
+ cacheDetailsList.addView(itemLayout);
+
+ // cache state
+ if (cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) {
+ itemLayout = createCacheState();
+ cacheDetailsList.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("--");
+ cacheDistance = itemValue;
+ cacheDetailsList.addView(itemLayout);
+ // difficulty
+ if (cache.getDifficulty() > 0f) {
+ itemLayout = createDifficulty();
+ cacheDetailsList.addView(itemLayout);
+ }
+
+ // terrain
+ if (cache.getTerrain() > 0f) {
+ itemLayout = createTerrain();
+ cacheDetailsList.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(WaypointPopup.this, CacheDetailActivity.class);
+ cachesIntent.putExtra(EXTRA_GEOCODE, geocode.toUpperCase());
+ startActivity(cachesIntent);
+
+ finish();
+ }
+ });
+
+ } catch (Exception e) {
+ Log.e("cgeopopup.init: " + e.toString());
+ }
+ }
+
+ @Override
+ protected void navigateTo() {
+ if (waypoint == null || waypoint.getCoords() == null) {
+ showToast(res.getString(R.string.err_location_unknown));
+ return;
+ }
+
+ NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, null, waypoint, null);
+ }
+
+ @Override
+ protected void cachesAround() {
+ if (waypoint == null || waypoint.getCoords() == null) {
+ showToast(res.getString(R.string.err_location_unknown));
+ return;
+ }
+
+ cgeocaches.startActivityCoordinates(this, waypoint.getCoords());
+
+ finish();
+ }
+
+ /**
+ * @param view
+ * unused here but needed since this method is referenced from XML layout
+ */
+ public void goDefaultNavigation(final View view) {
+ if (waypoint == null || waypoint.getCoords() == null) {
+ showToast(res.getString(R.string.cache_coordinates_no));
+ return;
+ }
+ NavigationAppFactory.startDefaultNavigationApplication(app.currentGeo(), this, null, waypoint, null);
+ finish();
+ }
+
+ /**
+ * Tries to navigate to the {@link cgCache} of this activity.
+ */
+ @Override
+ protected void startDefaultNavigation2() {
+ if (waypoint == null || waypoint.getCoords() == null) {
+ showToast(res.getString(R.string.cache_coordinates_no));
+ return;
+ }
+ 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
+ protected void logVisit() {
+ cache.logVisit(this);
+ finish();
+ }
+
+ @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 05383f1..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.gc.GCMap;
-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 = GCMap.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.startActivityCoordinates(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/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 03c8284..0618872 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -193,7 +193,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private static BlockingQueue<Runnable> go4CacheDisplayQueue = new ArrayBlockingQueue<Runnable>(1);
private static ThreadPoolExecutor go4CacheDisplayExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, go4CacheDisplayQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
-
// handlers
/** Updates the titles */
final private Handler displayHandler = new Handler() {
@@ -358,7 +357,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final MapProvider mapProvider = Settings.getMapProvider();
mapItemFactory = mapProvider.getMapItemFactory();
-
// Get parameters from the intent
final Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
@@ -836,7 +834,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
overlayPosition = mapView.createAddPositionOverlay(activity);
}
- if (overlayPosition != null && geo.getLocation() != null) {
+ if ((overlayPosition != null && geo.getLocation() != null)) {
overlayPosition.setCoordinates(geo.getLocation());
}
@@ -908,7 +906,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
*/
private class LoadTimer extends Thread {
- public LoadTimer() {
+ public LoadTimer() {
super("Load Timer");
}
@@ -1605,18 +1603,17 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (cache != null) {
final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(coord, cache.getType());
-
final int hashcode = new HashCodeBuilder()
- .append(cache.isReliableLatLon())
- .append(cache.getType().id)
+ .append(cache.isReliableLatLon())
+ .append(cache.getType().id)
.append(cache.isDisabled() || cache.isArchived())
- .append(cache.isOwn())
- .append(cache.isFound())
- .append(cache.hasUserModifiedCoords())
- .append(cache.getPersonalNote())
+ .append(cache.isOwn())
+ .append(cache.isFound())
+ .append(cache.hasUserModifiedCoords())
+ .append(cache.getPersonalNote())
.append(cache.isLogOffline())
.append(cache.getListId() > 0)
- .toHashCode();
+ .toHashCode();
final LayerDrawable ldFromCache = CGeoMap.overlaysCache.get(hashcode);
if (ldFromCache != null) {
@@ -1700,6 +1697,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
return null;
+
}
}
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index 9ca206e..4def934 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -2,8 +2,8 @@ package cgeo.geocaching.maps;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.Settings;
-import cgeo.geocaching.cgeopopup;
-import cgeo.geocaching.cgeowaypoint;
+import cgeo.geocaching.WaypointPopup;
+import cgeo.geocaching.CachePopup;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
@@ -228,10 +228,10 @@ 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());
- cgeowaypoint.startActivity(context, coordinate.getId());
+ WaypointPopup.startActivity(context, coordinate.getId(), coordinate.getGeocode());
} else {
waitDialog.dismiss();
return false;
@@ -240,6 +240,9 @@ public class CachesOverlay extends AbstractItemizedOverlay {
waitDialog.dismiss();
} catch (Exception e) {
Log.e("cgMapOverlay.onTap: " + e.toString());
+ if (waitDialog != null) {
+ waitDialog.dismiss();
+ }
}
return false;