diff options
| -rw-r--r-- | main/res/layout/caches_item.xml | 34 | ||||
| -rw-r--r-- | main/res/values/strings_not_translatable.xml | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCConstants.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCParser.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/sorting/DistanceComparator.java | 19 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheListAdapter.java | 69 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/DirectionImage.java | 32 |
8 files changed, 56 insertions, 117 deletions
diff --git a/main/res/layout/caches_item.xml b/main/res/layout/caches_item.xml index d4e7b27..1105f91 100644 --- a/main/res/layout/caches_item.xml +++ b/main/res/layout/caches_item.xml @@ -75,15 +75,13 @@ <!-- real text based direction and distance --> <RelativeLayout - android:id="@+id/direction_layout" android:layout_width="78dip" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginBottom="1dip" android:layout_marginRight="30dip" - android:layout_marginTop="1dip" - android:visibility="gone" > + android:layout_marginTop="1dip" > <view android:id="@+id/distance" @@ -111,31 +109,21 @@ android:gravity="center" android:minHeight="28px" android:minWidth="28px" - cc:skin="?compass" /> - </RelativeLayout> - - <!-- image based direction and distance --> - - <RelativeLayout - android:id="@+id/dirimg_layout" - android:layout_width="78dip" - android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:layout_centerVertical="true" - android:layout_marginBottom="1dip" - android:layout_marginRight="30dip" - android:layout_marginTop="1dip" - android:visibility="gone" > + cc:skin="?compass" + android:visibility="gone" /> <ImageView android:id="@+id/dirimg" - android:layout_width="55dip" - android:layout_height="30dip" - android:layout_centerInParent="true" + android:layout_width="78dip" + android:layout_height="28px" + android:layout_centerHorizontal="true" android:layout_gravity="center" + android:layout_marginTop="21dip" android:gravity="center" - android:scaleType="fitXY" - android:src="@null" /> + android:minHeight="28px" + android:minWidth="28px" + android:src="@null" + android:visibility="gone" /> </RelativeLayout> <!-- inventory and favorites --> diff --git a/main/res/values/strings_not_translatable.xml b/main/res/values/strings_not_translatable.xml index 8466627..8d70e14 100644 --- a/main/res/values/strings_not_translatable.xml +++ b/main/res/values/strings_not_translatable.xml @@ -97,6 +97,9 @@ <!-- changelog -->
<string name="changelog" translatable="false">\n
<b>Next release</b>\n\n
+ <b>Next bugfix release</b>\n
+ <b>Bugfixing:</b>\n
+ ยท Correction for compatability issue with tablet devices\n
\n
\n
<b>2013.05.16</b>\n
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java index 8567e7c..59f46be 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java @@ -117,7 +117,7 @@ public final class GCConstants { public final static Pattern PATTERN_SEARCH_TRACKABLES = Pattern.compile("<a id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxTravelBugList\" class=\"tblist\" data-tbcount=\"([0-9]+)\" data-id=\"[^\"]*\"[^>]*>(.*)</a>"); /** Second group used */ public final static Pattern PATTERN_SEARCH_TRACKABLESINSIDE = Pattern.compile("(<img src=\"[^\"]+\" alt=\"([^\"]+)\" title=\"[^\"]*\" />[^<]*)"); - public final static Pattern PATTERN_SEARCH_DIRECTION = Pattern.compile("<img id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxDistanceAndHeading\" title=\"[^\"]*\" src=\"[^\"]*/seek/CacheDir\\.ashx\\?k=([^\"]+)\"[^>]*>"); + public final static Pattern PATTERN_SEARCH_DIRECTION_DISTANCE = Pattern.compile("<img src=\"/images/icons/compass/([^\\.]+)\\.gif\"[^>]*>[^<]*<br />([^<]+)</span>"); public final static Pattern PATTERN_SEARCH_GEOCODE = Pattern.compile("\\|\\W*(GC[0-9A-Z]+)[^\\|]*\\|"); public final static Pattern PATTERN_SEARCH_ID = Pattern.compile("name=\"CID\"[^v]*value=\"([0-9]+)\""); public final static Pattern PATTERN_SEARCH_FAVORITE = Pattern.compile("<span id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxFavoritesValue\" title=\"[^\"]*\" class=\"favorite-rank\">([0-9]+)</span>"); diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index ef921de..de61007 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -166,7 +166,14 @@ public abstract class GCParser { // cache direction - image if (Settings.getLoadDirImg()) { - cache.setDirectionImg(Network.decode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION, true, 1, cache.getDirectionImg(), true))); + final String direction = BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION_DISTANCE, false, 1, null, false); + final String distance = BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION_DISTANCE, false, 2, null, false); + if (direction != null) { + cache.setDirectionImg(direction); + } + if (distance != null) { + cache.setDistance(DistanceParser.parseDistance(distance, Settings.isUseMetricUnits())); + } } // cache inventory @@ -291,7 +298,7 @@ public abstract class GCParser { final Set<Geocache> caches = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); for (Geocache cache : caches) { if (cache.getCoords() == null && StringUtils.isNotEmpty(cache.getDirectionImg())) { - DirectionImage.getDrawable(cache.getGeocode(), cache.getDirectionImg()); + DirectionImage.getDrawable(cache.getDirectionImg()); } } } diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index 15ea235..d5b610c 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -45,6 +45,7 @@ public class HtmlImage implements Html.ImageGetter { "trendcounter.com", "hit-counter-download.com" }; + public static final String SHARED = "shared"; final private String geocode; /** @@ -82,7 +83,7 @@ public class HtmlImage implements Html.ImageGetter { } final boolean shared = url.contains("/images/icons/icon_"); - final String pseudoGeocode = shared ? "shared" : geocode; + final String pseudoGeocode = shared ? SHARED : geocode; Bitmap imagePre = loadImageFromStorage(url, pseudoGeocode, shared); diff --git a/main/src/cgeo/geocaching/sorting/DistanceComparator.java b/main/src/cgeo/geocaching/sorting/DistanceComparator.java index 7b0afbb..731e356 100644 --- a/main/src/cgeo/geocaching/sorting/DistanceComparator.java +++ b/main/src/cgeo/geocaching/sorting/DistanceComparator.java @@ -27,13 +27,10 @@ public class DistanceComparator extends AbstractCacheComparator { if (cachedDistances) { return; } - for (Geocache cache : list) { + for (final Geocache cache : list) { if (cache.getCoords() != null) { cache.setDistance(coords.distanceTo(cache.getCoords())); } - else { - cache.setDistance(null); - } } cachedDistances = true; } @@ -46,16 +43,12 @@ public class DistanceComparator extends AbstractCacheComparator { @Override protected int compareCaches(final Geocache cache1, final Geocache cache2) { calculateAllDistances(); - if (cache1.getCoords() == null && cache2.getCoords() == null) { - return 0; - } - if (cache1.getCoords() == null) { - return 1; - } - if (cache2.getCoords() == null) { - return -1; + final Float distance1 = cache1.getDistance(); + final Float distance2 = cache2.getDistance(); + if (distance1 == null) { + return distance2 == null ? 0 : 1; } - return Float.compare(cache1.getDistance(), cache2.getDistance()); + return distance2 == null ? -1 : Float.compare(distance1, distance2); } } diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index b60586e..99ae405 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -22,8 +22,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import android.app.Activity; import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.text.Spannable; @@ -39,7 +37,6 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.ImageView; -import android.widget.RelativeLayout; import android.widget.TextView; import java.util.ArrayList; @@ -100,10 +97,8 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { TextView favorite; TextView info; ImageView inventory; - RelativeLayout directionLayout; DistanceView distance; CompassMiniView direction; - RelativeLayout dirImgLayout; ImageView dirImg; } @@ -358,10 +353,8 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { holder.checkbox = (CheckBox) v.findViewById(R.id.checkbox); holder.logStatusMark = (ImageView) v.findViewById(R.id.log_status_mark); holder.text = (TextView) v.findViewById(R.id.text); - holder.directionLayout = (RelativeLayout) v.findViewById(R.id.direction_layout); holder.distance = (DistanceView) v.findViewById(R.id.distance); holder.direction = (CompassMiniView) v.findViewById(R.id.direction); - holder.dirImgLayout = (RelativeLayout) v.findViewById(R.id.dirimg_layout); holder.dirImg = (ImageView) v.findViewById(R.id.dirimg); holder.inventory = (ImageView) v.findViewById(R.id.inventory); holder.favorite = (TextView) v.findViewById(R.id.favorite); @@ -434,64 +427,26 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { holder.inventory.setVisibility(View.GONE); } - boolean setDiDi = false; + if (cache.getDistance() != null) { + holder.distance.setDistance(cache.getDistance()); + } if (cache.getCoords() != null) { holder.direction.setVisibility(View.VISIBLE); + holder.dirImg.setVisibility(View.GONE); holder.direction.updateAzimuth(azimuth); if (coords != null) { holder.distance.update(coords); holder.direction.updateCurrentCoords(coords); } - setDiDi = true; - } else { - if (cache.getDistance() != null) { - holder.distance.setDistance(cache.getDistance()); - setDiDi = true; - } - if (cache.getDirection() != null) { - holder.direction.setVisibility(View.VISIBLE); - holder.direction.updateAzimuth(azimuth); - holder.direction.updateHeading(cache.getDirection()); - setDiDi = true; - } - } - - if (setDiDi) { - holder.directionLayout.setVisibility(View.VISIBLE); - holder.dirImgLayout.setVisibility(View.GONE); + } else if (cache.getDirection() != null) { + holder.direction.setVisibility(View.VISIBLE); + holder.dirImg.setVisibility(View.GONE); + holder.direction.updateAzimuth(azimuth); + holder.direction.updateHeading(cache.getDirection()); } else { - holder.directionLayout.setVisibility(View.GONE); - holder.distance.clear(); - - final Bitmap dirImgPre = BitmapFactory.decodeFile(DirectionImage.getDirectionFile(cache.getGeocode(), false).getPath()); - final Bitmap dirImg; - if (dirImgPre != null) { // null happens for invalid caches (not yet released) - dirImg = dirImgPre.copy(Bitmap.Config.ARGB_8888, true); - dirImgPre.recycle(); - } - else { - dirImg = null; - } - - if (dirImg != null) { - if (!lightSkin) { - final int length = dirImg.getWidth() * dirImg.getHeight(); - final int[] pixels = new int[length]; - dirImg.getPixels(pixels, 0, dirImg.getWidth(), 0, 0, dirImg.getWidth(), dirImg.getHeight()); - for (int i = 0; i < length; i++) { - if (pixels[i] == 0xff000000) { // replace black with white - pixels[i] = 0xffffffff; - } - } - dirImg.setPixels(pixels, 0, dirImg.getWidth(), 0, 0, dirImg.getWidth(), dirImg.getHeight()); - } - - holder.dirImg.setImageBitmap(dirImg); - holder.dirImgLayout.setVisibility(View.VISIBLE); - } else { - holder.dirImg.setImageBitmap(null); - holder.dirImgLayout.setVisibility(View.GONE); - } + holder.dirImg.setImageDrawable(DirectionImage.getDrawable(cache.getDirectionImg())); + holder.dirImg.setVisibility(View.VISIBLE); + holder.direction.setVisibility(View.GONE); } holder.favorite.setText(Integer.toString(cache.getFavoritePoints())); diff --git a/main/src/cgeo/geocaching/ui/DirectionImage.java b/main/src/cgeo/geocaching/ui/DirectionImage.java index 675d73b..df7275d 100644 --- a/main/src/cgeo/geocaching/ui/DirectionImage.java +++ b/main/src/cgeo/geocaching/ui/DirectionImage.java @@ -1,30 +1,22 @@ package cgeo.geocaching.ui; -import cgeo.geocaching.files.LocalStorage; -import cgeo.geocaching.network.Network; -import cgeo.geocaching.network.Parameters; +import cgeo.geocaching.StoredList; +import cgeo.geocaching.network.HtmlImage; -import ch.boye.httpclientandroidlib.HttpResponse; -import org.apache.commons.lang3.StringUtils; - -import java.io.File; +import android.graphics.drawable.BitmapDrawable; public class DirectionImage { - public static void getDrawable(final String geocode, final String code) { - if (StringUtils.isBlank(geocode) || StringUtils.isBlank(code)) { - return; - } - - final HttpResponse httpResponse = - Network.getRequest("http://www.geocaching.com/ImgGen/seek/CacheDir.ashx", new Parameters("k", code)); - if (httpResponse != null) { - LocalStorage.saveEntityToFile(httpResponse, getDirectionFile(geocode, true)); - } - } + static private HtmlImage htmlImage = new HtmlImage(HtmlImage.SHARED, false, StoredList.STANDARD_LIST_ID, false); - public static File getDirectionFile(final String geocode, final boolean createDirs) { - return LocalStorage.getStorageFile(geocode, "direction.png", false, createDirs); + /** + * Retrieve the direction image corresponding to the direction code. + * + * @param directionCode one of the eight cardinal points + * @return a drawable with the arrow pointing into the right direction + */ + public static BitmapDrawable getDrawable(final String directionCode) { + return htmlImage.getDrawable("http://www.geocaching.com/images/icons/compass/" + directionCode + ".gif"); } } |
