Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
amitginterface
Posts: 36
Registered: ‎09-28-2011
My Device: 9530

How to get screen resolution?

I want to develop one application.if I install it in Bold then it should give me screen resolution for bold if I installed it on torch then it should give it for torch likewise so how should I develop it?Any help?

Regular Contributor
heretocode
Posts: 70
Registered: ‎12-19-2011
My Device: Bold 9780

Re: How to get screen resolution?

Display.getWidth();

Display.getHeight();

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get screen resolution?

Being picky here, and people often use them in this way, but

Display.getWidth();

Display.getHeight();

are not technically the resolution of the screen.  They are the number of pixels that are contained in the screen.  Screen resolution is normally expressed in a dpi (dots per inch) measure.  For a BlackBerry device, you can obtain the resolution using
Display.getHorizontalResolution()
Display.getVerticalResolution()
This will give you pixels in a meter (i.e. the number of pixels that would be used if the screen was a meter wide/high.
 
This resolution is important if you want to scale things to look the same size on different devices.
Developer
sandeepkumar03
Posts: 117
Registered: ‎02-12-2009
My Device: Not Specified

Re: How to get screen resolution?

Hi Peter,

 

I think there are lot of discussions on forum for Designing for different screen resolutions. There were some approaches getting Display width and height and scale image based on that.

 

But as you have mentioned in post above there can be same screen size but different resolution. When I tried to use the Display.getHorizontalResolution() and Display.getVerticalResolution() on 9810 (OS 7) simulator, it printed 9661 for both. This might be OK because pixel density (ppm) might be same, But then, why the need for two separate functions in RIM JDE APIs

 

So how do we scale if we are getting same vertical/horizontal resolution?

 

Thanks and regards,

Sandeep

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get screen resolution?

[ Edited ]

Good question. 

 

I can't think of a good reason why a BlackBerry screen would have a different resolutions vertical and horizontal.  Amongst the problems this would cause is that it would change the visible aspect ratio of square Bitmaps when displayed on screen.  So I think you can safely say that the vertical and horizontal resolution will be the same and scale based on either one of these.   

 

Edit: So why did the Blackberry developers supply both?  "Just in case" is my guess.  If you think about it I'm guessing you coud find an application like, say, wide screen devices designed to play only movies, where the resolution might be different.    Just a thought...

Developer
sandeepkumar03
Posts: 117
Registered: ‎02-12-2009
My Device: Not Specified

Re: How to get screen resolution?

Thanks for your reply.

 

If we try to use resolution e.g. we are getting X value for 9810. May this would be reference against which we can try to compare the resolutions.

 

Now I have another simulator for which i am getting Y value for resolution. I can calculate Y is how much % of X and scale image for both Height and Width depending upon single value. But sometimes it may not be straight forward Width may be more than Height and we may have to scale image based on 2 values (Height/Width) instead of just resolution. What's your opinion on that?

 

I think while designing app for multiple phones (Screen size, touch, non-touch) it would be very tough to cater to all types, we may have to have seperate builds at times depending upon requirement.  Font, Layout, Images are the things which i think we need to check if we plan to target multiple phones. What could be a checklist if we plan to design for multiple devices?

 

Regards,

Sandeep

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get screen resolution?

I try to develop one code base for all devices and have the app decide at run time.  The key requirements are, as you suggest

 

a) touch verses non touch - touch devices need larger buttons for example

b) landscape verses portrait - this will determine how much you can get displayed on a specific screen.  On landscape format devices I will typically move headers and footers into the scrolling part of the screen, whereas on portrait devices you can fix the header and footer and still leave a reasonable scrolling area in between. 

 

Other aspects are typically less important.  The mechanism you suggest for scaling images works well in my experience.  If you specify fonts in points rather than pixels, then they scale themselves. If you look at the width of the screens, the number of pixels varies significantly, but the physical width of all the screens is about the same (with he exception of the pearl devices), so if you scale everything according to the pixel density (i.e. resolution) then the landscape format screens just need to scroll more. 

 

I've written a lot more about this, in one of the tutorials that you will find here:

http://supportforums.blackberry.com/t5/Java-Development/Tutorials-for-new-developers-Part-1/m-p/1621...

 

Have a look at that and tell me what you think.