Monday 18 March 2013

How to Install BlackBerry Application on a real device

Steps To Install BlackBerry App on real device:

>Install Latest BlackBerry Desktopmanager Software on your System
>To Test your BlackBerry Application on Real Device,you must have Signing keys
>Request for a Signing Keys by referring the URL Click Here 
>After Request Submitted you will be get a mail with three .CSI (RRT,RCR,RBB)files



Steps to Install .CSI Files:
>Connect your BlackBerry Device to the PC via USB Cable
>Open BlackBerry Desktop Manager Software
>In eclipse(BlackBerry java Plugin) right Click on your Project > BlackBerry > Signwith Signature Tool and then Install the 3 files one by one


After Signing got Completed

> Right Click on your Project > BlackBerry > Click Load Project on Device,This Step will install your Application on Real Device
Finally you can test your app on real device.

Wednesday 30 January 2013

Calling MySql Stored Procedure using Hibernate


Steps Involved  for Calling MySQL Stored Procedure in Hibernate:

Step1:
Create Employee Table

Create table Employee(ENO varchar(12),ENAME varchar(10),Primary Key(ENO));

 Insert into Employee(ENO,ENAME)VALUES('123','Rahul');

Step2:
Create a MySQL Stored Procedure

DELIMITER $$

DROP PROCEDURE IF EXISTS `EmployeeProcedure`$$

CREATE  PROCEDURE EmployeeProcedure (IN employeeNo varchar(10) )
BEGIN
SELECT * FROM Employee WHERE EMPNO=employeeNo;
END$$

DELIMITER ;

Step3:
1)Create Hibernate Project

2)Create a Model Class
Employee

package edu.model;

public class Employee {
 private String employeeNo;
 private String employeeName;
 public String getEmployeeNo() {
  return employeeNo;
 }
 public void setEmployeeNo(String employeeNo) {
  this.employeeNo = employeeNo;
 }
 public String getEmployeeName() {
  return employeeName;
 }
 public void setEmployeeName(String employeeName) {
  this.employeeName = employeeName;
 }

}


Create Employee.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
 <class name="edu.model.Employee" table="Employee">
  <id name="employeeNo" column="EMPNO">
  <generator class="identity" />  
  </id>
  <property name="employeeName">
   <column name="EMPNAME" />
  </property>
 </class>
 <sql-query name="EmployeeProcedure" callable="true">
 <return alias="employee" class="edu.model.Employee">
 <return-property name="employeeName" column="EMPNAME"/>
    <return-property name="employeeNo" column="EMPNO"/>

</return>
 <![CDATA[CALL EmployeeProcedure (:employeeNo)]]>

 </sql-query>
</hibernate-mapping>

Finally Create EmployeeTest Class:

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class EmployeeTest {
 public static void main(String args[]) {
  Session session = SessionUtil.getSession();
  Transaction tx = session.beginTransaction();
  try {
   Query query = session.getNamedQuery("EmployeeProcedure");
   query.setParameter("employeeNo", "123");
   Employee employee = (Employee) query.uniqueResult();
   System.out.println("Employee Name:" + employee.getEmployeeName());
  } catch (HibernateException e) {
   System.err.println("Hibernate Exception"+e.getMessage());
   tx.rollback();
  }
 }
}











Sunday 11 November 2012

Displaying Background Image on BlackBerry Screen

To Display a Background Image on BlackBerry Screen,you need to use the below Code:

Package Structure:




Step-1: Create a BlackBerry Project with the name BackgroundImage
Step-2: Create a Main Class with the name BackGroundApp
Step-3: Create a Class with the name BackGroundScreen
Step-4: Copy and paste your Background Image under your project res/img folder.

BackGroundApp:
import net.rim.device.api.ui.UiApplication;
public class BackGroundApp extends UiApplication {
private static BackGroundApp app;
private BackGroundScreen screen;
public BackGroundApp() {
screen = new BackGroundScreen();
pushScreen(screen);
}
public static void main(String args[]) {
app = new BackGroundApp();
app.enterEventDispatcher();
}
    }

BackGroundScreen:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class BackGroundScreen extends MainScreen {
private VerticalFieldManager mainManager;
private VerticalFieldManager subManager;
public BackGroundScreen(){
final Bitmap backgroundBitmap = Bitmap.getBitmapResource("background.png");
mainManager = new VerticalFieldManager(
net.rim.device.api.ui.container.VerticalFieldManager.NO_VERTICAL_SCROLLBAR
| net.rim.device.api.ui.container.VerticalFieldManager.NO_VERTICAL_SCROLLBAR) {
public void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, Display.getWidth(),
Display.getHeight(), backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
subManager = new VerticalFieldManager(
net.rim.device.api.ui.container.VerticalFieldManager.VERTICAL_SCROLL
| net.rim.device.api.ui.container.VerticalFieldManager.VERTICAL_SCROLLBAR) {
protected void sublayout(int maxWidth, int maxHeight) {
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
};
add(mainManager);
mainManager.add(subManager);
        }
               }
Output:








Saturday 10 November 2012

How to Place ads on Blackberry Application

If you have any requirement to place adverstisements like Banner Ads,Text adds etc...on to your Blackberry Application.Have a look at Below Code:

If you want to know more Information regarding Placing adds.Please have a look at BlackBerry Documents Click Here

Package Structure:


Step-1:Create a Project with any Name(Here I have Created with the name AddsonBlackBerry)
Step-2:Create a Class with the name AdDemo
Step-3: Place your Add Image under res/img Folder.

Finally Code Your AdDemo Class:

import java.util.Hashtable;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.UiApplication;
import net.rimlib.blackberry.api.advertising.app.Banner;
public class AdDemo extends UiApplication {
public static void main(String[] args) {
AdDemo theApp = new AdDemo();
theApp.enterEventDispatcher();
}
public AdDemo() {
pushScreen(new AdDemoScreen());
}
   }
 class AdDemoScreen extends MainScreen {
final Banner bannerAd;
public AdDemoScreen() {
Bitmap bit = Bitmap.getBitmapResource("BannerAd.png");
bannerAd = new Banner(85983, null,60000 , bit); bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_EXTRA_LARGE);
VerticalFieldManager vfm = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR
| Field.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager(
Field.FIELD_HCENTER | Field.FIELD_VCENTER);
hfm.add(bannerAd);
vfm.add(hfm);
add(vfm);
bannerAd.setFocus();
} 
protected boolean navigationClick(int status, int time) {
if (bannerAd.isFocus()) {
Dialog.alert("Hellloooo");
}
return true;
}
}
Note: If you click on your Banner add and you want to perform some action,you can place the below logic:
protected boolean navigationClick(int status, int time) {
if (bannerAd.isFocus()) {
Dialog.alert("Hellloooo");
}
return true;
}

OutPut:





Thursday 8 November 2012

LWUIT Theme in J2me Application(Nokia)

If  you want to apply Themes to Your Nokia Application ,You can use the below Code:

1)Create a Project with the Name LWUITTheme
2)Create a Midlet class
3)Copy the LWUITtheme.res file to your "res" folder(Download  LWUITtheme.res  form Click Here )
Note: To Successfully Execute this Application you require LWUIT Jar file(You can get this jar file from Click Here )

PackageStructure:

ThemeMidlet :
import com.sun.lwuit.Display;import com.sun.lwuit.Form;
import com.sun.lwuit.List;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import javax.microedition.midlet.MIDlet;
public class ThemeMidlet extends MIDlet {
    private Form form;
    private List list;
    private Object[] items;
    public ThemeMidlet() {
        Display.init(this);
        items = new Object[]{"Item1", "Item2", "Item3", "Item3", "Item4", "Item5"};
        list = new List(items);
        form = new Form("LWUIT Theme");
        //for the list to cover the entire screen width we need to set it    
        //list.setPreferredW(form.getWidth());
    }
   public void startApp() {
        try {
            Resources res = Resources.open("/res/LWUITtheme.res");
            UIManager.getInstance().setThemeProps(res.getTheme("LWUITDefault"));
            form.addComponent(list);
            form.show();
        } catch (Exception e) {
        }
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
   }
OutPut:





Wednesday 7 November 2012

RssFeed Reader in J2me(LWUIT)

This article Contains the Code to read an RssFile in j2me.After execution ,You can able to display the Title and an Image on Nokia Screen

The Midlet Class:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import com.sun.lwuit.*;
import com.sun.lwuit.animations.Transition3D;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import java.util.Vector;
import javax.microedition.midlet.*;
/**
 * @author pavan
 */
public class RssMidlet extends MIDlet implements ActionListener {
    private List rssFeedList;
    private Vector rssFeed;
    private Image image;
    private Form form1;
    private Command cmdExit, cmdDetails;
//Constructor 
      public RssMidlet() {
        Display.init(this);
        rssFeed = new Vector();
        cmdExit = new Command("Exit");
        cmdDetails = new Command("Details");
        form1 = new Form();
        form1.addCommand(cmdDetails);
        form1.addCommand(cmdExit);
        form1.setFocus(true);
        form1.addCommandListener(this);
        form1.setScrollableY(true);
        form1.setTransitionInAnimator(Transition3D.createRotation(250, true));
        rssFeedList = new List(rssFeed);
        rssFeedList.setRenderer(new NewsListCellRenderer());
        rssFeedList.setFixedSelection(List.FIXED_NONE);
        rssFeedList.setItemGap(0);
        form1.addComponent(rssFeedList);
        } 
         public void startApp() {
        String url = "rss URL";
        ParseThread myThread = new ParseThread(this);
        //this will start the second thread
         myThread.getXMLFeed(url);
          } 
      public void pauseApp() {
       }
                 public void destroyApp(boolean unconditional) {
        }
                 public void DisplayError(Exception error) {
        Dialog validDialog = new Dialog("Alert");
        validDialog.setScrollable(false);
        validDialog.setScrollable(false);
        // set timeout milliseconds
        validDialog.setTimeout(5000);
        //pass the alert text here
        TextArea textArea = new TextArea(error.getMessage());
        textArea.setFocusable(false);
        textArea.setScrollVisible(false);
        validDialog.addComponent(textArea);
        validDialog.show(0, 100, 10, 10, true);
        }
       public void addNews(RssModel newsItem) {
        rssFeed.addElement(newsItem);
        //to handle actions on the list we need to set the actionListener
        rssFeedList.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                List source = (List) ae.getSource();
            }
          });
        form1.show();
         }
    public void actionPerformed(ActionEvent ae) {
        if (ae.getCommand() == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
           }
          }
           }
A Model Class:
import com.sun.lwuit.Image;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author pavan
 */
public class RssModel {
 
    private String title;
    private Image image;
    public RssModel(String title){
        this.title=title;
       // this.image=image;
     
    }
 
    public String getTitle(){
        return title;
    }
    /* public Image getImage(){
        return image;
    }
    * */
 
   }
 RssParsing Class:
import com.sun.lwuit.Image;
import org.kxml2.io.*;
import java.io.*;
import javax.microedition.io.*;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParser;
public class ParseThread {
    protected RssMidlet parentMidlet;
    private Image image;
    private String title;
    public ParseThread(RssMidlet parent) {
        parentMidlet = parent;
    }
    public void getXMLFeed(final String url) {
        Thread t = new Thread() {
            public void run() {
                HttpConnection myConnection = null;
                try {
                    myConnection = (HttpConnection) Connector.open(url);


                    InputStream stream = myConnection.openInputStream();
                    ParseXMLFeed(stream);
                } catch (Exception error) {
                    parentMidlet.DisplayError(error);
                } finally {
                    try {
                        if (myConnection != null) {
                            myConnection.close();
                        }
                    } catch (IOException eroareInchidere) {
                        parentMidlet.DisplayError(eroareInchidere);
                    }
                }
            }
        };
        t.start();
    }
    private void ParseXMLFeed(InputStream input)
            throws IOException, XmlPullParserException {
        InputStreamReader isr = new InputStreamReader(input);
        KXmlParser myParser = null;
        try {
            myParser = new KXmlParser();

            myParser.setInput(isr);
            myParser.nextTag();
            System.out.println("nextTag");
            myParser.require(XmlPullParser.START_TAG, null, "rss");
            myParser.nextTag();
            myParser.require(XmlPullParser.START_TAG, null, "channel");
            myParser.nextTag();
            myParser.require(XmlPullParser.START_TAG, null, "title");
        } catch (Exception e) {
        }
        while (myParser.getEventType() != XmlPullParser.END_DOCUMENT) {
            String name = myParser.getName();
            if (name.equals("channel")) {
                break;
            }
            if (name.equals("item")) {
                if (myParser.getEventType() != XmlPullParser.END_TAG) {
                    myParser.nextTag();
                    title = myParser.nextText();
                    //myParser.nextTag();
                    // String link = myParser.nextText();
                    // myParser.nextTag();
                    // String imageurl = myParser.nextText();
                    // ImageClass ic = new ImageClass();
                    // image = ic.getImage(parentMidlet, imageurl.trim());

                    RssModel model = new RssModel(title);
                    parentMidlet.addNews(model);
                }
            } else {
                myParser.skipSubTree();
            }
            myParser.nextTag();
           }
         input.close();
           }
          }
Finally
NewsListCellRenderer :
You can Create this class by Referring This URL(Just Copy the ContactsRenderer Class File)
Here is the Sample:

public class NewsListCellRenderer extends Container implements ListCellRenderer {
      public NewsListCellRenderer() {  }
    public Component getListCellRendererComponent(List list, Object value, int i, boolean bln)              {}    
}

Thanks.........................





Sunday 4 November 2012

Blackberry SliderBar(SeekBar) Creation

This article will hepls you to Create a SliderBar on BlackBerry Screen,You can use the SliderBar for Controlling a Volume etc...According to your Actual Requirement

To Build this Application you require the below Classes
1)SliderApp: This is the Main Class.The Program Execution will Starts from here.

import net.rim.device.api.ui.UiApplication;

public class SliderApp extends UiApplication {
private static SliderApp app;
private SliderScreen screen;
public SliderApp(){
screen=new SliderScreen();
pushScreen(screen);
}
public static void main(String args[]){
app=new SliderApp();
app.enterEventDispatcher();
}
}



2)SliderScreen:You can get the Complete Code of this class below.
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class SliderScreen extends MainScreen  {
 private SliderField slider;
 private  HorizontalFieldManager manager;
 public SliderScreen(){
            slider = new SliderField(
Bitmap.getBitmapResource("slider2_thumb_normal.png"),
Bitmap.getBitmapResource("slider2_progress_normal.png"),
Bitmap.getBitmapResource("slider2_base_normal.png"),
Bitmap.getBitmapResource("slider2_thumb_focused.png"),
Bitmap.getBitmapResource("slider2_progress_focused.png"),
Bitmap.getBitmapResource("slider2_base_focused.png"), 8, 4,
8, 8, FOCUSABLE);
manager = new HorizontalFieldManager();
manager.add(slider);
setStatus(manager);
      }

      }
3)SliderField: You can get the Complete Code Click Here
Copy and Paste the Code.


Note: You can Download the Slider Images Click Here .

Check the Package Structure and Output in  below ScreenShots:

Package Structure:




OutPut: