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 #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

test #14

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"/>


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

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

import java.lang.reflect.Array;

import static nyc.c4q.R.color.background;

public class ListViewActivity extends Activity {

public static final String[] COLORS = {
Expand All @@ -17,13 +23,26 @@ public class ListViewActivity extends Activity {
"#ffc83f",
"#fa5e5b",
"#bf538d"


};

public TextView textLog;
public ListView listView;

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

textLog = (TextView) findViewById(R.id.textLog);


//I was trying to create a list adapter
// listView = (ListView) findViewById(R.id.list);
//ListView listView = new ListView(this);
// listView= (ListView) findViewById(R.id.list);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_listview,COLORS);
// listView.setAdapter(adapter);
}
}
177 changes: 146 additions & 31 deletions src/main/java/nyc/c4q/NetworkActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@
import android.widget.Button;
import android.widget.TextView;

import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
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 org.json.JSONArray;
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;
Expand All @@ -36,8 +43,66 @@ public class NetworkActivity extends Activity {
public Button cleartextlog;
final public String urlParams = "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't+ask+any+questions.";


// Code ===========================

public static String url = "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't+ask+any+questions.";

//JSON Node Names
public static final String comments = "comments";
public static final String custemail = "custemail";
public static final String custel = "custel";
public static final String delivery = "delivery";
public static final String size = "size";
public static final String topping = "topping";

public String getUrlParams() {
return urlParams;
}

public static String getUrl() {
return url;
}

public static void setUrl(String url) {
NetworkActivity.url = url;
}

public static String getComments() {
return comments;
}

public static String getCustemail() {
return custemail;
}

public static String getCustel() {
return custel;
}

public static String getDelivery() {
return delivery;
}

public static String getSize() {
return size;
}

public static String getTopping() {
return topping;
}

public JSONArray getJSONArray() {
return mJSONArray;
}

public void setJSONArray(JSONArray JSONArray) {
mJSONArray = JSONArray;
}

JSONArray mJSONArray = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -49,13 +114,19 @@ protected void onCreate(Bundle savedInstanceState) {
cleartextlog = (Button) findViewById(R.id.cleartextlog);
httptextlog = (TextView) findViewById(R.id.httptextlog);
httptextlog.setMovementMethod(new ScrollingMovementMethod());
final String TAG = NetworkActivity.class.getSimpleName();



/*
The goal is to use AsyncTasks here.
Shortcut to create URL in Java:

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




HTTP GET request we'll be using:

$ curl "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."
Expand All @@ -73,35 +144,79 @@ 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) {
}
});

httpbinpost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});

httpbinpostokhttp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});

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

if (

isNetworkAvailable()

)

{
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}

@Override
public void onResponse(Response response) throws IOException {
try {
String jsonData = response.body().string();
Log.d(TAG, jsonData);
if (response.isSuccessful()) {
getJSONArray();

Log.v(TAG, jsonData);
}
} catch (IOException e) {
Log.d(TAG, "Exception caught", e);
}

}

});


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

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

httpbinpost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});

httpbinpostokhttp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});

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


}

private boolean isNetworkAvailable() {
return false;
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/nyc/c4q/NotificationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ protected void onCreate(Bundle savedInstanceState) {
Button buttonnotification = (Button) findViewById(R.id.buttonnotification);

}


}
28 changes: 28 additions & 0 deletions src/main/res/color/background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<color android:name="a">#142b44</color>
<color android:name="b">#1d508d</color>
<color android:name="c">#297cbb</color>
<color android:name="d">#288ad6</color>
<color android:name="e">#0fdebd</color>
<color android:name="f">#feef6d</color>
<color android:name="g">#feef6d</color>
<color android:name="h">#ffc83f</color>
<color android:name="i">#fa5e5b</color>
<color android:name="j">#bf538d</color>

<array android:name="background">
<item>@color/a</item>
<item>@color/b</item>
<item>@color/c</item>
<item>@color/d</item>
<item>@color/e</item>
<item>@color/f</item>
<item>@color/g</item>
<item>@color/h</item>
<item>@color/i</item>
<item>@color/j</item>
</array>

</selector>
26 changes: 19 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,32 @@

<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.0"
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.0"
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.0"
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.0"
android:background="@color/background"
/>
</LinearLayout>
6 changes: 3 additions & 3 deletions src/main/res/layout/json_zipcodetile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:text="00010"
android:text="11101"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace" />
</LinearLayout>
Expand All @@ -47,7 +47,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:text="10"
android:text="23142"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace" />
</LinearLayout>
Expand All @@ -70,7 +70,7 @@
android:id="@+id/fieldcityvalue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEW YORK"
android:text="ASTORIA"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace" />
</LinearLayout>
Expand Down
Loading