Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. package mypackage;
  2.  
  3. import net.rim.device.api.system.Bitmap;
  4. import net.rim.device.api.ui.Field;
  5. import net.rim.device.api.ui.Graphics;
  6. import net.rim.device.api.ui.UiApplication;
  7. import net.rim.device.api.ui.container.MainScreen;
  8. import net.rim.device.api.ui.container.VerticalFieldManager;
  9.  
  10. class MyAPP extends UiApplication {
  11. public static void main(String[] args) {
  12. (new MyAPP()).enterEventDispatcher();
  13. }
  14.  
  15. public MyAPP() {
  16. MainScreen myScreen = new MainScreen();
  17. Bitmap bmFocused = Bitmap.getBitmapResource("focused.png");
  18. Bitmap bmUnfocused = Bitmap.getBitmapResource("unfocused.png");
  19. VerticalFieldManager myManager = new VerticalFieldManager() {
  20. protected void sublayout(int width, int height) {
  21. int nWidth = 0, nHeight = 0;
  22. if (getFieldCount() == 3) {
  23. Field f = getField(0);
  24.  
  25. setPositionChild(f, 26, 5);
  26. layoutChild(f, width, height);
  27. nWidth = Math.max(nWidth, f.getLeft() + f.getWidth());
  28. nHeight = Math.max(nHeight, f.getTop() + f.getHeight());
  29.  
  30. f = getField(1);
  31. setPositionChild(f, 30, 70);
  32. layoutChild(f, width, height);
  33. nWidth = Math.max(nWidth, f.getLeft() + f.getWidth());
  34. nHeight = Math.max(nHeight, f.getTop() + f.getHeight());
  35.  
  36. f = getField(2);
  37. setPositionChild(f, 60, 45);
  38. layoutChild(f, width, height);
  39. nWidth = Math.max(nWidth, f.getLeft() + f.getWidth());
  40. nHeight = Math.max(nHeight, f.getTop() + f.getHeight());
  41. }
  42. setExtent(nWidth, nHeight);
  43. }
  44. };
  45.  
  46. for (int i = 0; i < 3; i++) {
  47. myManager.add(new CustomButtonField(bmFocused, bmUnfocused, 0));
  48. }
  49. myScreen.add(myManager);
  50. UiApplication.getUiApplication().pushScreen(myScreen);
  51. }
  52. }
  53.  
  54. class CustomButtonField extends Field {
  55. Bitmap focussedImg;
  56. Bitmap unfocussedImg;
  57.  
  58. public CustomButtonField(Bitmap focussedImg, Bitmap unfocussedImg,
  59. long style) {
  60. super(style | FOCUSABLE);
  61. this.focussedImg = focussedImg;
  62. this.unfocussedImg = unfocussedImg;
  63. }
  64.  
  65. protected void layout(int width, int height) {
  66. setExtent(focussedImg.getWidth(), focussedImg.getHeight());
  67. }
  68.  
  69. protected void paint(Graphics graphics) {
  70. Bitmap bm = isFocus() ? focussedImg : unfocussedImg;
  71. graphics.drawBitmap(0, 0, bm.getWidth(), bm.getHeight(), bm, 0, 0);
  72. }
  73.  
  74. protected void drawFocus(Graphics graphics, boolean on) {
  75. }
  76.  
  77. protected boolean navigationClick(int status, int time) {
  78. fieldChangeNotify(0);
  79. return true;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement