From 8729f7ec10394e1b217fdf7fe82ef7c0079fa5f5 Mon Sep 17 00:00:00 2001 From: m47bell Date: Sun, 30 Aug 2015 11:25:31 -0400 Subject: [PATCH 1/3] adding fragment Activity --- src/main/java/nyc/c4q/PaceCalFragment.java | 54 +++++++++++++++++++ .../java/nyc/c4q/PaceCalculatorActivity.java | 15 +++++- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/main/java/nyc/c4q/PaceCalFragment.java diff --git a/src/main/java/nyc/c4q/PaceCalFragment.java b/src/main/java/nyc/c4q/PaceCalFragment.java new file mode 100644 index 0000000..a3f0c60 --- /dev/null +++ b/src/main/java/nyc/c4q/PaceCalFragment.java @@ -0,0 +1,54 @@ +package nyc.c4q; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; + +/** + * Created by c4q-marbella on 8/30/15. + */ +public class PaceCalFragment extends Fragment { + + EditText inputDistance; + EditText inputTimeMin; + EditText inputTimeSec; + EditText inputPaceMin; + EditText inputPaceSec; + Button buttonCalculate; + + + public static PaceCalFragment newInstance(int page, String title) { + PaceCalFragment paceCalFragment = new PaceCalFragment(); + Bundle args = new Bundle(); + args.putInt("page", page); + args.putString("title",title); + paceCalFragment.setArguments(args); + return paceCalFragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + int fragPage = getArguments().getInt("paceCalPage", 0); + String fragTitle = getArguments().getString("paceTitle", "paceCalc"); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, 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); + + return view; + } +} diff --git a/src/main/java/nyc/c4q/PaceCalculatorActivity.java b/src/main/java/nyc/c4q/PaceCalculatorActivity.java index 5c0616e..6ceb36a 100644 --- a/src/main/java/nyc/c4q/PaceCalculatorActivity.java +++ b/src/main/java/nyc/c4q/PaceCalculatorActivity.java @@ -1,14 +1,25 @@ package nyc.c4q; -import android.support.v4.app.FragmentActivity; import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentTransaction; public class PaceCalculatorActivity extends FragmentActivity { + PaceCalFragment mPaceCalFragment; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pace_calculator); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + mPaceCalFragment = PaceCalFragment.newInstance(0, "PaceCalc"); + ft.replace(R.id.activity_pace_calculator, mPaceCalFragment); + ft.commit(); + + } + } -} + From daeb88b3babcc7f109ff29f56ee2f6875a7993bc Mon Sep 17 00:00:00 2001 From: m47bell Date: Sun, 30 Aug 2015 13:00:52 -0400 Subject: [PATCH 2/3] adding list adapter --- src/main/AndroidManifest.xml | 6 -- src/main/java/nyc/c4q/ListActivity.java | 9 ++- src/main/java/nyc/c4q/PaceCalFragment.java | 64 +++++++++++++++++++ .../java/nyc/c4q/PaceCalculatorActivity.java | 2 +- src/main/java/nyc/c4q/PersonsAdapter.java | 38 +++++++++++ 5 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 src/main/java/nyc/c4q/PersonsAdapter.java diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f96e9d3..47056e3 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -16,12 +16,6 @@ - - - - { + + public PersonsAdapter(Context context, Person[] persons) { + super(context, 0, persons); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + Person person = getItem(position); + + if(convertView == null){ + convertView = LayoutInflater.from(getContext()).inflate(R.layout.listitem_member, parent,false); + } + + TextView tvName= (TextView) convertView.findViewById(R.id.text_name); + TextView tvHouse = (TextView) convertView.findViewById(R.id.text_house); + + tvName.setText(person.firstName); + tvHouse.setText(person.house.name()); + //Todo: set house color + // convertView.setBackgroundColor(); + + return convertView; + } +} From fe7718f02cf7bc59d4a78d8dfa4d56649b902fbc Mon Sep 17 00:00:00 2001 From: m47bell Date: Sun, 30 Aug 2015 18:18:02 -0400 Subject: [PATCH 3/3] text over --- src/main/java/nyc/c4q/BookInfo.java | 94 +++++++++++++++++++ src/main/java/nyc/c4q/JSONHelperVerison.java | 53 +++++++++++ src/main/java/nyc/c4q/LibraryActivity.java | 33 +++++++ src/main/java/nyc/c4q/ListActivity.java | 65 ++++++++++++- src/main/java/nyc/c4q/MemberInfo.java | 82 ++++++++++++++++ src/main/java/nyc/c4q/MySQLiteOpenHelper.java | 50 ++++++++++ src/main/java/nyc/c4q/PaceCalFragment.java | 86 +++++++++++------ src/main/java/nyc/c4q/Person.java | 12 ++- src/main/java/nyc/c4q/PersonsAdapter.java | 2 +- src/main/res/raw/books.json | 2 +- 10 files changed, 442 insertions(+), 37 deletions(-) create mode 100644 src/main/java/nyc/c4q/BookInfo.java create mode 100644 src/main/java/nyc/c4q/JSONHelperVerison.java create mode 100644 src/main/java/nyc/c4q/MemberInfo.java create mode 100644 src/main/java/nyc/c4q/MySQLiteOpenHelper.java diff --git a/src/main/java/nyc/c4q/BookInfo.java b/src/main/java/nyc/c4q/BookInfo.java new file mode 100644 index 0000000..5ed50e2 --- /dev/null +++ b/src/main/java/nyc/c4q/BookInfo.java @@ -0,0 +1,94 @@ +package nyc.c4q; + +/** + * Created by c4q-marbella on 8/30/15. + */ +public class BookInfo { + + public int id; + public String title; + public String author; + public long isbn; + public long isbn13; + public String publisher; + public int publishyear; + + public BookInfo(String author, int id, long isbn, long isbn13, int publishyear, String publisher, String title) { + this.author = author; + this.id = id; + this.isbn = isbn; + this.isbn13 = isbn13; + this.publishyear = publishyear; + this.publisher = publisher; + this.title = title; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public long getIsbn13() { + return isbn13; + } + + public void setIsbn13(long isbn13) { + this.isbn13 = isbn13; + } + + public long getIsbn() { + return isbn; + } + + public void setIsbn(long isbn) { + this.isbn = isbn; + } + + public int getPublishyear() { + return publishyear; + } + + public void setPublishyear(int publishyear) { + this.publishyear = publishyear; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public String toString() { + return "BookInfo{" + + "author='" + author + '\'' + + ", id=" + id + + ", title='" + title + '\'' + + ", isbn=" + isbn + + ", isbn13=" + isbn13 + + ", publisher='" + publisher + '\'' + + ", publishyear=" + publishyear + + '}'; + } +} diff --git a/src/main/java/nyc/c4q/JSONHelperVerison.java b/src/main/java/nyc/c4q/JSONHelperVerison.java new file mode 100644 index 0000000..73a4a8d --- /dev/null +++ b/src/main/java/nyc/c4q/JSONHelperVerison.java @@ -0,0 +1,53 @@ +package nyc.c4q; + +import android.content.Context; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.reflect.Type; +import java.util.List; + +/** + * Created by c4q-marbella on 8/30/15. + */ +public class JSONHelperVerison { + + public static List loadStaticMemberJsonRawUsingGson(Context context, int jsonResource) { + + InputStream raw = context.getResources().openRawResource(jsonResource); + Reader rd = new BufferedReader(new InputStreamReader(raw)); + Gson gson = new Gson(); + + String jsonOutput = "Your JSON String"; + Type listType = new TypeToken>(){}.getType(); + List memberInfos = (List) gson.fromJson(jsonOutput, listType); + return memberInfos; + } + + public static String convertToJsonUsingGson(MemberInfo memberInfo) { + Gson gson = new Gson(); + String json = gson.toJson(memberInfo); + return json; + } + + + public static BookInfo loadStaticBookJsonRawUsingGson(Context context, int jsonResource) { + + InputStream raw = context.getResources().openRawResource(jsonResource); + Reader rd = new BufferedReader(new InputStreamReader(raw)); + Gson gson = new Gson(); + BookInfo bookInfo = gson.fromJson(rd, BookInfo.class); + return bookInfo; + } + + public static String convertToJsonUsingGson(BookInfo bookInfo) { + Gson gson = new Gson(); + String json = gson.toJson(bookInfo); + return json; + } +} diff --git a/src/main/java/nyc/c4q/LibraryActivity.java b/src/main/java/nyc/c4q/LibraryActivity.java index ca2a050..67cb282 100644 --- a/src/main/java/nyc/c4q/LibraryActivity.java +++ b/src/main/java/nyc/c4q/LibraryActivity.java @@ -3,12 +3,21 @@ import android.app.Activity; import android.os.Bundle; import android.view.View; +import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; public class LibraryActivity extends Activity { public EditText inputParameter; + private TextView display; + private Button buttonMemberInfo; + private Button buttonBookInfo; + private Button buttonCheckedOut; + + + private static final String TAG = LibraryActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -16,12 +25,27 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_library); inputParameter = (EditText) findViewById(R.id.input_parameter); + display = (TextView) findViewById(R.id.text_display); + buttonMemberInfo = (Button) findViewById(R.id.button_getMember); + buttonBookInfo = (Button) findViewById(R.id.button_getBook); + buttonCheckedOut = (Button) findViewById(R.id.button_getCheckedOut); + +// // MemberInfo memberInfo = JSONHelperVerison.loadStaticMemberJsonRawUsingGson(this, R.raw.members); +// // Log.d(TAG, "membersJSON:\n" + memberInfo); +// +// String memberResponse = JSONHelperVerison.convertToJsonUsingGson(memberInfo); +// Log.d(TAG, "membersjson:" + memberResponse); } public void checkOut(int memberId, int bookId) { // TODO This method is called when the member with the given ID checks // out the book with the given ID. Update the system accordingly. // The due date for the book is two weeks from today. + + + + + } public boolean checkIn(int memberId, int bookId) { @@ -36,6 +60,7 @@ public boolean checkIn(int memberId, int bookId) { public void button_getMember_onClick(View view) { String name = inputParameter.getText().toString(); + // TODO Display member information for the member with the given name. } @@ -53,4 +78,12 @@ public void button_getCheckedOut_onClick(View view) { // earliest due first. } + + + + + + + + } diff --git a/src/main/java/nyc/c4q/ListActivity.java b/src/main/java/nyc/c4q/ListActivity.java index 91265ad..ffefadc 100644 --- a/src/main/java/nyc/c4q/ListActivity.java +++ b/src/main/java/nyc/c4q/ListActivity.java @@ -2,14 +2,24 @@ import android.app.Activity; import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ListView; -import android.widget.ToggleButton; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class ListActivity extends Activity { public ListView list; - ToggleButton togglebt; + Button namebt; + Button colorbt; + ArrayAdapter adapter; public static final Person[] PEOPLE = { new Person("Hannah", "Abbott", House.Hufflepuff), @@ -47,12 +57,59 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); - PersonsAdapter adapter = new PersonsAdapter(this,PEOPLE); + final PersonsAdapter adapter = new PersonsAdapter(this,PEOPLE); list = (ListView) findViewById(R.id.list); + + final List memberList = Arrays.asList(PEOPLE); + list.setAdapter(adapter); - togglebt = (ToggleButton) findViewById(R.id.button_name); + namebt = (Button) findViewById(R.id.button_name); + colorbt = (Button) findViewById(R.id.button_color); + + + + namebt.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + list.setAdapter(adapter); + if(namebt.isPressed()) { + Collections.sort(memberList); + adapter.notifyDataSetChanged(); + } +// else{ +// Collections.reverse(memberList); +// adapter.notifyDataSetChanged(); +// } + } + }); + + + + + colorbt.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + Map housecolors = new HashMap(); + housecolors.put("Gryffindor", R.color.gryffindor_red); + housecolors.put("Ravenclaw", R.color.ravenclaw_blue); + housecolors.put("Hufflepuff", R.color.hufflepuff_yellow); + housecolors.put("Slytherin", R.color.slytherin_green); + + + for(int i=0;i{ public String firstName; public String lastName; public House house; @@ -10,4 +10,14 @@ public Person(String firstName, String lastName, House house) { this.lastName = lastName; this.house = house; } + + + @Override + public int compareTo(Person person) { + return firstName.compareTo(person.firstName); + } + + public int compareToFirstName(Person person) { + return lastName.compareTo(person.lastName); + } } diff --git a/src/main/java/nyc/c4q/PersonsAdapter.java b/src/main/java/nyc/c4q/PersonsAdapter.java index 581044e..74d4335 100644 --- a/src/main/java/nyc/c4q/PersonsAdapter.java +++ b/src/main/java/nyc/c4q/PersonsAdapter.java @@ -28,7 +28,7 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView tvName= (TextView) convertView.findViewById(R.id.text_name); TextView tvHouse = (TextView) convertView.findViewById(R.id.text_house); - tvName.setText(person.firstName); + tvName.setText(person.firstName +" " + person.lastName); tvHouse.setText(person.house.name()); //Todo: set house color // convertView.setBackgroundColor(); diff --git a/src/main/res/raw/books.json b/src/main/res/raw/books.json index 8cc9673..79b378e 100644 --- a/src/main/res/raw/books.json +++ b/src/main/res/raw/books.json @@ -838,7 +838,7 @@ "isbn": "0439554934", "isbn13": "9780439554930", "publisher": "Scholastic", - "publishyear": 2003. + "publishyear": 2003, "checkedout": true, "checkedoutby": 38, "checkoutdateyear": 2015,