Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

my test #15

Open
wants to merge 1 commit 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
8 changes: 2 additions & 6 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ListViewActivity"
android:windowSoftInputMode="adjustPan" />
<activity android:name=".NetworkActivity" />
<activity android:name=".JSONActivity" />
<activity android:name=".NotificationActivity" />


<activity
android:name=".PaceCalculatorActivity"
android:label="@string/title_activity_pace_calculator"
Expand Down
136 changes: 136 additions & 0 deletions src/main/java/nyc/c4q/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package nyc.c4q;

import android.text.TextUtils;

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

import java.util.ArrayList;

/**
* Created by s3a on 8/30/15.
*/
public class Book {

String id;
String title;
String author;
String ibsnNumber;
String ibsn13Number;
String publisher;
String pubYear;

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getIbsn13Number() {
return ibsn13Number;
}

public void setIbsn13Number(String ibsn13Number) {
this.ibsn13Number = ibsn13Number;
}

public String getIbsnNumber() {
return ibsnNumber;
}

public void setIbsnNumber(String ibsnNumber) {
this.ibsnNumber = ibsnNumber;
}

public String getId() {
return id;
}

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

public String getPublisher() {
return publisher;
}

public void setPublisher(String publisher) {
this.publisher = publisher;
}

public String getPubYear() {
return pubYear;
}

public void setPubYear(String pubYear) {
this.pubYear = pubYear;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public static Book fromJson(JSONObject jsonObject) {
Book book = new Book();
try {
// Deserialize json into object fields

if (jsonObject.has("id")) {
book.id = jsonObject.getString("id");
} else if(jsonObject.has("title")) {
final JSONArray ids = jsonObject.getJSONArray("title");
book.id = ids.getString(0);
}
book.title = jsonObject.has("isbn") ? jsonObject.getString("isbn") : "";
book.author = getAuthor(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
// Return new object
return book;
}

// Return comma separated author list when there is more than one author
private static String getAuthor(final JSONObject jsonObject) {
try {
final JSONArray authors = jsonObject.getJSONArray("author");
int numAuthors = authors.length();
final String[] authorStrings = new String[numAuthors];
for (int i = 0; i < numAuthors; ++i) {
authorStrings[i] = authors.getString(i);
}
return TextUtils.join(", ", authorStrings);
} catch (JSONException e) {
return "";
}
}

// Decodes array of book json results into business model objects
public static ArrayList<Book> fromJson(JSONArray jsonArray) {
ArrayList<Book> books = new ArrayList<Book>(jsonArray.length());
// Process each result in json array, decode and convert to business
// object
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject bookJson = null;
try {
bookJson = jsonArray.getJSONObject(i);
} catch (Exception e) {
e.printStackTrace();
continue;
}
Book book = Book.fromJson(bookJson);
if (book != null) {
books.add(book);
}
}
return books;
}
}
34 changes: 34 additions & 0 deletions src/main/java/nyc/c4q/BookJson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package nyc.c4q;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
* Created by s3a on 8/30/15.
*/
public class BookJson {

public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getActivity().getAssets().open("books.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}

private Context getActivity() {
return null;
}
}
63 changes: 63 additions & 0 deletions src/main/java/nyc/c4q/CalcActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package nyc.c4q;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
* Created by s3a on 8/30/15.
*/
public class CalcActivity extends Activity {

public EditText inputDistance;
public EditText inputTimeMin;
public EditText inputTimeSec;
public EditText inputPaceMin;
public EditText inputPaceSec;
public Button buttonCalculate;
public String timeSecs;
public String paceSecs;
public Double resultInSecs;
public Double distance;
Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pace_calculator);


inputDistance = (EditText) findViewById(R.id.input_distance);
inputTimeMin = (EditText) findViewById(R.id.input_time_min);
inputTimeSec = (EditText) findViewById(R.id.input_time_sec);
inputPaceMin = (EditText) findViewById(R.id.input_pace_min);
inputPaceSec = (EditText) findViewById(R.id.input_pace_sec);
buttonCalculate = (Button) findViewById(R.id.button_calculate);

//Mile per minute is 26.8224s
//Miles per second is 1 609.344 m / s
//Convert minutes to seconds
//Divide miles /seconds

buttonCalculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

timeSecs = inputTimeMin.getText().toString();
paceSecs = inputPaceMin.getText().toString();



resultInSecs = Double.parseDouble(timeSecs) + Double.parseDouble(paceSecs);
//distance
// distance =

}


});

}
}
60 changes: 60 additions & 0 deletions src/main/java/nyc/c4q/Fragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package nyc.c4q;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

/**
* Created by s3a on 8/30/15.
*/
public class Fragment extends android.support.v4.app.Fragment {

public EditText inputDistance;
public EditText inputTimeMin;
public EditText inputTimeSec;
public EditText inputPaceMin;
public EditText inputPaceSec;
public Button buttonCalculate;
public String timeSecs;
public String paceSecs;
public Double resultInSecs;
Context mContext;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pace_calculator,container,false
);
mContext =container.getContext();
inputDistance = (EditText) view.findViewById(R.id.input_distance);
inputTimeMin = (EditText) view.findViewById(R.id.input_time_min);
inputTimeSec = (EditText) view.findViewById(R.id.input_time_sec);
inputPaceMin = (EditText) view.findViewById(R.id.input_pace_min);
inputPaceSec = (EditText) view.findViewById(R.id.input_pace_sec);
buttonCalculate = (Button) view.findViewById(R.id.button_calculate);


buttonCalculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

timeSecs=inputTimeMin.getText().toString();
paceSecs =inputPaceMin.getText().toString();

resultInSecs=Double.parseDouble(timeSecs)+Double.parseDouble(paceSecs);

}


});


return view;
}

}
35 changes: 34 additions & 1 deletion src/main/java/nyc/c4q/ListActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package nyc.c4q;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;


public class ListActivity extends Activity {
public class ListActivity extends Activity{

public ListView list;
public Button buttonColor;
public Button buttonName;
public TextView textName;
public TextView textHouse;
public Person mPerson;

public static final Person[] PEOPLE = {
new Person("Hannah", "Abbott", House.Hufflepuff),
Expand Down Expand Up @@ -46,8 +56,31 @@ public class ListActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
buttonName = (Button) findViewById(R.id.button_name);
buttonColor = (Button) findViewById(R.id.button_color);
textName = (TextView)findViewById(R.id.text_name);
textHouse =(TextView)findViewById(R.id.text_house);




list = (ListView) findViewById(R.id.list);
ArrayAdapter<Person> itemsAdapter = new ArrayAdapter<Person>(this,R.layout.activity_list,PEOPLE);
list.setAdapter(itemsAdapter);
itemsAdapter.addAll(PEOPLE);

//I was planning to compare the firstname which would obtain the last name and house

buttonName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

textName.setText(mPerson.getFirstName());


}
});

}

}
24 changes: 24 additions & 0 deletions src/main/java/nyc/c4q/ListAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nyc.c4q;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import java.util.ArrayList;

/**
* Created by s3a on 8/30/15.
*/
public class ListAdapter extends ArrayAdapter<Book>{

public ListAdapter(Context context, ArrayList<Book> aBooks) {
super(context, 0, aBooks);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO: Complete the definition of the view for each book
return null;
}
}
Loading