<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 35  文章 - 21  trackbacks - 0
    <2008年10月>
    2829301234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    文章分類

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜


    效果圖:



    前提準備:
    1,使用到一個上一次發布的組件:ImageLabelField。這個組件是一個圖標按鈕。
    可以接收用戶的點擊動作。
    2,一個關于時間格式的類 DateFormatOutil。

    行為:
    點擊左右的圖標按鈕,可以更換日期的顯示。
    并提供了獲得當前日期的函數:public Date getCurrentDate()

    代碼:
    DateFormatOutil
    package app.ui.outil;

    import java.util.Calendar;
    import java.util.Date;
    /**
     * 
     
    */
    public class DateFormatOutil {
     
        
    public final static long MILLISECONDS_IN_A_DAY = 86400000;
        
    public final static long MILLISECONDS_IN_AN_HOUR = 3600000;
        
    public final static long MILLISECONDS_IN_A_MINUTE = 60000;
        
        
    private static Calendar calendar = Calendar.getInstance();
        
        
    public static String formatDateAsFr_dMhm( java.util.Date date)
        {
           
    //format : dd/MM hh:mm
           calendar.setTime( date );
           
           
    int day = calendar.get(Calendar.DAY_OF_MONTH);
           
    int month = calendar.get(Calendar.MONTH) + 1;
           
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
           
    int minute = calendar.get(Calendar.MINUTE);
          
           
    return formatXX(day)+ "/" +formatXX(month)
                  
    + " " +formatXX(hour)+ ":" +formatXX(minute);
        }
        
        
    public static String formatDateAsFr_dMy( java.util.Date date)
        {
           
    //format : dd/MM/yyyy
           calendar.setTime( date );
           
           
    int day = calendar.get(Calendar.DAY_OF_MONTH);
           
    int month = calendar.get(Calendar.MONTH) + 1;
           
    int year = calendar.get(Calendar.YEAR);
           
    return formatXX(day)+ "/" +formatXX(month)+"/"+year;
        }
        
        
    public static String formatDateAsFr_dMyhm( Date date )
        {
           
    //format : dd/MM/yyyy hh:mm
           calendar.setTime( date );
           
           
    int day = calendar.get(Calendar.DAY_OF_MONTH);
           
    int month = calendar.get(Calendar.MONTH) + 1;
           
    int year = calendar.get(Calendar.YEAR);
           
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
           
    int minute = calendar.get(Calendar.MINUTE);
           
           
    return formatXX(day)+ "/" +formatXX(month) + "/" +year
                  
    + " " +formatXX(hour)+ ":" +formatXX(minute);
                  
        }
        
        
    public static Date addDays( Date date, int num )
        {
            
    long mseconds = date.getTime();
            
    return new Date( mseconds + MILLISECONDS_IN_A_DAY*num );
        }
            
        
    public static Date getBeginOfDay( Date date )
        {
           
    long mseconde = date.getTime();
           
    long plusmseconde = mseconde % MILLISECONDS_IN_A_DAY;
           Date beginningDate 
    = new Date( mseconde - plusmseconde - MILLISECONDS_IN_AN_HOUR );
           
    return beginningDate;
        }
        
        
    public static Date getEndOfDay( Date date )
        {
           
    long mseconds = date.getTime();
           
    long plusmseconds = mseconds % MILLISECONDS_IN_A_DAY;
           
    long restmseconds = MILLISECONDS_IN_A_DAY - plusmseconds ;
           Date endDate 
    = new Date( mseconds + restmseconds - MILLISECONDS_IN_AN_HOUR -1);
           
    return endDate;
        }
        
        
    private static String formatXX( int value )
        {
            
    return value < 10 ? "0"+value : ""+value;
        }
        
        
    }


    OneDayField :
    package app.ui.component;

    import app.ui.outil.DateFormatOutil;

    import java.util.Date;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Keypad;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.system.Bitmap;

    /**
     * 
     
    */
    public class OneDayField extends HorizontalFieldManager
    {    
        
    private Date currentDate;
        
    private LabelField dateChamp;
        
    private ImageLabelField previousButton;
        
    private ImageLabelField nextButton;
        
        
    public OneDayField( Date date, long style) 
        {   
            
    super( style );
            currentDate 
    = date;
            
            String dateStr 
    = DateFormatOutil.formatDateAsFr_dMy( currentDate );
            dateChamp 
    = new LabelField( dateStr, Field.NON_FOCUSABLE );
            
            Bitmap previousImage 
    = Bitmap.getBitmapResource( "arrow_date_previous.gif" );
            previousButton 
    = new ImageLabelField( previousImage );
            
            Bitmap nextImage 
    = Bitmap.getBitmapResource( "arrow_date_next.gif" );
            nextButton 
    = new ImageLabelField( nextImage );
            
            add( previousButton );
            add( dateChamp );
            add( nextButton );
        }


        
    public int getPreferredWidth()
        {
            
    int width = 0;
            
    for (int i = 0;  i < getFieldCount();  i++) {
                width 
    += getField(i).getPreferredWidth();
            }
            
    return width;
        }
        
        
    public int getPreferredHeight()
        {
            
    int height = 0;
            
    for (int i = 0;  i < getFieldCount();  i++) {
                
    int currentHeight = getField(i).getPreferredHeight();
                height 
    = height > currentHeight ? height : currentHeight;
            }
            
    return height;
        }
        
        
    public Date getCurrentDate()
        {
            
    return currentDate;
        }
        
        
    public void setCurrentDate( Date newDate )
        {
            currentDate 
    = newDate;
            dateChamp.setText( DateFormatOutil.formatDateAsFr_dMy( currentDate ) );
        }
        
        
        
    protected boolean keyDown(int keycode, int time)
        {
            
    if( Keypad.key( keycode ) == Keypad.KEY_ENTER)
            { 
               Field field 
    = getFieldWithFocus();
               
    if( field == previousButton )
               {
                   setCurrentDate( DateFormatOutil.addDays( currentDate, 
    -1 ) );
               }     
               
    else if( field == nextButton )
               {
                   setCurrentDate( DateFormatOutil.addDays( currentDate, 
    1 ) );
               }  
          
            }  
            
    else
            {
              fieldChangeNotify(
    1);
              
    return false;
            }
            fieldChangeNotify(
    1);
            
    return true;
        }
         
        
    protected void fieldChangeNotify(int context) 
        {
            
    try {
                
    this.getChangeListener().fieldChanged(this, context);
            } 
    catch (Exception exception) {
            }
        }

    }


    SevenDayField :
    package app.ui.component;

    import app.ui.outil.DateFormatOutil;

    import java.util.Date;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Keypad;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.system.Bitmap;

    /**
     * 
     
    */
    public class SevenDayField extends HorizontalFieldManager
    {
        
    private Date beginDate;
        
    private Date middleDate;
        
    private Date endDate;
        
    private LabelField beginDateChamp;
        
    private LabelField endDateChamp;
        
    private ImageLabelField previousButton;
        
    private ImageLabelField nextButton;
        
        
    public SevenDayField( Date date, long style) 
        {
            
            
    super( style );
            
            middleDate 
    = date;
            
            beginDate 
    = DateFormatOutil.addDays( middleDate, -3 );
            String beginDateStr 
    = DateFormatOutil.formatDateAsFr_dMy( beginDate );
            beginDateChamp 
    = new LabelField( beginDateStr, Field.NON_FOCUSABLE );
            
            endDate 
    = DateFormatOutil.addDays( middleDate, 3 );
            String endDateStr 
    = DateFormatOutil.formatDateAsFr_dMy( endDate );
            endDateChamp 
    = new LabelField( endDateStr, Field.NON_FOCUSABLE );
            
            Bitmap previousImage 
    = Bitmap.getBitmapResource( "arrow_date_previous.gif" );
            previousButton 
    = new ImageLabelField( previousImage );
            
            Bitmap nextImage 
    = Bitmap.getBitmapResource( "arrow_date_next.gif" );
            nextButton 
    = new ImageLabelField( nextImage );
            
            add( previousButton );
            add( beginDateChamp );
            add( 
    new LabelField( "-" ) );
            add( endDateChamp );
            add( nextButton );  
                  
        }
        
        
    public int getPreferredWidth()
        {
            
    int width = 0;
            
    for (int i = 0;  i < getFieldCount();  i++) {
                width 
    += getField(i).getPreferredWidth();
            }
            
    return width;
        }
        
        
    public int getPreferredHeight()
        {
            
    int height = 0;
            
    for (int i = 0;  i < getFieldCount();  i++) {
                
    int currentHeight = getField(i).getPreferredHeight();
                height 
    = height > currentHeight ? height : currentHeight;
            }
            
    return height;
        }    
        
        
    public Date getBeginDate()
        {
            
    return beginDate;
        }
        
        
    public Date getMiddleDate()
        {
            
    return middleDate;
        }
        
        
    public Date getEndDate()
        {
            
    return endDate;
        }
        
        
    public void setCurrentDate( Date newMiddleDate )
        {
            middleDate 
    = newMiddleDate;
            beginDate 
    = DateFormatOutil.addDays( middleDate, -3 );
            endDate 
    = DateFormatOutil.addDays( middleDate, 3);
            beginDateChamp.setText( DateFormatOutil.formatDateAsFr_dMy( beginDate ) ); 
            endDateChamp.setText( DateFormatOutil.formatDateAsFr_dMy( endDate ) );
        }

                
        
    protected boolean keyDown(int keycode, int time)
        {
            
    if( Keypad.key( keycode ) == Keypad.KEY_ENTER)
            { 
               Field field 
    = getFieldWithFocus();
               
               
    if( field == previousButton )
               {
                   setCurrentDate( DateFormatOutil.addDays( middleDate, 
    -1 ) );
               }     
               
    else if( field == nextButton )
               {
                   setCurrentDate( DateFormatOutil.addDays( middleDate, 
    1 ) );
               } 
            }  
            
    else
            {
              fieldChangeNotify(
    1);
              
    return false;
            }
            fieldChangeNotify(
    1);
            
    return true;
        }
         
        
    protected void fieldChangeNotify(int context) 
        {
            
    try {
                
    this.getChangeListener().fieldChanged(this, context);
            } 
    catch (Exception exception) {
            }
        }
          
    }


    posted on 2008-10-20 02:24 lincode 閱讀(316) 評論(0)  編輯  收藏 所屬分類: Blackberry
    主站蜘蛛池模板: 亚洲av无码一区二区三区人妖 | 春暖花开亚洲性无区一区二区| 亚洲熟女综合色一区二区三区| 小说专区亚洲春色校园| 一个人看www在线高清免费看| 亚洲成a人无码av波多野按摩| 久久久久久亚洲Av无码精品专口| 亚洲日韩精品国产3区| a毛片免费观看完整| 精品少妇人妻AV免费久久洗澡| 久久被窝电影亚洲爽爽爽| 亚洲精品无码国产片| 在线观看成人免费视频| 久久亚洲精品AB无码播放| 在线亚洲精品视频| 999久久久免费精品国产 | 七次郎成人免费线路视频 | 99在线精品视频观看免费| 亚洲精品在线电影| 精品97国产免费人成视频| 免费视频淫片aa毛片| 视频一区在线免费观看| 免费看韩国黄a片在线观看| 亚洲AV无码一区二区二三区入口 | EEUSS影院WWW在线观看免费| 免费无码又爽又刺激聊天APP| 亚洲熟妇AV一区二区三区宅男| 免费涩涩在线视频网| 黄色网址在线免费观看| 亚洲人成77777在线播放网站| 一级毛片视频免费观看| 亚洲成AV人片在线观看无码| 国产精彩免费视频| 男男gvh肉在线观看免费| 亚洲日韩国产精品第一页一区| 一区二区三区四区免费视频 | 免费人成又黄又爽的视频在线电影| 国产一精品一AV一免费孕妇| 亚洲Av永久无码精品一区二区| 亚洲日韩乱码中文无码蜜桃臀网站| 16女性下面无遮挡免费|