List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

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]);
}
}

Creating Folder on SD Card in Blackberry

The File Connection API is implemented in the javax.microedition.io.file package.
Internal Storage - FileConnection fc = (FileConnection)Connector.open("file:///Store")
External Storage - FileConnection fc = (FileConnection)Connector.open("file:///SDCard")

Creating a folder-

try 
        {    
             FileConnection fc = (FileConnection)Connector.open(
"file:///SDCard/myfolder/");
             if (!fc.exists())
             {
                 fc.mkdir(); 
             }
             fc.close();
         }
         catch (IOException ioe) 
         {
            System.out.println(ioe.getMessage() );
         }
 

Creating a file - 

 try 
      {
          FileConnection fc = 
               (FileConnection)Connector.open(
"file:///store/home/user/newfile.txt");
          if (!fc.exists())
          {
              fc.create();  
          }
          fc.close();
       }
       catch (IOException ioe) 
       {
          System.out.println(ioe.getMessage() );
       }
 

Writing text to a file - 

try 
    {
      FileConnection fc = (FileConnection)Connector.open(
"file:///store/home/user/newfile.txt"); 
      if (!fc.exists())
      {
          fc.create();  
      }
      OutputStream outStream = fc.openOutputStream(); 
      outStream.write("test content".getBytes());
      outStream.close();
      fc.close();
     }
     catch (IOException ioe) 
     {
        System.out.println(ioe.getMessage() );
     }
 

SQLite database in Blackberry

Creating a SQLite database-

     try
       {
           URI myURI = URI.create("file:///SDCard/Databases/" + 
                                  "MyDatabase.db"); 
           d = DatabaseFactory.create(myURI);
           d.close();
       }
       catch ( Exception e ) 
       {         
           System.out.println( e.getMessage() );
           e.printStackTrace();
       }

 Creating Table - 

try
        {
            URI myURI = URI.create("/SDCard/Databases/" +
                                   "MyDatabase.db"); 
            d = DatabaseFactory.open(myURI);
            Statement st = d.createStatement( "CREATE TABLE 'MyTable' ( " +
                                              "'Name' TEXT, " +
                                              "'Number' INTEGER )" );
            
            st.prepare();
            st.execute();
            st.close();
            d.close();
        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
 

Insert Data - 

try
        {
            URI myURI = URI.create("file:///SDCard/Databases/" +
                                   "MyDatabase.db"); 
            d = DatabaseFactory.open(myURI);
            
            Statement st = d.createStatement("INSERT INTO MyTable(Name,Number) " +
                                             "VALUES ('abc',123)");
            st.prepare();
            st.execute();
            st.close();
            d.close();

        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
 

 Retrive data - 

try
        {
            URI myURI = URI.create("file:///SDCard/Databases/" +
                                   "MyDatabase.db"); 
            d = DatabaseFactory.open(myURI);
            
            Statement st = d.createStatement("SELECT Name,Number FROM MyTable");

            st.prepare();
            net.rim.device.api.database.Cursor c = st.getCursor();
            
            Row r;
            int i = 0;
            while(c.next()) 
            {
                r = c.getRow();
                i++;
                add(new RichTextField(i + ". Name = " + r.getString(0) +
                                          " , " +
                                          "Number= " + r.getInteger(1)));
            }
            if (i==0)
            {
                add(new RichTextField("No data in the MyTable table."));
            }
            st.close();
            d.close();

        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
 

Delete Table - 

 try
        {
            URI myURI = URI.create("file:///SDCard/Databases/" +
                                   "MyDatabase.db"); 
            d = DatabaseFactory.open(myURI);
            
            Statement st = d.createStatement("DELETE MyTable");
            st.prepare();
            st.execute();
            st.close();
            d.close();

        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }

 Update Table - 

 try
       {
        URI myURI = URI.create("file:///SDCard/Databases/" +
                               "MyDatabase.db"); 
        d = DatabaseFactory.open(myURI);
            
        Statement st = d.createStatement("UPDATE MyTable SET Number=1" +
                                         "WHERE Name='abc'");
        st.prepare();
        st.execute();
        st.close();
        d.close();

        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
 

 Delete Database - 

 try
        {
            URI myURI = URI.create("file:///SDCard/Databases/" +
                                   "MyDatabase.db"); 
            DatabaseFactory.delete(myURI);       
        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }

 

Storing data in Blackberry

There are several ways you can store, share, and manage data for your apps:
Data storage approach Description and API
SQLite database Store data in relational databases with the Database API.
File system Store data in files and folders with the FileConnection API.
Persistent store Save objects across smartphone restarts with the PersistentStore API.
Runtime store Save objects nonpersistently, which is useful for sharing data between applications and creating system-wide singletons, with the RuntimeStore API.
Record store Store data in the MIDP Record Management System with the RMS API.

Navigation events in Blackberry

You can use the Screen navigation methods to create a BlackBerry device application. If your existing BlackBerry device application implements the TrackwheelListener interface, update your BlackBerry device application to use the Screen navigation methods.
navigationClick(int status, int time)
navigationUnclick(int status, int time)
navigationMovement(int dx, int dy, int status, int time)
 
Navagation Click - 
public boolean navigationClick(int status, int time) {
   if ((status & KeypadListener.STATUS_TRACKWHEEL) == KeypadListener.STATUS_TRACKWHEEL) {
      //Input came from the trackwheel
   } else if 
     ((status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY) {
      //Input came from a four way navigation input device 
   }
   return super.navigationClick(status, time);
}
 
Touch Event - 
protected boolean touchEvent(TouchEvent message) {
switch(message.getEvent()) {
    case TouchEvent.CLICK:
    Dialog.alert("A click action occurred");
    return true;

case TouchEvent.DOWN:
    Dialog.alert("A down action occurred");
    return true;

case TouchEvent.MOVE:
    Dialog.alert("A move action occurred");
    return true;
}

return false;
} 

Respond to a user touching the screen twice quickly -

protected boolean touchEvent(TouchEvent message) {
   switch(message.getEvent()) {
      case TouchEvent.GESTURE:
         TouchGesture gesture = message.getGesture();
         switch(gesture.getEvent()) {
            case TouchGesture.TAP:
               if(gesture.getTapCount() == 2) {
                  Dialog.alert("Double tap occurred");
                  return true;
               }
          }
   }
 return false;
}   

 Pinch gestures -

Enabling Pinch event - 
InputSettings ts = TouchscreenSettings.createEmptySet();
ts.set(TouchscreenSettings.DETECT_PINCH, 1);
addInputSettings(ts); 
 
protected boolean touchEvent(TouchEvent message) 
{
   switch(message.getEvent()) 
   {
      case TouchEvent.GESTURE:
         TouchGesture gesture = message.getGesture();
         switch(gesture.getEvent()) 
         {
           case TouchGesture.PINCH_END:
             Dialog.alert("Focal point: " + message.getX(1) 
             +            ", " + message.getY(1)
             +            "\nFinal zoom value: " + gesture.getPinchMagnitude());
             return true;
         }
   }
   return false;
}

Screens in Blackberry

The main component of a BlackBerry device UI is the Screen object.

Screen classes


Screen You can use the Screen class to create a screen and use a layout manager to lay out the UI components on the screen. You can define a specific type of screen by using the styles that the constants in the Field superclass define.
FullScreen You can use the FullScreen class to create an empty screen to which you can add UI components in a standard vertical layout. If you want to use another layout style, such as horizontal or diagonal, you can use the Screen class instead and add a layout manager to it.
MainScreen











  



 PopupScreen 
You can use the MainScreen class to create a screen with the following standard UI components:
  • default screen title, with a SeparatorField after the title
  • main scrollable section contained in a VerticalFieldManager
  • default menu with a Close menu item
  • default close action that closes the screen when the BlackBerry device user clicks the Close menu item or presses the Escape key
You should consider using a MainScreen object for the first screen of your BlackBerry device application to maintain consistency with other BlackBerry device applications.

Screen providing features for building dialog and status screens

UI components in Blackberry

The net.rim.device.api.ui package contains the fundamental classes that are used for all UI applications:
  • Field: A rectangular area that can be drawn on the screen of a device.
  • Manager: An area that contains other UI components and handles layout and scrolling behavior.
  • Screen: A drawable area that is pushed on to and popped off of an application's display stack.
For convenience, the net.rim.device.api.ui.component package contains prebuilt UI components such as the following:
For more information about the classes in the net.rim.device.api.ui.component package, see UI components.
The net.rim.device.api.ui.container package contains classes that you can use to arrange UI components on a screen, such as:
Button -

 ButtonField mySubmitButton = new ButtonField("Submit");

CheckBox  -
  CheckboxField chk=new CheckboxField("First Check Box", true);
 CheckboxField chk=new CheckboxField("First Check Box", false);
 
DialogBox 
  Dialog.alert("Specify the alert text that you want to display.")

LabelField -
 LabelField title = new LabelField("UI Component Sample", LabelField.ELLIPSIS);

RadioButton -

 RadioButtonGroup rbg = new RadioButtonGroup();
add(new RadioButtonField("Option 1",rbg,true));
add(new RadioButtonField("Option 2",rbg,false));
 
DateTimePicker -
DateTimePicker datePicker = DateTimePicker.getInstance();
datePicker.doModal();
Calendar cal = datePicker.getDateTime();
Date date = cal.getTime();
Dialog.alert("You selected " + date.toString()); 
 

FilePicker -
FilePicker fp = FilePicker.getInstance();
FilePickListener fileListener = new FilePickListener();
fp.setListener(fileListener);           
fp.show();   

class FilePickListener implements FilePicker.Listener 
{   
    public void selectionDone(String str)
    {
        Dialog.alert("You selected " + str);
    }
}
 
Text Fields 
RichTextField rich = new RichTextField("RichTextField");
BasicEditField bf = new BasicEditField(
     "BasicEditField: ", "", 10, EditField.FILTER_UPPERCASE);
EditField edit = new EditField(
            "EditField: ", "", 10, EditField.FILTER_DEFAULT);
AutoTextEditField autoT = new AutoTextEditField(
             "AutoTextEditField: ", "");
PasswordEditField pwd = new PasswordEditField("PasswordEditField: ", "");
 

Toolbar in Blackberry

Use a toolbar to provide users with a quick and easy way to access frequent actions for an application or screen. Each toolbar consists of a set of icons that appears along the bottom of the screen.
            if (ToolbarManager.isToolbarSupported()) 
            {
                setTitle("Toolbar Demo");
                
                ToolbarManager manager = new ToolbarManager();
                setToolbar(manager);

                try 
                {
                    Bitmap myBitmap = Bitmap.getBitmapResource("myImg.jpg");
                    Image myImage = ImageFactory.createImage(myBitmap);
                    
                    /*
                     * To create more buttons, Repeat the following lines 
                     * up until manager.add() 
                     */
                    ToolbarButtonField button1 = 
                         new ToolbarButtonField(myImage, new StringProvider("butn1"));
                    button1.setCommandContext(new Object()
                    {
                       public String toString()
                       {
                           return "Button1"; 
                       }          
                    });
                    
                    button1.setCommand(new Command(new CommandHandler()
                    {         
                       public void execute(ReadOnlyCommandMetadata metadata, Object context)
                       {
                           Dialog.alert("Executing command for " + context.toString());
                       }           
                    }));
                     
                    manager.add(new ToolbarSpacer(0));
                    manager.add(button1);
                }
                catch (Exception e)
                {
                    System.out.println(e.getMessage());
                }
            } 
            else 
            {
                Dialog.alert("The Toolbar is not supported on this device.");
            }

Title bar in Blackberry

Use a title bar to provide BlackBerry device users with information at the top of your application. Most title bars contain only a title, but title bars can display the following items:
  • application icon, descriptive title, and time
  • application notifications, such as a new message indicator
  • wireless connection indicators, including the wireless coverage level, network coverage, GPS indicator, Bluetooth indicator, and Wi-Fi connection indicator
  • battery power indicator
  • active call indicator 
StandardTitleBar myTitleBar = new StandardTitleBar()
            .addIcon("my_logo.png")
            .addTitle("Title Bar")
            .addClock()
            .addNotifications()
            .addSignalIndicator();
myTitleBar.setPropertyValue(StandardTitleBar.PROPERTY_BATTERY_VISIBILITY,
            StandardTitleBar.BATTERY_VISIBLE_LOW_OR_CHARGING);
setTitleBar(myTitleBar);

BitmapField in Blackberry

Use a bitmap field to display bitmap images that a BlackBerry device user can view.
Bitmap bitmapImage = Bitmap.getBitmapResource("your_image.jpg");
BitmapField bitmap_img= new BitmapField(bitmapImage);             
add(bitmap_img);

Map field in Blackberry

Use a map field to display a map in a BlackBerry device application.
MapField map = new MapField();
MapAction action = map.getAction();
action.setCentreAndZoom(new MapPoint(43.46518, -80.52237), 3);   
add(map);

Rich List in Blackberry

Use a rich list to display a list of items that contain an optional image on the left, a list of labels beside the image and an optional description below the image and labels.
 
Manager mainManager = getMainManager();
RichList list = new RichList(mainManager, true, 2, 1);
Bitmap bitmap1 = Bitmap.getBitmapResource("9500.png");
Bitmap bitmap2 = Bitmap.getBitmapResource("9000.png");
list.add(new Object[] {bitmap1, "Device 1","BlackBerry 9500", 
                                   "Description of Device 1."});
list.add(new Object[] {bitmap2, "Device 2","BlackBerry 9000", 
                                   "Description of Device 2."});

Simple list in Blackberry

Use a simple list to display a list of items as text.
 
Manager mainManager = getMainManager();
SimpleList listField = new SimpleList(mainManager);
listField.add("Item 1");
listField.add("Item 2");
listField.add("Item 3");
            

Auto complete field in Blackberry

The auto complete field sample application demonstrates how to create and configure an AutoCompleteField UI component using a variety of data sources. An AutoCompleteField is a text field that displays a list of values as the user types text in the field. The list contains values that match the field or criteria that you specify.The AutoCompleteField matches what the user types in the field against an associated data source.

BasicFilteredList filterList = new BasicFilteredList();
String[] currencyList = {RUB,AFN,EUR,ALL,GBP,GGP,DZD,EUR,AOA,XCD,XCD,
 ARS,AMD,AWG,SHP,AUD,EUR};   
int uniqueID = 0;
filterList.addDataSet(uniqueID,currencyList,"currency", 
BasicFilteredList.COMPARISON_IGNORE_CASE);
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
add(autoCompleteField);

Monday, June 3, 2013

Popup Screen with Transparent Background

public class popup extends PopupScreen
{

popup()
{
    super(new HorizontalFieldManager());

    setBackground (BackgroundFactory.createSolidTransparentBackground (Color.WHITE, 0));
    setBorder (BorderFactory.createRoundedBorder(new XYEdges(),Color.BLACK,2));


   //Here you can add Fields to the popup Screen.

}

}