RssReader, an Android RSS aggregator
Nothing new on the planet, RSS aggregator apps are VERY common on the Android platform. Still I would say RSS readers are the "contact book for the C language" of the Android platform : it's the common application that any developper has to make to get an overview of the basic mechanism of Android's API.
What is this project about:
1) Build a RSS XML parser to get RSS file into structured data.
2) Display RSS feed titles in a list widget
3) Catch click event and open the url link on a new web browser instance00
4) Allow user configuration of RSS stream to subscribe to
5) Proper error handling and management
05/10/2011
This project is almost finished : about 8hr work. The code is still a little messy, writing inline listener code is certainly pratical but makes the code bulky and hardly readable. For instance : writing code but not knowing in which class I actually was !
I think the Android API looks like all modern GUI API : MVC (Model View Controller) approach, XML descriptions of the view layer, event based. I always find this kind of programming to be hard to debug although easy to maintain. Here, thanks to the Eclipse Android plugin, to process is pretty smooth.
09/10/2011
The Android.widget.ListView class
This class is particular in the way that this widget displays a list, but each element cannot not be added or edited individually. Instead this widget has to be backed by a class that describe how to access each data element and how this element should be displayed : the Android.widget.BaseAdapter class.
Here is the version of my RSS listview adapter:
public class RssAdapter extends BaseAdapter {
private ArrayList<Entry> entries;
LayoutInflater inflater;
Context context;
public RssAdapter(Context context,ArrayList<Entry> entries) {
inflater = LayoutInflater.from(context);
this.entries = entries;
this.context = context;
}
public int getCount() {
return this.entries.size();
}
public Object getItem(int position) {
return this.entries.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
{
RssSaxHandler.Entry e = (RssSaxHandler.Entry)this.entries.get(position);
View v = inflater.inflate(R.layout.entry, null);
TextView tv;
tv = (TextView)v.findViewById(R.id.tvTitre);
tv.setText(e.getTitle());
return v;
}
else
{
return convertView;
}
}
}
Straightforward, the listview is here backed by an ArrayList containing RSS headline element.
Each element of the ListView is a TextView element containing one RSS headline title. The convertView parameter contains the former ListView element value, that is null the first time we get into this function so we create the TextView for it, but the other time with just return the former TextView value.
I have to initialize my ListView and set it as content of the main window, so that my application will directly display my ListView at startup.
ListView listview = new ListView(this);
RssAdapter rssadapter = new RssAdapter(this, arraylist);
listview.setAdapter(rssadapter);
setContentView(listview);
How to save user favorite RSS Urls ?
Now that user has entered his own prefered sites, we have to save data to disk. Android is well organized for that matters. A specific path is dedicated on the phone storage space, that path will be: /Android/data/
/files/.
Official doc about data storage : http://developer.android.com/guide/topics/data/data-storage.html
On the first call to getExternalFilesDir() the full path will be created.
Don't forget to add permission to write to the external storage in the application manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
24/04/2012
I've forked this project to create a french news reader application: MesNewzMatos:
https://play.google.com/store/apps/details?id=com.nicolasmy.mesnewzmatos