aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo')
-rw-r--r--main/src/cgeo/geocaching/AbstractPopupActivity.java2
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java32
-rw-r--r--main/src/cgeo/geocaching/EditWaypointActivity.java6
-rw-r--r--main/src/cgeo/geocaching/GeoDataProvider.java3
-rw-r--r--main/src/cgeo/geocaching/LogTrackableActivity.java15
-rw-r--r--main/src/cgeo/geocaching/SearchActivity.java14
-rw-r--r--main/src/cgeo/geocaching/Settings.java33
-rw-r--r--main/src/cgeo/geocaching/SettingsActivity.java115
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java17
-rw-r--r--main/src/cgeo/geocaching/VisitCacheActivity.java17
-rw-r--r--main/src/cgeo/geocaching/apps/AbstractApp.java22
-rw-r--r--main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java21
-rw-r--r--main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java7
-rw-r--r--main/src/cgeo/geocaching/cgCache.java22
-rw-r--r--main/src/cgeo/geocaching/cgeo.java2
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java20
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java99
-rw-r--r--main/src/cgeo/geocaching/cgeogpxes.java4
-rw-r--r--main/src/cgeo/geocaching/cgeonavigate.java12
-rw-r--r--main/src/cgeo/geocaching/cgeotrackable.java2
-rw-r--r--main/src/cgeo/geocaching/connector/ConnectorFactory.java4
-rw-r--r--main/src/cgeo/geocaching/enumerations/CacheAttribute.java4
-rw-r--r--main/src/cgeo/geocaching/export/GpxExport.java27
-rw-r--r--main/src/cgeo/geocaching/files/SimpleDirChooser.java55
-rw-r--r--main/src/cgeo/geocaching/go4cache/Go4Cache.java173
-rw-r--r--main/src/cgeo/geocaching/go4cache/Go4CacheUser.java106
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java152
-rw-r--r--main/src/cgeo/geocaching/maps/OtherCachersOverlay.java144
-rw-r--r--main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java36
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java9
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleMapView.java8
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlay.java117
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java32
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java5
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java3
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java12
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java9
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java8
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java120
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java32
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java10
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java8
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java120
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java32
-rw-r--r--main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java4
-rw-r--r--main/src/cgeo/geocaching/utils/HtmlUtils.java56
-rw-r--r--main/src/cgeo/geocaching/utils/LogTemplateProvider.java177
-rw-r--r--main/src/cgeo/geocaching/utils/ProcessUtils.java27
-rw-r--r--main/src/cgeo/geocaching/utils/TranslationUtils.java12
49 files changed, 507 insertions, 1460 deletions
diff --git a/main/src/cgeo/geocaching/AbstractPopupActivity.java b/main/src/cgeo/geocaching/AbstractPopupActivity.java
index a119949..d765bdc 100644
--- a/main/src/cgeo/geocaching/AbstractPopupActivity.java
+++ b/main/src/cgeo/geocaching/AbstractPopupActivity.java
@@ -109,8 +109,6 @@ public abstract class AbstractPopupActivity extends AbstractActivity {
}
protected void init() {
- app.setAction(geocode);
-
cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
if (cache == null) {
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index ed75d7a..f9f9059 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -25,6 +25,7 @@ import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.ClipboardUtils;
import cgeo.geocaching.utils.CryptUtils;
import cgeo.geocaching.utils.GeoDirHandler;
+import cgeo.geocaching.utils.HtmlUtils;
import cgeo.geocaching.utils.ImageHelper;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.TranslationUtils;
@@ -98,6 +99,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Activity to handle all single-cache-stuff.
@@ -123,6 +126,8 @@ public class CacheDetailActivity extends AbstractActivity {
private static final int CONTEXT_MENU_WAYPOINT_CACHES_AROUND = 1239;
private static final int CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION = 1240;
+ private static final Pattern DARK_COLOR_PATTERN = Pattern.compile(Pattern.quote("color=\"#") + "(0[0-9]){3}" + "\"");
+
private cgCache cache;
private final Progress progress = new Progress();
private SearchResult search;
@@ -283,11 +288,6 @@ public class CacheDetailActivity extends AbstractActivity {
return;
}
- // Go4Cache
- if (StringUtils.isNotBlank(geocode)) {
- app.setAction(geocode);
- }
-
final LoadCacheHandler loadCacheHandler = new LoadCacheHandler();
try {
@@ -484,10 +484,10 @@ public class CacheDetailActivity extends AbstractActivity {
showToast(res.getString(R.string.clipboard_copy_ok));
return true;
case MENU_FIELD_TRANSLATE:
- TranslationUtils.startActivityTranslate(this, Locale.getDefault().getLanguage(), clickedItemText.toString());
+ TranslationUtils.startActivityTranslate(this, Locale.getDefault().getLanguage(), HtmlUtils.extractText(clickedItemText));
return true;
case MENU_FIELD_TRANSLATE_EN:
- TranslationUtils.startActivityTranslate(this, Locale.ENGLISH.getLanguage(), clickedItemText.toString());
+ TranslationUtils.startActivityTranslate(this, Locale.ENGLISH.getLanguage(), HtmlUtils.extractText(clickedItemText));
return true;
case MENU_FIELD_SHARE:
final Intent intent = new Intent(Intent.ACTION_SEND);
@@ -2062,14 +2062,20 @@ public class CacheDetailActivity extends AbstractActivity {
* @param text
*/
private void fixBlackTextColor(final TextView view, final String text) {
- if (!Settings.isLightSkin()) {
- if (-1 != StringUtils.indexOfAny(text, new String[] { "color=\"#000000", "color=\"black" })) {
- view.setBackgroundResource(color.darker_gray);
- }
- else {
- view.setBackgroundResource(color.black);
+ if (Settings.isLightSkin()) {
+ return;
+ }
+ int backcolor = color.black;
+ if (-1 != StringUtils.indexOfAny(text, new String[] { "color=\"black", "color=\"#000080\"" })) {
+ backcolor = color.darker_gray;
+ }
+ else {
+ Matcher matcher = DARK_COLOR_PATTERN.matcher(text);
+ if (matcher.find()) {
+ backcolor = color.darker_gray;
}
}
+ view.setBackgroundResource(backcolor);
}
}
diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java
index d32be66..ef2a2cc 100644
--- a/main/src/cgeo/geocaching/EditWaypointActivity.java
+++ b/main/src/cgeo/geocaching/EditWaypointActivity.java
@@ -66,8 +66,6 @@ public class EditWaypointActivity extends AbstractActivity {
lookup = waypoint.getLookup();
own = waypoint.isUserDefined();
- app.setAction(geocode);
-
if (waypoint.getCoords() != null) {
((Button) findViewById(R.id.buttonLatitude)).setText(waypoint.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE));
((Button) findViewById(R.id.buttonLongitude)).setText(waypoint.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE));
@@ -126,10 +124,6 @@ public class EditWaypointActivity extends AbstractActivity {
setTitle(res.getString(R.string.waypoint_edit_title));
}
- if (geocode != null) {
- app.setAction(geocode);
- }
-
Button buttonLat = (Button) findViewById(R.id.buttonLatitude);
buttonLat.setOnClickListener(new coordDialogListener());
Button buttonLon = (Button) findViewById(R.id.buttonLongitude);
diff --git a/main/src/cgeo/geocaching/GeoDataProvider.java b/main/src/cgeo/geocaching/GeoDataProvider.java
index 1b9a0f5..f615630 100644
--- a/main/src/cgeo/geocaching/GeoDataProvider.java
+++ b/main/src/cgeo/geocaching/GeoDataProvider.java
@@ -2,7 +2,6 @@ package cgeo.geocaching;
import cgeo.geocaching.enumerations.LocationProviderType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4Cache;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.MemorySubject;
@@ -335,8 +334,6 @@ class GeoDataProvider extends MemorySubject<IGeoData> {
final int visible = gpsLocation.isRecent() ? satellitesVisible : 0;
final IGeoData current = new GeoData(locationData.location, gpsEnabled, visible, satellitesFixed);
notifyObservers(current);
-
- Go4Cache.signalCoordinates(current.getCoords());
}
}
diff --git a/main/src/cgeo/geocaching/LogTrackableActivity.java b/main/src/cgeo/geocaching/LogTrackableActivity.java
index 578bd62..5ae0d01 100644
--- a/main/src/cgeo/geocaching/LogTrackableActivity.java
+++ b/main/src/cgeo/geocaching/LogTrackableActivity.java
@@ -12,6 +12,7 @@ import cgeo.geocaching.ui.DateDialog;
import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.LogTemplateProvider;
+import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import cgeo.geocaching.utils.LogTemplateProvider.LogTemplate;
import org.apache.commons.collections.CollectionUtils;
@@ -51,6 +52,7 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
private int attempts = 0;
private CheckBox tweetCheck = null;
private LinearLayout tweetBox = null;
+ private cgTrackable trackable;
private static final int MENU_SIGNATURE = 1;
@@ -132,7 +134,7 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
}
}
- final cgTrackable trackable = app.getTrackableByGeocode(geocode);
+ trackable = app.getTrackableByGeocode(geocode);
if (StringUtils.isNotBlank(trackable.getName())) {
setTitle(res.getString(R.string.trackable_touch) + ": " + trackable.getName());
@@ -140,8 +142,6 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
setTitle(res.getString(R.string.trackable_touch) + ": " + trackable.getGeocode().toUpperCase());
}
- app.setAction("logging trackable");
-
if (guid == null) {
showToast(res.getString(R.string.err_tb_forgot_saw));
@@ -185,15 +185,16 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final int id = item.getItemId();
+ final LogContext logContext = new LogContext(trackable);
if (id == MENU_SIGNATURE) {
- insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), false), true);
+ insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), logContext), true);
return true;
}
final LogTemplate template = LogTemplateProvider.getTemplate(id);
if (template != null) {
- insertIntoLog(template.getValue(false), true);
+ insertIntoLog(template.getValue(logContext), true);
return true;
}
@@ -232,10 +233,6 @@ public class LogTrackableActivity extends AbstractActivity implements DateDialog
}
public void init() {
- if (geocode != null) {
- app.setAction("logging trackable");
- }
-
final Button typeButton = (Button) findViewById(R.id.type);
registerForContextMenu(typeButton);
typeButton.setText(typeSelected.getL10n());
diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java
index ae350c0..3221479 100644
--- a/main/src/cgeo/geocaching/SearchActivity.java
+++ b/main/src/cgeo/geocaching/SearchActivity.java
@@ -1,6 +1,9 @@
package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.connector.IConnector;
+import cgeo.geocaching.connector.capability.ISearchByGeocode;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
@@ -41,9 +44,6 @@ public class SearchActivity extends AbstractActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // init
- app.setAction(null);
-
// search query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
@@ -98,14 +98,18 @@ public class SearchActivity extends AbstractActivity {
* @return true if a search was performed, else false
*/
private boolean instantSearch(final String query, final boolean keywordSearch) {
- final String geocode = BaseUtils.getMatch(query, GCConstants.PATTERN_GC_CODE, true, 0, "", false);
- if (StringUtils.isNotBlank(geocode)) {
+
+ // Check if any connector can handle the query as a geocode
+ final String geocode = StringUtils.trim(query);
+ final IConnector connector = ConnectorFactory.getConnector(geocode);
+ if (connector instanceof ISearchByGeocode) {
final Intent cachesIntent = new Intent(this, CacheDetailActivity.class);
cachesIntent.putExtra("geocode", geocode.toUpperCase());
startActivity(cachesIntent);
return true;
}
+ // Check if the query is a TB code
final String trackable = BaseUtils.getMatch(query, GCConstants.PATTERN_TB_CODE, true, 0, "", false);
if (StringUtils.isNotBlank(trackable)) {
final Intent trackablesIntent = new Intent(this, cgeotrackable.class);
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java
index ee201e2..92241c2 100644
--- a/main/src/cgeo/geocaching/Settings.java
+++ b/main/src/cgeo/geocaching/Settings.java
@@ -22,6 +22,7 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.os.Environment;
import android.preference.PreferenceManager;
import java.util.Locale;
@@ -36,7 +37,6 @@ public final class Settings {
private static final String KEY_HELP_SHOWN = "helper";
private static final String KEY_ANYLONGITUDE = "anylongitude";
private static final String KEY_ANYLATITUDE = "anylatitude";
- private static final String KEY_PUBLICLOC = "publicloc";
private static final String KEY_USE_OFFLINEMAPS = "offlinemaps";
private static final String KEY_USE_OFFLINEWPMAPS = "offlinewpmaps";
private static final String KEY_WEB_DEVICE_CODE = "webDeviceCode";
@@ -96,6 +96,7 @@ public final class Settings {
private static final String KEY_LAST_TRACKABLE_ACTION = "trackableaction";
private static final String KEY_SHARE_AFTER_EXPORT = "shareafterexport";
private static final String KEY_GPX_EXPORT_DIR = "gpxExportDir";
+ private static final String KEY_GPX_IMPORT_DIR = "gpxImportDir";
private final static int unitsMetric = 1;
@@ -150,7 +151,6 @@ public final class Settings {
e.putBoolean(KEY_HELP_SHOWN, old.getInt(KEY_HELP_SHOWN, 0) != 0);
e.putFloat(KEY_ANYLONGITUDE, old.getFloat(KEY_ANYLONGITUDE, 0));
e.putFloat(KEY_ANYLATITUDE, old.getFloat(KEY_ANYLATITUDE, 0));
- e.putBoolean(KEY_PUBLICLOC, 0 != old.getInt(KEY_PUBLICLOC, 0));
e.putBoolean(KEY_USE_OFFLINEMAPS, 0 != old.getInt(KEY_USE_OFFLINEMAPS, 1));
e.putBoolean(KEY_USE_OFFLINEWPMAPS, 0 != old.getInt(KEY_USE_OFFLINEWPMAPS, 0));
e.putString(KEY_WEB_DEVICE_CODE, old.getString(KEY_WEB_DEVICE_CODE, null));
@@ -721,20 +721,6 @@ public final class Settings {
});
}
- public static boolean isPublicLoc() {
- return sharedPrefs.getBoolean(KEY_PUBLICLOC, false);
- }
-
- public static void setPublicLoc(final boolean publicLocation) {
- editSharedSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putBoolean(KEY_PUBLICLOC, publicLocation);
- }
- });
- }
-
public static boolean isTrackableAutoVisit() {
return sharedPrefs.getBoolean(KEY_AUTO_VISIT_TRACKABLES, false);
}
@@ -1168,7 +1154,7 @@ public final class Settings {
}
public static String getGpxExportDir() {
- return sharedPrefs.getString(KEY_GPX_EXPORT_DIR, "/sdcard/gpx");
+ return sharedPrefs.getString(KEY_GPX_EXPORT_DIR, Environment.getExternalStorageDirectory().getPath() + "/gpx");
}
public static void setGpxExportDir(final String gpxExportDir) {
@@ -1180,6 +1166,19 @@ public final class Settings {
});
}
+ public static String getGpxImportDir() {
+ return sharedPrefs.getString(KEY_GPX_IMPORT_DIR, Environment.getExternalStorageDirectory().getPath() + "/gpx");
+ }
+
+ public static void setGpxImportDir(final String gpxImportDir) {
+ editSharedSettings(new PrefRunnable() {
+ @Override
+ public void edit(Editor edit) {
+ edit.putString(KEY_GPX_IMPORT_DIR, gpxImportDir);
+ }
+ });
+ }
+
public static boolean getShareAfterExport() {
return sharedPrefs.getBoolean(KEY_SHARE_AFTER_EXPORT, true);
}
diff --git a/main/src/cgeo/geocaching/SettingsActivity.java b/main/src/cgeo/geocaching/SettingsActivity.java
index 8d802bf..ac8167a 100644
--- a/main/src/cgeo/geocaching/SettingsActivity.java
+++ b/main/src/cgeo/geocaching/SettingsActivity.java
@@ -18,6 +18,7 @@ import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.LogTemplateProvider;
import cgeo.geocaching.utils.LogTemplateProvider.LogTemplate;
+import cgeo.geocaching.utils.RunnableWithArgument;
import ch.boye.httpclientandroidlib.HttpResponse;
@@ -56,7 +57,8 @@ import java.util.List;
public class SettingsActivity extends AbstractActivity {
private final static int SELECT_MAPFILE_REQUEST = 1;
- private final static int SELECT_GPXDIR_REQUEST = 2;
+ private final static int SELECT_GPX_EXPORT_REQUEST = 2;
+ private final static int SELECT_GPX_IMPORT_REQUEST = 3;
private ProgressDialog loginDialog = null;
@@ -175,14 +177,11 @@ public class SettingsActivity extends AbstractActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == 0) {
- boolean status;
-
((EditText) findViewById(R.id.username)).setText("");
((EditText) findViewById(R.id.password)).setText("");
((EditText) findViewById(R.id.passvote)).setText("");
- status = saveValues();
- if (status) {
+ if (saveValues()) {
showToast(res.getString(R.string.init_cleared));
} else {
showToast(res.getString(R.string.err_init_cleared));
@@ -249,27 +248,6 @@ public class SettingsActivity extends AbstractActivity {
((EditText) findViewById(R.id.passvote)).setText(gcvoteLogin.right);
}
- // go4cache settings
- TextView go4cache = (TextView) findViewById(R.id.about_go4cache);
- go4cache.setClickable(true);
- go4cache.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View arg0) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://go4cache.com/")));
- }
- });
-
- final CheckBox publicButton = (CheckBox) findViewById(R.id.publicloc);
- publicButton.setChecked(Settings.isPublicLoc());
- publicButton.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- Settings.setPublicLoc(publicButton.isChecked());
- }
- });
-
// Twitter settings
Button authorizeTwitter = (Button) findViewById(R.id.authorize_twitter);
authorizeTwitter.setOnClickListener(new View.OnClickListener() {
@@ -590,7 +568,21 @@ public class SettingsActivity extends AbstractActivity {
public void onClick(View v) {
Intent dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class);
dirChooser.putExtra(SimpleDirChooser.START_DIR, Settings.getGpxExportDir());
- startActivityForResult(dirChooser, SELECT_GPXDIR_REQUEST);
+ startActivityForResult(dirChooser, SELECT_GPX_EXPORT_REQUEST);
+ }
+ });
+
+ // GPX Import directory
+ final EditText gpxImportDir = (EditText) findViewById(R.id.gpx_importdir);
+ gpxImportDir.setText(Settings.getGpxImportDir());
+ Button selectGpxImportDir = (Button) findViewById(R.id.select_gpx_importdir);
+ selectGpxImportDir.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Intent dirChooser = new Intent(SettingsActivity.this, SimpleDirChooser.class);
+ dirChooser.putExtra(SimpleDirChooser.START_DIR, Settings.getGpxImportDir());
+ startActivityForResult(dirChooser, SELECT_GPX_IMPORT_REQUEST);
}
});
@@ -786,31 +778,31 @@ public class SettingsActivity extends AbstractActivity {
String passvoteNew = StringUtils.trimToEmpty(((EditText) findViewById(R.id.passvote)).getText().toString());
// don't trim signature, user may want to have whitespace at the beginning
String signatureNew = ((EditText) findViewById(R.id.signature)).getText().toString();
+ String mapFileNew = StringUtils.trimToEmpty(((EditText) findViewById(R.id.mapfile)).getText().toString());
+
String altitudeNew = StringUtils.trimToNull(((EditText) findViewById(R.id.altitude)).getText().toString());
- String mfmapFileNew = StringUtils.trimToEmpty(((EditText) findViewById(R.id.mapfile)).getText().toString());
+ int altitudeNewInt = parseNumber(altitudeNew, 0);
- int altitudeNewInt = 0;
- if (altitudeNew != null) {
- try {
- altitudeNewInt = Integer.parseInt(altitudeNew);
- } catch (NumberFormatException e) {
- altitudeNewInt = 0;
- }
- }
+ TextView field = (TextView) findViewById(R.id.showwaypointsthreshold);
+ final int waypointThreshold = parseNumber(field.getText().toString(), 5);
final boolean status1 = Settings.setLogin(usernameNew, passwordNew);
final boolean status2 = Settings.setGCvoteLogin(passvoteNew);
final boolean status3 = Settings.setSignature(signatureNew);
final boolean status4 = Settings.setAltCorrection(altitudeNewInt);
- final boolean status5 = Settings.setMapFile(mfmapFileNew);
- TextView field = (TextView) findViewById(R.id.showwaypointsthreshold);
- Settings.setShowWaypointsThreshold(safeParse(field, 5));
+ final boolean status5 = Settings.setMapFile(mapFileNew);
+ Settings.setShowWaypointsThreshold(waypointThreshold);
+
+ String importNew = StringUtils.trimToEmpty(((EditText) findViewById(R.id.gpx_importdir)).getText().toString());
+ String exportNew = StringUtils.trimToEmpty(((EditText) findViewById(R.id.gpx_exportdir)).getText().toString());
+ Settings.setGpxImportDir(importNew);
+ Settings.setGpxExportDir(exportNew);
return status1 && status2 && status3 && status4 && status5;
}
/**
- * Returns the Int Value in the Field
+ * Returns the integer value from the string
*
* @param field
* the field to retrieve the integer value from
@@ -819,9 +811,9 @@ public class SettingsActivity extends AbstractActivity {
* @return either the field content or the default value
*/
- static private int safeParse(final TextView field, int defaultValue) {
+ static private int parseNumber(final String number, int defaultValue) {
try {
- return Integer.parseInt(field.getText().toString());
+ return Integer.parseInt(number);
} catch (NumberFormatException e) {
return defaultValue;
}
@@ -902,8 +894,7 @@ public class SettingsActivity extends AbstractActivity {
final Parameters params = new Parameters("name", nam, "code", cod);
HttpResponse response = Network.getRequest("http://send2.cgeo.org/auth.html", params);
- if (response != null && response.getStatusLine().getStatusCode() == 200)
- {
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
//response was OK
String[] strings = Network.getResponseData(response).split(",");
try {
@@ -922,7 +913,7 @@ public class SettingsActivity extends AbstractActivity {
}
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_MAPFILE_REQUEST) {
@@ -936,15 +927,35 @@ public class SettingsActivity extends AbstractActivity {
}
initMapfileEdittext(true);
}
- if (requestCode == SELECT_GPXDIR_REQUEST) {
- if (resultCode == RESULT_OK) {
- if (data.hasExtra("chosenDir")) {
- Settings.setGpxExportDir(data.getStringExtra("chosenDir"));
+ if (requestCode == SELECT_GPX_EXPORT_REQUEST) {
+ checkDirectory(resultCode, data, R.id.gpx_exportdir, new RunnableWithArgument<String>() {
+
+ @Override
+ public void run(String directory) {
+ Settings.setGpxExportDir(directory);
}
+ });
+ }
+ if (requestCode == SELECT_GPX_IMPORT_REQUEST) {
+ checkDirectory(resultCode, data, R.id.gpx_importdir, new RunnableWithArgument<String>() {
+
+ @Override
+ public void run(String directory) {
+ Settings.setGpxImportDir(directory);
+ }
+ });
+ }
+ }
+
+ private void checkDirectory(int resultCode, Intent data, int textField, RunnableWithArgument<String> runnableSetDir) {
+ if (resultCode == RESULT_OK) {
+ if (data.hasExtra(SimpleDirChooser.EXTRA_CHOSEN_DIR)) {
+ final String directory = data.getStringExtra(SimpleDirChooser.EXTRA_CHOSEN_DIR);
+ runnableSetDir.run(directory);
+ EditText directoryText = (EditText) findViewById(textField);
+ directoryText.setText(directory);
+ directoryText.requestFocus();
}
- EditText gpxExportDir = (EditText) findViewById(R.id.gpx_exportdir);
- gpxExportDir.setText(Settings.getGpxExportDir());
- gpxExportDir.requestFocus();
}
}
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index 6de1291..ea99d54 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -85,10 +85,13 @@ public class StaticMapsProvider {
}
private static void downloadMaps(cgCache cache, Display display) {
+ if (cache == null) {
+ Log.e("downloadMaps - missing input parameter cache");
+ return;
+ }
if ((!Settings.isStoreOfflineMaps() && !Settings.isStoreOfflineWpMaps()) || StringUtils.isBlank(cache.getGeocode())) {
return;
}
-
int edge = guessMaxDisplaySide(display);
if (Settings.isStoreOfflineMaps() && cache.getCoords() != null) {
@@ -112,6 +115,14 @@ public class StaticMapsProvider {
}
private static void storeWaypointStaticMap(final String geocode, int edge, cgWaypoint waypoint, final boolean waitForResult) {
+ if (geocode == null) {
+ Log.e("storeWaypointStaticMap - missing input parameter geocode");
+ return;
+ }
+ if (waypoint == null) {
+ Log.e("storeWaypointStaticMap - missing input parameter waypoint");
+ return;
+ }
if (waypoint.getCoords() == null) {
return;
}
@@ -142,6 +153,10 @@ public class StaticMapsProvider {
}
public static void storeCachePreviewMap(final cgCache cache) {
+ if (cache == null) {
+ Log.e("storeCachePreviewMap - missing input parameter cache");
+ return;
+ }
final String latlonMap = cache.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA);
final String markerUrl = MARKERS_URL + "my_location_mdpi.png";
final Display display = ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
diff --git a/main/src/cgeo/geocaching/VisitCacheActivity.java b/main/src/cgeo/geocaching/VisitCacheActivity.java
index e5410e7..c6823c8 100644
--- a/main/src/cgeo/geocaching/VisitCacheActivity.java
+++ b/main/src/cgeo/geocaching/VisitCacheActivity.java
@@ -15,6 +15,7 @@ import cgeo.geocaching.ui.DateDialog;
import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.LogTemplateProvider;
+import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import cgeo.geocaching.utils.LogTemplateProvider.LogTemplate;
import org.apache.commons.collections.CollectionUtils;
@@ -143,8 +144,7 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
inventoryView.addView(inventoryItem);
- if (Settings.isTrackableAutoVisit())
- {
+ if (Settings.isTrackableAutoVisit()) {
tb.action = LogTypeTrackable.VISITED;
tbChanged = true;
}
@@ -267,8 +267,6 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode().toUpperCase());
}
- app.setAction(geocode);
-
init();
}
@@ -332,7 +330,8 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
final int id = item.getItemId();
if (id == MENU_SIGNATURE) {
- insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), false), true);
+ final LogContext logContext = new LogContext(cache);
+ insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), logContext), true);
return true;
}
@@ -347,7 +346,8 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
final LogTemplate template = LogTemplateProvider.getTemplate(id);
if (template != null) {
- insertIntoLog(template.getValue(false), true);
+ final LogContext logContext = new LogContext(cache);
+ insertIntoLog(template.getValue(logContext), true);
return true;
}
@@ -466,9 +466,6 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
}
public void init() {
- if (geocode != null) {
- app.setAction(geocode);
- }
postButton = (Button) findViewById(R.id.post);
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
tweetCheck = (CheckBox) findViewById(R.id.tweet);
@@ -486,7 +483,7 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D
} else if (StringUtils.isNotBlank(Settings.getSignature())
&& Settings.isAutoInsertSignature()
&& StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) {
- insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), false), false);
+ insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache)), false);
}
if (!possibleLogTypes.contains(typeSelected)) {
diff --git a/main/src/cgeo/geocaching/apps/AbstractApp.java b/main/src/cgeo/geocaching/apps/AbstractApp.java
index 5bed2d9..678b98c 100644
--- a/main/src/cgeo/geocaching/apps/AbstractApp.java
+++ b/main/src/cgeo/geocaching/apps/AbstractApp.java
@@ -3,9 +3,9 @@ package cgeo.geocaching.apps;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgeo;
import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.utils.ProcessUtils;
import android.content.Intent;
-import android.content.pm.PackageManager;
public abstract class AbstractApp implements App {
@@ -24,28 +24,18 @@ public abstract class AbstractApp implements App {
this(name, intent, null);
}
- protected Intent getLaunchIntent() {
- if (packageName == null) {
- return null;
- }
- final PackageManager packageManager = cgeoapplication.getInstance().getPackageManager();
- try {
- // This can throw an exception where the exception type is only defined on API Level > 3
- // therefore surround with try-catch
- return packageManager.getLaunchIntentForPackage(packageName);
- } catch (Exception e) {
- return null;
- }
- }
-
@Override
public boolean isInstalled() {
- if (getLaunchIntent() != null) {
+ if (ProcessUtils.isInstalled(packageName)) {
return true;
}
return cgeo.isIntentAvailable(intent);
}
+ protected Intent getLaunchIntent() {
+ return ProcessUtils.getLaunchIntent(packageName);
+ }
+
@Override
public boolean isDefaultNavigationApp() {
return true;
diff --git a/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java b/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java
new file mode 100644
index 0000000..6e7cdca
--- /dev/null
+++ b/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java
@@ -0,0 +1,21 @@
+package cgeo.geocaching.apps.cache;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.enumerations.CacheAttribute;
+
+public class CacheBeaconApp extends AbstractGeneralApp {
+
+ protected CacheBeaconApp() {
+ super(getString(R.string.cache_menu_cachebeacon), "de.fun2code.android.cachebeacon");
+ }
+
+ @Override
+ public boolean isEnabled(cgCache cache) {
+ if (cache == null) {
+ return false;
+ }
+ return cache.hasAttribute(CacheAttribute.WIRELESS_BEACON, true);
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
index 98e7db8..57eb957 100644
--- a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
+++ b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
@@ -15,8 +15,11 @@ public final class GeneralAppsFactory extends AbstractAppFactory {
private static GeneralApp[] getGeneralApps() {
if (ArrayUtils.isEmpty(apps)) {
- apps = new GeneralApp[] { new GccApp(),
- new WhereYouGoApp() };
+ apps = new GeneralApp[] {
+ new CacheBeaconApp(),
+ new GccApp(),
+ new WhereYouGoApp()
+ };
}
return apps;
}
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index b8590e5..d22999d 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -10,9 +10,11 @@ import cgeo.geocaching.connector.capability.ISearchByGeocode;
import cgeo.geocaching.connector.gc.GCConnector;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.connector.gc.Tile;
+import cgeo.geocaching.enumerations.CacheAttribute;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.enumerations.LoadFlags.LoadFlag;
import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
@@ -22,6 +24,7 @@ import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.LogTemplateProvider;
+import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -407,7 +410,7 @@ public class cgCache implements ICache, IWaypoint {
public void logOffline(final Activity fromActivity, final LogType logType) {
final boolean mustIncludeSignature = StringUtils.isNotBlank(Settings.getSignature()) && Settings.isAutoInsertSignature();
- final String initial = mustIncludeSignature ? LogTemplateProvider.applyTemplates(Settings.getSignature(), true) : "";
+ final String initial = mustIncludeSignature ? LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(this, true)) : "";
logOffline(fromActivity, initial, Calendar.getInstance(), logType);
}
@@ -1591,4 +1594,21 @@ public class cgCache implements ICache, IWaypoint {
}
return null;
}
+
+ /**
+ * check whether the cache has a given attribute
+ *
+ * @param attribute
+ * @param yes
+ * true if we are looking for the attribute_yes version, false for the attribute_no version
+ * @return
+ */
+ public boolean hasAttribute(CacheAttribute attribute, boolean yes) {
+ // lazy loading of attributes
+ cgCache fullCache = cgeoapplication.getInstance().loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES));
+ if (fullCache == null) {
+ fullCache = this;
+ }
+ return fullCache.getAttributes().contains(attribute.getAttributeName(yes));
+ }
} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index 5bf728f..c80ec6f 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -248,8 +248,6 @@ public class cgeo extends AbstractActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- app.setAction(null);
-
setContentView(R.layout.main);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); // type to search
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index 137fe30..9c63555 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -36,7 +36,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class cgeoapplication extends Application {
final private cgData storage = new cgData();
- private String action = null;
private volatile GeoDataProvider geo;
private volatile DirectionProvider dir;
public boolean firstRun = true; // c:geo is just launched
@@ -368,25 +367,6 @@ public class cgeoapplication extends Application {
return storage.loadWaypoint(id);
}
- /**
- * set the current action to be reported to Go4Cache (if enabled in settings)<br>
- * this might be either
- * <ul>
- * <li>geocode</li>
- * <li>name of a cache</li>
- * <li>action like twittering</li>
- * </ul>
- *
- * @param action
- */
- public void setAction(String action) {
- this.action = action;
- }
-
- public String getAction() {
- return StringUtils.defaultString(action);
- }
-
/** {@link cgData#saveLogOffline(String, Date, LogType, String)} */
public boolean saveLogOffline(String geocode, Date date, LogType logtype, String log) {
return storage.saveLogOffline(geocode, date, logtype, log);
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index 580e4b7..654927a 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -431,8 +431,6 @@ public class cgeocaches extends AbstractListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- app.setAction(action);
-
setTheme();
setContentView(R.layout.caches);
@@ -1367,18 +1365,15 @@ public class cgeocaches extends AbstractListActivity {
final private Handler handler;
final private int listIdLD;
private volatile boolean needToStop = false;
- private int checked = 0;
private long last = 0L;
+ final private List<cgCache> selected;
public LoadDetailsThread(Handler handlerIn, int listId) {
handler = handlerIn;
+ selected = adapter.getCheckedOrAllCaches();
// in case of online lists, set the list id to the standard list
this.listIdLD = Math.max(listId, StoredList.STANDARD_LIST_ID);
-
- if (adapter != null) {
- checked = adapter.getCheckedCount();
- }
}
public void kill() {
@@ -1389,55 +1384,75 @@ public class cgeocaches extends AbstractListActivity {
public void run() {
removeGeoAndDir();
- final List<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
- for (cgCache cache : cacheListTemp) {
- if (checked > 0 && !cache.isStatusChecked()) {
- handler.sendEmptyMessage(0);
-
- yield();
+ final List<cgCache> cachesWithStaticMaps = new ArrayList<cgCache>(selected.size());
+ for (cgCache cache : selected) {
+ if (Settings.isStoreOfflineMaps() && StaticMapsProvider.hasStaticMapForCache(cache.getGeocode())) {
+ cachesWithStaticMaps.add(cache);
continue;
}
+ if (!refreshCache(cache)) {
+ // in case of interruption avoid the second loop
+ cachesWithStaticMaps.clear();
+ break;
+ }
+ }
- try {
- if (needToStop) {
- Log.i("Stopped storing process.");
- break;
- }
+ for (cgCache cache : cachesWithStaticMaps) {
+ if (!refreshCache(cache)) {
+ break;
+ }
+ }
- if ((System.currentTimeMillis() - last) < 1500) {
- try {
- int delay = 1000 + ((Double) (Math.random() * 1000)).intValue() - (int) (System.currentTimeMillis() - last);
- if (delay < 0) {
- delay = 500;
- }
+ handler.sendEmptyMessage(MSG_RESTART_GEO_AND_DIR);
+ handler.sendEmptyMessage(MSG_DONE);
+ }
- Log.i("Waiting for next cache " + delay + " ms");
- } catch (Exception e) {
- Log.e("cgeocaches.LoadDetailsThread.sleep: " + e.toString());
+ /**
+ * Refreshes the cache information.
+ *
+ * @param cache
+ * The cache to refresh
+ * @return
+ * <code>false</code> if the storing was interrupted, <code>true</code> otherwise
+ */
+ private boolean refreshCache(cgCache cache) {
+ try {
+ if (needToStop) {
+ throw new InterruptedException("Stopped storing process.");
+ }
+
+ if ((System.currentTimeMillis() - last) < 1500) {
+ try {
+ int delay = 1000 + ((Double) (Math.random() * 1000)).intValue() - (int) (System.currentTimeMillis() - last);
+ if (delay < 0) {
+ delay = 500;
}
- }
- if (needToStop) {
- Log.i("Stopped storing process.");
- break;
+ Log.i("Waiting for next cache " + delay + " ms");
+ } catch (Exception e) {
+ Log.e("cgeocaches.LoadDetailsThread.sleep: " + e.toString());
}
+ }
- detailProgress++;
- cache.refresh(listIdLD, null);
+ if (needToStop) {
+ throw new InterruptedException("Stopped storing process.");
+ }
- handler.sendEmptyMessage(cacheList.indexOf(cache));
+ detailProgress++;
+ cache.refresh(listIdLD, null);
- yield();
- } catch (Exception e) {
- Log.e("cgeocaches.LoadDetailsThread: " + e.toString());
- }
+ handler.sendEmptyMessage(cacheList.indexOf(cache));
- last = System.currentTimeMillis();
+ yield();
+ } catch (InterruptedException e) {
+ Log.i(e.getMessage());
+ return false;
+ } catch (Exception e) {
+ Log.e("cgeocaches.LoadDetailsThread: " + e.toString());
}
- cacheListTemp.clear();
- handler.sendEmptyMessage(MSG_RESTART_GEO_AND_DIR);
- handler.sendEmptyMessage(MSG_DONE);
+ last = System.currentTimeMillis();
+ return true;
}
}
diff --git a/main/src/cgeo/geocaching/cgeogpxes.java b/main/src/cgeo/geocaching/cgeogpxes.java
index 205ee59..15c96fa 100644
--- a/main/src/cgeo/geocaching/cgeogpxes.java
+++ b/main/src/cgeo/geocaching/cgeogpxes.java
@@ -11,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
-import android.os.Environment;
import java.io.File;
import java.util.List;
@@ -32,7 +31,8 @@ public class cgeogpxes extends FileList<GPXListAdapter> {
@Override
protected File[] getBaseFolders() {
- return new File[] { new File(Environment.getExternalStorageDirectory(), "gpx") };
+ String gpxImportDir = Settings.getGpxImportDir();
+ return new File[] { new File(gpxImportDir) };
}
@Override
diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java
index 53470b3..c308356 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -84,8 +84,6 @@ public class cgeonavigate extends AbstractActivity {
return;
}
- setGo4CacheAction();
-
// set header
setTitle();
setDestCoords();
@@ -99,8 +97,6 @@ public class cgeonavigate extends AbstractActivity {
public void onResume() {
super.onResume();
- setGo4CacheAction();
-
// sensor & geolocation manager
geoDirHandler.startGeoAndDir();
@@ -110,14 +106,6 @@ public class cgeonavigate extends AbstractActivity {
}
}
- private void setGo4CacheAction() {
- if (StringUtils.isNotBlank(geocode)) {
- app.setAction(geocode);
- } else if (StringUtils.isNotBlank(name)) {
- app.setAction(name);
- }
- }
-
@Override
public void onPause() {
geoDirHandler.stopGeoAndDir();
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java
index acd351d..3cdc58d 100644
--- a/main/src/cgeo/geocaching/cgeotrackable.java
+++ b/main/src/cgeo/geocaching/cgeotrackable.java
@@ -395,7 +395,7 @@ public class cgeotrackable extends AbstractActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- menu.findItem(MENU_LOG_TOUCH).setEnabled(trackable.isLoggable());
+ menu.findItem(MENU_LOG_TOUCH).setEnabled(StringUtils.isNotBlank(geocode) && trackable.isLoggable());
menu.findItem(MENU_BROWSER_TRACKABLE).setEnabled(StringUtils.isNotBlank(trackable.getUrl()));
return super.onPrepareOptionsMenu(menu);
}
diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java
index 784a54e..6b3afe9 100644
--- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java
+++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java
@@ -50,7 +50,9 @@ public final class ConnectorFactory {
return getConnector(cache.getGeocode());
}
- public static IConnector getConnector(String geocode) {
+ public static IConnector getConnector(final String geocodeInput) {
+ // this may come from user input
+ final String geocode = StringUtils.trim(geocodeInput);
if (isInvalidGeocode(geocode)) {
return UNKNOWN_CONNECTOR;
}
diff --git a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java
index 6456f71..a31b0cc 100644
--- a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java
+++ b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java
@@ -137,4 +137,8 @@ public enum CacheAttribute {
public static boolean isEnabled(final String attributeName) {
return !StringUtils.endsWithIgnoreCase(attributeName, INTERNAL_NO);
}
+
+ public String getAttributeName(final boolean yes) {
+ return gcRawName + (yes ? INTERNAL_YES : INTERNAL_NO);
+ }
}
diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java
index 8af85a8..6aa46e6 100644
--- a/main/src/cgeo/geocaching/export/GpxExport.java
+++ b/main/src/cgeo/geocaching/export/GpxExport.java
@@ -15,6 +15,7 @@ import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.app.AlertDialog;
@@ -153,9 +154,12 @@ class GpxExport extends AbstractExport {
gpx.write(Double.toString(cache.getCoords().getLongitude()));
gpx.write("\">");
- gpx.write("<time>");
- gpx.write(StringEscapeUtils.escapeXml(dateFormatZ.format(cache.getHiddenDate())));
- gpx.write("</time>");
+ final Date hiddenDate = cache.getHiddenDate();
+ if (hiddenDate != null) {
+ gpx.write("<time>");
+ gpx.write(StringEscapeUtils.escapeXml(dateFormatZ.format(hiddenDate)));
+ gpx.write("</time>");
+ }
gpx.write("<name>");
gpx.write(StringEscapeUtils.escapeXml(cache.getGeocode()));
@@ -228,21 +232,13 @@ class GpxExport extends AbstractExport {
gpx.write("<groundspeak:state></groundspeak:state>"); // c:geo cannot manage 2 separate fields, so we export as country
gpx.write("<groundspeak:short_description html=\"");
- if (BaseUtils.containsHtml(cache.getShortDescription())) {
- gpx.write("True");
- } else {
- gpx.write("False");
- }
+ gpx.write(BaseUtils.containsHtml(cache.getShortDescription()) ? "True" : "False");
gpx.write("\">");
gpx.write(StringEscapeUtils.escapeXml(cache.getShortDescription()));
gpx.write("</groundspeak:short_description>");
gpx.write("<groundspeak:long_description html=\"");
- if (BaseUtils.containsHtml(cache.getDescription())) {
- gpx.write("True");
- } else {
- gpx.write("False");
- }
+ gpx.write(BaseUtils.containsHtml(cache.getDescription()) ? "True" : "False");
gpx.write("\">");
gpx.write(StringEscapeUtils.escapeXml(cache.getDescription()));
gpx.write("</groundspeak:long_description>");
@@ -309,10 +305,7 @@ class GpxExport extends AbstractExport {
}
for (cgWaypoint wp : ownWaypoints) {
maxPrefix++;
- String prefix = String.valueOf(maxPrefix);
- if (prefix.length() == 1) {
- prefix = "0" + prefix;
- }
+ String prefix = StringUtils.leftPad(String.valueOf(maxPrefix), 2, '0');
writeCacheWaypoint(wp, prefix);
}
}
diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java
index 57cbc0c..c5ebb9b 100644
--- a/main/src/cgeo/geocaching/files/SimpleDirChooser.java
+++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java
@@ -1,6 +1,3 @@
-/**
- *
- */
package cgeo.geocaching.files;
import cgeo.geocaching.R;
@@ -10,6 +7,7 @@ import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -31,6 +29,7 @@ import java.util.List;
* Dialog for choosing a file or directory.
*/
public class SimpleDirChooser extends ListActivity {
+ public static final String EXTRA_CHOSEN_DIR = "chosenDir";
public static final String START_DIR = "start_dir";
private static final String PARENT_DIR = ".. ";
private File currentDir;
@@ -45,7 +44,7 @@ public class SimpleDirChooser extends ListActivity {
final Bundle extras = getIntent().getExtras();
String startDir = extras.getString(START_DIR);
if (startDir == null) {
- startDir = "/sdcard";
+ startDir = Environment.getExternalStorageDirectory().getPath();
} else {
startDir = startDir.substring(0, startDir.lastIndexOf(File.separatorChar));
}
@@ -65,7 +64,7 @@ public class SimpleDirChooser extends ListActivity {
public void onClick(View v) {
Intent intent = new Intent();
String chosenDirName = File.separator + checkedText;
- intent.putExtra("chosenDir", currentDir.getAbsolutePath() + chosenDirName);
+ intent.putExtra(EXTRA_CHOSEN_DIR, currentDir.getAbsolutePath() + chosenDirName);
setResult(RESULT_OK, intent);
finish();
}
@@ -108,40 +107,40 @@ public class SimpleDirChooser extends ListActivity {
public class FileArrayAdapter extends ArrayAdapter<Option> {
- private Context c;
+ private Context content;
private int id;
private List<Option> items;
public FileArrayAdapter(Context context, int simpleDirItemResId, List<Option> objects) {
super(context, simpleDirItemResId, objects);
- c = context;
- id = simpleDirItemResId;
- items = objects;
+ this.content = context;
+ this.id = simpleDirItemResId;
+ this.items = objects;
}
@Override
- public Option getItem(int i) {
- return items.get(i);
+ public Option getItem(int index) {
+ return items.get(index);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
- LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LayoutInflater vi = (LayoutInflater) content.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, null);
}
- final Option o = items.get(position);
- if (o != null) {
+ final Option option = items.get(position);
+ if (option != null) {
TextView t1 = (TextView) v.findViewById(R.id.TextView01);
if (t1 != null) {
t1.setOnClickListener(new OnTextViewClickListener(position));
- t1.setText(o.getName());
+ t1.setText(option.getName());
}
CheckBox check = (CheckBox) v.findViewById(R.id.CheckBox);
if (check != null) {
- check.setOnClickListener(new OnCheckBoxClickListener(o.getName()));
+ check.setOnClickListener(new OnCheckBoxClickListener(option.getName()));
}
}
return v;
@@ -157,12 +156,12 @@ public class SimpleDirChooser extends ListActivity {
@Override
public void onClick(View arg0) {
- Option o = adapter.getItem(position);
- if (o.getName().equals(PARENT_DIR)) {
- currentDir = new File(o.getPath());
+ Option option = adapter.getItem(position);
+ if (option.getName().equals(PARENT_DIR)) {
+ currentDir = new File(option.getPath());
fill(currentDir);
} else {
- File dir = new File(o.getPath());
+ File dir = new File(option.getPath());
if (dir.list(new DirOnlyFilenameFilter()).length > 0) {
currentDir = dir;
fill(currentDir);
@@ -201,12 +200,12 @@ public class SimpleDirChooser extends ListActivity {
}
public class Option implements Comparable<Option> {
- private String name;
- private String path;
+ private final String name;
+ private final String path;
- public Option(String n, String p) {
- name = n;
- path = p;
+ public Option(String name, String path) {
+ this.name = name;
+ this.path = path;
}
public String getName() {
@@ -218,9 +217,9 @@ public class SimpleDirChooser extends ListActivity {
}
@Override
- public int compareTo(Option o) {
- if (o != null && this.name != null) {
- return this.name.toLowerCase().compareTo(o.getName().toLowerCase());
+ public int compareTo(Option other) {
+ if (other != null && this.name != null) {
+ return String.CASE_INSENSITIVE_ORDER.compare(this.name, other.getName());
}
throw new IllegalArgumentException("");
}
diff --git a/main/src/cgeo/geocaching/go4cache/Go4Cache.java b/main/src/cgeo/geocaching/go4cache/Go4Cache.java
deleted file mode 100644
index 131faa4..0000000
--- a/main/src/cgeo/geocaching/go4cache/Go4Cache.java
+++ /dev/null
@@ -1,173 +0,0 @@
-package cgeo.geocaching.go4cache;
-
-import cgeo.geocaching.Settings;
-import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.GeopointFormatter.Format;
-import cgeo.geocaching.geopoint.Viewport;
-import cgeo.geocaching.network.Network;
-import cgeo.geocaching.network.Parameters;
-import cgeo.geocaching.utils.CryptUtils;
-import cgeo.geocaching.utils.Log;
-import cgeo.geocaching.utils.Version;
-
-import org.apache.commons.lang3.StringUtils;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
-
-/**
- *
- * Thread to send location information to go4cache.com. The singleton will be created
- * only if, at any time, the user opts in to send this information. Then the same thread
- * will take care of sending updated positions when available.
- *
- */
-
-public final class Go4Cache extends Thread {
-
- private static class InstanceHolder { // initialization on demand holder
- private static final Go4Cache INSTANCE = new Go4Cache();
- }
-
- private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2010-07-25 14:44:01
- final private ArrayBlockingQueue<Geopoint> queue = new ArrayBlockingQueue<Geopoint>(1);
-
- public static Go4Cache getInstance() { // no need to be synchronized
- return InstanceHolder.INSTANCE;
- }
-
- private Go4Cache() { // private singleton constructor
- super("Go4Cache");
- setPriority(Thread.MIN_PRIORITY);
- start();
- }
-
- /**
- * Send the coordinates to go4cache.com if the user opted in to do so.
- *
- * @param coords
- * the current coordinates
- */
- public static void signalCoordinates(final Geopoint coords) {
- if (Settings.isPublicLoc()) {
- getInstance().queue.offer(coords);
- }
- }
-
- @Override
- public void run() {
- Log.d("Go4Cache task started");
- Geopoint latestCoords = null;
- String latestAction = null;
-
- try {
- for (;;) {
- final Geopoint currentCoords = queue.take();
- final String currentAction = cgeoapplication.getInstance().getAction();
-
- // If we are too close and we haven't changed our current action, no need
- // to update our situation.
- if (null != latestCoords && latestCoords.distanceTo(currentCoords) < 0.75 && StringUtils.equals(latestAction, currentAction)) {
- continue;
- }
-
- final String username = Settings.getUsername();
- if (StringUtils.isBlank(username)) {
- continue;
- }
-
- final String latStr = currentCoords.format(Format.LAT_DECDEGREE_RAW);
- final String lonStr = currentCoords.format(Format.LON_DECDEGREE_RAW);
- final Parameters params = new Parameters(
- "u", username,
- "lt", latStr,
- "ln", lonStr,
- "a", currentAction,
- "s", (CryptUtils.sha1(username + "|" + latStr + "|" + lonStr + "|" + currentAction + "|" + CryptUtils.md5("carnero: developing your dreams"))).toLowerCase(),
- "v", Version.getVersionName(cgeoapplication.getInstance()));
-
- Network.postRequest("http://api.go4cache.com/", params);
-
- // Update our coordinates even if the request was not successful, as not to hammer the server
- // with invalid requests for every new GPS position.
- latestCoords = currentCoords;
- latestAction = currentAction;
- }
- } catch (InterruptedException e) {
- Log.e("Go4Cache.run: interrupted", e);
- }
- }
-
- /**
- * Return an immutable list of users present in the given viewport.
- *
- * @param username
- * the current username
- * @param viewport
- * the current viewport
- * @return the list of users present in the viewport
- */
- public static List<Go4CacheUser> getGeocachersInViewport(final String username, final Viewport viewport) {
- final List<Go4CacheUser> users = new ArrayList<Go4CacheUser>();
-
- if (null == username) {
- return users;
- }
-
- final Parameters params = new Parameters(
- "u", username,
- "ltm", viewport.bottomLeft.format(Format.LAT_DECDEGREE_RAW),
- "ltx", viewport.topRight.format(Format.LAT_DECDEGREE_RAW),
- "lnm", viewport.bottomLeft.format(Format.LON_DECDEGREE_RAW),
- "lnx", viewport.topRight.format(Format.LON_DECDEGREE_RAW));
-
- final String data = Network.getResponseData(Network.postRequest("http://api.go4cache.com/get.php", params));
-
- if (StringUtils.isBlank(data)) {
- Log.e("Go4Cache.getGeocachersInViewport: No data from server");
- return null;
- }
-
- try {
- final JSONArray usersData = new JSONObject(data).getJSONArray("users");
- final int count = usersData.length();
- for (int i = 0; i < count; i++) {
- final JSONObject oneUser = usersData.getJSONObject(i);
- users.add(parseUser(oneUser));
- }
- } catch (Exception e) {
- Log.e("cgBase.getGeocachersInViewport: " + e.toString());
- }
-
- return Collections.unmodifiableList(users);
- }
-
- /**
- * Parse user information from go4cache.com.
- *
- * @param user
- * a JSON object
- * @return a cgCache user filled with information
- * @throws JSONException
- * if JSON could not be parsed correctly
- * @throws ParseException
- * if the date could not be parsed as expected
- */
- private static Go4CacheUser parseUser(final JSONObject user) throws JSONException, ParseException {
- final Date date = dateFormat.parse(user.getString("located"));
- final String username = user.getString("user");
- final Geopoint coords = new Geopoint(user.getDouble("latitude"), user.getDouble("longitude"));
- final String action = user.getString("action");
- final String client = user.getString("client");
- return new Go4CacheUser(username, coords, date, action, client);
- }
-}
diff --git a/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java
deleted file mode 100644
index 08fd02e..0000000
--- a/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package cgeo.geocaching.go4cache;
-
-import cgeo.geocaching.R;
-import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.geopoint.Geopoint;
-
-import android.content.res.Resources;
-
-import java.util.Date;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class Go4CacheUser {
- private static final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE);
-
- private final Date date;
- private final String username;
- private final Geopoint coords;
- private final String action;
- private final String client;
-
- private String actionForDisplay;
- private String geocode;
- private Resources res;
-
- public Go4CacheUser(final String username, final Geopoint coords, final Date date, final String action, final String client) {
- this.username = username;
- this.coords = coords;
- this.date = new Date(date.getTime());
- this.action = action;
- this.client = client;
- }
-
- public Date getDate() {
- return date;
- }
-
- public String getUsername() {
- return username;
- }
-
- public Geopoint getCoords() {
- return coords;
- }
-
- public int getIconId() {
- if (client == null) {
- return -1;
- }
- if (client.equalsIgnoreCase("c:geo")) {
- return R.drawable.client_cgeo;
- }
- if (client.equalsIgnoreCase("preCaching")) {
- return R.drawable.client_precaching;
- }
- if (client.equalsIgnoreCase("Handy Geocaching")) {
- return R.drawable.client_handygeocaching;
- }
- return -1;
- }
-
- private void getGeocodeAndAction() {
- final Matcher matcherGeocode = patternGeocode.matcher(action.trim());
- res = cgeoapplication.getInstance().getResources();
-
- geocode = "";
- if (0 == action.length() || action.equalsIgnoreCase("pending")) {
- actionForDisplay = res.getString(R.string.go4cache_looking_around);
- } else if (action.equalsIgnoreCase("tweeting")) {
- actionForDisplay = res.getString(R.string.go4cache_tweeting);
- } else if (matcherGeocode.find()) {
- if (null != matcherGeocode.group(1)) {
- geocode = matcherGeocode.group(1).trim().toUpperCase();
- }
- if (null != matcherGeocode.group(3)) {
- actionForDisplay = res.getString(R.string.go4cache_heading_to) + " " + geocode + " (" + matcherGeocode.group(3).trim() + ")";
- } else {
- actionForDisplay = res.getString(R.string.go4cache_heading_to) + " " + geocode;
- }
- } else {
- actionForDisplay = action;
- }
- }
-
- public String getAction() {
- if (null == actionForDisplay) {
- getGeocodeAndAction();
- }
- return actionForDisplay + getTime() + ".";
- }
-
- private String getTime() {
- int minutes = (int) ((System.currentTimeMillis() - date.getTime()) / 60000);
- if (minutes < 0) {
- minutes = 0;
- }
- return " (" + res.getQuantityString(R.plurals.go4cache_time_minutes, minutes, minutes) + ")";
- }
-
- public String getGeocode() {
- if (null == geocode) {
- getGeocodeAndAction();
- }
- return geocode;
- }
-} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index c4d2192..aa9ed1b 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -22,8 +22,6 @@ import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
-import cgeo.geocaching.go4cache.Go4Cache;
-import cgeo.geocaching.go4cache.Go4CacheUser;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapActivityImpl;
@@ -33,7 +31,6 @@ import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapSource;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnMapDragListener;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.GeoDirHandler;
@@ -151,21 +148,16 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// map status data
private boolean followMyLocation = false;
private Viewport viewport = null;
- private Viewport viewportUsers = null;
private int zoom = -100;
// threads
private LoadTimer loadTimer = null;
- private Go4CacheTimer go4CacheTimer = null;
private LoadDetails loadDetailsThread = null;
/** Time of last {@link LoadRunnable} run */
private volatile long loadThreadRun = 0L;
- /** Time of last {@link Go4CacheRunnable} run */
- private volatile long go4CacheThreadRun = 0L;
//Interthread communication flag
private volatile boolean downloaded = false;
// overlays
private CachesOverlay overlayCaches = null;
- private OtherCachersOverlay overlayGo4Cache = null;
private ScaleOverlay overlayScale = null;
private PositionOverlay overlayPosition = null;
// data for overlays
@@ -206,10 +198,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private static ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
private static BlockingQueue<Runnable> loadQueue = new ArrayBlockingQueue<Runnable>(1);
private static ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
- private static BlockingQueue<Runnable> Go4CacheQueue = new ArrayBlockingQueue<Runnable>(1);
- private static ThreadPoolExecutor Go4CacheExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, Go4CacheQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
- 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 */
@@ -389,6 +377,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
waypointTypeIntent = WaypointType.findById(extras.getString(EXTRAS_WPTTYPE));
mapStateIntent = extras.getIntArray(EXTRAS_MAPSTATE);
mapTitle = extras.getString(EXTRAS_MAP_TITLE);
+
+ Settings.setLiveMap(mapMode == MapMode.LIVE_ONLINE ? true : false);
}
else {
mapMode = Settings.isLiveMap() ? MapMode.LIVE_ONLINE : MapMode.LIVE_OFFLINE;
@@ -431,10 +421,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// initialize overlays
mapView.clearOverlays();
- if (Settings.isPublicLoc() && overlayGo4Cache == null) {
- overlayGo4Cache = mapView.createAddUsersOverlay(activity, getResources().getDrawable(R.drawable.user_location));
- }
-
if (overlayCaches == null) {
overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker));
}
@@ -496,8 +482,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
public void onResume() {
super.onResume();
- app.setAction(StringUtils.defaultIfBlank(geocodeIntent, null));
-
addGeoDirObservers();
if (!CollectionUtils.isEmpty(dirtyCaches)) {
@@ -530,11 +514,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
loadTimer = null;
}
- if (go4CacheTimer != null) {
- go4CacheTimer.stopIt();
- go4CacheTimer = null;
- }
-
deleteGeoDirObservers();
savePrefs();
@@ -973,7 +952,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
/**
- * Starts the {@link LoadTimer} and {@link Go4CacheTimer}.
+ * Starts the {@link LoadTimer}.
*/
public synchronized void startTimer() {
@@ -989,15 +968,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
loadTimer = new LoadTimer();
loadTimer.start();
}
-
- if (Settings.isPublicLoc()) {
- if (go4CacheTimer != null) {
- go4CacheTimer.stopIt();
- go4CacheTimer = null;
- }
- go4CacheTimer = new Go4CacheTimer();
- go4CacheTimer.start();
- }
}
/**
@@ -1080,60 +1050,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
/**
- * Timer triggering every 250 ms to start the {@link Go4CacheRunnable} for displaying user.
- */
-
- private class Go4CacheTimer extends Thread {
-
- public Go4CacheTimer() {
- super("Users Timer");
- }
-
- private volatile boolean stop = false;
-
- public void stopIt() {
- stop = true;
- }
-
- @Override
- public void run() {
- while (!stop) {
- try {
- sleep(250);
-
- if (mapView != null) {
- // get current viewport
- final Viewport viewportNow = mapView.getViewport();
-
- // check if map moved or zoomed
- boolean moved = false;
-
- long currentTime = System.currentTimeMillis();
-
- if (60000 < (currentTime - go4CacheThreadRun)) {
- moved = true;
- } else if (viewportUsers == null) {
- moved = true;
- } else if (mapMoved(viewportUsers, viewportNow) && !viewportUsers.includes(viewportNow)) {
- moved = true;
- }
-
- // save new values
- if (moved && (1000 < (currentTime - go4CacheThreadRun))) {
- viewportUsers = viewportNow;
- Go4CacheExecutor.execute(new Go4CacheRunnable(viewportUsers));
- }
- }
-
- yield();
- } catch (Exception e) {
- Log.w("cgeomap.LoadUsersTimer.run: " + e.toString());
- }
- }
- }
- }
-
- /**
* Worker thread that loads caches and waypoints from the database and then spawns the {@link DownloadRunnable}.
* started by {@link LoadTimer}
*/
@@ -1215,7 +1131,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
/**
* Worker thread downloading caches from the internet.
- * Started by {@link LoadRunnable}. Duplicate Code with {@link Go4CacheRunnable}
+ * Started by {@link LoadRunnable}.
*/
private class DownloadRunnable extends DoRunnable {
@@ -1335,66 +1251,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
}
- /**
- * Thread to load users from Go 4 Cache
- */
-
- private class Go4CacheRunnable extends DoRunnable {
-
- public Go4CacheRunnable(final Viewport viewport) {
- super(viewport);
- }
-
- @Override
- public void run() {
- go4CacheThreadRun = System.currentTimeMillis();
- List<Go4CacheUser> go4CacheUsers = Go4Cache.getGeocachersInViewport(Settings.getUsername(), viewport.resize(1.5));
- go4CacheDisplayExecutor.execute(new Go4CacheDisplayRunnable(go4CacheUsers, viewport));
- }
- }
-
- /**
- * Thread to display users of Go 4 Cache started from {@link Go4CacheRunnable}
- */
- private class Go4CacheDisplayRunnable extends DoRunnable {
-
- private List<Go4CacheUser> users = null;
-
- public Go4CacheDisplayRunnable(List<Go4CacheUser> usersIn, final Viewport viewport) {
- super(viewport);
- users = usersIn;
- }
-
- @Override
- public void run() {
- if (mapView == null || CollectionUtils.isEmpty(users)) {
- return;
- }
-
- // display users
- List<OtherCachersOverlayItemImpl> items = new ArrayList<OtherCachersOverlayItemImpl>();
-
- int counter = 0;
- OtherCachersOverlayItemImpl item;
-
- for (Go4CacheUser userOne : users) {
- if (userOne.getCoords() == null) {
- continue;
- }
-
- item = mapItemFactory.getOtherCachersOverlayItemBase(activity, userOne);
- items.add(item);
-
- counter++;
- if ((counter % 10) == 0) {
- overlayGo4Cache.updateItems(items);
- displayHandler.sendEmptyMessage(INVALIDATE_MAP);
- }
- }
-
- overlayGo4Cache.updateItems(items);
- }
- }
/**
* Thread to display one point. Started on opening if in single mode.
diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java
deleted file mode 100644
index f8e4e17..0000000
--- a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package cgeo.geocaching.maps;
-
-import cgeo.geocaching.CacheDetailActivity;
-import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.go4cache.Go4CacheUser;
-import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
-import cgeo.geocaching.maps.interfaces.MapViewImpl;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-import cgeo.geocaching.utils.Log;
-
-import org.apache.commons.lang3.StringUtils;
-
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.graphics.Canvas;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class OtherCachersOverlay extends AbstractItemizedOverlay {
-
- private List<OtherCachersOverlayItemImpl> items = new ArrayList<OtherCachersOverlayItemImpl>();
- private Context context = null;
-
- public OtherCachersOverlay(ItemizedOverlayImpl ovlImplIn, Context contextIn) {
- super(ovlImplIn);
- populate();
-
- context = contextIn;
- }
-
- protected void updateItems(OtherCachersOverlayItemImpl item) {
- final List<OtherCachersOverlayItemImpl> itemsPre = new ArrayList<OtherCachersOverlayItemImpl>();
- itemsPre.add(item);
-
- updateItems(itemsPre);
- }
-
- public void updateItems(List<OtherCachersOverlayItemImpl> itemsPre) {
- if (itemsPre == null) {
- return;
- }
-
- for (OtherCachersOverlayItemImpl item : itemsPre) {
- item.setMarker(boundCenter(item.getMarker(0)));
- }
-
- items.clear();
-
- if (itemsPre.size() > 0) {
- items = new ArrayList<OtherCachersOverlayItemImpl>(itemsPre);
- }
-
- setLastFocusedItemIndex(-1); // to reset tap during data change
- populate();
- }
-
- @Override
- public boolean onTap(int index) {
- try {
- if (items.size() <= index) {
- return false;
- }
-
- final OtherCachersOverlayItemImpl item = items.get(index);
- final Go4CacheUser user = item.getUser();
-
- final String geocode = user.getGeocode();
- final int icon = user.getIconId();
-
- final AlertDialog.Builder dialog = new AlertDialog.Builder(context);
- if (icon > -1) {
- dialog.setIcon(icon);
- }
- dialog.setTitle(user.getUsername());
- dialog.setMessage(user.getAction());
- dialog.setCancelable(true);
- if (StringUtils.isNotBlank(geocode)) {
- dialog.setPositiveButton(geocode, new cacheDetails(geocode));
- }
- dialog.setNeutralButton(cgeoapplication.getInstance().getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
-
- dialog.create().show();
-
- return true;
- } catch (Exception e) {
- Log.e("cgUsersOverlay.onTap: " + e.toString());
- }
-
- return false;
- }
-
- @Override
- public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
- super.draw(canvas, mapView, false);
- }
-
- @Override
- public OtherCachersOverlayItemImpl createItem(int index) {
- try {
- return items.get(index);
- } catch (Exception e) {
- Log.e("cgUsersOverlay.createItem: " + e.toString());
- }
-
- return null;
- }
-
- @Override
- public int size() {
- try {
- return items.size();
- } catch (Exception e) {
- Log.e("cgUsersOverlay.size: " + e.toString());
- }
-
- return 0;
- }
-
- private class cacheDetails implements DialogInterface.OnClickListener {
-
- private String geocode = null;
-
- public cacheDetails(String geocodeIn) {
- geocode = geocodeIn;
- }
-
- @Override
- public void onClick(DialogInterface dialog, int id) {
- if (geocode != null) {
- CacheDetailActivity.startActivity(context, geocode);
- }
-
- dialog.cancel();
- }
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java
deleted file mode 100644
index 9844e83..0000000
--- a/main/src/cgeo/geocaching/maps/OtherCachersOverlayItem.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package cgeo.geocaching.maps;
-
-import cgeo.geocaching.R;
-import cgeo.geocaching.go4cache.Go4CacheUser;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-public class OtherCachersOverlayItem {
- private final Context context;
- private final Go4CacheUser user;
-
- public OtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) {
- context = contextIn;
- user = userIn;
- }
-
- public Drawable getMarker() {
- Drawable marker;
-
- if (user != null && user.getDate() != null && user.getDate().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) {
- marker = context.getResources().getDrawable(R.drawable.user_location_active);
- } else {
- marker = context.getResources().getDrawable(R.drawable.user_location);
- }
-
- marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
- marker.setAlpha(190);
-
- return marker;
- }
-
- public Go4CacheUser getUser() {
- return user;
- }
-} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java b/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java
index 1a10023..f40c799 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java
@@ -3,13 +3,9 @@ package cgeo.geocaching.maps.google;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapItemFactory;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-
-import android.content.Context;
public class GoogleMapItemFactory implements MapItemFactory {
@@ -22,9 +18,4 @@ public class GoogleMapItemFactory implements MapItemFactory {
public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
return new GoogleCacheOverlayItem(coordinate, type);
}
-
- @Override
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
- return new GoogleOtherCachersOverlayItem(context, userOne);
- }
}
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
index c575177..f43b6a4 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
@@ -5,7 +5,6 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import cgeo.geocaching.Settings;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.OtherCachersOverlay;
import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
@@ -120,13 +119,6 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public OtherCachersOverlay createAddUsersOverlay(Context context, Drawable markerIn) {
- GoogleOtherCachersOverlay ovl = new GoogleOtherCachersOverlay(context, markerIn);
- getOverlays().add(ovl);
- return ovl.getBase();
- }
-
- @Override
public PositionOverlay createAddPositionOverlay(Activity activity) {
GoogleOverlay ovl = new GoogleOverlay(activity, overlayType.PositionOverlay);
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlay.java
deleted file mode 100644
index 4c330c9..0000000
--- a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlay.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package cgeo.geocaching.maps.google;
-
-import cgeo.geocaching.maps.OtherCachersOverlay;
-import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
-import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
-import cgeo.geocaching.maps.interfaces.MapViewImpl;
-
-import com.google.android.maps.ItemizedOverlay;
-import com.google.android.maps.MapView;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Point;
-import android.graphics.drawable.Drawable;
-
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-public class GoogleOtherCachersOverlay extends ItemizedOverlay<GoogleOtherCachersOverlayItem> implements ItemizedOverlayImpl {
-
- private OtherCachersOverlay base;
- private Lock lock = new ReentrantLock();
-
- public GoogleOtherCachersOverlay(Context contextIn, Drawable markerIn) {
- super(boundCenter(markerIn));
- base = new OtherCachersOverlay(this, contextIn);
- }
-
- @Override
- public OtherCachersOverlay getBase() {
- return base;
- }
-
- @Override
- protected GoogleOtherCachersOverlayItem createItem(int i) {
- if (base == null) {
- return null;
- }
-
- return (GoogleOtherCachersOverlayItem) base.createItem(i);
- }
-
- @Override
- public int size() {
- if (base == null) {
- return 0;
- }
-
- return base.size();
- }
-
- @Override
- protected boolean onTap(int arg0) {
- if (base == null) {
- return false;
- }
-
- return base.onTap(arg0);
- }
-
- @Override
- public void draw(Canvas canvas, MapView mapView, boolean shadow) {
- base.draw(canvas, (MapViewImpl) mapView, shadow);
- }
-
- @Override
- public void superPopulate() {
- populate();
- }
-
- @Override
- public Drawable superBoundCenter(Drawable markerIn) {
- return super.boundCenter(markerIn);
- }
-
- @Override
- public Drawable superBoundCenterBottom(Drawable marker) {
- return super.boundCenterBottom(marker);
- }
-
- @Override
- public void superSetLastFocusedItemIndex(int i) {
- super.setLastFocusedIndex(i);
- }
-
- @Override
- public boolean superOnTap(int index) {
- return super.onTap(index);
- }
-
- @Override
- public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
- super.draw(canvas, (MapView) mapView, shadow);
- }
-
- @Override
- public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition,
- MapProjectionImpl projection, byte drawZoomLevel) {
- // Nothing to do here
- }
-
- @Override
- public void lock() {
- lock.lock();
- }
-
- @Override
- public void unlock() {
- lock.unlock();
- }
-
- @Override
- public MapViewImpl getMapViewImpl() {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java
deleted file mode 100644
index 0e3067a..0000000
--- a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package cgeo.geocaching.maps.google;
-
-import cgeo.geocaching.go4cache.Go4CacheUser;
-import cgeo.geocaching.maps.OtherCachersOverlayItem;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-
-import com.google.android.maps.GeoPoint;
-import com.google.android.maps.OverlayItem;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl {
- final private OtherCachersOverlayItem item;
-
- public GoogleOtherCachersOverlayItem(Context context, Go4CacheUser user) {
- super(new GeoPoint(user.getCoords().getLatitudeE6(), user.getCoords().getLongitudeE6()), user.getUsername(), "");
- item = new OtherCachersOverlayItem(context, user);
- }
-
- @Override
- public Drawable getMarker(int state) {
- final Drawable marker = item.getMarker();
- setMarker(marker);
- return marker;
- }
-
- @Override
- public Go4CacheUser getUser() {
- return item.getUser();
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java
index c38739d..e02d472 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java
@@ -3,9 +3,6 @@ package cgeo.geocaching.maps.interfaces;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
-
-import android.content.Context;
public interface MapItemFactory {
@@ -13,6 +10,4 @@ public interface MapItemFactory {
public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint iWaypoint, final CacheType type);
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context,
- Go4CacheUser userOne);
}
diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
index 1bafc57..ad481cb 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
@@ -2,7 +2,6 @@ package cgeo.geocaching.maps.interfaces;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.OtherCachersOverlay;
import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.ScaleOverlay;
@@ -48,8 +47,6 @@ public interface MapViewImpl {
CachesOverlay createAddMapOverlay(Context context, Drawable drawable);
- OtherCachersOverlay createAddUsersOverlay(Context context, Drawable markerIn);
-
ScaleOverlay createAddScaleOverlay(Activity activity);
PositionOverlay createAddPositionOverlay(Activity activity);
diff --git a/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java b/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java
deleted file mode 100644
index 453c8a9..0000000
--- a/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package cgeo.geocaching.maps.interfaces;
-
-import cgeo.geocaching.go4cache.Go4CacheUser;
-
-/**
- * Common functions of the provider-specific
- * UserOverlayItem implementations
- */
-public interface OtherCachersOverlayItemImpl extends OverlayItemImpl {
-
- public Go4CacheUser getUser();
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java
index 0df7894..10fcb03 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java
@@ -3,13 +3,9 @@ package cgeo.geocaching.maps.mapsforge;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapItemFactory;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-
-import android.content.Context;
public class MapsforgeMapItemFactory implements MapItemFactory {
@@ -23,9 +19,4 @@ public class MapsforgeMapItemFactory implements MapItemFactory {
return new MapsforgeCacheOverlayItem(coordinate, type);
}
- @Override
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
- return new MapsforgeOtherCachersOverlayItem(context, userOne);
- }
-
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
index c24a798..3dd58a7 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
@@ -5,7 +5,6 @@ import cgeo.geocaching.Settings;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.MapProviderFactory;
-import cgeo.geocaching.maps.OtherCachersOverlay;
import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
@@ -108,13 +107,6 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
}
@Override
- public OtherCachersOverlay createAddUsersOverlay(Context context, Drawable markerIn) {
- MapsforgeOtherCachersOverlay ovl = new MapsforgeOtherCachersOverlay(context, markerIn);
- getOverlays().add(ovl);
- return ovl.getBase();
- }
-
- @Override
public PositionOverlay createAddPositionOverlay(Activity activity) {
MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.PositionOverlay);
getOverlays().add(ovl);
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java
deleted file mode 100644
index 66aa13e..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package cgeo.geocaching.maps.mapsforge;
-
-import cgeo.geocaching.maps.OtherCachersOverlay;
-import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
-import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
-import cgeo.geocaching.maps.interfaces.MapViewImpl;
-
-import org.mapsforge.android.maps.Projection;
-import org.mapsforge.android.maps.overlay.ItemizedOverlay;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Point;
-import android.graphics.drawable.Drawable;
-
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-public class MapsforgeOtherCachersOverlay extends ItemizedOverlay<MapsforgeOtherCachersOverlayItem> implements ItemizedOverlayImpl {
-
- private OtherCachersOverlay base;
- private Lock lock = new ReentrantLock();
-
- public MapsforgeOtherCachersOverlay(Context contextIn, Drawable markerIn) {
- super(boundCenter(markerIn));
- base = new OtherCachersOverlay(this, contextIn);
- }
-
- @Override
- public OtherCachersOverlay getBase() {
- return base;
- }
-
- @Override
- protected MapsforgeOtherCachersOverlayItem createItem(int i) {
- if (base == null) {
- return null;
- }
-
- return (MapsforgeOtherCachersOverlayItem) base.createItem(i);
- }
-
- @Override
- public int size() {
- if (base == null) {
- return 0;
- }
-
- return base.size();
- }
-
- @Override
- protected boolean onTap(int arg0) {
- if (base == null) {
- return false;
- }
-
- return base.onTap(arg0);
- }
-
- @Override
- protected void drawOverlayBitmap(Canvas canvas, Point drawPosition,
- Projection projection, byte drawZoomLevel) {
-
- base.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel);
- }
-
- @Override
- public void superPopulate() {
- populate();
- }
-
- @Override
- public Drawable superBoundCenter(Drawable markerIn) {
- return super.boundCenter(markerIn);
- }
-
- @Override
- public Drawable superBoundCenterBottom(Drawable marker) {
- return super.boundCenterBottom(marker);
- }
-
- @Override
- public void superSetLastFocusedItemIndex(int i) {
- // Nothing to do here
- }
-
- @Override
- public boolean superOnTap(int index) {
- return super.onTap(index);
- }
-
- @Override
- public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
- // Nothing to do here
- }
-
- @Override
- public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition,
- MapProjectionImpl projection, byte drawZoomLevel) {
-
- super.drawOverlayBitmap(canvas, drawPosition, (Projection) projection.getImpl(), drawZoomLevel);
- }
-
- @Override
- public void lock() {
- lock.lock();
- }
-
- @Override
- public void unlock() {
- lock.unlock();
- }
-
- @Override
- public MapViewImpl getMapViewImpl() {
- return (MapViewImpl) internalMapView;
- }
-
-} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java
deleted file mode 100644
index f80664e..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package cgeo.geocaching.maps.mapsforge;
-
-import cgeo.geocaching.go4cache.Go4CacheUser;
-import cgeo.geocaching.maps.OtherCachersOverlayItem;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-
-import org.mapsforge.android.maps.overlay.OverlayItem;
-import org.mapsforge.core.GeoPoint;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl {
- private final OtherCachersOverlayItem item;
-
- public MapsforgeOtherCachersOverlayItem(Context context, Go4CacheUser user) {
- super(new GeoPoint(user.getCoords().getLatitudeE6(), user.getCoords().getLongitudeE6()), user.getUsername(), "");
- item = new OtherCachersOverlayItem(context, user);
- }
-
- @Override
- public Drawable getMarker(int state) {
- Drawable marker = item.getMarker();
- setMarker(marker);
- return marker;
- }
-
- @Override
- public Go4CacheUser getUser() {
- return item.getUser();
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
index 863cbca..5c64592 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
@@ -3,13 +3,9 @@ package cgeo.geocaching.maps.mapsforge.v024;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapItemFactory;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-
-import android.content.Context;
public class MapsforgeMapItemFactory024 implements MapItemFactory {
@@ -22,10 +18,4 @@ public class MapsforgeMapItemFactory024 implements MapItemFactory {
public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
return new MapsforgeCacheOverlayItem(coordinate, type);
}
-
- @Override
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
- return new MapsforgeOtherCachersOverlayItem(context, userOne);
- }
-
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
index e53d976..a459804 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
@@ -4,7 +4,6 @@ import cgeo.geocaching.R;
import cgeo.geocaching.Settings;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.OtherCachersOverlay;
import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
@@ -103,13 +102,6 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl {
}
@Override
- public OtherCachersOverlay createAddUsersOverlay(Context context, Drawable markerIn) {
- MapsforgeOtherCachersOverlay ovl = new MapsforgeOtherCachersOverlay(context, markerIn);
- getOverlays().add(ovl);
- return ovl.getBase();
- }
-
- @Override
public PositionOverlay createAddPositionOverlay(Activity activity) {
MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.PositionOverlay);
getOverlays().add(ovl);
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java
deleted file mode 100644
index 64ce8b0..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.maps.OtherCachersOverlay;
-import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
-import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
-import cgeo.geocaching.maps.interfaces.MapViewImpl;
-
-import org.mapsforge.android.mapsold.ItemizedOverlay;
-import org.mapsforge.android.mapsold.Projection;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Point;
-import android.graphics.drawable.Drawable;
-
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-public class MapsforgeOtherCachersOverlay extends ItemizedOverlay<MapsforgeOtherCachersOverlayItem> implements ItemizedOverlayImpl {
-
- private OtherCachersOverlay base;
- private Lock lock = new ReentrantLock();
-
- public MapsforgeOtherCachersOverlay(Context contextIn, Drawable markerIn) {
- super(boundCenter(markerIn));
- base = new OtherCachersOverlay(this, contextIn);
- }
-
- @Override
- public OtherCachersOverlay getBase() {
- return base;
- }
-
- @Override
- protected MapsforgeOtherCachersOverlayItem createItem(int i) {
- if (base == null) {
- return null;
- }
-
- return (MapsforgeOtherCachersOverlayItem) base.createItem(i);
- }
-
- @Override
- public int size() {
- if (base == null) {
- return 0;
- }
-
- return base.size();
- }
-
- @Override
- protected boolean onTap(int arg0) {
- if (base == null) {
- return false;
- }
-
- return base.onTap(arg0);
- }
-
- @Override
- protected void drawOverlayBitmap(Canvas canvas, Point drawPosition,
- Projection projection, byte drawZoomLevel) {
-
- base.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel);
- }
-
- @Override
- public void superPopulate() {
- populate();
- }
-
- @Override
- public Drawable superBoundCenter(Drawable markerIn) {
- return super.boundCenter(markerIn);
- }
-
- @Override
- public Drawable superBoundCenterBottom(Drawable marker) {
- return super.boundCenterBottom(marker);
- }
-
- @Override
- public void superSetLastFocusedItemIndex(int i) {
- // Nothing to do here
- }
-
- @Override
- public boolean superOnTap(int index) {
- return super.onTap(index);
- }
-
- @Override
- public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
- // Nothing to do here
- }
-
- @Override
- public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition,
- MapProjectionImpl projection, byte drawZoomLevel) {
-
- super.drawOverlayBitmap(canvas, drawPosition, (Projection) projection.getImpl(), drawZoomLevel);
- }
-
- @Override
- public void lock() {
- lock.lock();
- }
-
- @Override
- public void unlock() {
- lock.unlock();
- }
-
- @Override
- public MapViewImpl getMapViewImpl() {
- return (MapViewImpl) internalMapView;
- }
-
-} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java
deleted file mode 100644
index ec38500..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.go4cache.Go4CacheUser;
-import cgeo.geocaching.maps.OtherCachersOverlayItem;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
-
-import org.mapsforge.android.mapsold.GeoPoint;
-import org.mapsforge.android.mapsold.OverlayItem;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl {
- private final OtherCachersOverlayItem item;
-
- public MapsforgeOtherCachersOverlayItem(Context context, Go4CacheUser user) {
- super(new GeoPoint(user.getCoords().getLatitudeE6(), user.getCoords().getLongitudeE6()), user.getUsername(), "");
- item = new OtherCachersOverlayItem(context, user);
- }
-
- @Override
- public Drawable getMarker(int state) {
- Drawable marker = item.getMarker();
- setMarker(marker);
- return marker;
- }
-
- @Override
- public Go4CacheUser getUser() {
- return item.getUser();
- }
-}
diff --git a/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java b/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java
index ef198dd..22ee0fb 100644
--- a/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java
+++ b/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java
@@ -10,6 +10,7 @@ import cgeo.geocaching.utils.Log;
import ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity;
import ch.boye.httpclientandroidlib.util.EntityUtils;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -90,9 +91,6 @@ public class TwitterAuthorizationActivity extends AbstractActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // init
- app.setAction("setting up");
-
setTheme();
setContentView(R.layout.auth);
setTitle(res.getString(R.string.auth_twitter));
diff --git a/main/src/cgeo/geocaching/utils/HtmlUtils.java b/main/src/cgeo/geocaching/utils/HtmlUtils.java
new file mode 100644
index 0000000..a54ba57
--- /dev/null
+++ b/main/src/cgeo/geocaching/utils/HtmlUtils.java
@@ -0,0 +1,56 @@
+package cgeo.geocaching.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+
+import android.text.Spanned;
+import android.text.style.ImageSpan;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+public class HtmlUtils {
+
+ /**
+ * Extract the text from a HTML based string. This is similar to what HTML.fromHtml(...) does, but this method also
+ * removes the embedded images instead of replacing them by a small rectangular representation character.
+ *
+ * @param html
+ * @return
+ */
+ public static String extractText(CharSequence html) {
+ String result = html.toString();
+
+ // recognize images in textview HTML contents
+ if (html instanceof Spanned) {
+ Spanned text = (Spanned) html;
+ Object[] styles = text.getSpans(0, text.length(), Object.class);
+ ArrayList<Pair<Integer, Integer>> removals = new ArrayList<Pair<Integer, Integer>>();
+ for (Object style : styles) {
+ if (style instanceof ImageSpan) {
+ int start = text.getSpanStart(style);
+ int end = text.getSpanEnd(style);
+ removals.add(Pair.of(start, end));
+ }
+ }
+
+ // sort reversed and delete image spans
+ Collections.sort(removals, new Comparator<Pair<Integer, Integer>>() {
+
+ @Override
+ public int compare(Pair<Integer, Integer> lhs, Pair<Integer, Integer> rhs) {
+ return rhs.getRight().compareTo(lhs.getRight());
+ }
+ });
+ result = text.toString();
+ for (Pair<Integer, Integer> removal : removals) {
+ result = result.substring(0, removal.getLeft()) + result.substring(removal.getRight());
+ }
+ }
+
+ // some line breaks are still in the text, source is unknown
+ return StringUtils.replace(result, "<br />", "\n").trim();
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
index 60866e0..7cacd9d 100644
--- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
+++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
@@ -2,6 +2,8 @@ package cgeo.geocaching.utils;
import cgeo.geocaching.R;
import cgeo.geocaching.Settings;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgTrackable;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.network.Network;
@@ -9,12 +11,57 @@ import cgeo.geocaching.ui.Formatter;
import org.apache.commons.lang3.StringUtils;
+import java.util.ArrayList;
/**
* provides all the available templates for logging
*
*/
public class LogTemplateProvider {
+
+ /**
+ * Context aware data container for log templates.
+ * <p>
+ * Some log templates need additional information. To provide that information, it can be encapsulated in this log
+ * context.
+ * </p>
+ *
+ */
+ public static class LogContext {
+ private cgCache cache;
+ private cgTrackable trackable;
+ private boolean offline = false;
+
+ public LogContext(final cgCache cache) {
+ this(cache, false);
+ }
+
+ public LogContext(final cgTrackable trackable) {
+ this.trackable = trackable;
+ }
+
+ public LogContext(boolean offline) {
+ this(null, offline);
+ }
+
+ public LogContext(final cgCache cache, boolean offline) {
+ this.cache = cache;
+ this.offline = offline;
+ }
+
+ public cgCache getCache() {
+ return cache;
+ }
+
+ public cgTrackable getTrackable() {
+ return trackable;
+ }
+
+ public boolean isOffline() {
+ return offline;
+ }
+ }
+
public static abstract class LogTemplate {
private final String template;
private final int resourceId;
@@ -24,7 +71,7 @@ public class LogTemplateProvider {
this.resourceId = resourceId;
}
- abstract public String getValue(boolean offline);
+ abstract public String getValue(LogContext context);
public int getResourceId() {
return resourceId;
@@ -38,70 +85,80 @@ public class LogTemplateProvider {
return template;
}
- protected String apply(String input, boolean offline) {
+ protected String apply(String input, LogContext context) {
if (input.contains("[" + template + "]")) {
- return StringUtils.replace(input, "[" + template + "]", getValue(offline));
+ return StringUtils.replace(input, "[" + template + "]", getValue(context));
}
return input;
}
}
- private static LogTemplate[] templates;
-
- public static LogTemplate[] getTemplates() {
- if (templates == null) {
- templates = new LogTemplate[] {
- new LogTemplate("DATE", R.string.init_signature_template_date) {
-
- @Override
- public String getValue(final boolean offline) {
- return Formatter.formatFullDate(System.currentTimeMillis());
- }
- },
- new LogTemplate("TIME", R.string.init_signature_template_time) {
-
- @Override
- public String getValue(final boolean offline) {
- return Formatter.formatTime(System.currentTimeMillis());
- }
- },
- new LogTemplate("DATETIME", R.string.init_signature_template_datetime) {
-
- @Override
- public String getValue(final boolean offline) {
- final long currentTime = System.currentTimeMillis();
- return Formatter.formatFullDate(currentTime) + " " + Formatter.formatTime(currentTime);
- }
- },
- new LogTemplate("USER", R.string.init_signature_template_user) {
-
- @Override
- public String getValue(final boolean offline) {
- return Settings.getUsername();
- }
- },
- new LogTemplate("NUMBER", R.string.init_signature_template_number) {
-
- @Override
- public String getValue(final boolean offline) {
- int current = Login.getActualCachesFound();
- if (current == 0) {
- if (offline) {
- return "";
- }
- final String page = Network.getResponseData(Network.getRequest("http://www.geocaching.com/email/"));
- current = parseFindCount(page);
- }
-
- String findCount = "";
- if (current >= 0) {
- findCount = String.valueOf(current + 1);
- }
- return findCount;
- }
+ public static ArrayList<LogTemplate> getTemplates() {
+ ArrayList<LogTemplate> templates = new ArrayList<LogTemplateProvider.LogTemplate>();
+ templates.add(new LogTemplate("DATE", R.string.init_signature_template_date) {
+
+ @Override
+ public String getValue(final LogContext context) {
+ return Formatter.formatFullDate(System.currentTimeMillis());
+ }
+ });
+ templates.add(new LogTemplate("TIME", R.string.init_signature_template_time) {
+
+ @Override
+ public String getValue(final LogContext context) {
+ return Formatter.formatTime(System.currentTimeMillis());
+ }
+ });
+ templates.add(new LogTemplate("DATETIME", R.string.init_signature_template_datetime) {
+
+ @Override
+ public String getValue(final LogContext context) {
+ final long currentTime = System.currentTimeMillis();
+ return Formatter.formatFullDate(currentTime) + " " + Formatter.formatTime(currentTime);
+ }
+ });
+ templates.add(new LogTemplate("USER", R.string.init_signature_template_user) {
+
+ @Override
+ public String getValue(final LogContext context) {
+ return Settings.getUsername();
+ }
+ });
+ templates.add(new LogTemplate("NUMBER", R.string.init_signature_template_number) {
+
+ @Override
+ public String getValue(final LogContext context) {
+ int current = Login.getActualCachesFound();
+ if (current == 0) {
+ if (context.isOffline()) {
+ return "";
}
- };
- }
+ final String page = Network.getResponseData(Network.getRequest("http://www.geocaching.com/email/"));
+ current = parseFindCount(page);
+ }
+
+ String findCount = "";
+ if (current >= 0) {
+ findCount = String.valueOf(current + 1);
+ }
+ return findCount;
+ }
+ });
+ templates.add(new LogTemplate("OWNER", R.string.init_signature_template_owner) {
+
+ @Override
+ public String getValue(final LogContext context) {
+ cgTrackable trackable = context.getTrackable();
+ if (trackable != null) {
+ return trackable.getOwner();
+ }
+ cgCache cache = context.getCache();
+ if (cache != null) {
+ return cache.getOwnerDisplayName();
+ }
+ return "";
+ }
+ });
return templates;
}
@@ -114,13 +171,13 @@ public class LogTemplateProvider {
return null;
}
- public static String applyTemplates(String signature, boolean offline) {
+ public static String applyTemplates(String signature, LogContext context) {
if (signature == null) {
return "";
}
String result = signature;
for (LogTemplate template : getTemplates()) {
- result = template.apply(result, offline);
+ result = template.apply(result, context);
}
return result;
}
diff --git a/main/src/cgeo/geocaching/utils/ProcessUtils.java b/main/src/cgeo/geocaching/utils/ProcessUtils.java
new file mode 100644
index 0000000..53991fb
--- /dev/null
+++ b/main/src/cgeo/geocaching/utils/ProcessUtils.java
@@ -0,0 +1,27 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.cgeoapplication;
+
+import android.content.Intent;
+import android.content.pm.PackageManager;
+
+public class ProcessUtils {
+
+ public static boolean isInstalled(final String packageName) {
+ return getLaunchIntent(packageName) != null;
+ }
+
+ public static Intent getLaunchIntent(final String packageName) {
+ if (packageName == null) {
+ return null;
+ }
+ final PackageManager packageManager = cgeoapplication.getInstance().getPackageManager();
+ try {
+ // This can throw an exception where the exception type is only defined on API Level > 3
+ // therefore surround with try-catch
+ return packageManager.getLaunchIntentForPackage(packageName);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}
diff --git a/main/src/cgeo/geocaching/utils/TranslationUtils.java b/main/src/cgeo/geocaching/utils/TranslationUtils.java
index e086ab6..a29c5a7 100644
--- a/main/src/cgeo/geocaching/utils/TranslationUtils.java
+++ b/main/src/cgeo/geocaching/utils/TranslationUtils.java
@@ -18,6 +18,7 @@ public final class TranslationUtils {
private static final String translationFieldSeparator = "|";
public static final int translationTextLengthToWarn = 500;
+ private static final String TRANSLATION_APP = "com.google.android.apps.translate";
/**
* Build a URI for Google Translate
@@ -28,13 +29,18 @@ public final class TranslationUtils {
* The text to be translated
* @return URI ready to be parsed
*/
- public static String buildTranslationURI(final String toLang, final String text) {
- return translationWebsite + translationForceClassicMode + translationAutoSelect + translationFieldSeparator + toLang + translationFieldSeparator + URLEncoder.encode(text).replace("+", "%20");
+ private static String buildTranslationURI(final String toLang, final String text) {
+ String content = URLEncoder.encode(text);
+ // the app works better without the "+", the website works better with "+", therefore assume using the app if installed
+ if (ProcessUtils.isInstalled(TRANSLATION_APP)) {
+ content = content.replace("+", "%20");
+ }
+ return translationWebsite + translationForceClassicMode + translationAutoSelect + translationFieldSeparator + toLang + translationFieldSeparator + content;
}
/**
* Send Intent for Google Translate. Can be caught by Google Translate App or browser
- *
+ *
* @param toLang
* The two-letter lowercase ISO language codes as defined by ISO 639-1
* @param text