Thursday, May 20, 2010

Retrieve the phone number of the device in blackberry

Just write two lines

String phnumber;
phnumber = Phone.getDevicePhoneNumber(true);

Wednesday, May 19, 2010

show images in listfield

myList = new ListField()
{
protected boolean navigationClick(int status , int time)
{
int selectedindex = myList.getSelectedIndex();


bsid = businessid[selectedindex];
pid = personid[selectedindex];
did = driverid[selectedindex];
bkid = bookingid[selectedindex];
if(pid!=null&&bkid!=null&&did!=null&&bsid!=null)
{
UiApplication.getUiApplication().pushScreen(new HistoryRoute(obj));
}
return true;

}
};
myList.setRowHeight(70);


ListCallback myCallback = new ListCallback();
myList.setCallback(myCallback);
for(int i = 0;i {

String fieldOne = requireddate[i]+"#"+requiredtime[i]+"$"+endaddress[i]+"@"+images[i];
myList.insert(i);
myCallback.insert(fieldOne, i);


}


ListfieldCallback method :--

private static class ListCallback implements ListFieldCallback {

private Vector listElements = new Vector();

public void drawListRow(
ListField list, Graphics g, int index, int y, int w) {
String text = (String)listElements.elementAt(index);
Bitmap bmp =null;

int part1= text.indexOf("#");
int part2 =text.indexOf("$");
int part3 = text.indexOf("@");
g.setColor(Color.BLACK);
int len = text.length();
String str1 = new String();
String str2 = new String();
String str3 = new String();
String str4 = new String();
String str12 = text.substring(0,part1);
str1 = str12.substring(0,10);
String remstraftrfirst =text.substring(part1);
str2 = text.substring(part1+1,part2);
str3 = text.substring(part2+1,part3);
byte[] dataArray = null;
str4 = text.substring(part3+1, len);
try
{
byte [] Decoded = Base64InputStream.decode(str4, 0, str4.length());
String dd = new String(Decoded);
dataArray = dd.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
int multH;
int multW;
int currHeight = bitmap.getHeight();
int currWidth = bitmap.getWidth();
multH= Fixed32.div(Fixed32.toFP(currHeight),Fixed32.toFP(50));
multW = Fixed32.div(Fixed32.toFP(currWidth),Fixed32.toFP(60));
bitmap = bitmap.scaleImage32(multW,multH);
bmp = bitmap.getBitmap();
}
catch(Exception e)
{

}
int xpos = 0;
int ypos = 5 + y;
int wt = 80;
int h = 200;

g.drawBitmap( xpos, ypos, wt, h, bmp, 0, 0 );

xpos = 90;
ypos = 10+y ;

g.drawText(str1+" "+str2, xpos, ypos);

xpos = 90;
ypos = 30+y;

g.drawText("To:"+" "+str3, xpos, ypos);

g.setColor(Color.GRAY);

g.drawLine(0,ypos+37, 360,ypos+37);
g.drawLine(0,ypos+39, 360,ypos+39);

}

public Object get(ListField list, int index) {
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s) {
return listElements.indexOf(p, s);
}

public int getPreferredWidth(ListField list) {
int width = 300;
return width;
}
public void insert(String toInsert, int index) {
listElements.addElement(toInsert);
}

}