From 5e035c3c5a44f7107f6fdd882848ecc0ac833ec7 Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Sun, 30 Aug 2015 18:18:44 -0400 Subject: [PATCH 1/4] pushing --- src/main/AndroidManifest.xml | 7 +- src/main/java/nyc/c4q/DBAdapter.java | 144 +++++++++++++ src/main/java/nyc/c4q/ExampleFragment.java | 195 ++++++++++++++++++ src/main/java/nyc/c4q/LibraryActivity.java | 100 +++++++++ src/main/java/nyc/c4q/ListActivity.java | 49 ++++- .../java/nyc/c4q/PaceCalculatorActivity.java | 13 +- src/main/java/nyc/c4q/TestListAdapter.java | 112 ++++++++++ .../res/layout/activity_pace_calculator.xml | 14 +- src/main/res/values/strings.xml | 3 + 9 files changed, 623 insertions(+), 14 deletions(-) create mode 100644 src/main/java/nyc/c4q/DBAdapter.java create mode 100644 src/main/java/nyc/c4q/ExampleFragment.java create mode 100644 src/main/java/nyc/c4q/TestListAdapter.java 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 @@ - - - - + integerArrayList; + int distanceInput; + int timeMinInput ; + int timeSecInput ; + int paceMinInput ; + int paceSecInput ; + + public ExampleFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view= inflater.inflate(R.layout.fragment_pace_calculator,null); + distanceText= (EditText) view.findViewById(R.id.input_distance); + timeMin=(EditText) view.findViewById(R.id.input_time_min); + timeSec= (EditText) view.findViewById(R.id.input_time_sec); + paceMin=(EditText) view.findViewById(R.id.input_pace_min); + paceSec=(EditText) view.findViewById(R.id.input_pace_sec); + calculate=(Button) view.findViewById(R.id.button_calculate); + try{ + String distanceInputString = distanceText.getText().toString(); + String timeMinInputString = timeMin.getText().toString(); + String timeSecInputString = timeSec.getText().toString(); + String paceMinInputString =paceMin.getText().toString(); + String paceSecInputString = paceSec.getText().toString(); + + timeMinInput= Integer.parseInt(timeMinInputString); + timeSecInput= Integer.parseInt(timeSecInputString); + paceMinInput= Integer.parseInt(paceMinInputString); + paceSecInput= Integer.parseInt(paceSecInputString); + distanceInput= Integer.parseInt(distanceInputString); + + + String totalTimeString=timeMinInput+"."+timeSecInput; + double totalTime= Double.parseDouble(totalTimeString); + + String totalPaceString=paceMinInput+"."+paceSecInput; + double totalPace= Double.parseDouble(totalPaceString); + + integerArrayList=new ArrayList<>(); + integerArrayList.add(timeMinInput); + integerArrayList.add(timeSecInput); + integerArrayList.add(paceMinInput); + integerArrayList.add(paceSecInput); + integerArrayList.add(distanceInput); + }catch(NumberFormatException ex){ // handle your exception + Toast.makeText(getActivity(),"Invalid Input",Toast.LENGTH_LONG).show(); + } + + + + + calculate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int numNull = 0; + int numWithInput = 0; + if(integerArrayList!=null) { + for (Integer input : integerArrayList) { + if (input == null) { + numNull++; + } + if (input != null) { + numWithInput++; + } + } + + if (numWithInput == 0 || numWithInput == 1 || numWithInput == 5) { + } + + if (numNull > 3) { + } + } + + if (distanceText.getText() != null && timeMin.getText() != null && paceMin != null) { + } + + if (distanceText.getText() != null && timeMin.getText() != null && paceSec.getText() != null) { + } + + if (distanceText.getText() != null && timeSec.getText() != null && paceSec.getText() != null) { + } + + if (distanceText.getText() != null && timeSec.getText() != null && paceMin.getText() != null) { + } + + if (distanceText.getText() != null) { + if (timeMin.getText() != null || timeSec.getText() != null) { + calculatePace(timeMinInput, timeSecInput, distanceInput); + } + if (paceMin.getText() != null || timeSec.getText() != null) { + calculateTime(paceMinInput, paceSecInput, distanceInput); + } + } + if(distanceText.getText()==null) { + if (timeMin.getText() != null || timeSec.getText() != null) { + if (paceMin.getText() != null || paceSec.getText() != null) { + calculateDistance(timeMinInput, timeSecInput, paceMinInput, paceSecInput); + } + } + } + + } + }); + + return view; + } + + public void calculatePace(int timeMin, int timeSec, int distance) { + + String actualTimeString=timeMin+"."+timeSec; + + double actualTimeWithSeconds= Double.parseDouble(actualTimeString); + + double pace= distance/actualTimeWithSeconds; + + String paceString= String.valueOf(pace); + + if(paceString.contains(".")) { + String[] splitPace = paceString.split("."); + paceMin.setText(splitPace[0]); + paceMin.setText(splitPace[1]); + } else{ + paceMin.setText(String.valueOf(pace)); + } + } + + public void calculateDistance(int timeMin, int timeSec, int paceMin, int paceSec){ + try { + String totalTimeString=timeMin+"."+timeSec; + + double totalTime=Double.parseDouble(totalTimeString); + + String totalPaceString=paceMin+"."+paceSec; + + double totalPace=Double.parseDouble(totalPaceString); + + double distance= totalTime/totalPace; + + + distanceText.setText(String.valueOf(distance)); + + + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public void calculateTime(int paceMin, int paceSec, int distance){ + String paceString=paceMin+"."+paceSec; + double totalPace=Double.parseDouble(paceString.trim()); + + double time= distance/totalPace; + + String timeString=String.valueOf(time); + + if (timeString.contains(".")) { + String[] splitting = timeString.split("."); + timeMin.setText(splitting[0]); + timeSec.setText(splitting[1]); + } + else{ + timeMin.setText(timeString); + } + + } +} diff --git a/src/main/java/nyc/c4q/LibraryActivity.java b/src/main/java/nyc/c4q/LibraryActivity.java index ca2a050..4032c0b 100644 --- a/src/main/java/nyc/c4q/LibraryActivity.java +++ b/src/main/java/nyc/c4q/LibraryActivity.java @@ -5,17 +5,31 @@ import android.view.View; import android.widget.EditText; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; + public class LibraryActivity extends Activity { public EditText inputParameter; + DBAdapter dbAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_library); + dbAdapter = new DBAdapter(this); inputParameter = (EditText) findViewById(R.id.input_parameter); + + loadBookJSONFromAsset("books.json"); + loadMemberJSONFromAsset("members.json"); + + } public void checkOut(int memberId, int bookId) { @@ -36,6 +50,8 @@ public boolean checkIn(int memberId, int bookId) { public void button_getMember_onClick(View view) { String name = inputParameter.getText().toString(); + dbAdapter.getDataForMember(name); + // TODO Display member information for the member with the given name. } @@ -53,4 +69,88 @@ public void button_getCheckedOut_onClick(View view) { // earliest due first. } + public void loadMemberJSONFromAsset(String fileName) { + String json = null; + try { + InputStream is = getAssets().open(fileName); + 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(); + } + sendMemberInfo(json); + } + public void loadBookJSONFromAsset(String fileName) { + String json = null; + try { + InputStream is = getAssets().open(fileName); + 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(); + } + sendMemberInfo(json); + } + + public void sendMemberInfo(String json){ + + try { + JSONArray obj = new JSONArray(json); + + for(int i=0;i peopleList; public static final Person[] PEOPLE = { new Person("Hannah", "Abbott", House.Hufflepuff), @@ -41,13 +51,44 @@ public class ListActivity extends Activity { new Person("Ginny", "Weasley", House.Gryffindor), new Person("Ron", "Weasley", House.Gryffindor) }; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); list = (ListView) findViewById(R.id.list); - } + nameChange=(Button) findViewById(R.id.button_name); + colorChange=(Button) findViewById(R.id.button_color); + peopleList= new ArrayList<>(Arrays.asList(PEOPLE)); + + SharedPreferences sharedPreferences=getSharedPreferences("Info", Context.MODE_PRIVATE); + + numOfButtonToggles=sharedPreferences.getInt("numForName",0); + numofColorToggles=sharedPreferences.getInt("numForColor",0); + TestListAdapter testListAdapter = new TestListAdapter(this, peopleList, numOfButtonToggles, numofColorToggles); + + list.setAdapter(testListAdapter); + + + + nameChange.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + numOfButtonToggles++; + TestListAdapter testListAdapter = new TestListAdapter(ListActivity.this, peopleList, numOfButtonToggles, numofColorToggles); + list.setAdapter(testListAdapter); + } + }); + + colorChange.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + numofColorToggles++; + TestListAdapter testListAdapter = new TestListAdapter(ListActivity.this, peopleList, numOfButtonToggles, numofColorToggles); + list.setAdapter(testListAdapter); + } + }); + + } } diff --git a/src/main/java/nyc/c4q/PaceCalculatorActivity.java b/src/main/java/nyc/c4q/PaceCalculatorActivity.java index 5c0616e..a2bcfe8 100644 --- a/src/main/java/nyc/c4q/PaceCalculatorActivity.java +++ b/src/main/java/nyc/c4q/PaceCalculatorActivity.java @@ -1,14 +1,23 @@ package nyc.c4q; -import android.support.v4.app.FragmentActivity; import android.os.Bundle; +import android.support.v4.app.FragmentActivity; public class PaceCalculatorActivity extends FragmentActivity { + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pace_calculator); + + android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); + + android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction(); + + ExampleFragment fragment = new ExampleFragment(); + ft.add(R.id.activity_pace_calculator, fragment); + ft.commit(); } -} +} \ No newline at end of file diff --git a/src/main/java/nyc/c4q/TestListAdapter.java b/src/main/java/nyc/c4q/TestListAdapter.java new file mode 100644 index 0000000..3de0fed --- /dev/null +++ b/src/main/java/nyc/c4q/TestListAdapter.java @@ -0,0 +1,112 @@ +package nyc.c4q; + +import android.content.Context; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +/** + * Created by c4q-madelyntavarez on 8/30/15. + */ +public class TestListAdapter extends BaseAdapter { + + ArrayList persons; + Context context; + LayoutInflater layoutInflater; + int numOfButtonToggles; + int numOfColorToggles; + + public TestListAdapter(Context context,ArrayList persons,int numOfButtonToggles, int numOfColorToggles) { + this.persons = persons; + this.numOfButtonToggles=numOfButtonToggles; + this.context = context; + this.numOfColorToggles=numOfColorToggles; + layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + @Override + public int getCount() { + return persons.size(); + } + + @Override + public Object getItem(int position) { + return position; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + View view=layoutInflater.inflate(R.layout.listitem_member,null); + + TextView house=(TextView) view.findViewById(R.id.text_house); + TextView name=(TextView) view.findViewById(R.id.text_name); + + if(numOfButtonToggles % 2==0){ + name.setText(persons.get(position).lastName + ", " + persons.get(position).firstName); + house.setText(persons.get(position).house.toString()); + Collections.sort(persons, new Comparator() { + public int compare(Person result1, Person result2) { + return result1.lastName.compareTo(result2.lastName); + } + }); + + } + else{ + name.setText(persons.get(position).firstName + " " + persons.get(position).lastName); + house.setText(persons.get(position).house.toString()); + + Collections.sort(persons, new Comparator() { + public int compare(Person result1, Person result2) { + return result1.firstName.compareTo(result2.firstName); + } + }); + } + + House houseForColor=persons.get(position).house; + String color=houseForColor.toString(); + if(numOfColorToggles%2==0){ + name.setBackgroundColor(Color.TRANSPARENT); + } + else{ + if (color.equals("Gryffindor")) { + name.setBackgroundColor(context.getResources().getColor(R.color.gryffindor_red)); + Log.d("COLOR", color); + } + if (color.equals("Ravenclaw")) { + name.setBackgroundColor(context.getResources().getColor(R.color.ravenclaw_blue)); + Log.d("COLOR", color); + } + if (color.equals("Hufflepuff")) { + name.setBackgroundColor(context.getResources().getColor(R.color.hufflepuff_yellow)); + Log.d("COLOR", color); + } + if (color.equals("Slytherin")) { + name.setBackgroundColor(context.getResources().getColor(R.color.slytherin_green)); + Log.d("COLOR", color); + } + } + + SharedPreferences sharedPreferences=context.getSharedPreferences("Info",Context.MODE_PRIVATE); + SharedPreferences.Editor editor=sharedPreferences.edit(); + editor.putInt("numForName",numOfButtonToggles); + editor.putInt("numForColor",numOfColorToggles); + editor.commit(); + + return view; + } +} diff --git a/src/main/res/layout/activity_pace_calculator.xml b/src/main/res/layout/activity_pace_calculator.xml index ed76b3e..71e5fa2 100644 --- a/src/main/res/layout/activity_pace_calculator.xml +++ b/src/main/res/layout/activity_pace_calculator.xml @@ -4,5 +4,15 @@ 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"> + + + + + + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index b6a349a..b67749d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -24,4 +24,7 @@ Show Color Hide Color + + Hello blank fragment + From a3f96447163ceab32fe5116867fdb41cdf83d594 Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Mon, 31 Aug 2015 00:56:45 -0400 Subject: [PATCH 2/4] up --- src/main/java/nyc/c4q/DBAdapter.java | 98 ++++++++++++++++++++-- src/main/java/nyc/c4q/LibraryActivity.java | 12 ++- src/main/res/raw/books.json | 2 +- 3 files changed, 105 insertions(+), 7 deletions(-) diff --git a/src/main/java/nyc/c4q/DBAdapter.java b/src/main/java/nyc/c4q/DBAdapter.java index 59dd026..afc1cca 100644 --- a/src/main/java/nyc/c4q/DBAdapter.java +++ b/src/main/java/nyc/c4q/DBAdapter.java @@ -7,6 +7,8 @@ import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; +import java.util.ArrayList; + /** * Created by c4q-madelyntavarez on 8/30/15. */ @@ -43,7 +45,7 @@ public long insertBookData(int id, String title, String author, String isbn, Str contentValues.put(DBHelper.ISBN13,isbn13); contentValues.put(DBHelper.PUBLISHER,publisher); contentValues.put(DBHelper.PUBLISHERYEAR,pushlisherYear); - contentValues.put(DBHelper.ISCHECKOUTOUT,isCheckedOut); + contentValues.put(DBHelper.ISCHECKEDOUT,isCheckedOut); contentValues.put(DBHelper.CHECKEDOUTBY,checkedOutBy); contentValues.put(DBHelper.CHECKOUTYEAR,checkoutYear); contentValues.put(DBHelper.CHECKOUTMONTH,checkOutMonth); @@ -56,9 +58,7 @@ public long insertBookData(int id, String title, String author, String isbn, Str return id2; } public String getDataForMember(String name) { - //Select Name, password from Table where name="" SQLiteDatabase dbs = dbHelper.getWritableDatabase(); - //Select ID, Name and Password from table String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR}; Cursor cursor = dbs.query(DBHelper.TABLE_NAME_2, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); @@ -82,6 +82,94 @@ public String getDataForMember(String name) { return buffer.toString(); } + public String getBookInfo(String ISBN){ + + SQLiteDatabase dbs = dbHelper.getWritableDatabase(); + String[] columns = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, + DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; + + Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.ISBN + " = '" + ISBN + "'", null, null, null, null); + + StringBuffer buffer = new StringBuffer(); + while (cursor.moveToNext()) { + int index1=cursor.getColumnIndex(DBHelper.UID); + int index2 = cursor.getColumnIndex(DBHelper.TITLE); + int index17=cursor.getColumnIndex(DBHelper.AUTHOR); + int index3 = cursor.getColumnIndex(DBHelper.ISBN); + int index4= cursor.getColumnIndex(DBHelper.ISBN13); + int index5=cursor.getColumnIndex(DBHelper.PUBLISHER); + int index6=cursor.getColumnIndex(DBHelper.PUBLISHERYEAR); + + int userID=cursor.getInt(index1); + String title = cursor.getString(index2); + String author=cursor.getString(index17); + long isbn=cursor.getLong(index3); + long isbn13=cursor.getLong(index4); + String publisher=cursor.getString(index5); + long publicationYear=cursor.getLong(index6); + + buffer.append("id: "+userID+"\n title: "+title + "\n author: " + author + "\n isbn: "+isbn+"\n" + + "isbn13: "+isbn13+"\n publisher: "+publisher+"\n publication year: "+publicationYear); + + } + return buffer.toString(); + } + + public ArrayList getCurrentlyCheckedOut(String name){ + int UID = 0; + SQLiteDatabase dbs = dbHelper.getWritableDatabase(); + String[] columns = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, + DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; + + Cursor cursor = dbs.query(DBHelper.TABLE_NAME_2, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); + StringBuffer buffer = new StringBuffer(); + while (cursor.moveToNext()) { + int index1=cursor.getColumnIndex(DBHelper.UID); + UID=cursor.getInt(index1); + } + + SQLiteDatabase dbs1 = dbHelper.getWritableDatabase(); + String[] columns1 = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, + DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; + + Cursor cursor1 = dbs1.query(DBHelper.TABLE_NAME, columns1, DBHelper.CHECKEDOUTBY + " = '" + UID + "'", null, null, null, null); + + StringBuffer buffer1 = new StringBuffer(); + + + ArrayList arrayList=new ArrayList<>(); + while (cursor1.moveToNext()) { + int index1=cursor1.getColumnIndex(DBHelper.UID); + int index2 = cursor1.getColumnIndex(DBHelper.TITLE); + int index17=cursor1.getColumnIndex(DBHelper.AUTHOR); + int index3 = cursor1.getColumnIndex(DBHelper.ISBN); + int index4= cursor1.getColumnIndex(DBHelper.ISBN13); + int index5=cursor1.getColumnIndex(DBHelper.PUBLISHER); + int index6=cursor1.getColumnIndex(DBHelper.PUBLISHERYEAR); + int index7=cursor1.getColumnIndex(DBHelper.ISCHECKEDOUT); + int index8=cursor1.getColumnIndex(DBHelper.CHECKEDOUTBY); + int index9=cursor1.getColumnIndex(DBHelper.CHECKOUTYEAR); + int index10=cursor1.getColumnIndex(DBHelper.CHECKOUTMONTH); + int index11=cursor1.getColumnIndex(DBHelper.CHECKOUTDAY); + int index12=cursor1.getColumnIndex(DBHelper.DUEYEAR); + int index13=cursor1.getColumnIndex(DBHelper.DUEMONTH); + int index14= cursor1.getColumnIndex(DBHelper.DUEDAY); + + String title = cursor1.getString(index2); + String author=cursor1.getString(index17); + String checkOutDate=cursor1.getInt(index10)+"/"+cursor1.getInt(index11)+"/"+cursor1.getInt(index9); + String dueDate=cursor1.getInt(index13)+"/"+cursor1.getInt(index14)+"/"+cursor1.getInt(index12); + + String all="name: "+name+"title: "+title + "\n author: " + author + "\n checkout date: "+checkOutDate+"\n" + + "Due Date: "+dueDate; + + arrayList.add(all); + } + + + return arrayList; + } + static class DBHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "LibraryDatabase"; private static String TABLE_NAME = "LibraryBooks"; @@ -101,7 +189,7 @@ static class DBHelper extends SQLiteOpenHelper { private static final String AUTHOR="Author"; private static final String ISBN13="ISBN13"; private static final String PUBLISHER="Publisher"; - private static final String ISCHECKOUTOUT="IsCheckedOut"; + private static final String ISCHECKEDOUT="IsCheckedOut"; private static final String PUBLISHERYEAR="PublisherYear"; private static final String CHECKEDOUTBY="CheckedOutBy"; private static final String CHECKOUTYEAR="CheckoutYear"; @@ -114,7 +202,7 @@ static class DBHelper extends SQLiteOpenHelper { + " VARCHAR(255), " + CITY + " VARCHAR (255), "+STATE + " VARCHAR (255), "+ MONTH + " INTEGER PRIMARY KEY, " + DAY + " INTEGER PRIMARY KEY, " + YEAR + " INTEGER PRIMARY KEY);"; private static final String CREATE_BOOK_TABLE = "Create table "+ TABLE_NAME_2+" ("+ UID+" Integer PRIMARY KEY, " + TITLE + " VARCHAR (255), "+ ISBN + " VARCHAR (255), "+ ISBN13 + " VARCHAR (255), "+ - PUBLISHER + " VARCHAR (255), "+ PUBLISHERYEAR + " INTEGER PRIMARY KEY, " + CHECKEDOUTBY + " VARCHAR (255), "+ CHECKOUTYEAR + " INTEGER PRIMARY KEY, " + CHECKOUTMONTH + " INTEGER PRIMARY KEY, " + CHECKOUTDAY + " INTEGER PRIMARY KEY, " + + PUBLISHER + " VARCHAR (255), "+ PUBLISHERYEAR + " INTEGER PRIMARY KEY, " + ISCHECKEDOUT+ " INTEGER PRIMARY KEY, " + CHECKEDOUTBY + " INTEGER PRIMARY KEY, " + CHECKOUTYEAR + " INTEGER PRIMARY KEY, " + CHECKOUTMONTH + " INTEGER PRIMARY KEY, " + CHECKOUTDAY + " INTEGER PRIMARY KEY, " + DUEYEAR + " INTEGER PRIMARY KEY, " + DUEMONTH + " INTEGER PRIMARY KEY, " + DUEDAY + " INTEGER PRIMARY KEY);"; public DBHelper(Context context) { diff --git a/src/main/java/nyc/c4q/LibraryActivity.java b/src/main/java/nyc/c4q/LibraryActivity.java index 4032c0b..c2d2420 100644 --- a/src/main/java/nyc/c4q/LibraryActivity.java +++ b/src/main/java/nyc/c4q/LibraryActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.view.View; import android.widget.EditText; +import android.widget.TextView; import org.json.JSONArray; import org.json.JSONException; @@ -11,12 +12,14 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; public class LibraryActivity extends Activity { public EditText inputParameter; DBAdapter dbAdapter; + public TextView textDisplay; @Override protected void onCreate(Bundle savedInstanceState) { @@ -25,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) { dbAdapter = new DBAdapter(this); inputParameter = (EditText) findViewById(R.id.input_parameter); + textDisplay=(TextView) findViewById(R.id.text_display); loadBookJSONFromAsset("books.json"); loadMemberJSONFromAsset("members.json"); @@ -50,7 +54,7 @@ public boolean checkIn(int memberId, int bookId) { public void button_getMember_onClick(View view) { String name = inputParameter.getText().toString(); - dbAdapter.getDataForMember(name); + textDisplay.setText(dbAdapter.getDataForMember(name)); // TODO Display member information for the member with the given name. } @@ -58,12 +62,18 @@ public void button_getMember_onClick(View view) { public void button_getBook_onClick(View view) { String isbn = inputParameter.getText().toString(); + textDisplay.setText(dbAdapter.getBookInfo(isbn)); + // TODO Display book information for the book with the given ISBN. } public void button_getCheckedOut_onClick(View view) { String name = inputParameter.getText().toString(); + ArrayList checkedOutList=new ArrayList<>(); + + checkedOutList.addAll(dbAdapter.getCurrentlyCheckedOut(name)); + // TODO Display a list of books that the member with the given name // currently has checked out, ordered by due date, with the // earliest due first. 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, From 2e5c38cda42d57c03a9337b21660018d77fe2d85 Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Mon, 31 Aug 2015 01:12:05 -0400 Subject: [PATCH 3/4] mc --- src/main/java/nyc/c4q/DBAdapter.java | 12 ++++++------ src/main/java/nyc/c4q/LibraryActivity.java | 14 ++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/nyc/c4q/DBAdapter.java b/src/main/java/nyc/c4q/DBAdapter.java index afc1cca..9b3ede1 100644 --- a/src/main/java/nyc/c4q/DBAdapter.java +++ b/src/main/java/nyc/c4q/DBAdapter.java @@ -60,7 +60,7 @@ public long insertBookData(int id, String title, String author, String isbn, Str public String getDataForMember(String name) { SQLiteDatabase dbs = dbHelper.getWritableDatabase(); String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR}; - Cursor cursor = dbs.query(DBHelper.TABLE_NAME_2, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); + Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); StringBuffer buffer = new StringBuffer(); while (cursor.moveToNext()) { @@ -121,7 +121,7 @@ public ArrayList getCurrentlyCheckedOut(String name){ String[] columns = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; - Cursor cursor = dbs.query(DBHelper.TABLE_NAME_2, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); + Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); StringBuffer buffer = new StringBuffer(); while (cursor.moveToNext()) { int index1=cursor.getColumnIndex(DBHelper.UID); @@ -132,7 +132,7 @@ public ArrayList getCurrentlyCheckedOut(String name){ String[] columns1 = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; - Cursor cursor1 = dbs1.query(DBHelper.TABLE_NAME, columns1, DBHelper.CHECKEDOUTBY + " = '" + UID + "'", null, null, null, null); + Cursor cursor1 = dbs1.query(DBHelper.TABLE_NAME_2, columns1, DBHelper.CHECKEDOUTBY + " = '" + UID + "'", null, null, null, null); StringBuffer buffer1 = new StringBuffer(); @@ -199,11 +199,11 @@ static class DBHelper extends SQLiteOpenHelper { private static final String DUEMONTH="DueMonth"; private static final String DUEDAY="DueDay"; private static final String CREATE_MEMBER_TABLE = "Create table " + TABLE_NAME + " (" + UID + " INTEGER PRIMARY KEY, " + NAME - + " VARCHAR(255), " + CITY + " VARCHAR (255), "+STATE + " VARCHAR (255), "+ MONTH + " INTEGER PRIMARY KEY, " + DAY + " INTEGER PRIMARY KEY, " + YEAR + " INTEGER PRIMARY KEY);"; + + " VARCHAR(255), " + CITY + " VARCHAR (255), "+STATE + " VARCHAR (255), "+ MONTH + " INTEGER, " + DAY + " INTEGER, " + YEAR + " LONG);"; private static final String CREATE_BOOK_TABLE = "Create table "+ TABLE_NAME_2+" ("+ UID+" Integer PRIMARY KEY, " + TITLE + " VARCHAR (255), "+ ISBN + " VARCHAR (255), "+ ISBN13 + " VARCHAR (255), "+ - PUBLISHER + " VARCHAR (255), "+ PUBLISHERYEAR + " INTEGER PRIMARY KEY, " + ISCHECKEDOUT+ " INTEGER PRIMARY KEY, " + CHECKEDOUTBY + " INTEGER PRIMARY KEY, " + CHECKOUTYEAR + " INTEGER PRIMARY KEY, " + CHECKOUTMONTH + " INTEGER PRIMARY KEY, " + CHECKOUTDAY + " INTEGER PRIMARY KEY, " + - DUEYEAR + " INTEGER PRIMARY KEY, " + DUEMONTH + " INTEGER PRIMARY KEY, " + DUEDAY + " INTEGER PRIMARY KEY);"; + PUBLISHER + " VARCHAR (255), "+ PUBLISHERYEAR + " INTEGER, " + ISCHECKEDOUT+ " INTEGER, " + CHECKEDOUTBY + " INTEGER, " + CHECKOUTYEAR + " INTEGER, " + CHECKOUTMONTH + " INTEGER, " + CHECKOUTDAY + " INTEGER, " + + DUEYEAR + " INTEGER, " + DUEMONTH + " INTEGER, " + DUEDAY + " INTEGER);"; public DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); diff --git a/src/main/java/nyc/c4q/LibraryActivity.java b/src/main/java/nyc/c4q/LibraryActivity.java index c2d2420..1f5dadb 100644 --- a/src/main/java/nyc/c4q/LibraryActivity.java +++ b/src/main/java/nyc/c4q/LibraryActivity.java @@ -30,8 +30,10 @@ protected void onCreate(Bundle savedInstanceState) { inputParameter = (EditText) findViewById(R.id.input_parameter); textDisplay=(TextView) findViewById(R.id.text_display); - loadBookJSONFromAsset("books.json"); - loadMemberJSONFromAsset("members.json"); + + + loadBookJSONFromAsset(R.raw.books); + loadMemberJSONFromAsset(R.raw.members); } @@ -79,10 +81,10 @@ public void button_getCheckedOut_onClick(View view) { // earliest due first. } - public void loadMemberJSONFromAsset(String fileName) { + public void loadMemberJSONFromAsset(int fileName) { String json = null; try { - InputStream is = getAssets().open(fileName); + InputStream is = getResources().openRawResource(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); @@ -94,10 +96,10 @@ public void loadMemberJSONFromAsset(String fileName) { } sendMemberInfo(json); } - public void loadBookJSONFromAsset(String fileName) { + public void loadBookJSONFromAsset(int fileName) { String json = null; try { - InputStream is = getAssets().open(fileName); + InputStream is = getResources().openRawResource(fileName); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); From 0c505a2a3f52d65eaaefc69c9d5083929af459ff Mon Sep 17 00:00:00 2001 From: MadelynTav Date: Mon, 31 Aug 2015 01:31:56 -0400 Subject: [PATCH 4/4] m --- src/main/java/nyc/c4q/DBAdapter.java | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/nyc/c4q/DBAdapter.java b/src/main/java/nyc/c4q/DBAdapter.java index 9b3ede1..69b8d40 100644 --- a/src/main/java/nyc/c4q/DBAdapter.java +++ b/src/main/java/nyc/c4q/DBAdapter.java @@ -21,14 +21,17 @@ public DBAdapter(Context context){ public long insertMemberData(int id, String name, String city, String state, int month, int day, int year) { SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues contentValues = new ContentValues(); - contentValues.put(DBHelper.UID,id); + + contentValues.put(DBHelper.FOREIGNID,id); contentValues.put(DBHelper.NAME, name); contentValues.put(DBHelper.CITY, city); contentValues.put(DBHelper.MONTH,month); contentValues.put(DBHelper.DAY,day); contentValues.put(DBHelper.YEAR,year); contentValues.put(DBHelper.STATE, state); + long id1 = db.insert(DBHelper.TABLE_NAME, null, contentValues); + return id1; } @@ -38,7 +41,7 @@ public long insertBookData(int id, String title, String author, String isbn, Str SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues contentValues = new ContentValues(); - contentValues.put(DBHelper.UID,id); + contentValues.put(DBHelper.FOREIGNID,id); contentValues.put(DBHelper.TITLE,title); contentValues.put(DBHelper.AUTHOR,author); contentValues.put(DBHelper.ISBN,isbn); @@ -59,12 +62,12 @@ public long insertBookData(int id, String title, String author, String isbn, Str } public String getDataForMember(String name) { SQLiteDatabase dbs = dbHelper.getWritableDatabase(); - String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR}; + String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR,DBHelper.FOREIGNID}; Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); StringBuffer buffer = new StringBuffer(); while (cursor.moveToNext()) { - int index1=cursor.getColumnIndex(DBHelper.UID); + int index1=cursor.getColumnIndex(DBHelper.FOREIGNID); int index2 = cursor.getColumnIndex(DBHelper.NAME); int index3 = cursor.getColumnIndex(DBHelper.CITY); int index4= cursor.getColumnIndex(DBHelper.STATE); @@ -86,13 +89,13 @@ public String getBookInfo(String ISBN){ SQLiteDatabase dbs = dbHelper.getWritableDatabase(); String[] columns = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, - DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; + DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR,DBHelper.FOREIGNID}; Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.ISBN + " = '" + ISBN + "'", null, null, null, null); StringBuffer buffer = new StringBuffer(); while (cursor.moveToNext()) { - int index1=cursor.getColumnIndex(DBHelper.UID); + int index1=cursor.getColumnIndex(DBHelper.FOREIGNID); int index2 = cursor.getColumnIndex(DBHelper.TITLE); int index17=cursor.getColumnIndex(DBHelper.AUTHOR); int index3 = cursor.getColumnIndex(DBHelper.ISBN); @@ -118,13 +121,12 @@ public String getBookInfo(String ISBN){ public ArrayList getCurrentlyCheckedOut(String name){ int UID = 0; SQLiteDatabase dbs = dbHelper.getWritableDatabase(); - String[] columns = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH, - DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR}; + String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR,DBHelper.FOREIGNID}; Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null); StringBuffer buffer = new StringBuffer(); while (cursor.moveToNext()) { - int index1=cursor.getColumnIndex(DBHelper.UID); + int index1=cursor.getColumnIndex(DBHelper.FOREIGNID); UID=cursor.getInt(index1); } @@ -198,12 +200,13 @@ static class DBHelper extends SQLiteOpenHelper { private static final String DUEYEAR="DueYear"; private static final String DUEMONTH="DueMonth"; private static final String DUEDAY="DueDay"; - private static final String CREATE_MEMBER_TABLE = "Create table " + TABLE_NAME + " (" + UID + " INTEGER PRIMARY KEY, " + NAME - + " VARCHAR(255), " + CITY + " VARCHAR (255), "+STATE + " VARCHAR (255), "+ MONTH + " INTEGER, " + DAY + " INTEGER, " + YEAR + " LONG);"; + private static final String FOREIGNID="ForeignID"; + private static final String CREATE_MEMBER_TABLE = "Create table " + TABLE_NAME + " (" + UID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + + " VARCHAR(255), " + CITY + " VARCHAR (255), "+STATE + " VARCHAR (255), "+ MONTH + " INTEGER, " + DAY + " INTEGER, " + YEAR + " LONG, " + FOREIGNID + " INTEGER);"; - private static final String CREATE_BOOK_TABLE = "Create table "+ TABLE_NAME_2+" ("+ UID+" Integer PRIMARY KEY, " + TITLE + " VARCHAR (255), "+ ISBN + " VARCHAR (255), "+ ISBN13 + " VARCHAR (255), "+ + private static final String CREATE_BOOK_TABLE = "Create table "+ TABLE_NAME_2+" ("+ UID+" INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE + " VARCHAR (255), "+ ISBN + " VARCHAR (255), "+ ISBN13 + " VARCHAR (255), "+ PUBLISHER + " VARCHAR (255), "+ PUBLISHERYEAR + " INTEGER, " + ISCHECKEDOUT+ " INTEGER, " + CHECKEDOUTBY + " INTEGER, " + CHECKOUTYEAR + " INTEGER, " + CHECKOUTMONTH + " INTEGER, " + CHECKOUTDAY + " INTEGER, " + - DUEYEAR + " INTEGER, " + DUEMONTH + " INTEGER, " + DUEDAY + " INTEGER);"; + DUEYEAR + " INTEGER, " + DUEMONTH + " INTEGER, " + DUEDAY + " INTEGER, "+ FOREIGNID + " INTEGER);"; public DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION);