Skip to content

Instantly share code, notes, and snippets.

@clayallsopp
clayallsopp / structure.js
Created March 6, 2011 21:23
JSON structure for Brocabulary
[
{
"brocab": {
"description":"Fear of the brosephs",
"author":"",
"term":"Abroaphobia"
}
},
{
"brocab":{ ...
@clayallsopp
clayallsopp / Brocab.java
Created March 6, 2011 21:24
Initial Brocab object
public class Brocab {
String term;
String author;
String description;
public String getTerm() {
return term;
}
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:25
OfflineListActivity changes
String[] brocabs = {"Brotocol","Brobot","Theodore Broosevelt"};
ArrayList<Brocab> brocabList = new ArrayList<Brocab>(Arrays.asList(brocabs));
->
ArrayList<Brocab> brocabList = new ArrayList<Brocab>();
@clayallsopp
clayallsopp / BrocabAdapter.java
Created March 6, 2011 21:26
BrocabAdapter Changes
public class BrocabAdapter extends ArrayAdapter<String>
->
public class BrocabAdapter extends ArrayAdapter<Brocab>
public BrocabAdapter(Context context, int textViewResourceId, ArrayList<String> items)
->
public BrocabAdapter(Context context, int textViewResourceId, ArrayList<Brocab> items)
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:27
Loading brocabulary from file stub 1
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.local);
loadBrocabulary();
}
public void loadBrocabulary() {
...TO BE CONTINUED...
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:28
Loading brocabulary from file stub 2
public void loadBrocabulary() {
String jsonRep = null;
...
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:28
Loading brocabulary from file stub 3
...
try {
InputStream in = getResources().openRawResource(R.raw.iphone);
...TO BE CONTINUED...
} catch (Throwable t) {
Toast.makeText(this, "Exception: "+t.toString(), 2000).show();
}
...
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:29
Loading brocabulary from file stub 4
...
if (in != null) {
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
int n;
while((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:30
Loading brocabulary from file stub 5
...
String jsonRep = null;
try {
InputStream in = getResources().openRawResource(R.raw.iphone);
if (in != null) {
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
int n;
@clayallsopp
clayallsopp / OfflineListActivity.java
Created March 6, 2011 21:31
Loading brocabulary from file stub 6
...
try {
JSONArray jsonArray = new JSONArray(jsonRep);
...TO BE CONTINUED...
} catch (JSONException e) {
Toast.makeText(this, "JSONException: "+e.toString(), 2000).show();
}
...