Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mypackage;
- import net.rim.device.api.system.Bitmap;
- import net.rim.device.api.ui.Field;
- import net.rim.device.api.ui.Graphics;
- import net.rim.device.api.ui.UiApplication;
- import net.rim.device.api.ui.container.MainScreen;
- import net.rim.device.api.ui.container.VerticalFieldManager;
- class MyAPP extends UiApplication {
- public static void main(String[] args) {
- (new MyAPP()).enterEventDispatcher();
- }
- public MyAPP() {
- MainScreen myScreen = new MainScreen();
- Bitmap bmFocused = Bitmap.getBitmapResource("focused.png");
- Bitmap bmUnfocused = Bitmap.getBitmapResource("unfocused.png");
- VerticalFieldManager myManager = new VerticalFieldManager() {
- protected void sublayout(int width, int height) {
- int nWidth = 0, nHeight = 0;
- if (getFieldCount() == 3) {
- Field f = getField(0);
- setPositionChild(f, 26, 5);
- layoutChild(f, width, height);
- nWidth = Math.max(nWidth, f.getLeft() + f.getWidth());
- nHeight = Math.max(nHeight, f.getTop() + f.getHeight());
- f = getField(1);
- setPositionChild(f, 30, 70);
- layoutChild(f, width, height);
- nWidth = Math.max(nWidth, f.getLeft() + f.getWidth());
- nHeight = Math.max(nHeight, f.getTop() + f.getHeight());
- f = getField(2);
- setPositionChild(f, 60, 45);
- layoutChild(f, width, height);
- nWidth = Math.max(nWidth, f.getLeft() + f.getWidth());
- nHeight = Math.max(nHeight, f.getTop() + f.getHeight());
- }
- setExtent(nWidth, nHeight);
- }
- };
- for (int i = 0; i < 3; i++) {
- myManager.add(new CustomButtonField(bmFocused, bmUnfocused, 0));
- }
- myScreen.add(myManager);
- UiApplication.getUiApplication().pushScreen(myScreen);
- }
- }
- class CustomButtonField extends Field {
- Bitmap focussedImg;
- Bitmap unfocussedImg;
- public CustomButtonField(Bitmap focussedImg, Bitmap unfocussedImg,
- long style) {
- super(style | FOCUSABLE);
- this.focussedImg = focussedImg;
- this.unfocussedImg = unfocussedImg;
- }
- protected void layout(int width, int height) {
- setExtent(focussedImg.getWidth(), focussedImg.getHeight());
- }
- protected void paint(Graphics graphics) {
- Bitmap bm = isFocus() ? focussedImg : unfocussedImg;
- graphics.drawBitmap(0, 0, bm.getWidth(), bm.getHeight(), bm, 0, 0);
- }
- protected void drawFocus(Graphics graphics, boolean on) {
- }
- protected boolean navigationClick(int status, int time) {
- fieldChangeNotify(0);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement