PIM Event的循环数据读取与设置

 

1. 遍历EventList列表取得Item(Event)

 

PIMList list = PIM.getInstance().openPIMList(PIM.EVENT_LIST,PIM.READ_ONLY,name);
// 遍历所有的记录,获取Event
PIMItem item;
for (Enumeration e = list.items(); e.hasMoreElements();)
{
     item = (PIMItem)e.nextElement();
}

 

 

 

2. 读取Event循环数据

 

private void populateRepeatForm() throws PIMException {     //重复部分的处理
    RepeatRule repeat = ((Event)item).getRepeat();
    if(repeat != null) {    //存在重复
        int[] fields = repeat.getFields();
        for(int i=0; i<fields.length; i++) {
           switch(fields[i]) {
               case RepeatRule.FREQUENCY:       //判断日程循环类型
                   String value = null;
                   int frequency = repeat.getInt(RepeatRule.FREQUENCY);
                   switch(frequency) {
                       //按天循环
                       case RepeatRule.DAILY:   value = "dayly";    break;
                       //按周循环
                       case RepeatRule.WEEKLY:  value = "weekly";   break;
                       //按月循环
                       case RepeatRule.MONTHLY: value = "monthly";  break;
                       //按年循环
                       case RepeatRule.YEARLY:  value = "yearly";   break;
                   }
                   Item repeatItem = 
                       new TextField("repeat", value, 64, TextField.ANY);
                   append(repeatItem);
                   break;
               case RepeatRule.DAY_IN_MONTH:
                   //按月循环,取得是每月的第几天
                   int dayInMonth = repeat.getInt(RepeatRule.DAY_IN_MONTH);
                   Item dayItem = 
                       new TextField("day", dayInMonth+"", 128, TextField.DECIMAL);
                   append(dayItem);
                   break;
               case RepeatRule.DAY_IN_WEEK:
                   /* dayInWeek会返回一个int的数值,该数值为相应的星期对应的int值得和:
                    * 星期字段及对应值
                    * SUNDAY                65536
                    * MONDAY                32768
                    * TUESDAY               16384
                    * WEDNESDAY             8192
                    * THURSDAY              4096
                    * FRIDAY                2048
                    * 如果event选择每周一、三循环,则dayInWeek值为40960(32768+8192)
                    * 将得到的和进行拆分,判断选择的是周几
                    */
                   int dayInWeek = repeat.getInt(RepeatRule.DAY_IN_WEEK);
                   Item weekItem = 
                       new TextField("week", dayInWeek+"", 128, TextField.DECIMAL);
                   append(weekItem);
                   break;
               case RepeatRule.MONTH_IN_YEAR:
                   //monthInYear会返回RepeatRule.JANUARY等十二月的已定义常量定义
                   int monthInYear = repeat.getInt(RepeatRule.MONTH_IN_YEAR);
                   Item monthItem = 
                       new TextField("month", monthInYear+"", 128, TextField.DECIMAL);
                   append(monthItem);
                   break;
               case RepeatRule.INTERVAL:
                   //读取循环间隔
                   int interval = repeat.getInt(RepeatRule.INTERVAL);
                   Item intervalItem = 
                        new TextField("interval", interval+"", 128, TextField.DECIMAL);
                   append(intervalItem);
                   break;
               case RepeatRule.COUNT://搞不清干嘛的
                   int count = repeat.getInt(RepeatRule.COUNT);
                   Item countItem = 
                       new TextField("count",  count+"", 128, TextField.DECIMAL);
                   append(countItem);
                   break;
               case RepeatRule.END:
                   //如果有重复结束时间,取得结束时间
                   long end = repeat.getDate(RepeatRule.END);
                   Item endItem = 
                       new DateField("end", DateField.DATE_TIME);
                   ((DateField)endItem).setDate(new Date(end));
                   append(endItem);
                   break;
           }
        }
    }
}


3. 日历Event循环设置
   

RepeatRule repeat = new RepeatRule();
/*
 * 设置重复类型,
 * 每天重复:RepeatRule.DAILY
 * 每周重复:RepeatRule.WEEKLY
 * 每月重复:RepeatRule.MONTHLY
 * 每年重复:RepeatRule.YEARLY
 */
repeat.setInt(RepeatRule.FREQUENCY, RepeatRule.MONTHLY);

/*
 * 设置重复日期为每月的第二周的星期三
 */
repeat.setInt(RepeatRule.WEEK_IN_MONTH, RepeatRule.SECOND);	
repeat.setInt(RepeatRule.DAY_IN_WEEK, RepeatRule.WEDNESDAY);

/*
 * 设置重复到期时间12月31日下午23:59
 */
java.util.Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.AM_PM, Calendar.PM);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
setDate(RepeatRule.END, cal.getTime().getTime());	//第二个参数为long型

((Event)item).setRepeatRule(repeat);	//将循环规则加入到Event

 

 

 

 

你可能感兴趣的:(j2me pim event)