diff options
| author | c:geo <cgeo@cgeo.org> | 2011-08-01 22:09:20 -0700 |
|---|---|---|
| committer | c:geo <cgeo@cgeo.org> | 2011-08-01 22:09:20 -0700 |
| commit | 6118f6489847f98d2c257671c352082974134b14 (patch) | |
| tree | eeb68320e720f84224e647b02a10a2f645fe6387 | |
| parent | 53645ae292deb7f14ae3da2a19e2e9f11407746d (diff) | |
| parent | 7800d4761313a036f32e3d31747099f009c0e1da (diff) | |
| download | cgeo-6118f6489847f98d2c257671c352082974134b14.zip cgeo-6118f6489847f98d2c257671c352082974134b14.tar.gz cgeo-6118f6489847f98d2c257671c352082974134b14.tar.bz2 | |
Merge pull request #84 from rahu/master
Display images for logs
| -rw-r--r-- | AndroidManifest.xml | 2 | ||||
| -rw-r--r-- | res/drawable/log_img.png | bin | 0 -> 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.xml | 21 | ||||
| -rw-r--r-- | res/layout/log_img.xml | 20 | ||||
| -rw-r--r-- | res/layout/log_item.xml | 27 | ||||
| -rw-r--r-- | res/values/strings.xml | 6 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 31 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgCache.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgData.java | 89 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgHtmlImg.java | 50 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgImage.java (renamed from src/cgeo/geocaching/cgSpoiler.java) | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgLog.java | 3 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgSettings.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeoapplication.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeodetail.java | 40 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeoimages.java (renamed from src/cgeo/geocaching/cgeospoilers.java) | 166 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeoinit.java | 33 |
18 files changed, 391 insertions, 105 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 Binary files differnew file mode 100644 index 0000000..09e4037 --- /dev/null +++ b/res/drawable/log_img.png 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/cgBase.java b/src/cgeo/geocaching/cgBase.java index 51e6372..f4ad6d9 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -1098,6 +1098,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}\"[^>]*> ([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); @@ -1512,7 +1513,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) { @@ -1523,7 +1524,7 @@ public class cgBase { } if (cache.spoilers == null) { - cache.spoilers = new ArrayList<cgSpoiler>(); + cache.spoilers = new ArrayList<cgImage>(); } cache.spoilers.add(spoiler); } @@ -1694,6 +1695,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) { @@ -5018,10 +5032,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 dae75e6..a878a1f 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -55,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>(); 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 6c7473b..9b5a2e0 100644 --- a/src/cgeo/geocaching/cgSettings.java +++ b/src/cgeo/geocaching/cgSettings.java @@ -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; @@ -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); 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 a0b76d8..fa41293 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -1197,7 +1197,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); @@ -1219,8 +1247,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); } @@ -1580,8 +1608,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); } @@ -1902,8 +1931,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 4d2bd58..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,35 +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)); - - // google analytics - base.sendAnal(activity, "/spoilers"); + 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 @@ -174,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()); } @@ -186,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 39b36c4..25693e0 100644 --- a/src/cgeo/geocaching/cgeoinit.java +++ b/src/cgeo/geocaching/cgeoinit.java @@ -342,6 +342,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); @@ -802,6 +811,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 { |
