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);
}
}
Related
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);
Hi developers I have a screen with transparent background(bitmap). I have a list field placed on top of it, but the issue is the transparent background is not showing the previous screen, instead it shows white screen with listfield.
public class IndexScreen extends MainScreen implements ListFieldCallback {
private Vector rows;
ListField listItems;
int listItem;
int listFieldIndex = -1;
TableRowManager row;
Bitmap indexBox = Bitmap.getBitmapResource("res/screens/Index_Box.png");
public IndexScreen() {
listItems = new ListField() {
listItems.setRowHeight(20);
listItems.setCallback(this);
rows = new Vector();
listItems.setSize(rows.size());
_listVfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL) {
public void paint(Graphics g) {
g.drawBitmap(0, 0, UIinitialize.screenWidth,
UIinitialize.screenHeight, indexBox, 0, 0);
super.paint(g);
}
protected boolean navigationMovement(int dx, int dy, int status,
int time) {
return super.navigationMovement(dx, dy, status, time);
}
protected void sublayout(int maxWidth, int maxHeight) {
layoutChild(listItems, maxWidth, maxHeight);
setPositionChild(listItems, 5, 0);
setExtent(maxWidth, 255);
}
};
_listVfm.add(listItems);
add(_listVfm);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
listItems.invalidate();
}
}, 500, true);
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
TableRowManager rowManager = (TableRowManager) rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width, listItems.getRowHeight());
}
class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, 250);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.popContext();
}
protected void sublayout(int width, int height) {
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, preferredWidth, height);
setPositionChild(field, 0, 0);
setExtent(width, height);
}
public int getPreferredWidth() {
return listItems.getWidth();
}
public int getPreferredHeight() {
return listItems.getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
The above code is the part of the code that I am using.How can I implement to view the transparent background.Can anybody please help me.Thanks.
MainScreen includes its own non-transparent background. You'll have to extend Screen if you want to have a transparent/translucent background.
Another option, which I've used in my apps, is using FullScreen instead of MainScreen. FullScreen allows transparent backgrounds. If you're using setStatus or setTitle you'll have to find another method of displaying that data, but otherwise it's very similar.
From your code, though, extending Screen instead of MainScreen would likely by more appropriate.
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.
In Blackberry I want to create a class that extends HorizontalFieldManager so that I can display a label and an image on the same line with the label to the left and the image to the right.
I want the user to be able to interact with the HorizontalFieldManager as if it were a single field. I also want each HorizontalFieldManager to be focusable when added to a VeriticalFieldManager. I also want the clcik action events.
Sounds like you'll be wanting to start writing your own Field classes, here's an example to get you started:
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;
public class SimpleField extends Field {
private String label;
private Bitmap image;
private int fieldWidth;
private int fieldHeight;
private boolean hover = false;
private int focusColor = 0xcccccc;
public SimpleField(String label, Bitmap image) {
super(Field.FOCUSABLE);
this.label = label;
this.image = image;
fieldWidth = Display.getWidth();
fieldHeight = image.getHeight();
}
protected void onFocus(int direction) {
hover = true;
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
hover = false;
invalidate();
super.onUnfocus();
}
public int getPreferredWidth() {
return fieldWidth;
}
public int getPreferredHeight() {
return fieldHeight;
}
protected void layout(int width, int height) {
setExtent(fieldWidth, fieldHeight);
}
protected void paint(Graphics graphics) {
if(hover){
graphics.setColor(focusColor);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
}
graphics.drawText(label, 0, (fieldHeight - graphics.getFont().getHeight()) / 2);
graphics.drawBitmap(graphics.getFont().getAdvance(label), 0, image.getWidth(), image.getHeight(), image, 0, 0);
}
}
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);
}
}