From ac9d5f6dee33baa1dae075d7abb263f79b90dcbe Mon Sep 17 00:00:00 2001 From: TL Date: Sun, 30 Aug 2015 18:15:28 -0400 Subject: [PATCH] my test --- src/main/AndroidManifest.xml | 8 +- src/main/java/nyc/c4q/Book.java | 136 ++++++++++++++++++ src/main/java/nyc/c4q/BookJson.java | 34 +++++ src/main/java/nyc/c4q/CalcActivity.java | 63 ++++++++ src/main/java/nyc/c4q/Fragment.java | 60 ++++++++ src/main/java/nyc/c4q/ListActivity.java | 35 ++++- src/main/java/nyc/c4q/ListAdapter.java | 24 ++++ src/main/java/nyc/c4q/Members.java | 9 ++ .../java/nyc/c4q/PaceCalculatorActivity.java | 73 +++++++++- src/main/java/nyc/c4q/Person.java | 24 ++++ .../res/layout/activity_pace_calculator.xml | 121 +++++++++++++++- .../res/layout/fragment_pace_calculator.xml | 1 + src/main/res/raw/books.json | 2 +- 13 files changed, 579 insertions(+), 11 deletions(-) create mode 100644 src/main/java/nyc/c4q/Book.java create mode 100644 src/main/java/nyc/c4q/BookJson.java create mode 100644 src/main/java/nyc/c4q/CalcActivity.java create mode 100644 src/main/java/nyc/c4q/Fragment.java create mode 100644 src/main/java/nyc/c4q/ListAdapter.java create mode 100644 src/main/java/nyc/c4q/Members.java diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f96e9d3..07cf928 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -16,12 +16,8 @@ - - - - + + fromJson(JSONArray jsonArray) { + ArrayList books = new ArrayList(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; + } +} diff --git a/src/main/java/nyc/c4q/BookJson.java b/src/main/java/nyc/c4q/BookJson.java new file mode 100644 index 0000000..6ec5773 --- /dev/null +++ b/src/main/java/nyc/c4q/BookJson.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/nyc/c4q/CalcActivity.java b/src/main/java/nyc/c4q/CalcActivity.java new file mode 100644 index 0000000..86e19e2 --- /dev/null +++ b/src/main/java/nyc/c4q/CalcActivity.java @@ -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 = + + } + + + }); + + } +} \ No newline at end of file diff --git a/src/main/java/nyc/c4q/Fragment.java b/src/main/java/nyc/c4q/Fragment.java new file mode 100644 index 0000000..c527f0f --- /dev/null +++ b/src/main/java/nyc/c4q/Fragment.java @@ -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; +} + +} diff --git a/src/main/java/nyc/c4q/ListActivity.java b/src/main/java/nyc/c4q/ListActivity.java index 08894ac..f54f49a 100644 --- a/src/main/java/nyc/c4q/ListActivity.java +++ b/src/main/java/nyc/c4q/ListActivity.java @@ -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), @@ -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 itemsAdapter = new ArrayAdapter(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()); + + + } + }); + } } diff --git a/src/main/java/nyc/c4q/ListAdapter.java b/src/main/java/nyc/c4q/ListAdapter.java new file mode 100644 index 0000000..ce5f54c --- /dev/null +++ b/src/main/java/nyc/c4q/ListAdapter.java @@ -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{ + + public ListAdapter(Context context, ArrayList 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; + } +} diff --git a/src/main/java/nyc/c4q/Members.java b/src/main/java/nyc/c4q/Members.java new file mode 100644 index 0000000..b10d212 --- /dev/null +++ b/src/main/java/nyc/c4q/Members.java @@ -0,0 +1,9 @@ +package nyc.c4q; + +/** + * Created by s3a on 8/30/15. + */ +public class Members { + + +} diff --git a/src/main/java/nyc/c4q/PaceCalculatorActivity.java b/src/main/java/nyc/c4q/PaceCalculatorActivity.java index 5c0616e..4f03189 100644 --- a/src/main/java/nyc/c4q/PaceCalculatorActivity.java +++ b/src/main/java/nyc/c4q/PaceCalculatorActivity.java @@ -1,14 +1,83 @@ package nyc.c4q; +import android.app.FragmentManager; +import android.content.Context; +import android.content.Intent; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; public class PaceCalculatorActivity extends FragmentActivity { +// 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; - @Override + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pace_calculator); + + +// //I know this is one method +// FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); +//// Replace the contents of the container with the new fragment +// ft.replace(R.id.fragment_pace_calculator, new nyc.c4q.Fragment()); +//// or ft.add(R.id.your_placeholder, new FooFragment()); +//// Complete the changes added above +// ft.commit(); + + + + } + + + +//// @Nullable +//// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { +//// View view = inflater.inflate(R.layout.fragment_pace_calculator,container,false +//// ); +// +// 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; +// } + + } -} + diff --git a/src/main/java/nyc/c4q/Person.java b/src/main/java/nyc/c4q/Person.java index 2f2f167..50fc82b 100644 --- a/src/main/java/nyc/c4q/Person.java +++ b/src/main/java/nyc/c4q/Person.java @@ -5,6 +5,30 @@ public class Person { public String lastName; public House house; + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public House getHouse() { + return house; + } + + public void setHouse(House house) { + this.house = house; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + public Person(String firstName, String lastName, House house) { this.firstName = firstName; this.lastName = lastName; diff --git a/src/main/res/layout/activity_pace_calculator.xml b/src/main/res/layout/activity_pace_calculator.xml index ed76b3e..2ce0e08 100644 --- a/src/main/res/layout/activity_pace_calculator.xml +++ b/src/main/res/layout/activity_pace_calculator.xml @@ -5,4 +5,123 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context="nyc.c4q.PaceCalculatorActivity" - /> + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +