From e68f4fbea437072c8c37581e48b371ecfa42fb92 Mon Sep 17 00:00:00 2001 From: RosmaryFC Date: Sun, 28 Jun 2015 12:56:28 -0400 Subject: [PATCH 1/2] inital commit --- src/main/java/nyc/c4q/ListViewActivity.java | 57 +++++++++++++++++++++ src/main/res/layout/activity_listview.xml | 24 ++++++--- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/main/java/nyc/c4q/ListViewActivity.java b/src/main/java/nyc/c4q/ListViewActivity.java index 78104c6..6425690 100644 --- a/src/main/java/nyc/c4q/ListViewActivity.java +++ b/src/main/java/nyc/c4q/ListViewActivity.java @@ -2,6 +2,13 @@ import android.app.Activity; import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.BaseAdapter; +import android.widget.ListAdapter; +import android.widget.ListView; import android.widget.TextView; public class ListViewActivity extends Activity { @@ -25,5 +32,55 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_listview); textLog = (TextView) findViewById(R.id.textLog); + + initializeListViewWithAdapter(); + } + + //todo:continue here + public void initializeListViewWithAdapter() { + final ListView list = (ListView) findViewById(R.id.list); + ListAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, COLORS); + Log.d("adapter.getcount()", " " + adapter.getCount()); + + +// for(int i = 0; i < COLORS.length; i++){ +// View v = adapter.getView(i, null, list); +// v.setBackgroundColor(Color.parseColor(COLORS[i])); +// } + + ListAdapter lAdapter = new BaseAdapter() { + @Override + public int getCount() { + return COLORS.length; + } + + @Override + public Object getItem(int i) { + return COLORS[i]; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + + + //view.setBackgroundColor(Color.parseColor(COLORS[i])); + + //((TextView) view).setText(COLORS[i]); + + return view; + } + }; + + + list.setAdapter(lAdapter); + + + } + } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 0d4b9d6..30c7331 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -9,20 +9,30 @@ + android:layout_weight="3" + android:layout_width="0dp" + android:layout_height="match_parent" + android:text="You have not clicked anything." /> + + + android:layout_weight="9" + android:layout_width="match_parent" + android:layout_height="0dp"/> \ No newline at end of file From 485e0615e3b6efc19f367d5158daeab50ae71685 Mon Sep 17 00:00:00 2001 From: RosmaryFC Date: Sun, 28 Jun 2015 16:43:55 -0400 Subject: [PATCH 2/2] attempting other tests --- src/main/AndroidManifest.xml | 3 + src/main/java/nyc/c4q/JSONActivity.java | 12 +-- src/main/java/nyc/c4q/ListViewActivity.java | 67 +++++++------- src/main/java/nyc/c4q/NetworkActivity.java | 92 ++++++++++++++++--- .../java/nyc/c4q/NotificationActivity.java | 42 ++++++++- src/main/java/nyc/c4q/json/Zipcode.java | 3 + src/main/res/layout/activity_listview.xml | 1 + 7 files changed, 161 insertions(+), 59 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index ea076f1..c06e122 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -4,6 +4,9 @@ android:versionCode="2" android:versionName="1.0.0-SNAPSHOT"> + + + pairs = new ArrayList(); + pairs.add(new BasicNameValuePair("key1", "value1")); + pairs.add(new BasicNameValuePair("key2", "value2")); + try { + post.setEntity(new UrlEncodedFormEntity(pairs)); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + HttpResponse response = client.execute(post); + httptextlog.setText(response.toString()); + + } catch (IOException e) { + e.printStackTrace(); + } + } }); @@ -104,4 +129,45 @@ public void onClick(View v) { } }); } + + + public static String GET(String url){ + InputStream inputStream = null; + String result = ""; + try { + // create HttpClient + HttpClient httpclient = new DefaultHttpClient(); + + // make GET request to the given URL + HttpResponse httpResponse = httpclient.execute(new HttpGet(url)); + + // receive response as inputStream + inputStream = httpResponse.getEntity().getContent(); + + // convert inputstream to string + if(inputStream != null) + result = convertInputStreamToString(inputStream); + else + result = "Did not work!"; + + } catch (Exception e) { + Log.d("InputStream", e.getLocalizedMessage()); + } + + return result; + } + + // convert inputstream to String + private static String convertInputStreamToString(InputStream inputStream) throws IOException { + BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream)); + String line = ""; + String result = ""; + while((line = bufferedReader.readLine()) != null) + result += line; + + inputStream.close(); + return result; + } + + } diff --git a/src/main/java/nyc/c4q/NotificationActivity.java b/src/main/java/nyc/c4q/NotificationActivity.java index f1f56ad..ec226d8 100644 --- a/src/main/java/nyc/c4q/NotificationActivity.java +++ b/src/main/java/nyc/c4q/NotificationActivity.java @@ -1,8 +1,13 @@ package nyc.c4q; import android.app.Activity; +import android.app.Notification; import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.NotificationCompat; +import android.view.View; import android.widget.Button; public class NotificationActivity extends Activity { @@ -17,13 +22,46 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - Button autocancelnotification = (Button) findViewById(R.id.autocancelnotification); Button swipenotification = (Button) findViewById(R.id.swipenotification); Button permanentnotification = (Button) findViewById(R.id.permanentnotification); Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification); Button buttonnotification = (Button) findViewById(R.id.buttonnotification); + autocancelnotification.setOnClickListener(autocancelListener); + + + + + + } + + public void createNotification (String contentTitle, String contentText, int id){ + notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + builder.setAutoCancel(true); + + builder.setContentTitle(contentTitle); + builder.setContentText(contentText); + builder.setSmallIcon(R.drawable.c4qfavicon); + + //pendingIntent + Intent resultIntent = new Intent (this, NotificationActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(pendingIntent); + + Notification notification = builder.build(); + notificationManager.notify(id, notification); } + + public View.OnClickListener autocancelListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + + createNotification("default@c4q.nyc", "Touch me to dismiss me!", ID_AUTOCANCEL_NOTIFICATION ); + + } + + }; } diff --git a/src/main/java/nyc/c4q/json/Zipcode.java b/src/main/java/nyc/c4q/json/Zipcode.java index 6d4761f..b5aa42f 100644 --- a/src/main/java/nyc/c4q/json/Zipcode.java +++ b/src/main/java/nyc/c4q/json/Zipcode.java @@ -1,4 +1,7 @@ package nyc.c4q.json; public class Zipcode { + + + } diff --git a/src/main/res/layout/activity_listview.xml b/src/main/res/layout/activity_listview.xml index 30c7331..59a342f 100644 --- a/src/main/res/layout/activity_listview.xml +++ b/src/main/res/layout/activity_listview.xml @@ -35,4 +35,5 @@ android:layout_weight="9" android:layout_width="match_parent" android:layout_height="0dp"/> + \ No newline at end of file