From ec62a700b4b4dbdb4469f78e2a73b786761db529 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Tue, 6 Nov 2012 07:39:50 +0100 Subject: fix #2140: NPE in CacheDetailActivity --- main/src/cgeo/geocaching/CacheDetailActivity.java | 112 +++++++++++----------- 1 file changed, 57 insertions(+), 55 deletions(-) (limited to 'main/src/cgeo/geocaching') diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index ff65584..d5d028e 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -2026,45 +2026,45 @@ public class CacheDetailActivity extends AbstractActivity { registerForContextMenu(view.findViewById(R.id.longdesc)); } - /** - * Loads the description in background.
- *
- * Params: - *
    - *
  1. description string (String)
  2. - *
  3. target description view (TextView)
  4. - *
  5. loading indicator view (View, may be null)
  6. - *
- */ - private class LoadDescriptionTask extends AsyncTask { - private View loadingIndicatorView; - private TextView descriptionView; - private String descriptionString; - private Spanned description; + } - private class HtmlImageCounter implements Html.ImageGetter { + /** + * Loads the description in background.
+ *
+ * Params: + *
    + *
  1. description string (String)
  2. + *
  3. target description view (TextView)
  4. + *
  5. loading indicator view (View, may be null)
  6. + *
+ */ + private class LoadDescriptionTask extends AsyncTask { + private View loadingIndicatorView; + private TextView descriptionView; + private String descriptionString; + private Spanned description; - private int imageCount = 0; + private class HtmlImageCounter implements Html.ImageGetter { - @Override - public Drawable getDrawable(String url) { - imageCount++; - return null; - } + private int imageCount = 0; - public int getImageCount() { - return imageCount; - } + @Override + public Drawable getDrawable(String url) { + imageCount++; + return null; } - @Override - protected Void doInBackground(Object... params) { - try { - descriptionString = ((String) params[0]); - descriptionView = (TextView) params[1]; - loadingIndicatorView = (View) params[2]; - } catch (Exception e) { - } + public int getImageCount() { + return imageCount; + } + } + + @Override + protected Void doInBackground(Object... params) { + try { + descriptionString = ((String) params[0]); + descriptionView = (TextView) params[1]; + loadingIndicatorView = (View) params[2]; // Fast preview: parse only HTML without loading any images HtmlImageCounter imageCounter = new HtmlImageCounter(); @@ -2080,37 +2080,39 @@ public class CacheDetailActivity extends AbstractActivity { // If description has an HTML construct which may be problematic to render, add a note at the end of the long description. // Technically, it may not be a table, but a pre, which has the same problems as a table, so the message is ok even though // sometimes technically incorrect. - if (unknownTagsHandler.isProblematicDetected() && descriptionView == view.findViewById(R.id.longdesc)) { + if (unknownTagsHandler.isProblematicDetected() && descriptionView != null) { final int startPos = description.length(); ((Editable) description).append("\n\n").append(res.getString(R.string.cache_description_table_note)); ((Editable) description).setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); publishProgress(); } - return null; + } catch (Exception e) { + Log.e("LoadDescriptionTask: ", e); } + return null; + } - /* - * (non-Javadoc) - * - * @see android.os.AsyncTask#onProgressUpdate(Progress[]) - */ - @Override - protected void onProgressUpdate(Void... values) { - if (description != null) { - if (StringUtils.isNotBlank(descriptionString)) { - descriptionView.setText(description, TextView.BufferType.SPANNABLE); - descriptionView.setMovementMethod(LinkMovementMethod.getInstance()); - fixBlackTextColor(descriptionView, descriptionString); - } - - descriptionView.setVisibility(View.VISIBLE); - } else { - showToast(res.getString(R.string.err_load_descr_failed)); + /* + * (non-Javadoc) + * + * @see android.os.AsyncTask#onProgressUpdate(Progress[]) + */ + @Override + protected void onProgressUpdate(Void... values) { + if (description != null) { + if (StringUtils.isNotBlank(descriptionString)) { + descriptionView.setText(description, TextView.BufferType.SPANNABLE); + descriptionView.setMovementMethod(LinkMovementMethod.getInstance()); + fixBlackTextColor(descriptionView, descriptionString); } - if (null != loadingIndicatorView) { - loadingIndicatorView.setVisibility(View.GONE); - } + descriptionView.setVisibility(View.VISIBLE); + } else { + showToast(res.getString(R.string.err_load_descr_failed)); + } + + if (null != loadingIndicatorView) { + loadingIndicatorView.setVisibility(View.GONE); } } -- cgit v1.1