aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/.factorypath1
-rw-r--r--main/AndroidManifest.xml4
-rw-r--r--main/build.xml93
-rw-r--r--main/compile-libs/androidannotations-2.7.1.jarbin0 -> 555665 bytes
-rw-r--r--main/libs/androidannotations-api-2.7.1.jarbin0 -> 61745 bytes
-rw-r--r--main/project/simian/readme.txt3
-rw-r--r--main/project/simian/simian-2.3.34.jarbin0 -> 103092 bytes
-rw-r--r--main/res/layout/about_activity.xml6
-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
-rw-r--r--tests/res/raw/waymarking_gpx.gpx20
-rw-r--r--tests/res/raw/waymarking_loc.loc8
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java14
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java19
-rw-r--r--tests/src/cgeo/geocaching/utils/CryptUtilsTest.java2
34 files changed, 418 insertions, 216 deletions
diff --git a/main/.factorypath b/main/.factorypath
index d54f9b4..62efc08 100644
--- a/main/.factorypath
+++ b/main/.factorypath
@@ -1,3 +1,4 @@
<factorypath>
<factorypathentry kind="WKSPJAR" id="/cgeo/libs/butterknife-1.3.2.jar" enabled="true" runInBatchMode="false"/>
+ <factorypathentry kind="WKSPJAR" id="/cgeo/compile-libs/androidannotations-2.7.1.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index ef9d3fe..c391fe9 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -93,7 +93,7 @@
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
- android:name=".AboutActivity"
+ android:name=".AboutActivity_"
android:configChanges="keyboardHidden|orientation"
android:label="@string/about"
android:windowSoftInputMode="stateHidden" >
@@ -168,7 +168,7 @@
android:label="@string/map_map" >
</activity>
<activity
- android:name=".StaticMapsActivity"
+ android:name=".StaticMapsActivity_"
android:label="@string/map_static_title" >
</activity>
<activity
diff --git a/main/build.xml b/main/build.xml
index b97a158..2444787 100644
--- a/main/build.xml
+++ b/main/build.xml
@@ -91,13 +91,94 @@
</copy>
</target>
-<!--
- <target name="-pre-compile">
+<!-- start of modifications for android annotations, see https://github.com/excilys/androidannotations/wiki/Building-Project-Ant -->
+ <property name="generated.dir" value="annotation_gen" />
+ <property name="generated.absolute.dir" location="${generated.dir}" />
+ <property name="java.compilerargs" value="-s &apos;${generated.absolute.dir}&apos;" />
+ <target name="-pre-compile">
+ <mkdir dir="${generated.absolute.dir}" />
+ </target>
+ <target name="-compile" depends="-pre-build, -build-setup, -code-gen, -pre-compile">
+ <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
+ <!-- merge the project's own classpath and the tested project's classpath -->
+ <path id="project.javac.classpath">
+ <path refid="project.all.jars.path" />
+ <path refid="tested.project.classpath" />
+ <path path="${java.compiler.classpath}" />
+ <fileset dir="compile-libs" includes="*.jar"/>
+ </path>
+ <javac encoding="${java.encoding}"
+ source="${java.source}" target="${java.target}"
+ debug="true" extdirs="" includeantruntime="false"
+ destdir="${out.classes.absolute.dir}"
+ bootclasspathref="project.target.class.path"
+ verbose="${verbose}"
+ classpathref="project.javac.classpath"
+ fork="${need.javac.fork}">
+ <src path="${source.absolute.dir}" />
+ <src path="${gen.absolute.dir}" />
+ <compilerarg line="${java.compilerargs}" />
+ </javac>
+
+ <!-- if the project is instrumented, intrument the classes -->
+ <if condition="${build.is.instrumented}">
+ <then>
+ <echo level="info">Instrumenting classes from ${out.absolute.dir}/classes...</echo>
+
+ <!-- build the filter to remove R, Manifest, BuildConfig -->
+ <getemmafilter
+ appPackage="${project.app.package}"
+ libraryPackagesRefId="project.library.packages"
+ filterOut="emma.default.filter"/>
+
+ <!-- define where the .em file is going. This may have been
+ setup already if this is a library -->
+ <property name="emma.coverage.absolute.file" location="${out.absolute.dir}/coverage.em" />
+
+ <!-- It only instruments class files, not any external libs -->
+ <emma enabled="true">
+ <instr verbosity="${verbosity}"
+ mode="overwrite"
+ instrpath="${out.absolute.dir}/classes"
+ outdir="${out.absolute.dir}/classes"
+ metadatafile="${emma.coverage.absolute.file}">
+ <filter excludes="${emma.default.filter}" />
+ <filter value="${emma.filter}" />
+ </instr>
+ </emma>
+ </then>
+ </if>
+
+ <!-- if the project is a library then we generate a jar file -->
+ <if condition="${project.is.library}">
+ <then>
+ <echo level="info">Creating library output jar file...</echo>
+ <property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" />
+ <if>
+ <condition>
+ <length string="${android.package.excludes}" trim="true" when="greater" length="0" />
+ </condition>
+ <then>
+ <echo level="info">Custom jar packaging exclusion: ${android.package.excludes}</echo>
+ </then>
+ </if>
+
+ <propertybyreplace name="project.app.package.path" input="${project.app.package}" replace="." with="/" />
+
+ <jar destfile="${out.library.jar.file}">
+ <fileset dir="${out.classes.absolute.dir}"
+ includes="**/*.class"
+ excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/BuildConfig.class"/>
+ <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" />
+ </jar>
+ </then>
+ </if>
+
+ </do-only-if-manifest-hasCode>
</target>
--->
- <!-- This is typically used for code obfuscation.
- Compiled code location: ${out.classes.absolute.dir}
- If this is not done in place, override ${out.dex.input.absolute.dir} -->
+<!-- end of modifications for android-annotations -->
+
+
<!--
<target name="-post-compile">
</target>
diff --git a/main/compile-libs/androidannotations-2.7.1.jar b/main/compile-libs/androidannotations-2.7.1.jar
new file mode 100644
index 0000000..5fb9634
--- /dev/null
+++ b/main/compile-libs/androidannotations-2.7.1.jar
Binary files differ
diff --git a/main/libs/androidannotations-api-2.7.1.jar b/main/libs/androidannotations-api-2.7.1.jar
new file mode 100644
index 0000000..a829474
--- /dev/null
+++ b/main/libs/androidannotations-api-2.7.1.jar
Binary files differ
diff --git a/main/project/simian/readme.txt b/main/project/simian/readme.txt
new file mode 100644
index 0000000..3132e4e
--- /dev/null
+++ b/main/project/simian/readme.txt
@@ -0,0 +1,3 @@
+Simian, the similarity scanner. http://www.harukizaemon.com/simian/features.html
+
+Only used by CI builds, therefore please do not put this into the libs directory. \ No newline at end of file
diff --git a/main/project/simian/simian-2.3.34.jar b/main/project/simian/simian-2.3.34.jar
new file mode 100644
index 0000000..6dd2a8a
--- /dev/null
+++ b/main/project/simian/simian-2.3.34.jar
Binary files differ
diff --git a/main/res/layout/about_activity.xml b/main/res/layout/about_activity.xml
index c13b4b4..4bf9917 100644
--- a/main/res/layout/about_activity.xml
+++ b/main/res/layout/about_activity.xml
@@ -96,6 +96,7 @@
<Button
style="@style/button_full"
+ android:id="@+id/donate"
android:layout_width="280dip"
android:lines="2"
android:onClick="donate"
@@ -140,7 +141,6 @@
android:clickable="true"
android:focusable="true"
android:linksClickable="false"
- android:onClick="website"
android:text="@string/website"
android:textColor="?text_color"
android:textColorLink="?text_color_link"
@@ -157,7 +157,6 @@
android:clickable="true"
android:focusable="true"
android:linksClickable="false"
- android:onClick="facebook"
android:text="@string/facebook"
android:textColor="?text_color"
android:textColorLink="?text_color_link"
@@ -174,7 +173,6 @@
android:clickable="true"
android:focusable="true"
android:linksClickable="false"
- android:onClick="twitter"
android:text="@string/twitter"
android:textColor="?text_color"
android:textColorLink="?text_color_link"
@@ -191,7 +189,6 @@
android:clickable="true"
android:focusable="true"
android:linksClickable="false"
- android:onClick="nutshellmanual"
android:text="@string/nutshellmanual"
android:textColor="?text_color"
android:textColorLink="?text_color_link"
@@ -208,7 +205,6 @@
android:clickable="true"
android:focusable="true"
android:linksClickable="false"
- android:onClick="market"
android:text="@string/market"
android:textColor="?text_color"
android:textColorLink="?text_color_link"
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;
}
diff --git a/tests/res/raw/waymarking_gpx.gpx b/tests/res/raw/waymarking_gpx.gpx
new file mode 100644
index 0000000..5f93da9
--- /dev/null
+++ b/tests/res/raw/waymarking_gpx.gpx
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" creator="Groundspeak, Inc. All Rights Reserved. http://www.groundspeak.com" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd" xmlns="http://www.topografix.com/GPX/1/0">
+ <name>GPX Lite Waymark List Generated from Waymarking.com</name>
+ <desc>A list of waymarks generated from Waymarking.com</desc>
+ <author />
+ <email>contact@waymarking.com</email>
+ <url>http://www.waymarking.com</url>
+ <urlname>Waymarking - Unique and Interesting Locations</urlname>
+ <time>2013-06-08T07:06:36.3821125Z</time>
+ <keywords>waymark</keywords>
+ <bounds minlat="48.86422" minlon="9.1836" maxlat="48.86422" maxlon="9.1836" />
+ <wpt lat="48.86422" lon="9.1836">
+ <name>WM7BM7</name>
+ <desc>Roman water pipe Kornwestheim - A water fountain from an originally Roman water pipe.</desc>
+ <url>http://www.waymarking.com/waymarks/WM7BM7_Roman_water_pipe_Kornwestheim</url>
+ <urlname>Roman water pipe Kornwestheim</urlname>
+ <sym>Waymark</sym>
+ <type>Ancient Roman Civilization</type>
+ </wpt>
+</gpx> \ No newline at end of file
diff --git a/tests/res/raw/waymarking_loc.loc b/tests/res/raw/waymarking_loc.loc
new file mode 100644
index 0000000..caf3f7f
--- /dev/null
+++ b/tests/res/raw/waymarking_loc.loc
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<loc version="1.0" src="Groundspeak, Inc.">
+<waypoint>
+ <name id="WM7BK7"><![CDATA[Römerstrasse Kornwestheim by travelling]]></name>
+ <coord lat="48.856733" lon="9.197683"/>
+ <type>Waymark|Ancient Roman Civilization</type>
+ <link text="Waymark Details">http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim</link>
+</waypoint></loc> \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 8fd962e..5732f9a 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -13,6 +13,8 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
+import org.apache.commons.lang3.StringUtils;
+
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -281,4 +283,16 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
removeCacheCompletely(geocode);
}
+ public void testWaymarking() throws Exception {
+ final List<Geocache> caches = readGPX10(R.raw.waymarking_gpx);
+ assertEquals(1, caches.size());
+ final Geocache waymark = caches.get(0);
+ assertNotNull(waymark);
+ assertEquals("WM7BM7", waymark.getGeocode());
+ assertEquals("Roman water pipe Kornwestheim", waymark.getName());
+ assertTrue(StringUtils.isNotBlank(waymark.getUrl())); // connector must be able to create it
+ assertEquals(CacheType.UNKNOWN, waymark.getType());
+ assertEquals(CacheSize.UNKNOWN, waymark.getSize());
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index bcc8e78..6e00b35 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -2,6 +2,7 @@ package cgeo.geocaching.files;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.enumerations.CacheSize;
+import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
@@ -35,6 +36,7 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase {
assertNotNull(cache);
assertEquals("OC5952", cache.getGeocode());
assertEquals("Die Schatzinsel / treasure island", cache.getName());
+ assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName());
assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords());
}
@@ -45,9 +47,26 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase {
assertNotNull(cache);
assertEquals("GC1BKP3", cache.getGeocode());
assertEquals("Die Schatzinsel / treasure island", cache.getName());
+ assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName());
assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords());
assertEquals(1.0f, cache.getDifficulty());
assertEquals(5.0f, cache.getTerrain());
assertEquals(CacheSize.MICRO, cache.getSize());
}
+
+ public void testWaymarkingLoc() throws IOException, ParserException {
+ final List<Geocache> waymarks = readLoc(R.raw.waymarking_loc);
+ assertEquals(1, waymarks.size());
+ final Geocache waymark = waymarks.get(0);
+ assertNotNull(waymark);
+ assertEquals("WM7BK7", waymark.getGeocode());
+ assertEquals("Römerstrasse Kornwestheim", waymark.getName());
+ assertEquals("travelling", waymark.getOwnerDisplayName());
+ assertEquals(new Geopoint(48.856733, 9.197683), waymark.getCoords());
+ // links are not yet stored for single caches
+ // assertEquals("http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim", waymark.getUrl());
+ assertEquals(CacheSize.UNKNOWN, waymark.getSize());
+ assertEquals(CacheType.UNKNOWN, waymark.getType());
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
index fff24f2..e727747 100644
--- a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
@@ -9,6 +9,8 @@ public class CryptUtilsTest extends TestCase {
assertEquals("", CryptUtils.rot13(""));
assertEquals("", CryptUtils.rot13((String) null));
assertEquals("Pnpur uvag", CryptUtils.rot13("Cache hint"));
+ assertEquals("Pnpur [plain] uvag", CryptUtils.rot13("Cache [plain] hint"));
+ assertEquals("[all plain]", CryptUtils.rot13("[all plain]"));
assertEquals("123", CryptUtils.rot13("123"));
}