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 @@ - - - - + getCurrentlyCheckedOut(String name){ + int UID = 0; + SQLiteDatabase dbs = dbHelper.getWritableDatabase(); + 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.FOREIGNID); + 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_2, 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"; + private static String TABLE_NAME_2 = "LibraryMembers"; + private static int DATABASE_VERSION = 1; + private static final String UID = "_id"; + private Context context; + private static final String CITY = "City"; + private static final String STATE = "State"; + private static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME; + private static final String NAME = "Name"; + private static final String MONTH="Month"; + private static final String DAY="Day"; + private static final String YEAR="Year"; + private static final String TITLE="Title"; + private static final String ISBN="ISBN"; + private static final String AUTHOR="Author"; + private static final String ISBN13="ISBN13"; + private static final String PUBLISHER="Publisher"; + private static final String ISCHECKEDOUT="IsCheckedOut"; + private static final String PUBLISHERYEAR="PublisherYear"; + private static final String CHECKEDOUTBY="CheckedOutBy"; + private static final String CHECKOUTYEAR="CheckoutYear"; + private static final String CHECKOUTMONTH="CheckoutMonth"; + private static final String CHECKOUTDAY="CheckoutDay"; + private static final String DUEYEAR="DueYear"; + private static final String DUEMONTH="DueMonth"; + private static final String DUEDAY="DueDay"; + 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 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, "+ FOREIGNID + " INTEGER);"; + + public DBHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + this.context = context; + Toast.makeText(context,"Constructor Called",Toast.LENGTH_LONG).show(); + } + + @Override + public void onCreate(SQLiteDatabase db) { + Toast.makeText(context, "OnCreate Was Called", Toast.LENGTH_LONG).show(); + + db.execSQL(CREATE_MEMBER_TABLE); + db.execSQL(CREATE_BOOK_TABLE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Toast.makeText(context, "ONUPGRADE Was Called",Toast.LENGTH_LONG).show(); + db.execSQL(DROP_TABLE); + onCreate(db); + + + } + } +} + diff --git a/src/main/java/nyc/c4q/ExampleFragment.java b/src/main/java/nyc/c4q/ExampleFragment.java new file mode 100644 index 0000000..5f8aac9 --- /dev/null +++ b/src/main/java/nyc/c4q/ExampleFragment.java @@ -0,0 +1,195 @@ +package nyc.c4q; + + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import java.util.ArrayList; + +/** + * A simple {@link Fragment} subclass. + */ +public class ExampleFragment extends android.support.v4.app.Fragment { + EditText distanceText; + EditText timeMin; + EditText timeSec; + EditText paceMin; + EditText paceSec; + Button calculate; + ArrayList 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..1f5dadb 100644 --- a/src/main/java/nyc/c4q/LibraryActivity.java +++ b/src/main/java/nyc/c4q/LibraryActivity.java @@ -4,18 +4,38 @@ import android.os.Bundle; import android.view.View; import android.widget.EditText; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +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) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_library); + dbAdapter = new DBAdapter(this); inputParameter = (EditText) findViewById(R.id.input_parameter); + textDisplay=(TextView) findViewById(R.id.text_display); + + + + loadBookJSONFromAsset(R.raw.books); + loadMemberJSONFromAsset(R.raw.members); + + } public void checkOut(int memberId, int bookId) { @@ -36,21 +56,113 @@ public boolean checkIn(int memberId, int bookId) { public void button_getMember_onClick(View view) { String name = inputParameter.getText().toString(); + textDisplay.setText(dbAdapter.getDataForMember(name)); + // TODO Display member information for the member with the given name. } 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. } + public void loadMemberJSONFromAsset(int fileName) { + String json = null; + try { + InputStream is = getResources().openRawResource(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(int fileName) { + String json = null; + try { + InputStream is = getResources().openRawResource(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/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, 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 +