<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 閱讀(315) 評論(0)  編輯  收藏 所屬分類: Blackberry
    主站蜘蛛池模板: 亚洲AV无码乱码国产麻豆| 亚洲欧洲专线一区| 亚洲中文无码永久免费| 亚洲heyzo专区无码综合| 亚洲午夜久久久影院伊人| 免费在线视频你懂的| 国产精品亚洲一区二区无码| 亚洲av激情无码专区在线播放| 成全视频在线观看免费高清动漫视频下载 | 一色屋成人免费精品网站| 国产午夜亚洲精品不卡| 亚洲高清在线观看| 日韩在线免费播放| 一级毛片不卡片免费观看| 亚洲国产精品成人午夜在线观看| 亚洲精品自产拍在线观看| 99久久综合国产精品免费| a级毛片免费在线观看| 亚洲精品永久在线观看| 亚洲AV一宅男色影视| 国产亚洲精品免费| 日韩亚洲国产高清免费视频| 黄视频在线观看免费| 亚洲精品永久在线观看| 亚洲黄色片在线观看| 国产亚洲成人在线播放va| 免费高清在线爱做视频| 国产又大又粗又长免费视频| 97在线免费视频| 免费的黄色的网站| 国产成人精品亚洲日本在线 | 亚洲成人福利网站| 亚洲国产另类久久久精品黑人 | 波多野结衣在线免费观看| 国产成人高清精品免费观看| 亚洲免费综合色在线视频| 亚洲AV无码一区二区三区系列| 亚洲情侣偷拍精品| 国产成人免费福利网站| 成人无遮挡裸免费视频在线观看 | 伊人亚洲综合青草青草久热|