aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/AboutActivity.java71
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java9
-rw-r--r--main/src/cgeo/geocaching/Geocache.java5
-rw-r--r--main/src/cgeo/geocaching/LogViewHolder.java12
-rw-r--r--main/src/cgeo/geocaching/MainActivity.java2
-rw-r--r--main/src/cgeo/geocaching/NavigateAnyPointActivity.java6
-rw-r--r--main/src/cgeo/geocaching/StaticMapsActivity.java61
-rw-r--r--main/src/cgeo/geocaching/UsefulAppsActivity.java6
-rw-r--r--main/src/cgeo/geocaching/connector/ConnectorFactory.java1
-rw-r--r--main/src/cgeo/geocaching/connector/WaymarkingConnector.java40
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java5
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OkapiClient.java28
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java30
-rw-r--r--main/src/cgeo/geocaching/files/LocParser.java33
-rw-r--r--main/src/cgeo/geocaching/network/HtmlImage.java3
-rw-r--r--main/src/cgeo/geocaching/ui/AbstractViewHolder.java19
-rw-r--r--main/src/cgeo/geocaching/ui/AddressListAdapter.java19
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java6
-rw-r--r--main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java28
-rw-r--r--main/src/cgeo/geocaching/ui/GPXListAdapter.java28
-rw-r--r--main/src/cgeo/geocaching/utils/CryptUtils.java52
21 files changed, 261 insertions, 203 deletions
diff --git a/main/src/cgeo/geocaching/AboutActivity.java b/main/src/cgeo/geocaching/AboutActivity.java
index 3164602..f947655 100644
--- a/main/src/cgeo/geocaching/AboutActivity.java
+++ b/main/src/cgeo/geocaching/AboutActivity.java
@@ -1,85 +1,72 @@
package cgeo.geocaching;
-import butterknife.InjectView;
-
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.ui.AnchorAwareLinkMovementMethod;
import cgeo.geocaching.utils.Version;
+import com.googlecode.androidannotations.annotations.AfterViews;
+import com.googlecode.androidannotations.annotations.Click;
+import com.googlecode.androidannotations.annotations.EActivity;
+import com.googlecode.androidannotations.annotations.ViewById;
+
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
-import android.view.View;
import android.widget.TextView;
+@EActivity
public class AboutActivity extends AbstractActivity {
- @InjectView(R.id.about_version_string) protected TextView version;
- @InjectView(R.id.contributors) protected TextView contributors;
- @InjectView(R.id.changelog) protected TextView changeLog;
+ @ViewById(R.id.about_version_string) protected TextView version;
+ @ViewById(R.id.contributors) protected TextView contributors;
+ @ViewById(R.id.changelog) protected TextView changeLog;
@Override
public void onCreate(Bundle savedInstanceState) {
+ // TODO remove this after the theme has been fixed
super.onCreate(savedInstanceState, R.layout.about_activity);
+ }
+ @AfterViews
+ void initializeViews() {
version.setText(Version.getVersionName(this));
contributors.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance());
changeLog.setMovementMethod(AnchorAwareLinkMovementMethod.getInstance());
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void donate(View view) {
+ @Click(R.id.donate)
+ public void donate() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FMLNN8GXZKJEE")));
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void support(View view) {
+ @Click(R.id.support)
+ public void support() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:support@cgeo.org")));
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void website(View view) {
+
+ @Click(R.id.website)
+ void webSite() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.cgeo.org/")));
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void facebook(View view) {
+ @Click(R.id.facebook)
+ public void facebook() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/pages/cgeo/297269860090")));
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void twitter(View view) {
+ @Click(R.id.twitter)
+ public void twitter() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://twitter.com/android_gc")));
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void nutshellmanual(View view) {
+ @Click(R.id.nutshellmanual)
+ public void nutshellmanual() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://manual.cgeo.org/")));
}
- /**
- * @param view
- * unused here but needed since this method is referenced from XML layout
- */
- public void market(View view) {
- Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
+ @Click(R.id.market)
+ public void market() {
+ final Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(marketIntent);
}
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 58765bc..0f2fba0 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -2356,6 +2356,15 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
});
+ waypointView.setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ EditWaypointActivity.startActivityEditWaypoint(CacheDetailActivity.this, wpt.getId());
+ refreshOnResume = true;
+ return true;
+ }
+ });
+
waypoints.addView(waypointView);
}
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index fd1c2ce..66b23bf 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -1561,9 +1561,12 @@ public class Geocache implements ICache, IWaypoint {
Geocache cache;
// get cache details, they may not yet be complete
if (origCache != null) {
+ SearchResult search = null;
// only reload the cache if it was already stored or doesn't have full details (by checking the description)
if (origCache.isOffline() || StringUtils.isBlank(origCache.getDescription())) {
- final SearchResult search = searchByGeocode(origCache.getGeocode(), null, listId, false, handler);
+ search = searchByGeocode(origCache.getGeocode(), null, listId, false, handler);
+ }
+ if (search != null) {
cache = search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
} else {
cache = origCache;
diff --git a/main/src/cgeo/geocaching/LogViewHolder.java b/main/src/cgeo/geocaching/LogViewHolder.java
index 1fb3f55..14148d0 100644
--- a/main/src/cgeo/geocaching/LogViewHolder.java
+++ b/main/src/cgeo/geocaching/LogViewHolder.java
@@ -1,13 +1,14 @@
package cgeo.geocaching;
import butterknife.InjectView;
-import butterknife.Views;
+
+import cgeo.geocaching.ui.AbstractViewHolder;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
-public class LogViewHolder {
+public class LogViewHolder extends AbstractViewHolder {
@InjectView(R.id.added) protected TextView date ;
@InjectView(R.id.type) protected TextView type;
@InjectView(R.id.author) protected TextView author;
@@ -19,14 +20,13 @@ public class LogViewHolder {
private int position;
public LogViewHolder(View rowView) {
- Views.inject(this, rowView);
- rowView.setTag(this);
+ super(rowView);
}
/**
* Read the position of the cursor pointed to by this holder. <br/>
* This must be called by the UI thread.
- *
+ *
* @return the cursor position
*/
public int getPosition() {
@@ -36,7 +36,7 @@ public class LogViewHolder {
/**
* Set the position of the cursor pointed to by this holder. <br/>
* This must be called by the UI thread.
- *
+ *
* @param position
* the cursor position
*/
diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java
index 87f7ffd..e8de1f7 100644
--- a/main/src/cgeo/geocaching/MainActivity.java
+++ b/main/src/cgeo/geocaching/MainActivity.java
@@ -756,7 +756,7 @@ public class MainActivity extends AbstractActivity {
* unused here but needed since this method is referenced from XML layout
*/
public void showAbout(View view) {
- startActivity(new Intent(this, AboutActivity.class));
+ AboutActivity_.intent(this).start();
}
/**
diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
index 61ba0e5..cc6853b 100644
--- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
+++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java
@@ -8,6 +8,7 @@ import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.geopoint.DistanceParser;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
+import cgeo.geocaching.ui.AbstractViewHolder;
import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.ui.dialog.CoordinatesInputDialog;
import cgeo.geocaching.utils.GeoDirHandler;
@@ -62,14 +63,13 @@ public class NavigateAnyPointActivity extends AbstractActivity {
private String distanceUnit = "";
- protected static class ViewHolder {
+ protected static class ViewHolder extends AbstractViewHolder {
@InjectView(R.id.simple_way_point_longitude) protected TextView longitude;
@InjectView(R.id.simple_way_point_latitude) protected TextView latitude;
@InjectView(R.id.date) protected TextView date;
public ViewHolder(View rowView) {
- Views.inject(this, rowView);
- rowView.setTag(this);
+ super(rowView);
}
}
diff --git a/main/src/cgeo/geocaching/StaticMapsActivity.java b/main/src/cgeo/geocaching/StaticMapsActivity.java
index a6a81d5..d8bc614 100644
--- a/main/src/cgeo/geocaching/StaticMapsActivity.java
+++ b/main/src/cgeo/geocaching/StaticMapsActivity.java
@@ -1,36 +1,43 @@
package cgeo.geocaching;
+import cgeo.geocaching.StaticMapsActivity_.IntentBuilder_;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.utils.Log;
+import com.googlecode.androidannotations.annotations.EActivity;
+import com.googlecode.androidannotations.annotations.Extra;
+import com.googlecode.androidannotations.annotations.OptionsItem;
+import com.googlecode.androidannotations.annotations.OptionsMenu;
+
import org.apache.commons.collections.CollectionUtils;
import android.app.ProgressDialog;
import android.content.Context;
-import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
+@EActivity
+@OptionsMenu(R.menu.static_maps_activity_options)
public class StaticMapsActivity extends AbstractActivity {
private static final String EXTRAS_WAYPOINT = "waypoint";
private static final String EXTRAS_DOWNLOAD = "download";
private static final String EXTRAS_GEOCODE = "geocode";
+
+ @Extra(EXTRAS_DOWNLOAD) boolean download = false;
+ @Extra(EXTRAS_WAYPOINT) Integer waypoint_id = null;
+ @Extra(EXTRAS_GEOCODE) String geocode = null;
+
private final List<Bitmap> maps = new ArrayList<Bitmap>();
- private boolean download = false;
- private Integer waypoint_id = null;
- private String geocode = null;
private LayoutInflater inflater = null;
private ProgressDialog waitDialog = null;
private LinearLayout smapsView = null;
@@ -89,18 +96,6 @@ public class StaticMapsActivity extends AbstractActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.map_static);
- // get parameters
- final Bundle extras = getIntent().getExtras();
-
- // try to get data from extras
- if (extras != null) {
- download = extras.getBoolean(EXTRAS_DOWNLOAD, false);
- geocode = extras.getString(EXTRAS_GEOCODE);
- if (extras.containsKey(EXTRAS_WAYPOINT)) {
- waypoint_id = extras.getInt(EXTRAS_WAYPOINT);
- }
- }
-
if (geocode == null) {
showToast("Sorry, c:geo forgot for what cache you want to load static maps.");
finish();
@@ -156,20 +151,10 @@ public class StaticMapsActivity extends AbstractActivity {
}
}
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.static_maps_activity_options, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.menu_refresh) {
- downloadStaticMaps();
- restartActivity();
- return true;
- }
- return super.onOptionsItemSelected(item);
+ @OptionsItem(R.id.menu_refresh)
+ void refreshMaps() {
+ downloadStaticMaps();
+ restartActivity();
}
private boolean downloadStaticMaps() {
@@ -192,16 +177,10 @@ public class StaticMapsActivity extends AbstractActivity {
}
public static void startActivity(final Context activity, final String geocode, final boolean download, final Waypoint waypoint) {
- final Intent intent = new Intent(activity, StaticMapsActivity.class);
- // if resuming our app within this activity, finish it and return to the cache activity
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- intent.putExtra(EXTRAS_GEOCODE, geocode);
- if (download) {
- intent.putExtra(EXTRAS_DOWNLOAD, true);
- }
+ IntentBuilder_ builder = StaticMapsActivity_.intent(activity).geocode(geocode).download(download);
if (waypoint != null) {
- intent.putExtra(EXTRAS_WAYPOINT, waypoint.getId());
+ builder.waypoint_id(waypoint.getId());
}
- activity.startActivity(intent);
+ builder.start();
}
} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/UsefulAppsActivity.java b/main/src/cgeo/geocaching/UsefulAppsActivity.java
index d6e0ec8..b74db83 100644
--- a/main/src/cgeo/geocaching/UsefulAppsActivity.java
+++ b/main/src/cgeo/geocaching/UsefulAppsActivity.java
@@ -4,6 +4,7 @@ import butterknife.InjectView;
import butterknife.Views;
import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.ui.AbstractViewHolder;
import android.app.Activity;
import android.content.Intent;
@@ -20,13 +21,13 @@ public class UsefulAppsActivity extends AbstractActivity {
@InjectView(R.id.apps_list) protected ListView list;
- protected static class ViewHolder {
+ protected static class ViewHolder extends AbstractViewHolder {
@InjectView(R.id.title) protected TextView title;
@InjectView(R.id.image) protected ImageView image;
@InjectView(R.id.description) protected TextView description;
public ViewHolder(View rowView) {
- Views.inject(this, rowView);
+ super(rowView);
}
}
@@ -80,7 +81,6 @@ public class UsefulAppsActivity extends AbstractActivity {
ViewHolder holder = (ViewHolder) rowView.getTag();
if (null == holder) {
holder = new ViewHolder(rowView);
- rowView.setTag(holder);
}
final HelperApp app = getItem(position);
diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java
index f63e390..3319fe4 100644
--- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java
+++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java
@@ -36,6 +36,7 @@ public final class ConnectorFactory {
new OXConnector(),
new GeocachingAustraliaConnector(),
new GeopeitusConnector(),
+ new WaymarkingConnector(),
UNKNOWN_CONNECTOR // the unknown connector MUST be the last one
};
diff --git a/main/src/cgeo/geocaching/connector/WaymarkingConnector.java b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java
new file mode 100644
index 0000000..f184f6e
--- /dev/null
+++ b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java
@@ -0,0 +1,40 @@
+package cgeo.geocaching.connector;
+
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.ICache;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class WaymarkingConnector extends AbstractConnector {
+
+ @Override
+ public String getName() {
+ return "Waymarking";
+ }
+
+ @Override
+ public String getCacheUrl(Geocache cache) {
+ return getCacheUrlPrefix() + cache.getGeocode();
+ }
+
+ @Override
+ public String getHost() {
+ return "www.waymarking.com";
+ }
+
+ @Override
+ public boolean isOwner(ICache cache) {
+ // this connector has no user management
+ return false;
+ }
+
+ @Override
+ protected String getCacheUrlPrefix() {
+ return "http://" + getHost() + "/waymarks/";
+ }
+
+ @Override
+ public boolean canHandle(String geocode) {
+ return StringUtils.startsWith(geocode, "WM");
+ }
+}
diff --git a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java
index d349dc2..59d0f56 100644
--- a/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java
+++ b/main/src/cgeo/geocaching/connector/oc/OCApiLiveConnector.java
@@ -27,6 +27,11 @@ public class OCApiLiveConnector extends OCApiConnector implements ISearchByCente
}
@Override
+ public boolean isActivated() {
+ return Settings.isOCConnectorActive();
+ }
+
+ @Override
public SearchResult searchByViewport(Viewport viewport, String[] tokens) {
return new SearchResult(OkapiClient.getCachesBBox(viewport, this));
}
diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java
index af59604..da7708f 100644
--- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java
+++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java
@@ -52,6 +52,8 @@ import java.util.TimeZone;
final public class OkapiClient {
+ private static final char SEPARATOR = '|';
+ private static final String SEPARATOR_STRING = Character.toString(SEPARATOR);
private static final SimpleDateFormat logDateFormat;
static {
@@ -135,7 +137,7 @@ final public class OkapiClient {
// Assumes level 3 OAuth
public static List<Geocache> getCachesAround(final Geopoint center, OCApiConnector connector) {
- String centerString = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, center) + "|" + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, center);
+ String centerString = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, center) + SEPARATOR + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, center);
final Parameters params = new Parameters("search_method", METHOD_SEARCH_NEAREST);
final Map<String, String> valueMap = new LinkedHashMap<String, String>();
valueMap.put("center", centerString);
@@ -169,9 +171,9 @@ final public class OkapiClient {
}
String bboxString = GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, viewport.bottomLeft)
- + "|" + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, viewport.bottomLeft)
- + "|" + GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, viewport.topRight)
- + "|" + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, viewport.topRight);
+ + SEPARATOR + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, viewport.bottomLeft)
+ + SEPARATOR + GeopointFormatter.format(GeopointFormatter.Format.LAT_DECDEGREE_RAW, viewport.topRight)
+ + SEPARATOR + GeopointFormatter.format(GeopointFormatter.Format.LON_DECDEGREE_RAW, viewport.topRight);
final Parameters params = new Parameters("search_method", METHOD_SEARCH_BBOX);
final Map<String, String> valueMap = new LinkedHashMap<String, String>();
valueMap.put("bbox", bboxString);
@@ -482,8 +484,8 @@ final public class OkapiClient {
}
private static Geopoint parseCoords(final String location) {
- final String latitude = StringUtils.substringBefore(location, "|");
- final String longitude = StringUtils.substringAfter(location, "|");
+ final String latitude = StringUtils.substringBefore(location, SEPARATOR_STRING);
+ final String longitude = StringUtils.substringAfter(location, SEPARATOR_STRING);
if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) {
return new Geopoint(latitude, longitude);
}
@@ -512,8 +514,8 @@ final public class OkapiClient {
}
private static void setLocation(final Geocache cache, final String location) {
- final String latitude = StringUtils.substringBefore(location, "|");
- final String longitude = StringUtils.substringAfter(location, "|");
+ final String latitude = StringUtils.substringBefore(location, SEPARATOR_STRING);
+ final String longitude = StringUtils.substringAfter(location, SEPARATOR_STRING);
cache.setCoords(new Geopoint(latitude, longitude));
}
@@ -579,7 +581,7 @@ final public class OkapiClient {
}
if (connector.getSupportedAuthLevel() == OAuthLevel.Level3) {
- return SERVICE_CACHE_CORE_FIELDS + "|" + SERVICE_CACHE_CORE_L3_FIELDS;
+ return SERVICE_CACHE_CORE_FIELDS + SEPARATOR + SERVICE_CACHE_CORE_L3_FIELDS;
}
return SERVICE_CACHE_CORE_FIELDS;
@@ -594,13 +596,13 @@ final public class OkapiClient {
StringBuilder res = new StringBuilder(500);
res.append(SERVICE_CACHE_CORE_FIELDS);
- res.append("|").append(SERVICE_CACHE_ADDITIONAL_FIELDS);
+ res.append(SEPARATOR).append(SERVICE_CACHE_ADDITIONAL_FIELDS);
if (connector.getSupportedAuthLevel() == OAuthLevel.Level3) {
- res.append("|").append(SERVICE_CACHE_CORE_L3_FIELDS);
- res.append("|").append(SERVICE_CACHE_ADDITIONAL_L3_FIELDS);
+ res.append(SEPARATOR).append(SERVICE_CACHE_CORE_L3_FIELDS);
+ res.append(SEPARATOR).append(SERVICE_CACHE_ADDITIONAL_L3_FIELDS);
}
if (connector.getApiSupport() == ApiSupport.current) {
- res.append("|").append(SERVICE_CACHE_ADDITIONAL_CURRENT_FIELDS);
+ res.append(SEPARATOR).append(SERVICE_CACHE_ADDITIONAL_CURRENT_FIELDS);
}
return res.toString();
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index 4150b87..8412207 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -296,11 +296,7 @@ public abstract class GPXParser extends FileParser {
}
}
- if (StringUtils.isNotBlank(cache.getGeocode())
- && cache.getCoords() != null
- && ((type == null && sym == null)
- || StringUtils.contains(type, "geocache")
- || StringUtils.contains(sym, "geocache"))) {
+ if (isValidForImport()) {
fixCache(cache);
cache.setListId(listId);
cache.setDetailed(true);
@@ -451,6 +447,17 @@ public abstract class GPXParser extends FileParser {
}
});
+ // waypoint.urlname (name for waymarks)
+ waypoint.getChild(namespace, "urlname").setEndTextElementListener(new EndTextElementListener() {
+
+ @Override
+ public void end(String urlName) {
+ if (cache.getName().equals(cache.getGeocode()) && StringUtils.startsWith(cache.getGeocode(), "WM")) {
+ cache.setName(StringUtils.trim(urlName));
+ }
+ }
+ });
+
// for GPX 1.0, cache info comes from waypoint node (so called private children,
// for GPX 1.1 from extensions node
final Element cacheParent = getCacheParent(waypoint);
@@ -892,4 +899,17 @@ public abstract class GPXParser extends FileParser {
}
}
}
+
+ private boolean isValidForImport() {
+ if (StringUtils.isBlank(cache.getGeocode())) {
+ return false;
+ }
+ if (cache.getCoords() == null) {
+ return false;
+ }
+ return ((type == null && sym == null)
+ || StringUtils.contains(type, "geocache")
+ || StringUtils.contains(sym, "geocache")
+ || StringUtils.containsIgnoreCase(sym, "waymark"));
+ }
}
diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java
index 873bf1b..49b9d6e 100644
--- a/main/src/cgeo/geocaching/files/LocParser.java
+++ b/main/src/cgeo/geocaching/files/LocParser.java
@@ -27,19 +27,13 @@ import java.util.regex.Pattern;
public final class LocParser extends FileParser {
+ private static final String NAME_OWNER_SEPARATOR = " by ";
private static final Pattern patternGeocode = Pattern
.compile("name id=\"([^\"]+)\"");
private static final Pattern patternLat = Pattern
.compile("lat=\"([^\"]+)\"");
private static final Pattern patternLon = Pattern
.compile("lon=\"([^\"]+)\"");
- // premium only >>
- private static final Pattern patternDifficulty = Pattern
- .compile("<difficulty>([^<]+)</difficulty>");
- private static final Pattern patternTerrain = Pattern
- .compile("<terrain>([^<]+)</terrain>");
- private static final Pattern patternContainer = Pattern
- .compile("<container>([^<]+)</container>");
private static final Pattern patternName = Pattern.compile("CDATA\\[([^\\]]+)\\]");
private static final CacheSize[] SIZES = {
@@ -82,6 +76,7 @@ public final class LocParser extends FileParser {
if (StringUtils.isBlank(cache.getName())) {
cache.setName(coord.getName());
}
+ cache.setOwnerDisplayName(coord.getOwnerDisplayName());
}
static Map<String, Geocache> parseCoordinates(final String fileContent) {
@@ -156,7 +151,11 @@ public final class LocParser extends FileParser {
final MatcherWrapper matcherName = new MatcherWrapper(patternName, pointString);
if (matcherName.find()) {
final String name = matcherName.group(1).trim();
- cache.setName(StringUtils.substringBeforeLast(name, " by ").trim());
+ String ownerName = StringUtils.trim(StringUtils.substringAfterLast(name, NAME_OWNER_SEPARATOR));
+ if (StringUtils.isEmpty(cache.getOwnerDisplayName()) && StringUtils.isNotEmpty(ownerName)) {
+ cache.setOwnerDisplayName(ownerName);
+ }
+ cache.setName(StringUtils.substringBeforeLast(name, NAME_OWNER_SEPARATOR).trim());
} else {
cache.setName(cache.getGeocode());
}
@@ -167,20 +166,20 @@ public final class LocParser extends FileParser {
cache.setCoords(parsePoint(matcherLat.group(1).trim(), matcherLon.group(1).trim()));
}
- final MatcherWrapper matcherDifficulty = new MatcherWrapper(patternDifficulty, pointString);
+ final String difficulty = StringUtils.substringBetween(pointString, "<difficulty>", "</difficulty>");
+ final String terrain = StringUtils.substringBetween(pointString, "<terrain>", "</terrain>");
+ final String container = StringUtils.substringBetween(pointString, "<container>", "</container");
try {
- if (matcherDifficulty.find()) {
- cache.setDifficulty(Float.parseFloat(matcherDifficulty.group(1).trim()));
+ if (StringUtils.isNotBlank(difficulty)) {
+ cache.setDifficulty(Float.parseFloat(difficulty.trim()));
}
- final MatcherWrapper matcherTerrain = new MatcherWrapper(patternTerrain, pointString);
- if (matcherTerrain.find()) {
- cache.setTerrain(Float.parseFloat(matcherTerrain.group(1).trim()));
+ if (StringUtils.isNotBlank(terrain)) {
+ cache.setTerrain(Float.parseFloat(terrain.trim()));
}
- final MatcherWrapper matcherContainer = new MatcherWrapper(patternContainer, pointString);
- if (matcherContainer.find()) {
- final int size = Integer.parseInt(matcherContainer.group(1).trim());
+ if (StringUtils.isNotBlank(container)) {
+ final int size = Integer.parseInt(container.trim());
if (size >= 1 && size <= 8) {
cache.setSize(SIZES[size - 1]);
}
diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java
index d5b610c..616a951 100644
--- a/main/src/cgeo/geocaching/network/HtmlImage.java
+++ b/main/src/cgeo/geocaching/network/HtmlImage.java
@@ -43,7 +43,8 @@ public class HtmlImage implements Html.ImageGetter {
"hitwebcounter.com",
"kostenloser-counter.eu",
"trendcounter.com",
- "hit-counter-download.com"
+ "hit-counter-download.com",
+ "gcwetterau.de/counter"
};
public static final String SHARED = "shared";
diff --git a/main/src/cgeo/geocaching/ui/AbstractViewHolder.java b/main/src/cgeo/geocaching/ui/AbstractViewHolder.java
new file mode 100644
index 0000000..cc5cd4d
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/AbstractViewHolder.java
@@ -0,0 +1,19 @@
+package cgeo.geocaching.ui;
+
+import butterknife.Views;
+
+import android.view.View;
+
+/**
+ * Abstract super class for all view holders. It is responsible for the invocation of the view injection code and for
+ * the tagging of views.
+ *
+ */
+public abstract class AbstractViewHolder {
+
+ protected AbstractViewHolder(View view) {
+ Views.inject(this, view);
+ view.setTag(this);
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/ui/AddressListAdapter.java b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
index eb8b516..6689bb6 100644
--- a/main/src/cgeo/geocaching/ui/AddressListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/AddressListAdapter.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+
import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.cgeocaches;
@@ -24,9 +26,13 @@ public class AddressListAdapter extends ArrayAdapter<Address> {
final private LayoutInflater inflater;
final private Geopoint location;
- private static final class ViewHolder {
- TextView label;
- TextView distance;
+ protected static final class ViewHolder extends AbstractViewHolder {
+ @InjectView(R.id.label) protected TextView label;
+ @InjectView(R.id.distance) protected TextView distance;
+
+ public ViewHolder(View view) {
+ super(view);
+ }
}
public AddressListAdapter(final Context context) {
@@ -45,12 +51,7 @@ public class AddressListAdapter extends ArrayAdapter<Address> {
final ViewHolder holder;
if (view == null) {
view = inflater.inflate(R.layout.addresses_item, null);
-
- holder = new ViewHolder();
- holder.label = (TextView) view.findViewById(R.id.label);
- holder.distance = (TextView) view.findViewById(R.id.distance);
-
- view.setTag(holder);
+ holder = new ViewHolder(view);
} else {
holder = (ViewHolder) view.getTag();
}
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index c27c387..122f835 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -1,7 +1,6 @@
package cgeo.geocaching.ui;
import butterknife.InjectView;
-import butterknife.Views;
import cgeo.geocaching.CacheDetailActivity;
import cgeo.geocaching.Geocache;
@@ -94,7 +93,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
* view holder for the cache list adapter
*
*/
- protected static class ViewHolder {
+ protected static class ViewHolder extends AbstractViewHolder {
@InjectView(R.id.checkbox) protected CheckBox checkbox;
@InjectView(R.id.log_status_mark) protected ImageView logStatusMark;
@InjectView(R.id.text) protected TextView text;
@@ -106,8 +105,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
@InjectView(R.id.dirimg) protected ImageView dirImg;
public ViewHolder(View view) {
- Views.inject(this, view);
- view.setTag(this);
+ super(view);
}
}
diff --git a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java
index ea32178..c325f50 100644
--- a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+
import cgeo.geocaching.R;
import cgeo.geocaching.files.IFileSelectionView;
import cgeo.geocaching.utils.Log;
@@ -17,21 +19,18 @@ import java.util.List;
public class FileSelectionListAdapter extends ArrayAdapter<File> {
- private IFileSelectionView parentView;
- private LayoutInflater inflater;
+ private final IFileSelectionView parentView;
+ private final LayoutInflater inflater;
public FileSelectionListAdapter(IFileSelectionView parentIn, List<File> listIn) {
super(parentIn.getContext(), 0, listIn);
parentView = parentIn;
+ inflater = ((Activity) getContext()).getLayoutInflater();
}
@Override
public View getView(final int position, final View rowView, final ViewGroup parent) {
- if (inflater == null) {
- inflater = ((Activity) getContext()).getLayoutInflater();
- }
-
if (position > getCount()) {
Log.w("FileSelectionListAdapter.getView: Attempt to access missing item #" + position);
return null;
@@ -44,12 +43,7 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> {
ViewHolder holder;
if (v == null) {
v = inflater.inflate(R.layout.mapfile_item, null);
-
- holder = new ViewHolder();
- holder.filepath = (TextView) v.findViewById(R.id.mapfilepath);
- holder.filename = (TextView) v.findViewById(R.id.mapfilename);
-
- v.setTag(holder);
+ holder = new ViewHolder(v);
} else {
holder = (ViewHolder) v.getTag();
}
@@ -85,8 +79,12 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> {
}
}
- private static final class ViewHolder {
- TextView filepath;
- TextView filename;
+ protected static final class ViewHolder extends AbstractViewHolder {
+ @InjectView(R.id.mapfilepath) protected TextView filepath;
+ @InjectView(R.id.mapfilename) protected TextView filename;
+
+ public ViewHolder(View view) {
+ super(view);
+ }
}
}
diff --git a/main/src/cgeo/geocaching/ui/GPXListAdapter.java b/main/src/cgeo/geocaching/ui/GPXListAdapter.java
index d2bfe16..7f3c33f 100644
--- a/main/src/cgeo/geocaching/ui/GPXListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/GPXListAdapter.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.ui;
+import butterknife.InjectView;
+
import cgeo.geocaching.GpxFileListActivity;
import cgeo.geocaching.R;
import cgeo.geocaching.files.GPXImporter;
@@ -18,26 +20,27 @@ import java.io.File;
import java.util.List;
public class GPXListAdapter extends ArrayAdapter<File> {
- private GpxFileListActivity activity = null;
- private LayoutInflater inflater = null;
+ private final GpxFileListActivity activity;
+ private final LayoutInflater inflater;
+
+ protected static class ViewHolder extends AbstractViewHolder {
+ @InjectView(R.id.filepath) protected TextView filepath;
+ @InjectView(R.id.filename) protected TextView filename;
- private static class ViewHolder {
- TextView filepath;
- TextView filename;
+ public ViewHolder(View view) {
+ super(view);
+ }
}
public GPXListAdapter(GpxFileListActivity parentIn, List<File> listIn) {
super(parentIn, 0, listIn);
activity = parentIn;
+ inflater = ((Activity) getContext()).getLayoutInflater();
}
@Override
public View getView(final int position, final View rowView, final ViewGroup parent) {
- if (inflater == null) {
- inflater = ((Activity) getContext()).getLayoutInflater();
- }
-
if (position > getCount()) {
Log.w("GPXListAdapter.getView: Attempt to access missing item #" + position);
return null;
@@ -50,12 +53,7 @@ public class GPXListAdapter extends ArrayAdapter<File> {
final ViewHolder holder;
if (view == null) {
view = inflater.inflate(R.layout.gpx_item, null);
-
- holder = new ViewHolder();
- holder.filepath = (TextView) view.findViewById(R.id.filepath);
- holder.filename = (TextView) view.findViewById(R.id.filename);
-
- view.setTag(holder);
+ holder = new ViewHolder(view);
} else {
holder = (ViewHolder) view.getTag();
}
diff --git a/main/src/cgeo/geocaching/utils/CryptUtils.java b/main/src/cgeo/geocaching/utils/CryptUtils.java
index 5ddae96..aecf717 100644
--- a/main/src/cgeo/geocaching/utils/CryptUtils.java
+++ b/main/src/cgeo/geocaching/utils/CryptUtils.java
@@ -37,28 +37,36 @@ public final class CryptUtils {
}
}
+ private static class Rot13Encryption {
+ private boolean plaintext = false;
+
+ char getNextEncryptedCharacter(final char c) {
+ int result = c;
+ if (result == '[') {
+ plaintext = true;
+ } else if (result == ']') {
+ plaintext = false;
+ } else if (!plaintext) {
+ int capitalized = result & 32;
+ result &= ~capitalized;
+ result = ((result >= 'A') && (result <= 'Z') ? ((result - 'A' + 13) % 26 + 'A') : result)
+ | capitalized;
+ }
+ return (char) result;
+ }
+ }
+
public static String rot13(String text) {
if (text == null) {
return "";
}
final StringBuilder result = new StringBuilder();
- // plaintext flag (do not convert)
- boolean plaintext = false;
+ Rot13Encryption rot13 = new Rot13Encryption();
final int length = text.length();
for (int index = 0; index < length; index++) {
- int c = text.charAt(index);
- if (c == '[') {
- plaintext = true;
- } else if (c == ']') {
- plaintext = false;
- } else if (!plaintext) {
- int capitalized = c & 32;
- c &= ~capitalized;
- c = ((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 13) % 26 + 'A') : c)
- | capitalized;
- }
- result.append((char) c);
+ char c = text.charAt(index);
+ result.append(rot13.getNextEncryptedCharacter(c));
}
return result.toString();
}
@@ -111,22 +119,12 @@ public final class CryptUtils {
// a SpannableStringBuilder instead of the pure text and we must replace each character inline.
// Otherwise we loose all the images, colors and so on...
final SpannableStringBuilder buffer = new SpannableStringBuilder(span);
- boolean plaintext = false;
+ Rot13Encryption rot13 = new Rot13Encryption();
final int length = span.length();
for (int index = 0; index < length; index++) {
- int c = span.charAt(index);
- if (c == '[') {
- plaintext = true;
- } else if (c == ']') {
- plaintext = false;
- } else if (!plaintext) {
- int capitalized = c & 32;
- c &= ~capitalized;
- c = ((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 13) % 26 + 'A') : c)
- | capitalized;
- }
- buffer.replace(index, index + 1, String.valueOf((char) c));
+ char c = span.charAt(index);
+ buffer.replace(index, index + 1, String.valueOf(rot13.getNextEncryptedCharacter(c)));
}
return buffer;
}