07-04-2011 02:11 PM
Hi all,
Is it possible to get the landscape width of a screen (or just the Display) while the device is at portrait orientation and without physically rotating/tilting the device? and vice versa?
The only way I can think of is to force the screen into, say, landscape orientation (via Ui.getUiEngineInstance().setAcceptableDirections(D
Any help?
Thanks
Solved! Go to Solution.
07-04-2011 03:24 PM
07-04-2011 04:08 PM
OK, let me ask it a different way. I have a CustomButton class that extends ButtonField and I use in various other classes in my project. The constructor takes the label of the button and the width of the button. That way I can create a button that's, say, Display.getWidth()/2, or have the width based off of a PopupScreen the button is in. I then override the paint method for my button:
protected void paint(Graphics graphics)
{
graphics.setColor(curColor);
graphics.fillRect(0, 0, width(), height + padding);
setBorder(BorderFactory.createRoundedBorder(border Pad, curColor, Border.STYLE_FILLED));
graphics.setColor(Color.BLACK);
graphics.drawText(text, (width() - graphics.getFont().getAdvance(text))/2, (height - graphics.getFont().getHeight())/2);
}The width() method is a private method that returns the width of the button.
The problem comes when the phone is tilted (such as on a Storm 9530) the width is fixed. I was looking for a way to dynamically change this when the orientation changes. I thought I could do this by changing the constructor to take the label and then two widths, portrait and landscape:
public CustomButton(String text, int landWidth, int portWidth)
{
super(Field.FOCUSABLE | ButtonField.CONSUME_CLICK);
this.text = text;
this.landWidth = landWidth;
this.portWidth = portWidth;
height = Font.getDefault().getHeight();
curColor = unFocusColor;
}
Then in the width() method decide the orientation of the Display and return the appropriate width:
private int width()
{
if(Display.getOrientation() == Display.ORIENTATION_PORTRAIT || Display.getOrientation() == Display.ORIENTATION_SQUARE)
return portWidth;
if(Display.getOrientation() == Display.ORIENTATION_LANDSCAPE)
return landWidth;
return 0;
}
Let me know if that doesn't explain my problem clearly. Thanks for the help.
07-04-2011 04:56 PM
07-06-2011 09:15 AM