Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit 2 Assessment #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
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
12 changes: 12 additions & 0 deletions src/main/java/nyc/c4q/JSONActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -31,6 +32,14 @@ protected void onCreate(Bundle savedInstanceState) {

zipcodes = new ArrayList<Zipcode>();

//Double [] location = {-73.939393,40.750316};

String JSON_ZIPCODE = "{\"_id\":\"11101\",\"city\":\"ASTORIA\",\"loc\":[-73.939393,40.750316],\"pop\":23142,\"state\":\"NY\"}";
Gson gson = new Gson();
Zipcode z = gson.fromJson(JSON_ZIPCODE, Zipcode.class);

zipcodes.add(z);

Button savejson = (Button) findViewById(R.id.savejson);
Button loadjson = (Button) findViewById(R.id.loadjson);
Button addjson = (Button) findViewById(R.id.addjson);
Expand All @@ -48,11 +57,14 @@ public void onClick(View v) {
}
});



savejson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File directory = getExternalCacheDir();
File file = new File(directory, "zipcodes.json");

}
});

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/nyc/c4q/ListViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package nyc.c4q;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewActivity extends Activity {
Expand All @@ -19,11 +28,29 @@ public class ListViewActivity extends Activity {
"#bf538d"
};
public TextView textLog;
public ListView list;
public ListAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);

textLog = (TextView) findViewById(R.id.textLog);
list = (ListView) findViewById(R.id.list);


adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_multiple_choice,
COLORS);
list.setAdapter(adapter);

for (int i = 0; i < COLORS.length; i++) {
View v = adapter.getView(i, null, list);
v.setBackgroundColor(Color.parseColor(COLORS[i]));
}
}



}
9 changes: 9 additions & 0 deletions src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import org.assertj.android.api.Assertions;

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -76,12 +78,19 @@ protected void onCreate(Bundle savedInstanceState) {
httpbinget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

httptextlog.setText(urlParams);

}
});

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

String replaced = urlParams.replaceAll("\\+"," ");
httptextlog.setText(replaced);

}
});

Expand Down
83 changes: 83 additions & 0 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.Context;
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 {
Expand All @@ -12,11 +18,14 @@ public class NotificationActivity extends Activity {
public static final int ID_PERMANENT_NOTIFICATION = 3;
public static final int ID_BUTTON_NOTIFICATION = 4;

NotificationCompat.Builder mBuilder;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);

//make instance of notification manager
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Button autocancelnotification = (Button) findViewById(R.id.autocancelnotification);
Expand All @@ -25,5 +34,79 @@ protected void onCreate(Bundle savedInstanceState) {
Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification);
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);

autocancelnotification.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

mBuilder =
new NotificationCompat.Builder(NotificationActivity.this)
.setSmallIcon(R.drawable.c4qfavicon)
.setContentTitle("[email protected]")
.setContentText("Touch me to dismiss me!")
.setAutoCancel(true);
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
// Builds the notification and issues it.
notificationManager.notify(ID_AUTOCANCEL_NOTIFICATION, mBuilder.build());
}
});

swipenotification.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

mBuilder =
new NotificationCompat.Builder(NotificationActivity.this)
.setSmallIcon(R.drawable.c4qfavicon)
.setContentTitle("[email protected]")
.setContentText("Swipe right if you want to meet me. Otherwise, I'm not going away.");
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
// Builds the notification and issues it.
notificationManager.notify(ID_SWIPE_NOTIFICATION, mBuilder.build());
}


});

permanentnotification.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

mBuilder =
new NotificationCompat.Builder(NotificationActivity.this)
.setSmallIcon(R.drawable.c4qfavicon)
.setContentTitle("[email protected]")
.setContentText("I'm staying planted right here.")
.setOngoing(true);
// Builds the notification and issues it.
notificationManager.notify(ID_PERMANENT_NOTIFICATION, mBuilder.build());
}
});

dismisspermanentnotification.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

mBuilder =
new NotificationCompat.Builder(NotificationActivity.this)
.setSmallIcon(R.drawable.c4qfavicon)
.setContentTitle("[email protected]")
.setContentText("I'm staying planted right here.");

notificationManager.cancel(ID_PERMANENT_NOTIFICATION);
}
});

buttonnotification.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

mBuilder =
new NotificationCompat.Builder(NotificationActivity.this)
.setSmallIcon(R.drawable.c4qfavicon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setAutoCancel(true);
// Builds the notification and issues it.
notificationManager.notify(ID_BUTTON_NOTIFICATION, mBuilder.build());
}
});

}

}

56 changes: 56 additions & 0 deletions src/main/java/nyc/c4q/json/Zipcode.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
package nyc.c4q.json;


public class Zipcode {

public String _id;
public String city;
public String state;
public double [] loc;
public int pop;

public Zipcode (String _id, String city, double [] loc, int pop, String state) {

this._id = _id;
this.city = city;
this.state = state;
this.loc = loc;
this.pop = pop;
}

public String get_id() {
return _id;
}

public void set_id(String _id) {
this._id = _id;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public double[] getLoc() {
return loc;
}

public void setLoc(double[] loc) {
this.loc = loc;
}

public int getPop() {
return pop;
}

public void setPop(int pop) {
this.pop = pop;
}
}
26 changes: 19 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,32 @@

<LinearLayout
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
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="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:text="You have not clicked anything." />

<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="phone"
android:ems="10"
android:id="@+id/adapterCount" />

</LinearLayout>


<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"/>
</LinearLayout>
1 change: 1 addition & 0 deletions src/test/java/nyc/c4q/Part3JSONActivityTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void test16JSONActivityCreateJSONMappingID() throws NoSuchFieldException,
assertThat(Zipcode.class.getField("_id").get(z), instanceOf(String.class));
assertThat((String) Zipcode.class.getField("_id").get(z), equalTo("11101"));


assertThat(Zipcode.class.getField("city").get(z), instanceOf(String.class));
assertThat((String) Zipcode.class.getField("city").get(z), equalTo("ASTORIA"));

Expand Down