从xml中读取时间表
This commit is contained in:
+1
-4
@@ -1,6 +1,3 @@
|
||||
[Dolphin]
|
||||
Timestamp=2017,4,29,15,41,58
|
||||
Timestamp=2017,5,9,10,58,11
|
||||
Version=4
|
||||
|
||||
[Settings]
|
||||
HiddenFilesShown=true
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package wesayallright.timemanager.InnerLayer;
|
||||
|
||||
/**
|
||||
* Created by mj on 17-5-9.
|
||||
* 每个项目的类型, 有课程, 活动, 目标
|
||||
*/
|
||||
|
||||
public enum ItemType {
|
||||
Course, Activity, Target
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class User {
|
||||
public Date enrollDate;
|
||||
|
||||
public GroupList groups;
|
||||
//CalendarList calendar;
|
||||
// CalendarList calendar;
|
||||
|
||||
// 空的构造函数
|
||||
public User() {}
|
||||
|
||||
+1
@@ -20,6 +20,7 @@ class Course {
|
||||
String room;
|
||||
String teacher;
|
||||
public int color;
|
||||
public String id;
|
||||
int priority;//0:normal 1:course 2:alert
|
||||
private static final String TAG = "Course";
|
||||
Course(String week, int day, int starthour, int startmin, int endhour, int endmin, String name, String room, String teacher, int color, int priority) {
|
||||
|
||||
+77
-21
@@ -7,6 +7,7 @@ import android.content.SharedPreferences;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.format.DateFormat;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -30,10 +31,19 @@ import android.view.View;
|
||||
import android.util.Log;
|
||||
import android.os.Build;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import wesayallright.timemanager.InnerLayer.ItemType;
|
||||
import wesayallright.timemanager.InnerLayer.Package;
|
||||
import wesayallright.timemanager.R;
|
||||
|
||||
public class ScheduleFragment extends Fragment {
|
||||
@@ -257,30 +267,76 @@ public class ScheduleFragment extends Fragment {
|
||||
}
|
||||
|
||||
void ReadCourse() {
|
||||
// 这里读入数据
|
||||
Log.i(TAG, "ReadCourse: READ COURSE START!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
course.clear();
|
||||
int num;
|
||||
for (num = 0; ; num++)
|
||||
if (sharedPreferences.getString("week" + num, null) == null)
|
||||
break;
|
||||
Log.i(TAG, "ReadCourse: num:" + num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
course.add(
|
||||
new Course(
|
||||
sharedPreferences.getString("week" + i, null),
|
||||
sharedPreferences.getInt("day" + i, -1),
|
||||
sharedPreferences.getInt("starthour" + i, -1),
|
||||
sharedPreferences.getInt("startmin" + i, -1),
|
||||
sharedPreferences.getInt("endhour" + i, -1),
|
||||
sharedPreferences.getInt("endmin" + i, -1),
|
||||
sharedPreferences.getString("name" + i, null),
|
||||
sharedPreferences.getString("room" + i, null),
|
||||
sharedPreferences.getString("teacher" + i, null),
|
||||
sharedPreferences.getInt("color" + i, -1),
|
||||
sharedPreferences.getInt("priority" + i, -1)
|
||||
)
|
||||
);
|
||||
// int num;
|
||||
// for (num = 0; ; num++)
|
||||
// if (sharedPreferences.getString("week" + num, null) == null)
|
||||
// break;
|
||||
// Log.i(TAG, "ReadCourse: num:" + num);
|
||||
// for (int i = 0; i < num; i++) {
|
||||
// course.add(
|
||||
// new Course(
|
||||
// sharedPreferences.getString("week" + i, null),
|
||||
// sharedPreferences.getInt("day" + i, -1),
|
||||
// sharedPreferences.getInt("starthour" + i, -1),
|
||||
// sharedPreferences.getInt("startmin" + i, -1),
|
||||
// sharedPreferences.getInt("endhour" + i, -1),
|
||||
// sharedPreferences.getInt("endmin" + i, -1),
|
||||
// sharedPreferences.getString("name" + i, null),
|
||||
// sharedPreferences.getString("room" + i, null),
|
||||
// sharedPreferences.getString("teacher" + i, null),
|
||||
// sharedPreferences.getInt("color" + i, -1),
|
||||
// sharedPreferences.getInt("priority" + i, -1)
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
try {
|
||||
|
||||
Element rootElement = Package.calendarXMLTree.getDocumentElement();
|
||||
int schoolWeek = Integer.valueOf(rootElement.getAttribute("schoolWeek"));
|
||||
NodeList items = rootElement.getElementsByTagName("item");
|
||||
for (int i = 0; i < items.getLength(); i++) {
|
||||
Element item = (Element) items.item(i);
|
||||
ItemType type = ItemType.valueOf(item.getAttribute("type"));
|
||||
String id = item.getAttribute("id");
|
||||
String name = item.getAttribute("name");
|
||||
int priority = Integer.valueOf(item.getAttribute("priority"));
|
||||
String detail = item.getAttribute("details");
|
||||
Date firstDate = Package.dateFormatter.parse(item.getAttribute("firstDate"));
|
||||
Date lastDate = Package.dateFormatter.parse(item.getAttribute("lastDate"));
|
||||
//first date and last date are both includes
|
||||
|
||||
if (type == ItemType.Course) {
|
||||
detail = detail.split(":")[1]; // 教师: 小明
|
||||
}
|
||||
NodeList timeList = item.getElementsByTagName("time");
|
||||
for (int j = 0; j < timeList.getLength(); j++) {
|
||||
Element time = (Element) timeList.item(j);
|
||||
course.add(
|
||||
new Course(
|
||||
"sha?", //schoolWeek + j, TODO:星期为啥是String
|
||||
Integer.valueOf(time.getAttribute("day")),
|
||||
Integer.valueOf(time.getAttribute("startTime").split("-")[0]),
|
||||
Integer.valueOf(time.getAttribute("startTime").split("-")[1]),
|
||||
Integer.valueOf(time.getAttribute("endTime").split("-")[0]),
|
||||
Integer.valueOf(time.getAttribute("endTime").split("-")[1]),
|
||||
name,
|
||||
time.getAttribute("place"),
|
||||
detail,
|
||||
0xffffffff,// TODO: color
|
||||
priority
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "解析日期错误");
|
||||
}
|
||||
|
||||
|
||||
Log.i(TAG, "ReadCourse: READ COURSE END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,19 +12,19 @@
|
||||
id="C-NEU-大学生心理与健康教育㈡"
|
||||
name="大学生心理与健康教育㈡"
|
||||
details="教师:小明"
|
||||
priority="true"
|
||||
priority="1"
|
||||
firstDate="2017-2-27"
|
||||
lastDate="2017-4-17"
|
||||
>
|
||||
<time
|
||||
place="建筑A302"
|
||||
day="Monday"
|
||||
day="1"
|
||||
startTime="08-30"
|
||||
endTime="10-30"
|
||||
/>
|
||||
<time
|
||||
place="建筑A309"
|
||||
day="Tuesday"
|
||||
day="2"
|
||||
startTime="08-30"
|
||||
endTime="10-30"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user