android client
[scannr.git] / scannrmobile / src / com / example / scannrmobile / ScannrMobile.java
blob:a/scannrmobile/src/com/example/scannrmobile/ScannrMobile.java -> blob:b/scannrmobile/src/com/example/scannrmobile/ScannrMobile.java
--- a/scannrmobile/src/com/example/scannrmobile/ScannrMobile.java
+++ b/scannrmobile/src/com/example/scannrmobile/ScannrMobile.java
@@ -1,1 +1,66 @@
+package com.example.scannrmobile;
 
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import com.example.scannrmobile.HttpTask.HttpTaskHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import java.util.ArrayList;
+
+public class ScannrMobile extends Activity {
+    private ListView mainListView ;
+    private ArrayAdapter<String> listAdapter ;
+    private ScannrMobile view;
+    /**
+     * Called when the activity is first created.
+     */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+        mainListView = (ListView) findViewById( R.id.mainListView );
+        view = this;
+        //DownloadWebPageTask task = new DownloadWebPageTask();
+        //task.execute(new String[] { "http://www.vogella.com" });
+        HttpTask task = new HttpTask();
+
+        task.setTaskHandler(new HttpTaskHandler()
+        {
+            public void taskSuccessful(JSONArray nodes) {
+                // Just put the JSONObjects into an array list so we can use a ListAdapter
+                ArrayList<String> data = new ArrayList();
+                // Ingest Data
+                try {
+
+                Log.d(this.getClass().getName(), "Total Nodes: "+nodes.length());
+                for (int i = 0; i < nodes.length(); i++ ) {
+                    data.add(nodes.getJSONObject(i).toString() );
+                }
+                // TODO update the list
+                } catch (JSONException j){
+                    Log.e(this.getClass().getName(), j.getMessage());
+                }
+                // Create ArrayAdapter using the planet list.
+                listAdapter = new ArrayAdapter<String>(view, R.layout.simplerow, R.id.rowTextView, data);
+
+                // Set the ArrayAdapter as the ListView's adapter.
+                mainListView.setAdapter( listAdapter );
+            }
+
+            public void taskFailed() {
+                // handler failure (e.g network not available etc.)
+                Log.e(this.getClass().getName(),"Task Failed");
+            }
+        });
+        task.execute(new HttpGet("http://192.168.1.113/~maxious/scannr/calls.json.php?action=data"));
+    }
+
+
+}
+
+