Skip to main content

BlackBerry Tutorial Starter Code

From here i want to make some simple application that at least work on my phone and to create portfolio for me to get a decent job or just to demonstrate what we've been learning up till now.

Resources, requirement, credits and estimated result will be updated after.

The first case will be create a simple app that have home menu, about and exit.

this should be very simple. the home menu will be using ListField with Image. the whole application will be using small framework from wordpress for blackberry. but i never think its small. to learn the code it self it is very confusing but i made a smaller version from that. the code will be simple and i hope its easy to learn.

you can learn blackberry wordpress from here http://blackberry.wordpress.org/development/.



this is the the files. as you can see there are mvc. but at small dose. splashscreen being loaded for the first time.






okay now for the files. here are the main files

SmallMvc.java


 package SmallMvc;  
 import controller.MainController;  
 import view.SplashScreen;  
 import net.rim.device.api.ui.UiApplication;  
 /**  
  * This class extends the UiApplication class, providing a  
  * graphical user interface.  
  */  
 public class SmallMvc extends UiApplication  
 {  
   /**  
    * Entry point for application  
    * @param args Command line arguments (not used)  
    */   
   public static void main(String[] args)  
   {  
     // Create a new instance of the application and make the currently  
     // running thread the application's event dispatch thread.  
     SmallMvc theApp = new SmallMvc();      
     theApp.enterEventDispatcher();  
   }  
   /**  
    * Creates a new SmallMvc object  
    */  
   public SmallMvc()  
   {      
     // Push a screen onto the UI stack for rendering.  
        MainController mainScreen = new MainController();  
        new SplashScreen(this,mainScreen);  
   }    
 }  

these are the controller, from the name you already know that main controller extends from base controller

BaseController.java

 package controller;  
 //import view.ErrorView;  
 //import view.InfoView;  
 //import view.InquiryView;  
 import view.InquiryView;  
 import net.rim.device.api.ui.Screen;  
 import net.rim.device.api.ui.UiApplication;  
 import net.rim.device.api.ui.component.Dialog;  
 public abstract class BaseController {  
      // Utility routine to display errors  
      public synchronized void displayError(final Exception e, String message) {  
           displayError(message + "\n" + e.getMessage());  
      }  
      // Utility routine to display errors  
      public synchronized void displayError(String msg) {  
           System.out.println(msg);       
           //ErrorView errView= new ErrorView(msg);  
           //errView.doModal();  
      }  
      // Utility routine to display msg  
      public synchronized void displayMessage(String msg) {  
           System.out.println(msg);  
 //          InfoView infoView= new InfoView(msg);  
 //          infoView.doModal();  
      }  
      // Utility routine to ask question to the user  
      public synchronized int askQuestion(String msg) {  
           System.out.println(msg);  
           InquiryView inqView= new InquiryView(msg);  
           return inqView.doModal();  
      }  
      public void dismissDialog(final Dialog dlg) {  
           UiApplication.getUiApplication().invokeLater(new Runnable() {  
                public void run() {  
                     dlg.close();  
                }  
           });  
      }  
      public void backCmd(){        
            UiApplication.getUiApplication().invokeLater(new Runnable() {  
                public void run() {  
                     Screen scr=UiApplication.getUiApplication().getActiveScreen();  
                      UiApplication.getUiApplication().popScreen(scr);                 
                }  
           });  
      }  
      // Utility routine to ask question about exit application  
      public synchronized boolean exitApp() {  
        int result=this.askQuestion("Are sure to exit?");    
        if(Dialog.YES==result) {  
             System.exit(0);  
             return true;  
        } else {  
             return false;  
        }  
      }  
 }  

MainController.java


 package controller;  
 import net.rim.device.api.ui.UiApplication;  
 import view.MainView;  
 public class MainController extends BaseController {  
      private MainView mainView = null;  
      public static final String ADDBLOGVIEW="AddBlogsView";  
      public MainController() {  
           super();  
           this.mainView= new MainView(this);  
      }  
      public void showMainView(){  
           UiApplication.getUiApplication().pushScreen(this.mainView);  
      }  
      public void deleteBlog(int selectedBlog){  
                System.out.println("selezionato per la cancellazione: ");        
      }  
 }  

and now the View. all view you have made will be extends from BaseView including MainView. InquiryView is extends from Dialog because its just a dialog asking something. the SplashScreen is only MainScreen, i dont know why. the logo at splash screen can be change in these file.

anyway here are the code.

SplashScreen.java


 package view;  
 import java.util.Timer;  
 import java.util.TimerTask;  
 import controller.MainController;  
 import net.rim.device.api.system.Bitmap;  
 import net.rim.device.api.system.Characters;  
 import net.rim.device.api.system.KeyListener;  
 import net.rim.device.api.ui.Field;  
 import net.rim.device.api.ui.Font;  
 import net.rim.device.api.ui.FontFamily;  
 import net.rim.device.api.ui.UiApplication;  
 import net.rim.device.api.ui.component.BitmapField;  
 import net.rim.device.api.ui.component.LabelField;  
 import net.rim.device.api.ui.container.MainScreen;  
 public class SplashScreen extends MainScreen {  
        private MainController next;  
        private UiApplication application;  
        private Timer timer = new Timer();  
        public SplashScreen(UiApplication ui, MainController next) {  
         super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT);  
         this.application = ui;  
         this.next = next;  
         //this.add(new BitmapField(_bitmap, Field.FIELD_HCENTER | Field.FIELD_VCENTER));  
         SplashScreenListener listener = new SplashScreenListener(this);  
         LabelField headerText = new LabelField("**TITLE**"  
                        ,FIELD_HCENTER | LabelField.ELLIPSIS );  
         Font myFont = headerText.getFont();  
         FontFamily fontFamily;  
         try {  
              fontFamily = FontFamily.forName("System");  
              myFont = fontFamily.getFont(Font.BOLD, 28);  
         } catch (ClassNotFoundException e) {  
         }  
         headerText.setFont(myFont);  
         this.add(headerText);  
         this.add(new BitmapField(Bitmap.getBitmapResource("riza_logo.png"),Field.FIELD_HCENTER));  
         this.addKeyListener(listener);  
         timer.schedule(new CountDown(), 3000);  
         application.pushScreen(this);  
        }  
        public void dismiss() {  
         timer.cancel();  
         application.popScreen(this);  
         next.showMainView();  
        }  
        private class CountDown extends TimerTask {  
         public void run() {  
           DismissThread dThread = new DismissThread();  
           application.invokeLater(dThread);  
         }  
        }  
        private class DismissThread implements Runnable {  
         public void run() {  
           dismiss();  
         }  
        }  
        protected boolean navigationClick(int status, int time) {  
         dismiss();  
         return true;  
        }  
        protected boolean navigationUnclick(int status, int time) {  
         return false;  
        }  
        protected boolean navigationMovement(int dx, int dy, int status, int time) {  
         return false;  
        }  
        public static class SplashScreenListener implements KeyListener {  
         private SplashScreen screen;  
         public boolean keyChar(char key, int status, int time) {  
           //intercept the ESC and MENU key - exit the splash screen  
           boolean retval = false;  
           switch (key) {  
            case Characters.CONTROL_MENU:  
            case Characters.ESCAPE:  
            screen.dismiss();  
            retval = true;  
            break;  
           }  
           return retval;  
         }  
         public boolean keyDown(int keycode, int time) {  
           return false;  
         }  
         public boolean keyRepeat(int keycode, int time) {  
           return false;  
         }  
         public boolean keyStatus(int keycode, int time) {  
           return false;  
         }  
         public boolean keyUp(int keycode, int time) {  
           return false;  
         }  
         public SplashScreenListener(SplashScreen splash) {  
           screen = splash;  
         }  
        }  
      }   

BaseView.java


 package view;  
 import net.rim.device.api.ui.container.MainScreen;  
 public class BaseView extends MainScreen {  
      /**  
       *   
       */  
      public BaseView() {  
           super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);  
           // TODO Auto-generated constructor stub  
      }  
      public BaseView(long style) {  
           super(style);  
      }  
      public boolean onClose() {  
     setDirty(false);  
     return super.onClose();  
   }  
 }  

MainView.java

 package view;  
 import net.rim.device.api.ui.container.MainScreen;  
 import controller.MainController;  
 public class MainView extends MainScreen {  
      private MainController mainController = null;  
      /**  
       *   
       */  
      public MainView(MainController mainController) {  
           super();  
           this.mainController=mainController;  
           setTitle("Main View");  
      }  
   public boolean onClose()  {  
        return mainController.exitApp();  
   }  
 }  

InquiryView


 package view;  
 import net.rim.device.api.system.Bitmap;  
 import net.rim.device.api.ui.component.Dialog;  
 public class InquiryView extends Dialog {  
      /**  
       * Use this inquiry dialog boxes when users must confirm an action before continuing.   
       * A question mark (?) indicator appears in an inquiry dialog box.  
       *   
       * @param message  
       */  
      public InquiryView(String message) {  
           super(Dialog.D_YES_NO, message, Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), Dialog.GLOBAL_STATUS);  
      }       
 }  

These code is a simple and easy to learn rather than pulling from repository and then revert it back to the very first repository.

anyway if you need to ask please comment. thanks


Comments

Popular posts from this blog

JavaScript Real Time Calculation

I've been around looking for javascript that can do Real Time Calculation. javascript real time calculation, javascript real time calculation textbox. by some lucky keywords i found this code. this is exactly the code that i want. it really do the real time calculation. and it doesn't need onChange or OnBlur function. Just try it Example + = this is the javascript code <script type='text/javascript' > function startCalc(){   interval = setInterval("calc()",1); } function calc(){   one = document.autoSumForm.firstBox.value;   two = document.autoSumForm.secondBox.value;   document.autoSumForm.thirdBox.value = (one * 1) + (two * 1); } function stopCalc(){   clearInterval(interval); } </script> this is the html code <form name="autoSumForm">   <input class="right" type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br>

Learning Odoo 13 Module Development and Review

USING ODOO 13 Introduction This writing supposed to be a cheat sheet for helping myself to learn about Odoo, Odoo Development and also anyone who want to read this.   Odoo already have a good documentation in their websites you can check it here https://www.odoo.com/documentation/13.0/ What you need Odoo source you can get the source from odoo.com or github https://www.odoo.com/page/download or https://github.com/odoo/odoo. Right now I'm using the  https://www.odoo.com/page/download  . I did using the github twice so I'm already familiar with it but now i want to explore something new and maybe we will find something. Python v3.6++ (intermediate level). https://www.python.org/downloads/windows/ You can learn some basic “web development with python” first if you still new at programming. Search with google. Postgresql https://www.postgresql.org/download/ I’m using win Os for development and Visual Studio Code for IDE What should you re

BlackBerry ListField Tutorial Part 2

Blackberry ListField with Clicked Row this time i create based on rtm4bb code. it used manager as TableRowManager to create the field for each row. first i create MenuListField.java