diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f96e9d3..4389266 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -16,12 +16,7 @@ - - - - + objects; + + + public CustomListAdapter(Context context, int resource, ArrayList objects) { + super(context, resource, objects); + this.objects = objects; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View v = convertView; + + if (v == null){ + LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + v = inflater.inflate(R.layout.listitem_member,null); + } + + Person i = objects.get(position); + + if(i != null){ + TextView name = (TextView) v.findViewById(R.id.text_name); + TextView house = (TextView) v.findViewById(R.id.text_house); + + if(name != null){ + name.setText(i.getFirstName() + "," + i.getLastName()); + } + if(house != null){ + house.setText(i.getHouse().toString()); + } + } + return v; + + } +} diff --git a/src/main/java/nyc/c4q/LibraryActivity.java b/src/main/java/nyc/c4q/LibraryActivity.java index ca2a050..5b43332 100644 --- a/src/main/java/nyc/c4q/LibraryActivity.java +++ b/src/main/java/nyc/c4q/LibraryActivity.java @@ -5,6 +5,14 @@ import android.view.View; import android.widget.EditText; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONTokener; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + public class LibraryActivity extends Activity { @@ -16,12 +24,31 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_library); inputParameter = (EditText) findViewById(R.id.input_parameter); + + BufferedReader jsonReader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(R.raw.books))); + StringBuilder jsonBuilder = new StringBuilder(); + try { + for (String line = null; (line = jsonReader.readLine()) != null;) { + jsonBuilder.append(line).append("\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } + + //Parse Json + JSONTokener tokener = new JSONTokener(jsonBuilder.toString()); + try { + JSONArray jsonArray = new JSONArray(tokener); + } catch (JSONException e) { + e.printStackTrace(); + } } 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) { diff --git a/src/main/java/nyc/c4q/ListActivity.java b/src/main/java/nyc/c4q/ListActivity.java index 08894ac..68290ec 100644 --- a/src/main/java/nyc/c4q/ListActivity.java +++ b/src/main/java/nyc/c4q/ListActivity.java @@ -1,15 +1,28 @@ package nyc.c4q; import android.app.Activity; +import android.database.DataSetObserver; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; public class ListActivity extends Activity { public ListView list; + private Button buttonName,buttonColor; + private TextView textName,textHouse; public static final Person[] PEOPLE = { new Person("Hannah", "Abbott", House.Hufflepuff), @@ -48,6 +61,62 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_list); list = (ListView) findViewById(R.id.list); + buttonColor = (Button) findViewById(R.id.button_color); + buttonName = (Button) findViewById(R.id.button_name); + textHouse = (TextView) findViewById(R.id.text_house); + textName = (TextView) findViewById(R.id.text_name); + + final ArrayList peopleList = new ArrayList<>(); + + for(int i = 0;i peopleNamesList = new ArrayList<>(); + + for(Person person: peopleList){ + peopleNamesList.add(person.getFirstName()); + } + Collections.sort(peopleNamesList, new Comparator() { + @Override + public int compare(String s1, String s2) { + return s1.compareToIgnoreCase(s2); + } + }); + } + }); + + buttonColor.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + for (Person people : peopleList) { + for (int i = 0; i < list.getCount(); i++) { + if (people.getHouse().toString().equalsIgnoreCase("Gryffindor")) { + adapter.getView(i, null, list).setBackgroundColor(R.color.gryffindor_red); + } else if (people.getHouse().toString().equalsIgnoreCase("Ravenclaw")) { + adapter.getView(i, null, list).setBackgroundColor(R.color.ravenclaw_blue); + } else if (people.getHouse().toString().equalsIgnoreCase("Hufflepuff")) { + adapter.getView(i, null, list).setBackgroundColor(R.color.hufflepuff_yellow); + } else if (people.getHouse().toString().equalsIgnoreCase("Slytherin")) { + adapter.getView(i, null, list).setBackgroundColor(R.color.slytherin_green); + } + } + } + } + }); + + + + + } } -} + diff --git a/src/main/java/nyc/c4q/Member.java b/src/main/java/nyc/c4q/Member.java new file mode 100644 index 0000000..a069e0e --- /dev/null +++ b/src/main/java/nyc/c4q/Member.java @@ -0,0 +1,167 @@ +package nyc.c4q; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by c4q-ac35 on 8/30/15. + */ +public class Member { + @Expose + private Integer id; + @Expose + private String name; + @SerializedName("dob_month") + @Expose + private Integer dobMonth; + @SerializedName("dob_day") + @Expose + private Integer dobDay; + @SerializedName("dob_year") + @Expose + private Integer dobYear; + @Expose + private String city; + @Expose + private String state; + + Member(){ + + } + Member(Integer id,String name,Integer dobMonth,Integer dobDay,Integer dobYear,String city, String state){ + this.id = id; + this.name = name; + this.dobMonth = dobMonth; + this.dobDay = dobDay; + this.dobYear = dobYear; + this.city = city; + this.state = state; + } + + /** + * + * @return + * The id + */ + public Integer getId() { + return id; + } + + /** + * + * @param id + * The id + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * + * @return + * The name + */ + public String getName() { + return name; + } + + /** + * + * @param name + * The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * + * @return + * The dobMonth + */ + public Integer getDobMonth() { + return dobMonth; + } + + /** + * + * @param dobMonth + * The dob_month + */ + public void setDobMonth(Integer dobMonth) { + this.dobMonth = dobMonth; + } + + /** + * + * @return + * The dobDay + */ + public Integer getDobDay() { + return dobDay; + } + + /** + * + * @param dobDay + * The dob_day + */ + public void setDobDay(Integer dobDay) { + this.dobDay = dobDay; + } + + /** + * + * @return + * The dobYear + */ + public Integer getDobYear() { + return dobYear; + } + + /** + * + * @param dobYear + * The dob_year + */ + public void setDobYear(Integer dobYear) { + this.dobYear = dobYear; + } + + /** + * + * @return + * The city + */ + public String getCity() { + return city; + } + + /** + * + * @param city + * The city + */ + public void setCity(String city) { + this.city = city; + } + + /** + * + * @return + * The state + */ + public String getState() { + return state; + } + + /** + * + * @param state + * The state + */ + public void setState(String state) { + this.state = state; + } + +} diff --git a/src/main/java/nyc/c4q/PaceCalculatorActivity.java b/src/main/java/nyc/c4q/PaceCalculatorActivity.java index 5c0616e..b90a4bc 100644 --- a/src/main/java/nyc/c4q/PaceCalculatorActivity.java +++ b/src/main/java/nyc/c4q/PaceCalculatorActivity.java @@ -2,13 +2,55 @@ import android.support.v4.app.FragmentActivity; import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import java.util.List; public class PaceCalculatorActivity extends FragmentActivity { + EditText inputDistance,inputTimeMin,inputTimeSec,inputPaceMin,inputPaceSec; + Button buttonCalculate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_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); + + buttonCalculate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(inputDistance != null + && inputTimeMin != null + && inputTimeSec != null + && inputPaceMin != null + && inputPaceSec != null){ + //DO NOTHING + }else if(inputDistance == null + && inputTimeMin == null + && inputTimeSec == null + && inputPaceSec == null + && inputPaceSec == null){ + //DO NOTHING + } else if(inputDistance != null + && inputTimeMin != null + && inputTimeSec != null + && inputPaceMin == null + && inputPaceSec == null){ + } + } + }); } + + + } diff --git a/src/main/java/nyc/c4q/Person.java b/src/main/java/nyc/c4q/Person.java index 2f2f167..4689b69 100644 --- a/src/main/java/nyc/c4q/Person.java +++ b/src/main/java/nyc/c4q/Person.java @@ -1,13 +1,46 @@ package nyc.c4q; -public class Person { +public class Person implements Comparable { public String firstName; 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; this.house = house; } + + @Override + public int compareTo(Person another) { + int comparedFirstName = this.firstName.compareToIgnoreCase(another.getFirstName()); + if(comparedFirstName == 0){ + return this.lastName.compareTo(another.getLastName()); + } + return comparedFirstName; + } } diff --git a/src/main/java/nyc/c4q/db/BooksHelper.java b/src/main/java/nyc/c4q/db/BooksHelper.java new file mode 100644 index 0000000..e4f8a46 --- /dev/null +++ b/src/main/java/nyc/c4q/db/BooksHelper.java @@ -0,0 +1,110 @@ +package nyc.c4q.db; + +import android.content.ContentValues; +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.provider.BaseColumns; + +/** + * Created by c4q-ac35 on 8/30/15. + */ +public class BooksHelper extends SQLiteOpenHelper { + private static final String DB_NAME = "books.db"; + private static final int DB_VERSION = 1; + + private static BooksHelper INSTANCE; + + + public static synchronized BooksHelper getInstance(Context context) + { + if(INSTANCE == null) + { + INSTANCE = new BooksHelper(context.getApplicationContext()); + } + + return INSTANCE; + } + + public BooksHelper(Context context) { + super(context, DB_NAME, null, DB_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(SQL_CREATE_TABLE_BOOKS); + + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + onCreate(db); + } + + public void insertData(String tableName){ + SQLiteDatabase db = getWritableDatabase(); + db.delete(tableName, null, null); + } + + public static void insertRow(String bookTitle, String author, String isbn, String isbn13, String tableName, String publisher, int publishYear, boolean checkedOut, int memberId, int checkedOutYear, int checkoutMonth, int checkoutDay, int yearDue, int monthDue, int dayDue ,SQLiteDatabase db){ + ContentValues values = new ContentValues(); + values.put(BookEntry.COLUMN_TITLE,bookTitle); + values.put(BookEntry.COLUMN_AUTHOR,author); + values.put(BookEntry.COLUMN_ISBN,isbn); + values.put(BookEntry.COLUMN_ISBN_13,isbn13); + values.put(BookEntry.COLUMN_PUBLISHER,publisher); + values.put(BookEntry.COLUMN_PUBLISH_YEAR,publishYear); + values.put(BookEntry.COLUMN_CHECKED_OUT,checkedOut); + values.put(BookEntry.COLUMN_CHECKED_OUT_BY,memberId); + values.put(BookEntry.COLUMN_CHECKOUT_YEAR,checkedOutYear); + values.put(BookEntry.COLUMN_CHECKOUT_MONTH,checkoutMonth); + values.put(BookEntry.COLUMN_CHECKOUT_DAY,checkoutDay); + values.put(BookEntry.COLUMN_DUE_DATE_YEAR,yearDue); + values.put(BookEntry.COLUMN_DUE_DATE_MONTH,monthDue); + values.put(BookEntry.COLUMN_DUE_DATE_DAY,dayDue); + + db.insertOrThrow(tableName,null,values); + } + + public static abstract class BookEntry implements BaseColumns { + public static final String COLUMN_TITLE = "Title"; + public static final String COLUMN_AUTHOR = "Author"; + public static final String COLUMN_ISBN = "ISBN"; + public static final String COLUMN_ISBN_13 = "Hours"; + public static final String COLUMN_PUBLISHER = "Publisher"; + public static final String COLUMN_PUBLISH_YEAR = "Publish Year"; + public static final String COLUMN_CHECKED_OUT = "Checked Out"; + public static final String COLUMN_CHECKED_OUT_BY = "Checked Out By"; + public static final String COLUMN_CHECKOUT_YEAR = "Checkout Year"; + public static final String COLUMN_CHECKOUT_MONTH = "Checkout Month"; + public static final String COLUMN_CHECKOUT_DAY = "Checkout Day"; + public static final String COLUMN_DUE_DATE_YEAR = "Year Due"; + public static final String COLUMN_DUE_DATE_MONTH = "Month Due"; + public static final String COLUMN_DUE_DATE_DAY = "Day Due"; + } + + private static final String SQL_CREATE_TABLE_BOOKS = + "CREATE TABLE" + "BOOKS" +" (" + + BookEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + BookEntry.COLUMN_TITLE+" TEXT," + + BookEntry.COLUMN_AUTHOR+" TEXT," + + BookEntry.COLUMN_ISBN+" TEXT," + + BookEntry.COLUMN_ISBN_13+" TEXT"+ + BookEntry.COLUMN_PUBLISHER+" TEXT"+ + BookEntry.COLUMN_PUBLISH_YEAR+" INTEGER"+ + BookEntry.COLUMN_CHECKED_OUT+" BOOLEAN"+ + BookEntry.COLUMN_CHECKED_OUT_BY+" INTEGER"+ + BookEntry.COLUMN_CHECKOUT_YEAR+" INTEGER"+ + BookEntry.COLUMN_CHECKOUT_MONTH+" INTEGER"+ + BookEntry.COLUMN_CHECKOUT_DAY+" INTEGER"+ + BookEntry.COLUMN_DUE_DATE_YEAR+" INTEGER"+ + BookEntry.COLUMN_DUE_DATE_MONTH+" INTEGER"+ + BookEntry.COLUMN_DUE_DATE_DAY+" INTEGER"+ + " )"; + + + public String deleteTable(String tableName){ + String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + tableName.toUpperCase(); + return SQL_DELETE_ENTRIES; + } +} diff --git a/src/main/res/layout/activity_pace_calculator.xml b/src/main/res/layout/activity_pace_calculator.xml index ed76b3e..4655e70 100644 --- a/src/main/res/layout/activity_pace_calculator.xml +++ b/src/main/res/layout/activity_pace_calculator.xml @@ -4,5 +4,49 @@ android:id="@+id/activity_pace_calculator" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="nyc.c4q.PaceCalculatorActivity" - /> + tools:context="nyc.c4q.PaceCalculatorActivity"> + + + + + + + +