Android Open Source - rss-parser Main Activity






From Project

Back to project page rss-parser.

License

The source code is released under:

Copyright (c) 2014 Artem Gapchenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the So...

If you think the Android project rss-parser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package aga.rssparser.sample;
/*from w w  w .j a  v  a 2  s  .  c  o m*/
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import java.net.MalformedURLException;

import aga.rssparser.RSSReadException;
import aga.rssparser.RSSReader;
import aga.rssparser.model.RSSChannel;
import aga.rssparser.model.RSSItem;

public class MainActivity extends ListActivity {
    private ArrayAdapter<RSSItem> mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAdapter = new RSSItemAdapter(this);

        setListAdapter(mAdapter);

        new AsyncTask<Void, Void, RSSChannel> () {
            @Override
            protected RSSChannel doInBackground(Void... params) {
                try {
                    final RSSReader reader = new RSSReader();

                    return reader.readFrom("http://feeds.feedburner.com/androidcentral?format=xml");
                } catch (MalformedURLException | RSSReadException ignored) {
                    Log.e(MainActivity.class.getName(), ignored.toString());
                }

                return null;
            }

            @Override
            protected void onPostExecute(final RSSChannel channel) {
                if (channel != null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        mAdapter.addAll(channel.getItems());
                    } else {
                        for (RSSItem item : channel.getItems()) {
                            mAdapter.add(item);
                        }
                    }

                    mAdapter.notifyDataSetChanged();
                } else {
                    Toast.makeText(MainActivity.this, "RSS loading error", Toast.LENGTH_LONG).show();
                }
            }
        }.execute(null, null);
    }
}




Java Source Code List

aga.rssparser.RSSReadException.java
aga.rssparser.RSSReader.java
aga.rssparser.Utils.java
aga.rssparser.model.Enclosure.java
aga.rssparser.model.FieldTypeAware.java
aga.rssparser.model.RSSChannel.java
aga.rssparser.model.RSSItem.java
aga.rssparser.sample.MainActivity.java
aga.rssparser.sample.RSSItemAdapter.java
aga.rssparser.sample.ViewHolder.java