diff options
Diffstat (limited to 'src/cgeo/geocaching/cgeodetail.java')
| -rw-r--r-- | src/cgeo/geocaching/cgeodetail.java | 148 |
1 files changed, 72 insertions, 76 deletions
diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java index a6aaad6..b9c5bf7 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -84,16 +84,21 @@ public class cgeodetail extends AbstractActivity { private loadLongDesc threadLongDesc = null; private Thread storeThread = null; private Thread refreshThread = null; - private HashMap<String, Integer> gcIcons = new HashMap<String, Integer>(); private ProgressDialog storeDialog = null; private ProgressDialog refreshDialog = null; private ProgressDialog dropDialog = null; private ProgressDialog watchlistDialog = null; // progress dialog for watchlist add/remove private Thread watchlistThread = null; // thread for watchlist add/remove private HashMap<Integer, String> calendars = new HashMap<Integer, String>(); + private ViewGroup attributeIconsLayout; // layout for attribute icons private ViewGroup attributeDescriptionsLayout; // layout for attribute descriptions private boolean attributesShowAsIcons = true; // default: show icons + /** <code>noAttributeImagesFound</code> + * This will be the case if the cache was imported with an older version of c:geo. + * These older versions parsed the attribute description from the tooltip in the web + * page and put them into the DB. No icons can be matched for these. */ + private boolean noAttributeIconsFound = false; private int attributeBoxMaxWidth; private Handler storeCacheHandler = new Handler() { @@ -453,24 +458,10 @@ public class cgeodetail extends AbstractActivity { final int id = item.getItemId(); if (id == 1) { - final Intent cachesIntent = new Intent(this, cgeocaches.class); - - cachesIntent.putExtra("type", "owner"); - cachesIntent.putExtra("username", contextMenuUser); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); - + cgeocaches.startActivityCacheOwner(this, contextMenuUser); return true; } else if (id == 2) { - final Intent cachesIntent = new Intent(this, cgeocaches.class); - - cachesIntent.putExtra("type", "username"); - cachesIntent.putExtra("username", contextMenuUser); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); - + cgeocaches.startActivityCacheUser(this, contextMenuUser); return true; } else if (id == 3) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser)))); @@ -605,22 +596,6 @@ public class cgeodetail extends AbstractActivity { } try { - if (gcIcons == null || gcIcons.isEmpty()) { - gcIcons.put("ape", R.drawable.type_ape); - gcIcons.put("cito", R.drawable.type_cito); - gcIcons.put("earth", R.drawable.type_earth); - gcIcons.put("event", R.drawable.type_event); - gcIcons.put("letterbox", R.drawable.type_letterbox); - gcIcons.put("locationless", R.drawable.type_locationless); - gcIcons.put("mega", R.drawable.type_mega); - gcIcons.put("multi", R.drawable.type_multi); - gcIcons.put("traditional", R.drawable.type_traditional); - gcIcons.put("virtual", R.drawable.type_virtual); - gcIcons.put("webcam", R.drawable.type_webcam); - gcIcons.put("wherigo", R.drawable.type_wherigo); - gcIcons.put("gchq", R.drawable.type_hq); - gcIcons.put("mystery", R.drawable.type_mystery); - } if (null == geocode && cache.geocode.length() > 0) { @@ -643,11 +618,7 @@ public class cgeodetail extends AbstractActivity { detailsList.removeAllViews(); // actionbar icon, default myster< - String typeId = "mystery"; - if (cache.type != null && gcIcons.containsKey(cache.type)) { // cache icon - typeId = cache.type; - } - ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(gcIcons.get(typeId)), null, null, null); + ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(cgBase.getCacheIcon(cache.type)), null, null, null); // cache name (full name) itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); @@ -840,7 +811,8 @@ public class cgeodetail extends AbstractActivity { // cache attributes if (cache.attributes != null && cache.attributes.size() > 0) { - final LinearLayout attribBox = (LinearLayout) findViewById(R.id.attributes_innerbox); + final LinearLayout attribBox = (LinearLayout) findViewById( + R.id.attributes_innerbox); // maximum width for attribute icons is screen width - paddings of parents attributeBoxMaxWidth = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) @@ -866,10 +838,18 @@ public class cgeodetail extends AbstractActivity { } ); // icons or text? - if (attributesShowAsIcons) + // + // also show icons when noAttributeImagesFound == true. Explanation: + // 1. no icons could be found in the first invocation of this method + // 2. user refreshes cache from web + // 3. now this method is called again + // 4. attributeShowAsIcons is false but noAttributeImagesFound is true + // => try to show them now + if (attributesShowAsIcons || noAttributeIconsFound) { showAttributeIcons(attribBox, attributeBoxMaxWidth); - else + } else { showAttributeDescriptions(attribBox); + } findViewById(R.id.attributes_box).setVisibility(View.VISIBLE); } @@ -882,7 +862,7 @@ public class cgeodetail extends AbstractActivity { StringBuilder inventoryString = new StringBuilder(); for (cgTrackable inventoryItem : cache.inventory) { if (inventoryString.length() > 0) { - inventoryString.append("\n"); + inventoryString.append('\n'); } // avoid HTML parsing where possible if (inventoryItem.name.indexOf('<') >= 0 || inventoryItem.name.indexOf('&') >= 0 ) { @@ -1430,15 +1410,7 @@ public class cgeodetail extends AbstractActivity { } private void cachesAround() { - cgeocaches cachesActivity = new cgeocaches(); - - Intent cachesIntent = new Intent(this, cachesActivity.getClass()); - cachesIntent.putExtra("type", "coordinate"); - cachesIntent.putExtra("latitude", cache.latitude); - cachesIntent.putExtra("longitude", cache.longitude); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); + cgeocaches.startActivityCachesAround(this, cache.latitude, cache.longitude); finish(); } @@ -1973,8 +1945,14 @@ public class cgeodetail extends AbstractActivity { * and makes it visible */ private void showAttributeIcons(LinearLayout attribBox, int parentWidth) { - if (attributeIconsLayout == null) + if (attributeIconsLayout == null) { attributeIconsLayout = createAttributeIconsLayout(parentWidth); + // no matching icons found? show text + if (noAttributeIconsFound) { + showAttributeDescriptions(attribBox); + return; + } + } attribBox.removeAllViews(); attribBox.addView(attributeIconsLayout); attributesShowAsIcons = true; @@ -1985,8 +1963,9 @@ public class cgeodetail extends AbstractActivity { * and makes it visible */ private void showAttributeDescriptions(LinearLayout attribBox) { - if (attributeDescriptionsLayout == null) + if (attributeDescriptionsLayout == null) { attributeDescriptionsLayout = createAttributeDescriptionsLayout(); + } attribBox.removeAllViews(); attribBox.addView(attributeDescriptionsLayout); attributesShowAsIcons = false; @@ -1996,10 +1975,17 @@ public class cgeodetail extends AbstractActivity { * toggle attribute descriptions and icons */ private void toggleAttributeDisplay(LinearLayout attribBox, int parentWidth) { - if (attributesShowAsIcons) + // Don't toggle when there are no icons to show. + if (noAttributeIconsFound) { + return; + } + + // toggle + if (attributesShowAsIcons) { showAttributeDescriptions(attribBox); - else + } else { showAttributeIcons(attribBox, parentWidth); + } } private ViewGroup createAttributeIconsLayout(int parentWidth) { @@ -2010,11 +1996,14 @@ public class cgeodetail extends AbstractActivity { LinearLayout attributeRow = newAttributeIconsRow(); rows.addView(attributeRow); + noAttributeIconsFound = true; + for(String attributeName : cache.attributes) { boolean strikethru = attributeName.endsWith("_no"); // cut off _yes / _no - if (attributeName.endsWith("_no") || attributeName.endsWith("_yes")) + if (attributeName.endsWith("_no") || attributeName.endsWith("_yes")) { attributeName = attributeName.substring(0, attributeName.lastIndexOf("_")); + } // check if another attribute icon fits in this row attributeRow.measure(0, 0); int rowWidth = attributeRow.getMeasuredWidth(); @@ -2028,26 +2017,30 @@ public class cgeodetail extends AbstractActivity { // dynamically search icon of the attribute Drawable d = null; - int id = res.getIdentifier("attribute_" + attributeName, "drawable", base.context.getPackageName()); - if (id > 0) + int id = res.getIdentifier("attribute_" + attributeName, "drawable", + base.context.getPackageName()); + if (id > 0) { + noAttributeIconsFound = false; d = res.getDrawable(id); - else + iv.setImageDrawable(d); + // strike through? + if (strikethru) { + // generate strikethru image with same properties as attribute image + ImageView strikethruImage = new ImageView(this); + strikethruImage.setLayoutParams(iv.getLayoutParams()); + d = res.getDrawable(R.drawable.attribute__strikethru); + strikethruImage.setImageDrawable(d); + fl.addView(strikethruImage); + } + } else { d = res.getDrawable(R.drawable.attribute_icon_not_found); - iv.setImageDrawable(d); - - // strike through? - if (strikethru) { - // generate strikethru image with same properties as attribute image - ImageView strikethruImage = new ImageView(this); - strikethruImage.setLayoutParams(iv.getLayoutParams()); - d = res.getDrawable(R.drawable.attribute__strikethru); - strikethruImage.setImageDrawable(d); - fl.addView(strikethruImage); - } + iv.setImageDrawable(d); + } + attributeRow.addView(fl); } - return rows; + return rows; } private LinearLayout newAttributeIconsRow() { @@ -2059,7 +2052,8 @@ public class cgeodetail extends AbstractActivity { } private ViewGroup createAttributeDescriptionsLayout() { - final LinearLayout descriptions = (LinearLayout) inflater.inflate(R.layout.attribute_descriptions, null); + final LinearLayout descriptions = (LinearLayout) inflater.inflate( + R.layout.attribute_descriptions, null); TextView attribView = (TextView) descriptions.getChildAt(0); StringBuilder buffer = new StringBuilder(); @@ -2068,19 +2062,21 @@ public class cgeodetail extends AbstractActivity { attribute = cache.attributes.get(i); // dynamically search for a translation of the attribute - int id = res.getIdentifier("attribute_" + attribute, "string", base.context.getPackageName()); + int id = res.getIdentifier("attribute_" + attribute, "string", + base.context.getPackageName()); if (id > 0) { String translated = res.getString(id); if (translated != null && translated.length() > 0) { attribute = translated; } } - if (buffer.length() > 0) { - buffer.append('\n'); - } + if (buffer.length() > 0) buffer.append('\n'); buffer.append(attribute); } + if (noAttributeIconsFound) + buffer.append("\n\n").append(res.getString(R.string.cache_attributes_no_icons)); + attribView.setText(buffer); return descriptions; |
