android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/android-ibc-forum.git
Log | Files | Refs

NewsDetailActivity.java (2051B)


      1 package de.mtbnews.android;
      2 
      3 import java.io.IOException;
      4 
      5 import org.apache.http.client.ClientProtocolException;
      6 import org.mcsoxford.rss.RSSFault;
      7 import org.mcsoxford.rss.RSSFeed;
      8 import org.mcsoxford.rss.RSSItem;
      9 import org.mcsoxford.rss.RSSReader;
     10 import org.mcsoxford.rss.RSSReaderException;
     11 
     12 import android.app.Activity;
     13 import android.content.SharedPreferences;
     14 import android.os.Bundle;
     15 import android.preference.PreferenceManager;
     16 import android.webkit.WebView;
     17 import de.mtbnews.android.util.IBC;
     18 import de.mtbnews.android.util.ServerAsyncTask;
     19 
     20 public class NewsDetailActivity extends Activity
     21 {
     22 	protected SharedPreferences prefs;
     23 
     24 	@Override
     25 	protected void onCreate(Bundle savedInstanceState)
     26 	{
     27 		super.onCreate(savedInstanceState);
     28 
     29 		setTheme(((IBCApplication) getApplication()).themeResId);
     30 		setContentView(R.layout.detail);
     31 
     32 		prefs = PreferenceManager.getDefaultSharedPreferences(this);
     33 
     34 		final WebView webView = (WebView) findViewById(R.id.webView);
     35 
     36 		new ServerAsyncTask(this, R.string.waitingfor_news)
     37 		{
     38 			private RSSFeed feed;
     39 
     40 			@Override
     41 			protected void callServer() throws IOException
     42 			{
     43 				final RSSFeed oldFeed = ((IBCApplication) getApplication()).getNewsFeed();
     44 
     45 				if (oldFeed != null)
     46 				{
     47 					feed = oldFeed;
     48 				}
     49 				else
     50 				{
     51 
     52 					RSSReader reader = new RSSReader();
     53 					try
     54 					{
     55 						feed = reader.load(IBC.IBC_NEWS_RSS_URL);
     56 						((IBCApplication) getApplication()).setNewsFeed(feed);
     57 					}
     58 					catch (RSSReaderException e)
     59 					{
     60 						throw new ClientProtocolException(e);
     61 					}
     62 					catch (RSSFault e)
     63 					{
     64 						throw new ClientProtocolException(e);
     65 					}
     66 				}
     67 			}
     68 
     69 			protected void doOnSuccess()
     70 			{
     71 				final RSSItem item = feed.getItems().get(getIntent().getIntExtra("itemid", 0));
     72 
     73 				final String html = item.getFullContent();
     74 
     75 				webView.getSettings().setLoadsImagesAutomatically(prefs.getBoolean("load_images", false));
     76 				webView.loadDataWithBaseURL(IBC.IBC_NEWS_RSS_URL, html, "text/html", "UTF-8", null);
     77 
     78 				setTitle(item.getTitle());
     79 			}
     80 		}.execute();
     81 	}
     82 
     83 }