赞
踩
实现了教务系统中课程的导入,分类显示课程。学期的修改,增加,修改。课程按照周的显示。课程修改上课星期和上课周。上课课程的自动归类。
一开始因为毕设有关课程表的要求不明,主要就是利用jsoup拉取学校教务管理系统的课程数据进行课程表界面的填充显示,并不能课程的个性化调整。
后来重新调整了需求,参考了超级课程表的功能。重新设计了实体类,利用bmob移动端云作为爬取到的数据的数据服务器进行了重新的开发。
- package com.mangues.coursemanagement.bean;
-
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
-
- import cn.bmob.v3.BmobObject;
-
- public class CourseBean extends BmobObject implements Serializable {
- public static final String TAG = "CourseBean";
-
- private String studentId;
- private String dataYear;
- private String dataTerm;
-
- private String courseName = ""; //课程名
- private String courseRoom = ""; //教室
- private String courseTeacher = ""; //老师
- //private String courseWeekNumber = "0";
- private ArrayList<Integer> courseWeekNumber = new ArrayList<>(); //周数
- private int courseWeek = 0; //星期几上课
- private int courseLow = 0; //第几排
- private int courseSection = 0; //延续几节课
- //private String courseSection = "12"; //第几节上课1,2,12(2节课)
- //private String courseIn = "3"; //单双周 1(单),2(双),3(全)
- public CourseBean() {
- super();
- }
-
- public void setCourseBase(String studentId, String dataYear, String dataTerm) {
- this.studentId = studentId;
- this.dataYear = dataYear;
- this.dataTerm = dataTerm;
- }
-
- public CourseBean(String courseName, String courseRoom, String courseTeacher, ArrayList<Integer> courseWeekNumber, int courseWeek, int courseLow, int courseSection) {
- this.courseName = courseName;
- this.courseRoom = courseRoom;
- this.courseTeacher = courseTeacher;
- this.courseWeekNumber = courseWeekNumber;
- this.courseWeek = courseWeek;
- this.courseLow = courseLow;
- this.courseSection = courseSection;
- }
-
- /**
- * str 数据到bean
- * @Name: stringToBean
- * @param str
- * @return
- * @Time: 2015-12-21 上午11:00:57
- * @Return: CourseBean
- */
- public static CourseBean stringToBean(String str) {
- return toBean(str);
- }
-
- //辅助
- private static CourseBean toBean(String courseDatas){
- CourseBean bean = null;
- String[] courseData = courseDatas.split("◇");
- if(courseData.length>3){ //有数据
- bean = new CourseBean();
- String courseName = courseData[0];
- String courseRoom = courseData[2];
- //获取上课周数
- findWeekNumberFromStr(courseData[1],bean);
- bean.setCourseName(courseName);
- bean.setCourseRoom(courseRoom);
- findCourseInFromStr(courseData[4],bean);
- }
- return bean;
- }
-
- /**
- * 找出上课周数,老师名字
- * @Name: findFromStr
- * @return
- * @Time: 2015-12-21 上午11:22:30
- * @Return: String
- */
- public static void findWeekNumberFromStr(String courseData,CourseBean bean){
- Pattern pattern = Pattern.compile("(\\w*)\\((\\d+)-(\\d+)\\)");
- Matcher matcher = pattern.matcher(courseData);
- if(matcher.find()){
- String teacher = matcher.group(1);
- bean.setCourseTeacher(teacher);
- String weekNumberstart = matcher.group(2);
- String weekNumberfinish = matcher.group(3);
- Integer weekNumberstartInt = Integer.parseInt(weekNumberstart);
- Integer weekNumberfinishInt = Integer.parseInt(weekNumberfinish);
- for (int i = weekNumberstartInt;i<=weekNumberfinishInt;i++){
- bean.getCourseWeekNumber().add(i);
- }
- }
- }
-
-
- /**
- * 找出 上课是不是单双周,几节课
- * @Name: findCourseInFromStr
- * @param courseData
- * @return
- * @Time: 2015-12-21 下午1:29:05
- * @Return: String
- */
- public static void findCourseInFromStr(String courseData,CourseBean bean){
- Pattern pattern = Pattern.compile("(\\w*)\\{(\\d*)节\\}");
- Matcher matcher = pattern.matcher(courseData);
- if(matcher.find()){
- String str = matcher.group(1);
- ArrayList<Integer> list = bean.getCourseWeekNumber();
- switch (str) {
- case "单周":
- for (int i = 0;i< list.size();i++){
- Integer weekNumber = list.get(i);
- if (weekNumber%2==0){ //移除偶数
- bean.getCourseWeekNumber().remove(i);
- }
- }
- break;
- case "双周":
- for (int i = 0;i< list.size();i++){
- Integer weekNumber = list.get(i);
- if (weekNumber%2!=0){ //移除奇数
- bean.getCourseWeekNumber().remove(i);
- }
- }
- break;
- default:
- break;
- }
- String str2 = matcher.group(2);
- String[] args = str2.split("");
- if (args.length==3){
- Integer integer = Integer.parseInt(args[1]);
- Integer integer2 = Integer.parseInt(args[2]);
- bean.setCourseLow(integer);
- bean.setCourseSection(integer2-integer+1);
-
-
- }else if (args.length==4){
- Integer integer = Integer.parseInt(args[1]);
- Integer integer2 = Integer.parseInt(args[2]+args[3]);
- bean.setCourseLow(integer);
- bean.setCourseSection(integer2-integer+1);
-
- }else if (args.length==5){
- Integer integer = Integer.parseInt(args[1]+args[2]);
- Integer integer2 = Integer.parseInt(args[3]+args[4]);
- bean.setCourseLow(integer);
- bean.setCourseSection(integer2-integer+1);
-
- }else if (args.length==2){
- Integer integer = Integer.parseInt(args[1]);
- bean.setCourseLow(integer);
- bean.setCourseSection(1);
- }
-
-
-
-
- }
- }
-
-
-
-
- public String getCourseName() {
- return courseName;
- }
-
- public void setCourseName(String courseName) {
- this.courseName = courseName;
- }
-
- public String getCourseRoom() {
- return courseRoom;
- }
-
- public void setCourseRoom(String courseRoom) {
- this.courseRoom = courseRoom;
- }
-
- public String getCourseTeacher() {
- return courseTeacher;
- }
-
- public void setCourseTeacher(String courseTeacher) {
- this.courseTeacher = courseTeacher;
- }
-
- public ArrayList<Integer> getCourseWeekNumber() {
- return courseWeekNumber;
- }
-
- public void setCourseWeekNumber(ArrayList<Integer> courseWeekNumber) {
- this.courseWeekNumber = courseWeekNumber;
- }
-
- public int getCourseWeek() {
- return courseWeek;
- }
-
- public void setCourseWeek(int courseWeek) {
- this.courseWeek = courseWeek;
- }
-
- public int getCourseLow() {
- return courseLow;
- }
-
- public void setCourseLow(int courseLow) {
- this.courseLow = courseLow;
- }
-
- public int getCourseSection() {
- return courseSection;
- }
-
- public void setCourseSection(int courseSection) {
- this.courseSection = courseSection;
- }
-
- public String getStudentId() {
- return studentId;
- }
-
- public void setStudentId(String studentId) {
- this.studentId = studentId;
- }
-
- public String getDataYear() {
- return dataYear;
- }
-
- public void setDataYear(String dataYear) {
- this.dataYear = dataYear;
- }
-
- public String getDataTerm() {
- return dataTerm;
- }
-
- public void setDataTerm(String dataTerm) {
- this.dataTerm = dataTerm;
- }
- }
-
- //按天查询数据
- private void getDayDate(List<CourseBean> list){
- boolean boo = SaveUtil.getSharedPreferencesSwitch(mContext);
- ArrayList<CourseBean> integerA = new ArrayList<>();
- if (boo){
- if (weekNum!=-1){
- for (int l=0;l<list.size();l++){ //去除
- ArrayList<Integer> integerArrayList = list.get(l).getCourseWeekNumber();
- if (!integerArrayList.contains(weekNum)){ //不包含,就是不是本周,去除
- integerA.add(list.get(l));
- }
- }
- list.removeAll(integerA);
-
-
- }
- }
-
-
-
-
-
- List<CourseBean> list1 = null;
- Map<Integer,List<CourseBean>> map = new HashMap<>();
-
- for (CourseBean be :list) {
-
-
- Integer weekNum = be.getCourseWeek();
- if (map.containsKey(weekNum)){ //有数据
- list1 = map.get(weekNum);
- }else {
- list1 = new ArrayList<>();
- map.put(weekNum,list1);
- }
- list1.add(be);
- }
-
- ArrayList<CourseBeanMap> ls = new ArrayList<>();
-
- //按星期几处理
- for (Map.Entry<Integer,List<CourseBean>> entry : map.entrySet()) {
- List<CourseBeanMap> mapw = handleRepeat(entry.getValue(),entry.getKey());
- ls.addAll(mapw);
-
-
- }
-
- //本地存储存储使用
- TimeTableBmob bmob = new TimeTableBmob();
- bmob.setStudentId(CourseApplication.getInstance().getUserInfo().getStudentId());
- bmob.setCourseList(ls);
- bmob.setTerm(dataTerm);
- bmob.setYear(dataYear);
- CourseApplication.getInstance().setTimeTableBmob(bmob);
-
- dataBack.onDataBack(ls);
- }
-
-
-
-
- //处理重复
- private List<CourseBeanMap> handleRepeat(List<CourseBean> list,Integer weekNum){
-
- Collections.sort(list,new Comparator<CourseBean>(){
- public int compare(CourseBean arg0, CourseBean arg1) {
- Integer year1 = arg0.getCourseLow();
- Integer year2 = arg1.getCourseLow();
- return year1.compareTo(year2);
- }
- });
-
-
-
- List<CourseBeanMap> listKey = new ArrayList<>();
- List<String> liststr = new ArrayList<>();
-
- int size = list.size();
-
- for (int h=0;h<list.size();h++){
- CourseBean bean = list.get(h);
- Integer low = bean.getCourseLow();
- Integer sesson = bean.getCourseSection();
- Boolean isAdd = false;
-
- for (int kk=0;kk<listKey.size();kk++){
-
-
- String key = liststr.get(kk);
- String[] keys = key.split("-");//
- Integer low1 =Integer.parseInt(keys[0]);//3
- Integer sesson1 =Integer.parseInt(keys[1]);//2
-
-
- if ((low1+sesson1-1)>=low){ //包含在内
- isAdd = true;
- CourseBeanMap cousermap = listKey.get(kk);
- cousermap.setCourseLow(low1);
- cousermap.setCourseWeek(weekNum);
- cousermap.setCourseSection(sesson+low-low1);
- liststr.set(kk,low1+"-"+(sesson+low-low1));//修改key值
- cousermap.add(bean);
- }
- }
-
-
- if (isAdd==false){
- CourseBeanMap cousermap = new CourseBeanMap();
- cousermap.setCourseLow(low);
- cousermap.setCourseWeek(weekNum);
- cousermap.setCourseSection(sesson);
- cousermap.add(bean);
- listKey.add(cousermap);
- liststr.add(low+"-"+sesson);
- }
- }
-
-
- return listKey;
- }
利用了网上找到的一段代码进行部分修改完成
- //初始化课程表界面
- private void initTable() {
- // 获得列头的控件
- empty = (TextView) this.findViewById(R.id.test_empty);
- monColum = (TextView) this.findViewById(R.id.test_monday_course);
- tueColum = (TextView) this.findViewById(R.id.test_tuesday_course);
- wedColum = (TextView) this.findViewById(R.id.test_wednesday_course);
- thrusColum = (TextView) this.findViewById(R.id.test_thursday_course);
- friColum = (TextView) this.findViewById(R.id.test_friday_course);
- satColum = (TextView) this.findViewById(R.id.test_saturday_course);
- sunColum = (TextView) this.findViewById(R.id.test_sunday_course);
- course_table_layout = (RelativeLayout) this
- .findViewById(R.id.test_course_rl);
- course_table_layout.removeAllViews(); //清楚页面数据
- DisplayMetrics dm = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(dm);
- // 屏幕宽度
- int width = dm.widthPixels;
- // 平均宽度
- int aveWidth = width / 8;
- // 第一个空白格子设置为25宽
- empty.setWidth(aveWidth * 3 / 4);
- monColum.setWidth(aveWidth * 33 / 32 + 1);
- tueColum.setWidth(aveWidth * 33 / 32 + 1);
- wedColum.setWidth(aveWidth * 33 / 32 + 1);
- thrusColum.setWidth(aveWidth * 33 / 32 + 1);
- friColum.setWidth(aveWidth * 33 / 32 + 1);
- satColum.setWidth(aveWidth * 33 / 32 + 1);
- sunColum.setWidth(aveWidth * 33 / 32 + 1);
- this.screenWidth = width;
- this.aveWidth = aveWidth;
- int height = dm.heightPixels;
- gridHeight = height / 12;
- // 设置课表界面
- // 动态生成12 * maxCourseNum个textview
- for (int i = 1; i <= 12; i++) {
-
- for (int j = 1; j <= 8; j++) {
-
- TextView tx = new TextView(mContext);
- tx.setId((i - 1) * 8 + j);
- // 除了最后一列,都使用course_text_view_bg背景(最后一列没有右边框)
- if (j < 8)
- tx.setBackgroundDrawable(mContext.getResources()
- .getDrawable(R.drawable.course_text_view_bg));
- else
- tx.setBackgroundDrawable(mContext.getResources()
- .getDrawable(R.drawable.course_table_last_colum));
- // 相对布局参数
- RelativeLayout.LayoutParams rp = new RelativeLayout.LayoutParams(
- aveWidth * 33 / 32 + 1, gridHeight);
- // 文字对齐方式
- tx.setGravity(Gravity.CENTER);
- // 字体样式
- tx.setTextAppearance(mContext, R.style.courseTableText);
- // 如果是第一列,需要设置课的序号(1 到 12)
- if (j == 1) {
- tx.setAlpha(0.3f);
- tx.setText(String.valueOf(i));
- rp.width = aveWidth * 3 / 4;
- // 设置他们的相对位置
- if (i == 1)
- rp.addRule(RelativeLayout.BELOW, empty.getId());
- else
- rp.addRule(RelativeLayout.BELOW, (i - 1) * 8);
- } else {
- tx.setAlpha(0f);
- rp.addRule(RelativeLayout.RIGHT_OF, (i - 1) * 8 + j - 1);
- rp.addRule(RelativeLayout.ALIGN_TOP, (i - 1) * 8 + j - 1);
- tx.setText("");
- }
-
- tx.setLayoutParams(rp);
- course_table_layout.addView(tx);
- }
- }
- }
-
- //数据填充
- private void setCourseData(final CourseBeanMap map, final int index) {
- final CourseBean bean = map.returnfirstTrue(weekNum);
-
- // 添加课程信息
- TextView courseInfo = new TextView(mContext);
- courseInfo.setText(bean.getCourseName() + "@" + bean.getCourseRoom());
- // 该textview的高度根据其节数的跨度来设置
- RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
-
- aveWidth * 31 / 32, (gridHeight - 5) * map.getCourseSection());
- // textview的位置由课程开始节数和上课的时间(day of week)确定
- rlp.topMargin = 5 + (map.getCourseLow() - 1) * gridHeight;
- rlp.leftMargin = 1;
- // 偏移由这节课是星期几决定
- rlp.addRule(RelativeLayout.RIGHT_OF, map.getCourseWeek());
- // 字体剧中
- courseInfo.setGravity(Gravity.CENTER);
- // 设置一种背景
- final int back;
- final int huiback;
- if (map.isDoubleBean()) {// 有单双周
- back = ColorDrawable.getCourseBgMulti(map.getCourseLow(),
- map.getCourseWeek());
- huiback = ColorDrawable.grayColorMulti;
- } else {
- back = ColorDrawable.getCourseBg(map.getCourseLow(),
- map.getCourseWeek());
- huiback = ColorDrawable.grayColor;
- }
- if (map.returntTrue(weekNum)){
- courseInfo.setBackgroundResource(back);
- }else {
- courseInfo.setBackgroundResource(huiback);
- }
-
-
- courseInfo.setTextSize(12);
- courseInfo.setLayoutParams(rlp);
- courseInfo.setTextColor(Color.WHITE);
- // 设置不透明度
- courseInfo.getBackground().setAlpha(222);
- final int upperCourseIndex = 0;
- // 设置监听事件
- courseInfo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- if (map.isDoubleBean()) {// 大于双数
- // 如果有多个课程,则设置点击弹出gallery 3d 对话框
- // LayoutInflater layoutInflater =
- // (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View galleryView = layoutInflater.inflate(
- R.layout.course_info_gallery_layout, null);
- final Dialog coursePopupDialog = new AlertDialog.Builder(
- mContext).create();
- coursePopupDialog.setCanceledOnTouchOutside(true);
- coursePopupDialog.setCancelable(true);
- coursePopupDialog.show();
- WindowManager.LayoutParams params = coursePopupDialog
- .getWindow().getAttributes();
- params.width = WindowManager.LayoutParams.FILL_PARENT;
- coursePopupDialog.getWindow().setAttributes(params);
-
- DisplayMetrics dm = new DisplayMetrics();
- getWindowManager().getDefaultDisplay()
- .getMetrics(dm);
- // 屏幕宽度
- int width = dm.widthPixels;
-
- CourseInfoAdapter adapter = new CourseInfoAdapter(mContext,
- map, width, back,weekNum);
- CourseInfoGallery gallery = (CourseInfoGallery) galleryView
- .findViewById(R.id.course_info_gallery);
- gallery.setSpacing(10);
- gallery.setAdapter(adapter);
- gallery.setSelection(upperCourseIndex);
- gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1,
- int arg2, long arg3) {
- CourseBean bean = map.get(arg2);
- Intent intent = new Intent(mContext,CourseInfoActivity.class);
- Bundle mBundle = new Bundle();
- mBundle.putSerializable(CourseBean.TAG, bean);
- mBundle.putInt("index", index);
- mBundle.putInt("courseBeanIndex", arg2);
- intent.putExtras(mBundle);
- startActivity(intent);
- coursePopupDialog.cancel();
- }
- });
- coursePopupDialog.setContentView(galleryView);
- }else { //没有单双周
- Intent intent = new Intent(mContext,CourseInfoActivity.class);
- Bundle mBundle = new Bundle();
- mBundle.putInt("index", index);
- mBundle.putInt("courseBeanIndex", 0);
- mBundle.putSerializable(CourseBean.TAG, bean);
- intent.putExtras(mBundle);
- startActivity(intent);
- }
- }
-
- });
- course_table_layout.addView(courseInfo);
- }
一个DEMO下载地址:http://download.csdn.net/download/qq_24531461/9831957
另一个DEMO下载地址:http://download.csdn.net/download/qq_24531461/9832004
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。