commit 82920acd16ffbb5e0e50aca9d1dd5e60f6709ce9
parent c3c04b3359b7beb9e831a190b3ab2cbc222a3df3
Author: Jan Dankert <devnull@localhost>
Date: Wed, 10 Oct 2012 00:02:38 +0200
Zum Anzeigen der News-Details eine WebView verwenden.
Diffstat:
4 files changed, 30 insertions(+), 211 deletions(-)
diff --git a/res/layout/detail.xml b/res/layout/detail.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<WebView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/webView"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+/>+
\ No newline at end of file
diff --git a/src/de/mtbnews/android/NewsDetailActivity.java b/src/de/mtbnews/android/NewsDetailActivity.java
@@ -10,17 +10,10 @@ import org.mcsoxford.rss.RSSReader;
import org.mcsoxford.rss.RSSReaderException;
import android.app.Activity;
-import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.text.Html;
-import android.text.format.DateFormat;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.TextView;
-import de.mtbnews.android.image.URLImageParser;
+import android.webkit.WebView;
import de.mtbnews.android.util.IBC;
import de.mtbnews.android.util.ServerAsyncTask;
@@ -32,13 +25,11 @@ public class NewsDetailActivity extends Activity
protected void onCreate(Bundle savedInstanceState)
{
prefs = PreferenceManager.getDefaultSharedPreferences(this);
- setContentView(R.layout.newsdetail);
+ setContentView(R.layout.detail);
super.onCreate(savedInstanceState);
- final TextView datum = (TextView) findViewById(R.id.item_date);
- final TextView desc = (TextView) findViewById(R.id.item_description);
- final Button button = (Button) findViewById(R.id.item_button);
+ final WebView webView = (WebView) findViewById(R.id.webView);
new ServerAsyncTask(this, R.string.waitingfor_news)
{
@@ -79,36 +70,32 @@ public class NewsDetailActivity extends Activity
final RSSItem item = feed.getItems().get(
getIntent().getIntExtra("itemid", 0));
- datum.setText(DateFormat.getTimeFormat(NewsDetailActivity.this)
- .format(item.getPubDate()));
+// final String title = DateFormat.getTimeFormat(NewsDetailActivity.this)
+// .format(item.getPubDate());
+
+// NewsDetailActivity.this.setTitle(title);
+
- // TextView name = (TextView) findViewById(R.id.item_title);
- // name.setText(item.getTitle());
-
- // if (e.getContent() != null)
final String html = item.getFullContent();
+
+ webView.getSettings().setLoadsImagesAutomatically(prefs.getBoolean("load_images", false));
+ webView.loadData(html,"text/html","UTF-16");
- Html.ImageGetter imageGetter = null;
- if (prefs.getBoolean("load_images", false))
- imageGetter = new URLImageParser(desc,
- NewsDetailActivity.this);
-
- desc.setText(Html.fromHtml(html, imageGetter, null));
setTitle(item.getTitle());
- button.setOnClickListener(new OnClickListener()
- {
-
- @Override
- public void onClick(View v)
-
- {
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(item.getLink());
- startActivity(i);
- }
- });
+ // button.setOnClickListener(new OnClickListener()
+ // {
+ //
+ // @Override
+ // public void onClick(View v)
+ //
+ // {
+ // Intent i = new Intent(Intent.ACTION_VIEW);
+ // i.setData(item.getLink());
+ // startActivity(i);
+ // }
+ // });
}
}.execute();
}
diff --git a/src/de/mtbnews/android/image/URLDrawable.java b/src/de/mtbnews/android/image/URLDrawable.java
@@ -1,22 +0,0 @@
-package de.mtbnews.android.image;
-
-import android.graphics.Canvas;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-
-public class URLDrawable extends BitmapDrawable
-{
- // the drawable that you need to set, you could set the initial drawing
- // with the loading image if you need to
- protected Drawable drawable;
-
- @Override
- public void draw(Canvas canvas)
- {
- // override the draw to facilitate refresh function later
- if (drawable != null)
- {
- drawable.draw(canvas);
- }
- }
-}
diff --git a/src/de/mtbnews/android/image/URLImageParser.java b/src/de/mtbnews/android/image/URLImageParser.java
@@ -1,153 +0,0 @@
-package de.mtbnews.android.image;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
-import android.text.Html.ImageGetter;
-import android.util.Log;
-import android.view.View;
-import de.mtbnews.android.util.IBC;
-
-public class URLImageParser implements ImageGetter
-{
- /**
- * Einfacher Bildercache, der zu einer URL das {@link Drawable} speichert.
- * Achtung: Bei nächsten GC-Lauf wird der Inhalt der Map entfernt.
- */
- private static Map<String, Drawable> drawableCache = new WeakHashMap<String, Drawable>();
-
- private Context context;
- private View view;
-
- /***
- * Construct the URLImageParser which will execute AsyncTask and refresh the
- * container
- *
- * @param t
- * @param c
- */
- public URLImageParser(View t, Context c)
- {
- this.context = c;
- this.view = t;
- }
-
- public Drawable getDrawable(String source)
- {
- URLDrawable urlDrawable = new URLDrawable();
-
- // get the actual source
- ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable);
-
- asyncTask.execute(source);
-
- // return reference to URLDrawable where I will change with actual image
- // from
- // the src tag
- return urlDrawable;
- }
-
- public class ImageGetterAsyncTask extends AsyncTask<String, Void, Drawable>
- {
- URLDrawable urlDrawable;
-
- public ImageGetterAsyncTask(URLDrawable d)
- {
- this.urlDrawable = d;
- }
-
- @Override
- protected Drawable doInBackground(String... params)
- {
- String source = params[0];
- return fetchDrawable(source);
- }
-
- @Override
- protected void onPostExecute(Drawable result)
- {
- if (result != null)
- {
-
- // set the correct bound according to the result from HTTP call
- urlDrawable.setBounds(0, 0, 0 + result.getIntrinsicWidth(),
- 0 + result.getIntrinsicHeight());
-
- // change the reference of the current drawable to the result
- // from the HTTP call
- urlDrawable.drawable = result;
-
- // redraw the image by invalidating the container
- URLImageParser.this.view.invalidate();
- }
- }
-
- /***
- * Get the Drawable from URL
- *
- * @param urlString
- * @return
- */
- private Drawable fetchDrawable(String urlString)
- {
- try
- {
- // Bild bereits im Cache?
- final Drawable drawableFromCache = drawableCache.get(urlString);
- if (drawableFromCache != null)
- return drawableFromCache;
-
- InputStream is = fetch(urlString);
- Drawable drawable = null;
- try
- {
- drawable = Drawable.createFromStream(is, "src");
- }
- catch (OutOfMemoryError e)
- {
- Log.w(IBC.TAG, "OutOfMemory: Image too big: "
- + e.getMessage(), e);
- }
- catch (Exception e)
- {
- Log
- .w(IBC.TAG, "unable to load image: "
- + e.getMessage(), e);
- }
- if (drawable == null)
- Log.w(IBC.TAG, "drawable is null, url=" + urlString);
- else
- drawable.setBounds(0, 0, 0 + drawable.getIntrinsicWidth(),
- 0 + drawable.getIntrinsicHeight());
-
- // Bild in den Cache einfügen
- drawableCache.put(urlString, drawable);
- return drawable;
- }
- catch (Exception e)
- {
- Log.w(IBC.TAG, e);
- return null;
- }
- }
-
- private InputStream fetch(String urlString)
- throws MalformedURLException, IOException
- {
- DefaultHttpClient httpClient = new DefaultHttpClient();
- HttpGet request = new HttpGet(urlString);
- HttpResponse response = httpClient.execute(request);
- return response.getEntity().getContent();
- }
- }
-}