BlackBerry textfield - blackberry

I am trying to develop an application in which text is displayed on a background image.
Text must be displayed on an image and when the background image is changed text also must change.

To achive above requirement first you need to set Background image for your MainScreen for this there are more methods one is to override paint method of MainScreen.
Example code:
Bitmap screen1=Bitmap.getBitmapResource("Screen_1.jpg");
public void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),screen1, 0, 0);
super.paint(graphics);
}
};
After setting background image for screen you need to add LabelField or RichTextField to screen.
Example:
LabelField lf=new LabelField("text",Field.USE_ALL_WIDTH|DrawStyle.HCENTER);
add(lf);
When you need to change Backgound image set.
screen1=Bitmap.getBitmapResource("you image.jpg");
lf.setText("your labelfield text");
invalidate();
Hope this will help you.

Related

How to move drop down left in blackberry + java

I am using ObjectChoiceField example. it is showing drop down at the end of right side, but i need to show some margin on the left side .
how we can achieve this ?
String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday"};
int iSetTo = 0;
VerticalFieldManager vfm=new VerticalFieldManager(){
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
};
vfm.add(new ObjectChoiceField("Day of the week",choices,iSetTo){
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
});
I am using this example:
![enter image description here][1]
You can do this with many fields by setting their margin. Field#setMargin() has been available since BBOS 6.0 officially, but was undocumented and usable in 5.0 (at least), too. So, at this point, I consider it perfectly acceptable to use in 5.0+ apps.
For example:
public ChoiceMarginScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday"};
int iSetTo = 0;
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
ObjectChoiceField days = new ObjectChoiceField("Day of the week", choices, iSetTo) {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
};
// set margin XYEdges(top, right, bottom, left):
days.setMargin(new XYEdges(0, 150, 0, 0));
vfm.add(days);
add(vfm);
}
Note that you also don't need to override the VerticalFieldManager#paint() method just to set a solid background color. You can use setBackground() for that. For setting the white font color on your object choice field, though, overriding paint() is a fine solution.
Also: I just went off your screen shot, and assumed you wanted the choice field moved to the left, but with no other field to the right of it. If you want the choice field to the left to make room for another field on its right, then you probably want to put both those fields in a HorizontalFieldManager, representing a row, and then add that HorizontalFieldManager to your VerticalFieldManager. But, that's not what you showed, so I offer my answer above.

Blackberry VerticalfieldManager virtual scroll view size too large

Developing on the blackberry (OS 7.0) and I have an extended Vertical Field manager created as such:
_myVFM = new MyViewManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT | Manager.VERTICAL_SCROLL){};
However, when I scroll the view, the virtual scroll view size appears way too big.
i.e, I can scroll quite alot further down than is needed and I cant work out why?
Any body any quick ideas? I do have a background image in there that is created as such:
public void paint(Graphics graphics)
{
Bitmap backgroundBitmap = Bitmap.getBitmapResource("bg.png");
Bitmap newBackground = new Bitmap(Display.getWidth(), Display.getHeight());
backgroundBitmap.scaleInto(newBackground, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FILL);
graphics.clear();
graphics.drawBitmap(0, 0, Display.getWidth(),
Display.getHeight(), newBackground, 0, 0);
super.paint(graphics);
}
Please and thanks,
Burrows
You can redefine the method to define the height of the manager
protected void setExtent(int width, int height) {
super.setExtent(width, myHeight);
}
To not repeat the background image is necessary to redefine the following method, returning false
protected boolean isScrollCopyable() {
return false;
}
Another comment is that it is a bad practice to obtain an image from the paint method. What you are doing is every time you call the paint method is going to get this image.
It's best to get the image once and then use it.
public MyScreen() {
super(NO_VERTICAL_SCROLL);
I managed to fix the issue in my extension of MainScreen using 'NO_VERTICAL_SCROLL' style parameter
Combined with Rupak's suggestion of setting the Background in the constructor of my Vertical Field Manager rather than overriding paint (
https://gist.github.com/3248319)
everything seems Good now - thanks all for your help.
Burrows
No need to USE_ALL_HEIGHT in your constructor.
// instead use this
_myVFM = new MyViewManager(Manager.USE_ALL_WIDTH | Manager.VERTICAL_SCROLL){};

How to remove white color around Labelfield in Blackberry

I am developing a blackberry app and I am new to Blackberry. I am using Label Field in every screens, but there is a color surrounding the LabelField other than the background I have given for the screen like the image I have given here..
This is a header in my App,which comes in every screens. Here you can see a white color around the "state editions". It does not look good. I want the orange background color at the place of white color. Thanks in advance...
You are using the following code.. (from your comment)
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER) {
public void paint(Graphics graphics) {
graphics.clear();
graphics.setColor(Color.BLACK);
graphics.setBackgroundColor(Color.ORANGE); graphics.fillRect(0, 0,0, 0);
super.paint(graphics);
}
};
Try to modify this like the following:
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER) {
public void paint(Graphics graphics) {
super.paint(graphics);
}
};
That means, you don't have to extend default LabelField.
Just use,
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER);
And check the Graphics , graphics.clear() etc in the API.

Create Transparent Mainscreen in Blackberry

i want to create a type of MainScreen in my Blackberry app which should be Transparen/Translucent.
I tried with following code on MyCustomMainScreen's constructor but it still shows a white screen
Background bg = BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50);
this.setBackground(bg);
I have read in the forum and also tested it for popup screens and it works fine with them but fails with mainscreens.
Does anyone have any idea how to achieve this for MainScreen..?
-Big O
override the paint method like:
class M extends MainScreen
{
public M()
{
setBackground(BackgroundFactory.createSolidTransparentBackground(Color.ANTIQUEWHITE, 100));
LabelField l=new LabelField("hello");
add(l);
}
protected void paint(Graphics graphics)
{
super.subpaint(graphics);
}
}
Instead of
Background bg = BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50);
this.setBackground(bg);
maybe better
Background bg = BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50);
getMainManager().setBackground(bg);
I found the solution without overriding the paint method. You need to set the background full transparent for the Screen and translucent for the main manager:
// Full transparent background
setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
// Manager translucent background
getMainManager().setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 50));

Buttons In Blackberry

I want to create a screen in which there is an image in the background and in the foreground there are two centered buttons.
When either of the buttons are clicked, I want to display new screens.
I am able to create the buttons only -- the rest I am unable to complete.
RIM offers an extensive set of Development Guides that are a good start.
You need to have a field manager to cover the entire screen. and in the paint method of that manager you need to draw the background image of entire screen size then call super.Paint()
after that you can add two buttons on the same manager.
final Bitmap bodyBG = Bitmap.getBitmapResource("body"+ApplicationUtil.getInstance().getScreenResolution()+".png");
VerticalFieldManager pannel = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL){
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(Display.getWidth(), Display.getHeight());
setExtent(Display.getWidth(), Display.getHeight());
}
protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
graphics.clear();
graphics.drawBitmap(0,0,bodyBG.getWidth(), bodyBG.getHeight(), bodyBG, 0, 0);
super.paint(graphics);
}
};
now add buttons on pannel

Resources