I am adding a VerticalFieldManager to a screen. I'm painting a background image and to remove whitespace at the bottom of screen when user scrolls down im overriding sublayout in my verticalfieldmanager like so:
protected void sublayout( int maxWidth, int maxHeight ) {
super.sublayout( maxWidth, maxHeight );
setExtent(maxWidth,Constants.BACKGROUND_IMAGE.getHeight());
}
This doesn't work -- white space appears at the bottom of the screen when the user scrolls down. I thought overriding sublayout, using the same code, on the screen object would take precedence over the VerticalFieldManager, which is a child of the screen.
A couple things to check. If, on your MainScreen, you're calling super(VERTICAL_SCROLL | USE_ALL_WIDTH) then your Screen's manager will be the one actually scrolling down, not the VFM you've customized. You may try overriding the paint() method of your VFM and do something as such:
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, getVerticalScroll(), bg.getWidth(), bg.getHeight(), bg, 0, 0);
super.paint(graphics);
}
Which should make your background "move" with the scroll.
Related
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.
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){};
I have a screen with a background image being rendered like so:
bg = new VerticalFieldManager(
VerticalFieldManager.USE_ALL_WIDTH |
VerticalFieldManager.USE_ALL_HEIGHT |
VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR |
VerticalFieldManager.NO_VERTICAL_SCROLLBAR |
VerticalFieldManager.NO_HORIZONTAL_SCROLL |
VerticalFieldManager.NO_VERTICAL_SCROLL) {
//Override the paint method to draw the background image.
public void paint(Graphics graphics) {
//Draw the background image and then call paint.
graphics.drawBitmap(Graphics.getScreenWidth()/2 - bgBitmap.getWidth()/2,
Graphics.getScreenHeight()/2 - bgBitmap.getHeight()/2,
bgBitmap.getWidth(), bgBitmap.getHeight(), bgBitmap, 0, 0);
super.paint(graphics);
}
};
add(bg);
Then I'm adding any fields for the screen to this manager. I have a ListField that I'd like to see the background through. When the screen is first rendered, all is well. I can see the image. As soon as I scroll down, select something and unselect it, the background disappears (turns white).
Do I need to do something special when drawing my list rows in order to make them truly transparent after the selection color is gone?
NOTE: I've found that this happens no matter what field is drawn on top of the background. It displays correctly until the selection color is drawn for a given focusable field and then you select something else. All the area that was filled with the selection color turns to the default white after unselecting it.
use invalidate() function within onfocus() and onunfocus() method.
For example if you use LabelField then use:
LabelField l=new LabelField("Hello",FOCUSABLE)
{
protected void onFocus(int direction)
{
invalidate();
super.onFocus(direction);
}
protected void onUnfocus()
{
invalidate();
super.onUnfocus();
}
};
I ended up overriding moveFocus() in my custom ListField.
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
return super.moveFocus(amount, status, time);
}
Vivek's method works well for single fields outside of a ListField row though.
In BlackBerry I have developed a screen which display a image of size
480 X 360 in background. My BB screen is of size 480 X 360. As the image is bit big in size when I scroll vertically the screen gets scrolled and disturbs my screen.
I want to lock the scrolling such that I will not be able to do vertical scrolling.
My code is as follows:
public LaunchXtcMsngrScreen()
{
int intwidth = Display.getWidth();
int intheight = Display.getHeight();
//getting the height/width of BB screen
Debugger.debug(UrlInfo.workflow_File,"Screen Height ="+intheight);
Debugger.debug(UrlInfo.workflow_File,"Screen Width ="+intwidth);
BMbackground = Bitmap.getBitmapResource("xtclogo.jpg");
VerticalFieldManager VFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH
| VerticalFieldManager.USE_ALL_HEIGHT
| VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR)
{
//Override the paint method to draw the background image.
public void paint(Graphics graphics)
{
//Draw the XTC Messenger logo
graphics.drawBitmap(0, 0,Display.getWidth(),Display.getHeight(),BMbackground, 0, 0);
super.paint(graphics);
}
};
Bitmap registerbitmap = Bitmap.getBitmapResource("register_button.PNG");
BFregister = new ImageButtonField(registerbitmap);
BFregister.setMargin(245,0,0,190);//vertical pos,0,0,horizontal pos
VFM.add(BFregister);
add(VFM);
}
add the below code as the next line of the function declaration
super(NO_VERTICAL_SCROLL|NO_VERTICAL_SCROLLBAR);
If you have placed your image inside a manager then u can follow any idea viz:
1) either create a custom manager and write setExtent(480,360) in its sublayout method.
2) you can also write setExtent(480,360) in any HorizontalfieldManager or VerticalFieldManager's sublayout method
have you tried using USE_ALL_WIDTH and USE_ALL_HEIGHT in any manager?
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