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

Jose G #25

Open
wants to merge 4 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
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
16 changes: 10 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 @@ -28,6 +22,7 @@ public class JSONActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_json);
final String JSON_ZIPCODE = "{\"_id\":\"11101\",\"city\":\"ASTORIA\",\"loc\":[-73.939393,40.750316],\"pop\":23142,\"state\":\"NY\"}";

zipcodes = new ArrayList<Zipcode>();

Expand All @@ -42,6 +37,15 @@ protected void onCreate(Bundle savedInstanceState) {
final TextView _lat = (TextView) findViewById(R.id.fieldloclatvalue);
final TextView _long = (TextView) findViewById(R.id.fieldloclongvalue);


Gson gson = new Gson();
Zipcode z = gson.fromJson(JSON_ZIPCODE,Zipcode.class);

z.setId("11101");
z.setCity("ASTORIA");
z.setState("NY");
z.setPop(23142);

addjson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/nyc/c4q/ListViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package nyc.c4q;

import android.app.Activity;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
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.lang.reflect.Array;
import java.util.List;

public class ListViewActivity extends Activity {

public static final String[] COLORS = {
Expand All @@ -19,11 +31,30 @@ public class ListViewActivity extends Activity {
"#bf538d"
};
public TextView textLog;
public ListView list;
public EditText adapterCount;
// public Color[] colorArray = R.array.colorArray;

@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);
adapterCount = (EditText) findViewById(R.id.adapterCount);

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

for (int i = 0; i < COLORS.length; i++) {
View v = adapter.getView(i,null,list);
// for(int j =0; j < colorArray.length;j++)
//v.setBackgroundColor(array.colorArray[j]);

}




}
}
41 changes: 40 additions & 1 deletion 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 @@ -50,6 +51,27 @@ protected void onCreate(Bundle savedInstanceState) {
httptextlog = (TextView) findViewById(R.id.httptextlog);
httptextlog.setMovementMethod(new ScrollingMovementMethod());

AsyncTask replaceText = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
httptextlog.setText(urlParams);

return null;
}
};

AsyncTask replaceText2 = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
String replaced = urlParams.replaceAll("\\+"," ");
httptextlog.setText(replaced);
return null;
}
};
replaceText.execute();
replaceText2.execute();


/*
The goal is to use AsyncTasks here.
Shortcut to create URL in Java:
Expand All @@ -73,9 +95,16 @@ protected void onCreate(Bundle savedInstanceState) {
https://httpbin.org/post
*/

final String newUrl = "https://httpbin.org/get?custname=james+dean&custtel=347-841-6090&custemail=hello%40c4q.nyc&size=small&topping=cheese&delivery=18%3A15&comments=Leave+it+by+the+garage+door.+Don%27t+ask+any+questions.";

httpbinget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
httptextlog.setText(run(newUrl));
} catch (IOException e) {
e.printStackTrace();
}
}
});

Expand All @@ -102,6 +131,16 @@ public void onClick(View v) {
public void onClick(View v) {
httptextlog.setText("cleared HTTP response");
}
});
});}

public String run(String url) throws IOException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();

}

}
75 changes: 75 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 @@ -25,5 +31,74 @@ protected void onCreate(Bundle savedInstanceState) {
Button dismisspermanentnotification = (Button) findViewById(R.id.dismisspermanentnotification);
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);

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

NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this.getApplicationContext());

builder.setContentTitle("[email protected]");
builder.setContentText("Touch me to dismiss me!");
builder.setSmallIcon(R.drawable.c4qfavicon);

PendingIntent pendingIntent =
PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
builder.setContentIntent(pendingIntent);

Notification n = builder.build();
n.flags |= Notification.FLAG_AUTO_CANCEL;
builder.setAutoCancel(true);
notificationManager.notify(ID_AUTOCANCEL_NOTIFICATION, n);
}
});

swipenotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this.getApplicationContext());

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

PendingIntent pendingIntent =
PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
builder.setContentIntent(pendingIntent);

Notification n = builder.build();
builder.setAutoCancel(false);
notificationManager.notify(ID_SWIPE_NOTIFICATION, n);
}
});

permanentnotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this.getApplicationContext());

builder.setContentTitle("[email protected]");
builder.setContentText("I'm staying planted right here.");
builder.setSmallIcon(R.drawable.c4qfavicon);

PendingIntent pendingIntent =
PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
builder.setContentIntent(pendingIntent);

Notification n = builder.build();
builder.setAutoCancel(false);
builder.setOngoing(true);
n.flags |= Notification.FLAG_NO_CLEAR;
notificationManager.notify(ID_PERMANENT_NOTIFICATION, n);
}
});

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

}
}

3 changes: 3 additions & 0 deletions src/main/java/nyc/c4q/Unit2AssessmentActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nyc.c4q;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Expand Down Expand Up @@ -53,4 +54,6 @@ public void onClick(View v) {
});

}


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

public class Zipcode {
public String id;
public String city;
public String state;
public int pop;

public String getCity() {
return city;
}

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

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public int getPop() {
return pop;
}

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

public String getState() {
return state;
}

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

public String getField(String field){
if(field.equalsIgnoreCase("_id")){
return this.id;
}else if(field.equalsIgnoreCase("city")){
return this.city;
}else if(field.equalsIgnoreCase("state")){
return this.state;
}else if(field.equalsIgnoreCase("pop")){
return String.valueOf(this.pop);
}
else return null;
}
}
24 changes: 17 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,30 @@

<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:id="@+id/adapterCount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="phone"/>


</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>
15 changes: 15 additions & 0 deletions src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name = "colorArray">
<item> <color name = "color1">#142b44</color> </item>
<item> <color name = "color2">#1d508d</color> </item>
<item> <color name = "color3">#297cbb</color> </item>
<item> <color name = "color4">#288ad6</color> </item>
<item> <color name = "color5">#0fdebd</color> </item>
<item> <color name = "color6">#16c98d</color> </item>
<item> <color name = "color7">#feef6d</color> </item>
<item> <color name = "color8">#ffc83f</color> </item>
<item> <color name = "color9">#fa5e5b</color> </item>
<item> <color name = "color10">#bf538d</color> </item>
</array>
</resources>
Loading