diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-25 13:03:38 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-25 13:03:38 +0200 |
commit | 1f31dff47fb8b3ac1dd469b942a798145376a6b1 (patch) | |
tree | f1cfe3d94a93f5a91c9b3ae7df08f587fc2d80fb /src/de | |
parent | a974358f262749eb58060aed13e3068811ea12ed (diff) | |
download | AntennaPod-1f31dff47fb8b3ac1dd469b942a798145376a6b1.zip |
Webview is now loaded asynchronously
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/podfetcher/activity/ItemviewActivity.java | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/src/de/podfetcher/activity/ItemviewActivity.java b/src/de/podfetcher/activity/ItemviewActivity.java index f6ebe6102..e83e567e6 100644 --- a/src/de/podfetcher/activity/ItemviewActivity.java +++ b/src/de/podfetcher/activity/ItemviewActivity.java @@ -7,6 +7,7 @@ import java.text.DateFormat; import org.apache.commons.lang3.StringEscapeUtils; import android.content.Intent; +import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.util.Log; @@ -20,6 +21,7 @@ import com.actionbarsherlock.app.SherlockActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.Window; import de.podfetcher.R; import de.podfetcher.asynctask.DownloadObserver; @@ -50,9 +52,9 @@ public class ItemviewActivity extends SherlockActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); manager = FeedManager.getInstance(); + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); extractFeeditem(); populateUI(); - } @Override @@ -87,22 +89,8 @@ public class ItemviewActivity extends SherlockActivity { .getTime(), System.currentTimeMillis(), DateFormat.MEDIUM, DateFormat.SHORT)); txtvTitle.setText(item.getTitle()); - String url = ""; - try { - if (item.getContentEncoded() == null) { - url = URLEncoder.encode(item.getDescription(), "utf-8") - .replaceAll("\\+", " "); - } else { - url = URLEncoder.encode(StringEscapeUtils.unescapeHtml4(item.getContentEncoded()), "utf-8") - .replaceAll("\\+", " "); - } - - } catch (UnsupportedEncodingException e) { - url = "Page could not be loaded"; - e.printStackTrace(); - } - - webvDescription.loadData(url, "text/html", "utf-8"); + + webViewLoader.execute(); } @@ -134,4 +122,46 @@ public class ItemviewActivity extends SherlockActivity { public boolean onPrepareOptionsMenu(Menu menu) { return FeedItemMenuHandler.onPrepareMenu(menu, item); } + + private AsyncTask<Void, Void, Void> webViewLoader = new AsyncTask<Void, Void, Void>() { + String url; + + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + webvDescription.loadData(url, "text/html", "utf-8"); + setSupportProgressBarIndeterminateVisibility(false); + Log.d(TAG, "Webview loaded"); + } + + @Override + protected void onPreExecute() { + super.onPreExecute(); + setSupportProgressBarIndeterminateVisibility(true); + } + + @Override + protected Void doInBackground(Void... params) { + Log.d(TAG, "Loading Webview"); + url = ""; + try { + if (item.getContentEncoded() == null) { + url = URLEncoder.encode(item.getDescription(), "utf-8") + .replaceAll("\\+", " "); + } else { + url = URLEncoder.encode( + StringEscapeUtils.unescapeHtml4(item + .getContentEncoded()), "utf-8").replaceAll( + "\\+", " "); + } + + } catch (UnsupportedEncodingException e) { + url = "Page could not be loaded"; + e.printStackTrace(); + } + + return null; + } + + }; } |