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

test #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

test #13

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"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application android:name=".Unit2AssessmentApplication">
<activity
android:name=".Unit2AssessmentActivity"
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/nyc/c4q/JSONActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -23,6 +32,7 @@
public class JSONActivity extends Activity {

public List<Zipcode> zipcodes;
Zipcode z;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -42,17 +52,39 @@ protected void onCreate(Bundle savedInstanceState) {
final TextView _lat = (TextView) findViewById(R.id.fieldloclatvalue);
final TextView _long = (TextView) findViewById(R.id.fieldloclongvalue);


addjson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
z = new Zipcode("11101", "ASTORIA", "NY", 23142, new double[] {-73.939393,40.750316});
zipcodes.add(z);


}
});

savejson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String result = "\"_id\":\"" + z.get_id() + "\"pop\":\"" + "" + z.getPop() + "\"city\":\"" + z.getCity() + "\"state\":\"" + z.getState() + "" + "\"loc\":\"" + "" + z.getLoc()[0] + "" + "\"loc\":\"" + "" + z.getLoc()[1] + "";
File directory = getExternalCacheDir();
File file = new File(directory, "zipcodes.json");
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file, false);
} catch (IOException e) {
e.printStackTrace();
}
try {
fileWriter.write(result);
} catch (IOException e) {
e.printStackTrace();
}
try {
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});

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

try {
FileInputStream fis = new FileInputStream("zipcodes.json");
DataInputStream in = new DataInputStream(fis);
BufferedReader br =
new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
result +=strLine;
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}



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

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class ListViewActivity extends Activity {

public static final String[] COLORS = {
Expand All @@ -19,11 +30,28 @@ public class ListViewActivity extends Activity {
"#bf538d"
};
public TextView textLog;
public ListView listView;
public EditText adapterCount;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
textLog = (TextView) findViewById(R.id.textLog);
listView = (ListView) findViewById(R.id.list);
adapterCount = (EditText) findViewById(R.id.adapterCount);
// int n = Integer.parseInt(adapterCount.getText().toString());


ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, COLORS);
listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
textLog.setText("You clicked on Item(position=" + i + ", color=" + ListViewActivity.COLORS[i] + ")");
}
});

}
}
61 changes: 61 additions & 0 deletions src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.squareup.okhttp.FormEncodingBuilder;
Expand All @@ -16,10 +17,18 @@
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

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

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
Expand Down Expand Up @@ -76,12 +85,20 @@ protected void onCreate(Bundle savedInstanceState) {
httpbinget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MyAsync myAsync = new MyAsync();
myAsync.execute(String.format("https://httpbin.org/get?%s", urlParams));


}
});

httpbingetokhttp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String replaced = String.format("https://httpbin.org/get?%s", urlParams).replaceAll("\\+"," ");
MyAsync myAsync = new MyAsync();
myAsync.execute(replaced);

}
});

Expand All @@ -97,11 +114,55 @@ public void onClick(View v) {
}
});


cleartextlog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
httptextlog.setText("cleared HTTP response");
}
});
}

class MyAsync extends AsyncTask<String, Void, String> {

protected String doInBackground(String... strings) {
BufferedReader reader = null;
String line;

URL urlString = null;
try {
urlString = new URL(strings[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) urlString.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder stringBuilder = new StringBuilder();
try {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}

try {
while ((line = reader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
String resultString = stringBuilder.toString();
return resultString;
}

@Override
protected void onPostExecute(String result) {
httptextlog = (TextView) findViewById(R.id.httptextlog);
httptextlog.setText(result);
}
}
}
56 changes: 56 additions & 0 deletions src/main/java/nyc/c4q/NotificationActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
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.os.Handler;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.Button;

public class NotificationActivity extends Activity {
Expand All @@ -19,11 +26,60 @@ 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);
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) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this);
builder.setContentTitle("[email protected]");
builder.setContentText("Touch me to dismiss me!");
builder.setSmallIcon(R.drawable.c4qfavicon);

//disappears when the user read it
builder.setAutoCancel(true);

Notification notification = builder.build();
notificationManager.notify(ID_AUTOCANCEL_NOTIFICATION, notification);

}
});


swipenotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this);
builder.setContentTitle("[email protected]");
builder.setContentText("Swipe right if you want to meet me. Otherwise, I'm not going away.");
builder.setSmallIcon(R.drawable.c4qfavicon);


//disappears when the user read it
builder.setAutoCancel(true);

Notification notification = builder.build();
notificationManager.notify(ID_SWIPE_NOTIFICATION, notification);

}
});

dismisspermanentnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
notificationManager.cancel(NotificationActivity.ID_PERMANENT_NOTIFICATION);

}
});

}
}



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

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

public Zipcode(String _id, String city,String state, int pop, double[] loc) {
this._id = _id;
this.city = city;
this.state = state;
this.pop = pop;
this.loc = loc;
}

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 int getPop() {
return pop;
}

public void setPop(int pop) {
this.pop = pop;
}


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

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