How to determine height of the Display on Blackberry touch devices? - blackberry

I trying to determine display vertical size of my Blackberry Storm 2.
I know, my device has 480 pixels height. I try to get this value in my code, but if virtual keyboard is shown, i get value equals to 480 - (height of virtual keyboard). Is there any function to determine real display height on any device (with or without keyboard, with enabled or disabled virtual keyboard).
Im also discover RIM classes:
I get these values with hidden virtual keyboard:
Display.getWidth(); //360
Display.getHeight(); //480
UiApplication.getUiApplication().getActiveScreen().getContentWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getContentHeight(); //480
UiApplication.getUiApplication().getActiveScreen().getWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getHeight(); //480
UiApplication.getUiApplication().getActiveScreen().getVirtualWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getVirtualHeight(); //480
UiApplication.getUiApplication().getActiveScreen().getVisibleWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getVisibleHeight(); //480
I get these values with showed virtual keyboard:
Display.getWidth(); //360
Display.getHeight(); //248
UiApplication.getUiApplication().getActiveScreen().getContentWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getContentHeight(); //248
UiApplication.getUiApplication().getActiveScreen().getWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getHeight(); //248
UiApplication.getUiApplication().getActiveScreen().getVirtualWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getVirtualHeight(); //248
UiApplication.getUiApplication().getActiveScreen().getVisibleWidth(); //360
UiApplication.getUiApplication().getActiveScreen().getVisibleHeight(); //248
Is there any way to determine real screen height?

I would like to know workaround too
In the meantime you can store size of display for different devices and retrieve them depending on DeviceInfo.getDeviceName()
Or you can save Display.getHeight() value on app start

Related

Designing Portrait Game for Iphone X in Unity

I am attempting to make a game in unity and have been playing around with the notch of my new iPhone X. I understand that there are new safety margins that we have to now place UI elements in order to make sure they are not being cropped off by the notch or home gesture bar.
When I try and place a UI element near the top right of the screen, however, the placement is going to look different on iPhone X then on iPhone 7.
For example, if I place a UI element 35 units down and to the left of the right edge of the screen. On an iPhone7 the UI element will be placed 35 units down from the top of the usable screen whereas on the iPhoneX the UI element will be placed a total of 35 units minus the screen notch height from the top of the usable screen (lets say 5 units if the notch is 20 units)
Here is an image of what I am talking about:
SO my question is, how do I make the UI element 35 from the top of the "usable" screen? I guess the problem I have with the current solution is that if the game is run on a phone that has no notch, there will be a big blank space at the top.
So I found a solution, not a perfect solution but still a solution. I am first detecting if the device is a generation X iPhone and if this is true set the y position of the UI element to the Screen.safeArea.max.y position.
I would still like to see other solutions to this.
Here is my code:
if (UnityEngine.iOS.Device.generation == UnityEngine.iOS.DeviceGeneration.iPhoneX)
{
theImage.transform.position = new Vector2(theImage.transform.position.x, Screen.safeArea.max.y);
}
You can use Unity's Screen.safeArea method to get the generic safe area of any iPhone. Use this to create a reactive safe area parent panel, then create your child image anchored 35 pixels out from the top right of the safe panel.
This will be a more generic solution than hardcoding to a device, as future versions of the iPhone X (Xs, Xs Max, XR) and other notched Android phones may not have the same sized notch. It will also account for the Home indicator and side safe areas when in landscape mode.
This requires Unity 2017.2.1+. The safe area panel should be a full screen UI panel (Anchor 0,0 to 1,1; Pivot 0.5,0.5). Also recommended to have your Canvas set to "Scale With Screen Size" and "Match (Width-Height)" = 0.5, in order to match any screen size and orientation.
You can use this script for the safe area parent panel:
public class SafeArea : MonoBehaviour
{
RectTransform Panel;
Rect LastSafeArea = new Rect (0, 0, 0, 0);
void Awake ()
{
Panel = GetComponent<RectTransform> ();
Refresh ();
}
void Update ()
{
Refresh ();
}
void Refresh ()
{
Rect safeArea = GetSafeArea ();
if (safeArea != LastSafeArea)
ApplySafeArea (safeArea);
}
Rect GetSafeArea ()
{
return Screen.safeArea;
}
void ApplySafeArea (Rect r)
{
LastSafeArea = r;
Vector2 anchorMin = r.position;
Vector2 anchorMax = r.position + r.size;
anchorMin.x /= Screen.width;
anchorMin.y /= Screen.height;
anchorMax.x /= Screen.width;
anchorMax.y /= Screen.height;
Panel.anchorMin = anchorMin;
Panel.anchorMax = anchorMax;
}
}
For a more in depth breakdown, I've written a detailed article with screenshots here: https://connect.unity.com/p/updating-your-gui-for-the-iphone-x-and-other-notched-devices. Hope it helps!

VirtualTreeView node height based on icon font size

I am trying to set node height based on system icon font size.
My code so far:
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
if (SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
{
// This is a hack because font height itself doesn't give me correct node height - everything is too tight
int Height = VST->DefaultNodeHeight - abs(VST->Font->Height)+1;
VST->DefaultNodeHeight = abs(lf.lfHeight)+Height;
VST->Font->Name = lf.lfFaceName;
VST->Font->Height = lf.lfHeight;
}
The above works but I cannot get the DefaultNodeHeight right - it is not the same size as default used when font is fixed. Font height is good.
How can I retrieve the correct value from the system, or auto-size VirtualTreeView to use correct node height which would be the same as default but based on above code?
Default font height is -14, font size is 8 and node height is 18.
So in other words I need:
a) icon font size
b) appropriate DefaultNodeHeight, based on font size (in case if I use different font size, then DefaultNodeHeight is recalculated based on that particular size)

radio button not visible in a HorizontalFieldManager in blackberry?

I am working on a blackberry application which includes radio button controls.
HorizontalFieldManager hr = new HorizontalFieldManager();
setTitle("UI Component Sample");
RadioButtonGroup rbg = new RadioButtonGroup();
RadioButtonField r1 = new RadioButtonField("Option 1",rbg,true);
RadioButtonField r2 = new RadioButtonField("Option 2",rbg,false);
hr.add(r1);
hr.add(r2);
add(hr);
Working with this code I can see my both radio buttons in curve device but when I install my app in Torch device, only 1st radio button is visible on the screen.
Getting problem in showing one radio group in a horizontal field.
It works when i use a vertical field for a group.
And Horizontal and vertical both works when i works on curve device.
Please suggest what type of bus or problem this is.
In OS 6, RadioButtonField causes some problem regarding its width. Overriding the layout(int, int) method may solve your problem. Try following code.
RadioButtonGroup rbg = new RadioButtonGroup();
RadioButtonField rbf = new RadioButtonField("Label", rbg, true) {
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};

How to Increase the row height of the selected item of listfield

I am using a ListField for my app to show the data in a list. Now my requirement is that i want to increase the row height of the selected item of the list.
For this, i created a GridFieldManager and populated my list using this manager. I then override the onFocus() method of this manager. But, this method is never invoked. As a result i am unable to increase the height of the selected row item.
Please help.
ListField rows are all designed to be uniformly sized, so unfortunately you won't be able to directly change the size of one row. It's possible you can emulate it by setting it so that the row above and below draw a little bit of the focus color at the bottom and top respectively. Alternatively, you could have one field that just stays centered above whatever row is focused. Then redraw this "floating Field" with the information from the selected row.
I got it working. I faked the ListField implementation. I removed ListField and replaced it with VerticalFieldManager. I adjusted its size during onfocus() and onUnfocus() and used sublayout() to change the height of this manager. Its working exactly the way i want.
you can increase the row height/font text/...
as ultimately, all of the api's call canvas's paint methods
how to do:
//try playing with the font_type,font height
Font myFont = Font.getDefault().derive(Font.PLAIN, 14, Ui.UNITS_px);
private class ListCallback implements ListFieldCallback {
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
g.setFont(myFont);
String text = (String)listElements.elementAt(index);
g.drawText(text, 0, y, 0, w);
//you can increase the height of a particular row in the height parameter.
// if you want it to be specific, put an 'if conditon'
EX: if(index=1)
{
w+=10;
}
}
}

Horizontal blackberry file manager

i have a horizontal file manager on a screen ...and a vertical field manager inside the horizontal field manager..but the height of the vertical field manager increases and decreases due to adding and deleting fields dynamically... and the height of the horizontal file manager changes accordingly which i don't want...i want to fix the height of the horizontal file manager to a specific height..which would be max val for vertical field manager...
how can i do this...
try this code
HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR){
protected void sublayout(int maxWidth, int maxHeight) {
maxHeight = specificHeight;
super.sublayout(maxWidth, maxHeight);
}
};

Resources