Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added an RSS readring example

  • Loading branch information...
commit a529669e3c447ac5ec34f51d99971459444fab4c 1 parent 31fd283
@RobertSzkutak authored
Showing with 858 additions and 5 deletions.
  1. +3 −5 README
  2. +8 −0 RSSExample/.classpath
  3. +33 −0 RSSExample/.project
  4. +27 −0 RSSExample/AndroidManifest.xml
  5. BIN  RSSExample/bin/RSSExample.apk
  6. BIN  RSSExample/bin/classes.dex
  7. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$attr.class
  8. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$drawable.class
  9. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$id.class
  10. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$layout.class
  11. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$string.class
  12. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R.class
  13. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSExampleActivity$1.class
  14. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSExampleActivity$DownloadFeedTask.class
  15. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSExampleActivity.class
  16. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSFeed.class
  17. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSHandler.class
  18. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSItem.class
  19. BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/StoryActivity.class
  20. BIN  RSSExample/bin/res/drawable-hdpi/ic_launcher.png
  21. BIN  RSSExample/bin/res/drawable-ldpi/ic_launcher.png
  22. BIN  RSSExample/bin/res/drawable-mdpi/ic_launcher.png
  23. BIN  RSSExample/bin/resources.ap_
  24. +40 −0 RSSExample/gen/com/robertszkutak/androidexamples/rss/R.java
  25. +40 −0 RSSExample/proguard.cfg
  26. +11 −0 RSSExample/project.properties
  27. BIN  RSSExample/res/drawable-hdpi/ic_launcher.png
  28. BIN  RSSExample/res/drawable-ldpi/ic_launcher.png
  29. BIN  RSSExample/res/drawable-mdpi/ic_launcher.png
  30. +16 −0 RSSExample/res/layout/news.xml
  31. +8 −0 RSSExample/res/layout/newsoptions.xml
  32. +23 −0 RSSExample/res/layout/newsstory.xml
  33. +7 −0 RSSExample/res/values/strings.xml
  34. +211 −0 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSExampleActivity.java
  35. +70 −0 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSFeed.java
  36. +174 −0 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSHandler.java
  37. +82 −0 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSItem.java
  38. +105 −0 RSSExample/src/com/robertszkutak/androidexamples/rss/StoryActivity.java
View
8 README
@@ -14,6 +14,8 @@ These Android Examples each demonstrate a concept or a solution to a common prob
Imgur Example -- This is a simple single Activity Imgur client which uses the Android Web Browser to perform OAUTH authentication and uses the authenticated Imgur API to upload photos to the user's account.
+RSS Example -- Asynchronously loads an RSS feed. Allows for viewing of single items in the RSS feed. RSS Item viewer contains a simple HTML parser. Uses shared preferences for viewing different RSS feeds.
+
Tumblr Example -- This is a simple single Activity Tumblr client which uses the Android Web Browser to perform OAUTH authentication and allows the user to post to their blog.
Twitter Example -- This is a simple single Activity Twitter client which uses the Android Web Browser to perform OAUTH authentication and then send a Tweet using the Twitter4J library.
@@ -24,8 +26,4 @@ http://twitter.com/#!/robertszkutak
-- My Website --
-http://robertszkutak.com
-
--- My Blog --
-
-http://robertszkutak.blogspot.com
+http://robertszkutak.com
View
8 RSSExample/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 RSSExample/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RSSExample</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
27 RSSExample/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.robertszkutak.androidexamples.rss"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="4" />
+
+ <uses-permission android:name="android.permission.INTERNET"/>
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".RSSExampleActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".StoryActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation"></activity>
+ </application>
+
+</manifest>
View
BIN  RSSExample/bin/RSSExample.apk
Binary file not shown
View
BIN  RSSExample/bin/classes.dex
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$attr.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$drawable.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$id.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$layout.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R$string.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/R.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSExampleActivity$1.class
Binary file not shown
View
BIN  ...n/classes/com/robertszkutak/androidexamples/rss/RSSExampleActivity$DownloadFeedTask.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSExampleActivity.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSFeed.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSHandler.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/RSSItem.class
Binary file not shown
View
BIN  RSSExample/bin/classes/com/robertszkutak/androidexamples/rss/StoryActivity.class
Binary file not shown
View
BIN  RSSExample/bin/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  RSSExample/bin/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  RSSExample/bin/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  RSSExample/bin/resources.ap_
Binary file not shown
View
40 RSSExample/gen/com/robertszkutak/androidexamples/rss/R.java
@@ -0,0 +1,40 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package com.robertszkutak.androidexamples.rss;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int ic_launcher=0x7f020000;
+ }
+ public static final class id {
+ public static final int digitalClock1=0x7f050003;
+ public static final int imageView1=0x7f050001;
+ public static final int linearLayout1=0x7f050000;
+ public static final int linearLayout2=0x7f050002;
+ public static final int linearLayout3=0x7f050008;
+ public static final int link=0x7f05000b;
+ public static final int listView1=0x7f050004;
+ public static final int newsrefresh=0x7f050005;
+ public static final int newssettings=0x7f050006;
+ public static final int pub=0x7f05000c;
+ public static final int scrollView1=0x7f050007;
+ public static final int story=0x7f05000a;
+ public static final int title=0x7f050009;
+ }
+ public static final class layout {
+ public static final int news=0x7f030000;
+ public static final int newsoptions=0x7f030001;
+ public static final int newsstory=0x7f030002;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040001;
+ public static final int hello=0x7f040000;
+ }
+}
View
40 RSSExample/proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
View
11 RSSExample/project.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-4
View
BIN  RSSExample/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  RSSExample/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  RSSExample/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
16 RSSExample/res/layout/news.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:background="#FFFFFFFF">
+ <ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher"></ImageView>
+ <LinearLayout android:layout_height="fill_parent" android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:gravity="center_vertical|right">
+ <DigitalClock android:layout_height="wrap_content" android:textColor="#FF000000" android:id="@+id/digitalClock1" android:layout_width="wrap_content" android:text="DigitalClock" android:textSize="12pt"></DigitalClock>
+ </LinearLayout>
+ </LinearLayout>
+ <!--<TextView android:text="TextView" android:id="@+id/feedtitle" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
+ <TextView android:text="TextView" android:id="@+id/feedpubdate" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>TextView link = (TextView) findViewById(R.id.link);TextView link = (TextView) findViewById(R.id.link);-->
+ <ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>
+</LinearLayout>
View
8 RSSExample/res/layout/newsoptions.xml
@@ -0,0 +1,8 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/newsrefresh"
+ android:icon="@drawable/ic_launcher"
+ android:title="Refresh" />
+ <item android:id="@+id/newssettings"
+ android:icon="@+drawable/ic_launcher"
+ android:title="Change Feed" />
+</menu>
View
23 RSSExample/res/layout/newsstory.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="#FFFFFFFF">
+ <ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView1" android:layout_height="fill_parent">
+ <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
+ <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:orientation="horizontal">
+ <ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher"></ImageView>
+ <LinearLayout android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical|right">
+ <DigitalClock android:layout_height="wrap_content" android:id="@+id/digitalClock1" android:textSize="12pt" android:layout_width="wrap_content" android:text="DigitalClock" android:textColor="#FF000000"></DigitalClock>
+ </LinearLayout>
+ </LinearLayout>
+ <TextView android:textColor="#FF000000" android:layout_height="wrap_content" android:text="Title goes here ..." android:layout_width="wrap_content" android:id="@+id/title" android:textAppearance="?android:attr/textAppearanceLarge"></TextView>
+ <TextView android:textColor="#FF000000" android:autoLink="web" android:layout_height="wrap_content" android:text="story goes here ...." android:layout_width="fill_parent" android:id="@+id/story"></TextView>
+ <TextView android:textColor="#FF000000" android:autoLink="all" android:layout_height="wrap_content" android:text="Link goes here .." android:layout_width="wrap_content" android:id="@+id/link" android:textSize="4pt"></TextView>
+ <TextView android:textColor="#FF000000" android:layout_height="wrap_content" android:text="Publication date goes here ..." android:layout_width="wrap_content" android:textSize="4pt" android:id="@+id/pub"></TextView>
+ </LinearLayout>
+ </ScrollView>
+
+</LinearLayout>
View
7 RSSExample/res/values/strings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, RSSExampleActivity!</string>
+ <string name="app_name">RSSExample</string>
+
+</resources>
View
211 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSExampleActivity.java
@@ -0,0 +1,211 @@
+/*
+ RSSExampleActivity.java : Part of an example RSS Reader for Android
+ Copyright (C) 2011 Robert L Szkutak II (http://robertszkutak.com)
+ Copyright (C) 2011 Daniel S Lips (lipsapps on Android Market)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package com.robertszkutak.androidexamples.rss;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.*;
+import android.widget.ListView;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemClickListener;
+import java.net.URL;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+
+public class RSSExampleActivity extends Activity implements OnItemClickListener
+{
+ public final String tag = "RSSReader";
+
+ private RSSFeed feed = null;
+ ProgressDialog dialog;
+ AlertDialog alert;
+ DownloadFeedTask task;
+ SharedPreferences pref;
+ boolean in;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.news);
+
+ pref = PreferenceManager.getDefaultSharedPreferences(this);
+ in = pref.getBoolean("native", true);
+ new DownloadFeedTask().execute(new String (getFeed()));
+ }
+
+ public void onItemClick(AdapterView parent, View v, int position, long id)
+ {
+ Intent itemintent = null;
+
+ if(in)
+ {
+ itemintent = new Intent(this, StoryActivity.class);
+ itemintent.putExtra("title", feed.getItem(position).getTitle());
+ itemintent.putExtra("description", feed.getItem(position).getDescription());
+ itemintent.putExtra("link", feed.getItem(position).getLink());
+ itemintent.putExtra("pubdate", feed.getItem(position).getPubDate());
+ }
+ else
+ itemintent = new Intent(Intent.ACTION_VIEW, Uri.parse(feed.getItem(position).getLink().toString()));
+
+ startActivity(itemintent);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.layout.newsoptions, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
+ switch (item.getItemId())
+ {
+ case R.id.newssettings:
+ final CharSequence[] items = {"Latest Articles",
+ "Academic News",
+ "Arts and Entertainment"};
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Select a feed");
+ builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
+ final Editor editor = pref.edit();
+ switch(item)
+ {
+ case 0:
+ editor.putString("EXFEED", "http://ww2.fredonia.edu/News/DesktopModules/DnnForge%20-%20NewsArticles/Rss.aspx?TabID=1101&ModuleID=1878&MaxCount=25");
+ break;
+ case 1:
+ editor.putString("EXFEED", "http://ww2.fredonia.edu/News/DesktopModules/DnnForge%20-%20NewsArticles/RSS.aspx?TabID=1101&ModuleID=1878&CategoryID=14");
+ break;
+ case 2:
+ editor.putString("EXFEED", "http://ww2.fredonia.edu/News/DesktopModules/DnnForge%20-%20NewsArticles/RSS.aspx?TabID=1101&ModuleID=1878&CategoryID=28");
+ break;
+ }
+ editor.commit();
+ alert.cancel();
+ refreshCurrentFeed();
+ }
+ });
+ alert = builder.create();
+ alert.show();
+ break;
+ case R.id.newsrefresh:
+ refreshCurrentFeed();
+ break;
+ }
+ return true;
+ }
+
+ public String getFeed()
+ {
+ String ret = null;
+ ret = pref.getString("EXFEED", "http://ww2.fredonia.edu/News/DesktopModules/DnnForge%20-%20NewsArticles/Rss.aspx?TabID=1101&ModuleID=1878&MaxCount=25");
+
+ return ret;
+ }
+
+ public void refreshCurrentFeed() {
+ new DownloadFeedTask().execute(new String (getFeed()));
+ }
+
+ private class DownloadFeedTask extends AsyncTask<String, Void, RSSFeed>
+ {
+ @Override
+ protected RSSFeed doInBackground(String... RSSuri)
+ {
+ try
+ {
+ // setup the url
+ URL url = new URL(RSSuri[0]);
+ // create the factory
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ // create a parser
+ SAXParser parser = factory.newSAXParser();
+ // create the reader (scanner)
+ XMLReader xmlreader = parser.getXMLReader();
+ // instantiate our handler
+ RSSHandler theRssHandler = new RSSHandler();
+ // assign our handler
+ xmlreader.setContentHandler(theRssHandler);
+ // get our data via the url class
+ InputSource is = new InputSource(url.openStream());
+ // perform the synchronous parse
+ xmlreader.parse(is);
+ // get the results - should be a fully populated RSSFeed instance, or null on error
+ return theRssHandler.getFeed();
+ }
+ catch (Exception ee)
+ {
+ return null;
+
+ }
+ }
+
+ @Override
+ protected void onPostExecute(RSSFeed _resultFeed) {
+ feed = _resultFeed;
+ dialog.cancel();
+ UpdateDisplay();
+ }
+ @Override
+ protected void onPreExecute() {
+ dialog = ProgressDialog.show(RSSExampleActivity.this, "Fetching feed...", "Downloading");
+
+ }
+ }
+
+ private void UpdateDisplay()
+ {
+ ListView itemlist = (ListView) findViewById(R.id.listView1);
+
+ if (feed == null)
+ return;
+
+ ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems());
+
+ itemlist.setAdapter(adapter);
+ itemlist.setOnItemClickListener(this);
+ itemlist.setSelection(0);
+
+ }
+}
View
70 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSFeed.java
@@ -0,0 +1,70 @@
+/*
+ RSSFeed.java : Part of an example RSS Reader for Android
+ Copyright (C) 2011 Robert L Szkutak II (http://robertszkutak.com)
+ Copyright (C) 2011 Daniel S Lips (lipsapps on Android Market)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package com.robertszkutak.androidexamples.rss;
+
+import java.util.List;
+import java.util.Vector;
+
+public class RSSFeed
+{
+ private String _title = null;
+ private String _pubdate = null;
+ private int _itemcount = 0;
+ private List<RSSItem> _itemlist;
+
+ RSSFeed()
+ {
+ _itemlist = new Vector(0);
+ }
+ int addItem(RSSItem item)
+ {
+ _itemlist.add(item);
+ _itemcount++;
+ return _itemcount;
+ }
+ public RSSItem getItem(int location)
+ {
+ return _itemlist.get(location);
+ }
+ public List getAllItems()
+ {
+ return _itemlist;
+ }
+ int getItemCount()
+ {
+ return _itemcount;
+ }
+ void setTitle(String title)
+ {
+ _title = title;
+ }
+ void setPubDate(String pubdate)
+ {
+ _pubdate = pubdate;
+ }
+ String getTitle()
+ {
+ return _title;
+ }
+ String getPubDate()
+ {
+ return _pubdate;
+ }
+}
View
174 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSHandler.java
@@ -0,0 +1,174 @@
+/*
+ RSSHandler.java : Part of an example RSS Reader for Android
+ Copyright (C) 2011 Robert L Szkutak II (http://robertszkutak.com)
+ Copyright (C) 2011 Daniel S Lips (lipsapps on Android Market)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package com.robertszkutak.androidexamples.rss;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.*;
+
+public class RSSHandler extends DefaultHandler
+{
+ RSSFeed _feed;
+ RSSItem _item;
+ String _lastElementName = "";
+ boolean bFoundChannel = false;
+ final int RSS_TITLE = 1;
+ final int RSS_LINK = 2;
+ final int RSS_DESCRIPTION = 3;
+ final int RSS_CATEGORY = 4;
+ final int RSS_PUBDATE = 5;
+
+ StringBuffer chars = new StringBuffer();
+
+ int depth = 0;
+ int currentstate = 0;
+ /*
+ * Constructor
+ */
+ public RSSHandler()
+ {
+ }
+
+ /*
+ * getFeed - this returns our feed when all of the parsing is complete
+ */
+ public RSSFeed getFeed()
+ {
+ return _feed;
+ }
+
+
+ public void startDocument() throws SAXException
+ {
+ // initialize our RSSFeed object - this will hold our parsed contents
+ _feed = new RSSFeed();
+ // initialize the RSSItem object - we will use this as a crutch to grab the info from the channel
+ // because the channel and items have very similar entries..
+ _item = new RSSItem();
+
+ }
+ public void endDocument() throws SAXException
+ {
+ }
+ public void startElement(String namespaceURI, String localName,String qName, Attributes atts) throws SAXException
+ {
+
+ chars = new StringBuffer();
+
+ depth++;
+ if (localName.equals("channel"))
+ {
+ currentstate = 0;
+ return;
+ }
+ if (localName.equals("image"))
+ {
+
+ // record our feed data - we temporarily stored it in the item :)
+ _feed.setTitle(_item.getTitle());
+ _feed.setPubDate(_item.getPubDate());
+ }
+ if (localName.equals("item"))
+ {
+ // create a new item
+ _item = new RSSItem();
+ return;
+ }
+ if (localName.equals("title"))
+ {
+
+ currentstate = RSS_TITLE;
+ return;
+ }
+ if (localName.equals("description"))
+ {
+ currentstate = RSS_DESCRIPTION;
+ return;
+ }
+ if (localName.equals("link"))
+ {
+ currentstate = RSS_LINK;
+ return;
+ }
+ if (localName.equals("category"))
+ {
+ currentstate = RSS_CATEGORY;
+ return;
+ }
+ if (localName.equals("pubDate"))
+ {
+ currentstate = RSS_PUBDATE;
+ return;
+ }
+ // if we don't explicitly handle the element, make sure we don't wind up erroneously
+ // storing a newline or other bogus data into one of our existing elements
+ currentstate = 0;
+ }
+
+ public void endElement(String namespaceURI, String localName, String qName) throws SAXException
+ {
+ depth--;
+ if (localName.equals("item"))
+ {
+ // add our item to the list!
+ _feed.addItem(_item);
+ return;
+
+ }
+ switch (currentstate)
+ {
+ case RSS_TITLE:
+
+ _item.setTitle(chars.toString());
+ currentstate = 0;
+ break;
+ case RSS_LINK:
+ _item.setLink(chars.toString());
+ currentstate = 0;
+ break;
+ case RSS_DESCRIPTION:
+ _item.setDescription(chars.toString());
+ currentstate = 0;
+ break;
+ case RSS_CATEGORY:
+ _item.setCategory(chars.toString());
+ currentstate = 0;
+ break;
+ case RSS_PUBDATE:
+ _item.setPubDate(chars.toString());
+ currentstate = 0;
+ break;
+ default:
+ return;
+ }
+ }
+
+ public void characters(char ch[], int start, int length)
+ {
+// String theString = new String(ch,start,length);
+// Log.i("RSSReader","characters[" + theString + "]");
+
+
+ chars.append(new String(ch, start, length));
+
+
+
+ }
+}
+
View
82 RSSExample/src/com/robertszkutak/androidexamples/rss/RSSItem.java
@@ -0,0 +1,82 @@
+/*
+ RSSItem.java : Part of an example RSS Reader for Android
+ Copyright (C) 2011 Robert L Szkutak II (http://robertszkutak.com)
+ Copyright (C) 2011 Daniel S Lips (lipsapps on Android Market)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package com.robertszkutak.androidexamples.rss;
+
+public class RSSItem
+{
+ private String _title = null;
+ private String _description = null;
+ private String _link = null;
+ private String _category = null;
+ private String _pubdate = null;
+
+ RSSItem()
+ {
+ }
+ void setTitle(String title)
+ {
+ _title = title;
+ }
+ void setDescription(String description)
+ {
+ _description = description;
+ }
+ void setLink(String link)
+ {
+ _link = link;
+ }
+ void setCategory(String category)
+ {
+ _category = category;
+ }
+ void setPubDate(String pubdate)
+ {
+ _pubdate = pubdate;
+ }
+ public String getTitle()
+ {
+ return _title;
+ }
+ public String getDescription()
+ {
+ return _description;
+ }
+ public String getLink()
+ {
+ return _link;
+ }
+ public String getCategory()
+ {
+ return _category;
+ }
+ public String getPubDate()
+ {
+ return _pubdate;
+ }
+ public String toString()
+ {
+ if (_title.length() > 42)
+ {
+ return _title.substring(0, 42) + "...";
+ }
+ return _title;
+ }
+}
+
View
105 RSSExample/src/com/robertszkutak/androidexamples/rss/StoryActivity.java
@@ -0,0 +1,105 @@
+/*
+ StoryActivity.java : Part of an example RSS Reader for Android
+ Copyright (C) 2011 Robert L Szkutak II (http://robertszkutak.com)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package com.robertszkutak.androidexamples.rss;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+import android.content.Intent;
+
+public class StoryActivity extends Activity
+{
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.newsstory);
+
+ Intent startingIntent = getIntent();
+
+ TextView title = (TextView) findViewById(R.id.title);
+ TextView story = (TextView) findViewById(R.id.story);
+ TextView link = (TextView) findViewById(R.id.link);
+ TextView pub = (TextView) findViewById(R.id.pub);
+
+ if(startingIntent != null)
+ {
+ title.setText(startingIntent.getStringExtra("title"));
+ story.setText(parseHTML(" " + startingIntent.getStringExtra("description")+"\n"));
+ link.setText("Read More:\n" + startingIntent.getStringExtra("link") + "\n\n");
+ pub.setText("Published on : " + startingIntent.getStringExtra("pubdate"));
+ }
+ else
+ finish();
+ }
+
+ String parseHTML(String parse)
+ {
+ //Remove Tables
+ while(parse.contains("<table"))
+ {
+ int tableStart = parse.indexOf("<table");
+ int tableEnd = parse.indexOf("</table>", tableStart) + 8;
+ String table = parse.substring(tableStart, tableEnd);
+ parse = parse.replace(table, "\n ");
+ }
+ //Remove Images
+ while(parse.contains("<img"))
+ {
+ int imageStart = parse.indexOf("<img");
+ int imageEnd = parse.indexOf("/>", imageStart) + 2;
+ String image = parse.substring(imageStart, imageEnd);
+ parse = parse.replace(image, "\n ");
+ }
+ //Parse URLs
+ while(parse.contains("<a href="))
+ {
+ int linkStart = parse.indexOf("<a href=") + 9;
+ int linkEnd = parse.indexOf(">", linkStart);
+ String link = parse.substring(linkStart, linkEnd-1) + " ";
+ linkStart = parse.indexOf("<a");
+ linkEnd = parse.indexOf("</a>") + 4;
+ String oldlink = parse.substring(linkStart, linkEnd);
+ parse = parse.replace(oldlink, link);
+ }
+
+ //Combinational Tags
+ parse = parse.replaceAll("<div></div>", "");
+ parse = parse.replaceAll("<span></span>", "");
+ parse = parse.replaceAll("<div><span>", "\n ");
+ parse = parse.replaceAll("<span><div>", "\n ");
+
+ //Individual Tags
+ parse = parse.replaceAll("<br />", "");// "\n" ?
+ parse = parse.replaceAll("<br>", "");// "\n" ?
+ parse = parse.replaceAll("<div>", "\n ");
+ parse = parse.replaceAll("</div>", "");
+ parse = parse.replaceAll("<em>", "");
+ parse = parse.replaceAll("</em>", "");
+ parse = parse.replaceAll("<p>", "\n ");
+ parse = parse.replaceAll("</p>", "");
+ parse = parse.replaceAll("<span>", "\n ");
+ parse = parse.replaceAll("</span>", "");
+
+ //HTML Hex
+ parse = parse.replaceAll("&#160;", " ");
+
+ return parse;
+ }
+}

0 comments on commit a529669

Please sign in to comment.
Something went wrong with that request. Please try again.