Search This Blog

Friday, 15 June 2012

Another UI with header and Tab for Blackberry

Hello friends,
                     Here is the approach which you sometime needs when making some entertainment app or when you need to show data ina listfield and wants to make that looking awesome....

This contains the header, then comes the data space , you can add anything to this manager like list or any thing you want buttons etc... and bottom is the tab with icons to navigate the user on other screens....

you just need to copy paste this whole code its a complete screen code...

for resize function please look my previous post ....

CODE:


package mypackage;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.image.Image;
import net.rim.device.api.ui.image.ImageFactory;
import net.rim.device.api.ui.toolbar.ToolbarButtonField;
import net.rim.device.api.ui.toolbar.ToolbarManager;
import net.rim.device.api.util.StringProvider;


public final class MyScreen extends MainScreen
{
   int _width,_height;
    public MyScreen()
    {       
        _width = Display.getWidth();
        _height = Display.getHeight();

        Background _black = BackgroundFactory.createLinearGradientBackground(Color.BLACK,Color.BLACK
                ,Color.BLACK,Color.BLACK);
       
    VerticalFieldManager _master = new VerticalFieldManager(){
        public int getPreferredWidth(){
            return _width;
        }
        public int getPreferredHeight(){
            return _height;
        }
        public void sublayout(int maxWidth,int maxHeight){
            super.sublayout(getPreferredWidth(), getPreferredHeight());
            setExtent(getPreferredWidth(),getPreferredHeight());
        }
    };
    _master.setBackground(_black);
   
    HorizontalFieldManager _header = new HorizontalFieldManager(){
        public int getPreferredWidth(){
            return _width;
        }
        public int getPreferredHeight(){
            return _height/6;
        }
        public void sublayout(int maxWidth,int maxHeight){
            super.sublayout(getPreferredWidth(), getPreferredHeight());
            setExtent(getPreferredWidth(),getPreferredHeight());
        }
    };
   
    Background _headerBack = BackgroundFactory.createBitmapBackground(MyApp.resize("HeaderAutumn1.jpg", _width, _height/5));
    _header.setBackground(_headerBack);
   
    VerticalFieldManager _dataController = new VerticalFieldManager(Manager.VERTICAL_SCROLL){
        public int getPreferredWidth(){
            return _width;
        }
        public int getPreferredHeight(){
            return _height-(_height/6)-(_height/10);
        }
        public void sublayout(int maxWidth,int maxHeight){
            super.sublayout(getPreferredWidth(), getPreferredHeight());
            setExtent(getPreferredWidth(),getPreferredHeight());
        }
    };
   
    _dataController.setBackground(_black);
   
   
    ToolbarManager _manager = new ToolbarManager(){
        public int getPreferredWidth(){
            return _width;
        }
        public int getPreferredHeight(){
            return _height/10;
        }
        public void sublayout(int maxWidth,int maxHeight){
            super.sublayout(getPreferredWidth(), getPreferredHeight());
            setExtent(getPreferredWidth(),getPreferredHeight());
        }
    };
   
    Image _homeI = ImageFactory.createImage(MyApp.resize("home.png", 62, 62));
    Image _favI = ImageFactory.createImage(MyApp.resize("Favorites-icon.png", 62,62));
    Image _webI = ImageFactory.createImage(MyApp.resize("Web-icon.png", 62,62));
   
    ToolbarButtonField _home = new ToolbarButtonField(_homeI,new StringProvider("Home"));
    ToolbarButtonField _fav = new ToolbarButtonField(_favI,new StringProvider("Favourites"));
    ToolbarButtonField _web = new ToolbarButtonField(_webI,new StringProvider("Web"));
   
    _manager.add(_home);
    _manager.add(_fav);
    _manager.add(_web);
   
    this.add(_master);
    _master.add(_header);
    _master.add(_dataController);
    _master.add(_manager);
   
    }
    public boolean onClose(){
    int st = Dialog.ask(Dialog.D_YES_NO,"Are you sure ?");
    if(st==Dialog.YES){
        System.exit(1);
    }else{
    return false;
    }
    return false;
    }
}




No comments:

Post a Comment