Android课程表的设计开发
下载链接
鉴于很多人需要源码,这里给下代码。
下载地址(需要5积分,支持下(积累点积分。。。),没有积分的直接留言邮箱,我发给你或者找其他已经发过的人要下)
没积分的直接用百度云下载把,积分多的可以支持下,谢谢
链接: https://pan.baidu.com/s/1dFCdoFR 密码: pbsn
说明:
本来想早点就弄出来的,最近一段时间太忙,好久没有更新博客了。忘记发了。刚刚看博客才发现这么多人要。发你们的版本,把教师端的和一些和课程表无关的功能代码都删了。毕竟这毕设也是给学校用的。还有这个服务端是依赖bmob服务器的(不知道什么原因里面的原始数据被bmob删了,备份复原也复原不了,找了客服没人理。。。。),目前是没有数据的,所有功能都是依赖bmob和 学校的教务系统(因为已经原来的账户没法登录了,也没法爬取数据了。。。。),所以可以跑起来,没有数据是登录不进去的,也看不到效果,你们可以根据数据格式 造假数据。
代码包含:网络爬虫,你们可以修改下,爬取自己学校教务系统的数据。申请个bmob的账户配置好,就可以执行接下来的步骤了。
不过这样比较麻烦,代码都在里面,你们看源码就行了,也不复杂。还有代码是我16年毕业时候的毕业设计,初写android没多久。写的有点烂,代码架构不合理(根本没有架构),凑合的看就行了。
导语
实现了教务系统中课程的导入,分类显示课程。学期的修改,增加,修改。课程按照周的显示。课程修改上课星期和上课周。上课课程的自动归类。
一、主要功能界面
开发过程
一开始因为毕设有关课程表的要求不明,主要就是利用jsoup拉取学校教务管理系统的课程数据进行课程表界面的填充显示,并不能课程的个性化调整。
后来重新调整了需求,参考了超级课程表的功能。重新设计了实体类,利用bmob移动端云作为爬取到的数据的数据服务器进行了重新的开发。
主要代码
1、课程实体类
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;}
}
2、课程归类处理
//按天查询数据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]);//3Integer sesson1 =Integer.parseInt(keys[1]);//2if ((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;}
3.课程表界面
利用了网上找到的一段代码进行部分修改完成
//初始化课程表界面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个textviewfor (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));elsetx.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());elserp.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() {@Overridepublic 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() {@Overridepublic 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);}