have developed an app for BB storm while tilting the device the background image of the app screen does not matches with the screen size, i have tried with the sublayout method
public void sublayout(int width, int height)
{
//update scrren layout based on orientation
if(Display.getOrientation()== Display.ORIENTATION_LANDSCAPE)
{
invalidate();
}
else if(Display.getOrientation()== Display.ORIENTATION_PORTRAIT)
{
invalidate();
}
super.sublayout(width, height);
}
Still not successfull can any one help to sort out this tilt issue in BB storm
Thanks
SujithRavindran
Rapidvaluesolutions
You are calling invalidate() but not doing anything to change the actual background image. You'll probably want to change the image for your BitmapField (or whatever you're using for the background), and then call invalidate().
You don't need to call invalidate() as part of your sublayout method. Layout happens first, and then your screen is automatically invalidated by the system.
Also, updating the layout in your sublayout method will trigger a second layout.
Related
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 make code to Blackberry Storm. When my application in horizontal display (480x360), it's work. But when the Blackberry tilt into Vertical (360x480), the picture is cut off. So I was asking how to set up so that at the time of rotation, also resize the picture? is there any method to check if BlackBerry again horizontal or vertical display?
Thanks.
Here are two things, either you will lock screen orientation or you will support in your application.
Code sample: Retrieving screen orientation
switch(Display.getOrientation())
{
case Display.ORIENTATION_LANDSCAPE:
Dialog.alert("Screen orientation is landscape"); break;
case Display.ORIENTATION_PORTRAIT:
Dialog.alert("Screen orientation is portrait"); break;
case Display.ORIENTATION_SQUARE:
Dialog.alert("Screen orientation is square"); break;
default:
Dialog.alert("Screen orientation is not known"); break;
}
Code sample: Forcing portrait view in a BlackBerry API application
// Use code like this before invoking UiApplication.pushScreen()
int direction = Display.DIRECTION_NORTH;
Ui.getUiEngineInstance().setAcceptableDirections(direction);
You you want to handle the images and other graphics setup on orientation change then you can do the following changes in your code.
Override the sublayout method, in your MainScreen subclass.
protected void sublayout(int arg0, int arg1) {
// do all the
super.sublayout(arg0, arg1);
}
Check for the orientation changes, rearrange the UI. Usages of relative layout is recommended for such things.
Hope, this might help you out. For more info visit Specifying_display_direction_of_screen
Edit: override sublayout() and then write the code specific to orientation
public void sublayout(int width, int height) {
switch(Display.getOrientation())
{
case Display.ORIENTATION_LANDSCAPE:
// write the piece of code for refreshing the screen UI which screen orientation is landscape
break;
case Display.ORIENTATION_PORTRAIT:
// write the piece of code for refreshing the screen UI which screen orientation is portrait
break;
}
super.sublayout(width, height);
}
Edit 2:
you were going wrong because of UI event lock, now you do the following changes to your code.
public void sublayout(int maxWidth, int maxHeight) {
int displayWidth = deviceWidth;
int displayHeight = deviceHeight;
switch (Display.getOrientation()) {
case Display.ORIENTATION_LANDSCAPE:
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Screen orientation is landscape");
// here you need to change your uI code as you want to do in for landscape mode
// you may need to delete and add the UI comps manually
// if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size
}
});
break;
case Display.ORIENTATION_PORTRAIT:
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Screen orientation is PORTRAIT:");
// here you need to change your uI code as you want to do in for PORTRAIT mode
// you may need to delete and add the UI comps manually
// if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size
}
});
break;
}
super.sublayout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
Well I faced this problem before and solved it. The solution is not to "oblige the blackberry screen not to rotate". I made this before and it is annoying. Well the solution to this is override the subLayout method of the main screen and all the managers included in the main screen. This method is always called when a rotation occurs.
Your code will looks like follows:
public void sublayout(int width, int height) {
changeImage(); // this method will change your image x and y and then draw it again
super.sublayout(width, height);
}
Why getHeight after setTitle equal null?
How do I get the actual height value?
public class ActivityScreen extends MainScreen {
/**
* Creates new instance Activity screen
*/
public ActivityScreen() {
super();
TitleFieldManager titleField = new TitleFieldManager(Display.getWidth());
super.setTitle(titleField);
if (titleField.getHeight() == 0) {
// Why titleField.getHeight() == 0 ?
}
}
}
Because you are calling titleField.getHeight() in the screen's constructor. At this point the UI framework has not passed the layouting/measuring process for the screen yet. If for instance, you will call the same titleField.getHeight() after at least one screen's paint(Graphics graphics) call has been executed you'll be able to get a non-zero value. All layouting/measuring is guaranteedly passed BEFORE the screen content can be drawn.
Check the Manager.sublayout(int width, int height) API. MainScreen is also a Manager. So at some point AFTER the screen has been constructed, but BEFORE it is painted, the UI framework calls its sublayout(int width, int height) where all layouting/measuring happens (all child fields get their sizes).
I'm not 100% sure of this, but I think the height of the element is calculated when the manager that contains it is laid out.
Try pushing the screen that contains that title and then calling titleField.getHeight()
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
i am developing a blackberry app. i want to paint the screen. i have implemented this
VerticalFieldManager hfmBg = new VerticalFieldManager(Field.USE_ALL_HEIGHT )
{
protected void paint(Graphics g)
{
g.setBackgroundColor(Color.SILVER);
g.clear();
super.paint(g);
}//end of paint method
};//end of vertical field manager
but tell me is there any other approach to paint the whole screen?
You have the right idea - just put that paint method in your Screen (MainScreen or FullScreen) class instead of your Manager class. You may also have to add the following empty method to your Screen class to override themes that set the default colors:
protected void applyTheme() {
}