Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
android:versionCode="2"
android:versionName="1.0.0-SNAPSHOT">

<uses-permission android:name="android.permission.INTERNET" />

<application android:name=".Unit2AssessmentApplication">
<activity
android:name=".Unit2AssessmentActivity"
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/nyc/c4q/ListViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package nyc.c4q;

import android.app.Activity;
import android.app.ListActivity;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class ListViewActivity extends Activity {



public static final String[] COLORS = {
"#142b44",
"#1d508d",
Expand All @@ -19,11 +31,25 @@ public class ListViewActivity extends Activity {
"#bf538d"
};
public TextView textLog;
public EditText adapterCount;
public ListView list;
public ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
textLog = (TextView) findViewById(R.id.textLog);

adapterCount = (EditText) findViewById(R.id.adapterCount);
list = (ListView) findViewById(R.id.list);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, COLORS );
list.setAdapter(adapter);

// for (int i = 0; i < COLORS.length; i++) {
//
// list.indexOfChild(i).setBackground(COLORS);
// }

}
}
10 changes: 10 additions & 0 deletions src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -73,6 +74,9 @@ protected void onCreate(Bundle savedInstanceState) {
https://httpbin.org/post
*/

String.format("https://httpbin.org/get?%s", urlParams);
httptextlog.setText(urlParams);

httpbinget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -82,12 +86,15 @@ public void onClick(View v) {
httpbingetokhttp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String replaced = urlParams.replaceAll("\\+"," ");
httptextlog.setText(replaced);
}
});

httpbinpost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});

Expand All @@ -103,5 +110,8 @@ public void onClick(View v) {
httptextlog.setText("cleared HTTP response");
}
});



}
}
95 changes: 93 additions & 2 deletions src/main/java/nyc/c4q/NotificationActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
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.service.notification.StatusBarNotification;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.Button;

public class NotificationActivity extends Activity {
Expand All @@ -19,11 +25,96 @@ protected void onCreate(Bundle savedInstanceState) {

notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Button autocancelnotification = (Button) findViewById(R.id.autocancelnotification);
final 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);
final Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification);
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);



Intent intent = new Intent(this, NotificationActivity.class);
final PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);


autocancelnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("default@c4q.nyc")
.setContentText("Touch me to dismiss me!")
.setSmallIcon(R.drawable.c4qfavicon)
.setContentIntent(pIntent)
.setAutoCancel(true)
.addAction(R.drawable.c4qfavicon, "And more", pIntent).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(0, n);
}
});

swipenotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("swipe@c4q.nyc")
.setContentText("Swipe right if you want to meet me. Otherwise, I'm not going away.")
.setSmallIcon(R.drawable.c4qfavicon)
.setContentIntent(pIntent)
.setAutoCancel(false)
.addAction(R.drawable.c4qfavicon, "And more", pIntent).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(1, n);
}
});

permanentnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("permanent@c4q.nyc")
.setContentText("I'm staying planted right here.")
.setSmallIcon(R.drawable.c4qfavicon)
.setContentIntent(pIntent).setOngoing(true)
.setAutoCancel(false)
.addAction(R.drawable.c4qfavicon, "And more", pIntent).build();


NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
n.flags = Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(0, n);
}
});

dismisspermanentnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("permanent@c4q.nyc")
.setContentText("I'm staying planted right here.")
.setSmallIcon(R.drawable.c4qfavicon)
.setContentIntent(pIntent).setOngoing(false)
.setAutoCancel(true)
.addAction(R.drawable.c4qfavicon, "And more", pIntent).build();


NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(0, n);

}
});






}
}
4 changes: 4 additions & 0 deletions src/main/res/drawable/color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<color android:name="mycolor">#FF6666</color>
</selector>
29 changes: 22 additions & 7 deletions src/main/res/layout/activity_listview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,35 @@

<LinearLayout
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1.0"
android:orientation="horizontal">

<TextView
android:id="@+id/textLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fill this textview" />
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="3.0"
android:text="You have not clicked anything." />

<EditText
android:id="@+id/adapterCount"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:inputType="phone"
android:text="Fill this textview2" />

</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="9.0"
android:background="@drawable/color"/>



</LinearLayout>
2 changes: 1 addition & 1 deletion src/main/res/layout/activity_network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/cleartextlog"
android:layout_alignParentBottom="true"
android:text="No HTTP response"
android:text="urlParams"
android:typeface="monospace" />

</RelativeLayout>
2 changes: 1 addition & 1 deletion src/test/java/nyc/c4q/Part4NotificationActivityTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void test21NotificationActivityCreateAutoCancelNotification(){
autocancelnotification.callOnClick();
ShadowNotificationManager snm = Robolectric.shadowOf(notificationManager);

assertThat(snm.size(), equalTo(1));
assertThat(snm.size(), equalTo(1));
ShadowNotification n = Robolectric.shadowOf(snm.getAllNotifications().get(0));

assertThat(n.getContentTitle().toString(), containsString("default@c4q.nyc"));
Expand Down