Permalink
Browse files

Now able to parse local file and display in list view

Need to cleanup code though
  • Loading branch information...
1 parent 2c99aa0 commit 5814bbbde5b7384c39c31319426b6671dca71de5 @axelson axelson committed Dec 8, 2011
File renamed without changes.
@@ -1,19 +1,25 @@
package org.hicapacity.techhui;
-import android.app.Activity;
+import android.app.ListActivity;
import android.os.Bundle;
-import android.widget.TextView;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.Toast;
-/**
- * @author Jason Axelson
- *
- */
-public class CommunityActivity extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+public class CommunityActivity extends ListActivity {
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry",
+ "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" };
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
+ android.R.layout.simple_list_item_1, values);
+ setListAdapter(adapter);
+ }
- TextView textview = new TextView(this);
- textview.setText("This is the community tab");
- setContentView(textview);
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ String item = (String) getListAdapter().getItem(position);
+ Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
@@ -1,5 +1,7 @@
package org.hicapacity.techhui;
+import java.io.IOException;
+import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
@@ -11,16 +13,31 @@
public class ConferenceActivity extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry",
- "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" };
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1, values);
- setListAdapter(adapter);
+ System.out.println("creating conference activity");
+
+ ScheduleRetriever scheduleRetriever = new FileScheduleRetriever(getAssets());
+ List<ScheduleElement> elements = null;
+ try {
+ elements = scheduleRetriever.getElements();
+ }
+ catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
+ // "Blackberry",
+ // "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" };
+ // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
+ // android.R.layout.simple_list_item_1, values);
+ ArrayAdapter<ScheduleElement> adapter = new ArrayAdapter<ScheduleElement>(this,
+ android.R.layout.simple_list_item_1, elements);
+ this.setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
- String item = (String) getListAdapter().getItem(position);
+ ScheduleElement item = (ScheduleElement) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
@@ -0,0 +1,38 @@
+package org.hicapacity.techhui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.res.AssetManager;
+
+/**
+ * @author Jason Axelson
+ *
+ */
+public class FileScheduleRetriever implements ScheduleRetriever {
+ AssetManager mManager;
+
+ public FileScheduleRetriever(AssetManager manager) {
+ mManager = manager;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public List<ScheduleElement> getElements() throws IOException {
+ BufferedReader br = null;
+ br = new BufferedReader(new InputStreamReader(mManager.open("data.txt")));
+ System.out.println(br.readLine());
+ ArrayList<ScheduleElement> scheduleList = new ArrayList<ScheduleElement>();
+ String line;
+ while ((line = br.readLine()) != null) {
+ System.out.println(line);
+ ScheduleElement scheduleElement = ScheduleElement.parseFromString(line);
+ scheduleList.add(scheduleElement);
+ }
+ return scheduleList;
+ }
+
+}
@@ -0,0 +1,30 @@
+package org.hicapacity.techhui;
+
+/**
+ * @author Jason Axelson
+ *
+ */
+public class ScheduleElement {
+ private String mTitle;
+ private String mTime;
+
+ public ScheduleElement(String title, String time) {
+ mTime = title;
+ mTime = time;
+ }
+
+ public static ScheduleElement parseFromString(String input) {
+ return new ScheduleElement("fake time", input);
+ }
+
+ public String getShortDescription() {
+ String string = mTime + mTitle;
+ return string.substring(0, 20);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return this.getShortDescription();
+ }
+}
@@ -0,0 +1,17 @@
+package org.hicapacity.techhui;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author Jason Axelson
+ *
+ */
+public interface ScheduleRetriever {
+
+ /**
+ * @return
+ * @throws IOException
+ */
+ public List<ScheduleElement> getElements() throws IOException;
+}

0 comments on commit 5814bbb

Please sign in to comment.