aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer <rschum@web.de>2011-08-02 09:56:06 +0200
committerRainer <rschum@web.de>2011-08-02 09:56:06 +0200
commitc153cf1a0c86480568f0aea016fa0428689a1dc2 (patch)
tree0d7d5318e312f684a77bb3c66eb7cfb819d026c1
parent62e208f0dbdecfae56694bb359267df1d146b594 (diff)
parent6118f6489847f98d2c257671c352082974134b14 (diff)
downloadcgeo-c153cf1a0c86480568f0aea016fa0428689a1dc2.zip
cgeo-c153cf1a0c86480568f0aea016fa0428689a1dc2.tar.gz
cgeo-c153cf1a0c86480568f0aea016fa0428689a1dc2.tar.bz2
Merge branch 'master' of https://github.com/cgeo/c-geo-opensource
Conflicts: src/cgeo/geocaching/cgeospoilers.java
-rw-r--r--AndroidManifest.xml2
-rw-r--r--res/drawable/log_img.pngbin0 -> 419 bytes
-rw-r--r--res/layout/cache_image_item.xml (renamed from res/layout/spoiler_item.xml)0
-rw-r--r--res/layout/init.xml21
-rw-r--r--res/layout/log_img.xml20
-rw-r--r--res/layout/log_item.xml27
-rw-r--r--res/values/strings.xml6
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/RadarApp.java2
-rw-r--r--src/cgeo/geocaching/cgBase.java162
-rw-r--r--src/cgeo/geocaching/cgCache.java31
-rw-r--r--src/cgeo/geocaching/cgData.java89
-rw-r--r--src/cgeo/geocaching/cgHtmlImg.java50
-rw-r--r--src/cgeo/geocaching/cgImage.java (renamed from src/cgeo/geocaching/cgSpoiler.java)2
-rw-r--r--src/cgeo/geocaching/cgLog.java3
-rw-r--r--src/cgeo/geocaching/cgSettings.java68
-rw-r--r--src/cgeo/geocaching/cgeoapplication.java2
-rw-r--r--src/cgeo/geocaching/cgeodetail.java40
-rw-r--r--src/cgeo/geocaching/cgeoimages.java (renamed from src/cgeo/geocaching/cgeospoilers.java)163
-rw-r--r--src/cgeo/geocaching/cgeoinit.java115
-rw-r--r--src/cgeo/geocaching/googlemaps/googleMapView.java13
-rw-r--r--src/cgeo/geocaching/mapcommon/cgeomap.java58
-rw-r--r--src/cgeo/geocaching/sorting/SizeComparator.java2
22 files changed, 535 insertions, 341 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c3b0a52..2db95f5 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -193,7 +193,7 @@
</intent-filter>
</activity>
<activity
- android:name=".cgeospoilers"
+ android:name=".cgeoimages"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
diff --git a/res/drawable/log_img.png b/res/drawable/log_img.png
new file mode 100644
index 0000000..09e4037
--- /dev/null
+++ b/res/drawable/log_img.png
Binary files differ
diff --git a/res/layout/spoiler_item.xml b/res/layout/cache_image_item.xml
index 9913a8f..9913a8f 100644
--- a/res/layout/spoiler_item.xml
+++ b/res/layout/cache_image_item.xml
diff --git a/res/layout/init.xml b/res/layout/init.xml
index 3bcdba5..8ea63f3 100644
--- a/res/layout/init.xml
+++ b/res/layout/init.xml
@@ -387,6 +387,27 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
+ <CheckBox android:id="@+id/save_log_img"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_gravity="left"
+ android:padding="1px"
+ android:gravity="center" />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:gravity="left"
+ android:paddingRight="3dip"
+ android:textSize="14dip"
+ android:textColor="?text_color"
+ android:text="@string/init_save_log_img" />
+ </LinearLayout>
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
<CheckBox android:id="@+id/units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/res/layout/log_img.xml b/res/layout/log_img.xml
new file mode 100644
index 0000000..483323f
--- /dev/null
+++ b/res/layout/log_img.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ImageView
+ android:layout_height="wrap_content"
+ android:src="@drawable/log_img"
+ android:layout_width="wrap_content"/>
+ <TextView
+ android:id="@+id/title"
+ android:text="TextView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_gravity="left|top"
+ android:textSize="14dip"
+ android:layout_marginLeft="2dip"
+ android:textColor="?text_color"/>
+</LinearLayout>
diff --git a/res/layout/log_item.xml b/res/layout/log_item.xml
index 3af56e0..8f94082 100644
--- a/res/layout/log_item.xml
+++ b/res/layout/log_item.xml
@@ -90,15 +90,22 @@
android:layout_marginBottom="2dip"
android:scaleType="fitXY"
android:src="@drawable/mark_red_more" />
+ </LinearLayout>
+ <LinearLayout android:id="@+id/log_layout"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:orientation="vertical"
+ android:padding="3dip"
+ android:textSize="14dip"
+ android:layout_marginLeft="84dip">
+ <TextView android:id="@+id/log"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="22dip"
+ android:layout_gravity="left"
+ android:gravity="left"
+ android:padding="3dip"
+ android:textSize="14dip"
+ android:textColor="?text_color" />
</LinearLayout>
- <TextView android:id="@+id/log"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="22dip"
- android:layout_marginLeft="82dip"
- android:layout_gravity="left"
- android:gravity="left"
- android:padding="3dip"
- android:textSize="14dip"
- android:textColor="?text_color" />
</RelativeLayout> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2715581..2509377 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -204,6 +204,8 @@
<string name="warn_search_help_user">Fill name of user at Geocaching.com.</string>
<string name="warn_search_help_tb">Fill code of trackable. For example \"TB29QMZ\".</string>
<string name="warn_log_text_fill">Please, fill some log text.</string>
+ <string name="warn_load_log_image">Sorry, c:geo failed to load log image.</string>
+ <string name="warn_load_spoiler_image">Sorry, c:geo failed to load spoiler image.</string>
<string name="info_altitude">Current altitude</string>
<string name="info_distance">Distance traveled</string>
@@ -388,6 +390,7 @@
<string name="init_exclude">Exclude own and found caches</string>
<string name="init_disabled">Exclude disabled caches</string>
<string name="init_offline">Store static maps for offline use</string>
+ <string name="init_save_log_img">Save Images from Logs</string>
<string name="init_units">Use miles/feet\n(imperial units)</string>
<string name="init_nav">Use Google Navigation</string>
<string name="init_autoload">Auto-loading long description</string>
@@ -464,6 +467,9 @@
<string name="cache_attributes">Attributes</string>
<string name="cache_inventory">Inventory</string>
<string name="cache_log_offline">Offline log</string>
+ <string name="cache_log_images_loading">Loading log Image ...</string>
+ <string name="cache_log_images_title">Logimage</string>
+ <string name="cache_log_image_default_title">Photo</string>
<string name="cache_description">Description</string>
<string name="cache_description_long">Long description</string>
<string name="cache_watchlist">Watchlist</string>
diff --git a/src/cgeo/geocaching/apps/cache/navi/RadarApp.java b/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
index 95cc23b..5bb1e6c 100644
--- a/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
@@ -24,7 +24,7 @@ class RadarApp extends AbstractNavigationApp implements NavigationApp {
return true; // seems like Radar is assumed to be available always
}
- private void navigateTo(Activity activity, Double latitude, Double longitude) {
+ private static void navigateTo(Activity activity, Double latitude, Double longitude) {
Intent radarIntent = new Intent(INTENT);
radarIntent.putExtra("latitude", Float.valueOf(latitude.floatValue()));
radarIntent.putExtra("longitude", Float.valueOf(longitude.floatValue()));
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index b17c7f8..3a5c3b6 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -95,7 +95,7 @@ public class cgBase {
public static DateFormat dateOutShort = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
private Resources res = null;
private HashMap<String, String> cookies = new HashMap<String, String>();
- private final String passMatch = "[/\\?&]*[Pp]ass(word)?=[^&^#^$]+";
+ private static final String passMatch = "[/\\?&]*[Pp]ass(word)?=[^&^#^$]+";
private final Pattern patternLoggedIn = Pattern.compile("<span class=\"Success\">You are logged in as[^<]*<strong[^>]*>([^<]+)</strong>[^<]*</span>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
private final Pattern patternLogged2In = Pattern.compile("<strong>[^\\w]*Hello,[^<]*<a[^>]+>([^<]+)</a>[^<]*</strong>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
private final Pattern patternViewstate = Pattern.compile("id=\"__VIEWSTATE\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
@@ -104,9 +104,6 @@ public class cgBase {
public static final double deg2rad = Math.PI / 180;
public static final double rad2deg = 180 / Math.PI;
public static final float erad = 6371.0f;
- public static final int mapAppAny = 0;
- public static final int mapAppLocus = 1;
- public static final int mapAppRmaps = 2;
private cgeoapplication app = null;
private cgSettings settings = null;
private SharedPreferences prefs = null;
@@ -1099,6 +1096,7 @@ public class cgBase {
final Pattern patternCountLog = Pattern.compile(" src=\"\\/images\\/icons\\/([^\\.]*).gif\" alt=\"[^\"]*\" title=\"[^\"]*\" />([0-9]*)[^0-9]+", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
final Pattern patternLogs = Pattern.compile("<table class=\"LogsTable[^\"]*\"[^>]*>[^<]*<tr>(.*)</tr>[^<]*</table>[^<]*<p", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
final Pattern patternLog = Pattern.compile("<td[^>]*>[^<]*<strong>[^<]*<img src=\"[^\"]*/images/icons/([^\\.]+)\\.[a-z]{2,5}\"[^>]*>&nbsp;([a-zA-Z]+) (\\d+)(, (\\d+))? by <a href=[^>]+>([^<]+)</a>[<^]*</strong>([^\\(]*\\((\\d+) found\\))?(<br[^>]*>)+((?:(?!<small>).)*)(<br[^>]*>)+<small>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ final Pattern patternLogImgs = Pattern.compile("a href=\"http://img.geocaching.com/cache/log/([^\"]+)\".+?<span>([^<]*)", Pattern.CASE_INSENSITIVE);
final Pattern patternAttributes = Pattern.compile("<h3 class=\"WidgetHeader\">[^<]*<img[^>]+>[^\\w]*Attributes[^<]*</h3>[^<]*<div class=\"WidgetBody\">(([^<]*<img src=\"[^\"]+\" alt=\"[^\"]+\"[^>]*>)+)[^<]*<p", Pattern.CASE_INSENSITIVE);
final Pattern patternAttributesInside = Pattern.compile("[^<]*<img src=\"([^\"]+)\" alt=\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE);
final Pattern patternSpoilers = Pattern.compile("<span id=\"ctl00_ContentBody_Images\">((<a href=\"[^\"]+\"[^>]*>[^<]*<img[^>]+>[^<]*<span>[^>]+</span>[^<]*</a>[^<]*<br[^>]*>([^<]*(<br[^>]*>)+)?)+)[^<]*</span>", Pattern.CASE_INSENSITIVE);
@@ -1513,7 +1511,7 @@ public class cgBase {
while (matcherSpoilersInside.find()) {
if (matcherSpoilersInside.groupCount() > 0) {
- final cgSpoiler spoiler = new cgSpoiler();
+ final cgImage spoiler = new cgImage();
spoiler.url = matcherSpoilersInside.group(1);
if (matcherSpoilersInside.group(2) != null) {
@@ -1524,7 +1522,7 @@ public class cgBase {
}
if (cache.spoilers == null) {
- cache.spoilers = new ArrayList<cgSpoiler>();
+ cache.spoilers = new ArrayList<cgImage>();
}
cache.spoilers.add(spoiler);
}
@@ -1695,6 +1693,19 @@ public class cgBase {
if (matcherLog.group(8) != null) {
logDone.found = new Integer(matcherLog.group(8));
}
+
+ final Matcher matcherImg = patternLogImgs.matcher(logs[k]);
+
+ while (matcherImg.find()) {
+ final cgImage logImage = new cgImage();
+ logImage.url = "http://img.geocaching.com/cache/log/" + matcherImg.group(1);
+ logImage.title = matcherImg.group(2);
+ if (logDone.logImages == null) {
+ logDone.logImages = new ArrayList<cgImage>();
+ }
+ logDone.logImages.add(logImage);
+ }
+
logDone.log = logTmp;
if (cache.logs == null) {
@@ -1877,7 +1888,7 @@ public class cgBase {
return caches;
}
- private Date parseDate(String input) {
+ private static Date parseDate(String input) {
if (input == null) {
return null;
}
@@ -3967,7 +3978,7 @@ public class cgBase {
return -1; // error
}
- boolean guidOnPage = checkPageForGuid(cache, page);
+ boolean guidOnPage = cache.isGuidContainedInPage(page);
if (guidOnPage) {
Log.i(cgSettings.tag, "cgBase.addToWatchlist: cache is on watchlist");
cache.onWatchlist = true;
@@ -4008,7 +4019,7 @@ public class cgBase {
params.put("ctl00$ContentBody$btnYes", "Yes");
page = request(false, host, path, method, params, false, false, false).getData();
- boolean guidOnPage = checkPageForGuid(cache, page);
+ boolean guidOnPage = cache.isGuidContainedInPage(page);
if (! guidOnPage) {
Log.i(cgSettings.tag, "cgBase.removeFromWatchlist: cache removed from watchlist");
cache.onWatchlist = false;
@@ -4018,29 +4029,6 @@ public class cgBase {
return guidOnPage ? -1 : 0; // on watchlist (=error) / not on watchlist
}
- /**
- * checks if a page contains the guid of a cache
- *
- * @param cache the cache to look for
- * @param page the page to search in
- *
- * @return true: page contains guid of cache, false: otherwise
- */
- private boolean checkPageForGuid(cgCache cache, String page) {
- // check if the guid of the cache is anywhere in the page
- if (cache.guid == null || cache.guid.length() == 0)
- return false;
- Pattern patternOk = Pattern.compile(cache.guid, Pattern.CASE_INSENSITIVE);
- Matcher matcherOk = patternOk.matcher(page);
- if (matcherOk.find()) {
- Log.i(cgSettings.tag, "cgBase.checkPageForGuid: guid '" + cache.guid + "' found");
- return true;
- } else {
- Log.i(cgSettings.tag, "cgBase.checkPageForGuid: guid '" + cache.guid + "' not found");
- return false;
- }
- }
-
final public static HostnameVerifier doNotVerify = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
@@ -4181,7 +4169,7 @@ public class cgBase {
}
}
- private void readIntoBuffer(BufferedReader br, StringBuffer buffer) throws IOException {
+ private static void readIntoBuffer(BufferedReader br, StringBuffer buffer) throws IOException {
int bufferSize = 1024*16;
char[] bytes = new char[bufferSize];
int bytesRead;
@@ -4195,99 +4183,6 @@ public class cgBase {
}
}
- /*
- public ArrayList<String> translate(ArrayList<String> text, String target) {
- if (settings.translate == false) {
- return text;
- }
-
- String[] languages = null;
- if (settings.languages != null) {
- languages = settings.languages.split(" ");
- }
-
- ArrayList<String> translated = new ArrayList<String>();
- String language = null;
-
- if (text == null || text.isEmpty()) {
- return text;
- }
-
- // cut to 5000 characters (limitation of Google Translation API)
- for (String textOne : text) {
- int len = urlencode_rfc3986(textOne).length();
- if (len > 5000) {
- textOne = Html.fromHtml(textOne).toString();
- len = urlencode_rfc3986(textOne).length();
-
- if (len > 5000) {
- int cut = 2000;
- if (textOne.length() > cut) {
- cut = 1000;
- }
-
- textOne = textOne.substring(0, cut) + "...";
- }
- }
- }
-
- try {
- if (target == null) {
- final Locale locale = Locale.getDefault();
- target = locale.getLanguage();
- }
-
- final String scheme = "https://";
- final String host = "www.googleapis.com";
- final String path = "/language/translate/v2";
-
- final ArrayList<String> params = new ArrayList<String>();
- params.add("key=" + urlencode_rfc3986("AIzaSyAJH8x5etFHUbFifmgChlWoCVmwBFSwShQ"));
- params.add("target=" + urlencode_rfc3986(target));
- for (String textOne : text) {
- params.add("q=" + urlencode_rfc3986(textOne));
- }
- params.add("format=" + urlencode_rfc3986("html"));
-
- String page = requestJSON(scheme, host, path, "POST", implode("&", params.toArray()));
-
- if (page == null || page.length() == 0) {
- return text;
- }
-
- JSONObject json = new JSONObject(page);
- JSONObject jsonData = json.getJSONObject("data");
- JSONArray jsonTranslations = jsonData.getJSONArray("translations");
- int translationCnt = jsonTranslations.length();
-
- for (int i = 0; i < translationCnt; i ++) {
- JSONObject jsonTranslation = jsonTranslations.getJSONObject(i);
- language = jsonTranslation.getString("detectedSourceLanguage");
-
- boolean toTranslate = true;
- if (languages != null) {
- for (String lng : languages) {
- if (lng.equalsIgnoreCase(language)) {
- toTranslate = false;
- }
- }
- }
-
- if (toTranslate == false) {
- translated.add(text.get(i));
- } else {
- Log.i(cgSettings.tag, "Translating #" + i + ": " + language + ">" + target);
- translated.add(jsonTranslation.getString("translatedText"));
- }
- }
- } catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.translate: " + e.toString());
- }
-
- return translated;
- }
- */
-
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
@@ -4671,7 +4566,7 @@ public class cgBase {
return response;
}
- private String replaceWhitespace(final StringBuffer buffer) {
+ private static String replaceWhitespace(final StringBuffer buffer) {
final int length = buffer.length();
final char[] bytes = new char[length];
buffer.getChars(0, length, bytes, 0);
@@ -5135,10 +5030,21 @@ public class cgBase {
// store spoilers
if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
- for (cgSpoiler oneSpoiler : cache.spoilers) {
+ for (cgImage oneSpoiler : cache.spoilers) {
imgGetter.getDrawable(oneSpoiler.url);
}
}
+
+ // store images from logs
+ if (settings.storelogimages == true) {
+ for (cgLog log : cache.logs) {
+ if (log.logImages != null && log.logImages.isEmpty() == false) {
+ for (cgImage oneLogImg : log.logImages) {
+ imgGetter.getDrawable(oneLogImg.url);
+ }
+ }
+ }
+ }
// store map previews
if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java
index 8b2bb00..a878a1f 100644
--- a/src/cgeo/geocaching/cgCache.java
+++ b/src/cgeo/geocaching/cgCache.java
@@ -3,8 +3,11 @@ package cgeo.geocaching;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import android.text.Spannable;
+import android.util.Log;
public class cgCache {
@@ -52,7 +55,7 @@ public class cgCache {
public boolean onWatchlist = false;
public ArrayList<String> attributes = null;
public ArrayList<cgWaypoint> waypoints = null;
- public ArrayList<cgSpoiler> spoilers = null;
+ public ArrayList<cgImage> spoilers = null;
public ArrayList<cgLog> logs = null;
public ArrayList<cgTrackable> inventory = null;
public HashMap<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
@@ -233,4 +236,30 @@ public class cgCache {
}
return true;
}
+
+ /**
+ * checks if a page contains the guid of a cache
+ *
+ * @param cache the cache to look for
+ * @param page the page to search in
+ *
+ * @return true: page contains guid of cache, false: otherwise
+ */
+ boolean isGuidContainedInPage(final String page) {
+ // check if the guid of the cache is anywhere in the page
+ if (guid == null || guid.length() == 0) {
+ return false;
+ }
+ Pattern patternOk = Pattern.compile(guid, Pattern.CASE_INSENSITIVE);
+ Matcher matcherOk = patternOk.matcher(page);
+ if (matcherOk.find()) {
+ Log.i(cgSettings.tag, "cgCache.isGuidContainedInPage: guid '" + guid + "' found");
+ return true;
+ } else {
+ Log.i(cgSettings.tag, "cgCache.isGuidContainedInPage: guid '" + guid + "' not found");
+ return false;
+ }
+ }
+
+
}
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java
index 421ab41..c8c98a0 100644
--- a/src/cgeo/geocaching/cgData.java
+++ b/src/cgeo/geocaching/cgData.java
@@ -33,7 +33,7 @@ public class cgData {
private cgDbHelper dbHelper = null;
private SQLiteDatabase databaseRO = null;
private SQLiteDatabase databaseRW = null;
- private static final int dbVersion = 53;
+ private static final int dbVersion = 54;
private static final String dbName = "data";
private static final String dbTableCaches = "cg_caches";
private static final String dbTableLists = "cg_lists";
@@ -42,6 +42,7 @@ public class cgData {
private static final String dbTableSpoilers = "cg_spoilers";
private static final String dbTableLogs = "cg_logs";
private static final String dbTableLogCount = "cg_logCount";
+ private static final String dbTableLogImages = "cg_logImages";
private static final String dbTableLogsOffline = "cg_logs_offline";
private static final String dbTableTrackables = "cg_trackables";
private static final String dbTableSearchDestionationHistory = "cg_search_destination_history";
@@ -151,6 +152,13 @@ public class cgData {
+ "type integer not null default 4, "
+ "count integer not null default 0 "
+ "); ";
+ private static final String dbCreateLogImages = ""
+ + "create table " + dbTableLogImages + " ("
+ + "_id integer primary key autoincrement, "
+ + "log_id integer not null, "
+ + "title text not null, "
+ + "url text not null"
+ + "); ";
private static final String dbCreateLogsOffline = ""
+ "create table " + dbTableLogsOffline + " ("
+ "_id integer primary key autoincrement, "
@@ -397,6 +405,7 @@ public class cgData {
db.execSQL(dbCreateSpoilers);
db.execSQL(dbCreateLogs);
db.execSQL(dbCreateLogCount);
+ db.execSQL(dbCreateLogImages);
db.execSQL(dbCreateLogsOffline);
db.execSQL(dbCreateTrackables);
db.execSQL(dbCreateSearchDestinationHistory);
@@ -701,7 +710,7 @@ public class cgData {
Log.e(cgSettings.tag, "Failed to upgrade to ver. 51: " + e.toString());
}
}
-
+
if (oldVersion < 52) { // upgrade to 52
try {
db.execSQL(dbCreateSearchDestinationHistory);
@@ -711,7 +720,7 @@ public class cgData {
Log.e(cgSettings.tag, "Failed to upgrade to ver. 52", e);
}
}
-
+
if (oldVersion < 53) { // upgrade to 53
try {
db.execSQL("alter table " + dbTableCaches + " add column onWatchlist integer");
@@ -721,6 +730,15 @@ public class cgData {
Log.e(cgSettings.tag, "Failed to upgrade to ver. 53", e);
}
}
+
+ if (oldVersion < 54) { // update to 54
+ try {
+ db.execSQL(dbCreateLogImages);
+ } catch (Exception e) {
+ Log.e(cgSettings.tag, "Failed to upgrade to ver. 54: " + e.toString());
+
+ }
+ }
}
db.setTransactionSuccessful();
@@ -1386,7 +1404,7 @@ public class cgData {
return false;
}
- public boolean saveSpoilers(String geocode, ArrayList<cgSpoiler> spoilers) {
+ public boolean saveSpoilers(String geocode, ArrayList<cgImage> spoilers) {
init();
if (geocode == null || geocode.length() == 0 || spoilers == null) {
@@ -1399,7 +1417,7 @@ public class cgData {
if (!spoilers.isEmpty()) {
ContentValues values = new ContentValues();
- for (cgSpoiler oneSpoiler : spoilers) {
+ for (cgImage oneSpoiler : spoilers) {
values.clear();
values.put("geocode", geocode);
values.put("updated", System.currentTimeMillis());
@@ -1446,8 +1464,18 @@ public class cgData {
values.put("log", oneLog.log);
values.put("date", oneLog.date);
values.put("found", oneLog.found);
-
- databaseRW.insert(dbTableLogs, null, values);
+
+ long log_id = databaseRW.insert(dbTableLogs, null, values);
+
+ if ((oneLog.logImages != null) && (oneLog.logImages.size() > 0)) {
+ for (cgImage img : oneLog.logImages) {
+ values.clear();
+ values.put("log_id", log_id);
+ values.put("title", img.title);
+ values.put("url", img.url);
+ databaseRW.insert(dbTableLogImages, null, values);
+ }
+ }
}
}
databaseRW.setTransactionSuccessful();
@@ -1837,10 +1865,10 @@ public class cgData {
}
if (loadS == true) {
- ArrayList<cgSpoiler> spoilers = loadSpoilers(cache.geocode);
+ ArrayList<cgImage> spoilers = loadSpoilers(cache.geocode);
if (spoilers != null && spoilers.isEmpty() == false) {
if (cache.spoilers == null)
- cache.spoilers = new ArrayList<cgSpoiler>();
+ cache.spoilers = new ArrayList<cgImage>();
else
cache.spoilers.clear();
cache.spoilers.addAll(spoilers);
@@ -2049,7 +2077,7 @@ public class cgData {
return waypoints;
}
- public ArrayList<cgSpoiler> loadSpoilers(String geocode) {
+ public ArrayList<cgImage> loadSpoilers(String geocode) {
init();
if (geocode == null || geocode.length() == 0) {
@@ -2057,7 +2085,7 @@ public class cgData {
}
Cursor cursor = null;
- ArrayList<cgSpoiler> spoilers = new ArrayList<cgSpoiler>();
+ ArrayList<cgImage> spoilers = new ArrayList<cgImage>();
cursor = databaseRO.query(
dbTableSpoilers,
@@ -2073,7 +2101,7 @@ public class cgData {
cursor.moveToFirst();
do {
- cgSpoiler spoiler = new cgSpoiler();
+ cgImage spoiler = new cgImage();
spoiler.url = (String) cursor.getString(cursor.getColumnIndex("url"));
spoiler.title = (String) cursor.getString(cursor.getColumnIndex("title"));
spoiler.description = (String) cursor.getString(cursor.getColumnIndex("description"));
@@ -2175,7 +2203,8 @@ public class cgData {
log.log = (String) cursor.getString(cursor.getColumnIndex("log"));
log.date = (long) cursor.getLong(cursor.getColumnIndex("date"));
log.found = (int) cursor.getInt(cursor.getColumnIndex("found"));
-
+ log.logImages = loadLogImages(log.id);
+
logs.add(log);
} while (cursor.moveToNext());
}
@@ -2224,6 +2253,40 @@ public class cgData {
return logCounts;
}
+
+ public ArrayList<cgImage> loadLogImages(int log_id) {
+ init();
+
+ ArrayList<cgImage> logImgList = new ArrayList<cgImage>();
+
+ Cursor cursor = null;
+ cursor = databaseRO.query(
+ dbTableLogImages,
+ new String[]{"_id", "log_id", "title", "url"},
+ "log_id = \"" + log_id + "\"",
+ null,
+ null,
+ null,
+ null,
+ "100");
+
+ if (cursor != null && cursor.getCount() > 0) {
+ cursor.moveToFirst();
+
+ do {
+ final cgImage log_img = new cgImage();
+ log_img.title = (String)cursor.getString(cursor.getColumnIndex("title"));
+ log_img.url = (String)cursor.getString(cursor.getColumnIndex("url"));
+ logImgList.add(log_img);
+ } while (cursor.moveToNext());
+ }
+
+ if (cursor != null) {
+ cursor.close();
+ }
+
+ return logImgList;
+ }
public ArrayList<cgTrackable> loadInventory(String geocode) {
init();
diff --git a/src/cgeo/geocaching/cgHtmlImg.java b/src/cgeo/geocaching/cgHtmlImg.java
index 023912a..645e9d2 100644
--- a/src/cgeo/geocaching/cgHtmlImg.java
+++ b/src/cgeo/geocaching/cgHtmlImg.java
@@ -31,6 +31,7 @@ public class cgHtmlImg implements Html.ImageGetter {
private boolean placement = true;
private int reason = 0;
private boolean onlySave = false;
+ private boolean save = true;
private BitmapFactory.Options bfOptions = new BitmapFactory.Options();
private Display display = null;
private int maxWidth = 0;
@@ -38,20 +39,25 @@ public class cgHtmlImg implements Html.ImageGetter {
private double ratio = 1.0d;
private int width = 0;
private int height = 0;
-
+
public cgHtmlImg(Activity activityIn, cgSettings settingsIn, String geocodeIn, boolean placementIn, int reasonIn, boolean onlySaveIn) {
+ this(activityIn, settingsIn, geocodeIn, placementIn, reasonIn, onlySaveIn, true);
+ }
+
+ public cgHtmlImg(Activity activityIn, cgSettings settingsIn, String geocodeIn, boolean placementIn, int reasonIn, boolean onlySaveIn, boolean saveIn) {
activity = activityIn;
settings = settingsIn;
geocode = geocodeIn;
placement = placementIn;
reason = reasonIn;
onlySave = onlySaveIn;
+ save = saveIn;
bfOptions.inTempStorage = new byte[16 * 1024];
display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
maxWidth = display.getWidth() - 25;
- maxHeight = display.getHeight() - 25;
+ maxHeight = display.getHeight() - 25;
}
@Override
@@ -212,27 +218,29 @@ public class cgHtmlImg implements Html.ImageGetter {
}
}
- try {
- // save to memory/SD cache
- if (bufferedEntity != null) {
- final InputStream is = (InputStream) bufferedEntity.getContent();
- final FileOutputStream fos = new FileOutputStream(fileName);
- try {
- final byte[] buffer = new byte[4096];
- int l;
- while ((l = is.read(buffer)) != -1) {
- fos.write(buffer, 0, l);
+ if (save == true) {
+ try {
+ // save to memory/SD cache
+ if (bufferedEntity != null) {
+ final InputStream is = (InputStream) bufferedEntity.getContent();
+ final FileOutputStream fos = new FileOutputStream(fileName);
+ try {
+ final byte[] buffer = new byte[4096];
+ int l;
+ while ((l = is.read(buffer)) != -1) {
+ fos.write(buffer, 0, l);
+ }
+ } catch (IOException e) {
+ Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (saving to cache): " + e.toString());
+ } finally {
+ is.close();
+ fos.flush();
+ fos.close();
}
- } catch (IOException e) {
- Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (saving to cache): " + e.toString());
- } finally {
- is.close();
- fos.flush();
- fos.close();
}
+ } catch (Exception e) {
+ Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (saving to cache): " + e.toString());
}
- } catch (Exception e) {
- Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (saving to cache): " + e.toString());
}
entity = null;
@@ -282,5 +290,5 @@ public class cgHtmlImg implements Html.ImageGetter {
image.setBounds(new Rect(0, 0, width, height));
return image;
- }
+ }
}
diff --git a/src/cgeo/geocaching/cgSpoiler.java b/src/cgeo/geocaching/cgImage.java
index fca5648..260bf15 100644
--- a/src/cgeo/geocaching/cgSpoiler.java
+++ b/src/cgeo/geocaching/cgImage.java
@@ -1,6 +1,6 @@
package cgeo.geocaching;
-public class cgSpoiler {
+public class cgImage {
public String url = "";
public String title = "";
public String description = "";
diff --git a/src/cgeo/geocaching/cgLog.java b/src/cgeo/geocaching/cgLog.java
index 5b1b44a..2d77a3d 100644
--- a/src/cgeo/geocaching/cgLog.java
+++ b/src/cgeo/geocaching/cgLog.java
@@ -1,5 +1,7 @@
package cgeo.geocaching;
+import java.util.ArrayList;
+
public class cgLog {
public int id = 0;
public int type = 4; // note
@@ -7,6 +9,7 @@ public class cgLog {
public String log = "";
public long date = 0;
public int found = -1;
+ public ArrayList<cgImage> logImages = null;
public String cacheName = ""; // used for trackables
public String cacheGuid = ""; // used for trackables
}
diff --git a/src/cgeo/geocaching/cgSettings.java b/src/cgeo/geocaching/cgSettings.java
index 97e8c5c..9b5a2e0 100644
--- a/src/cgeo/geocaching/cgSettings.java
+++ b/src/cgeo/geocaching/cgSettings.java
@@ -1,23 +1,23 @@
package cgeo.geocaching;
+import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.HashMap;
import org.mapsforge.android.maps.MapDatabase;
-import cgeo.geocaching.googlemaps.googleMapFactory;
-import cgeo.geocaching.mapinterfaces.MapFactory;
-import cgeo.geocaching.mapsforge.mfMapFactory;
-import android.os.Environment;
-import android.content.Intent;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
+import android.os.Environment;
import android.util.Log;
+import cgeo.geocaching.googlemaps.googleMapFactory;
+import cgeo.geocaching.mapinterfaces.MapFactory;
+import cgeo.geocaching.mapsforge.mfMapFactory;
public class cgSettings {
-
+
public enum mapSourceEnum {
googleMap,
googleSat,
@@ -25,7 +25,7 @@ public class cgSettings {
mapsforgeOsmarender,
mapsforgeCycle,
mapsforgeOffline;
-
+
static mapSourceEnum fromInt(int id) {
mapSourceEnum[] values = mapSourceEnum.values();
if (id >= 0 && id < values.length) {
@@ -39,11 +39,11 @@ public class cgSettings {
if (googleMap == this || googleSat == this) {
return true;
}
-
+
return false;
}
}
-
+
// constants
public final static int unitsMetric = 1;
public final static int unitsImperial = 2;
@@ -62,7 +62,7 @@ public class cgSettings {
public int buttonActive = R.drawable.action_button_dark;
public int buttonInactive = R.drawable.action_button_dark_off;
public int buttonPressed = R.drawable.action_button_dark_pressed;
-
+
// settings
public boolean loaded = false;
public boolean hideMySearch = false;
@@ -81,6 +81,7 @@ public class cgSettings {
public int excludeMine = 0;
public int excludeDisabled = 0;
public int storeOfflineMaps = 0;
+ public boolean storelogimages = false;
public int asBrowser = 1;
public int useCompass = 1;
public int useGNavigation = 1;
@@ -109,7 +110,7 @@ public class cgSettings {
private String username = null;
private String password = null;
private String passVote = null;
-
+
// maps
public MapFactory mapFactory = null;
public mapSourceEnum mapSourceUsed = mapSourceEnum.googleMap;
@@ -129,7 +130,7 @@ public class cgSettings {
initialized = prefs.getInt("initialized", 0);
helper = prefs.getInt("helper", 0);
-
+
skin = prefs.getInt("skin", 0);
setSkinDefaults();
@@ -146,6 +147,7 @@ public class cgSettings {
excludeMine = prefs.getInt("excludemine", 0);
excludeDisabled = prefs.getInt("excludedisabled", 0);
storeOfflineMaps = prefs.getInt("offlinemaps", 1);
+ storelogimages = prefs.getBoolean("logimages", false);
asBrowser = prefs.getInt("asbrowser", 1);
useCompass = prefs.getInt("usecompass", 1);
useGNavigation = prefs.getInt("usegnav", 1);
@@ -164,10 +166,10 @@ public class cgSettings {
webDeviceCode = prefs.getString("webDeviceCode", null);
trackableAutovisit = prefs.getBoolean("trackautovisit", false);
signatureAutoinsert = prefs.getBoolean("sigautoinsert", false);
-
+
setLanguage(useEnglish);
}
-
+
private void setSkinDefaults() {
if (skin == 1) {
buttonActive = R.drawable.action_button_light;
@@ -190,7 +192,7 @@ public class cgSettings {
setSkinDefaults();
}
}
-
+
public void setLanguage(boolean useEnglish) {
Locale locale = Locale.getDefault();
if (useEnglish) {
@@ -306,7 +308,7 @@ public class cgSettings {
this.username = username;
this.password = password;
-
+
return prefsEdit.commit();
}
@@ -463,31 +465,31 @@ public class cgSettings {
maplive = 0;
}
}
-
+
public int getLastList() {
int listId = prefs.getInt("lastlist", -1);
-
+
return listId;
}
-
+
public void saveLastList(int listId) {
final SharedPreferences.Editor edit = prefs.edit();
-
+
edit.putInt("lastlist", listId);
edit.commit();
}
public void setWebNameCode(String name, String code) {
final SharedPreferences.Editor edit = prefs.edit();
-
+
this.webDeviceCode=code;
this.webDeviceName=name;
-
+
edit.putString("webDeviceName", name);
edit.putString("webDeviceCode", code);
edit.commit();
}
-
+
public MapFactory getMapFactory() {
if (mapSource.isGoogleMapSource()) {
if (!mapSourceUsed.isGoogleMapSource() || mapFactory == null) {
@@ -500,32 +502,32 @@ public class cgSettings {
mapSourceUsed = mapSource;
}
}
-
+
return mapFactory;
}
-
+
public String getMapFile() {
return mapFile;
}
-
+
public boolean setMapFile(String mapFileIn) {
final SharedPreferences.Editor prefsEdit = prefs.edit();
prefsEdit.putString("mfmapfile", mapFileIn);
-
- boolean commitResult = prefsEdit.commit();
+
+ boolean commitResult = prefsEdit.commit();
mapFile = mapFileIn;
mapFileValid = checkMapfile(mapFile);
-
+
return commitResult;
}
-
+
public boolean hasValidMapFile() {
return mapFileValid;
}
-
- private boolean checkMapfile(String mapFileIn) {
+
+ private static boolean checkMapfile(String mapFileIn) {
return MapDatabase.isValidMapFile(mapFileIn);
}
diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java
index d642640..3df765b 100644
--- a/src/cgeo/geocaching/cgeoapplication.java
+++ b/src/cgeo/geocaching/cgeoapplication.java
@@ -769,7 +769,7 @@ public class cgeoapplication extends Application {
return storage.loadInventory(geocode);
}
- public ArrayList<cgSpoiler> loadSpoilers(String geocode) {
+ public ArrayList<cgImage> loadSpoilers(String geocode) {
return storage.loadSpoilers(geocode);
}
diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java
index 559cb79..cc3d621 100644
--- a/src/cgeo/geocaching/cgeodetail.java
+++ b/src/cgeo/geocaching/cgeodetail.java
@@ -1179,7 +1179,35 @@ public class cgeodetail extends Activity {
else {
((TextView) rowView.findViewById(R.id.log)).setText(log.log);
}
-
+ // add LogImages
+ LinearLayout logLayout = (LinearLayout) rowView.findViewById(R.id.log_layout);
+
+ if ((log.logImages != null) && (!log.logImages.isEmpty())) {
+ for (int i_img_cnt = 0; i_img_cnt < log.logImages.size(); i_img_cnt++) {
+ String img_title = log.logImages.get(i_img_cnt).title;
+ if (img_title.equals("")) {
+ img_title = res.getString(R.string.cache_log_image_default_title);
+ }
+ final String title = img_title;
+ final String url = log.logImages.get(i_img_cnt).url;
+ LinearLayout log_imgView = (LinearLayout) inflater.inflate(R.layout.log_img, null);
+ TextView log_img_title = (TextView)log_imgView.findViewById(R.id.title);
+ log_img_title.setText(title);
+ log_img_title.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent logImgIntent = new Intent(activity, cgeoimages.class);
+ logImgIntent.putExtra("geocode", geocode.toUpperCase());
+ logImgIntent.putExtra("type", cgeoimages.LOG_IMAGE);
+ logImgIntent.putExtra("title", title);
+ logImgIntent.putExtra("url", url);
+ activity.startActivity(logImgIntent);
+ }
+ });
+ logLayout.addView(log_imgView);
+ }
+ }
+
final ImageView markFound = (ImageView) rowView.findViewById(R.id.found_mark);
final ImageView markDNF = (ImageView) rowView.findViewById(R.id.dnf_mark);
final ImageView markDisabled = (ImageView) rowView.findViewById(R.id.disabled_mark);
@@ -1201,8 +1229,8 @@ public class cgeodetail extends Activity {
markDisabled.setVisibility(View.GONE);
}
- ((TextView) rowView.findViewById(R.id.author)).setOnClickListener(new userActions());
- ((TextView) rowView.findViewById(R.id.log)).setOnClickListener(new decryptLog());
+ ((TextView) rowView.findViewById(R.id.author)).setOnClickListener(new userActions());
+ ((TextView) logLayout.findViewById(R.id.log)).setOnClickListener(new decryptLog());
listView.addView(rowView);
}
@@ -1562,8 +1590,9 @@ public class cgeodetail extends Activity {
warning.showToast(res.getString(R.string.err_detail_no_spoiler));
}
- Intent spoilersIntent = new Intent(activity, cgeospoilers.class);
+ Intent spoilersIntent = new Intent(activity, cgeoimages.class);
spoilersIntent.putExtra("geocode", geocode.toUpperCase());
+ spoilersIntent.putExtra("type", cgeoimages.SPOILER_IMAGE);
activity.startActivity(spoilersIntent);
}
@@ -1884,8 +1913,7 @@ public class cgeodetail extends Activity {
}
}
}
-
-
+
public void goHome(View view) {
base.goHome(activity);
}
diff --git a/src/cgeo/geocaching/cgeospoilers.java b/src/cgeo/geocaching/cgeoimages.java
index 3af8341..4e6b493 100644
--- a/src/cgeo/geocaching/cgeospoilers.java
+++ b/src/cgeo/geocaching/cgeoimages.java
@@ -20,10 +20,17 @@ import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.view.ViewGroup.LayoutParams;
-public class cgeospoilers extends Activity {
- private ArrayList<cgSpoiler> spoilers = new ArrayList<cgSpoiler>();
+public class cgeoimages extends Activity {
+
+ public static final int LOG_IMAGE = 1;
+ public static final int SPOILER_IMAGE = 2;
+
+ private int img_type;
+ private ArrayList<cgImage> images = new ArrayList<cgImage>();
private Resources res = null;
private String geocode = null;
+ private String title = null;
+ private String url = null;
private cgeoapplication app = null;
private Activity activity = null;
private cgSettings settings = null;
@@ -32,21 +39,30 @@ public class cgeospoilers extends Activity {
private LayoutInflater inflater = null;
private ProgressDialog progressDialog = null;
private ProgressDialog waitDialog = null;
- private LinearLayout spoilerView = null;
+ private LinearLayout imagesView = null;
private int offline = 0;
+ private boolean save = true;
private int count = 0;
private int countDone = 0;
- private Handler loadSpoilersHandler = new Handler() {
+ private String load_process_string;
+
+ private Handler loadImagesHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
- if (spoilers.isEmpty()) {
+ if (images.isEmpty()) {
if (waitDialog != null) {
waitDialog.dismiss();
}
-
- warning.showToast("Sorry, c:geo failed to load spoiler images.");
+ switch (img_type) {
+ case LOG_IMAGE:
+ warning.showToast(res.getString(R.string.warn_load_log_image));
+ break;
+ case SPOILER_IMAGE:
+ warning.showToast(res.getString(R.string.warn_load_spoiler_image));
+ break;
+ }
finish();
return;
@@ -61,27 +77,27 @@ public class cgeospoilers extends Activity {
offline = 0;
}
- count = spoilers.size();
+ count = images.size();
progressDialog = new ProgressDialog(activity);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setMessage(res.getString(R.string.cache_spoiler_images_loading));
+ progressDialog.setMessage(load_process_string);
progressDialog.setCancelable(true);
progressDialog.setMax(count);
progressDialog.show();
LinearLayout rowView = null;
- for (final cgSpoiler spl : spoilers) {
- rowView = (LinearLayout) inflater.inflate(R.layout.spoiler_item, null);
+ for (final cgImage img : images) {
+ rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null);
- ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(spl.title));
+ ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.title));
- if (spl.description != null && spl.description.length() > 0) {
+ if (img.description != null && img.description.length() > 0) {
final TextView descView = (TextView) rowView.findViewById(R.id.description);
- descView.setText(Html.fromHtml(spl.description), TextView.BufferType.SPANNABLE);
+ descView.setText(Html.fromHtml(img.description), TextView.BufferType.SPANNABLE);
descView.setVisibility(View.VISIBLE);
}
- final Handler handler = new onLoadHandler(rowView, spl);
+ final Handler handler = new onLoadHandler(rowView, img);
new Thread() {
@@ -89,26 +105,26 @@ public class cgeospoilers extends Activity {
public void run() {
BitmapDrawable image = null;
try {
- cgHtmlImg imgGetter = new cgHtmlImg(activity, settings, geocode, true, offline, false);
+ cgHtmlImg imgGetter = new cgHtmlImg(activity, settings, geocode, true, offline, false, save);
- image = imgGetter.getDrawable(spl.url);
+ image = imgGetter.getDrawable(img.url);
Message message = handler.obtainMessage(0, image);
handler.sendMessage(message);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeospoilers.onCreate.onClick.run: " + e.toString());
+ Log.e(cgSettings.tag, "cgeoimages.onCreate.onClick.run: " + e.toString());
}
}
}.start();
- spoilerView.addView(rowView);
+ imagesView.addView(rowView);
}
}
} catch (Exception e) {
if (waitDialog != null) {
waitDialog.dismiss();
}
- Log.e(cgSettings.tag, "cgeospoilers.loadSpoilersHandler: " + e.toString());
+ Log.e(cgSettings.tag, "cgeoimages.loadImagesHandler: " + e.toString());
}
}
};
@@ -131,32 +147,89 @@ public class cgeospoilers extends Activity {
} else {
setTheme(R.style.dark);
}
- setContentView(R.layout.spoilers);
- base.setTitle(activity, res.getString(R.string.cache_spoiler_images_title));
+ setContentView(R.layout.spoilers);
// get parameters
Bundle extras = getIntent().getExtras();
// try to get data from extras
if (extras != null) {
- geocode = extras.getString("geocode");
+ geocode = extras.getString("geocode");
+ img_type = extras.getInt("type", 0);
}
-
+
+ // google analytics
+ if (img_type == SPOILER_IMAGE)
+ {
+ base.setTitle(activity, res.getString(R.string.cache_spoiler_images_title));
+ base.sendAnal(activity, "/spoilers");
+ } else if (img_type == LOG_IMAGE) {
+ base.setTitle(activity, res.getString(R.string.cache_log_images_title));
+ base.sendAnal(activity, "/logimg");
+ }
+
if (geocode == null) {
warning.showToast("Sorry, c:geo forgot for what cache you want to load spoiler images.");
finish();
return;
}
-
+ switch (img_type) {
+ case LOG_IMAGE:
+ title = extras.getString("title");
+ url = extras.getString("url");
+ if ((title == null) || (url == null)) {
+ warning.showToast("Sorry, c:geo forgot which logimage you wanted to load.");
+ finish();
+ return;
+ }
+ break;
+ }
+
inflater = activity.getLayoutInflater();
- if (spoilerView == null) {
- spoilerView = (LinearLayout) findViewById(R.id.spoiler_list);
+ if (imagesView == null) {
+ imagesView = (LinearLayout) findViewById(R.id.spoiler_list);
}
-
- waitDialog = ProgressDialog.show(this, null, res.getString(R.string.cache_spoiler_images_loading), true);
+
+ switch (img_type) {
+ case SPOILER_IMAGE:
+ load_process_string = res.getString(R.string.cache_spoiler_images_loading);
+ save = true;
+ break;
+ case LOG_IMAGE:
+ load_process_string = res.getString(R.string.cache_log_images_loading);
+ if (settings.storelogimages == true) {
+ save = true;
+ } else {
+ save = false;
+ }
+ break;
+ default:
+ load_process_string = new String("Loading...");
+ }
+ waitDialog = ProgressDialog.show(this, null, load_process_string, true);
waitDialog.setCancelable(true);
- (new loadSpoilers()).start();
+ switch (img_type) {
+ case LOG_IMAGE:
+ cgImage logimage = new cgImage();
+ logimage.title = title;
+ logimage.url = url;
+ logimage.description = "";
+ images.add(logimage);
+ try {
+ loadImagesHandler.sendMessage(new Message());
+ } catch (Exception e) {
+ Log.e(cgSettings.tag, "cgeoimages.loadImagesHandler.sendMessage: " + e.toString());
+ }
+ break;
+ case SPOILER_IMAGE:
+ (new loadSpoilers()).start();
+ break;
+ default:
+ warning.showToast("Sorry, can't load unknown image type.");
+ finish();
+ }
+
}
@Override
@@ -171,9 +244,9 @@ public class cgeospoilers extends Activity {
@Override
public void run() {
try {
- spoilers = app.loadSpoilers(geocode);
+ images = app.loadSpoilers(geocode);
- loadSpoilersHandler.sendMessage(new Message());
+ loadImagesHandler.sendMessage(new Message());
} catch (Exception e) {
Log.e(cgSettings.tag, "cgeospoilers.loadSpoilers.run: " + e.toString());
}
@@ -183,35 +256,35 @@ public class cgeospoilers extends Activity {
private class onLoadHandler extends Handler {
LinearLayout view = null;
- cgSpoiler spoiler = null;
+ cgImage img = null;
- public onLoadHandler(LinearLayout view, cgSpoiler spoiler) {
+ public onLoadHandler(LinearLayout view, cgImage image) {
this.view = view;
- this.spoiler = spoiler;
+ this.img = image;
}
@Override
public void handleMessage(Message message) {
BitmapDrawable image = (BitmapDrawable) message.obj;
if (image != null) {
- ImageView spoilerImage = null;
- spoilerImage = (ImageView) inflater.inflate(R.layout.image_item, null);
+ ImageView image_view = null;
+ image_view = (ImageView) inflater.inflate(R.layout.image_item, null);
Rect bounds = image.getBounds();
- spoilerImage.setImageResource(R.drawable.image_not_loaded);
- spoilerImage.setClickable(true);
- spoilerImage.setOnClickListener(new View.OnClickListener() {
+ image_view.setImageResource(R.drawable.image_not_loaded);
+ image_view.setClickable(true);
+ image_view.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
- activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(spoiler.url)));
+ activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(img.url)));
}
});
- spoilerImage.setImageDrawable((BitmapDrawable) message.obj);
- spoilerImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
- spoilerImage.setLayoutParams(new LayoutParams(bounds.width(), bounds.height()));
+ image_view.setImageDrawable((BitmapDrawable) message.obj);
+ image_view.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ image_view.setLayoutParams(new LayoutParams(bounds.width(), bounds.height()));
- view.addView(spoilerImage);
+ view.addView(image_view);
}
countDone++;
diff --git a/src/cgeo/geocaching/cgeoinit.java b/src/cgeo/geocaching/cgeoinit.java
index 33d9f29..ce13b74 100644
--- a/src/cgeo/geocaching/cgeoinit.java
+++ b/src/cgeo/geocaching/cgeoinit.java
@@ -1,33 +1,31 @@
package cgeo.geocaching;
-import gnu.android.app.appmanualclient.*;
+import gnu.android.app.appmanualclient.AppManualReaderClient;
+
+import java.io.File;
-import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
-import android.view.View;
-import android.widget.EditText;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
-import android.util.Log;
+import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
-import android.widget.LinearLayout;
+import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
-import android.widget.AdapterView.OnItemSelectedListener;
-
-import java.io.File;
-
import cgeo.geocaching.cgSettings.mapSourceEnum;
public class cgeoinit extends Activity {
@@ -75,7 +73,7 @@ public class cgeoinit extends Activity {
init();
}
};
-
+
private Handler webAuthHandler = new Handler() {
@Override
@@ -132,7 +130,7 @@ public class cgeoinit extends Activity {
@Override
public void onResume() {
super.onResume();
-
+
settings.load();
}
@@ -192,7 +190,7 @@ public class cgeoinit extends Activity {
}
public void init() {
-
+
// geocaching.com settings
String usernameNow = prefs.getString("username", null);
if (usernameNow != null) {
@@ -202,7 +200,7 @@ public class cgeoinit extends Activity {
if (usernameNow != null) {
((EditText) findViewById(R.id.password)).setText(passwordNow);
}
-
+
Button logMeIn = (Button) findViewById(R.id.log_me_in);
logMeIn.setOnClickListener(new logIn());
@@ -324,7 +322,7 @@ public class cgeoinit extends Activity {
disabledButton.setChecked(true);
}
disabledButton.setOnClickListener(new cgeoChangeDisabled());
-
+
CheckBox autovisitButton = (CheckBox) findViewById(R.id.trackautovisit);
if (prefs.getBoolean("trackautovisit", false)) {
autovisitButton.setChecked(true);
@@ -341,6 +339,15 @@ public class cgeoinit extends Activity {
}
offlineButton.setOnClickListener(new cgeoChangeOffline());
+ CheckBox saveLogImgButton = (CheckBox) findViewById(R.id.save_log_img);
+ if (prefs.getBoolean("logimages", false) == false) {
+ saveLogImgButton.setChecked(false);
+ } else {
+ saveLogImgButton.setChecked(true);
+ }
+ saveLogImgButton.setOnClickListener(new cgeoChangeSaveLogImg());
+
+
CheckBox autoloadButton = (CheckBox) findViewById(R.id.autoload);
if (prefs.getInt("autoloaddesc", 0) == 0) {
autoloadButton.setChecked(false);
@@ -380,14 +387,14 @@ public class cgeoinit extends Activity {
browserButton.setChecked(true);
}
browserButton.setOnClickListener(new cgeoChangeBrowser());
-
+
// Altitude settings
EditText altitudeEdit = (EditText) findViewById(R.id.altitude);
altitudeEdit.setText("" + prefs.getInt("altcorrection", 0));
//Send2cgeo settings
String webDeviceName = prefs.getString("webDeviceName", null);
-
+
if ((webDeviceName != null) &&(webDeviceName.length() > 0)) {
((EditText) findViewById(R.id.webDeviceName)).setText(webDeviceName);
} else {
@@ -397,7 +404,7 @@ public class cgeoinit extends Activity {
Button webAuth = (Button) findViewById(R.id.sendToCgeo_register);
webAuth.setOnClickListener(new webAuth());
-
+
/*TextView webText = (TextView) findViewById(R.id.sendToCgeo);
webText.setClickable(true);
webText.setOnClickListener(new View.OnClickListener() {
@@ -406,29 +413,29 @@ public class cgeoinit extends Activity {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://send2cgeo.carnero.cc/")));
}
});*/
-
+
// Map source settings
Spinner mapSourceSelector = (Spinner) findViewById(R.id.mapsource);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.map_sources, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- mapSourceSelector.setAdapter(adapter);
+ mapSourceSelector.setAdapter(adapter);
int mapsource = prefs.getInt("mapsource", 0);
mapSourceSelector.setSelection(mapsource);
mapSourceSelector.setOnItemSelectedListener(new cgeoChangeMapSource());
-
+
initMapfileEdittext(false);
-
+
Button selectMapfile = (Button) findViewById(R.id.select_mapfile);
selectMapfile.setOnClickListener(new View.OnClickListener() {
-
+
@Override
public void onClick(View v) {
Intent selectIntent = new Intent(activity, cgSelectMapfile.class);
activity.startActivityForResult(selectIntent, SELECT_MAPFILE_REQUEST);
}
});
-
+
// Cache db backup
TextView lastBackup = (TextView) findViewById(R.id.backup_last);
File lastBackupFile = app.isRestoreFile();
@@ -437,9 +444,9 @@ public class cgeoinit extends Activity {
} else {
lastBackup.setText(res.getString(R.string.init_backup_last_no));
}
-
+
}
-
+
private void initMapfileEdittext(boolean setFocus) {
EditText mfmapFileEdit = (EditText) findViewById(R.id.mapfile);
mfmapFileEdit.setText(prefs.getString("mfmapfile", ""));
@@ -450,13 +457,13 @@ public class cgeoinit extends Activity {
public void backup(View view) {
final String file = app.backupDatabase();
-
+
if (file != null) {
warning.helpDialog(res.getString(R.string.init_backup_backup), res.getString(R.string.init_backup_success) + "\n" + file);
} else {
warning.helpDialog(res.getString(R.string.init_backup_backup), res.getString(R.string.init_backup_failed));
}
-
+
TextView lastBackup = (TextView) findViewById(R.id.backup_last);
File lastBackupFile = app.isRestoreFile();
if (lastBackupFile != null) {
@@ -465,17 +472,17 @@ public class cgeoinit extends Activity {
lastBackup.setText(res.getString(R.string.init_backup_last_no));
}
}
-
+
public void restore(View view) {
final boolean status = app.restoreDatabase();
-
+
if (status) {
warning.helpDialog(res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_success));
} else {
warning.helpDialog(res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_failed));
}
}
-
+
public boolean saveValues() {
String usernameNew = ((EditText) findViewById(R.id.username)).getText().toString();
String passwordNew = ((EditText) findViewById(R.id.password)).getText().toString();
@@ -496,14 +503,14 @@ public class cgeoinit extends Activity {
if (signatureNew == null) {
signatureNew = "";
}
-
+
int altitudeNewInt = 0;
if (altitudeNew == null) {
altitudeNewInt = 0;
} else {
altitudeNewInt = new Integer(altitudeNew);
}
-
+
if (mfmapFileNew == null) {
mfmapFileNew = "";
}
@@ -705,7 +712,7 @@ public class cgeoinit extends Activity {
return;
}
}
-
+
private class cgeoChangeAutovisit implements View.OnClickListener {
public void onClick(View arg0) {
@@ -729,7 +736,7 @@ public class cgeoinit extends Activity {
return;
}
}
-
+
private class cgeoChangeSignatureAutoinsert implements View.OnClickListener {
public void onClick(View arg0) {
@@ -801,6 +808,30 @@ public class cgeoinit extends Activity {
return;
}
}
+
+ private class cgeoChangeSaveLogImg implements View.OnClickListener {
+
+ public void onClick(View arg0) {
+ SharedPreferences.Editor edit = prefs.edit();
+ if (prefs.getBoolean("logimages", true) == false) {
+ edit.putBoolean("logimages", true);
+ settings.storelogimages = true;
+ } else {
+ edit.putBoolean("logimages", false);
+ settings.storelogimages = false;
+ }
+ edit.commit();
+
+ CheckBox saveLogImgButton = (CheckBox) findViewById(R.id.save_log_img);
+ if (prefs.getBoolean("logimages", true) == false) {
+ saveLogImgButton.setChecked(false);
+ } else {
+ saveLogImgButton.setChecked(true);
+ }
+
+ return;
+ }
+ }
private class cgeoChangeLivelist implements View.OnClickListener {
@@ -986,14 +1017,14 @@ public class cgeoinit extends Activity {
@Override
public void run() {
int pin = 0;
-
+
String nam = deviceName==null?"":deviceName;
String cod = deviceCode==null?"":deviceCode;
-
+
String params = "name="+cgBase.urlencode_rfc3986(nam)+"&code="+cgBase.urlencode_rfc3986(cod);
-
+
cgResponse response = base.request(false, "send2cgeo.carnero.cc", "/authDev.php", "GET", params, 0, true);
-
+
if (response.getStatusCode() == 200)
{
//response was OK
@@ -1006,17 +1037,17 @@ public class cgeoinit extends Activity {
String code = strings[0];
settings.setWebNameCode(nam, code);
}
-
+
webAuthHandler.sendEmptyMessage(pin);
}
}).start();
}
}
-
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
-
+
if (requestCode == SELECT_MAPFILE_REQUEST) {
if (resultCode == RESULT_OK) {
if (data.hasExtra("mapfile")) {
diff --git a/src/cgeo/geocaching/googlemaps/googleMapView.java b/src/cgeo/geocaching/googlemaps/googleMapView.java
index 48b8a38..737e64e 100644
--- a/src/cgeo/geocaching/googlemaps/googleMapView.java
+++ b/src/cgeo/geocaching/googlemaps/googleMapView.java
@@ -1,8 +1,5 @@
package cgeo.geocaching.googlemaps;
-import org.mapsforge.android.maps.MapDatabase;
-import org.mapsforge.android.maps.MapViewMode;
-
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
@@ -86,12 +83,12 @@ public class googleMapView extends MapView implements MapViewImpl{
@Override
public cgMapOverlay createAddMapOverlay(cgSettings settings,
Context context, Drawable drawable, boolean fromDetailIntent) {
-
+
googleCacheOverlay ovl = new googleCacheOverlay(settings, context, drawable, fromDetailIntent);
getOverlays().add(ovl);
return ovl.getBase();
}
-
+
@Override
public cgUsersOverlay createAddUsersOverlay(Context context, Drawable markerIn) {
googleUsersOverlay ovl = new googleUsersOverlay(context, markerIn);
@@ -106,7 +103,7 @@ public class googleMapView extends MapView implements MapViewImpl{
@Override
public void setMapSource(cgSettings settings) {
-
+
switch(settings.mapSource) {
case googleSat:
setSatellite(true);
@@ -114,8 +111,8 @@ public class googleMapView extends MapView implements MapViewImpl{
default:
setSatellite(false);
}
-
-
+
+
}
@Override
diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java
index eeb2017..38a350e 100644
--- a/src/cgeo/geocaching/mapcommon/cgeomap.java
+++ b/src/cgeo/geocaching/mapcommon/cgeomap.java
@@ -46,13 +46,13 @@ import cgeo.geocaching.mapinterfaces.MapViewImpl;
import cgeo.geocaching.mapinterfaces.UserOverlayItemImpl;
public class cgeomap extends MapBase {
-
+
private static final int MENU_SELECT_MAPVIEW = 1;
private static final int MENU_MAP_LIVE = 2;
- private static final int MENU_STORE_CACHES = 3;
+ private static final int MENU_STORE_CACHES = 3;
private static final int MENU_TRAIL_MODE = 4;
private static final int MENU_CIRCLE_MODE = 5;
-
+
private static final int SUBMENU_VIEW_GOOGLE_MAP = 10;
private static final int SUBMENU_VIEW_GOOGLE_SAT = 11;
private static final int SUBMENU_VIEW_MF_MAPNIK = 13;
@@ -346,8 +346,8 @@ public class cgeomap extends MapBase {
if (geocodeIntent != null || searchIdIntent != null || (latitudeIntent != null && longitudeIntent != null) || mapStateIntent != null) {
centerMap(geocodeIntent, searchIdIntent, latitudeIntent, longitudeIntent, mapStateIntent);
}
-
-
+
+
setMyLoc(null);
startTimer();
}
@@ -462,10 +462,10 @@ public class cgeomap extends MapBase {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
-
+
SubMenu submenu = menu.addSubMenu(1, MENU_SELECT_MAPVIEW, 0, res.getString(R.string.map_view_map)).setIcon(android.R.drawable.ic_menu_more);
addMapViewMenuItems(submenu);
-
+
menu.add(0, MENU_MAP_LIVE, 0, res.getString(R.string.map_live_disable)).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
menu.add(0, MENU_STORE_CACHES, 0, res.getString(R.string.caches_store_offline)).setIcon(android.R.drawable.ic_menu_set_as).setEnabled(false);
menu.add(0, MENU_TRAIL_MODE, 0, res.getString(R.string.map_trail_hide)).setIcon(android.R.drawable.ic_menu_recent_history);
@@ -473,10 +473,10 @@ public class cgeomap extends MapBase {
return true;
}
-
+
private void addMapViewMenuItems(final Menu menu) {
String[] mapViews = res.getStringArray(R.array.map_sources);
-
+
menu.add(0, SUBMENU_VIEW_GOOGLE_MAP, 0, mapViews[0]);
menu.add(0, SUBMENU_VIEW_GOOGLE_SAT, 0, mapViews[1]);
menu.add(0, SUBMENU_VIEW_MF_MAPNIK, 0, mapViews[2]);
@@ -523,7 +523,7 @@ public class cgeomap extends MapBase {
} else {
item.setTitle(res.getString(R.string.map_circles_show));
}
-
+
item = menu.findItem(SUBMENU_VIEW_MF_OFFLINE);
if (settings.hasValidMapFile()) {
item.setEnabled(true);
@@ -642,16 +642,16 @@ public class cgeomap extends MapBase {
}
overlayCaches.switchCircles();
-
+
} else if (SUBMENU_VIEW_GOOGLE_MAP <= id && SUBMENU_VIEW_MF_OFFLINE >= id) {
-
+
mapSourceEnum mapSource = getMapSourceFromMenuId(id);
-
+
boolean mapRestartRequired = switchMapSource(mapSource);
-
+
if (mapRestartRequired) {
Intent mapIntent = new Intent(activity, settings.getMapFactory().getMapClass());
-
+
mapIntent.putExtra("detail", fromDetailIntent);
mapIntent.putExtra("searchid", searchIdIntent);
mapIntent.putExtra("geocode", geocodeIntent);
@@ -664,21 +664,21 @@ public class cgeomap extends MapBase {
mapState[1] = mapCenter.getLongitudeE6();
mapState[2] = mapView.getMapZoomLevel();
mapIntent.putExtra("mapstate", mapState);
-
+
activity.startActivity(mapIntent);
-
+
activity.finish();
}
-
+
return true;
}
-
+
return false;
}
-
- private mapSourceEnum getMapSourceFromMenuId(int menuItemId) {
-
+
+ private static mapSourceEnum getMapSourceFromMenuId(int menuItemId) {
+
switch(menuItemId) {
case SUBMENU_VIEW_GOOGLE_MAP:
return mapSourceEnum.googleMap;
@@ -696,20 +696,20 @@ public class cgeomap extends MapBase {
return mapSourceEnum.googleMap;
}
}
-
+
private boolean switchMapSource(mapSourceEnum mapSource) {
settings.mapSource = mapSource;
-
+
prefsEdit.putInt("mapsource", settings.mapSource.ordinal());
prefsEdit.commit();
boolean mapRestartRequired = settings.mapSource.isGoogleMapSource()!= settings.mapSourceUsed.isGoogleMapSource();
-
+
if (!mapRestartRequired) {
mapView.setMapSource(settings);
}
-
+
return mapRestartRequired;
}
@@ -1647,7 +1647,7 @@ public class cgeomap extends MapBase {
// move map to view results of searchIdIntent
private void centerMap(String geocodeCenter, Long searchIdCenter, Double latitudeCenter, Double longitudeCenter, int[] mapState) {
-
+
if (!centered && mapState != null) {
try {
mapController.setCenter(settings.getMapFactory().getGeoPointBase(mapState[0], mapState[1]));
@@ -1655,9 +1655,9 @@ public class cgeomap extends MapBase {
} catch (Exception e) {
// nothing at all
}
-
+
centered = true;
- alreadyCentered = true;
+ alreadyCentered = true;
} else if (!centered && (geocodeCenter != null || searchIdIntent != null)) {
try {
ArrayList<Object> viewport;
diff --git a/src/cgeo/geocaching/sorting/SizeComparator.java b/src/cgeo/geocaching/sorting/SizeComparator.java
index f5bd643..dd9d448 100644
--- a/src/cgeo/geocaching/sorting/SizeComparator.java
+++ b/src/cgeo/geocaching/sorting/SizeComparator.java
@@ -30,7 +30,7 @@ public class SizeComparator extends AbstractCacheComparator {
* @param cache
* @return
*/
- private int getSize(final cgCache cache) {
+ private static int getSize(final cgCache cache) {
char c = cache.size.charAt(0);
switch (c) {
case 'm': // micro