aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CacheDetailActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CacheDetailActivity.java')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java389
1 files changed, 133 insertions, 256 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 4a9cc6e..8597abd 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -3,7 +3,6 @@ package cgeo.geocaching;
import butterknife.InjectView;
import butterknife.Views;
-import cgeo.calendar.ICalendar;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.AbstractViewPagerActivity;
import cgeo.geocaching.activity.Progress;
@@ -16,11 +15,10 @@ import cgeo.geocaching.enumerations.CacheAttribute;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.WaypointType;
-import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.geopoint.Units;
+import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.network.Network;
-import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.AbstractCachingPageViewCreator;
import cgeo.geocaching.ui.AnchorAwareLinkMovementMethod;
@@ -52,7 +50,7 @@ import cgeo.geocaching.utils.TextUtils;
import cgeo.geocaching.utils.TranslationUtils;
import cgeo.geocaching.utils.UnknownTagsHandler;
-import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -64,8 +62,6 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Typeface;
@@ -89,7 +85,6 @@ import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
@@ -121,25 +116,7 @@ import java.util.regex.Pattern;
*
* e.g. details, description, logs, waypoints, inventory...
*/
-public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailActivity.Page> {
-
- private static final int MENU_FIELD_COPY = 1;
- private static final int MENU_FIELD_TRANSLATE = 2;
- private static final int MENU_FIELD_TRANSLATE_EN = 3;
- private static final int MENU_FIELD_SHARE = 4;
- private static final int MENU_SHARE = 12;
- private static final int MENU_CALENDAR = 11;
- private static final int MENU_CACHES_AROUND = 10;
- private static final int MENU_BROWSER = 7;
- private static final int MENU_DEFAULT_NAVIGATION = 13;
-
- private static final int CONTEXT_MENU_WAYPOINT_EDIT = 1234;
- private static final int CONTEXT_MENU_WAYPOINT_DUPLICATE = 1235;
- private static final int CONTEXT_MENU_WAYPOINT_DELETE = 1236;
- private static final int CONTEXT_MENU_WAYPOINT_NAVIGATE = 1238;
- private static final int CONTEXT_MENU_WAYPOINT_CACHES_AROUND = 1239;
- private static final int CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION = 1240;
- private static final int CONTEXT_MENU_WAYPOINT_RESET_ORIGINAL_CACHE_COORDINATES = 1241;
+public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailActivity.Page> implements CacheMenuHandler.ActivityInterface {
private static final int MESSAGE_FAILED = -1;
private static final int MESSAGE_SUCCEEDED = 1;
@@ -173,7 +150,6 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
};
private CharSequence clickedItemText = null;
- private int contextMenuWPIndex = -1;
/**
* If another activity is called and can modify the data of this activity, we refresh it on resume.
@@ -184,6 +160,10 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
private TextView cacheDistanceView;
protected ImagesList imagesList;
+ /**
+ * waypoint selected in context menu. This variable will be gone when the waypoint context menu is a fragment.
+ */
+ private Waypoint selectedWaypoint;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -291,7 +271,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
title = geocode;
}
progress.show(this, title, res.getString(R.string.cache_dialog_loading_details), true, loadCacheHandler.cancelMessage());
- } catch (final Exception e) {
+ } catch (final RuntimeException e) {
// nothing, we lost the window
}
@@ -360,18 +340,20 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) {
super.onCreateContextMenu(menu, view, info);
final int viewId = view.getId();
- contextMenuWPIndex = -1;
switch (viewId) {
case R.id.value: // coordinates, gc-code, name
+ assert view instanceof TextView;
clickedItemText = ((TextView) view).getText();
final String itemTitle = (String) ((TextView) ((View) view.getParent()).findViewById(R.id.name)).getText();
- buildOptionsContextmenu(menu, viewId, itemTitle, true);
+ buildDetailsContextMenu(menu, itemTitle, true);
break;
case R.id.shortdesc:
+ assert view instanceof TextView;
clickedItemText = ((TextView) view).getText();
- buildOptionsContextmenu(menu, viewId, res.getString(R.string.cache_description), false);
+ buildDetailsContextMenu(menu, res.getString(R.string.cache_description), false);
break;
case R.id.longdesc:
+ assert view instanceof TextView;
// combine short and long description
final String shortDesc = cache.getShortDescription();
if (StringUtils.isBlank(shortDesc)) {
@@ -379,19 +361,22 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
} else {
clickedItemText = shortDesc + "\n\n" + ((TextView) view).getText();
}
- buildOptionsContextmenu(menu, viewId, res.getString(R.string.cache_description), false);
+ buildDetailsContextMenu(menu, res.getString(R.string.cache_description), false);
break;
case R.id.personalnote:
+ assert view instanceof TextView;
clickedItemText = ((TextView) view).getText();
- buildOptionsContextmenu(menu, viewId, res.getString(R.string.cache_personal_note), true);
+ buildDetailsContextMenu(menu, res.getString(R.string.cache_personal_note), true);
break;
case R.id.hint:
+ assert view instanceof TextView;
clickedItemText = ((TextView) view).getText();
- buildOptionsContextmenu(menu, viewId, res.getString(R.string.cache_hint), false);
+ buildDetailsContextMenu(menu, res.getString(R.string.cache_hint), false);
break;
case R.id.log:
+ assert view instanceof TextView;
clickedItemText = ((TextView) view).getText();
- buildOptionsContextmenu(menu, viewId, res.getString(R.string.cache_logs), false);
+ buildDetailsContextMenu(menu, res.getString(R.string.cache_logs), false);
break;
case -1:
if (null != cache.getWaypoints()) {
@@ -401,28 +386,27 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (parent.getChildAt(i) == view) {
final List<Waypoint> sortedWaypoints = new ArrayList<Waypoint>(cache.getWaypoints());
Collections.sort(sortedWaypoints);
- final Waypoint waypoint = sortedWaypoints.get(i);
- final int index = cache.getWaypoints().indexOf(waypoint);
+ selectedWaypoint = sortedWaypoints.get(i);
+
menu.setHeaderTitle(res.getString(R.string.waypoint));
- if (waypoint.getWaypointType().equals(WaypointType.ORIGINAL)) {
- menu.add(CONTEXT_MENU_WAYPOINT_RESET_ORIGINAL_CACHE_COORDINATES, index, 0, R.string.waypoint_reset_cache_coords);
- } else {
- menu.add(CONTEXT_MENU_WAYPOINT_EDIT, index, 0, R.string.waypoint_edit);
- menu.add(CONTEXT_MENU_WAYPOINT_DUPLICATE, index, 0, R.string.waypoint_duplicate);
- }
- contextMenuWPIndex = index;
- if (waypoint.isUserDefined() && !waypoint.getWaypointType().equals(WaypointType.ORIGINAL)) {
- menu.add(CONTEXT_MENU_WAYPOINT_DELETE, index, 0, R.string.waypoint_delete);
- }
- if (waypoint.getCoords() != null) {
- menu.add(CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION, index, 0, NavigationAppFactory.getDefaultNavigationApplication().getName());
- menu.add(CONTEXT_MENU_WAYPOINT_NAVIGATE, index, 0, R.string.cache_menu_navigate).setIcon(R.drawable.ic_menu_mapmode);
- menu.add(CONTEXT_MENU_WAYPOINT_CACHES_AROUND, index, 0, R.string.cache_menu_around);
- }
+ getMenuInflater().inflate(R.menu.waypoint_options, menu);
+ final boolean isOriginalWaypoint = selectedWaypoint.getWaypointType().equals(WaypointType.ORIGINAL);
+ menu.findItem(R.id.menu_waypoint_reset_cache_coords).setVisible(isOriginalWaypoint);
+ menu.findItem(R.id.menu_waypoint_edit).setVisible(!isOriginalWaypoint);
+ menu.findItem(R.id.menu_waypoint_duplicate).setVisible(!isOriginalWaypoint);
+ final boolean userDefined = selectedWaypoint.isUserDefined() && !selectedWaypoint.getWaypointType().equals(WaypointType.ORIGINAL);
+ menu.findItem(R.id.menu_waypoint_delete).setVisible(userDefined);
+ final boolean hasCoords = selectedWaypoint.getCoords() != null;
+ final MenuItem defaultNavigationMenu = menu.findItem(R.id.menu_waypoint_navigate_default);
+ defaultNavigationMenu.setVisible(hasCoords);
+ defaultNavigationMenu.setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName());
+ menu.findItem(R.id.menu_waypoint_navigate).setVisible(hasCoords);
+ menu.findItem(R.id.menu_waypoint_caches_around).setVisible(hasCoords);
+
break;
}
}
- } catch (final Exception e) {
+ } catch (final RuntimeException e) {
}
}
break;
@@ -434,171 +418,118 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
}
- private void buildOptionsContextmenu(ContextMenu menu, int viewId, String fieldTitle, boolean copyOnly) {
+ private void buildDetailsContextMenu(ContextMenu menu, String fieldTitle, boolean copyOnly) {
menu.setHeaderTitle(fieldTitle);
- menu.add(viewId, MENU_FIELD_COPY, 0, res.getString(android.R.string.copy));
+ getMenuInflater().inflate(R.menu.details_context, menu);
+ menu.findItem(R.id.menu_translate_to_sys_lang).setVisible(!copyOnly);
if (!copyOnly) {
- if (clickedItemText.length() > TranslationUtils.translationTextLengthToWarn) {
+ if (clickedItemText.length() > TranslationUtils.TRANSLATION_TEXT_LENGTH_WARN) {
showToast(res.getString(R.string.translate_length_warning));
}
- menu.add(viewId, MENU_FIELD_TRANSLATE, 0, res.getString(R.string.translate_to_sys_lang, Locale.getDefault().getDisplayLanguage()));
- if (Settings.isUseEnglish() && !StringUtils.equals(Locale.getDefault().getLanguage(), Locale.ENGLISH.getLanguage())) {
- menu.add(viewId, MENU_FIELD_TRANSLATE_EN, 0, res.getString(R.string.translate_to_english));
- }
-
+ menu.findItem(R.id.menu_translate_to_sys_lang).setTitle(res.getString(R.string.translate_to_sys_lang, Locale.getDefault().getDisplayLanguage()));
}
- menu.add(viewId, MENU_FIELD_SHARE, 0, res.getString(R.string.cache_share_field));
+ final boolean localeIsEnglish = StringUtils.equals(Locale.getDefault().getLanguage(), Locale.ENGLISH.getLanguage());
+ menu.findItem(R.id.menu_translate_to_english).setVisible(!copyOnly && !localeIsEnglish);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
- final int groupId = item.getGroupId();
- final int index = item.getItemId();
- switch (groupId) {
- case R.id.value:
- case R.id.shortdesc:
- case R.id.longdesc:
- case R.id.personalnote:
- case R.id.hint:
- case R.id.log:
- switch (index) {
- case MENU_FIELD_COPY:
- ClipboardUtils.copyToClipboard(clickedItemText);
- showToast(res.getString(R.string.clipboard_copy_ok));
- return true;
- case MENU_FIELD_TRANSLATE:
- TranslationUtils.startActivityTranslate(this, Locale.getDefault().getLanguage(), HtmlUtils.extractText(clickedItemText));
- return true;
- case MENU_FIELD_TRANSLATE_EN:
- TranslationUtils.startActivityTranslate(this, Locale.ENGLISH.getLanguage(), HtmlUtils.extractText(clickedItemText));
- return true;
- case MENU_FIELD_SHARE:
- final Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("text/plain");
- intent.putExtra(Intent.EXTRA_TEXT, clickedItemText.toString());
- startActivity(Intent.createChooser(intent, res.getText(R.string.cache_share_field)));
- return true;
- default:
- break;
- }
-
- break;
- case CONTEXT_MENU_WAYPOINT_EDIT:
- final Waypoint waypointEdit = cache.getWaypoint(index);
- if (waypointEdit != null) {
- EditWaypointActivity.startActivityEditWaypoint(this, waypointEdit.getId());
+ switch (item.getItemId()) {
+ // detail fields
+ case R.id.menu_copy:
+ ClipboardUtils.copyToClipboard(clickedItemText);
+ showToast(res.getString(R.string.clipboard_copy_ok));
+ return true;
+ case R.id.menu_translate_to_sys_lang:
+ TranslationUtils.startActivityTranslate(this, Locale.getDefault().getLanguage(), HtmlUtils.extractText(clickedItemText));
+ return true;
+ case R.id.menu_translate_to_english:
+ TranslationUtils.startActivityTranslate(this, Locale.ENGLISH.getLanguage(), HtmlUtils.extractText(clickedItemText));
+ return true;
+ case R.id.menu_cache_share_field:
+ final Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.setType("text/plain");
+ intent.putExtra(Intent.EXTRA_TEXT, clickedItemText.toString());
+ startActivity(Intent.createChooser(intent, res.getText(R.string.cache_share_field)));
+ return true;
+ // waypoints
+ case R.id.menu_waypoint_edit:
+ if (selectedWaypoint != null) {
+ EditWaypointActivity.startActivityEditWaypoint(this, cache, selectedWaypoint.getId());
refreshOnResume = true;
}
- break;
- case CONTEXT_MENU_WAYPOINT_DUPLICATE:
- final Waypoint waypointDuplicate = cache.getWaypoint(index);
- if (cache.duplicateWaypoint(waypointDuplicate)) {
- cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ return true;
+ case R.id.menu_waypoint_duplicate:
+ if (cache.duplicateWaypoint(selectedWaypoint)) {
+ DataStore.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
notifyDataSetChanged();
}
- break;
- case CONTEXT_MENU_WAYPOINT_DELETE:
- final Waypoint waypointDelete = cache.getWaypoint(index);
- if (cache.deleteWaypoint(waypointDelete)) {
- cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ return true;
+ case R.id.menu_waypoint_delete:
+ if (cache.deleteWaypoint(selectedWaypoint)) {
+ DataStore.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
notifyDataSetChanged();
}
- break;
- case CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION:
- final Waypoint waypointNavigation = cache.getWaypoint(index);
- if (waypointNavigation != null) {
- NavigationAppFactory.startDefaultNavigationApplication(1, this, waypointNavigation);
+ return true;
+ case R.id.menu_waypoint_navigate_default:
+ if (selectedWaypoint != null) {
+ NavigationAppFactory.startDefaultNavigationApplication(1, this, selectedWaypoint);
}
- break;
- case CONTEXT_MENU_WAYPOINT_NAVIGATE:
- final Waypoint waypointNav = cache.getWaypoint(contextMenuWPIndex);
- if (waypointNav != null) {
- NavigationAppFactory.showNavigationMenu(this, null, waypointNav, null);
+ return true;
+ case R.id.menu_waypoint_navigate:
+ if (selectedWaypoint != null) {
+ NavigationAppFactory.showNavigationMenu(this, null, selectedWaypoint, null);
}
- break;
- case CONTEXT_MENU_WAYPOINT_CACHES_AROUND:
- final Waypoint waypointAround = cache.getWaypoint(index);
- if (waypointAround != null) {
- cgeocaches.startActivityCoordinates(this, waypointAround.getCoords());
+ return true;
+ case R.id.menu_waypoint_caches_around:
+ if (selectedWaypoint != null) {
+ CacheListActivity.startActivityCoordinates(this, selectedWaypoint.getCoords());
}
- break;
-
- case CONTEXT_MENU_WAYPOINT_RESET_ORIGINAL_CACHE_COORDINATES:
- final Waypoint waypointReset = cache.getWaypoint(index);
+ return true;
+ case R.id.menu_waypoint_reset_cache_coords:
if (ConnectorFactory.getConnector(cache).supportsOwnCoordinates()) {
- createResetCacheCoordinatesDialog(cache, waypointReset).show();
+ createResetCacheCoordinatesDialog(cache, selectedWaypoint).show();
}
else {
final ProgressDialog progressDialog = ProgressDialog.show(this, getString(R.string.cache), getString(R.string.waypoint_reset), true);
final HandlerResetCoordinates handler = new HandlerResetCoordinates(this, progressDialog, false);
- new ResetCoordsThread(cache, handler, waypointReset, true, false, progressDialog).start();
+ new ResetCoordsThread(cache, handler, selectedWaypoint, true, false, progressDialog).start();
}
- break;
-
+ return true;
default:
- if (imagesList != null && imagesList.onContextItemSelected(item)) {
- return true;
- }
- return onOptionsItemSelected(item);
+ break;
+ }
+ if (imagesList != null && imagesList.onContextItemSelected(item)) {
+ return true;
}
- return false;
+ return onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- if (null != cache) {
- menu.add(0, MENU_DEFAULT_NAVIGATION, 0, NavigationAppFactory.getDefaultNavigationApplication().getName()).setIcon(R.drawable.ic_menu_compass); // default navigation tool
-
- final SubMenu subMenu = menu.addSubMenu(0, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(R.drawable.ic_menu_mapmode);
- NavigationAppFactory.addMenuItems(subMenu, cache);
-
- menu.add(0, MENU_CALENDAR, 0, res.getString(R.string.cache_menu_event)).setIcon(R.drawable.ic_menu_agenda); // add event to calendar
- LoggingUI.addMenuItems(this, 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_BROWSER, 0, res.getString(R.string.cache_menu_browser)).setIcon(R.drawable.ic_menu_globe); // browser
- menu.add(0, MENU_SHARE, 0, res.getString(R.string.cache_menu_share)).setIcon(R.drawable.ic_menu_share); // share cache
- }
+ CacheMenuHandler.addMenuItems(this, menu, cache);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- if (cache != null) {
- menu.findItem(MENU_DEFAULT_NAVIGATION).setVisible(null != cache.getCoords());
- menu.findItem(MENU_CALENDAR).setVisible(cache.canBeAddedToCalendar());
- menu.findItem(MENU_CACHES_AROUND).setVisible(null != cache.getCoords() && cache.supportsCachesAround());
- menu.findItem(MENU_BROWSER).setVisible(cache.canOpenInBrowser());
- LoggingUI.onPrepareOptionsMenu(menu, cache);
- }
+ CacheMenuHandler.onPrepareOptionsMenu(menu, cache);
+ LoggingUI.onPrepareOptionsMenu(menu, cache);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ if (CacheMenuHandler.onMenuItemSelected(item, this, cache)) {
+ return true;
+ }
+
final int menuItem = item.getItemId();
switch (menuItem) {
case 0:
// no menu selected, but a new sub menu shown
return false;
- case MENU_DEFAULT_NAVIGATION:
- startDefaultNavigation();
- return true;
- case MENU_BROWSER:
- cache.openInBrowser(this);
- return true;
- case MENU_CACHES_AROUND:
- cgeocaches.startActivityCoordinates(this, cache.getCoords());
- return true;
- case MENU_CALENDAR:
- addToCalendarWithIntent();
- return true;
- case MENU_SHARE:
- if (cache != null) {
- cache.shareCache(this, res);
- return true;
- }
- return false;
default:
if (NavigationAppFactory.onMenuItemSelected(item, this, cache)) {
return true;
@@ -732,80 +663,6 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
/**
- * Indicates whether the specified action can be used as an intent. This
- * method queries the package manager for installed packages that can
- * respond to an intent with the specified action. If no suitable package is
- * found, this method returns false.
- *
- * @param context
- * The application's environment.
- * @param action
- * The Intent action to check for availability.
- * @param uri
- * The Intent URI to check for availability.
- *
- * @return True if an Intent with the specified action can be sent and
- * responded to, false otherwise.
- */
- private static boolean isIntentAvailable(Context context, String action, Uri uri) {
- final PackageManager packageManager = context.getPackageManager();
- final Intent intent;
- if (uri == null) {
- intent = new Intent(action);
- } else {
- intent = new Intent(action, uri);
- }
- final List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
- PackageManager.MATCH_DEFAULT_ONLY);
- return !list.isEmpty();
- }
-
- private void addToCalendarWithIntent() {
-
- final boolean calendarAddOnAvailable = isIntentAvailable(this, ICalendar.INTENT, Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST));
-
- if (calendarAddOnAvailable) {
- final Parameters params = new Parameters(
- ICalendar.PARAM_NAME, cache.getName(),
- ICalendar.PARAM_NOTE, StringUtils.defaultString(cache.getPersonalNote()),
- ICalendar.PARAM_HIDDEN_DATE, String.valueOf(cache.getHiddenDate().getTime()),
- ICalendar.PARAM_URL, StringUtils.defaultString(cache.getUrl()),
- ICalendar.PARAM_COORDS, cache.getCoords() == null ? "" : cache.getCoords().format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW),
- ICalendar.PARAM_LOCATION, StringUtils.defaultString(cache.getLocation()),
- ICalendar.PARAM_SHORT_DESC, StringUtils.defaultString(cache.getShortDescription()),
- ICalendar.PARAM_START_TIME_MINUTES, StringUtils.defaultString(cache.guessEventTimeMinutes())
- );
-
- startActivity(new Intent(ICalendar.INTENT,
- Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST + "?" + params.toString())));
- } else {
- // Inform user the calendar add-on is not installed and let them get it from Google Play
- new AlertDialog.Builder(this)
- .setTitle(res.getString(R.string.addon_missing_title))
- .setMessage(new StringBuilder(res.getString(R.string.helper_calendar_missing))
- .append(' ')
- .append(res.getString(R.string.addon_download_prompt))
- .toString())
- .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- final Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(Uri.parse(ICalendar.CALENDAR_ADDON_URI));
- startActivity(intent);
- }
- })
- .setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- })
- .create()
- .show();
- }
- }
-
- /**
* Tries to navigate to the {@link Geocache} of this activity.
*/
private void startDefaultNavigation() {
@@ -1134,7 +991,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (time > 0) {
String dateString = Formatter.formatFullDate(time);
if (cache.isEventCache()) {
- dateString = DateUtils.formatDateTime(cgeoapplication.getInstance().getBaseContext(), time, DateUtils.FORMAT_SHOW_WEEKDAY) + ", " + dateString;
+ dateString = DateUtils.formatDateTime(CgeoApplication.getInstance().getBaseContext(), time, DateUtils.FORMAT_SHOW_WEEKDAY) + ", " + dateString;
}
details.add(cache.isEventCache() ? R.string.cache_event : R.string.cache_hidden, dateString);
}
@@ -1279,7 +1136,6 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
private Handler handler;
public DropCacheThread(Handler handler) {
- super();
this.handler = handler;
}
@@ -1481,7 +1337,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
Settings.saveLastList(listId);
- cgData.moveToList(cache, listId);
+ DataStore.moveToList(cache, listId);
updateListBox();
}
@@ -1564,7 +1420,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
// update text
final TextView text = (TextView) view.findViewById(R.id.list_text);
- final StoredList list = cgData.getList(cache.getListId());
+ final StoredList list = DataStore.getList(cache.getListId());
if (list != null) {
text.setText(res.getString(R.string.cache_list_text) + " " + list.title);
} else {
@@ -1615,7 +1471,8 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
return;
}
- ((ImageView) view.findViewById(R.id.map_preview)).setImageDrawable(image);
+ final ImageView imageView = (ImageView) view.findViewById(R.id.map_preview);
+ imageView.setImageDrawable(image);
view.findViewById(R.id.map_preview_box).setVisibility(View.VISIBLE);
} catch (final Exception e) {
Log.e("CacheDetailActivity.PreviewMapTask", e);
@@ -1706,12 +1563,16 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
hintView.setVisibility(View.VISIBLE);
hintView.setClickable(true);
- hintView.setOnClickListener(new DecryptTextClickListener());
+ hintView.setOnClickListener(new DecryptTextClickListener(hintView));
+ hintBoxView.setOnClickListener(new DecryptTextClickListener(hintView));
+ hintBoxView.setClickable(true);
registerForContextMenu(hintView);
} else {
hintView.setVisibility(View.GONE);
hintView.setClickable(false);
hintView.setOnClickListener(null);
+ hintBoxView.setClickable(false);
+ hintBoxView.setOnClickListener(null);
}
final TextView spoilerlinkView = ((TextView) view.findViewById(R.id.hint_spoilerlink));
@@ -1808,6 +1669,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
private final View shortDescView;
public LoadDescriptionTask(final String description, final View descriptionView, final View loadingIndicatorView, final View shortDescView) {
+ assert descriptionView instanceof IndexOutOfBoundsAvoidingTextView;
this.descriptionString = description;
this.descriptionView = (IndexOutOfBoundsAvoidingTextView) descriptionView;
this.loadingIndicatorView = loadingIndicatorView;
@@ -2028,7 +1890,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
waypointView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
- EditWaypointActivity.startActivityEditWaypoint(CacheDetailActivity.this, wpt.getId());
+ EditWaypointActivity.startActivityEditWaypoint(CacheDetailActivity.this, cache, wpt.getId());
refreshOnResume = true;
return true;
}
@@ -2197,7 +2059,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
cache.setCoords(wpt.getCoords());
cache.setUserModifiedCoords(false);
cache.deleteWaypointForce(wpt);
- cgData.saveChangedCache(cache);
+ DataStore.saveChangedCache(cache);
handler.sendEmptyMessage(LOCAL);
}
@@ -2452,7 +2314,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
protected void storeCache(final int listId, final StoreCacheHandler storeCacheHandler) {
- progress.show(CacheDetailActivity.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, storeCacheHandler.cancelMessage());
+ progress.show(this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, storeCacheHandler.cancelMessage());
if (storeThread != null) {
storeThread.interrupt();
@@ -2491,7 +2353,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
cache.parseWaypointsFromNote();
TextView personalNoteView = (TextView) activity.findViewById(R.id.personalnote);
setPersonalNote(personalNoteView, note);
- cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ DataStore.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
activity.notifyDataSetChanged();
}
};
@@ -2509,4 +2371,19 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
personalNoteView.setVisibility(View.GONE);
}
}
+
+ @Override
+ public void navigateTo() {
+ startDefaultNavigation();
+ }
+
+ @Override
+ public void showNavigationMenu() {
+ NavigationAppFactory.showNavigationMenu(this, cache, null, null);
+ }
+
+ @Override
+ public void cachesAround() {
+ CacheListActivity.startActivityCoordinates(this, cache.getCoords());
+ }
}