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
11 changes: 5 additions & 6 deletions src/main/java/nyc/c4q/JSONActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

import nyc.c4q.json.Zipcode;

Expand All @@ -29,12 +23,16 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_json);

Gson gson = new Gson();


zipcodes = new ArrayList<Zipcode>();

Button savejson = (Button) findViewById(R.id.savejson);
Button loadjson = (Button) findViewById(R.id.loadjson);
Button addjson = (Button) findViewById(R.id.addjson);


final TextView _id = (TextView) findViewById(R.id.field_idvalue);
final TextView pop = (TextView) findViewById(R.id.fieldpopvalue);
final TextView city = (TextView) findViewById(R.id.fieldcityvalue);
Expand All @@ -45,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
addjson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});

Expand Down
64 changes: 63 additions & 1 deletion src/main/java/nyc/c4q/ListViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package nyc.c4q;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewActivity extends Activity {

//array of colors
public static final String[] COLORS = {
"#142b44",
"#1d508d",
Expand All @@ -18,12 +23,69 @@ public class ListViewActivity extends Activity {
"#fa5e5b",
"#bf538d"
};

//variables
private ListView list;
private ArrayAdapter arrayAdapter;
public TextView textLog;

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

//declaring variables
textLog = (TextView) findViewById(R.id.textLog);
EditText adapterCount = (EditText) findViewById(R.id.adapterCount);
list = (ListView) findViewById(R.id.list);

// this-The current activity context.
// Second param is the resource Id for list layout row item
// Third param is input array
arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, COLORS);
list.setAdapter(arrayAdapter);

//change the color for the division
// list.setDivider(new ColorDrawable());
ColorDrawable sage = new ColorDrawable(this.getResources().getColor(R.color.sage));
list.setDivider(sage);
list.setDividerHeight(2);
}
}

/*TODO: For test07- was I suppose to ColorDrawable to show the string values of the array into the color background (ex: the "#color" should show a color in one of the row backgrounds*/
//TODO: For test08- textLog should say "You clicked on Item(position=%s (item within the array), color=%s (color of the item)- Not sure within the listview or on the listview xml
//TODO: For test09 and 10- not sure what to do with the Inputs. Is there a for loop with boolean statements in it?


// The Idea was to make a View method that can use if statements to get the color from text to show color
//I got this info at http://www.survivingwithandroid.com/2013/04/android-listview-background-row-style.html

// public View getView(int position, View convertView, ViewGroup parent) {
// View v = convertView;
//
// PlanetHolder holder = new PlanetHolder();
//
// // First let's verify the convertView is not null
// if (convertView == null) {
// // This a new view we inflate the new layout
// LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// v = inflater.inflate(R.layout.row_layout, null);
// // Now we can fill the layout with the right values
// TextView tv = (TextView) v.findViewById(R.id.name);
//
// holder.planetNameView = tv;
//
// v.setTag(holder);
//
// v.setBackgroundResource(R.drawable.rounded_corner);
// }
// else
// holder = (PlanetHolder) v.getTag();
//
// Planet p = planetList.get(position);
// holder.planetNameView.setText(p.getName());
//
// return v;
// }

}
26 changes: 8 additions & 18 deletions src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
package nyc.c4q;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

public class NetworkActivity extends Activity {

// Fields ===========================
Expand All @@ -50,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) {
httptextlog = (TextView) findViewById(R.id.httptextlog);
httptextlog.setMovementMethod(new ScrollingMovementMethod());

/*
/* TODO: Are we suppose to do this? So Confused!!
The goal is to use AsyncTasks here.
Shortcut to create URL in Java:

Expand All @@ -73,9 +56,13 @@ protected void onCreate(Bundle savedInstanceState) {
https://httpbin.org/post
*/


//Todo: Are we Suppose to do this? Fill out the OnClicks?

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

}
});

Expand Down Expand Up @@ -105,3 +92,6 @@ public void onClick(View v) {
});
}
}

/*TODO: I know the concepts of GET and POST. Not sure how to use it though. Look at the ServiceHandler.java
* TODO: For test12- we want to go the GET parts of the URLConnection and for test13- we want to GET the OKHTTP*/
50 changes: 50 additions & 0 deletions src/main/java/nyc/c4q/NotificationActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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 {
private static final int NOTIFICATION_ID = 0 ;
NotificationManager notificationManager;
public static final int ID_AUTOCANCEL_NOTIFICATION = 1;
public static final int ID_SWIPE_NOTIFICATION = 2;
Expand All @@ -25,5 +32,48 @@ protected void onCreate(Bundle savedInstanceState) {
Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification);
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);



// View startDelayButton = findViewById(R.id.startDelay); <---Give Delay of the Notification
// startDelayButton.setOnClickListener(new View.OnClickListener()
// {
// @Override
// public void onClick(View v)
// {
// startDelay();
// }
// });

View cancelButton = findViewById(R.id.autocancelnotification);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelNotification();
}
});
}




private void updateNotification(String titleText, String contentText) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle(titleText);
builder.setContentText(contentText);
//builder.setSmallIcon(R.drawable.);
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(NOTIFICATION_ID, notification);
}

private void cancelNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
}

}
92 changes: 92 additions & 0 deletions src/main/java/nyc/c4q/ServiceHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package nyc.c4q;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
* Created by c4q-joshelynvivas on 6/28/15.
*/

//TODO: Does this have something to do with the url params? It includes POST, GET and HTTP
public class ServiceHandler {

String response = null;
public final static int GET = 1;
// public final static int POST = 2;

public ServiceHandler() {

}

/**
* Making service call
* @url - url to make request
* @method - http request method
* */
public String makeServiceCall(String url, int method) {
return this.makeServiceCall(url, method, null);
}

/**
* Making service call
* @url - url to make request
* @method - http request method
* @params - http request params
* */
public String makeServiceCall(String url, int method,
List<NameValuePair> params) {
try {
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;

// // Checking http request method type
// if (method == POST) {
// HttpPost httpPost = new HttpPost(url);
// adding post params
// if (params != null) {
// httpPost.setEntity(new UrlEncodedFormEntity(params));
// }
//
// httpResponse = httpClient.execute(httpPost);}

if (method == GET) {
// appending params to url
if (params != null) {
String paramString = URLEncodedUtils
.format(params, "utf-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);

httpResponse = httpClient.execute(httpGet);

}
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return response;

}
}


Loading