Search This Blog

Tuesday, 29 May 2012

How to use GridFieldManager in Blackberry

Hello friends,
                   What you mostly do when you are supposed to display some data in a table form?....i was asking this same question till yesterday....but i got something called "GridFieldManager".I am still learning the functions of this field and will update you soon.But for now,Here is the simple code to add a GridFieldManager and add data to it.....Follow the Code:

CODE:

In your Screen or you can say java file , where you want to display the GridFieldManager,declare the object first....

GridFieldManager _grid;

Now, initialize it .....

_grid = new GridFieldManager(10,4,0); <arg0=int rows,arg1=int columns,arg2=int style>

Now lets ur give some padding to rows and columns.....

_grid.setColumnPadding(5); <5 pixels>

Now let's give these columns fixed size.....as we have 4 columns as we declared while initializing the GridFieldManager,I'll divide the screen Width into 4 parts.....

_grid.setColumnProperty(0,GridFieldManager.FIXED_SIZE,Display.getWidth()/4-5)<arg0=int Column,arg1=int Property,arg2=value>

Remember you need to set the columnproperty individually for every column,with this you can give a different fixed size to columns.....

Now , lets set Padding for rows........

_grid.setRowPadding(20);

Now,simply add the Data to this GridFieldManager.....

_grid.add(new LabelField("One"));
_grid.add(new LabelField("Two));
_grid.add(new LabelField("Three"));
_grid.add(new LabelField("Four"));
_grid.add(new LabelField("Five"));
_grid.add(new LabelField("Six"));


Finally , add this GridFieldManager to the screen.....or layout wherever you want....

this.add(_grid);

Done!!!

Try this code and check the output...

Friday, 25 May 2012

How to check if Phone is locked or not in Blackberry

Hello friends,
                    May be its a lil helpful for you , its as simple as making ice.......to check if the ph. is locked or not and if its not locked you can lock it programmatically.

Code:

ApplicationManager _manager = ApplicationManager.getApplicationManager();

To check if ph. is locked or not :
_manager.isSystemLocked()      <returns true if ph. is locked>

To Lock the phone programmatically :

_manager.lockSystem(true);



CHAO!!! try it

Thursday, 24 May 2012

How to Apply Border and background for any Field or Manager in Blackberry

Hello friends,
                     Got struck with those sharp edged boring EditFields ,and dull looks? Try giving some background and border to your Layouts and Fields....Follow the code Below...

Code:

For Declaring a Border :

XYEdges _padding = new XYEdges(3,3,3,3);
        int _color =0x004E78A0;
        int _lineStyle = Border.STYLE_FILLED;
        Border _border = BorderFactory.createRoundedBorder(_padding, _color, _lineStyle);  

//try Different values for _lineStyle and _color ,_padding gives the thickness of the border...

For Background (Bitmap):
Background _toolbarBack = BackgroundFactory.createBitmapBackground(<Bitmap>);

For Background(Gradient Color):

Background _layoutBack = BackgroundFactory.createLinearGradientBackground(int colorTopLeft, int colorTopRight, int colorBottomRight, int colorBottomLeft);

How to apply Border and Background to a Field or Manager :

Suppose we have a EditField with an object name _text;

so here it is how we apply border and background to this field:

_text.setBorder(_border);
_text.setBackground(_layoutBack);

Apply border and background to Managers in same way....

CHAO!!!!

Tuesday, 22 May 2012

How to check if SdCard is supported and present in Blackberry

Hello friends,
                    Here is the simple one to get the info if SDCard is supported and present in the device or not , Follow below code:

CODE:
boolean _sdcardStatus = false;

String _modelNum = DeviceInfo.getDeviceName();
        if((_modelNum.startsWith("8")&& !_modelNum.startsWith("87"))|| _modelNum.startsWith("9")){
            String root = null;
            Enumeration e = FileSystemRegistry.listRoots();
            while(e.hasMoreElements()){
                root = (String)e.nextElement();
                if(root.equalsIgnoreCase("sdcard/")){
                    _sdcardStatus = true;
                }
            }
        }

_sdcardStatus variable returns true in case SD Card is supported and present in device otherwise it returns false;

Monday, 21 May 2012

How to use ObjectChoiceField in Blackberry

Hello friends ,
                  Below is the code to use ObjectChoiceField in your Blackberry app,

CODE:

 String[] _productsVector = {"Acer Laptop","Blackberry","Samsung Mobiles","iPhone 4S"};

   ObjectChoiceField  _product = new ObjectChoiceField("",_productsVector,"");
 
   this.add(_product);

Friday, 18 May 2012

How to use ToolbarManager in Blackberry

Hello friends ,
                Here it is the major thing to give ur app a gorgeous look as you may seen in many apps , a Toolbar or some people call it "Tab Bar".Follow below code to implement that ,

Code:

Initialization :

ToolbarManager _manager = new ToolbarManager();

Now, create an image of  icons to display on this ToolbarManager , as below :

Bitmap _iconB = Bitmap.getBitmapResource("icon.png");
Image _iconI = ImageFactory.createImage(_iconB);

Now,initialize the ToolbarButtonField for this ToolbarManager,as Below:

ToolbarButtonField _but1 = new ToolbarButtonField(_iconI,new StringProvider("Home"));

Now , simple add this ToolbarButtonField to ToolbarManager,as Below:

_manager.add(_but1);

Now, add this ToolbarManager to your screen , as Below:

this.add(_manager);

NOTE:
Remeber you can resize the icons and ToolbarManager as a desscribed in previous posts,Resize ToolbarManager as a manager,use sublayout instead using layout, layout is used for fields not for managers.

Thursday, 17 May 2012

How to integrate a DateField in Blackberry

Hello,
     Here is another simple one,how to use DateField in your app for user to select a particular date in a easy way.

Code:

DateField _date = new DateField("Select Date",System.currentTimeMillis(),DateField.DATE_TIME);

you can change the size of the datefield as i have described in my previous post,plus to align the text shown in DateField you can use DrawStyle.HCENTRE or whatever you want see below example:

Code:
DateField _date =new DateField(null,System.currentTimeMillis(),DateField.DATE_TIME|DrawStyle.HCENTER);



Tuesday, 15 May 2012

How to use Phone listener in blackberry

Hello friends,
              Here is the thing, when you want to do something on network activity like incoming call , outgoing call countered:

CODE:

First step : implement "PhoneListener" on your screen

ex: public MyScreen extends MainScreen implements PhoneListener{
....
....
....
...
Phone.addPhoneListener(this);
}
    public void callAdded(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callAnswered(int callId) {
    Do Something//       
    }



    public void callConferenceCallEstablished(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callConnected(int callId) {
               // TODO Auto-generated method stub
    }



    public void callDirectConnectConnected(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callDirectConnectDisconnected(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callDisconnected(int callId) {
     // TODO Auto-generated method stub
       
    }



    public void callEndedByUser(int callId) {
       
         // TODO Auto-generated method stub
    }



    public void callFailed(int callId, int reason) {
        // TODO Auto-generated method stub
       
    }



    public void callHeld(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callIncoming(int callId) {
       
       
      // TODO Auto-generated method stub
       
    }



    public void callInitiated(int callid) {
        _reason = "Outgoing Call";
        _i=1;
    }



    public void callRemoved(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callResumed(int callId) {
        // TODO Auto-generated method stub
       
    }



    public void callWaiting(int callid) {
        // TODO Auto-generated method stub
       
    }



    public void conferenceCallDisconnected(int callId) {
        // TODO Auto-generated method stub
       
    }
}

How to get Sim no. in blackberry

Hello friends,
           Again, to get the Sim no. of device ,

String _simNo = GPRSInfo.imeiToString(SIMCardInfo.getIMSI());

How to get IMEI of device in blackberry

Hello friends,
         Here is the simple one to get the imei no. of the device.

String _imei = GPRSInfo.imeiToString(GPRSInfo.getIMEI(), false);

Thursday, 10 May 2012

How to get network location when GPS is not available in blackberry


Hello friends,
           Here is the code for Blackberry to get the Tower location when GPS is not available in blackberry

CODE:

BlackBerryCriteria _criteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE);
BlackBerryLocationProvider  _locationProvider=(BlackBerryLocationProvider)LocationProvider.getInstance(_criteria);
                                BlackBerryLocation _location = (BlackBerryLocation)_locationProvider.getLocation(-1);

double _lat = _location.getQualifiedCoordinates().getLatitude();
double _lon = _location.getQualifiedCoordinates().getLongitude();



Sorry , this thing is giving problems,i just counter that ,i m unable to get network location from this , try GEOLOCATION_MODE_CELL or something else i am also doing R&D on this will update you soon

Wednesday, 9 May 2012

how to give permisiion programatically in blackberry

Hello friends here is the code to prompt for the particular permission  in your app start up, in case if tht permission is not allowed.....nothing much to explain so see the code below :

Code:


ApplicationPermissionsManager manager = ApplicationPermissionsManager
        .getInstance();
    int current = manager
        .getPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
    if (current != ApplicationPermissions.VALUE_ALLOW) {
        ApplicationPermissions permissions = new ApplicationPermissions();
        permissions.addPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
        manager.invokePermissionsRequest(permissions);
    }

Tuesday, 8 May 2012

How to save a variable in Persistent store at particular address.

Hello friends ,
            Today i'll tell you how to use a persistent store to store a variable,it is helpful when your app needs one time activation and you want your app know automatically that if the device is registered or not , in that case what we do is we send the data to the server by using JSON for the registration and get some value in return as an acknowledgement for successful registration now if you store that value in persistent store and let your app check that variable everytime it statrt up.That makes your app capable of knowing that if the device is registered or not,now the issue comes that how to use persistent store.The very first step is to get the address of some register on device.So below is the process....

1.First type something in eclipse like-abc,urname,ur application name etc.
2.Now select the word you just typed and right click on it and select Convert String to long.You will get the address.
3.Now see the below code :

Code:

To check the Value stored in Persistent store:

PersistentObject _store;
_store = PersistentStore.getPersistentObject(0x1700827a621f6962L);//Use your address here.
       
        UiApplication.getUiApplication().invokeLater(new Runnable(){

            public void run() {
                synchronized(MyApp._store){
                    i = (String)MyApp._store.getContents();
                }
                if(i!=null){
                    Do something when register has a value.
//                                    }else{
                    Do something when register is empty
                }
            }
           
        });

To insert the value in Persistent Store:

try{
                                    synchronized(MyApp._store){
                                        MyApp._store.setContents(pass the value here);
                                        MyApp._store.commit();
                                        Dialog.alert("Successfully Activated!");
                                    }
                                    }catch(Exception e){
                                        Dialog.alert("Error : "+e.toString());
                                    }

Remeber you need to initialize the Persistent object first whether to insert the value or to check it , the best way to do this is declare and initialize the variable ,as here it is _store.....in MyApp java file and make it static

Monday, 7 May 2012

How to change color of Menu in Blackberry

Hello friends here is the simple solution for this override make menu function as below:

Code:
protected void makeMenu(Menu menu,int context){
     Background _menuBack =     BackgroundFactory.createLinearGradientBackground(0x00901A1A,0x00901A1A,0x00901A1A,0x00901A1A);
     menu.setCaretBackground(_menuBack);
     super.makeMenu(menu, context);
}