azure011328

导航

 

基于Android的日程管理软件

  1. 系统的需求分析

1.1系统目标

目前市场上日程管理软件种类繁多,如Google日历、微软To-Do等,功能各异。本程序旨在开发一款操作简单、功能实用的日程管理软件,支持多种日程类型和灵活的提醒设置,帮助用户高效管理时间。

1.2功能需求

该日程管理软件应具备以下功能:

 

日程添加:支持用户添加不同类型的日程(如会议、约会、电话等)。

 

日程编辑:允许用户修改已创建的日程内容、时间和类型。

 

提醒设置:提供多种提醒方式(如单次提醒、重复提醒等)。

 

日程查看:按时间顺序展示日程列表,方便用户快速浏览。

2.系统的概要设计

该软件是一款是基于Android开发的手机应用,简单实用,易于上手。

1.1 运行环境

1.Android手机或平板电脑:主频在1Ghz及以上,内存为512MB以上,系统版本为Android4.4.2及以上。

2.eclipse平台下安装了安卓android SDK 插件的电脑:Window All

1.2 数据库表设计

schedule

列名

数据类型

是否允许空

Id

integer

不允许

Type

text

不允许

Content

text

不允许

Date

text

不允许

Reminder

Text

允许

  1. 设计与实现部分

运行画面截图

 

 

 

关键代码:

public class CalendarActivity extends Activity implements OnGestureListener {

   private ViewFlipper flipper = null;
   private GestureDetector gestureDetector = null;
   private CalendarView calV = null;
   private GridView gridView = null;
   private BorderText topText = null;
   private Drawable draw = null;
   private static int jumpMonth = 0;      //每次滑动,增加或减去一个月,默认为0(即显示当前月)
   private static int jumpYear = 0;       //滑动跨越一年,则增加或者减去一年,默认为0(即当前年)
   private int year_c = 0;
   private int month_c = 0;
   private int day_c = 0;
   private String currentDate = "";
   
   private ScheduleDAO dao = null;
   

   public CalendarActivity() {

      Date date = new Date();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
       currentDate = sdf.format(date);  //当期日期
       year_c = Integer.parseInt(currentDate.split("-")[0]);
       month_c = Integer.parseInt(currentDate.split("-")[1]);
       day_c = Integer.parseInt(currentDate.split("-")[2]);
       
       dao = new ScheduleDAO(this);
       
   }

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      gestureDetector = new GestureDetector(this);
        flipper = (ViewFlipper) findViewById(R.id.flipper);
        flipper.removeAllViews();
        calV = new CalendarView(this, getResources(),jumpMonth,jumpYear,year_c,month_c,day_c);
        
        addGridView();
        gridView.setAdapter(calV);
        //flipper.addView(gridView);
        flipper.addView(gridView,0);
        
      topText = (BorderText) findViewById(R.id.toptext);
      addTextToTopTextView(topText);
   
   }
   
   @Override
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
         float velocityY) {
      int gvFlag = 0;         //每次添加gridviewviewflipper中时给的标记
      if (e1.getX() - e2.getX() > 120) {
            //像左滑动
         addGridView();   //添加一个gridView
         jumpMonth++;     //下一个月
         
         calV = new CalendarView(this, getResources(),jumpMonth,jumpYear,year_c,month_c,day_c);
           gridView.setAdapter(calV);
           //flipper.addView(gridView);
           addTextToTopTextView(topText);
           gvFlag++;
           flipper.addView(gridView, gvFlag);
         this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in));
         this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_out));
         this.flipper.showNext();
         flipper.removeViewAt(0);
         return true;
      } else if (e1.getX() - e2.getX() < -120) {
            //向右滑动
         addGridView();   //添加一个gridView
         jumpMonth--;     //上一个月
         
         calV = new CalendarView(this, getResources(),jumpMonth,jumpYear,year_c,month_c,day_c);
           gridView.setAdapter(calV);
           gvFlag++;
           addTextToTopTextView(topText);
           //flipper.addView(gridView);
           flipper.addView(gridView,gvFlag);
           
         this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_in));
         this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_out));
         this.flipper.showPrevious();
         flipper.removeViewAt(0);
         return true;
      }
      return false;
   }
   
   /**
    * 创建菜单
    */
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {

      menu.add(0, menu.FIRST, menu.FIRST, "今天");
      menu.add(0, menu.FIRST+1, menu.FIRST+1, "跳转");
      menu.add(0, menu.FIRST+2, menu.FIRST+2, "日程");
      menu.add(0, menu.FIRST+3, menu.FIRST+3, "日期转换");
      return super.onCreateOptionsMenu(menu);
   }
   
   /**
    * 选择菜单
    */
   @Override
   public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch (item.getItemId()){
        case Menu.FIRST:
           //跳转到今天
           int xMonth = jumpMonth;
           int xYear = jumpYear;
           int gvFlag =0;
           jumpMonth = 0;
           jumpYear = 0;
           addGridView();   //添加一个gridView
           year_c = Integer.parseInt(currentDate.split("-")[0]);
           month_c = Integer.parseInt(currentDate.split("-")[1]);
           day_c = Integer.parseInt(currentDate.split("-")[2]);
           calV = new CalendarView(this, getResources(),jumpMonth,jumpYear,year_c,month_c,day_c);
           gridView.setAdapter(calV);
           addTextToTopTextView(topText);
           gvFlag++;
           flipper.addView(gridView,gvFlag);
           if(xMonth == 0 && xYear == 0){
              //nothing to do
           }else if((xYear == 0 && xMonth >0) || xYear >0){
              this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_out));
            this.flipper.showNext();
           }else{
              this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_out));
            this.flipper.showPrevious();
           }
         flipper.removeViewAt(0);
           break;
        case Menu.FIRST+1:
           
           new DatePickerDialog(this, new OnDateSetListener() {
            
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                  int dayOfMonth) {
               //1901-1-1 ----> 2049-12-31
               if(year < 1901 || year > 2049){
                  //不在查询范围内
                  new AlertDialog.Builder(CalendarActivity.this).setTitle("错误日期").setMessage("跳转日期范围(1901/1/1-2049/12/31)").setPositiveButton("确认", null).show();
               }else{
                  int gvFlag = 0;
                  addGridView();   //添加一个gridView
                    calV = new CalendarView(CalendarActivity.this, CalendarActivity.this.getResources(),year,monthOfYear+1,dayOfMonth);
                    gridView.setAdapter(calV);
                    addTextToTopTextView(topText);
                    gvFlag++;
                    flipper.addView(gridView,gvFlag);
                    if(year == year_c && monthOfYear+1 == month_c){
                       //nothing to do
                    }
                    if((year == year_c && monthOfYear+1 > month_c) || year > year_c ){
                       CalendarActivity.this.flipper.setInAnimation(AnimationUtils.loadAnimation(CalendarActivity.this,R.anim.push_left_in));
                       CalendarActivity.this.flipper.setOutAnimation(AnimationUtils.loadAnimation(CalendarActivity.this,R.anim.push_left_out));
                       CalendarActivity.this.flipper.showNext();
                    }else{
                       CalendarActivity.this.flipper.setInAnimation(AnimationUtils.loadAnimation(CalendarActivity.this,R.anim.push_right_in));
                       CalendarActivity.this.flipper.setOutAnimation(AnimationUtils.loadAnimation(CalendarActivity.this,R.anim.push_right_out));
                       CalendarActivity.this.flipper.showPrevious();
                    }
                    flipper.removeViewAt(0);
                    //跳转之后将跳转之后的日期设置为当期日期
                    year_c = year;
                  month_c = monthOfYear+1;
                  day_c = dayOfMonth;
                  jumpMonth = 0;
                  jumpYear = 0;
               }
            }
         },year_c, month_c-1, day_c).show();
           break;
        case Menu.FIRST+2:
           Intent intent = new Intent();
         intent.setClass(CalendarActivity.this, ScheduleAll.class);
         startActivity(intent);
           break;
        case Menu.FIRST+3:
           Intent intent1 = new Intent();
           intent1.setClass(CalendarActivity.this, CalendarConvert.class);
           intent1.putExtra("date", new int[]{year_c,month_c,day_c});
           startActivity(intent1);
           break;
        }
      return super.onMenuItemSelected(featureId, item);
   }
   
   @Override
   public boolean onTouchEvent(MotionEvent event) {

      return this.gestureDetector.onTouchEvent(event);
   }

   @Override
   public boolean onDown(MotionEvent e) {
      // TODO Auto-generated method stub
      return false;
   }

   @Override
   public void onLongPress(MotionEvent e) {
      // TODO Auto-generated method stub

   }

   @Override
   public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
         float distanceY) {
      // TODO Auto-generated method stub
      return false;
   }

   @Override
   public void onShowPress(MotionEvent e) {
      // TODO Auto-generated method stub

   }

   @Override
   public boolean onSingleTapUp(MotionEvent e) {
      // TODO Auto-generated method stub
      return false;
   }

运行画面截图

 

 

关键代码:

public class CalendarConvert extends Activity {

   private LunarCalendar lc = null;
   private BorderTextView convertDate = null;
   private BorderTextView convertBT = null;
   private TextView lunarDate = null;
   
   private int year_c;
   private int month_c;
   private int day_c;
   
   public CalendarConvert(){
      lc = new LunarCalendar();
   }
   
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.convert);

      convertDate = (BorderTextView) findViewById(R.id.convertDate);
      convertBT = (BorderTextView) findViewById(R.id.convert);
      lunarDate = (TextView) findViewById(R.id.convertResult);
      
      Intent intent = getIntent();
      int[] date = intent.getIntArrayExtra("date");
      year_c = date[0];
      month_c = date[1];
      day_c = date[2];
      convertDate.setText(year_c+"年"+month_c+"月"+day_c);
      
      convertDate.setOnClickListener(new OnClickListener() {
         
         @Override
         public void onClick(View v) {

            new DatePickerDialog(CalendarConvert.this, new OnDateSetListener() {
               
               @Override
               public void onDateSet(DatePicker view, int year, int monthOfYear,
                     int dayOfMonth) {

                  if(year < 1901 || year > 2049){
                     //不在查询范围内
                     new AlertDialog.Builder(CalendarConvert.this).setTitle("错误日期").setMessage("跳转日期范围(1901/1/1-2049/12/31)").setPositiveButton("确认", null).show();
                  }else{
                     year_c = year;
                     month_c = monthOfYear+1;
                     day_c = dayOfMonth;
                     convertDate.setText(year_c+"年"+month_c+"月"+day_c);
                  }
               }
            }, year_c, month_c-1, day_c).show();
         }
      });
      
      convertBT.setOnClickListener(new OnClickListener() {
         
         @Override
         public void onClick(View v) {

            String lunarDay = getLunarDay(year_c,month_c,day_c);
            String lunarYear = String.valueOf(lc.getYear());
            String lunarMonth = lc.getLunarMonth();
            
            lunarDate.setText(lunarYear+"年"+lunarMonth+lunarDay);
         }
      });
      
   }
   
   /**
    * 根据日期的年月日返回阴历日期
    * @param year
    * @param month
    * @param day
    * @return
    */
   public String getLunarDay(int year, int month, int day) {
      String lunarDay = lc.getLunarDate(year, month, day, true);
      // {由于在取得阳历对应的阴历日期时,如果阳历日期对应的阴历日期为"初一",就被设置成了月份(:四月,五月。。。等)},所以在此就要判断得到的阴历日期是否为月份,如果是月份就设置为"初一"
      if (lunarDay.substring(1, 2).equals("月")) {
         lunarDay = "初一";
      }
      return lunarDay;
   }
}

 

public class CalendarView extends BaseAdapter {

   private ScheduleDAO dao = null;
   private boolean isLeapyear = false;  //是否为闰年
   private int daysOfMonth = 0;      //某月的天数
   private int dayOfWeek = 0;        //具体某一天是星期几
   private int lastDaysOfMonth = 0;  //上一个月的总天数
   private Context context;
   private String[] dayNumber = new String[49];  //一个gridview中的日期存入此数组中
   private static String week[] = {"周日","周一","周二","周三","周四","周五","周六"};
   private SpecialCalendar sc = null;
   private LunarCalendar lc = null;
   private Resources res = null;
   private Drawable drawable = null;
   
   private String currentYear = "";
   private String currentMonth = "";
   private String currentDay = "";
   
   private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
   private int currentFlag = -1;     //用于标记当天
   private int[] schDateTagFlag = null;  //存储当月所有的日程日期
   
   private String showYear = "";   //用于在头部显示的年份
   private String showMonth = "";  //用于在头部显示的月份
   private String animalsYear = "";
   private String leapMonth = "";   //闰哪一个月
   private String cyclical = "";   //天干地支
   //系统当前时间
   private String sysDate = "";  
   private String sys_year = "";
   private String sys_month = "";
   private String sys_day = "";
   
   //日程时间(需要标记的日程日期)
   private String sch_year = "";
   private String sch_month = "";
   private String sch_day = "";
   
   public CalendarView(){
      Date date = new Date();
      sysDate = sdf.format(date);  //当期日期
      sys_year = sysDate.split("-")[0];
      sys_month = sysDate.split("-")[1];
      sys_day = sysDate.split("-")[2];
      
   }
   
   public CalendarView(Context context,Resources rs,int jumpMonth,int jumpYear,int year_c,int month_c,int day_c){
      this();
      this.context= context;
      sc = new SpecialCalendar();
      lc = new LunarCalendar();
      this.res = rs;
      
      int stepYear = year_c+jumpYear;
      int stepMonth = month_c+jumpMonth ;
      if(stepMonth > 0){
         //往下一个月滑动
         if(stepMonth%12 == 0){
            stepYear = year_c + stepMonth/12 -1;
            stepMonth = 12;
         }else{
            stepYear = year_c + stepMonth/12;
            stepMonth = stepMonth%12;
         }
      }else{
         //往上一个月滑动
         stepYear = year_c - 1 + stepMonth/12;
         stepMonth = stepMonth%12 + 12;
         if(stepMonth%12 == 0){
            
         }
      }
   
      currentYear = String.valueOf(stepYear);;  //得到当前的年份
      currentMonth = String.valueOf(stepMonth);  //得到本月 jumpMonth为滑动的次数,每滑动一次就增加一月或减一月)
      currentDay = String.valueOf(day_c);  //得到当前日期是哪天
      
      getCalendar(Integer.parseInt(currentYear),Integer.parseInt(currentMonth));
      
   }
   
   public CalendarView(Context context,Resources rs,int year, int month, int day){
      this();
      this.context= context;
      sc = new SpecialCalendar();
      lc = new LunarCalendar();
      this.res = rs;
      currentYear = String.valueOf(year);;  //得到跳转到的年份
      currentMonth = String.valueOf(month);  //得到跳转到的月份
      currentDay = String.valueOf(day);  //得到跳转到的天
      
      getCalendar(Integer.parseInt(currentYear),Integer.parseInt(currentMonth));
      
   }
   
   @Override
   public int getCount() {
      // TODO Auto-generated method stub
      return dayNumber.length;
   }

   @Override
   public Object getItem(int position) {
      // TODO Auto-generated method stub
      return position;
   }

   @Override
   public long getItemId(int position) {
      // TODO Auto-generated method stub
      return position;
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {

      if(convertView == null){
         convertView = LayoutInflater.from(context).inflate(R.layout.calendar, null);
       }
      TextView textView = (TextView) convertView.findViewById(R.id.tvtext);
      String d = dayNumber[position].split("\\.")[0];
      String dv = dayNumber[position].split("\\.")[1];
      //Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Helvetica.ttf");
      //textView.setTypeface(typeface);
      SpannableString sp = new SpannableString(d+"\n"+dv);
      sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, d.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      sp.setSpan(new RelativeSizeSpan(1.2f) , 0, d.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      if(dv != null || dv != ""){
            sp.setSpan(new RelativeSizeSpan(0.75f), d.length()+1, dayNumber[position].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
      //sp.setSpan(new ForegroundColorSpan(Color.MAGENTA), 14, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
      textView.setText(sp);
      textView.setTextColor(Color.GRAY);
      if(position<7){
         //设置周
         textView.setTextColor(Color.BLACK);
         drawable = res.getDrawable(R.drawable.week_top);
         textView.setBackgroundDrawable(drawable);
      }
      
      if (position < daysOfMonth + dayOfWeek+7 && position >= dayOfWeek+7) {
         // 当前月信息显示
         textView.setTextColor(Color.BLACK);// 当月字体设黑
         drawable = res.getDrawable(R.drawable.item);
         //textView.setBackgroundDrawable(drawable);
         //textView.setBackgroundColor(Color.WHITE);

      }
      if(schDateTagFlag != null && schDateTagFlag.length >0){
         for(int i = 0; i < schDateTagFlag.length; i++){
            if(schDateTagFlag[i] == position){
               //设置日程标记背景
               textView.setBackgroundResource(R.drawable.mark);
            }
         }
      }
      if(currentFlag == position){
         //设置当天的背景
         drawable = res.getDrawable(R.drawable.current_day_bgc);
         textView.setBackgroundDrawable(drawable);
         textView.setTextColor(Color.WHITE);
      }
      return convertView;
   }
   
   //得到某年的某月的天数且这月的第一天是星期几
   public void getCalendar(int year, int month){
      isLeapyear = sc.isLeapYear(year);              //是否为闰年
      daysOfMonth = sc.getDaysOfMonth(isLeapyear, month);  //某月的总天数
      dayOfWeek = sc.getWeekdayOfMonth(year, month);      //某月第一天为星期几
      lastDaysOfMonth = sc.getDaysOfMonth(isLeapyear, month-1);  //上一个月的总天数
      Log.d("DAY", isLeapyear+" ======  "+daysOfMonth+"  ============  "+dayOfWeek+"  =========   "+lastDaysOfMonth);
      getweek(year,month);
   }
   
   //将一个月中的每一天的值添加入数组dayNuber
   private void getweek(int year, int month) {
      int j = 1;
      int flag = 0;
      String lunarDay = "";
      
      //得到当前月的所有日程日期(这些日期需要标记)
      dao = new ScheduleDAO(context);
      ArrayList<ScheduleDateTag> dateTagList = dao.getTagDate(year,month);
      if(dateTagList != null && dateTagList.size() > 0){
         schDateTagFlag = new int[dateTagList.size()];
      }
      
      for (int i = 0; i < dayNumber.length; i++) {
         // 周一
         if(i<7){
            dayNumber[i]=week[i]+"."+" ";
         }
         else if(i < dayOfWeek+7){  //前一个月
            int temp = lastDaysOfMonth - dayOfWeek+1-7;
            lunarDay = lc.getLunarDate(year, month-1, temp+i,false);
            dayNumber[i] = (temp + i)+"."+lunarDay;
         }else if(i < daysOfMonth + dayOfWeek+7){   //本月
            String day = String.valueOf(i-dayOfWeek+1-7);   //得到的日期
            lunarDay = lc.getLunarDate(year, month, i-dayOfWeek+1-7,false);
            dayNumber[i] = i-dayOfWeek+1-7+"."+lunarDay;
            //对于当前月才去标记当前日期
            if(sys_year.equals(String.valueOf(year)) && sys_month.equals(String.valueOf(month)) && sys_day.equals(day)){
               //笔记当前日期
               currentFlag = i;
            }
            
            //标记日程日期
            if(dateTagList != null && dateTagList.size() > 0){
               for(int m = 0; m < dateTagList.size(); m++){
                  ScheduleDateTag dateTag = dateTagList.get(m);
                  int matchYear = dateTag.getYear();
                  int matchMonth = dateTag.getMonth();
                  int matchDay = dateTag.getDay();
                  if(matchYear == year && matchMonth == month && matchDay == Integer.parseInt(day)){
                     schDateTagFlag[flag] = i;
                     flag++;
                  }
               }
            }
            
            setShowYear(String.valueOf(year));
            setShowMonth(String.valueOf(month));
            setAnimalsYear(lc.animalsYear(year));
            setLeapMonth(lc.leapMonth == 0?"":String.valueOf(lc.leapMonth));
            setCyclical(lc.cyclical(year));
         }else{   //下一个月
            lunarDay = lc.getLunarDate(year, month+1, j,false);
            dayNumber[i] = j+"."+lunarDay;
            j++;
         }
      }
        
        String abc = "";
        for(int i = 0; i < dayNumber.length; i++){
            abc = abc+dayNumber[i]+":";
        }
        Log.d("DAYNUMBER",abc);


   }
   
   
   public void matchScheduleDate(int year, int month, int day){
      
   }
   
   /**
    * 点击每一个item时返回item中的日期
    * @param position
    * @return
    */
   public String getDateByClickItem(int position){
      return dayNumber[position];
   }
   
   /**
    * 在点击gridView时,得到这个月中第一天的位置
    * @return
    */
   public int getStartPositon(){
      return dayOfWeek+7;
   }
   
   /**
    * 在点击gridView时,得到这个月中最后一天的位置
    * @return
    */
   public int getEndPosition(){
      return  (dayOfWeek+daysOfMonth+7)-1;
   }
   
   public String getShowYear() {
      return showYear;
   }

   public void setShowYear(String showYear) {
      this.showYear = showYear;
   }

   public String getShowMonth() {
      return showMonth;
   }

   public void setShowMonth(String showMonth) {
      this.showMonth = showMonth;
   }
   
   public String getAnimalsYear() {
      return animalsYear;
   }

   public void setAnimalsYear(String animalsYear) {
      this.animalsYear = animalsYear;
   }
   
   public String getLeapMonth() {
      return leapMonth;
   }

   public void setLeapMonth(String leapMonth) {
      this.leapMonth = leapMonth;
   }
   
   public String getCyclical() {
      return cyclical;
   }

   public void setCyclical(String cyclical) {
      this.cyclical = cyclical;
   }
}

 

运行画面截图

 

关键代码:

  1. public class ScheduleAll extends Activity {

       private ScrollView sv = null;
       private LinearLayout layout = null;
       private BorderTextView textTop = null;
       private ScheduleDAO dao = null;
       private ScheduleVO scheduleVO = null;
       private ArrayList<ScheduleVO> schList = new ArrayList<ScheduleVO>();
       private String scheduleInfo = "";
       private final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
       
       private int scheduleID = -1;
       
       @Override
       protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          
          dao = new ScheduleDAO(this);
          sv = new ScrollView(this);
          
          params.setMargins(0, 5, 0, 0);
          layout = new LinearLayout(this); // 实例化布局对象
          layout.setOrientation(LinearLayout.VERTICAL);
          layout.setBackgroundResource(R.drawable.schedule_bk);
          layout.setLayoutParams(params);
          
          textTop = new BorderTextView(this, null);
          textTop.setTextColor(Color.BLACK);
          textTop.setBackgroundResource(R.drawable.top_day);
          textTop.setText("所有日程");
          textTop.setHeight(47);
          textTop.setGravity(Gravity.CENTER);
          
          layout.addView(textTop);
          sv.addView(layout);
          
          setContentView(sv);
          
          getScheduleAll();
       }
       
       /**
        * 得到所有的日程信息
        */
       public void getScheduleAll(){
          schList = dao.getAllSchedule();
          if(schList != null){
             for (ScheduleVO vo : schList) {
                String content = vo.getScheduleContent();
                int startLine = content.indexOf("\n");
                if(startLine > 0){
                   content = content.substring(0, startLine)+"...";
                }else if(content.length() > 30){
                   content = content.substring(0, 30)+"...";
                }
                scheduleInfo = CalendarConstant.sch_type[vo.getScheduleTypeID()]+"\n"+vo.getScheduleDate()+"\n"+content;
                scheduleID = vo.getScheduleID();
                createInfotext(scheduleInfo, scheduleID);
             }
          }else{
             scheduleInfo = "没有日程";
             createInfotext(scheduleInfo,-1);
          }
       }
       
       /**
        * 创建放日程信息的textview
        */
       public void createInfotext(String scheduleInfo, int scheduleID){
          final BorderTextView info = new BorderTextView(this, null);
          info.setText(scheduleInfo);
          info.setTextColor(Color.BLACK);
          info.setBackgroundColor(Color.WHITE);
          info.setLayoutParams(params);
          info.setGravity(Gravity.CENTER_VERTICAL);
          info.setPadding(10, 5, 10, 5);
          info.setTag(scheduleID);
          layout.addView(info);
          
          //点击每一个textview就跳转到shceduleInfoView中显示详细信息
          info.setOnClickListener(new OnClickListener() {
             
             @Override
             public void onClick(View v) {
                String schID = String.valueOf(v.getTag());
                String scheduleIDs[] = new String[]{schID};
                Intent intent = new Intent();
                intent.setClass(ScheduleAll.this, ScheduleInfoView.class);
                intent.putExtra("scheduleID", scheduleIDs);
                startActivity(intent);
             }
          });
          
          
       }
       
       
       
       @Override
       public boolean onCreateOptionsMenu(Menu menu) {

          menu.add(1, menu.FIRST, menu.FIRST, "返回日历");
          menu.add(1, menu.FIRST+1, menu.FIRST+1, "添加日程");
          return super.onCreateOptionsMenu(menu);
       }
       
       @Override
       public boolean onOptionsItemSelected(MenuItem item) {

          switch(item.getItemId()){
          case Menu.FIRST:
             Intent intent = new Intent();
             intent.setClass(ScheduleAll.this, CalendarActivity.class);
             startActivity(intent);
             break;
          case Menu.FIRST+1:
             Intent intent1 = new Intent();
             intent1.setClass(ScheduleAll.this, ScheduleView.class);
             startActivity(intent1);
             break;
          }
          return super.onOptionsItemSelected(item);
       }
    }
  2. 心得体会

在开发过程中,深刻体会到Android开发的复杂性和调试的重要性。例如,在实现提醒功能时,需处理不同Android版本的权限问题,并通过日志逐步排查逻辑错误。此外,界面设计需兼顾美观与易用性,反复调整布局和交互细节。

遇到的问题及解决方法:

界面适配问题:部分设备显示异常。使用约束布局和尺寸单位dp”优化适配性。

通过本次开发,不仅掌握了日程管理软件的核心功能实现,还提升了解决实际问题的能力。

posted on 2025-06-11 08:40  淮竹i  阅读(10)  评论(0)    收藏  举报