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

Rosmary fc #15

Open
wants to merge 2 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"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application android:name=".Unit2AssessmentApplication">
<activity
android:name=".Unit2AssessmentActivity"
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/nyc/c4q/JSONActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@

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 Down Expand Up @@ -45,6 +37,8 @@ protected void onCreate(Bundle savedInstanceState) {
addjson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


}
});

Expand All @@ -64,5 +58,7 @@ public void onClick(View v) {
File file = new File(directory, "zipcodes.json");
}
});


}
}
52 changes: 52 additions & 0 deletions src/main/java/nyc/c4q/ListViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewActivity extends Activity {
Expand All @@ -25,5 +28,54 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
textLog = (TextView) findViewById(R.id.textLog);

initializeListViewWithAdapter();

}

//todo:set background color
public void initializeListViewWithAdapter() {
final ListView list = (ListView) findViewById(R.id.list);
ListAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, COLORS);


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

// ListAdapter lAdapter = new BaseAdapter() {
// @Override
// public int getCount() {
// return COLORS.length;
// }
//
// @Override
// public Object getItem(int i) {
// return COLORS[i];
// }
//
// @Override
// public long getItemId(int i) {
// return i;
// }
//
// @Override
// public View getView(int i, View view, ViewGroup viewGroup) {
//
//
// //view.setBackgroundColor(Color.parseColor(COLORS[i]));
//
// //((TextView) view).setText(COLORS[i]);
//
// return view;
// }
// };


list.setAdapter(adapter);


}

}
92 changes: 79 additions & 13 deletions src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
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 org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class NetworkActivity extends Activity {

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


/*
The goal is to use AsyncTasks here.
Shortcut to create URL in Java:
Expand All @@ -76,6 +78,9 @@ protected void onCreate(Bundle savedInstanceState) {
httpbinget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

httptextlog.setText(String.format("https://httpbin.org/get?%s", urlParams));

}
});

Expand All @@ -88,6 +93,26 @@ public void onClick(View v) {
httpbinpost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String address = String.format("https://httpbin.org/get?%s", urlParams);
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(address);

List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("key1", "value1"));
pairs.add(new BasicNameValuePair("key2", "value2"));
try {
post.setEntity(new UrlEncodedFormEntity(pairs));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
HttpResponse response = client.execute(post);
httptextlog.setText(response.toString());

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

}
});

Expand All @@ -104,4 +129,45 @@ public void onClick(View v) {
}
});
}


public static String GET(String url){
InputStream inputStream = null;
String result = "";
try {
// create HttpClient
HttpClient httpclient = new DefaultHttpClient();

// make GET request to the given URL
HttpResponse httpResponse = httpclient.execute(new HttpGet(url));

// receive response as inputStream
inputStream = httpResponse.getEntity().getContent();

// convert inputstream to string
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";

} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}

return result;
}

// convert inputstream to String
private static String convertInputStreamToString(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;

inputStream.close();
return result;
}


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

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
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 @@ -17,13 +22,46 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);

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





}

public void createNotification (String contentTitle, String contentText, int id){
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);

builder.setContentTitle(contentTitle);
builder.setContentText(contentText);
builder.setSmallIcon(R.drawable.c4qfavicon);

//pendingIntent
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(id, notification);
}

public View.OnClickListener autocancelListener = new View.OnClickListener() {
@Override
public void onClick(View view) {

createNotification("[email protected]", "Touch me to dismiss me!", ID_AUTOCANCEL_NOTIFICATION );

}

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

public class Zipcode {



}
25 changes: 18 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,31 @@

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

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

</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_weight="9"
android:layout_width="match_parent"
android:layout_height="0dp"/>

</LinearLayout>