diff --git a/pooni/.idea/caches/build_file_checksums.ser b/pooni/.idea/caches/build_file_checksums.ser index fc563ac..060f439 100644 Binary files a/pooni/.idea/caches/build_file_checksums.ser and b/pooni/.idea/caches/build_file_checksums.ser differ diff --git a/pooni/.idea/misc.xml b/pooni/.idea/misc.xml index 99202cc..c0f68ed 100644 --- a/pooni/.idea/misc.xml +++ b/pooni/.idea/misc.xml @@ -25,7 +25,7 @@ - + diff --git a/pooni/app/build.gradle b/pooni/app/build.gradle index 7859fcd..f07adc4 100644 --- a/pooni/app/build.gradle +++ b/pooni/app/build.gradle @@ -31,4 +31,5 @@ dependencies { implementation 'com.google.code.gson:gson:2.4' implementation 'com.android.support:design:27.1.0' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' + implementation 'com.android.support:recyclerview-v7:27.1.1' } diff --git a/pooni/app/src/main/java/com/uki121/pooni/Book.java b/pooni/app/src/main/java/com/uki121/pooni/Book.java index f893b38..4a4979a 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/Book.java +++ b/pooni/app/src/main/java/com/uki121/pooni/Book.java @@ -99,24 +99,23 @@ public boolean IsValidNum(String _target) //Set the number of access this book data public void setNumAcc(String _numAcc) { this.category[NUM_ACC] = _numAcc;} //Get a title for a book - public final String getTitle() { return category[TITLE]; } + public final String getTitle() { return category[TITLE]!= null? category[TITLE] : null; } //Get total time when whole problems are solved - public final String getToTime() { return category[TOTAL_TIME]; } + public final String getToTime() { return category[TOTAL_TIME]!= null? category[TOTAL_TIME] : null; } //Get max time when one problem is solved - public final String getEachTime() { return category[EACH_TIME]; } + public final String getEachTime() { return category[EACH_TIME] != null? category[EACH_TIME] : null; } //Get rest time between subjects - public final String getRestTime() { return category[REST_TIME]; } + public final String getRestTime() { return category[REST_TIME]!= null? category[REST_TIME] : null; } //Get how much a book has problems - public final String getNumProb() { return category[NUM_PROB]; } + public final String getNumProb() { return category[NUM_PROB]!= null? category[NUM_PROB] : null; } //Get the number of access this book data - public final String getNumAcc() { return category[NUM_ACC]; } + public final String getNumAcc() { return category[NUM_ACC]!= null? category[NUM_ACC] : null; } //Get current book' info public final String[] getBook() { System.out.println("Book_title " + category[TITLE]); for (int i = 1; i < MAX_CATEGORY - 1; ++i) { System.out.println("book_info : " + category[i]); } - System.out.println("\n"); return category; } }; diff --git a/pooni/app/src/main/java/com/uki121/pooni/ContractDBinfo.java b/pooni/app/src/main/java/com/uki121/pooni/ContractDBinfo.java index 27f7208..2425606 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/ContractDBinfo.java +++ b/pooni/app/src/main/java/com/uki121/pooni/ContractDBinfo.java @@ -44,26 +44,28 @@ public class ContractDBinfo { //public static final String COL_RECBOT = "cut_bottom10"; public static final String COL_DATE = "date_record"; public static final String COL_SOVLED = "numOfsolved"; - public static final String COL_STRACC = "string_access"; + public static final String COL_STRLAP = "string_laptime"; public static final String SQL_CREATE_REC ="CREATE TABLE IF NOT EXISTS " + TBL_RECORD + "(" + COL_RECID + " INTEGER PRIMARY KEY AUTOINCREMENT" + ", " + COL_BOOKID + " INTEGER " + ", " + - COL_DATE + " TEXT DEFAULT 'DATE(now)' " + ", " + + COL_DATE + " TEXT NOT NULL" + ", " + COL_SOVLED + " INTEGER DEFALUT '0'" + ", " + - COL_STRACC + " VARCHAR(1024)" + ", " + + COL_STRLAP + " VARCHAR(2048)" + ", " + "FOREIGN KEY(" + COL_BOOKID + ") " + "REFERENCES " + TBL_BOOK + "(" + COL_ID + ")" + " ON DELETE CASCADE" + ")" ; public static final String TBL_HISTORY_PIE = "TABLE_HISTORY_PIE"; + public static final String COL_CATE0 = "passed"; public static final String COL_CATE1 = "in_1_minutes"; public static final String COL_CATE2 = "in_2_minutes"; public static final String COL_CATE3 = "in_4_minutes"; public static final String COL_CATE4 = "out_of_time"; public static final String SQL_CREATE_HISTORY_PIE = "CREATE TABLE IF NOT EXISTS " + TBL_HISTORY_PIE + "(" + - COL_DATE + " TEXT DEFALUT 'DATE(now)'" + ", " + + COL_DATE + " TEXT NOT NULL" + ", " + + COL_CATE0 + " INTEGER DEFALUT '0'" + ", " + COL_CATE1 + " INTEGER DEFALUT '0'" + ", " + COL_CATE2 + " INTEGER DEFALUT '0'" + ", " + COL_CATE3 + " INTEGER DEFALUT '0'" + ", " + @@ -77,7 +79,7 @@ public class ContractDBinfo { public static final String SQL_CREATE_HISTORY_LINE = "CREATE TABLE IF NOT EXISTS " + TBL_HISTORY_LINE + "(" + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT " + ", " + - COL_MONTH + " TEXT DEFALUT 'DATE(now)'" + ", " + + COL_MONTH + " TEXT NOT NULL" + ", " + COL_EXCESS + " INTEGER DEFALUT '0'" + ", " + COL_NUM_BOOKS + " INTEGER DEFALUT '0'" + ", " + COL_NUM_SOLVED + " INTEGER DEFALUT '0'" + @@ -104,20 +106,4 @@ public class ContractDBinfo { public static final String SQL_INSERT_HISTORY_LINE = "INSERT OR REPLACE INTO " + TBL_HISTORY_LINE + " VALUES "; public static final String SQL_DELETE = "DELETE FROM "; //Update - public static final String WHERE_TITLE = "title=?"; //Book - public static final String WHERE_TOTIME = "total_time=?"; - public static final String WHERE_EATIME = "each_time=?"; - public static final String WHERE_RETIME = "rest_time=?"; - public static final String WHERE_NOPROB = "prob_num=?"; - public static final String WHERE_NOACC = "access_num=?"; - public static final String WHERE_RECID = "rid=?"; //User - public static final String WHERE_BOOKID = "bid=?"; - public static final String WHERE_EXECPROB = "prob_excess=?"; - public static final String WHERE_SOLVEDPROB = "prob_solved=?"; - public static final String WHERE_CORRPROB = "prob_corrected=?"; - public static final String WHERE_RECAVG = "avg=?"; //Record - public static final String WHERE_RECTOP= "cut_top10=?"; - public static final String WHERE_RECBOT = "cut_bottom10=?"; - public static final String WHERE_STRACC = "string_access=?"; - public static final String WHERE_DATE = "where " + COL_DATE + " between "; } diff --git a/pooni/app/src/main/java/com/uki121/pooni/DataMonth.java b/pooni/app/src/main/java/com/uki121/pooni/DataMonth.java index 6c0d83a..c8972fe 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/DataMonth.java +++ b/pooni/app/src/main/java/com/uki121/pooni/DataMonth.java @@ -11,27 +11,30 @@ public class DataMonth { //def private final String TAG = "Data Month"; + private final int MONTH_NUM = 12; //var - private int num; //the number of month private Month[] months; - public DataMonth(){}; - public DataMonth(int _num) { - this.num = _num; - months = new Month[_num]; + public DataMonth(){ + months = new Month[MONTH_NUM]; + for(int i = 0; i < MONTH_NUM; ++i) { + months[i] = new Month(i); + } + } + public DataMonth(String _json) { + DataMonth month = ToClass(_json); + months = new Month[MONTH_NUM];//Todo : is need? + setData(month); } public DataMonth(Month[] _month) { if (_month != null) { - this.num = _month.length; - this.months = _month; + months = _month; } } public DataMonth(ArrayList < Month> _month) { int sz = _month.size(); try { if (sz> 0) { - this.num = sz; - this.months = new Month[sz]; for (int i = 0; i < sz; ++i) { months[i] = _month.get(i); } @@ -41,24 +44,59 @@ public DataMonth(ArrayList < Month> _month) { } } //set - public void setData(DataMonth _src) { - this.num = _src.getNum(); - this.months = _src.getMonth(); + public boolean setData(DataMonth _src) { + try { + months = _src.getMonth(); + if (months != null) + return true; + } catch(Exception e) { + Log.d(TAG, e.getMessage()); + } + return false; + } + public boolean setData(ElapsedRecord _src) { + Log.d(TAG, "setData"); + //set new month + try { + Month _month = new Month(_src); + int _pos = _month.getKey();//find index of month + if (_pos < 0) { + Log.e(TAG, "> elp date has an error, pos is lower than 0"); + return false; + } + Log.d(TAG, "> month : " + (_pos + 1)); + //size check + if (months == null) { + months = new Month[MONTH_NUM]; + for (int i = 0; i< MONTH_NUM; ++i) + months[i] = new Month(i); + } + //accumulate it into an origin + months[_pos].accumMonth(_month); + return true; + } catch(Exception e) { + Log.e(TAG, e.getMessage()); + } + return false; } //get public Month getMonth(int _index) { - if (num < _index) { - Log.e(TAG, "Array index overflow"); - return null; + try { + if (months != null) { + return months[_index]; + } + } catch (Exception e) { + Log.e(TAG, e.getMessage()); } - return months[_index]; + return null; } - public Month[] getMonth() { return this.months;} - public int getNum() { return this.num;} + public Month[] getMonth() { return months != null? months : null;} public String ToString() { Gson gson = new GsonBuilder().create(); return gson.toJson(this, DataMonth.class); } + public int getExcess(int _pos) { return months[_pos] != null? months[_pos].getTotalExcess() : -1;} + public float getAvg(int _pos) { return months[_pos] != null? months[_pos].getAvgByprob() : -1;} public static DataMonth ToClass(String _str) { Gson gson = new Gson(); return gson.fromJson(_str, DataMonth.class); diff --git a/pooni/app/src/main/java/com/uki121/pooni/DataTotal.java b/pooni/app/src/main/java/com/uki121/pooni/DataTotal.java index f46c8b2..9d9d6ef 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/DataTotal.java +++ b/pooni/app/src/main/java/com/uki121/pooni/DataTotal.java @@ -6,72 +6,92 @@ import com.google.gson.GsonBuilder; import java.util.ArrayList; +import java.util.Iterator; public class DataTotal { //def private static final String TAG = "Data Total"; - private final int DEFAULT_STANDARD = 60; + private final int LESS_THAN_BY_1 = 60000; + private final int LESS_THAN_BY_2 = 120000; + private final int LESS_THAN_BY_4 = 240000; //var - private static final int NUM_CATE = 4; - private int standard; //second + private static final int NUM_CATE = 5; private int[] category; - private int totalNum; + private int totalNum = 0;//sum of category //constructor public DataTotal(){ - this.standard = DEFAULT_STANDARD; - this.category = new int[]{0, 0, 0, 0}; + this.category = new int[]{0, 0, 0, 0, 0}; this.totalNum = 0; }; public DataTotal(int[] _category) { - this.standard = DEFAULT_STANDARD; this.category = _category; setTotalNum(); } public DataTotal(String _strData) { DataTotal d = ToClass(_strData); - this.standard = d.getStandard(); this.category = d.getData(); this.totalNum = d.getSize(); } //set - public void setData(ElapsedRecord _elp) { - ArrayList < String> lap = _elp.getEachAccess(); - int taken_time, gap; - for (int i=0; i the record data is not valid"); + return false; + } + try { + //count each excess + ArrayList < String> _excess_list = _elp.getEachExcess(); + Iterator < String> _excess_it = _excess_list.iterator(); + int gap; + while(_excess_it.hasNext()) + { + gap = Integer.parseInt(_excess_it.next()); + //Log.d(TAG, "> gap : " + gap); + if (gap < 0) { //in_range_of_standard + category[0]++; + } else if (gap < LESS_THAN_BY_1) { //exceed_by_more than_1_minutes + category[1]++; + } else if (gap < LESS_THAN_BY_2) { //exceed_by__more than_2_minutes + category[2]++; + } else if (gap < LESS_THAN_BY_4){ //exceed_by__more than_4_minutes + category[3]++; + } else { + category[4]++; + } } + setTotalNum(); + return true; + } catch(Exception e) { + Log.e(TAG, e.getMessage()); } - setTotalNum(); + return false; } - public void setData(int[] _data) { - if (_data != null) { - for (int i = 0; i < NUM_CATE; ++i) { - this.category[i] = _data[i]; + public boolean setData(int[] _data) { + try { + if (_data != null) { + for (int i = 0; i < NUM_CATE; ++i) { + this.category[i] = _data[i]; + } + return true; + } else { + Log.w(TAG, "the argument of setData is null"); } - } else { - Log.w(TAG, "the argument of setData is null"); + } catch (Exception e) { + Log.d(TAG, e.getMessage()); } + return false; } private void setTotalNum() { if (category != null) { for (int i = 0; i < NUM_CATE; ++i) { - this.totalNum = this.category[i]; + totalNum += category[i]; } } else { Log.w(TAG, "category date is empty, totalNum cannot be set."); } } //get - public int getStandard() { return this.standard;} public int[] getData() { return category; } public int getSize() { return totalNum;} public String ToString() { diff --git a/pooni/app/src/main/java/com/uki121/pooni/ElapsedRecord.java b/pooni/app/src/main/java/com/uki121/pooni/ElapsedRecord.java index f0ee4ca..0e8789b 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/ElapsedRecord.java +++ b/pooni/app/src/main/java/com/uki121/pooni/ElapsedRecord.java @@ -9,48 +9,140 @@ import java.util.StringTokenizer; public class ElapsedRecord { - //var + //def + private final int LAP_SIZE = 8; private final String TAG = "ElapsedRecord"; - private final int[] time_unit = {3600, 60, 1};//hour, min, secon - private final int TOKEN_SIZE = 6; + private final int[] time_unit = {1, 1000, 60000};//milli:second:min + private final String DEFAULT_TITLE = "default_book"; + private final int DEFAULT_STANDARD = 60000;//1 min to milli + //var private Book baseBook; private String bookid, recordid; private String date; - private ArrayList eachExcess;//save it as seconds - private int num; //acutal size of record - private String strExcess; + /* + * eachLaptime set when FragmentLap is done + * eachExcess will be set when HistoryActivity is called + * + * */ + /* Todo : eachExcess is useless because DataTotal can calculate its excess */ + private ArrayList eachLaptime;//save it as milli + private int num = 0; //acutal size of record + private String strExcess, strLap; private boolean isBookSet = false; - //private float recordAvg; //private float cutTop10, cutBottom10; + //private float recordAvg; //method - public ElapsedRecord() {}; - public ElapsedRecord(Book _bs, List < String> _records) { - if (_bs != null) { + public ElapsedRecord() { + this.baseBook = new Book(); + this.eachLaptime = new ArrayList(){}; + }; + public ElapsedRecord(ElapsedRecord _elp) { + this.baseBook = new Book(_elp.getBaseBook()); + if (this.baseBook != null) { isBookSet = true; - baseBook = new Book(_bs); - } - num = _records.size(); - recordid = new String(); - bookid = new String(); - date = new String(); - strExcess = new String(); - eachExcess = new ArrayList < String>(); + } + this.bookid = _elp.getBookId(); + this.recordid = _elp.getRecordId(); + this.date = _elp.getDate(); + this.eachLaptime = _elp.getEachLaptime(); + this.num = eachLaptime.size(); + } + public ElapsedRecord(Book _bs, List < String> _records) {//used by FragmentLap + //book setting + this.baseBook = new Book(_bs); + if (this.baseBook.getTitle().equals(DEFAULT_TITLE) != true) { + //default book is considered as 'isBookset = false' + this.isBookSet = true; + } + this.recordid = new String(); + this.bookid = new String(); + this.date = new String(); + this.num = _records.size(); + this.eachLaptime = new ArrayList < String>(); //Set eachRecord Iterator < String> it = _records.iterator(); while (it.hasNext()) { int _item = getSecond(it.next()); - if (_item> 0) { eachExcess.add(_item);} + if (_item> 0) { this.eachLaptime.add(_item);} } - Collections.sort(eachExcess); + Collections.sort(this.eachLaptime); + setStrData("lap"); } //Set - public void setBaseBook(Book _bs) { baseBook = _bs;} + public void setRecordId(String _rid) { this.recordid = _rid;} + public void setBookId(String _bid) { this.bookid = _bid;} + public void setBaseBook(Book _bs) { + if (_bs != null) { + isBookSet = true; + this.baseBook = new Book(_bs); + } else { + Log.w(TAG, "setBaseBook() received null object"); + } + } public void setDate(String _date) { this.date = _date;} - public void setEachExcess(ArrayList eachAccess) { this.eachExcess = eachExcess; } - public void setEachExcess(String _src) { - this.eachExcess = convertStrTolist(_src); + /* + public void setExcessFromLap() { + Log.d(TAG, " #### START : setEachExcess #### "); + //eachLaptime -> eachExcess + if (baseBook == null) { + Log.w(TAG, "There is no book setting in Elp"); + Log.d(TAG, " #### END : setEachExcess #### "); + return ; + } + if (eachLaptime == null) { + Log.w(TAG, "There is no eachLapTime in Elp"); + Log.d(TAG, " #### END : setEachExcess #### "); + return ; + } + //standard time from basebook + try { + int standard = Integer.parseInt(baseBook.getEachTime()) * 1000;//convert second into milli + Log.d(TAG, ">> Standard for (int)excess time : " + standard); + Iterator it = eachLaptime.iterator(); + Log.d(TAG, ">> eachLaptime size : " + eachLaptime.size()); + while (it.hasNext()) { + int _excess = Integer.parseInt(it.next()) - standard; + Log.d(TAG, ">> CONVERTING string to (int)excess time : " + _excess); + if (_excess> 0) { + eachExcess.add(String.valueOf(_excess)); + } + } + Log.d(TAG, ">> RESULT : eachExcess size : " + eachExcess.size()); + } catch(Exception e) { + Log.e(TAG, e.getMessage()); + } + finally { + Log.d(TAG, " #### END : setEachExcess #### "); + } + } + */ + public void setEachLaptime(String _src) { + Log.d(TAG, " #### START : setEachLaptime #### "); + this.eachLaptime = new ArrayList < ElapsedRecord>(convertStrTolist(_src)); + this.num = eachLaptime.size(); + Log.d(TAG, " #### END : setEachLaptime #### "); + } + private void setStrData(String _targetname) { + String src = convertListTostr(_targetname); + //exception + if (src != null) { + Log.i("Record converting", ">> Done well"); + } else { + Log.w("Record converting",">> Err"); + return ; + } + switch(_targetname) { + case "excess" :{ + strExcess = src; + break; + } + case "lap" :{ + strLap = src; + } + default : + break; + } } - public void setBookId(String _bid) { this.bookid = _bid;} //Get public boolean IsBookSet() { return isBookSet;} public String getBookId() { return this.bookid;} @@ -61,68 +153,127 @@ public void setEachExcess(String _src) { //public float getCutTop10() { return cutTop10;} //public float getCutBottom10() { return cutBottom10;} public Book getBaseBook() { return baseBook;} - public ArrayList getEachAccess() { return eachExcess; } - public String getRecord() { - Iterator < String> it = eachExcess.iterator(); - StringBuffer res = new StringBuffer(); - while(it.hasNext()) { - res.append(it.next()); + public ArrayList getEachLaptime() { return this.eachLaptime;} + public ArrayList getEachExcess() { + Log.d(TAG, " ### getEachExess"); + if (baseBook == null) { + Log.w(TAG, "There is no book setting in Elp"); } - return res.toString(); + if (eachLaptime == null && eachLaptime.size() < 0) { + Log.w(TAG, "There is no eachLapTime in Elp"); + Log.d(TAG, " #### END : setEachExcess #### "); + return null; + } + ArrayList < String> eachExcess = new ArrayList(); + try { + //standard time from basebook + int standard = baseBook != null? Integer.parseInt(baseBook.getEachTime()) * 1000 : DEFAULT_STANDARD;//convert second into milli + Iterator < String> it = eachLaptime.iterator(); + Log.d(TAG, ">> Standard for (int)excess time : " + standard); + //Log.d(TAG, ">> eachLaptime size : " + eachLaptime.size()); + while (it.hasNext()) { + int _excess = Integer.parseInt(it.next()) - standard; + Log.d(TAG, ">> CONVERTING string to (int)excess time : " + _excess); + eachExcess.add(String.valueOf(_excess)); + } + //Log.d(TAG, ">> RESULT : eachExcess size : " + eachExcess.size()); + if (eachExcess.size()> 0) + return eachExcess; + else { + Log.d(TAG, "> this record has no excess"); + } + } catch(Exception e) { + Log.e(TAG, e.getMessage()); + } + finally { + Log.d(TAG, " #### END : setEachExcess #### "); + } + return null; } - public String getStrExcess() { - if (strExcess != null) { return this.strExcess; } - //serialize list 'eachExcess' to string'strExcess' - StringBuffer src = convertListTostr(); - Log.d(TAG, "getStrExcess : " + src.toString()); - if (src != null) { - Log.i("Record converting", "Done well"); - strExcess = src.toString(); - return strExcess; - } else { - Log.w("Record converting","Err : Check convertStrAcc()"); + //public String getStrLap() { return this.strLap;} + //public String getStrExcess() { return this.strExcess;} + public String getRecord() { + if (eachLaptime.isEmpty() != true ) { + Iterator it = eachLaptime.iterator(); + StringBuffer res = new StringBuffer(); + while (it.hasNext()) { + res.append(it.next()); + } + return res.toString(); } + Log.i(TAG, "Elp has no lap time data"); return null; } + //cal + public String getStrData(String _tartgetname) { + switch (_tartgetname) { + case "excess" : { + if (strExcess != null) { return this.strExcess;} + setStrData(_tartgetname); + return this.strExcess; + } + case "lap" : { + if (strLap != null) { return this.strLap;} + setStrData(_tartgetname); + return this.strLap; + } + default : + return null; + } + } public void getInfo(){ - System.out.println("date : " + date); - System.out.println("Record id : " + recordid); - System.out.println("isBookSet : " + isBookSet); - System.out.println("Book : " + baseBook.getTitle()); + try { + System.out.println("date : " + date); + System.out.println("Record id : " + recordid); + System.out.println("isBookSet : " + isBookSet); + System.out.println("Book : " + baseBook.getTitle()); + System.out.println("strLap : " + strLap); + System.out.println("strExcess : " + strExcess); + } catch(Exception e) { + Log.e(TAG, e.getMessage()); + } } + //Calculate - private StringBuffer convertListTostr() { + private String convertListTostr(String _listname) {//convert List to string //The substring of each string as a unit has a size by 6 //The basic string format is like "1. 00:00:00", and it would be cut out, 000000. StringBuffer res = new StringBuffer(); - Iterator < String> it = eachExcess.iterator(); + Iterator < String> it; + if (_listname.equals("lap")) {//lap + it = eachLaptime.iterator(); + } else { + Log.e(TAG, "convertListToStr has fatal error"); + return null; + } while (it.hasNext()) { - res.append(it.next()); - if (it.hasNext()) { res.append(":"); } //delimeter + res.append(String.valueOf(it.next())); + if (it.hasNext()) { + res.append(":"); + } //delimeter } - return res; + return res.toString(); } - public ArrayList convertStrTolist(String _from) { - int strSize = _from.length(); - Log.d(TAG, ">> (Before) String is " + _from); - Log.d(TAG, ">> (Before) String size : " + strSize); + public ArrayList convertStrTolist(String _str) { + int strSize = _str.length(); + Log.d(TAG, ">> (Before) String is " + _str); ArrayList < String> list_rec = new ArrayList(); - StringTokenizer str = new StringTokenizer(_from, ":"); + StringTokenizer str = new StringTokenizer(_str, ":"); for (int i = 0; str.hasMoreElements(); ) { - list_rec.add(str.nextToken()); + String _element = str.nextToken(); + //Log.d(TAG, " token : " + _element); + list_rec.add(_element); } return list_rec; } //Each Record date is convert to int as a second - public int getSecond(String _record) { - Log.d(TAG, "getSeconds"); - Log.d(TAG, "String : " + _record); + public int getSecond(String _laptime) { + Log.d(TAG, "getSeconds - lap time is : " + _laptime); int second = 0; - StringBuffer element = new StringBuffer(); //Extract index - int begin = _record.indexOf(" ") + 1;//ex) 1. 00:06:66 + int begin = _laptime.indexOf(" ") + 1;//ex) 1. 00:06:66 //Extract Time - StringTokenizer str = new StringTokenizer(_record.substring(begin, begin + 7), ":");//ex) 00:06:66 + StringTokenizer str = new StringTokenizer(_laptime.substring(begin, begin + LAP_SIZE), ":");//ex) 00:06:66 //Exception if (str.countTokens() < 3) { Log.w(TAG, "Record date has a wrong format"); @@ -130,10 +281,12 @@ public int getSecond(String _record) { } //Todo : split(":"), is it more efficient? for (int i = 2; i>= 0; --i) { - second += (time_unit[i] * Integer.parseInt(str.nextToken())); + String _tok = str.nextToken(); + second += (time_unit[i] * Integer.parseInt(_tok)); } + //Todo : delete because it is imposible case if (second < 0) { - Log.d(TAG, "current record has no excess time"); + Log.d(TAG, "laptime has negative number"); return 0; } return second; diff --git a/pooni/app/src/main/java/com/uki121/pooni/FragmentAnsSheet.java b/pooni/app/src/main/java/com/uki121/pooni/FragmentAnsSheet.java new file mode 100644 index 0000000..2e81efb --- /dev/null +++ b/pooni/app/src/main/java/com/uki121/pooni/FragmentAnsSheet.java @@ -0,0 +1,74 @@ +package com.uki121.pooni; + +import android.app.Fragment; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import com.google.gson.Gson; + +import java.util.ArrayList; + +public class FragmentAnsSheet extends Fragment { + private Book curBook; + private ArrayList mSource; + private static final String CUR_BOOK = "current_book"; + private final String TAG = "FragmentAnsSheet"; + //Recycle view + private RecyclerView mRecyclerView; + private RecyclerView.Adapter mAdapter; + private RecyclerView.LayoutManager mLayoutManager; + + public static FragmentAnsSheet newInstance(String _gsonBook) { + System.out.println(">> new :" + _gsonBook); + FragmentAnsSheet fragment = new FragmentAnsSheet(); + Bundle args = new Bundle(); + args.putString(CUR_BOOK, _gsonBook); + fragment.setArguments(args); + return fragment; + } + @Override + public void onCreate(Bundle SavedInstancState) { + super.onCreate(SavedInstancState); + if (getArguments() != null) { + String strCurBook = getArguments().getString(CUR_BOOK); + Gson gson = new Gson(); + curBook = gson.fromJson(strCurBook, Book.class); + //curBook.getBook(); + } else { + Log.e(TAG, "fatal error in OnCreate()"); + } + } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + final View view = inflater.inflate(R.layout.fragment_answer_sheet, container, false); + + return view; + } + public void init(View view) { + for(int i=0; i<10; ++i) { + mSource.add(new SheetItem()); + } + mRecyclerView = (RecyclerView)view.findViewById(R.id.recycler_view_omr); + + // use this setting to improve performance if you know that changes + // in content do not change the layout size of the RecyclerView + mRecyclerView.setHasFixedSize(true); + + // use a linear layout manager + mLayoutManager = new LinearLayoutManager(view.getContext()); + mRecyclerView.setLayoutManager(mLayoutManager); + + // specify an adapter (see also next example) + mAdapter = new SheetAdapter(this.getContext(), mSource); + mRecyclerView.setAdapter(mAdapter); + } +} diff --git a/pooni/app/src/main/java/com/uki121/pooni/FragmentHomeMenu.java b/pooni/app/src/main/java/com/uki121/pooni/FragmentHomeMenu.java index 554bc0b..d67652d 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/FragmentHomeMenu.java +++ b/pooni/app/src/main/java/com/uki121/pooni/FragmentHomeMenu.java @@ -15,26 +15,25 @@ public class FragmentHomeMenu extends Fragment { //Bundle private static final String CURB = "current_book_info"; - private static String strCurBook; - private Book curbook; + private String strCurBook; public FragmentHomeMenu() { }; public static FragmentHomeMenu newInstance(String _gsonBook) { - strCurBook = _gsonBook; FragmentHomeMenu fragment = new FragmentHomeMenu(); - Bundle args = new Bundle(); - args.putString(CURB, _gsonBook);//key : value - fragment.setArguments(args); + if (_gsonBook != null) { + Bundle args = new Bundle(); + args.putString(CURB, _gsonBook);//key : value + fragment.setArguments(args); + } return fragment; } @Override public void onCreate(Bundle SavedInstancState) { super.onCreate(SavedInstancState); if (getArguments() != null) {; - String strCurBook = getArguments().getString(CURB); - Gson gson = new Gson(); - curbook = gson.fromJson(strCurBook, Book.class); - curbook.getBook(); + strCurBook = getArguments().getString(CURB); + } else { + strCurBook = null; } } @Override @@ -47,28 +46,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Button btn_quick_start = (Button) view.findViewById(R.id.btn_quick_start); Button btn_setlog = (Button) view.findViewById(R.id.btn_setlog); - //feat1 : Create new dialog + //create new dialog btn_new_start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openSetDialog(); } }); - //feat2 : Start 'stopwatch' right away + //start 'stopwatch' right away btn_quick_start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (curbook != null) { - transaction.replace(R.id.frag_home_container, FragmentLap.newInstance(strCurBook, false)); - } else { - transaction.replace(R.id.frag_home_container, new FragmentLap()); - } + //transaction.replace(R.id.frag_home_container, FragmentLap.newInstance(strCurBook, false)); + transaction.replace(R.id.frag_home_container, FragmentAnsSheet.newInstance(strCurBook)); transaction.addToBackStack(null); transaction.commit(); } }); - //feat3 : Set your setting and check your logs + //set your setting and check your logs btn_setlog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/pooni/app/src/main/java/com/uki121/pooni/FragmentLap.java b/pooni/app/src/main/java/com/uki121/pooni/FragmentLap.java index 3b7cd48..622de6f 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/FragmentLap.java +++ b/pooni/app/src/main/java/com/uki121/pooni/FragmentLap.java @@ -9,6 +9,8 @@ import android.os.Handler; import android.os.Message; import android.os.SystemClock; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; @@ -31,11 +33,15 @@ /* ToDo : separte some functions from class FragmentLap, too big */ public class FragmentLap extends Fragment implements HomeActivity.onKeyBackPressedListener { + //def + private final String DEFAULT_TITLE = "default_book"; + private final int DEFAULT_EACH = 60000; //Bundle - private static final String APPB = "applied_book_info"; + private static final String CUR_BOOK = "applied_book_info"; + private static final String IS_NEWBOOK = "is_new_book"; private static String strCurBook; private Book curBook; - private static boolean IsNewBook = false; + private static boolean isNewBook = false; //View private Button btnStart, btnRec, btnEnd, btnDel; private TextView myOutput, myRec; @@ -55,12 +61,11 @@ public class FragmentLap extends Fragment implements HomeActivity.onKeyBackPress public void FragmentLap(){ }; public static FragmentLap newInstance(String _gsonBook, boolean _isNewBook) { - strCurBook = _gsonBook; - IsNewBook = _isNewBook; - System.out.println(">> new :" + strCurBook); + System.out.println(">> new :" + _gsonBook); FragmentLap fragment = new FragmentLap(); Bundle args = new Bundle(); - args.putString(APPB, _gsonBook); + args.putString(CUR_BOOK, _gsonBook); + args.putBoolean(IS_NEWBOOK, _isNewBook); fragment.setArguments(args); return fragment; } @@ -68,16 +73,14 @@ public static FragmentLap newInstance(String _gsonBook, boolean _isNewBook) { public void onCreate(Bundle SavedInstancState) { super.onCreate(SavedInstancState); if (getArguments() != null) { - if (IsNewBook == true) {//case1. new Book is set - strCurBook = getArguments().getString(APPB); - Gson gson = new Gson(); - curBook = gson.fromJson(strCurBook, Book.class); - curBook.getBook(); - } else {//case2. current book is set - strCurBook = getArguments().getString(APPB); + strCurBook = getArguments().getString(CUR_BOOK); + isNewBook = getArguments().getBoolean(IS_NEWBOOK); + if (strCurBook != null) { Gson gson = new Gson(); curBook = gson.fromJson(strCurBook, Book.class); curBook.getBook(); + } else { + curBook = null; } } } @@ -103,17 +106,17 @@ public void init(View view) { btnDel.setOnClickListener(btnOnClickListener); btnEnd.setOnClickListener(btnOnClickListener); - /* [ToDo] : each time is considered as min. If not, it will cause error and bug */ - //apply current book's setting to count time - if (curBook != null) - { + //set book + if (curBook != null) { each_time = Integer.parseInt(curBook.getEachTime()) * 1000; //considered this as second - total_time = Integer.parseInt(curBook.getToTime()) * 60000; //considered this as min - if (IsNewBook == false) { - Log.i("Book_SettingInLap", "Existing setting is applied"); - } else { //(IsNewBook == true) - Log.i("Book_SettingInLap", "New setting is applied"); - } + } else { //default setting will be applied + each_time = DEFAULT_EACH; + } + //if new book + if (isNewBook == false) { + Log.i("Book_SettingInLap", "Existing setting is applied"); + } else { //(IsNewBook == true) + Log.i("Book_SettingInLap", "New setting is applied"); } } //Handler for current time @@ -272,18 +275,26 @@ public void checkEachBound(String _curLaptime) { } Log.i("Excess_problem", String.valueOf(excess_prob)); } - public String convertToRecord(Book src_book, List < String> src_lap) { + //Calculate a mount of excess time + public void checkTotalBound() { + //current time + String _curPauseTime = myOutput.getText().toString(); + long _curTotaltime = recordTolong(_curPauseTime, "hms"); + //set total_time + if (curBook != null) { + total_time = Integer.parseInt(curBook.getToTime()) * 60000; //considered this as min + } else { //default setting will be applied + total_time = listLap.size() * each_time; + } + //calculte excess time + excess_time = _curTotaltime - total_time; + Log.i("Excess_time", String.valueOf(excess_time)); + } + public String convertElpTostr(Book src_book, List < String> src_lap) { ElapsedRecord userRecord = new ElapsedRecord(src_book, src_lap);//new instance of ElapsedRecord from record made Gson gson = new GsonBuilder().create(); return gson.toJson(userRecord, ElapsedRecord.class); } - //Calculate a mount of access time - public void checkTotalBound() { - String _curPauseTime = myOutput.getText().toString(); - long _curToTimeInMilli = recordTolong(_curPauseTime, "hms"); - excess_time = _curToTimeInMilli - total_time; - Log.i("Access_time", String.valueOf(excess_time)); - } class BtnOnClickListener implements Button.OnClickListener { final String LAP_RECORD = "elapsed_record"; @Override @@ -323,7 +334,7 @@ public void onClick(View view) { switch (cur_Status) { case Run: String curlap = getLabTimeout(); - checkEachBound(curlap);//Event access + checkEachBound(curlap);//Event excess String str = String.format("%d. %s\n", myCount, curlap); //print colored a string every 5th. if (myCount % 5 != 0) { @@ -360,17 +371,19 @@ public void onClick(View view) { break; } case R.id.btn_end: { - /* ToDo : new ElapsedRecord and Deliver or SaveNShare */ - /* ToDo : More arguments are need like 'user' class*/ checkTotalBound(); - String strElp = convertToRecord(curBook, listLap); //convert + //default setting have to be instantiated + if (curBook == null) { + curBook = new Book(); + curBook.setTitle(DEFAULT_TITLE); + curBook.setEachTime(String.valueOf(each_time)); + curBook.setToTime(String.valueOf(total_time)); + curBook.setNumProb(String.valueOf(listLap.size())); + } + String strElp = convertElpTostr(curBook, listLap); System.out.println(">> Record :" + strElp); FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (curBook != null) { - transaction.replace(R.id.frag_home_container, FragmentSaveShare.newInstance(strElp, IsNewBook)); - } else { - transaction.replace(R.id.frag_home_container, new FragmentSaveShare()); - } + transaction.replace(R.id.frag_home_container, FragmentSaveShare.newInstance(strElp, isNewBook)); transaction.addToBackStack(null); transaction.commit(); break; diff --git a/pooni/app/src/main/java/com/uki121/pooni/FragmentMonthHistory.java b/pooni/app/src/main/java/com/uki121/pooni/FragmentMonthHistory.java index 8c36064..069547a 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/FragmentMonthHistory.java +++ b/pooni/app/src/main/java/com/uki121/pooni/FragmentMonthHistory.java @@ -35,17 +35,16 @@ public class FragmentMonthHistory extends Fragment { //def private final String TAG = "FragmentMonthHistory"; private static final String ARG = "month_history"; + private final int NUM_MONTH = 12; + protected String[] mMonths = new String[] { + "Jan", "Feb", "Mar", "Apr", "May", "June", "July","Aug", "Sep", "Oct", "Nov", "Dec" + }; //var private DataMonth monthhistory; private boolean isMonthhistory = false; - //chart private CombinedChart combinedchart; - private final int itemcount = 12; private ArrayList< Entry> lineEntries; private ArrayList< BarEntry> barEntries; - protected String[] mMonths = new String[] { - "Jan", "Feb", "Mar", "Apr", "May", "June", "July","Aug", "Sep", "Oct", "Nov", "Dec" - }; public FragmentMonthHistory() {}; public static FragmentMonthHistory newInstance(String _monthHistory) { @@ -61,10 +60,9 @@ public static FragmentMonthHistory newInstance(String _monthHistory) { public void onCreate(Bundle SavedInstancState) { super.onCreate(SavedInstancState); if (getArguments() != null) { - Log.d(TAG, "onCreate : argument is get"); String str = getArguments().getString(ARG); isMonthhistory = str != null? true : false; - monthhistory = new DataMonth().ToClass(str); + monthhistory = isMonthhistory != false? new DataMonth(str) : null; } else { Log.d(TAG, "onCreate : argument is null"); isMonthhistory = false; @@ -89,7 +87,7 @@ public void onValueSelected(Entry e, Highlight h) { if (isMonthhistory != false) { //history data-set int pos = (int) h.getX(); int numOfprob = monthhistory.getMonth(pos).getNumOfprob(); - Toast.makeText(getActivity(), "이달 푼 문제수 :" + numOfprob + "\n" + "총 초과량 : " + barEntries.get(pos) + "초\n 평균 초과량 : " + lineEntries.get(pos) + "분", Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity(), "이달 푼 문제수 :" + numOfprob + "\n" + "총 초과량 : " + barEntries.get(pos).getY() + "초\n 평균 초과량 : " + lineEntries.get(pos).getY() + "분", Toast.LENGTH_LONG).show(); } else { //default data-mode Toast.makeText(getActivity(), "This is default mode.\nNo data found ", Toast.LENGTH_LONG).show(); } @@ -107,7 +105,6 @@ private void setup_chart(View view) { combinedchart.setDrawGridBackground(false); combinedchart.setDrawBarShadow(false); combinedchart.setHighlightFullBarEnabled(false); - // draw bars behind lines combinedchart.setDrawOrder(new CombinedChart.DrawOrder[]{ DrawOrder.BAR, DrawOrder.LINE @@ -150,9 +147,9 @@ public String getFormattedValue(float value, AxisBase axis) { private LineData generateLineData() { LineData d = new LineData(); lineEntries = new ArrayList(); - //initialize entry set + //init entries lineEntries = getLineEntriesData(lineEntries); - + //init line data set based on entris LineDataSet set = new LineDataSet(lineEntries, "Line DataSet"); set.setColor(Color.rgb(213, 45, 23)); set.setLineWidth(2.5f); @@ -182,18 +179,20 @@ private BarData generateBarData() { float barWidth = 0.45f; // x2 dataset BarData d = new BarData(set1); d.setBarWidth(barWidth); - return d; } //initialize chart data : line chart private ArrayList getLineEntriesData(ArrayList entries) { if (isMonthhistory == false) {//default-mode - for (int index = 0; index < itemcount; index++) { + Log.w(TAG, "Default line data is set"); + for (int index = 0; index < NUM_MONTH; ++index) { entries.add(new Entry(index, getRandom(15, 5))); } } else {//history data-set - for (int index = 0; index < itemcount; index++) { - float _avgByprob = monthhistory.getMonth(index).getAvgByprob(); + Log.d(TAG, "custom line data is set"); + for (int index = 0; index < NUM_MONTH; ++index) { + float _avgByprob = (float)(Math.round(monthhistory.getMonth(index).getAvgByprob())/1000.0); //milli -> sec + Log.d(TAG, "> avgProb : " + _avgByprob); entries.add(new Entry(index, _avgByprob)); } } @@ -202,14 +201,15 @@ private ArrayList getLineEntriesData(ArrayList entries) { //initialize chart data : bar chart private ArrayList getBarEnteries(ArrayList entries) { if (isMonthhistory == false) {//default-mode - Log.w(TAG, "Default data mode active"); - for (int index = 0; index < itemcount; index++) { + Log.w(TAG, "Default bar data is set"); + for (int index = 0; index < NUM_MONTH; index++) { entries.add(new BarEntry(index, getRandom(25, 25))); } } else {//history data-set - Log.d(TAG, "Valid data mode active"); - for (int index = 0; index < itemcount; index++) { - int _totalexcess = monthhistory.getMonth(index).getTotalExcess(); + Log.d(TAG, "custom data is set"); + for (int index = 0; index < NUM_MONTH; index++) { + float _totalexcess = (float) (Math.round(monthhistory.getMonth(index).getTotalExcess())/1000.0); + Log.d(TAG, "> total excess : " + _totalexcess); entries.add(new BarEntry(index, _totalexcess)); } } diff --git a/pooni/app/src/main/java/com/uki121/pooni/FragmentSaveShare.java b/pooni/app/src/main/java/com/uki121/pooni/FragmentSaveShare.java index 9dc6c10..0f071d4 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/FragmentSaveShare.java +++ b/pooni/app/src/main/java/com/uki121/pooni/FragmentSaveShare.java @@ -20,23 +20,22 @@ public class FragmentSaveShare extends Fragment implements HomeActivity.onKeyBackPressedListener { //Bundle - //for current book - private static final String APPR = "applied_record_info"; + private static final String CUR_BOOK = "applied_book_info"; + private static final String IS_NEWBOOK = "is_new_book"; private static String strUserRecord; private onUpdateStateListener updateToHomeListener; private ElapsedRecord curUserRec; - private static boolean IsNewBook = false; - private static boolean IsSaved; + private static boolean isNewBook = false; + private static boolean isSaved; //view private Button btnShare, btnSave; public void FragmentSaveShare(){}; public static FragmentSaveShare newInstance(String _gsonUser, boolean _IsNewSet) { - strUserRecord = _gsonUser;//pair < book, list < string>> to String - IsNewBook = _IsNewSet; FragmentSaveShare fragment = new FragmentSaveShare(); Bundle args = new Bundle(); - args.putString(APPR, _gsonUser); + args.putString(CUR_BOOK, _gsonUser); + args.putBoolean(IS_NEWBOOK, _IsNewSet); fragment.setArguments(args); return fragment; } @@ -44,7 +43,10 @@ public static FragmentSaveShare newInstance(String _gsonUser, boolean _IsNewSet) public void onCreate(Bundle SavedInstancState) { super.onCreate(SavedInstancState); if (getArguments() != null) { - strUserRecord = getArguments().getString(APPR); + strUserRecord = getArguments().getString(CUR_BOOK); + isNewBook = getArguments().getBoolean(IS_NEWBOOK); + //restore elp from srUserRecord + //Todo : usless Gson gson = new Gson(); curUserRec = gson.fromJson(strUserRecord, ElapsedRecord.class); } @@ -58,12 +60,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return view; } void init(View view) { - IsSaved = false; + isSaved = false; btnShare = (Button) view.findViewById(R.id.btn_share); btnShare.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { - updateToHomeListener.onUpdateRecord(strUserRecord, IsNewBook); + updateToHomeListener.onUpdateRecord(strUserRecord, isNewBook); updateToHomeListener.onSharingSNS(strUserRecord); } }); @@ -79,8 +81,8 @@ public void onClick(View view) { .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { - updateToHomeListener.onUpdateRecord(strUserRecord, IsNewBook); - IsSaved = true; + updateToHomeListener.onUpdateRecord(strUserRecord, isNewBook); + isSaved = true; sDialog.dismissWithAnimation(); } }) @@ -111,7 +113,7 @@ public void onAttach(Context context) { @Override public void onBack() { System.out.println(">> SaveShare_back"); - if (IsSaved == false) { //already saved the data + if (isSaved == false) { //already saved the data Log.i("onBack", "Not saved states"); backDialog(); } else { //Go back to home @@ -140,7 +142,7 @@ public void onClick(@android.support.annotation.NonNull MaterialDialog dialog, @ fragmentManager.popBackStack(); FragmentTransaction transaction = fragmentManager.beginTransaction(); if (curUserRec != null) { - transaction.replace(R.id.frag_home_container, FragmentLap.newInstance(strUserRecord, IsNewBook)); + transaction.replace(R.id.frag_home_container, FragmentLap.newInstance(strUserRecord, isNewBook)); } else { transaction.replace(R.id.frag_home_container, new FragmentLap()); } diff --git a/pooni/app/src/main/java/com/uki121/pooni/FragmentTotalHistory.java b/pooni/app/src/main/java/com/uki121/pooni/FragmentTotalHistory.java index 148b6c9..437b208 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/FragmentTotalHistory.java +++ b/pooni/app/src/main/java/com/uki121/pooni/FragmentTotalHistory.java @@ -20,17 +20,17 @@ public class FragmentTotalHistory extends Fragment { //def - private static String TAG = "FragmentTotalHistory"; + private String TAG = "FragmentTotalHistory"; private static final String ARG = "total_history"; - private static final String HISTORY_PIE = "총 풀이 기록"; - private static final int NUM_CATEGORY = 4; + private final String HISTORY_PIE = "총 풀이 기록"; + private final int NUM_CATEGORY = 5; + private final String[] pie_category = {"통과", "1분 미만 초과 ", "2분 미만", "4분 미만", "기타"}; //var private PieChart chartTotalHistory; private DataTotal totalhistory; - private static final String[] pie_category = {"1분 미만", "2분 미만", "4분 미만", "기타"}; - private static float[] pie_value = {1.0f, 2.0f, 93.0f, 4.0f};//defalut - private int[] pie_raw_value; - private static boolean IsSetHistory = false; + private int[] pie_raw_value = new int[]{1, 2 ,86, 4, 7};//defalut + private float[] pie_value = new float[]{1.0f, 2.0f, 86.0f, 4.0f, 7.0f};//defalut + private boolean isSetHistory = false; public FragmentTotalHistory (){}; public static FragmentTotalHistory newInstance(String _totalHistory) { @@ -46,14 +46,13 @@ public static FragmentTotalHistory newInstance(String _totalHistory) { public void onCreate(Bundle SavedInstancState) { super.onCreate(SavedInstancState); if (getArguments() != null) { - Log.d(TAG,"History is active"); + Log.d(TAG,"History custom data is set"); String str = getArguments().getString(ARG); - totalhistory = new DataTotal(str); - pie_raw_value = totalhistory.getData(); - IsSetHistory = true; + isSetHistory = str != null? true : false; + totalhistory = isSetHistory != false? new DataTotal(str) : null; } else { Log.d(TAG,"History is null now"); - IsSetHistory = false; + isSetHistory = false; totalhistory = null; } } @@ -65,8 +64,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return view; } public void init(View view) { - Log.d(TAG, "onCreate: starting to create chart"); chartTotalHistory = (PieChart) view.findViewById(R.id.piechart_total_history); + //char attribute //chartTotalHistory.setDescription("Sales by employee (In Thousands $"); chartTotalHistory.setRotationEnabled(true); //pieChart.setUsePercentValues(true); @@ -76,8 +75,11 @@ public void init(View view) { chartTotalHistory.setTransparentCircleAlpha(0); chartTotalHistory.setCenterText(HISTORY_PIE); chartTotalHistory.setCenterTextSize(10); + //Entry attribute //pieChart.setDrawEntryLabels(true); + chartTotalHistory.setDrawEntryLabels(false); //pieChart.setEntryLabelTextSize(20); + chartTotalHistory.setEntryLabelColor(Color.WHITE); //More options just check out the documentation! setDataSet(); addDataSet(); @@ -90,13 +92,8 @@ public void onValueSelected(Entry e, Highlight h) { Log.d(TAG, "onValueSelected: " + h.toString()); int pos = (int) h.getX(); //If history is set, then show the number of value of each category and its percent - if (IsSetHistory == true) { - Toast.makeText(getActivity(), "카테고리:" + pie_category[pos] + "\n" + "수치: " + pie_value[pos] + "% (" + pie_raw_value[pos] + "개)", Toast.LENGTH_LONG).show(); - } - //If a default history is set, then show its percent - else { - Toast.makeText(getActivity(), "카테고리:" + pie_category[pos] + "\n" + "수치: " + pie_value[pos] + "%", Toast.LENGTH_LONG).show(); - } + Toast.makeText(getActivity(), "카테고리 : " + pie_category[pos] + "\n" + "수치 : " + pie_value[pos] + "% (" + pie_raw_value[pos] + "개)", Toast.LENGTH_LONG).show(); + } @Override public void onNothingSelected() { @@ -104,34 +101,36 @@ public void onNothingSelected() { }); } public void setDataSet() { - if (totalhistory != null) { - Log.d(TAG, "SetDataSet"); - int total = totalhistory.getSize(); - int[] val = totalhistory.getData(); - for (int i=0; i value = new ArrayList(); - ArrayList < String> value_name = new ArrayList(); - - //step1.initializing - for (int i=0; i pie_data = new ArrayList(); + ArrayList < String> pie_name = new ArrayList(); + //set pie data on chart + for (int i = 0; i < NUM_CATEGORY; ++i) { + //pie_name.add(pie_category[i]); + //pie_value.add(new PieEntry(pie_raw_value[i] , pie_name.get(i))); + pie_data.add(new PieEntry(pie_value[i] , pie_category[i])); } - for (int i=0; i colors = new ArrayList(); colors.add(Color.BLUE); colors.add(Color.GREEN); @@ -141,13 +140,11 @@ public void addDataSet() { //colors.add(Color.RED); //colors.add(Color.YELLOW); pieDataSet.setColors(colors); - //add legend to chart Legend legend = chartTotalHistory.getLegend(); legend.setForm(Legend.LegendForm.CIRCLE); legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART); - - //create pie data object + //create pie data object based on data set PieData pieData = new PieData(pieDataSet); chartTotalHistory.setData(pieData); chartTotalHistory.invalidate(); diff --git a/pooni/app/src/main/java/com/uki121/pooni/History.java b/pooni/app/src/main/java/com/uki121/pooni/History.java index ce578f5..cd21102 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/History.java +++ b/pooni/app/src/main/java/com/uki121/pooni/History.java @@ -14,11 +14,14 @@ public class History { private final String TOTAL_HISOTRY = "total_history"; private final String MONTH_HISTORY = "month_history"; //var - private DataTotal total_history = null; - private DataMonth month_history = null; + private DataTotal total_history; + private DataMonth month_history; private boolean isDataTotal = false , isDataMonth = false; //Constructor - public History() {} + public History() { + this.total_history = new DataTotal(); + this.month_history = new DataMonth(); + } public History(History history) { this.total_history = history.getHistoryToTal(); this.month_history = history.getHistoryMonth(); @@ -33,62 +36,75 @@ public History(ArrayList < ElapsedRecord> _elpList) { public History(DataTotal _datatotal, DataMonth _datamonth) { try { //selective assignment - this.total_history = _datatotal != null ? _datatotal : null; - this.month_history = _datamonth != null ? _datamonth : null; + isDataTotal = _datatotal != null? true : false; + isDataMonth = _datamonth != null? true : false; + this.total_history = isDataTotal != false ? _datatotal : null; + this.month_history = isDataMonth != false ? _datamonth : null; } catch(Exception e) { Log.e(TAG, e.getMessage()); } } //set //set History by History class - public void setHistory(History _history) { + public boolean setHistory(History _history) { if (_history != null) { - if (_history.getHistoryToTal() != null) { + if (_history.IsTotalHistory() != false) { Log.d(TAG, "setHistory() has Total data"); - this.total_history = _history.getHistoryToTal(); + total_history = _history.getHistoryToTal(); isDataTotal = true; + return true; } else { Log.d(TAG, "setHistory() has no Data"); } - if (_history.getHistoryMonth() != null) { + if (_history.IsTotalHistory() != false) { Log.d(TAG, "setHistory() has Month data"); - this.month_history = _history.getHistoryMonth(); + month_history = _history.getHistoryMonth(); isDataMonth = true; + return true; } else { Log.d(TAG, "setHistory() has no Month data"); } } else { Log.d(TAG, "setHistory() has null history now"); + Log.d(TAG, "> no change in this history"); } + return false; } //set History by ElapsedRecord class public void setHistory(ArrayList < ElapsedRecord> _elpList) { - setTotal_history(_elpList); - setMonth_history(_elpList); + isDataTotal = setTotal_history(_elpList); + isDataMonth = setMonth_history(_elpList); } //set TotalHistory - private void setTotal_history(ArrayList < ElapsedRecord> _elpList){ + private boolean setTotal_history(ArrayList < ElapsedRecord> _elpList){ if (_elpList.isEmpty()) { Log.w(TAG, "setTotal_history() has 0 size list"); - return; + return false; } - isDataTotal = true; - int[] res = new int[4]; Iterator < ElapsedRecord> it = _elpList.iterator(); while(it.hasNext()) { - total_history.setData(it.next()); + boolean _flag = total_history.setData(it.next()); + if (_flag == false ) + return false; } + return true; } //set MonthHistory - private void setMonth_history(ArrayList < ElapsedRecord> _elpList) { + private boolean setMonth_history(ArrayList < ElapsedRecord> _elpList) { + if (_elpList.size() < 0) { + Log.w(TAG, "setMonth_history() has 0 size list"); + return false; + } try { //part1.create Month Map < Integer, Month> _mMap = new HashMap(); Iterator < ElapsedRecord> it = _elpList.iterator(); while(it.hasNext()) { ElapsedRecord _elp = it.next(); + /* //step1.check a infomation of elp elements _elp.getInfo(); + */ //step2.classify their month //step2.1.find target as month "05" and extract (int)5 from (string)05 String[] _src = _elp.getDate().split("-");//ex) 2018, 05, 11, 05 is a target. @@ -106,15 +122,36 @@ private void setMonth_history(ArrayList < ElapsedRecord> _elpList) { //part2.create DataMonth based on Month Map < Integer, Month> _months = new TreeMap(_mMap); Month[] arg_months = (Month[])_months.values().toArray(); - this.month_history.setData(new DataMonth(arg_months)); + return month_history.setData(new DataMonth(arg_months)); } catch (Exception e) { Log.w(TAG, "constructor of Month class : " + e.getMessage()); } - + return false; + } + public boolean onUpdateByrecord(ArrayList < ElapsedRecord> _newrecord) { + if (_newrecord != null && _newrecord.size()> 0) { + Iterator < ElapsedRecord> it = _newrecord.iterator(); + while (it.hasNext()) { + ElapsedRecord item = new ElapsedRecord(it.next()); + try { + item.getInfo(); + isDataTotal = total_history.setData(item); + isDataMonth = month_history.setData(item); + return true; + } catch (Exception e) { + Log.e(TAG, "onUpdateByrecord() - " + e.getMessage()); + return false; + } + } + } else { + Log.d(TAG, "There is no update for history because record data is null"); + } + return false; } //get - public DataTotal getHistoryToTal() {return total_history;} - public DataMonth getHistoryMonth() {return month_history;} + public DataTotal getHistoryToTal() {return isDataTotal == true? total_history : null;} + public DataMonth getHistoryMonth() {return isDataMonth == true? month_history : null;} public boolean IsTotalHistory() { return isDataTotal;} public boolean IsMonthHistory() { return isDataMonth;} + public boolean IsSet(){ return isDataMonth & isDataTotal;} } diff --git a/pooni/app/src/main/java/com/uki121/pooni/HistoryActivity.java b/pooni/app/src/main/java/com/uki121/pooni/HistoryActivity.java index 6ec0835..e36bd15 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/HistoryActivity.java +++ b/pooni/app/src/main/java/com/uki121/pooni/HistoryActivity.java @@ -1,6 +1,8 @@ package com.uki121.pooni; +import android.content.ContentValues; import android.content.SharedPreferences; +import android.content.res.TypedArray; import android.database.Cursor; import android.os.Bundle; import android.support.annotation.Nullable; @@ -9,30 +11,31 @@ import android.support.v7.app.AppCompatActivity; import android.util.Log; +import java.lang.reflect.Array; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; import java.util.Map; import java.util.Set; - -public class HistoryActivity extends AppCompatActivity{ - //Debug +public class HistoryActivity extends AppCompatActivity { + //def private static final String TAG = "HistoryActivity"; //DB private bookDBHelper dbhelper; - private ArrayList< ElapsedRecord> newRecord; + private ArrayList newRecord; private History history; + private boolean isTotalHist = false, isMonthHist = false; //SharedPreference - private static final String SYNC_DATE = "date synchronized"; + private final String SYNC_POINT = "sync_point"; private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - private String sync_date; - private boolean IsSetSync = false, //Is set Synchronized date - IsSyncRequest = false;//request from other fragment + private String sync_point; //Tab-Fragment private HistoryAdapter hisAdapter; private ViewPager viewpager; private TabLayout histab; + @Override protected void onCreate(Bundle savedInstanceStates) { super.onCreate(savedInstanceStates); @@ -40,77 +43,96 @@ protected void onCreate(Bundle savedInstanceStates) { setContentView(R.layout.fragment_container_history); init(); } + // Todo : current db don't operate now public void init() { //db create and open dbhelper = new bookDBHelper(HistoryActivity.this); - dbhelper.createTable(ContractDBinfo.TBL_HISTORY_PIE); - dbhelper.createTable(ContractDBinfo.TBL_HISTORY_LINE); + dbhelper.createTable(ContractDBinfo.TBL_HISTORY_PIE, null); + dbhelper.createTable(ContractDBinfo.TBL_HISTORY_LINE, null); //assignment - sync_date = new String(); history = new History(); //load - onLoadSyncDate();//from sharedPreferences - onLoadRecord(); //from db - - //Todo : reinforcement selective because of addtion of DataMonth - //set up viewpager and tab_layout - if (IsSetSync != true) { - hisAdapter = new HistoryAdapter(getSupportFragmentManager(), newRecord);//view pager - } else { + onLoadSyncInfo();//from sharedPreferences + onLoadHistory();//read history table + onLoadRecord(); //read record table + //set adapter + if (history.IsSet() == true) hisAdapter = new HistoryAdapter(getSupportFragmentManager(), history); - } + else + hisAdapter = new HistoryAdapter(getSupportFragmentManager(), null); + //set up viewpager and tab_layout viewpager = (ViewPager) findViewById(R.id.viewpager_history); viewpager.setAdapter(hisAdapter); histab = (TabLayout) findViewById(R.id.tab_history);//tab layout histab.setupWithViewPager(viewpager); } + @Override public void finish() { super.finish(); this.overridePendingTransition(R.anim.end_enter, R.anim.end_exit); } - //Load elapsed record from db - public void onLoadRecord() { - if (sync_date == null) { - Log.d(TAG, "Load ElpRecord from db"); - //no synchronized information then read all elapsed records from db - newRecord = dbhelper.getElapsedRecord(null); + //Load synchronized date from sharedPrefereces + private void onLoadSyncInfo() { + //load syn_point by sharedpreferences + SharedPreferences sp_date = getSharedPreferences(SYNC_POINT, 0); + sync_point = new String(sp_date.getString(SYNC_POINT, "-1")); + //current date in Record table + StringBuffer _where_reindx = null; + Log.d(TAG, ">> sync_point : " + sync_point); + //saved sync_point existed + if (sync_point.equals("-1") != true) { + Log.d(TAG, "onLoadSyncinfo - synchronized history has existed"); } else { - Log.d(TAG, "Load ElpRecord from db"); - //if there is a history of synchronizing, then read history data - newRecord = null; - history.setHistory(onLoadHistory(ContractDBinfo.TBL_HISTORY_PIE, ContractDBinfo.SQL_SELECT_HISTORY_PIE));//history total setting - history.setHistory(onLoadHistory(ContractDBinfo.TBL_HISTORY_LINE, ContractDBinfo.SQL_SELECT_HISTORY_LINE));//history month setting + Log.d(TAG, "onLoadSyncinfo - no synchronized history is found"); } - //load check - } - //Load synchronized date from sharedPrefereces - private void onLoadSyncDate() { - SharedPreferences sp = getSharedPreferences(SYNC_DATE, 0); - sync_date = sp.getString(SYNC_DATE, ""); - if (sync_date.equals("") == true) { - IsSetSync = false; - Log.d(TAG, "There is no synchronized date."); - } else { - IsSetSync = true; - Log.d(TAG, "Synchronized date : " + sync_date); + //Load history from db + public void onLoadHistory() { + isTotalHist = history.setHistory(LoadHistory(ContractDBinfo.TBL_HISTORY_PIE, ContractDBinfo.SQL_SELECT_HISTORY_PIE));//history total setting + isMonthHist = history.setHistory(LoadHistory(ContractDBinfo.TBL_HISTORY_LINE, ContractDBinfo.SQL_SELECT_HISTORY_LINE));//history month setting + } + //Load elapsed record from db + public void onLoadRecord() { + Log.d(TAG, ">> onLoadRecord"); + //where Query + StringBuffer _where_reindx = new StringBuffer(); + _where_reindx.append(ContractDBinfo.COL_RECID) + .append(">\"") + .append(sync_point) + .append("\""); + //find record from record_table + newRecord = dbhelper.getElapsedRecord(_where_reindx.toString(), true); + //Todo : delete + if (newRecord != null) { + Iterator it = newRecord.iterator(); + System.out.println(">> newRecord size is " + newRecord.size()); + /* + while (it.hasNext()) { + ElapsedRecord _elp = it.next(); + _elp.getBaseBook().getBook(); + } + */ } + //update history by updated record + boolean isUpdate = history.onUpdateByrecord(newRecord); + //update sync date + onUpdateSyncDate(isUpdate); } - public History onLoadHistory(String _table, String _query) { + private History LoadHistory(String _table, String _query) { Cursor cursor = dbhelper.selectFromTable(_table, _query); if (cursor != null && cursor.moveToFirst()) { Log.d(TAG, "onLoadHistory - " + _table + " table is loading now..."); if (_table.equals(ContractDBinfo.TBL_HISTORY_PIE)) { //set DataTotal int[] _contents = new int[4]; - for (int i=0; i<4; ++i) { + for (int i = 0; i < 4; ++i) { _contents[i] = cursor.getInt(i); } return new History(new DataTotal(_contents), null); - } else if (_table.equals(ContractDBinfo.TBL_HISTORY_LINE)){ - ArrayList < Month> _month = new ArrayList(); + } else if (_table.equals(ContractDBinfo.TBL_HISTORY_LINE)) { + ArrayList _month = new ArrayList(); while (cursor.moveToNext()) { //set DataMonth String _name = new String(cursor.getString(0)); @@ -134,19 +156,67 @@ public void onResume() { Log.d(TAG, "onSume"); } */ - private void onUpdateSyncDate() { - //if (IsSyncRequest == true) { - SharedPreferences spf = getSharedPreferences(SYNC_DATE, 0); - SharedPreferences.Editor editor = spf.edit(); - String _sync_date = getTime(); - editor.putString(SYNC_DATE, _sync_date); - editor.commit(); - //} + @Override + public void onStop() { + super.onStop(); + Log.d(TAG, "on Stop"); + onClearSyncDate(); + } + //Save Synchronized data for HistoryActivity + private void onUpdateSyncDate(boolean _isupdate) { + Log.d(TAG, ">> onUpdateSyncDate - switch on: " + _isupdate); + SharedPreferences spf = getSharedPreferences(SYNC_POINT, 0); + SharedPreferences.Editor editor = spf.edit(); + //if the update of history was completed successfully + if (_isupdate != false) { + //Todo : check that newrecord has to be sorted + int sz = newRecord.size(); + String _curStr_rid = newRecord.get(sz - 1).getRecordId(); + Log.i(TAG, " synchronized point will be updated"); + sync_point = _curStr_rid; + } else { + //syn_point is unvalid or the number of record is lack than sync_point + if (dbhelper.getNumOfrecord() <= Integer.parseInt(sync_point) + 1) { + Log.w(TAG, " synchronized point will be reset because the size of recordTable is lower than sync_point"); + sync_point = "-1"; + } else { + Log.i(TAG, " it is currently up-to-date"); + } + } + editor.putString(SYNC_POINT, sync_point); + editor.commit(); } + private void onClearSyncDate() { + SharedPreferences pref = getSharedPreferences(SYNC_POINT, 0); + SharedPreferences.Editor editor = pref.edit(); + editor.clear(); + editor.commit(); + } + //Todo : 레코드 데이터를 히스토리로 전환하는 것을 완료 + //이제 히스토리를 디비에 저장하는 과정을 살펴봐야함 + //ContractDBinfo에 함수 살펴볼것 + private void onUpdateHistory(boolean _isupdate) { + if (isTotalHist != true) { + //insert + dbhelper.insertHistory(history, ContractDBinfo.TBL_HISTORY_PIE); + } else { + //update + dbhelper.updateHistory(history, ContractDBinfo.COL_DATE, sync_point, ContractDBinfo.TBL_HISTORY_PIE); + } + if (isMonthHist != true) { + //insert + dbhelper.insertHistory(history, ContractDBinfo.TBL_HISTORY_LINE); + } else { + //update + dbhelper.updateHistory(history, ContractDBinfo.COL_MONTH, null, ContractDBinfo.TBL_HISTORY_LINE); + } + } + /* private String getTime() {//YYYY:MM:DD long now = System.currentTimeMillis(); Date date = new Date(now); String ydmTime = sdf.format(date); return ydmTime; } + */ } \ No newline at end of file diff --git a/pooni/app/src/main/java/com/uki121/pooni/HistoryAdapter.java b/pooni/app/src/main/java/com/uki121/pooni/HistoryAdapter.java index b69c702..e74ac4b 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/HistoryAdapter.java +++ b/pooni/app/src/main/java/com/uki121/pooni/HistoryAdapter.java @@ -15,47 +15,46 @@ public class HistoryAdapter extends FragmentPagerAdapter { //var private static final String TAG = "HistoryAdapter"; private final int FRAG_NUM = 2; - private ArrayList< ElapsedRecord> curElp; private History history; - + //private ArrayList < ElapsedRecord> curElp; + /* public HistoryAdapter(FragmentManager fragmentmanager, ArrayList < ElapsedRecord> _elp) { super(fragmentmanager); + Log.d(TAG, "constructor(1) is active"); if (_elp != null) { Log.d(TAG, "constructor(1)_Elp is valid"); - curElp = new ArrayList(_elp); + //curElp = new ArrayList(_elp); history = new History(_elp); } else { Log.d(TAG, "constructor(1)_Elp is empty"); - curElp = null; + //curElp = null; history = null; } - }; + } + */ public HistoryAdapter(FragmentManager fragmentmanager, History _history) { super(fragmentmanager); if (_history != null) { - Log.d(TAG, "constructor(2)_History is set"); + Log.d(TAG, "constructor - History is set"); history = new History(_history); - curElp = null; } else { - Log.d(TAG, "constructor(2)_History is empty"); + Log.w(TAG, "constructor - History is empty"); history = null; - curElp = null; } - }; + } @Override public Fragment getItem(int position) { switch(position) { case 0: - Log.d(TAG, "TotalHistory"); - //Todo : if condition - if (history !=null && history.IsTotalHistory() == true) { + Log.d(TAG, " ## start : TotalHistory"); + if (history !=null) { return FragmentTotalHistory.newInstance(history.getHistoryToTal().ToString()); } else { return FragmentTotalHistory.newInstance(null); } case 1: - Log.d(TAG, "MonthHistory"); - if (history !=null && history.IsMonthHistory() == true) { + Log.d(TAG, " ## start : MonthHistory"); + if (history !=null) { return FragmentMonthHistory.newInstance(history.getHistoryMonth().ToString()); } else { return FragmentMonthHistory.newInstance(null); diff --git a/pooni/app/src/main/java/com/uki121/pooni/HomeActivity.java b/pooni/app/src/main/java/com/uki121/pooni/HomeActivity.java index 684250c..d47d549 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/HomeActivity.java +++ b/pooni/app/src/main/java/com/uki121/pooni/HomeActivity.java @@ -4,6 +4,7 @@ import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.content.ContentValues; import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; @@ -30,6 +31,9 @@ import com.google.gson.GsonBuilder; +import java.text.SimpleDateFormat; +import java.util.Date; + import cn.pedant.SweetAlert.SweetAlertDialog; /** @@ -37,7 +41,11 @@ */ public class HomeActivity extends AppCompatActivity implements onUpdateStateListener { + //def + private final String TAG = "HomeActivity"; + private final String DEFAULT_TITLE = "default_book"; private final long FINISH_INTERVAL_TIME = 2000; + //var private long backPressedTime = 0; private onKeyBackPressedListener mOnKeyBackPressedListener; private bookShelf bookshelf; @@ -45,7 +53,7 @@ public class HomeActivity extends AppCompatActivity implements onUpdateStateList //SharedPreferences private final String sharedCurBook = "shared_cur_book"; private final String sharedKey = "cur_book_info"; - private Book curbook; + //var private boolean IsSharedPref = false; //Bundle private static String strCurBook; @@ -62,27 +70,16 @@ public void init() { bookshelf = new bookShelf(); dbhelper = new bookDBHelper(HomeActivity.this); - LoadBookShelf();//Load books' info from database + onLoadBookShelf();//Load books' info from database onSearchInnerData();//Load a basic book setting user sets in the sharedPreferences before //Inflate HomeFragment try { - if (IsSharedPref = true) { - //convert book to gson - Gson gson = new GsonBuilder().create(); - strCurBook = gson.toJson(curbook, Book.class); - } else { - strCurBook = null; - } //Create fragment String tag = "frag_home"; FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); - if (curbook != null) { - fragmentTransaction.add(R.id.frag_home_container, FragmentHomeMenu.newInstance(strCurBook), tag);} - else { //No data in the book shelf - fragmentTransaction.add(R.id.frag_home_container, new FragmentHomeMenu(), tag);} + fragmentTransaction.add(R.id.frag_home_container, FragmentHomeMenu.newInstance(strCurBook), tag); fragmentTransaction.commit(); - } catch(Exception e) { Log.e("HOME_ERROR", e.getMessage()); } @@ -95,34 +92,37 @@ protected void onStop() { } protected void onSaveInnerData() { try { - if (curbook != null) { - Log.i("Save new shardPrefernces","Excuted"); - Gson gson = new GsonBuilder().create(); - String strCurBook = gson.toJson(curbook, Book.class); - + if (strCurBook != null) { + Log.i(TAG, "Save new shardPrefernces - strCurbook is saved"); SharedPreferences sp = getSharedPreferences(sharedCurBook, 0); SharedPreferences.Editor editor = sp.edit(); editor.putString(sharedKey, strCurBook); editor.commit(); - } else { Log.w("Save shardPrefernces", "ignored");} + } else { Log.w(TAG,"Save shardPrefernces - no strCurbook is found");} } catch (Exception e) { Log.e("Search_sharedPrefernces",e.getMessage()); } } + //Load a default book from SharedPreferences protected void onSearchInnerData() { try { SharedPreferences sp = getSharedPreferences(sharedCurBook, 0); String strCurBook = sp.getString(sharedKey, ""); - //conversion - if (strCurBook.equals("") == false) { - Log.i("SharedPreferences", "Inner Found."); + //Load a initial setting of Book from SharedPreferences + if (strCurBook.equals("") != false) { //found + Log.i(TAG, "SharedPreferences - Inner Found."); System.out.println(">> strCurBook :" + strCurBook); - Gson gson = new Gson(); - curbook = gson.fromJson(strCurBook, Book.class); IsSharedPref = true; - } else { + } else {//not found Log.i("SharedPreferences", "default is applied."); - curbook = bookshelf.getBook(0); + //set a default book from bookshelf + Book _defaultbook = bookshelf.getBook(0); + if (_defaultbook != null) { + Gson gson = new GsonBuilder().create(); + strCurBook = new String(gson.toJson(_defaultbook, Book.class)); + } else { + strCurBook = null; + } } } catch (Exception e) { Log.e("Search_sharedPrefernces",e.getMessage()); @@ -157,7 +157,7 @@ public void onBackPressed() { } } //Load book data from Database - public void LoadBookShelf() { + public void onLoadBookShelf() { System.out.println("###################### Start ######################"); System.out.println(" Load Book DB"); SQLiteDatabase db = dbhelper.getReadableDatabase(); @@ -190,7 +190,6 @@ public void LoadBookShelf() { System.out.println("###################### Ends ######################"); } } - public void loadBookUser() { } @@ -198,35 +197,43 @@ public void loadBookUser() { @Override public boolean onUpdateRecord(String _strUserRec, boolean _IsNewBook) { //Convert json format into ElapsedRecord class + Log.d(TAG, " ##### onUpdateRecord start #####"); + Log.d(TAG, " strUserRec : " + _strUserRec); + //restore class from strUserRec Gson gsonUser = new Gson(); - ElapsedRecord elp = gsonUser.fromJson(_strUserRec, ElapsedRecord.class); - ///If book is set - if (elp.IsBookSet() == true) { - int bid = -1; - Book _target = new Book(elp.getBaseBook()); - try { - //Update Book info or insert new book - if (_IsNewBook == false) { - //case1.update book - Log.i("Current Book", "Insert unnecessary,instead update its attributes"); - bid = dbhelper.updateData(ContractDBinfo.COL_NOACC, _target.getNumAcc() + 1, ContractDBinfo.TBL_BOOK);//There is a only change for the number of access now - } else { - //case2.new book is added - Log.i("Current Book", "New book is inserted sucessfully"); - bid = (int) dbhelper.insertData(elp, ContractDBinfo.TBL_BOOK); - } - elp.setBookId(String.valueOf(bid)); - //Save Record - dbhelper.insertData(elp, ContractDBinfo.TBL_RECORD); - return true; - } catch (Exception e) { - Log.e("UpdateDB on HomeActivity", e.getMessage()); + ElapsedRecord _elp = gsonUser.fromJson(_strUserRec, ElapsedRecord.class); + //set book from elp + int bid = -1; + Book _target = new Book(_elp.getBaseBook()); + String _title = _target.getTitle(); + if (_title != null) { + Log.d(TAG, " book title : " + _title); + Log.d(TAG, " book valid : " + _elp.IsBookSet()); + //exception Todo : delete + if (_title.equals(DEFAULT_TITLE) != true & _elp.IsBookSet() == false) { + Log.e(TAG, "fatal error is occured!!!"); + return false; + } + //target have been already existed in table_book + if (dbhelper.getBookId(_title) != -1) { + Log.i("Current Book", "Insert unnecessary, instead update its attributes"); + ContentValues _updatedata = new ContentValues(); + _updatedata.put(ContractDBinfo.COL_NOACC, _target.getNumAcc() + 1); + bid = dbhelper.updateBook(ContractDBinfo.COL_TITLE, _updatedata, _target.getTitle()); + } else { //new book is added + Log.i(TAG,"Book is inserted sucessfully"); + bid = (int) dbhelper.insertData(_elp, ContractDBinfo.TBL_BOOK); } + _elp.setBookId(String.valueOf(bid)); + //Save Record + _elp.getInfo(); + dbhelper.insertData(_elp, ContractDBinfo.TBL_RECORD); + Log.d(TAG, "#### onUpdateRecrod end ####"); + return true; } else { - //No Book is setting then only record data - Log.w("Update_Book","No Book is founded"); - return false; + Log.w(TAG, "updateRecord - fail due to a fact that no book is set"); } + Log.d(TAG, "#### onUpdateRecrod end ####"); return false; }; public void reset() { diff --git a/pooni/app/src/main/java/com/uki121/pooni/Month.java b/pooni/app/src/main/java/com/uki121/pooni/Month.java index 91d4f07..b588c74 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/Month.java +++ b/pooni/app/src/main/java/com/uki121/pooni/Month.java @@ -10,16 +10,19 @@ public class Month { //def private final String TAG = "Month"; + private final int TOKEN_MONTH = 2; //var private String name;//month - private int totalExcess;//total amount of access in this month - private int numOfprob;//total amount of problems solved in this month - private int numOfbook;//total amount of booked solved in this month + private int totalExcess = 0;//total amount of access in this month + private int numOfprob = 0;//total amount of problems solved in this month + private int numOfbook = 0;//total amount of booked solved in this month protected final String[] mMonths = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec"}; //constructort - public Month() {} + public Month(int _pos) { + this.name = new String(mMonths[_pos]); + } public Month(String _name, int[] _val) { this.name = _name; if (_val != null) { @@ -29,31 +32,41 @@ public Month(String _name, int[] _val) { } } public Month(ElapsedRecord _elp) { + //Log.d(TAG, " ## month constructor "); int _pos = _elp.getDate().indexOf("-") + 1; - int _key = Integer.parseInt(_elp.getDate().substring(_pos, _pos + 1)); + //Log.d(TAG, "> elp date : " + _elp.getDate()); + //Log.d(TAG, "> date pos : " + _pos); + //Log.d(TAG, "> substring of date : " + _elp.getDate().substring(_pos, _pos + TOKEN_MONTH)); + int _key = Integer.parseInt(_elp.getDate().substring(_pos, _pos + TOKEN_MONTH)) - 1; + //Log.d(TAG, "> data key : " + _key); this.name = new String(mMonths[_key]); - Iterator it = _elp.getEachAccess().iterator(); + //get each amount of excess from laptme in elp + Iterator < String> it = _elp.getEachExcess().iterator(); while (it.hasNext()) { int _oneExcess = Integer.parseInt(it.next()); + //if excess is positive, it means 'excess' if (_oneExcess> 0) { this.totalExcess += _oneExcess; } } - this.numOfprob += Integer.valueOf(_elp.getEachAccess().size()); - this.numOfbook = 1; + numOfprob += _elp.getNumOfRec(); + Log.d(TAG, " ## num of prob : " + numOfprob); + numOfbook = 1;//ToDo : this is wrong assigning } //set private float setAvg(String _by) { //exception - if (this.numOfbook == 0 || this.numOfprob == 0) { - throw new NullPointerException(); + if (numOfbook <= 0 || numOfprob <= 0) { + Log.w(TAG, name + ", this month has no data"); + return 0; } try { + Log.d(TAG, name + ", this month has data"); switch (_by) { case "prob": - return this.totalExcess / this.numOfprob; + return this.totalExcess / this.numOfprob;//mill by num case "book": - return this.totalExcess / this.numOfbook; + return this.totalExcess / this.numOfbook;//mill by num default: Log.e(TAG, "In setAvg() in error"); break; @@ -61,7 +74,7 @@ private float setAvg(String _by) { } catch(Exception e) { Log.e(TAG, e.getMessage()); } - return -1; + return 0; } public void accumMonth(Month _month) { this.totalExcess += _month.getTotalExcess(); @@ -70,9 +83,15 @@ public void accumMonth(Month _month) { } //get public String getName() { return this.name;} - public int getTotalExcess() { return this.totalExcess;} - public int getNumOfprob() { return this.numOfprob;} - public int getNumOfbook() {return this.numOfbook;} + public int getKey() { + for (int i = 0; i < mMonths.length; ++i) { + if (name.equals(mMonths[i])) { return i;} + } + return -1; + } + public int getTotalExcess() { return totalExcess;} + public int getNumOfprob() { return numOfprob;} + public int getNumOfbook() {return numOfbook;} public float getAvgByprob() { return setAvg("prob");} public float getAvgBybook() { return setAvg("book");} diff --git a/pooni/app/src/main/java/com/uki121/pooni/SheetAdapter.java b/pooni/app/src/main/java/com/uki121/pooni/SheetAdapter.java new file mode 100644 index 0000000..be8d86c --- /dev/null +++ b/pooni/app/src/main/java/com/uki121/pooni/SheetAdapter.java @@ -0,0 +1,80 @@ +package com.uki121.pooni; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; + +import java.lang.reflect.Array; +import java.util.ArrayList; + +public class SheetAdapter extends RecyclerView.Adapter { + private ArrayList answerList; + private Context context; + + // Provide a reference to the views for each data item + // Complex data items may need more than one view per item, and + // you provide access to all the views for a data item in a view holder + public static class ViewHolder extends RecyclerView.ViewHolder { + // each data item is just a string in this case + public TextView mTextView; + public RadioGroup rbGroup; + public RadioButton btn1, btn2, btn3, btn4, btn5; + public ViewHolder(TextView view) { + super(view); + mTextView = (TextView)view.findViewById(R.id.ans_number); + rbGroup = (RadioGroup) view.findViewById(R.id.ans_radio_group); + } + } + // Provide a suitable constructor (depends on the kind of dataset) + public SheetAdapter(Context _context, ArrayList _answerList) { + context = _context; + answerList = _answerList; + } + + // Create new views (invoked by the layout manager) + @Override + public SheetAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, + int viewType) { + // create a new view + TextView v = (TextView) LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_answer_sheet, parent, false); + ViewHolder holder = new ViewHolder(v); + return holder; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ViewHolder holder, final int position) { + // - get element from your dataset at this position + // - replace the contents of the view with that element + holder.mTextView.setText(answerList.get(position).getNumber()); + + holder.rbGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + + public void onCheckedChanged(RadioGroup group, int checkedId) { + answerList.get(position).setAnswer(checkedId); + } + }); + holder.mTextView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(String.valueOf(answerList.get(position).getAnswer()))); + context.startActivity(intent); + } + }); + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return this.answerList.size(); + } +} diff --git a/pooni/app/src/main/java/com/uki121/pooni/SheetItem.java b/pooni/app/src/main/java/com/uki121/pooni/SheetItem.java new file mode 100644 index 0000000..d768dde --- /dev/null +++ b/pooni/app/src/main/java/com/uki121/pooni/SheetItem.java @@ -0,0 +1,14 @@ +package com.uki121.pooni; + +public class SheetItem { + public static int number = 1;//what index of this problem is + private int mIndex; + private int mAnswer;//which one is marked + public SheetItem() { + mAnswer = -1; + mIndex = number++; + } + public void setAnswer(int _ans) { mAnswer = _ans;} + public int getNumber() {return number;} + public int getAnswer() { return mAnswer;} +} diff --git a/pooni/app/src/main/java/com/uki121/pooni/bookDBHelper.java b/pooni/app/src/main/java/com/uki121/pooni/bookDBHelper.java index e963ea2..a8539f3 100644 --- a/pooni/app/src/main/java/com/uki121/pooni/bookDBHelper.java +++ b/pooni/app/src/main/java/com/uki121/pooni/bookDBHelper.java @@ -11,7 +11,9 @@ import android.widget.Switch; import android.widget.Toast; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; public class bookDBHelper extends SQLiteOpenHelper { @@ -49,9 +51,9 @@ public void init_table(SQLiteDatabase db) { Log.d(TAG, "###################### Start ######################"); Log.d(TAG, " Initialize Tables"); try { - createTable(ContractDBinfo.TBL_BOOK); - createTable(ContractDBinfo.TBL_RECORD); - createTable(ContractDBinfo.TBL_USER); + createTable(ContractDBinfo.TBL_BOOK, db); + createTable(ContractDBinfo.TBL_RECORD, db); + //createTable(ContractDBinfo.TBL_USER, db); } catch(SQLException e) { Log.d("SQL_onCreate", e.getMessage()); } finally { @@ -59,8 +61,10 @@ public void init_table(SQLiteDatabase db) { } } //create - public void createTable(String _tablename) { - SQLiteDatabase db = getWritableDatabase(); + public void createTable(String _tablename, SQLiteDatabase db) { + if (db == null) { + db = getWritableDatabase(); + } switch(_tablename) { case ContractDBinfo.TBL_BOOK : Log.d(TAG, "create table Book"); @@ -102,7 +106,7 @@ public Cursor selectFromTable(String _tablename, String _query) { return null; } //insert - public long insertData(History history, String _targetTable) { + public long insertHistory(History history, String _targetTable) { Log.d(TAG, "###################### Start ######################"); Log.d(TAG, " Insert into history of db"); ContentValues cv = new ContentValues(); @@ -115,9 +119,19 @@ public long insertData(History history, String _targetTable) { cv.put(ContractDBinfo.COL_CATE2, c[1]); cv.put(ContractDBinfo.COL_CATE3, c[2]); cv.put(ContractDBinfo.COL_CATE4, c[3]); + cv.put(ContractDBinfo.COL_CATE4, c[4]); long newRowid = db.insert(ContractDBinfo.TBL_HISTORY_PIE, null, cv); return newRowid; case ContractDBinfo.TBL_HISTORY_LINE: + Month[] _months = history.getHistoryMonth().getMonth(); + db.beginTransaction(); + for (int i = 0; i < 12; ++i) { + cv.put(ContractDBinfo.COL_MONTH, _months[i].getName()); + cv.put(ContractDBinfo.COL_EXCESS, _months[i].getTotalExcess()); + cv.put(ContractDBinfo.COL_NUM_BOOKS, _months[i].getNumOfbook()); + cv.put(ContractDBinfo.COL_NUM_SOLVED, _months[i].getNumOfprob()); + } + db.setTransactionSuccessful(); break; default: Log.w(TAG, "There is no such table"); @@ -134,7 +148,6 @@ public long insertData(History history, String _targetTable) { public long insertData(ElapsedRecord elp, String _targetTable) { Log.d(TAG, "###################### Start ######################"); Log.d(TAG, " Insert into " + _targetTable); - ContentValues cv = new ContentValues(); SQLiteDatabase db = getWritableDatabase(); try { @@ -150,17 +163,18 @@ public long insertData(ElapsedRecord elp, String _targetTable) { long newRowid = db.insert(ContractDBinfo.TBL_BOOK, null, cv); Log.d(TAG, ">> newRowId :" + newRowid); return newRowid; - } else if (_targetTable.equals(ContractDBinfo.TBL_USER)) { - /* - return getWritableDatabase().insert(ContractDBinfo.TBL_USER, null, cv); - */ } else if (_targetTable.equals(ContractDBinfo.TBL_RECORD)) { cv.put(ContractDBinfo.COL_BOOKID, Integer.parseInt(elp.getBookId())); + cv.put(ContractDBinfo.COL_DATE, new SimpleDateFormat("yyyy-MM-dd").format(new Date())); cv.put(ContractDBinfo.COL_SOVLED, elp.getNumOfRec()); - cv.put(ContractDBinfo.COL_STRACC, elp.getStrExcess()); + cv.put(ContractDBinfo.COL_STRLAP, elp.getStrData("lap")); long newRowid = db.insert(ContractDBinfo.TBL_RECORD, null, cv); Log.d(TAG, ">> newRowId :" + newRowid); return newRowid; + } else if (_targetTable.equals(ContractDBinfo.TBL_USER)) { + /* + return getWritableDatabase().insert(ContractDBinfo.TBL_USER, null, cv); + */ } else { Log.d(TAG, "No such table in Db"); } @@ -213,53 +227,62 @@ public void insertAllDatas(ArrayList bs) { } */ //update - public int updateData(String _attr, String _whereArgs, String _targetTable) { + public int updateBook(String _attr, ContentValues _changes, String _whereArgs) { System.out.println("###################### Start ######################"); System.out.println(" Update into db"); - SQLiteDatabase db = getWritableDatabase(); - ContentValues cv = new ContentValues(); try { - if (_targetTable.equals(ContractDBinfo.TBL_BOOK)) { - switch(_attr) { - case ContractDBinfo.COL_TITLE : - cv.put(ContractDBinfo.COL_TITLE, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_TITLE, new String[]{_whereArgs}); - case ContractDBinfo.COL_TOTIME : - cv.put(ContractDBinfo.COL_TOTIME, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_TITLE, new String[]{_whereArgs}); - case ContractDBinfo.COL_EATIME : - cv.put(ContractDBinfo.COL_EATIME, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_TITLE, new String[]{_whereArgs}); - case ContractDBinfo.COL_RETIME : - cv.put(ContractDBinfo.COL_RETIME, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_TITLE, new String[]{_whereArgs}); - case ContractDBinfo.COL_NOPROB : - cv.put(ContractDBinfo.COL_NOPROB, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_TITLE, new String[]{_whereArgs}); - case ContractDBinfo.COL_NOACC : - cv.put(ContractDBinfo.COL_NOACC, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_TITLE, new String[]{_whereArgs}); - default : - return -1; + String _where = _attr + "=? "; + return db.update(ContractDBinfo.TBL_BOOK, _changes, _where, new String[]{_whereArgs}); + } catch (SQLException e) { + Log.e("SQL_INSERT", e.getMessage()); + } finally { + System.out.println("####################### End #######################"); + } + return -1; + } + //조정중 + //history 상태에 따라서 insert와 update 동작하도록 + public int updateHistory(History _history, String _where, String _whereArgs, String _table) { + System.out.println("###################### Start ######################"); + System.out.println(" Update into db"); + SQLiteDatabase db = getWritableDatabase(); + db.beginTransaction(); + try { + ArrayList < ContentValues> contents = new ArrayList(); + Iterator < ContentValues> it_contents = contents.iterator(); + String where = _where + "=? "; + if (_table.equals(ContractDBinfo.TBL_HISTORY_PIE)) { + int[] data = _history.getHistoryToTal().getData(); + ContentValues changes = new ContentValues(); + changes.put(ContractDBinfo.COL_CATE0, data[0]); + changes.put(ContractDBinfo.COL_CATE0, data[1]); + changes.put(ContractDBinfo.COL_CATE0, data[2]); + changes.put(ContractDBinfo.COL_CATE0, data[3]); + contents.add(changes); + return db.update(_table, it_contents.next(), where, new String[]{_whereArgs}); + } else if (_table.equals(ContractDBinfo.TBL_HISTORY_LINE)) { + int i; + Month[] _linemonths = _history.getHistoryMonth().getMonth(); + //set wherequery + ArrayList < String> whereArgs = new ArrayList(); + //add content from history + for (i = 0; i < 12; ++i) { + ContentValues changes = new ContentValues();//contentvalues + changes.put(ContractDBinfo.COL_MONTH, _linemonths[i].getName()); + changes.put(ContractDBinfo.COL_EXCESS, _linemonths[i].getTotalExcess()); + changes.put(ContractDBinfo.COL_NUM_BOOKS, _linemonths[i].getNumOfbook()); + changes.put(ContractDBinfo.COL_NUM_SOLVED, _linemonths[i].getNumOfprob()); + contents.add(changes); + whereArgs.add(_linemonths[i].getName());//for whereQuery + } + //insert into db + i = 0; + while(it_contents.hasNext()) { + db.update(_table, it_contents.next(), where, new String[]{whereArgs.get(i)}); } - } else if (_targetTable.equals(ContractDBinfo.TBL_USER)) { - switch(_attr) { - case ContractDBinfo.COL_EXECPROB : - cv.put(ContractDBinfo.COL_EXECPROB, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_EXECPROB, new String[]{_whereArgs}); - case ContractDBinfo.COL_SOLVEDPROB : - cv.put(ContractDBinfo.COL_SOLVEDPROB, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_SOLVEDPROB, new String[]{_whereArgs}); - case ContractDBinfo.COL_CORRPROB : - cv.put(ContractDBinfo.COL_CORRPROB, _whereArgs); - return db.update(_targetTable, cv, ContractDBinfo.WHERE_CORRPROB, new String[]{_whereArgs}); - default : - return -1; - }/* - return getWritableDatabase().insert(ContractDBinfo.TBL_USER, null, cv); - */ } + db.setTransactionSuccessful(); } catch (SQLException e) { Log.e("SQL_INSERT", e.getMessage()); } finally { @@ -334,11 +357,14 @@ public int getBookId(String _title) { SQLiteDatabase db = getReadableDatabase(); StringBuffer sql_select_where = new StringBuffer(ContractDBinfo.SQL_SELECT_BOOK); sql_select_where.append(" Where ") - .append("title=") - .append(_title); + .append("title=\"") + .append(_title) + .append("\""); Cursor cursor = db.rawQuery(sql_select_where.toString(), null); - if (cursor.moveToNext()) { - return cursor.getInt(0); + cursor.moveToFirst(); + if (cursor != null & cursor.getCount()> 0) { + Log.d(TAG, "getBookId - found element!!!"); + return cursor.getInt(0); } return -1; } @@ -346,10 +372,12 @@ public Book findBookByid(int _bookid) { SQLiteDatabase db = getReadableDatabase(); StringBuffer sql_find_book = new StringBuffer(ContractDBinfo.SQL_SELECT_BOOK); sql_find_book.append(" where ") - .append("bid=") + .append("id=") .append( _bookid); Cursor cursor = db.rawQuery(sql_find_book.toString(), null); - if (cursor.moveToNext()) { + if (cursor != null & cursor.getCount() != 0) { + Log.d(TAG, "findBookById has valid cursor"); + cursor.moveToFirst(); Book _book = new Book(); _book.setTitle(cursor.getString(1)); _book.setToTime(cursor.getString(2)); @@ -361,26 +389,64 @@ public Book findBookByid(int _bookid) { } return null; } - public ArrayList < ElapsedRecord> getElapsedRecord(StringBuffer _whereQuery) { - SQLiteDatabase db = getReadableDatabase(); - StringBuffer sql_select_record = new StringBuffer(ContractDBinfo.SQL_SELECT_RECORD); - //ToDo : if _whereQuery is null, is it good - if (_whereQuery != null) { sql_select_record.append(_whereQuery.toString());} - Cursor cursor = db.rawQuery(sql_select_record.toString(), null); - int bookIdx = 0; - ArrayList < ElapsedRecord> elplist = new ArrayList< ElapsedRecord>(); - while (cursor.moveToNext()) { - ElapsedRecord elp = new ElapsedRecord(); - bookIdx = cursor.getInt(1); - System.out.println(">> cursor_book : " + bookIdx); - if (bookIdx != -1) { - elp.setBaseBook(findBookByid(bookIdx)); + //load record and set elp class + public ArrayList < ElapsedRecord> getElapsedRecord(String _whereQuery, boolean _switch) { + Log.d(TAG, " #### START : getElapsedRercord #### "); + try { + if (_switch != false) { + //load database + SQLiteDatabase db = getReadableDatabase(); + StringBuffer sql_select_record = new StringBuffer(ContractDBinfo.SQL_SELECT_RECORD); + //set where_query + if (_whereQuery != null) { + sql_select_record.append(" where ") + .append(_whereQuery); + } + //execute cursor(where_query) + Cursor cursor = db.rawQuery(sql_select_record.toString(), null); + //checking exception then + if (cursor != null && cursor.getCount() != 0) { + Log.d(TAG, ">> cursor count : " + cursor.getCount()); + int bookIdx = 0; + ArrayList elplist = new ArrayList(); + cursor.moveToFirst(); + do { + //new item + ElapsedRecord elp = new ElapsedRecord(); + elp.setRecordId(String.valueOf(cursor.getInt(0)));//elp.recid + bookIdx = cursor.getInt(1);//elp.book & bookid + if (bookIdx != -1) { + elp.setBookId(String.valueOf(bookIdx)); + elp.setBaseBook(findBookByid(bookIdx)); + } else { + Log.w(TAG, "an index of book saved in record table is -1"); + throw new SQLException(); + } + elp.setDate(cursor.getString(2));//elp.date + elp.setEachLaptime(cursor.getString(4));//elp.eachLap + // //elp.setExcessFromLap();//elp.eachExcess + elplist.add(elp); + } while (cursor.moveToNext()); + return elplist; + } else { + Log.d(TAG, "> no such data for this whereQuery"); + } } - elp.setEachExcess(cursor.getString(6)); - elplist.add(elp); + } catch (SQLException e_sql) { + Log.d(TAG, e_sql.getMessage()); + } catch (Exception e) { + Log.d(TAG, e.getMessage()); + } finally { + Log.d(TAG, " #### END : getElapsedRercord #### "); } - if (elplist.isEmpty() != false) - return elplist; return null; } + public int getNumOfrecord() { + SQLiteDatabase db = getReadableDatabase(); + Cursor cursor = db.rawQuery(ContractDBinfo.SQL_SELECT_RECORD, null); + if (cursor != null) { + return cursor.getCount(); + } + return -1; + } } diff --git a/pooni/app/src/main/res/layout/fragment_answer_sheet.xml b/pooni/app/src/main/res/layout/fragment_answer_sheet.xml new file mode 100644 index 0000000..284e91f --- /dev/null +++ b/pooni/app/src/main/res/layout/fragment_answer_sheet.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/pooni/app/src/main/res/layout/item_answer_sheet.xml b/pooni/app/src/main/res/layout/item_answer_sheet.xml new file mode 100644 index 0000000..d5b013e --- /dev/null +++ b/pooni/app/src/main/res/layout/item_answer_sheet.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + diff --git a/pooni/build.gradle b/pooni/build.gradle index f76b4f9..8fd7939 100644 --- a/pooni/build.gradle +++ b/pooni/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.android.tools.build:gradle:3.1.2' // NOTE: Do not place your application dependencies here; they belong diff --git a/pooni/pooni b/pooni/pooni new file mode 100644 index 0000000..e69de29

AltStyle によって変換されたページ (->オリジナル) /