Reduce height and width of BlackBerry BasicEditField - blackberry

I am trying to change the width and height of a BlackBerry BasicEditField.
But its not displaying the BasicEditField as i mention.
HorizontalFieldManager HFMreg =
new HorizontalFieldManager(
HorizontalFieldManager.USE_ALL_WIDTH
| HorizontalFieldManager.USE_ALL_HEIGHT) {
//Override the paint method to draw the background image.
public void paint(Graphics graphics) {
//Draw the registration background image
graphics.drawBitmap(0,0,Display.getWidth(),Display.getHeight(),BMregbg, 0, 0);
super.paint(graphics);
}
};
BEFfirstname = new BasicEditField("","",5,EditField.NO_NEWLINE) {
protected void paint(Graphics graphics) {
graphics.fillRect(0,0,80,25);
graphics.setBackgroundColor(Color.WHITE);
graphics.clear();
super.paint(graphics);
}
protected void layout() {
super.layout(getPreferredWidth(),getPreferredHeight());
setExtent(80,25); //width,height
}
public int getPreferredWidth() {
int fieldWidth = 80; //required width
return fieldWidth;
}
public int getPreferredHeight() {
int fieldHeight = 25; // required height
return fieldHeight;
}
};
//BEFfirstname.setMargin(200,0,0,60);
HFMreg.add(LFfirstname);
HFMreg.add(BEFfirstname);
add(HFMreg);

just an other way round:
BasicEditField BEFfirstname = new BasicEditField("","",5,EditField.NO_NEWLINE);
MyManager obj = new MyManger();
obj.add(BEFfirstname);
add(obj);
class MyManager extends Manager
{
MyManager()
{
super(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
}
protected void sublayout(int width, int height)
{
Field f = getField(0);
layoutChild(f,80,25);
setPositionChild(f, 10, 10);
}
}

Related

Editfield dynamic

I used the below code for edit text where I give the width and the height for the edit text and once the text fills the given height the field will scroll its content, but I want to make this code more dynamic. I want this editfield with only one line and it will grow for a number of lines done 3 or 4 and after this is done the field should scroll what it contains. Any help with that?
public class TextBoxField extends VerticalFieldManager {
private int managerWidth;
private int managerHeight;
private EditField editField;
public TextBoxField(int width, int height) {
super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;
managerHeight = height;
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
editField = new EditField(){
public void paint(Graphics g) {
getManager().invalidate();
super.paint(g);
}
};
vfm.add(editField);
add(vfm);
}
public void paint(Graphics g) {
super.paint(g);
g.drawRect(0, 0, getWidth(), getHeight());
}
public void sublayout(int width, int height) {
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth,managerHeight);
}
public String getText() {
return editField.getText();
}
public void setText(String text) {
editField.setText(text);
}
}

center object in GridFieldManager on blackberry

I want to center the objects in the GridFieldManager. This can be seen from the selected image in the blue zone like in the first picture. How can I center these objects (text+picture)???
This is my code
VerticalFieldManager manager = (VerticalFieldManager) getMainManager();
gfm = new GridFieldManager(rows, columns, GridFieldManager.FIXED_SIZE);
manager.add(gfm);
int columnWidth = (Display.getWidth() / columns)
- gfm.getColumnPadding();
for ( i = 0; i < columns; i++) {
gfm.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
}
BitmapField[] images = new BitmapField[6];
EncodedImage Icon = null;
for (i = 0; i < 6; i++) {
Icon = EncodedImage
.getEncodedImageResource("img/HOME.png");
images[i] = new BitmapField(Icon.getBitmap(), Field.FIELD_HCENTER
| Field.FIELD_VCENTER | Field.FOCUSABLE) {
protected void layout(int width, int height) {
setExtent(getPreferredWidth()+20, getPreferredHeight() + 15);
}
protected void paint(Graphics graphics) {
super.paint(graphics);
graphics.drawText("text", 0,
getBitmapHeight(), 2, getBitmapWidth() + 20);
}
};
gfm.setPadding(10, 0, 0, 0);
gfm.setRowPadding(20);
images[i].setPadding(20, 10, 5, 10);
gfm.add(images[i]);
}
}
Try this sample code:
public class PictureScreen extends MainScreen implements FieldChangeListener
{
static EditField editField;
private Bitmap lockBit;
private BitmapField bitmapField[];
private int size=0, i=0;;
public PictureScreen()
{
lockBit=Bitmap.getBitmapResource("HOME.png");
size=10;
createGUI();
}
private void createGUI()
{
bitmapField=new BitmapField[size];
HorizontalFieldManager hr=null;
for(i=0;i<size;i=i+3)
{
hr=new HorizontalFieldManager(Field.FIELD_HCENTER);
for(int j=i;j<i+3;j++) //Here I am taking 3 images per line(Horizontal Manager);
{
if(j<size)
{
final String _label="Text: "+(j+1);
bitmapField[j]=new BitmapField(null,Field.FOCUSABLE)
{
protected void layout(int width, int height)
{
setExtent( 100,100);
}
protected void paint(Graphics g)
{
g.drawBitmap(50-24, 0,lockBit.getWidth(), lockBit.getHeight(), lockBit, 0, 0); //Here 24= image width is 48pixel so,48/2 and 50=setExtent( 100,100); width=100/2;
g.setFont(Font.getDefault().derive(Font.BOLD|Font.ITALIC, 18));
g.drawText(_label, 50-24, 50);
super.paint(g);
}
};
bitmapField[j].setChangeListener(this);
bitmapField[j].setPadding(10, 10, 10, 10);
hr.add(bitmapField[j]);
}
}
add(hr);
}
}
public void fieldChanged(Field field, int context)
{
for(int i=0;i<size;i++)
{
if(field==bitmapField[i])
{
Status.show("Buy the Full Version", 500);
}
}
}
}
Then I got like this:
Try this and see the comments in the class;
I thinks your image is not in center and its Transparent area is not align properly . If you want to do this in easy way than it have to use PictureBackgroundButtonField Custom class. In this class you can handle focus and unfocus using tow different images . Below is the class .
package com.picturebackgroundbuttonfield;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
public class PictureBackgroundButtonField extends Field
{
private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;
private Bitmap _onPicture, _offPicture;
private Bitmap _currentPicture;
public PictureBackgroundButtonField(Bitmap onFocus, Bitmap offFocus, String text, long style)
{
super(style);
_onPicture = onFocus;
_offPicture = offFocus;
_font = getFont();
_label = text;
_labelHeight = _onPicture.getHeight();
_labelWidth = _onPicture.getWidth();
_currentPicture = _offPicture;
}
/**
* #return The text on the button
*/
String getText()
{
return _label;
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#getPreferredHeight()
*/
public int getPreferredHeight()
{
return _labelHeight;
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#getPreferredWidth()
*/
public int getPreferredWidth()
{
return _labelWidth;
}
/**
* Field implementation. Changes the picture when focus is gained.
* #see net.rim.device.api.ui.Field#onFocus(int)
*/
protected void onFocus(int direction)
{
_currentPicture = _onPicture;
// setFont(getFont().derive(Font.BOLD));
invalidate();
}
/**
* Field implementation. Changes picture back when focus is lost.
* #see net.rim.device.api.ui.Field#onUnfocus()
*/
protected void onUnfocus()
{
_currentPicture = _offPicture;
// setFont(getFont().derive(Font.PLAIN));
invalidate();
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)
*/
protected void drawFocus(Graphics graphics, boolean on)
{
// Do nothing
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#layout(int, int)
*/
protected void layout(int width, int height)
{
setExtent(Math.min( width, getPreferredWidth()),
Math.min( height, getPreferredHeight()));
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#paint(Graphics)
*/
/**
* Overridden so that the Event Dispatch thread can catch this event
* instead of having it be caught here..
* #see net.rim.device.api.ui.Field#navigationClick(int, int)
*/
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(1);
return true;
}
/*protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
}*/
protected void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);
graphics.setBackgroundColor(Color.BLACK);
graphics.drawText(_label, 2, 0,
(int)( getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK ),
getWidth() - 6 );
}
}

Title on mapfieldScreen in blackeberry is not visible

I am creating a map app. in which i am using mapfield. on the MapFieldScreen I am trying to add Title and also creating tabs but these two things are not visible. instead there is just gray color on these two places..
Here is my code.
class MapFieldScreen extends MainScreen
{
MapFieldScreen()
{
title= new LabelField("My Trip",LabelField.FIELD_HCENTER|LabelField.USE_ALL_WIDTH)
{
protected void layout(int width,int height)
{
setExtent(UIConstants.SCREEN_WIDTH, getFont().getHeight()*2);
}
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawText(label,UIConstants.SCREEN_WIDTH*2/5,getFont().getHeight()/2);
super.paint(g);
}
};
setTitle(title);
mLoc= Bitmap.getBitmapResource(UIConstants.STOP);
mmMapField = new MapField();
add(mMapField);
}
}
You can check follwing code:
LabelField title = new LabelField("My Trip") {
int _width = Display.getWidth();
int _height = getFont().getHeight() * 2;
protected void layout(int width, int height) {
setExtent(_width, _height);
}
public void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
int xText = (_width - getFont().getAdvance(getText())) / 2;
int yText = (_height - getFont().getHeight()) / 2;
graphics.drawText(getText(), xText, yText);
}
};
setTitle(title);

blackberery popup windows without black border color

hi all The below is my code .i try to remove black border color from popup window .i tried this but still i get small black border .
public class S2SPopup extends PopupScreen
{
public S2SPopup()
{
super(new VerticalFieldManager()
{
public void paint(Graphics g)
{
int a = g.getGlobalAlpha();
int c = g.getColor();
g.setColor(c);
g.drawBitmap(0, 0, HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight(),HomeScreen.popupimg, 0, 0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout( HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight());
setExtent( HomeScreen.popupimg.getWidth(),HomeScreen.popupimg.getHeight());
}
});
setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 0));
VerticalFieldManager vfm_Label = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth,150);
setExtent(maxWidth, 150);
}
};
vfm_Label.setMargin(80, 0, 0, 0);
ButtonField btnclose = new ButtonField("",ButtonField.RIGHT)
{
public void paint(Graphics g)
{
//setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 0));
int c = g.getGlobalAlpha();
g.setBackgroundColor(c);
super.paint(g);
}
};
btnclose.setMargin(0, 0, 0, 250);
btnclose.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
close();
}
});
LabelField s2sLabelField = new LabelField()
{
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
super.paint(g);
}
protected void layout(int width, int height)
{
super.layout(width, 150);
setExtent(width, 150);
}
};
s2sLabelField.setPadding(0, 50, 0, 30);
s2sLabelField.setText("lasjdfljlsjlfj ljsfdl jsflljfiowurnowncnvouern.zvovn ljlsfdjj jlj" +
"jsljfdlj ljsfl sjfl jfjsljdfljslfu jsjf;ujerpljsfdjpn sdflsajf ss23s mail jsldfjlfdju nsfjljljlfjmnn,nsf,n,nlojljlsndf,n,ljnsjfdljjufsn jj" +
"sjfd;jjljlsduflja;sfj ljsldfujrqnfqperiujf.zvnpqrue 33333333333333333333333333333333333333 ");
add(btnclose);
vfm_Label.add(s2sLabelField);
add(vfm_Label);
} //end of constructor
} // end of main screen
Override applyTheme with an empty implementation, and the black border goes away. You can't fix this from the constructor alone:
protected void applyTheme(){}
I doubt that it will correct this, but you may try giving your delegate manager a margin of 0 just to be certain that there isn't one on it and background color is creeping in from the theme. A solution that I have implemented in the past is to create your own custom Screen
public class CustomPopup extends Screen {
public CustomPopup() {
super(new VerticalFieldManager() {
//your custom code or a custom manager class (which is what I did)
);
setBackground(BackgroundFactory.createSolidTransparentBackground(0x000000, 0));
}
protected void sublayout(int width, int height) {
//make this screen take up the entire display
setPosition(0, 0);
setExtent(Display.getWidth(), Display.getHeight());
//and layout the delegate
setPositionDelegate(some_x, some_y);
layoutDelegate(some_width, some_height);
}
}
You'll have to add your own buttons and other graphics to it, but This should at least help point you in the right direction.

CustomButton Field not aligning in the center

I have created a custom button and i am placing the bunch of Custombuttons in a verticalfieldManager , I have aligned the verticalField Manager in the center. when i am creating a default buttonField then verticalfield Manager is able to align the buttonfield in the center. but when i am assigning custombuttonfield in the verticalField Manager it's not aligning in the center.
here is my custombuttoncode
public CustomButtonField(String label,long style) {
super(style);
this.label = label;
onPicture = Bitmap.getBitmapResource(onPicturePath);
font = getFont();
this.setPadding(5,5, 5, 5);
}
public String getLabel() {
return label;
}
public int getPreferredHeight() {
return onPicture.getHeight();
}
public int getPreferredWidth() {
return onPicture.getWidth();
}
protected void layout(int width , int height) {
setExtent(Math.min(width, Display.getWidth()), Math.min(height,getPreferredHeight()));
}
protected void paint(Graphics graphics) {
int texty =(getHeight()-getFont().getHeight())/2;
if (isFocus()) {
graphics.setColor(Color.BLACK);
graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0);
graphics.setColor(Color.WHITE);
graphics.setFont(font);
graphics.drawText(label,0,texty,DrawStyle.ELLIPSIS,getWidth());
} else {
graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0);
graphics.setColor(Color.WHITE);
graphics.setFont(font);
graphics.drawText(label,0,texty,DrawStyle.ELLIPSIS,getWidth());
}
}
public boolean isFocusable() {
return true;
}
protected void onFocus(int direction) {
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean keyChar(char character, int status, int time) {
if (character == Keypad.KEY_ENTER) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}
When you create the button you need to pass the Field.FIELD_HCENTER flag as one of your style flags.
CustomButtonField button = new CustomButtonField("TestLabel", Field.FIELD_HCENTER);

Resources