Touch screen keyboard not displaying correctly - blackberry

When the user hovers over editfield below the touch screen keyboard does not display. What is displayed is a white area that is same size as keyboard. This is an issue on BlackBerry Torch. I would expect the touch screen keyboard to appear correctly using below code ?
BasicEditField nameField =
new BasicEditField(
" "+Local.getInfo8()+ " : ", "", 100, BasicEditField.FILTER_DEFAULT)
{
private int iRectX = getFont().getAdvance(getLabel());
private int iRectWidth = backgroundButtonBitmap.getWidth() - iRectX - 4;
public int getPreferredHeight() {
return backgroundButtonBitmap.getHeight() / 2;
}
public void layout(int width, int height) {
//setExtent(width, getPreferredHeight());
super.layout(width, getPreferredHeight());
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.setBackgroundColor(Color.WHITE);
//g.drawRect(iRectX, 0, iRectWidth, 20);
super.paint(g);
}
};

On the display screen, the method sublayout was being overriden -
protected void sublayout( int maxWidth, int maxHeight ) {
super.sublayout( maxWidth, maxHeight );
setExtent(maxWidth,Constants.BACKGROUND_IMAGE.getHeight());
}
The line - setExtent(maxWidth,Constants.BACKGROUND_IMAGE.getHeight()); is causing the issue.

Related

Label caption is not set in label background center

I am working on a logic where I have to align the label caption in vertically center but it's not working.
I have tried to set text padding but the whole label with background is shifting.Is there any way to solve this.
Here is my code:
final Bitmap tabBackGroundImage1 = Bitmap.getBitmapResource("box_img.png");
homeContentManager.setBorder( BorderFactory.createBitmapBorder(
new XYEdges(16,16,16,16), tabBackGroundImage));
//homeContentManager.setBorder(roundedBourder);
//HOME SCREEN HORIZONTAL MANAGER
buddiesLabel=new LabelField("Buddies");
_bitmap = EncodedImage.getEncodedImageResource("buddies.png");
final BitmapField buddiesBmp = new BitmapField(Constant.sizePic(_bitmap,
_bitmap.getHeight(), _bitmap.getWidth()));
buddiesBmp.setMargin(3,5,0,5);
if(BuddyListField.onlineBuddyCount < 1000) {
buddyCount=new LabelField(" "+BuddyListField.onlineBuddyCount+" "){
/*public void setText(String text,int offset,int length){
text = String.valueOf(BuddyListField.onlineBuddyCount);
offset = 200;
length = 5;
super.setText(text, offset, length);
}*/
public int getPreferredHeight() {
return tabBackGroundImage1.getHeight();
}
public int getPreferredWidth() {
return tabBackGroundImage1.getWidth();
}
protected void layout(int width, int height) {
super.layout(width, height);
setExtent(Math.min(width, tabBackGroundImage1.getWidth()), Math.min(height, tabBackGroundImage1.getHeight()));
}
protected void paint(Graphics graphics) {
int deviceWidth=net.rim.device.api.system.Display.getWidth();
int deviceHeight=net.rim.device.api.system.Display.getHeight();
graphics.clear();
graphics.drawBitmap(0, 0, deviceWidth,
deviceHeight, tabBackGroundImage1, 0, 0);
super.paint(graphics);
}
};
This is the output:
But I need to set zero to vertically center in background.
Try like this
protected void paint(Graphics graphics) {
int deviceWidth=net.rim.device.api.system.Display.getWidth();
int deviceHeight=net.rim.device.api.system.Display.getHeight();
graphics.clear();
graphics.drawBitmap(0, 0, deviceWidth,
deviceHeight, tabBackGroundImage1, 0, 0);
graphics.drawText((getPreferredWidth()-getText())/2,(getPreferredHeight()-graphics.getFont().getHeight())/2,getText);
// super.paint(graphics);
}

How to display text in multiline using customized label field in Blackberry?

How to display text in multi-line using customized label field in Blackberry?
When I use following code, I can display the label with desired font size, however the problem is when the extent is limited in width the text gets cut off and not displayed entirely , also rest of the label part is not displayed on next line.
Any Help here is appreciated.
Following is my code for customized label field.
public class GrayBgLabelField extends LabelField {
private int width = Display.getWidth();
private int height = 40;
private String label;
private Font font;
public GrayBgLabelField(){
super();
}
public GrayBgLabelField(String label, int fieldWidth){
super(label, 0 );
this.label = label;
width = fieldWidth;
}
public GrayBgLabelField(String label, int fieldWidth , long style){
super( label, style );
this.label = label;
width = fieldWidth;
}
public GrayBgLabelField(String label, int fieldWidth , int fieldHeight){
this(label,fieldWidth);
this.label = label;
height = fieldHeight;
}
public GrayBgLabelField(String label, int fieldWidth , int fieldHeight, long style){
super( label, style );
this.label = label;
width = fieldWidth;
height = fieldHeight;
}
protected void layout( int maxWidth, int maxHeight)
{
super.layout( width, height);
setExtent( width, height);
}
protected void paint(Graphics g) {
if(font !=null){
g.setFont(font);
}
if (label.length() != 0) {
g.drawText(label, width/30, height/4);
}
g.setColor(Color.BLACK);
}
public void setFont(int f){
font = this.getFont().derive(f);
}
public void setFont(Font font){
this.font = font;
}
protected void paintBackground(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0xF5F6F8); // Gray-DDDDDD color code.
g.fillRect(0, 0, getWidth(), getHeight());
} finally {
g.setColor(oldColor);
}
}
}
Override methods which control width and height of your custom field.
Here is the tutorial: "How to create a custom field"
And when you change your label field text, invalidate it via invalidate() method, to redraw field contents on the screen.

How i cn set Backgroungd image in Blackberry?

i want to set background image in Vertical field manager. i had try but it not fill with height you can see that in my screen. and Following in my code what i am doing mistake please help me.
vfmCenter = new VerticalFieldManager(FIELD_HCENTER)
{
public void paint(Graphics graphics)
{
graphics.clear();
graphics.drawBitmap(0, 0,deviceWidth,deviceHeight,newimg,0,0);
super.paint(graphics);
}
protected void sublayout( int maxWidth, int maxHeight)
{
int width = Display.getWidth();
int height = Display.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};
vfmMain.add(vfmCenter);
this.add(vfmMain);
I was also facing the same issue earlier.. I solved my problem with this..
class MyClass extends MainScreen
{
// function for scaling your image to fit the screen
public EncodedImage scaleImage(EncodedImage source, int requiredWidth, int requiredHeight)
{
int currentWidthFixed32 = Fixed32.toFP(source.getWidth());
int requiredWidthFixed32 = Fixed32.toFP(requiredWidth);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int currentHeightFixed32 = Fixed32.toFP(source.getHeight());
int requiredHeightFixed32 = Fixed32.toFP(requiredHeight);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
return source.scaleImage32(scaleXFixed32, scaleYFixed32);
}
public MyClass
{
ei = EncodedImage.getEncodedImageResource("res/background_image");
ei1= scaleImage(ei,requires_width,required_height);
vfm= new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT|VerticalFieldManager.USE_ALL_WIDTH);
vfm.setBackground(BackgroundFactory.createBitmapBackground(ei1.getBitmap()));
vfm.add(new LabelField("hello notice the background behind me");
add(vfm);
}
}
Try this. I think it will work for you!!
Try like this:
VerticalFieldManager vertical=new VerticalFieldManager()
{
protected void paint(Graphics g)
{
g.drawBitmap(0, 0,Display.getWidth(), Display.getHeight(), bitmap, 0, 0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
add(vertical);
you can get.
This is the simple using getMainManager but whole background not a particular Field Manager
getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("sample.png")));

background image scroll disable in Main field manager in blackberry

In my application there is one MainScreen .This screen contain lots of Vertical and Horizontal field manager and all content display successfully with scroll .
This is my main VerticalFieldmanager code .
vfm_Main = new VerticalFieldManager()
{
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,mybackgroundImage.getWidth(),mybackgroundImage.getHeight(),mybackgroundImage,0,0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
there is one background image draw for this screen . When i scroll this screen to see the full content of this screen my Background image also scroll with the content ..for that reason background image looks so blury and it is repeat at the bottom of the screen .
i want to scroll only the content of that screen .so how to implement this ..?
i had try alot but not getting any suggetion and hits to prevent that ?
if any one facing this problem or have any idea please help me ...
Thanks in Advance !!!
You have to do like this:
vfm_Main = new VerticalFieldManager()
{
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,mybackgroundImage.getWidth(),mybackgroundImage.getHeight(),mybackgroundImage,0,0);
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
subver=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),Display.getHeight()-3);//here we scroll the inner vertical
setExtent(Display.getWidth(),Display.getHeight()-3);
}
}
//Write all the code here;
subver.setpadding(1,0,0,0);
vfm_main.add(subver);
add(vfm_Main);
Like this Image:
Enough;
I too faced the same issue once. I fixed it by using 2 field managers like this.
VerticalFieldManager mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
{
public void paint(Graphics graphics)
{
graphics.clear();
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
//this manager is used for adding the componentes
VerticalFieldManager subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};

Blackberry EditField - height changing not effective

What I try to do is to simply change the height of an EditField.
This sounds pretty easy but I facing a problem that drives me crazy.
Here is my code:
public class CMainManager extends HorizontalFieldManager
{
EditField mtxt=new EditField(EditField.FOCUSABLE | EditField.FILTER_DEFAULT);
/* Constructeur */
public CMainManager()
{
add(mtxt);
}
public int getPreferredHeight()
{
return Display.getHeight();
}
public int getPreferredWidth()
{
return Display.getWidth();
}
protected void sublayout(int width, int height)
{
layoutChild(mtxt, 50, 500);
setPositionChild(mtxt, 0, 10);
mtxt.setBackground(
BackgroundFactory.createSolidBackground(0x000000FF));
setExtent(width, height);
}
}
The line layoutChild(mtxt, 50, 500); should set the width and height of my EditField. It does, but only with the width. The height is constant. If I set it to 500 I get the same result as if I set it to 10.
Any idea of what I'm missing ? because I'm sure this is a stupid error I'm doing...
Thanks
==edit
After jproffit help, I've understood what I did wrong. However now that it works (I can set the height) I have another problem. Here is me code:
private EditField m_Txt=new EditField(EditField.FOCUSABLE |
EditField.FILTER_DEFAULT) {
protected void layout(int width, int height)
{
setExtent(Display.getWidth(), m_TxtHeight);
}
public boolean isFocusable()
{
return true;
}
protected void onFocus(int direction)
{
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
};
With this code I cannot manage the focus correctly. What do I forget ? I cannot see the cursor in my field.
Any idea ?
Thanks
You aren't telling it the dimensions to take, you're specifying the maximum amount of space it can take up. So when you tell it 10, 50, or 500, if it only want to use a height of 8 that's all it will be. You'll have to override layout() on the EditField if you want to control its dimensions as well.
Try doing like this..
create a custom editfield and inside the layout method
_editField = new EditField("", initialValueOfTextField)
{
protected void layout(int maxWidth, int maxHeight)
{
int myWidth = getMaxSize() * getFont().getAdvance("W");// define your req width
int myHeight= 50 // your required height
super.layout(myWidth, myHeight);
}
};

Resources