Skip to content

Commit

Permalink
Now able to parse local file and display in list view
Browse files Browse the repository at this point in the history
Need to cleanup code though
  • Loading branch information
axelson committed Dec 8, 2011
1 parent 2c99aa0 commit 5814bbb
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 18 deletions.
File renamed without changes.
30 changes: 18 additions & 12 deletions src/org/hicapacity/techhui/CommunityActivity.java
@@ -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();
}
}
29 changes: 23 additions & 6 deletions src/org/hicapacity/techhui/ConferenceActivity.java
@@ -1,5 +1,7 @@
package org.hicapacity.techhui;

import java.io.IOException;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
Expand All @@ -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();
}
}
38 changes: 38 additions & 0 deletions src/org/hicapacity/techhui/FileScheduleRetriever.java
@@ -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;
}

}
30 changes: 30 additions & 0 deletions src/org/hicapacity/techhui/ScheduleElement.java
@@ -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();
}
}
17 changes: 17 additions & 0 deletions src/org/hicapacity/techhui/ScheduleRetriever.java
@@ -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.