⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 homescreen.java

📁 In the last three articles, I’ve been walking you through the creation of an end-to-end BlackBerry a
💻 JAVA
字号:
package KnowledgeBase;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.Bitmap;

class HomeScreen extends MainScreen  {
    
    private String mnuSearchTitles;
    private String mnuBrowseTags;
    private String mnuViewRecent;
    private String[] mainMenuItems;
    private MyObjectListField menu;
    private SearchScreen searchScreen;
    private TagsScreen tagsScreen;
    private ArticlesScreen articlesScreen;
    private OptionsScreen optionsScreen;
    
    private MenuItem optionsMenu = new MenuItem("Options",100,10) {
       public void run() {
           showOptionsScreen();
       } 
    };
    
    HomeScreen() {
        
        this.setTitle("Knowledge Base");
        
        menu = new MyObjectListField();
        mnuSearchTitles = "Search by Title";
        mnuBrowseTags = "Browse Tags";
        mnuViewRecent = "View Recent";
        mainMenuItems = new String[]{mnuSearchTitles,mnuBrowseTags,mnuViewRecent};
        menu.set(mainMenuItems);
        this.add(menu);
    }
    
    private void showOptionsScreen() {
        if (null == optionsScreen) {
            optionsScreen = new OptionsScreen();
        }
        optionsScreen.displayOptions();
        UiApplication.getUiApplication().pushScreen(optionsScreen);
        
    }
    
    protected void makeMenu(Menu menu, int instance) {
        menu.add(optionsMenu);
        menu.add(MenuItem.separator(optionsMenu.getOrdinal() + 1));
        super.makeMenu(menu,instance);
    }
    
    protected boolean navigationClick(int status, int time) {
        
        // Determine which menu item was clicked.
        int selected = menu.getSelectedIndex();
        switch (selected) {
            case 0:
                if (null == articlesScreen) {
                 articlesScreen = new ArticlesScreen();   
                }
                if (null == searchScreen) {
                 searchScreen = new SearchScreen(articlesScreen);   
                }
                UiApplication.getUiApplication().pushScreen(searchScreen);
            break;
            case 1:
                if (null == articlesScreen) {
                 articlesScreen = new ArticlesScreen();   
                }
                if (null == tagsScreen) {
                 tagsScreen = new TagsScreen(articlesScreen);   
                }
                UiApplication.getUiApplication().pushScreen(tagsScreen);
            break;
            case 2:
                if (null == articlesScreen) {
                 articlesScreen = new ArticlesScreen();   
                }
                UiApplication.getUiApplication().pushScreen(articlesScreen);
            break;
        }
        
        return true;
    }
    
    private class MyObjectListField extends ObjectListField {
        
        private Bitmap icon = Bitmap.getBitmapResource("img/star_green.png");  
        
        // We are going to take care of drawing the item.
        public void drawListRow(ListField listField, Graphics graphics, 
                int index, int y, int width) {
            if (null != icon) {
                int offsetY = (this.getRowHeight() - icon.getHeight())/2;
                graphics.drawBitmap(1,y + offsetY, icon.getWidth(),
                        icon.getHeight(),icon,0,0);
                graphics.drawText(mainMenuItems[index], 
                    icon.getWidth() + 2, y, DrawStyle.ELLIPSIS, width - icon.getWidth() + 2);
            } else {
                graphics.drawText("- " + mainMenuItems[index], 0,
                    y, DrawStyle.ELLIPSIS, width - graphics.getFont().getAdvance("- "));
            }
        }
    };
    
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -