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...

iOS 5 Creating eCommerce with Shopping Cart App Part 1

[Created 11-28-2012] it seems like there are tons of tutorial ios and xcode for beginner out there. you can view the list at my post here http://javalearning-adventure.blogspot.com/2012/11/learning-xcode.html that's the link that i always update if i find anything. this tutorial will consist of step by step in creating Shopping Cart App. There will be Browse Product, Shopping Cart, and Checkout Method. I will update these later after i satisfied with the end result. These tutorial will also include web programming using php. but these php will only using basic sample not the very complex with mysql database and everything. these php pages will only creating json output. i think you don't need to learn php and json. you should only learn how to handle json using objective-c. I am still a beginner in xcode and objective-c, its still only 1 month since i started these tutorial. requirements suppose to be iOS 5 with xcode 4. [i will update these later][postponed...

BlackBerry ListField Tutorial Part 3

This Part 3 will consist of Networking, ListField, JSON and Thread. I'm really sorry for pending this part 3. I've been busy making money and still failed. Its just really hard to live in third world country by coding. anyway, There are few Library that you will need creating ListField with JSON data, but we wont touch that area first. we need to learn the basic. * note added : Aug 26 2013 The basic should be : Networking Thread ListField [if i find anything, will be add here]