import com.td.utility.DateUtil;\r
\r
public class MonitorTimeActivity extends Activity {\r
- private static int N = 7;// TODO\r
- private CheckBox[] checkBoxes = new CheckBox[N];\r
+ private CheckBox[] checkBoxes = new CheckBox[DateUtil.WEEK];\r
\r
private MonitorDao dao;\r
private List<Monitor> list = new ArrayList<Monitor>();\r
cancelButton = (Button) findViewById(R.id.button65);\r
closeButton = (Button) findViewById(R.id.button66);\r
CheckBox checkBox;\r
- for (int i = 0; i < N; i++) {\r
+ for (int i = 0; i < DateUtil.WEEK; i++) {\r
switch (i) {\r
case 0:\r
checkBox = (CheckBox) findViewById(R.id.checkBox61);\r
scrollView.setEnabled(enabled);\r
timePicker1.setEnabled(enabled);\r
timePicker2.setEnabled(enabled);\r
- for (int i = 0; i < N; i++) {\r
+ for (int i = 0; i < DateUtil.WEEK; i++) {\r
checkBoxes[i].setEnabled(enabled);\r
}\r
}\r
timePicker1.setCurrentMinute(from % 100);\r
timePicker2.setCurrentHour(to / 100);\r
timePicker2.setCurrentMinute(to % 100);\r
- for (int i = 0; i < N; i++) {\r
+ for (int i = 0; i < DateUtil.WEEK; i++) {\r
checkBoxes[i].setChecked(monitor.getWeek(i));\r
}\r
}\r
int hm2 = DateUtil.getHm(h2, m2);\r
\r
Monitor monitor = new Monitor(id, hm1, hm2);\r
- for (int i = 0; i < N; i++){\r
+ for (int i = 0; i < DateUtil.WEEK; i++){\r
monitor.setWeek(i, checkBoxes[i].isChecked());\r
}\r
return monitor;\r
this.from = from;\r
this.to = to;\r
\r
- week = new boolean[7]; //TODO\r
+ week = new boolean[DateUtil.WEEK];\r
for (int i = 0; i < week.length; i++){\r
week[i] = false;\r
}\r
import android.database.sqlite.SQLiteDatabase;\r
import android.database.sqlite.SQLiteStatement;\r
\r
+import com.td.utility.DateUtil;\r
import com.td.utility.Debug;\r
import com.td.utility.Util;\r
\r
cursor.getInt(0),\r
cursor.getInt(8),\r
cursor.getInt(9));\r
- for (int j = 0; j < 7; j++) { // TODO\r
+ for (int j = 0; j < DateUtil.WEEK; j++) {\r
monitor.setWeek(j, Util.toBoolean(cursor.getInt(j + 1)));\r
}\r
list.add(monitor);\r
import com.td.utility.DateUtil;\r
\r
public class Scheduler {\r
- private int N = 7;//TODO\r
private static Calendar cal = Calendar.getInstance();\r
private List<Term>[] list = null;\r
private Comparator<Term> comp = new Comparator<Term>(){\r
int hm = DateUtil.getHm(h, m);\r
int w = date.getDay();\r
\r
- for (int i = 0; i < N; i++){\r
- int n = (w + i) % N;\r
+ for (int i = 0; i < DateUtil.WEEK + 1; i++){\r
+ int n = (w + i) % DateUtil.WEEK;\r
List<Term> l = list[n];\r
int j = isContain(l, hm);\r
if (j == 0){\r
}\r
\r
public void clearSchedule(){\r
- list = new List[N];\r
+ list = new List[DateUtil.WEEK];\r
for (int i = 0; i < list.length; i++){\r
list[i] = new ArrayList<Term>();\r
}\r
\r
public void add(List<Term>[] ll, Monitor monitor){\r
Term term = new Term(monitor.getFrom(), monitor.getTo());\r
- for (int i = 0; i < N; i++){\r
+ for (int i = 0; i < DateUtil.WEEK; i++){\r
if (monitor.getWeek(i)){\r
add(ll[i], term);\r
}\r
\r
import java.util.ArrayList;\r
import java.util.Calendar;\r
+import java.util.Date;\r
import java.util.List;\r
\r
import com.td.db.Monitor;\r
import com.td.utility.Debug;\r
\r
public class SchedulerTest {\r
- private static int N = 7;// TODO\r
-\r
public static void main() {\r
SchedulerTest obj = new SchedulerTest();\r
\r
int mi2 = -1;\r
\r
\r
- for (int i = 0; i < 3; i++){\r
+ for (int i = 0; i < 5; i++){\r
sc = new Scheduler();\r
+ Debug.d(sc, "case " + i);\r
+ \r
+ sc.clearSchedule();\r
list = sc.getList();\r
\r
switch (i){\r
mi = 0;\r
cal1 = DateUtil.getCalendar(y, m, d, h, mi);\r
now = cal1.getTimeInMillis();\r
- \r
+\r
n1 = DateUtil.getWeek(cal1);\r
l = list[n1];\r
t = new Term(DateUtil.getHm(10, 0), DateUtil.getHm(10, 5));\r
t = new Term(DateUtil.getHm(23, 0), DateUtil.getHm(24, 0));\r
l.add(t);\r
break;\r
+ case 3:\r
+ // \97j\93ú\82ð\82Ü\82½\82¢\82Å\81A\8e\9f\82ÌTerm\81B\8e\9f\82Ì\94N\r
+ y = 2011;\r
+ m = 12;\r
+ d = 31;\r
+ h = 23;\r
+ mi = 30;\r
+ cal1 = DateUtil.getCalendar(y, m, d, h, mi);\r
+ now = cal1.getTimeInMillis();\r
+ \r
+ n1 = DateUtil.getWeek(cal1);\r
+ n1 = (n1 + 1) % DateUtil.WEEK;\r
+ l = list[n1];\r
+ t = new Term(DateUtil.getHm(1, 23), DateUtil.getHm(23, 35));\r
+ l.add(t);\r
+ break;\r
+ case 4:\r
+ // \93ú\82ð\82Ü\82½\82¢\82Å\8e\9f\82ÌTerm\82ª\91¶\8dÝ\82·\82é\r
+ y = 2011;\r
+ m = 1;\r
+ d = 1;\r
+ h = 23;\r
+ mi = 59;\r
+ cal1 = DateUtil.getCalendar(y, m, d, h, mi);\r
+ now = cal1.getTimeInMillis();\r
+ \r
+ n1 = DateUtil.getWeek(cal1);\r
+ n1 = (n1 + 1) % DateUtil.WEEK;\r
+ l = list[n1];\r
+ t = new Term(DateUtil.getHm(0, 0), DateUtil.getHm(23, 59));\r
+ l.add(t);\r
+ break;\r
}\r
\r
next = sc.nextSchedule(now);\r
+ if (next < 0){\r
+ throw new TestException();\r
+ }\r
cal2 = Calendar.getInstance();\r
cal2.setTimeInMillis(next);\r
y2 = DateUtil.getYear(cal2);\r
\r
switch (i){\r
case 0:\r
- ;\r
+ mi += DateUtil.LEN;\r
break;\r
case 1:\r
- mi2 = 0;\r
+ d += DateUtil.WEEK;\r
+ mi = 0;\r
break;\r
case 2:\r
- h2 = 23;\r
- mi2 = 0;\r
+ h = 23;\r
+ mi = 0;\r
+ break;\r
+ case 3:\r
+ y = 2012;\r
+ m = 1;\r
+ d = 1;\r
+ h = 1;\r
+ mi = 23;\r
+ break;\r
+ case 4:\r
+ y = 2011;\r
+ m = 1;\r
+ d = 2;\r
+ h = 0;\r
+ mi = 9;\r
break;\r
}\r
\r
import java.util.Date;\r
\r
public class DateUtil {\r
+ public static final int WEEK = 7;\r
public static final int HM_MIN = 0;\r
public static final int HM_MAX = 9999;\r
public static final int LEN = 10;\r
// TODO test\r
public static Calendar getCalendar(int y, int m, int d, int h, int mi){\r
Calendar cal = Calendar.getInstance();\r
- cal.set(y - 1900, m - 1, d, h, mi);\r
+ //cal.set(y - 1900, m - 1, d, h, mi);\r
+ cal.set(y, m - 1, d, h, mi);\r
return cal;\r
}\r
\r
\r
// TODO test\r
public static int getWeek(Calendar cal){\r
- return cal.get(Calendar.DAY_OF_WEEK);\r
+ return cal.get(Calendar.DAY_OF_WEEK) - 1;\r
}\r
\r
// TODO test\r
public static int getYear(Calendar cal){\r
- return cal.get(Calendar.YEAR) + 1900;\r
+ // TODO\r
+ //return cal.get(Calendar.YEAR) + 1900;\r
+ return cal.get(Calendar.YEAR);\r
}\r
\r
// TODO test\r
\r
// TODO test\r
public static int getDay(Calendar cal){\r
- return cal.get(Calendar.HOUR_OF_DAY);\r
+ return cal.get(Calendar.DAY_OF_MONTH);\r
}\r
\r
// TODO test\r
public static int getHour(Calendar cal){\r
- return cal.get(Calendar.HOUR);\r
+ return cal.get(Calendar.HOUR_OF_DAY);\r
}\r
\r
// TODO test\r