我的Sprint2冲刺——日历表的事件处理和管理(刘铸辉,刘静)
我的Sprint2冲刺计划领到的任务是和静姐结对编程,完成日历表的事件处理和管理,下面详细讲解下技术细节。
1.设计结构图
首先要画出整个UI设计图,方便理解这个日历布局和日历样式的绘制。
这里总共分解为两个 View 文件:
1:calender_main.xml(Calender.java用来绘制日历表和日历表中的事件)
作为启动的主画面,新建项目时,首先生成。
schedule_toptext:用来显示年月日,闰几月,年份和干支
flipper:因为要实现左右滑屏,这里采用的方案是使用 ViewFlipper。我们设计的目标是显示公历 1901 - 2100 年区间的月历,相应的帧画面有 (2100 - 1900) * 12 幅帧画面,如果多创建出来,将占用非常大的内存资源。将由 ViewFlipper 来管理,由它决定某一帧何时创建,何时销毁,以节约内存资源。
2:calender_main.xml(代码在CalenderView.java中)
tvtext:日历gridview中的每一个item显示的textview
2.开始制作 Activity 画面
1.首先绘制整个日历的框架
这里有android指定的类,相关资源都从这里获取http://developer.android.com/guide/topics/providers/calendar-provider.html#intents
1 public CalendarView(){ 2 Date date = new Date(); 3 sysDate = sdf.format(date); //当期日期 4 sys_year = sysDate.split("-")[0]; 5 sys_month = sysDate.split("-")[1]; 6 sys_day = sysDate.split("-")[2]; 7 8 } 9 10 public CalendarView(Context context,Resources rs,int jumpMonth,int jumpYear,int year_c,int month_c,int day_c){ 11 this(); 12 this.context= context; 13 specialCalendar = new SpecialCalendar(); 14 lunarCalendar = new LunarCalendar(); 15 this.res = rs; 16 17 int stepYear = year_c+jumpYear; 18 int stepMonth = month_c+jumpMonth ; 19 if(stepMonth > 0){ 20 //往下一个月滑动 21 if(stepMonth%12 == 0){ 22 stepYear = year_c + stepMonth/12 -1; 23 stepMonth = 12; 24 }else{ 25 stepYear = year_c + stepMonth/12; 26 stepMonth = stepMonth%12; 27 } 28 }else{ 29 //往上一个月滑动 30 stepYear = year_c - 1 + stepMonth/12; 31 stepMonth = stepMonth%12 + 12; 32 if(stepMonth%12 == 0){ 33 34 } 35 } 36 37 currentYear = String.valueOf(stepYear);; //得到当前的年份 38 currentMonth = String.valueOf(stepMonth); //得到本月 (jumpMonth为滑动的次数,每滑动一次就增加一月或减一月) 39 currentDay = String.valueOf(day_c); //得到当前日期是哪天 40 41 getCalendar(Integer.parseInt(currentYear),Integer.parseInt(currentMonth)); 42 43 } 44 45 public CalendarView(Context context,Resources rs,int year, int month, int day){ 46 this(); 47 this.context= context; 48 specialCalendar = new SpecialCalendar(); 49 lunarCalendar = new LunarCalendar(); 50 this.res = rs; 51 currentYear = String.valueOf(year); //得到跳转到的年份 52 currentMonth = String.valueOf(month); //得到跳转到的月份 53 currentDay = String.valueOf(day); //得到跳转到的天 54 55 getCalendar(Integer.parseInt(currentYear),Integer.parseInt(currentMonth)); 56 }