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
38 changes: 36 additions & 2 deletions src/main/java/nyc/c4q/JSONActivity.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
package nyc.c4q;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

import nyc.c4q.json.Zipcode;
import nyc.c4q.json.ZipcodeDeserializer;

public class JSONActivity extends Activity {

public List<Zipcode> zipcodes;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -32,8 +47,8 @@ protected void onCreate(Bundle savedInstanceState) {
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 Button loadjson = (Button) findViewById(R.id.loadjson);
final Button addjson = (Button) findViewById(R.id.addjson);

final TextView _id = (TextView) findViewById(R.id.field_idvalue);
final TextView pop = (TextView) findViewById(R.id.fieldpopvalue);
Expand All @@ -42,9 +57,15 @@ protected void onCreate(Bundle savedInstanceState) {
final TextView _lat = (TextView) findViewById(R.id.fieldloclatvalue);
final TextView _long = (TextView) findViewById(R.id.fieldloclongvalue);

//_id.setText(zipcodes.hashCode());




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

}
});

Expand All @@ -53,6 +74,18 @@ public void onClick(View v) {
public void onClick(View v) {
File directory = getExternalCacheDir();
File file = new File(directory, "zipcodes.json");


ObjectOutputStream outputStream = null;
try{
outputStream = new ObjectOutputStream(new FileOutputStream(file));
System.out.println("Start Writings");
outputStream.writeObject(file);
outputStream.flush();
outputStream.close();
}catch (Exception e){
System.err.println("Error: " + e);
}
}
});

Expand All @@ -62,6 +95,7 @@ public void onClick(View v) {
public void onClick(View v) {
File directory = getExternalCacheDir();
File file = new File(directory, "zipcodes.json");

}
});
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/nyc/c4q/ListViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package nyc.c4q;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

public class ListViewActivity extends Activity {
ListView list;

public static final String[] COLORS = {
"#142b44",
Expand All @@ -18,12 +28,37 @@ public class ListViewActivity extends Activity {
"#fa5e5b",
"#bf538d"
};

public TextView textLog;
public EditText adapterCount;

@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);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, COLORS);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

int position = i;
String value = (String) list.getItemAtPosition(i);
//TODO working on the onClickItem
}
});
//
//
// // Show Alert
// Toast.makeText(getApplicationContext(),
// "Position :" + itemPosition + " ListItem : " + itemValue, Toast.LENGTH_LONG)
// .show();
//
// }
// }
}
}
63 changes: 62 additions & 1 deletion src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

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

public class NetworkActivity extends Activity {

Expand Down Expand Up @@ -50,6 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
httptextlog = (TextView) findViewById(R.id.httptextlog);
httptextlog.setMovementMethod(new ScrollingMovementMethod());

// new LoadingAsyntask().execute();
/*
The goal is to use AsyncTasks here.
Shortcut to create URL in Java:
Expand All @@ -73,15 +85,19 @@ protected void onCreate(Bundle savedInstanceState) {
https://httpbin.org/post
*/



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

}
});

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

}
});

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


}

public class LoadingAsyntask extends AsyncTask<String, Void, Boolean > {

@Override
protected void onPreExecute() {
super.onPreExecute();

}

@Override
protected Boolean doInBackground(String... strings) {

try {

HttpGet httppost = new HttpGet(urlParams);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);

// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();

if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);


JSONObject jsono = new JSONObject(data);

return true;
}


} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {

e.printStackTrace();
}
return false;
}

}

}
}
74 changes: 72 additions & 2 deletions src/main/java/nyc/c4q/NotificationActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package nyc.c4q;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
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 @@ -20,10 +23,77 @@ protected void onCreate(Bundle savedInstanceState) {
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);
final Button swipenotification = (Button) findViewById(R.id.swipenotification);
final Button permanentnotification = (Button) findViewById(R.id.permanentnotification);
Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification);
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);



autocancelnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
autoCanel(view);
}
});

swipenotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
swipeNotification(view);
}
});

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

dismisspermanentnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismissPermanNotification(view);
}
});
}


public void autoCanel (View view) {
Notification.Builder nb = new Notification.Builder(NotificationActivity.this);
nb.setContentTitle("default@c4q.nyc");
nb.setContentText("Touch me to dismiss me!");
nb.setSmallIcon(R.drawable.c4qfavicon);
nb.setAutoCancel(true);
Notification notification = nb.build();
notificationManager.notify(1,notification);
}

public void swipeNotification(View view) {
Notification.Builder nb = new Notification.Builder(NotificationActivity.this);
nb.setContentTitle("swipe@c4q.nyc");
nb.setContentText("Swipe right if you want to meet me. Otherwise, I'm not going away.");
nb.setSmallIcon(R.drawable.c4qfavicon);
Notification notification = nb.build();
notificationManager.notify(1,notification);
}

public void permanNotification(View view) {
Notification.Builder pn = new Notification.Builder(NotificationActivity.this);
pn.setContentTitle("permanent@c4q.nyc");
pn.setContentText("I'm staying planted right here.");
pn.setSmallIcon(R.drawable.c4qfavicon);
pn.setOngoing(true);
Notification notification = pn.build();
notificationManager.notify(1,notification);

}

public void dismissPermanNotification(View view) {
notificationManager.cancelAll();

}


}
Loading