I am new to blackberry,This is my first question.I am doing one sample app for this i require multi line textbox.i googled about this,I found the code below.
VerticalFieldManager vfm =new VerticalFieldManager(Manager.VERTICAL_SCROLL)
{
public void paint(Graphics g)
{
g.drawRoundRect(0, 0,getWidth(), getHeight(),12,12);
super.paint(g);
}
public void sublayout(int width, int height)
{
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth,managerHeight);
}
};
editField = new EditField(){
public void paint(Graphics g) {
getManager().invalidate();
super.paint(g);
}
};
vfm.add(editField);
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
add(vfm);
It works fine,if the text is less than Field height,if the text is greater than the field height.The text is crossing the border.How i fix that problem.Please help me.
You need to implement your own custom field.
Documentation can be found here: "Create a custom field"
You can use EditField from Blackberry APIs and use:
yourEditField.setBorder(yourBorder);
You will have then an edit field with a border and which accepts several lines
package nativeapp;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
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.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class LoginScreen extends MainScreen {
/**
* Login page
*/
private ButtonField btnLogin;
//private EditField txtUserID;
CustomTextBox txtUserID;
CustomTextBox txtPassword;
// private PasswordEditField txtPassword;
private CheckboxField Chkbox;
private LabelField RememberMe;
public LoginScreen() {
super(NO_VERTICAL_SCROLL);
txtUserID = new CustomTextBox() {
protected void paint(Graphics g) {
// Border roundedBorder = BorderFactory
// .createRoundedBorder(new XYEdges(9, 9, 9, 9),
// Color.GRAY, Border.STYLE_SOLID);
// setBorder(roundedBorder);
// setBackground(BackgroundFactory
// .createSolidBackground(Color.WHITE));
if (getText().length() == 0) {
g.setColor(Color.GRAY);
g.drawText("UserName", 0, 0);
}
g.setColor(Color.BLACK);
//g.drawRect(0, 0, (int) (Display.getWidth() / 1.5),
//txtUserID.getHeight()/* (int)(Display.getHeight()/9) */);
super.paint(g);
}
};
txtPassword = new CustomTextBox() {
protected void paint(Graphics g) {
Border roundedBorder = BorderFactory
.createRoundedBorder(new XYEdges(9, 9, 9, 9),
Color.GRAY, Border.STYLE_SOLID);
setBorder(roundedBorder);
setBackground(BackgroundFactory
.createSolidBackground(Color.WHITE));
if (getText().length() == 0) {
g.setColor(Color.GRAY);
g.drawText("txtPassword", 0, 0);
}
g.setColor(Color.BLACK);
super.paint(g);
}
};
// btnLogin = new ButtonField("SignIn");
btnLogin = new ButtonField("Sign In", Field.FIELD_HCENTER);
Chkbox = new CheckboxField();
// Chkbox.setMargin(0, 0, 0, 30);
RememberMe = new LabelField("Remember Me");
// RememberMe.setMargin(10, 0, 0, 0);
FieldChangeListener login = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String uname = txtUserID.getText().toString().trim();
String pword = txtPassword.getText().toString().trim();
if (!uname.equalsIgnoreCase("")
&& !uname.equalsIgnoreCase(null)
&& !pword.equalsIgnoreCase("")
&& !pword.equalsIgnoreCase(null)) {
boolean lgnStatus = (new httpClient()).loginStatus(uname,
pword, DataURL.smartURLloginchk);
if (lgnStatus) {
PersistentsStore ps = new PersistentsStore();
ps.setObject(DataURL.UserName, uname);
ps.setObject(DataURL.PassWord, pword);
UiApplication.getUiApplication().popScreen(
LoginScreen.this);
UiApplication.getUiApplication().pushScreen(
new WelcomeScreen());
} else {
Dialog.inform("Invalid UserID or Password");
}
} else {
Dialog.inform("UserID and Password shouldnot be Empty");
}
}
};
FieldChangeListener cancel = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
}
};
btnLogin.setChangeListener(login);
// btnCancel.setChangeListener(cancel);
setLoginScreen();
}
private void setLoginScreen() {
VerticalFieldManager vfmForCenterDisplay = new VerticalFieldManager(
Field.FIELD_HCENTER | Field.FIELD_VCENTER | Field.USE_ALL_WIDTH
| Field.USE_ALL_HEIGHT) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
}
};
Background background = BackgroundFactory.createBitmapBackground(Bitmap
.getBitmapResource("bground.png"));
vfmForCenterDisplay.setBackground(background);
int topSpace = (Display.getHeight() / 4);
vfmForCenterDisplay.setPadding(topSpace, 0, 0, 0);
VerticalFieldManager vfmBasicInfoWithBorder1 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
}
};
BitmapField bitmapField = new BitmapField(
Bitmap.getBitmapResource("loginbg_01.png")) {
protected void layout(int width, int height) {
setExtent(250, 95);
}
};
vfmBasicInfoWithBorder1.add(bitmapField);
VerticalFieldManager vfmBasicInfoWithBorder2 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
}
};
vfmBasicInfoWithBorder2.setBackground(BackgroundFactory
.createBitmapBackground(Bitmap
.getBitmapResource("loginbg_02.jpg")));
VerticalFieldManager vfmBasicInfoWithBorder3 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
setExtent(250, 95);
}
};
vfmBasicInfoWithBorder3.setBackground(BackgroundFactory
.createBitmapBackground(Bitmap
.getBitmapResource("loginbg_03.png")));
vfmBasicInfoWithBorder3.add(btnLogin);
// btnLogin.setMargin(0, 0, 0, 0);
// HorizontalFieldManager hfm1 = new HorizontalFieldManager(
// Field.FIELD_HCENTER);
HorizontalFieldManager hfm2 = new HorizontalFieldManager(
Field.FIELD_VCENTER);
hfm2.add(txtUserID);
// txtUserID.setMargin(0, 0, 0, 0);
HorizontalFieldManager hfm3 = new HorizontalFieldManager(FIELD_HCENTER
& FIELD_VCENTER);
hfm3.add(txtPassword);
// txtPassword.setMargin(0, 0, 0, 10);
HorizontalFieldManager hfm4 = new HorizontalFieldManager(
Field.FIELD_HCENTER);
hfm4.add(Chkbox);
Chkbox.setMargin(0, 0, 0, 10);
hfm4.add(RememberMe);
RememberMe.setMargin(0, 0, 0, 10);
// HorizontalFieldManager hfm5 = new
// HorizontalFieldManager(FIELD_HCENTER
// & FIELD_VCENTER) {
// protected void sublayout(int maxWidth, int maxHeight) {
// super.sublayout(250, 95);
// }
// };
// hfm5.add(btnLogin);
// btnLogin.setMargin(0, 0, 0, 0);
// hfm5.add(btnCancel);
// hfm5.setPadding(new XYEdges(0, 0, 0, ((250 - (70 + 75)) / 2)));
// btnCancel.setMargin(0, 0, 0, 15);
// vfmBasicInfoWithBorder1.add(hfm1);
vfmBasicInfoWithBorder2.add(hfm2);
vfmBasicInfoWithBorder2.add(hfm3);
vfmBasicInfoWithBorder3.add(hfm4);
// vfmBasicInfoWithBorder3.add(hfm5);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder1);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder2);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder3);
add(vfmForCenterDisplay);
}
}
Related
I want to add header.In header,i want to add background image..and two buttons.. in Blackberry.
so what i have to do??
I have tried following.. but it did not work..
VerticalFieldManager vfm=new VerticalFieldManager();
vfm.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("topbar.png")));
setTitle(vfm);
try this -
final Bitmap bg = Bitmap.getBitmapResource("bg.png");
VerticalFieldManager vfm_mid = new VerticalFieldManager(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_HORIZONTAL_SCROLLBAR | Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | Field.USE_ALL_WIDTH){
public void paint(Graphics graphics) {
graphics.setBackgroundColor(0x040811);
graphics.clear();
graphics.drawBitmap(0, 0, bg.getWidth(),
bg.getHeight(), bg, 0, 0);
super.paint(graphics);
}
};
ButtonField b1=new ButtonField("Button 1");
ButtonField b2=new ButtonField("Button 2");
vfm_mid.add(b1);
vfm_mid.add(b2);
setTitle(vfm_mid);
try this custom header:
public class TopBar extends HorizontalFieldManager implements FieldChangeListener{
int width;
int height;
Bitmap bgBitmap;
Button btnHome;
Bitmap btnImage;
boolean isHome;
MainScreen screenFromNavigate;
LabelField lblTitle;
public TopBar(String title)
{
super(FIELD_HCENTER);
setLayout(title);
}
public void setLayout(String title)
{
this.width=Display.getWidth();
this.height=50;
this.bgBitmap= Bitmap.getBitmapResource("topbar.png");
this.isHome = isHomeBtn;
btnHome = new ButtonField("Button 1");
btnHome.setMargin(7, 0, 0, 15);
add(btnHome);
btnHome.setChangeListener(this);
lblTitle = new LabelField(title);
add(lblTitle);
lblTitle.setMargin(12, 0, 0,Display.getWidth()/2-160);
}
protected void sublayout(int maxWidth, int maxHeight)
{
maxWidth=width;
maxHeight=height;
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, maxHeight);
}
protected void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, Display.getWidth(),50, bgBitmap, 0, 0);
// graphics.setBackgroundColor(Color.GRAY);
// graphics.clear();
super.paint(graphics);
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
}
}
}
call this:
TopBar topBar = new TopBar("Test");
setTitle(topBar);
How to create three editfields like this
HorizontalFieldManager hfm_city=new HorizontalFieldManager();
VerticalFieldManager vfm_city = new VerticalFieldManager();
vfm_city.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_city.setMargin(0, 200, 0, 0);
final EditField city = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "City";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_city.add(city);
VerticalFieldManager vfm_state = new VerticalFieldManager();
vfm_state.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_state.setMargin(0, 0, 0, 0);
final EditField state = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "State";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_state.add(state);
VerticalFieldManager vfm_zip = new VerticalFieldManager();
vfm_zip.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_zip.setMargin(0, 0, 0, 0);
final EditField zip = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "Zip";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_zip.add(zip);
hfm_city.add(vfm_city);
hfm_city.add(vfm_state);
hfm_city.add(vfm_zip);
You are going in the right way. but you have to give specific width & height to yourVerticalFieldManager otherwise it will take full width by default.
VerticalFieldManager vfm_city = new VerticalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getwidth()/3,30);
setExtent(Display.getwidth()/3,30);
}
};
Do this in your State & city vfm and add in your hfm and try.
Check my answer
{
Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
VerticalFieldManager vert=new VerticalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
HorizontalFieldManager hr=new HorizontalFieldManager(USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),50);
setExtent(Display.getWidth(),50);
}
};
hr.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
EditField e1=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(100,30);
setExtent(100,30);
}
};
EditField e2=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
EditField e3=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
e1.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e2.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e3.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e1.setPadding(0, 0, 0, 10);
e2.setPadding(0, 0, 0, 20);
e3.setPadding(0, 0, 0, 10);
e1.setBorder(bdr);
e2.setBorder(bdr);
e3.setBorder(bdr);
hr.add(e1);
hr.add(e2);
hr.add(e3);
vert.add(hr);
add(vert);
}
i want to set status bar at the bottom of screen and it should display one button left side and one right side. you can see my Screen at below.
my code is like this..
private void BottomLayout()
{
Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics graphics)
{
graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(topBg1.getWidth(), topBg1.getHeight());
setExtent(topBg1.getWidth(), topBg1.getHeight());
}
};
Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);
btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
hfmbottom.add(btn_prev);
Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);
btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
hfmbottom.add(btn_next);
setStatus(hfmbottom);
}
Thanks in advance.
I am posting you only the status bar panel.
Actually in the HorizontalFieldManager it does create problem.
Therefore found out the following way and it is working. It does add extra code but it works
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
class SampleBottomPanelScreen extends MainScreen {
private HorizontalFieldManager title_bar;
private VerticalFieldManager btn1_manager;
private ButtonField btn1;
private VerticalFieldManager btn2_manager;
private ButtonField btn2;
Bitmap bg_image;
public SampleBottomPanelScreen() {
//bg_image = Bitmap.getBitmapResource("backgroundImage.png");
btn1_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_LEFT) {
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth() / 2;
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
btn2_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_RIGHT | VerticalFieldManager.USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth() / 2;
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
title_bar = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){
public void paint(Graphics graphics) {
graphics.setBackgroundColor(0x2bb1ff);
graphics.clear();
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight() / 8;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
btn1 = new ButtonField("Submit", ButtonField.LEFT | ButtonField.FIELD_LEFT);
btn2 = new ButtonField("Cancel", ButtonField.RIGHT| ButtonField.FIELD_RIGHT);
btn1_manager.add(btn1);
btn2_manager.add(btn2);
title_bar.add(btn1_manager);
title_bar.add(btn2_manager);
this.add(title_bar);
}
}
try layout manager class
package com.doapps.blackberry.layouts;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
public class LayoutManager extends Manager
{
int n;
public LayoutManager(int n)
{
super(Manager.NO_VERTICAL_SCROLL);
this.n =n;
}
protected void sublayout(int width, int height)
{
if(n==2)
{
Field first = getField(0);
Field second = getField(1);
layoutChild(first, this.getPreferredWidth(), this.getPreferredHeight());
layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
setPositionChild(first,0, getPreferredHeight() -first.getHeight());
setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -first.getHeight());
setExtent(width, height);
}
if(n==1)
{
Field second= getField(0);
layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -second.getHeight());
setExtent(width, height);
}
}
public int getPreferredHeight() {
return 45;
}
public int getPreferredWidth() {
return Display.getWidth();
}
}
I think you need to use GridFieldManager. Rearrange the following code fragment to your needs and play with paddings ...
private HorizontalFieldManager createRightTab () {
HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_RIGHT);
ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_1), button_w, button_h);
button.setFocusListener(this);
hMgr.add(button);
return hMgr;
}
private HorizontalFieldManager createLeftTab () {
HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_LEFT);
ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_2), button_w, button_h);
button.setFocusListener(this);
hMgr.add(button);
return hMgr;
}
public void GridControlScreen() {
int w = net.rim.device.api.system.Display.getWidth();
gridMgr = new GridFieldManager(1, 3, 0);
gridMgr.setColumnProperty(0, GridFieldManager.FIXED_SIZE, (button_w));
gridMgr.setColumnProperty(1, GridFieldManager.FIXED_SIZE, (w-(2*button_w)));
gridMgr.setColumnProperty(2, GridFieldManager.FIXED_SIZE, (button_w));
HorizontalFieldManager hMgr_a = createLeftTab();
HorizontalFieldManager hMgr_center = new HorizontalFieldManager();
HorizontalFieldManager hMgr_b = createRightTab();
gridMgr.add(hMgr_a);
gridMgr.add(hMgr_center);
gridMgr.add(hMgr_b);
add(gridMgr);
}
Hope this can help.
Try this
private void BottomLayout()
{
Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics graphics)
{
graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(topBg1.getWidth(), topBg1.getHeight());
setExtent(topBg1.getWidth(), topBg1.getHeight());
}
};
Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);
btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
hfmbottom.add(btn_prev);
Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);
btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
btn_next.setPadding(0, 0, 0, Display.getWidth()-btn_prev.getWidth()-btn_next.getWidth());
hfmbottom.add(btn_next);
setStatus(hfmbottom);
}
this another way which we can set Field Left and right side.
http://keraisureshvblackberry.blogspot.in/2012/02/there-are-very-common-there-there-are.html
I want a BasicEditField with rounded border and white background fill.
This is my code
public class BasicField extends BasicEditField {
XYEdges padding = new XYEdges(0,0,0,0);
int color = Color.BLACK;
int lineStyle = Border.STYLE_SOLID;
int Width, Height;
Border roundedBorder = BorderFactory.createRoundedBorder(padding, color, lineStyle);
public BasicField()
{
super(BasicEditField.NO_NEWLINE);
//this.setPadding(2, 2, 2, 2);
//this.setBorder(roundedBorder);
}
public int getPreferredWidth()
{
int labelWidth = getFont().getAdvance(getLabel()) - 1;
Width = Graphics.getScreenWidth() -150;
return Width;
}
public int getPreferredHeight()
{
return 10;
}
public void paint(Graphics g) {
int currCol = g.getColor();
g.setBackgroundColor( Color.WHITE );
g.fillRect(0, 0, getPreferredWidth(), getPreferredHeight() );
g.clear();
g.setColor( Color.NAVY );
super.paint( g );
}
protected void layout( int maxWidth, int maxHeight )
{
super.layout( getPreferredWidth(), getPreferredHeight() );
}
}
Here you go -
Screenshot:
border.png:
MyEdit.java:
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
public class MyEdit extends UiApplication {
public static void main(String args[]) {
MyEdit app = new MyEdit();
app.enterEventDispatcher();
}
public MyEdit() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
Border myBorder = BorderFactory.createBitmapBorder(
new XYEdges(20, 16, 27, 23),
Bitmap.getBitmapResource("border.png"));
BasicEditField myField = new BasicEditField(TextField.NO_NEWLINE) {
protected void paint(Graphics g) {
if (getTextLength() == 0) {
g.setColor(Color.LIGHTGRAY);
g.drawText("Search", 0, 0);
}
g.setColor(Color.BLACK);
super.paint(g);
}
};
public MyScreen() {
myField.setBorder(myBorder);
setTitle(myField);
}
}
Friend... try this code.....
class BasicEditScreen extends MainScreen
{
public BasicEditScreen()
{
add(new BasicField(200, 40, FIELD_LEFT, "Enter here..", "horizontal"));
}
}
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class BasicField extends Manager
{
private int managerWidth;
private int managerHeight;
private int inactiveBorderColor = Color.GRAY;
private int activeBorderColor = Color.GREENYELLOW;
private int borderColor = inactiveBorderColor;
private int backgroundColor = Color.WHITE;
private int arcWidth;
private VerticalFieldManager vfm ;
private EditField editField;
int nn =1;
int count=0;
public BasicField(int width, int height, long style, final String hint,String type_horizontal_vertical)
{
super(style | NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
if(type_horizontal_vertical.equalsIgnoreCase("Horizontal"))
vfm = new VerticalFieldManager(HORIZONTAL_SCROLL | USE_ALL_WIDTH );
if(type_horizontal_vertical.equalsIgnoreCase("Vertical"))
vfm = new VerticalFieldManager(VERTICAL_SCROLL| USE_ALL_WIDTH | USE_ALL_HEIGHT);
managerWidth = width;
managerHeight = height;
long innerStyle = style & (READONLY | FOCUSABLE_MASK); // at least
if (innerStyle == 0)
{
innerStyle = FOCUSABLE;
}
if(style==EditField.FILTER_EMAIL)
{
innerStyle = EditField.FILTER_EMAIL;
}
if(style==EditField.FILTER_INTEGER)
{
innerStyle = EditField.FILTER_INTEGER;
}
editField = new EditField("", null, EditField.DEFAULT_MAXCHARS, innerStyle)
{
public void paint(Graphics g)
{
if(editField.getText().length()==0)
{
g.setColor(Color.GRAY);
g.drawText(hint,5,2);
super.paint(g);
}
g.setColor(Color.BLACK);
super.paint(g);
}
};
arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE; // make it even
add(vfm);
vfm.add(editField);
}
public void setFont(Font font)
{
super.setFont(font);
editField.setFont(font);
arcWidth = editField.getFont().getHeight() & 0xFFFFFFFE;
updateLayout();
}
public void setBorderColors(int inactive, int active)
{
inactiveBorderColor = inactive;
activeBorderColor = active;
invalidate();
}
public void setBackgroundColor(int bgColor)
{
backgroundColor = Color.AQUA;
invalidate();
}
public String getText()
{
return editField.getText();
}
public void setText(String newText)
{
editField.setText(newText);
}
public int getPreferredWidth()
{
return managerWidth;
}
public int getPreferredHeight()
{
return managerHeight;
}
protected void sublayout(int w, int h)
{
if (managerWidth == 0)
{
managerWidth = w;
}
if (managerHeight == 0)
{
managerHeight = h;
}
int actWidth = Math.min(managerWidth, w);
int actHeight = Math.min(managerHeight, h);
layoutChild(vfm, actWidth - arcWidth, actHeight - arcWidth);
setPositionChild(vfm, arcWidth / 2, arcWidth / 2);
setExtent(actWidth, actHeight);
}
protected void paint(Graphics g)
{
int prevColor = g.getColor();
int myWidth = managerWidth;
int myHeight = managerHeight;
g.setColor(backgroundColor);
g.fillRoundRect(0, 0, myWidth, myHeight, arcWidth, arcWidth);
g.setColor(borderColor);
g.drawRoundRect(0, 0, myWidth, myHeight, 10,10);
g.drawRoundRect(1, 1, myWidth - 2, myHeight - 2, 10-2, 10-2);
g.setColor(prevColor);
super.paint(g);
}
private void adjustBorderColor()
{
int nextColor;
if (editField.isFocus())
{
nextColor = activeBorderColor;
}
else
{
nextColor = inactiveBorderColor;
}
if (borderColor != nextColor)
{
borderColor = nextColor;
invalidate();
}
}
}
I am trying to design a splash screen with an activity indicator on it.
I am successfully creating a splash screen but my indicator is not being added to it,
it is being hidden below the image while i am setting its layout.
How can I fix this?
Here is my code:
package mypackage;
import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorController;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorModel;
import net.rim.device.api.ui.component.progressindicator.ActivityIndicatorView;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
//import net.rim.device.api.ui.extension.container.EyelidFieldManager;
public final class SplashScreen extends SplashScreenPage
{
public SplashScreen()
{
super(Bitmap.getBitmapResource("splash-blackberry.png"),2);
}
}
class SplashScreenPage extends MainScreen
{
VerticalFieldManager vfm= new VerticalFieldManager(Field.FIELD_VCENTER);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_VCENTER)
{
protected void sublayout( int maxWidth, int maxHeight )
{
super.sublayout(360,60);
setExtent(360, 60);
Field field = getField(0);
layoutChild(field,140, 60);
setPositionChild(field, 100,200);
}
public void paint(Graphics graphics)
{
//Draw the background image and then call paint.
// super.paint(graphics);
//graphics.clear();
// graphics.setBackgroundColor(0x000000);
//graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0);
// super.paint(graphics);
// graphics.clear();
// graphics.drawBitmap(0, 0, 360, 480, popup, 0, 0);
}
};
ActivityIndicatorView view = new ActivityIndicatorView(Field.USE_ALL_WIDTH);
ActivityIndicatorModel model = new ActivityIndicatorModel();
ActivityIndicatorController controller = new ActivityIndicatorController();
boolean notlogged = false;
Bitmap popup;
SplashScreenPage screen1 = this;
private Timer splashTimer = new Timer();
private TimerTask splashTask;
int count = 0;
int screenWidth = Display.getWidth();
int screenHeight = Display.getHeight();
int yCoord;
int xCoord;
boolean showSplash = true;
boolean splashDisplayed = false;
//SplashScreen page is here
public SplashScreenPage(Bitmap popup, final int seconds)
{
view.setController(controller);
view.setModel(model);
view.setLabel("Loading");
controller.setModel(model);
controller.setView(view);
model.setController(controller);
Bitmap bitmap = Bitmap.getBitmapResource("images.jpeg");
view.createActivityImageField(bitmap, 5, Field.FIELD_BOTTOM);
// add(view);
add(hfm);
hfm.add(view);
// add(vfm);
// vfm.add(Bitmap.getBitmapResource("splash-blackberry.png"));
this.popup = popup;
xCoord = (screenWidth - popup.getWidth()) / 2;
yCoord = (screenHeight - popup.getHeight()) / 2;
splashTask = new TimerTask() {
public void run() {
if (showSplash && !splashDisplayed) {
count++;
if (count == seconds * 15) {
showSplash = false;
splashDisplayed = true;
splashTimer.cancel();
invalidate();
synchronized (Application.getEventLock()){
UiApplication.getUiApplication().pushScreen(new secondscreen());
notlogged = true;
}
}
}
}
};
splashTimer.scheduleAtFixedRate(splashTask, 100, 100);
}
protected void paint(Graphics graphics) {
super.paint(graphics);
if (showSplash && !splashDisplayed) {
graphics.drawBitmap(xCoord, yCoord, popup.getWidth(), popup.getHeight(), popup, 0, 0);
// super.paint(graphics);
// graphics.clear();
}
}
protected void onUiEngineAttached(boolean attached) {
showSplash = true;
invalidate();
super.onUiEngineAttached(attached);
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return DismissSplash();
}
protected boolean navigationClick(int status, int time) {
return DismissSplash();
}
protected boolean keyChar(char c, int status, int time) {
return DismissSplash();
}
private boolean DismissSplash() {
if (showSplash) {
showSplash = false;
splashDisplayed = true;
invalidate();
return true;
}else{
return false;
}
}
public void onExposed() {
if( notlogged)
UiApplication.getUiApplication().popScreen(this);
}
}
In your HorizontalFieldManager that you are adding view to, you need to make sure you are calling super.paint() because it called subpaint() which will tell its child Fields (view in this case) to paint themselves. I see that you have it commented out, so you've probably been messing with that. Also, be sure that you do your background painting before you call super.paint() so you don't cover up the ActivityIndicatorView with your own painting.
Would it be possible for you to go through and clean up the code (removing the commented out code that isn't important) to a point where you would expect it to work so it is a littler easier to distinguish between "trying anything you can" code and "working" code.