Friday, September 20, 2013

Splash / Loading Screen in Blackberry

The following code will display splash screen.
public class App extends UiApplication {
     public static App theApp;
   
     public static void main(String[] args) {
       
                 theApp = new App();
                 theApp.enterEventDispatcher();   
           
           
        }  
   
    public App() {
          
            splash next = null;
            splash1 splash1=new splash1(this ,next);
            pushScreen(splash1);
           

    }
}

splash1 class is given below-
    public splash1(UiApplication app, splash next){
        application=app;
        VerticalFieldManager vfm=new VerticalFieldManager();
        final Bitmap header_Bitmap =Bitmap.getBitmapResource("splash.png");
        BitmapField bit =new BitmapField(header_Bitmap);
        vfm.add(bit);
        add(vfm);
      
         timer = new Timer();
         timer.schedule(new CountDown(), 1000);
             
    }

     public class CountDown extends TimerTask {
          public void run() {
             DismissThread dThread = new DismissThread();
             application.invokeLater(dThread);
          }
       }
     public void dismiss() {
          timer.cancel();
          application.popScreen(this);
       
          application.pushScreen(next);
       }
       public class DismissThread implements Runnable {
              public void run() {
                 dismiss();
              }
           }
}

splash class is the landing page(Home page)-
public class splash extends MainScreen {
        public splash(){
    //Here you can add your fields.......
  }
}

Thursday, September 5, 2013

Creating Facebook Like Slider Menu in Blackberry

 For creating a sliding bar like android facebook app, refer the following code. You have to customize it. Its only give you the idea. you have to implement it in your own way.




public final class MyScreen extends MainScreen
{
    boolean val=false;
    VerticalFieldManager vfm_r1;

    public MyScreen()
    {       

        final ButtonField l=new ButtonField("menu");
       
       
        final HorizontalFieldManager hfm_main=new HorizontalFieldManager();
       
        final VerticalFieldManager vfm_l=new VerticalFieldManager(){
             protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(280, maxHeight);
                    setExtent(280, maxHeight);
                }
             protected void paint(Graphics g){
                    g.setBackgroundColor(Color.RED);
                    // Clears the entire graphic area to the current background
                    g.clear();
                    super.paint(g);
                }
        };
        final VerticalFieldManager vfm_r=new VerticalFieldManager(){
             protected void sublayout(int maxWidth, int maxHeight) {
                 super.sublayout(maxWidth+300, maxHeight);
                 setExtent(maxWidth, maxHeight);
             }
             protected void paint(Graphics g){
                 g.setBackgroundColor(Color.YELLOW);
                 // Clears the entire graphic area to the current background
                 g.clear();
                 super.paint(g);
             }
        };
       
        vfm_l.add(new LabelField("sliding pannel"));
        
        vfm_r.add(l);
        vfm_r.add(new LabelField("main view"));
       
        hfm_main.add(vfm_r);
       
        add(hfm_main);
       
     FieldChangeListener listener=new FieldChangeListener() {
           
            public void fieldChanged(Field field, int context) {
                if(field==l){
                    if(!val){
                        val=true;
                        hfm_main.deleteAll();
                        hfm_main.add(vfm_l);
                        hfm_main.add(vfm_r);
                        hfm_main.invalidate();
                       
                }else{
                    val=false;
                    hfm_main.deleteAll();
                    hfm_main.add(vfm_r);
                    hfm_main.invalidate();
                                       
                }
                }
            }
        };
        l.setChangeListener(listener);
       
    }
}

Wednesday, July 24, 2013

Showing Google Maps in Blackberry

The following code will show your location in google map. No inbuilt Maps neede for this. Just fetch the location and pass it here.

  StringBuffer html;
  String initial = "\r\n" +
        " \r\n" +
        " \r\n" +
        "   \r\n" +
        "  Google Maps Multiple Markers \r\n" +
        "  \r\n" +
        "
\r\n" +        "\r\n" +
        "  


\r\n" +
        "\r\n" +
        "  \r\n" +
        "
\r\n" +        "
";
  html=new StringBuffer();
  html.append(initial);
 
  //add your location here
  String point = "['"+""+"',"+lattitude+","+longitude+","+""+"],";
        html.append(point);
        //add your location here
       centerPoint = "  center: new google.maps.LatLng("+lattitude+","+longitude+"),";
       html.append(second);
       html.append(centerPoint);
       html.append(finalpart);
       //System.out.println("Plot is"+html.toString());
       BrowserFieldConfig _bfConfig = new BrowserFieldConfig();      
      _bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
      _bfConfig.setProperty( BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
      _bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
      BrowserField myBrowserField = new BrowserField(_bfConfig);

       myBrowserField.displayContent(html.toString(), "");
       HorizontalFieldManager horf=new HorizontalFieldManager(HORIZONTAL_SCROLL);
       horf.add(myBrowserField);
  add(horf);
 

Thursday, June 27, 2013

Creating a persistent store in Blackberry

To create a persistent store, you create at least one PersistentObject. Each PersistentObject has a unique key of type long.

Creating Store - 
static PersistentObject store;
static {
store = PersistentStore.getPersistentObject( 0xa1a569278238dad2L );
}
 
Insert datas to store -  
String[] userinfo = {username, password};
synchronized(store) {
store.setContents(userinfo); 
store.commit();
} 

Retrive datas from store -
synchronized(store) {
String[] currentinfo = (String[])store.getContents(); 
if(currentinfo == null) {
Dialog.alert(_resources.getString(APP_ERROR));
} 
else {
currentusernamefield.setText(currentinfo[0]);
currentpasswordfield.setText(currentinfo[1]);
}
}