PhotoActivity.java (2121B)
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.ListActivity; 13 import android.content.Intent; 14 import android.os.Bundle; 15 import android.view.View; 16 import android.widget.AdapterView; 17 import android.widget.ListAdapter; 18 import android.widget.ListView; 19 import android.widget.AdapterView.OnItemClickListener; 20 import de.mtbnews.android.adapter.RSSContentAdapter; 21 import de.mtbnews.android.util.IBC; 22 import de.mtbnews.android.util.ServerAsyncTask; 23 24 /** 25 * Anzeige des RSSFeed für neue Fotos. 26 * 27 * @author dankert 28 * 29 */ 30 public class PhotoActivity extends ListActivity 31 { 32 @Override 33 protected void onCreate(Bundle savedInstanceState) 34 { 35 setTheme(((IBCApplication) getApplication()).themeResId); 36 setContentView(R.layout.listing); 37 38 super.onCreate(savedInstanceState); 39 40 new ServerAsyncTask(this, R.string.waitingforcontent) 41 { 42 43 private RSSFeed feed; 44 45 @Override 46 protected void callServer() throws IOException 47 { 48 final RSSReader reader = new RSSReader(); 49 try 50 { 51 feed = reader.load(IBC.IBC_FOTOS_RSS_URL); 52 } 53 catch (RSSReaderException e) 54 { 55 throw new ClientProtocolException("Feed not available", e); 56 } 57 catch (RSSFault e) 58 { 59 throw new ClientProtocolException("Feed not available", e); 60 } 61 } 62 63 protected void doOnSuccess() 64 { 65 ListAdapter adapter = new RSSContentAdapter(PhotoActivity.this, feed); 66 PhotoActivity.this.setTitle(feed.getTitle()); 67 68 setListAdapter(adapter); 69 } 70 }.execute(); 71 72 final ListView list = getListView(); 73 74 list.setOnItemClickListener(new OnItemClickListener() 75 { 76 77 @Override 78 public void onItemClick(AdapterView<?> parent, View view, int position, long id) 79 { 80 RSSItem item = (RSSItem) getListAdapter().getItem(position); 81 82 Intent i = new Intent(Intent.ACTION_VIEW); 83 i.setData(item.getLink()); 84 startActivity(i); 85 86 } 87 }); 88 89 } 90 }