Getting mobile screen dimensions

Hi all,
I'm developing a game which is to be played on two mobiles. I use the Canvas class to display the playing field. Both mobiles need to decide on the screen size that both mobiles can use, e.g. find the smallest size displayable in both mobiles.
I use getHeight() and getWidth() in the canvas objec MyCanvas:
    public MyCanvas(MyGame theGame, MyData theData, Font theFont) {
         myGame = theGame;
        myData = theData;
        font   = theFont;
        // Get dimensions of the screen
        height = this.getHeight();      
        width  = this.getWidth();
        myData.setFieldDimension(width, height);But if I ask to print the dimensions using:
System.out.println (" myCanvas.constructor, read height=" + height + " and width = " + width + ".");        I get:
myCanvas.constructor, read height=0 and width = 0.
Anyone know why I do not get the requested screen dimensions?
TIA,
Maik

Hi,
I appreciate the effort you both put into my problem, but your advices contradicts each other.
I set my code back to the original situation, like:
    public MyCanvas(MyGame theGame, MyData theData, Font theFont) {
         myGame = theGame;
        myData = theData;
        font   = theFont;
        // Let Server start
        isServer = true;
        // Get dimensions of the screen
        height = getHeight();      
        width  = getWidth();
        myData.setFieldDimension(width, height);
System.out.println ("myCanvas.constructor, set height=" + height + " and width = " + width + ".");       
        // Set width of the rackets
        racketWidth = width/QUOTIENT;
System.out.println ("myCanvas.setScreenDimensions, set rackets to; " + racketWidth);       
    }with the result:
myCanvas.constructor, set height=0 and width = 0.
myCanvas.setScreenDimensions, set rackets to; 0I even tried waiting until the canvas is shown by using Canvas.isShown(). But no luck in that department.
Anyone have an insight I can use?
Maik

Similar Messages

  • Getting Mobile Device (Correct) Screen Size

    I have some confusion over getting the screen size of a mobile device. I measured the following:
    var hsa:AlertObject = new AlertObject();
    hsa.alertMessage = "screen w:" +  this.stage.fullScreenWidth + "  h:" + this.stage.fullScreenHeight + "\n" +
                        "capscreen w: " + capmc.width + " h:" + capmc.height + "\n" +                    
                        "capabilites w: " + Capabilities.screenResolutionX + " h: " + Capabilities.screenResolutionY;
    hsa.open(this, false);
    I ran this on an iPod touch 4 which has a resolution of 960 X 640. The above code gives me:
    screen = 480 X 320
    capscreen (a movie clip I load that is scaled to the full screen and is displaying properly) = 1548.85 X 677 (I presume the original dimensions my designer gave the SWF).
    Capabilities = 480 X 320
    Note that 480 X 320 is precisely half of the actual screen dimensions of an iPod Touch 4. Can someone please tell me why. And, given that capscreen is displaying (properly) at the time I take these measurements and display results, why is capscreen reporting larger than the actual dimensions of the device? Also, my app orrientation is landscape only and yet the dimensions I'm getting are that width is < height which means the device is reporting in portrait mode.
    If I just need to check for iOS and then double dimensions, that's fine. But, I don't want to do that for this iPod Touch test to find it works differently on other iOS devices.
    I know that all of my screens are on the stage, BTW. I know this because I get the AlertObject to show me alerts by pressing one of the buttons of a loaded screen I am measuring - and the button is not enabled until all SWF's are finished loading and being added to stage.

    <?xml version="1.0" encoding="utf-8"?>
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark" title="NewCappoCamera" actionBarVisible="false" xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
    private function loadSWF():void {
    pictureButtons.load();
    pictureButtons.content.addEventListener(Event.ADDED, loadComplete);
    //initCamera();
    private var mc:MovieClip;
    private var hasBeenInit:Boolean = false;
    private function loadComplete(event:Event):void{
    event.target.removeEventListener(Event.ADDED, loadComplete);
    if(event.target is MovieClip && mc == null) {
    mc = MovieClip(event.target);
    mc.play();
    if(event.target.name == "acceptPicBtn") {
    acceptButton = SimpleButton(event.target);
    acceptButton.enabled = false;
    else if(event.target.name == "retakePicBtn") {
    retakeButton = SimpleButton(event.target);
    retakeButton.addEventListener(MouseEvent.CLICK, retakeClicked);
    retakeButton.enabled = false;
    else if(event.target.name == "takePicBtn") {
    cameraButton = SimpleButton(event.target);
    cameraButton.addEventListener(MouseEvent.CLICK, cameraButtonPressed);
    if(cameraButton != null && acceptButton != null
    && retakeButton != null && cameraButton != null && mc != null && !hasBeenInit) {
    mc.stop();
    pictureButtons.endEffectsStarted();
    hasBeenInit = true;
    initCamera();
    //private var numTimes:uint = 0;
    private function initCamera():void {
    cameraButton.visible = true;
    cameraButton.enabled = true;
    acceptButton.enabled = false;
    retakeButton.enabled = false;
    acceptButton.visible = false;
    retakeButton.visible = false;
    //front camera loads if they have one and it's an iOS device.
    var a:Array = Camera.names;
    var camName:String = "";
    var isAndroid:Boolean = false;
    for(var i:uint = 0; i < a.length; i++) {
    camName = a[i];
    if(camName.indexOf("Front") != -1) {
    break;
    //test if android as right now only the back camera
    ///works on that platform.
    if(Capabilities.version.indexOf('AND') != -1) {
    this.camera = Camera.getCamera();
    isAndroid = true;
    else if(camName.indexOf("Front") != -1 &&
    !isAndroid) {
    this.camera = Camera.getCamera("1");
    else {
    this.camera = Camera.getCamera();
    if(!Camera.isSupported) {
    //todo
    if(camera.muted) {
    //todo
    //following works on droid but is not working in iPod...
    //camera.setMode(
    //pictureButtons.contentWidth + this.width,
    //pictureButtons.contentHeight + this.height, 30, true);
    //the code below works on both platforms.
    var ch:Number = Capabilities.screenResolutionY;
    var cw:Number = Capabilities.screenResolutionX;
    var vidh:Number = ch;
    var vidw:Number = cw;
    if(ch > cw) {
    //in this case, the device must be registering in the portrait mode
    //multiply eveything by 2 and switch orrientation...
    vidw = ch * 2;
    vidh = cw * 2;
    camera.setMode(vidw, vidh, 30, false);
    //android dimensions have to be doubled no matter what
    else if(!(ch < cw) && isAndroid) {
    vidw = cw * 2;
    vidh = ch * 2;
    camera.setMode(vidw, vidh, 30, false);
    else {
    //otherwise, everything should already be double and there's no need to switch
    //width and height like there is above.
    //need to test that this remains the case with ipod but can't seem to get ipod
    //orientation to report other than "rotatedRight" no matter how the device is held.
    camera.setMode(vidw, vidh, 30);
    vidComponent.height = vidh;
    vidComponent.width = vidw;
    this.video = new Video();
    video.width = vidComponent.width;
    video.height = vidComponent.height;
    video.attachCamera(camera);
    vidComponent.addChild(video);
    vidComponent.visible = true;
    ]]>
    </fx:Script>
    <mx:UIComponent id="vidComponent" x="0" y="0" width="100%" height="100%"/>
        <s:Image id="capturedImage" x="0" y="0"
                 width="100%" height="100%"
                 visible="false"/>
        <s:SWFLoader
            id="pictureButtons"
            x="0" y="0"
            width="100%" height="100%"
            scaleContent="true"
            source="@Embed('assets/SignUpPicButtons.swf')"
            creationComplete="{loadSWF()}" autoLoad="false"
            />   
        <s:SWFLoader
            id="busyLoader"
            x="0" y="0"
            width="100%" height="100%"
            scaleContent="true"
            source="@Embed('assets/CheckingSWF.swf')"
            autoLoad="false"
            />
        <s:SWFLoader
            id="invisibleBusy"
            x="0" y="0"
            width="100%" height="100%"
            scaleContent="true"
            source="@Embed('assets/InvCheckingSWF.swf')"
            autoLoad="false"
            />
    </s:View>
    Let me know if you want the SWF's required to run this code.

  • I was updating software and suddenly my IPHONE  started asking for I tunes on mobile screen ,  how can  i  get by screen back or How i can restore without loosing data , I m more worried about data , Please help in resolutio

    i was updating software and suddenly my IPHONE  started asking for I tunes on mobile screen ,  how can  i  get by screen back or How i can restore without loosing data , I m more worried about data , Please help in resolutio

    What exactly are you seeing on the phone's screen ? If the iTunes icon and cable then the phone is in recovery mode, in which case it's too late to take a new backup or to copy any content off the phone - you will have to connect the phone to your computer's iTunes and reset it back to factory defaults, after which you can restore to the last backup that you took or just resync your content to it

  • Treo 800w (Sprint) Won't Get Past Windows Mobile Screen

    I've tried everything I can think of, soft reset just gets me to the Windows Mobile screen, won't get past that.  Battery has a full charge, at least according to the status light.  Kind of dead in the water.  Any ideas?  Appreciate any help that's offered, thanks.
    Post relates to: Treo 800w (Sprint)

    Hello!
    Hmmmm stuck on the load screen eh, stuck on the green screen?  If the soft reset, taking the battery out for a few sec and back in, does not work then the hard reset is the next option.  Unfortunately Windows Mobile does not have a safe mode like the ones found on PalmOS devices.  Unfortunately the hard reset will erase all data but that would not be an issue if you have been syncing the phone or using Sprite Backup provided on the ROM. 
    Post relates to: Treo 650 (Unlocked GSM)

  • Curve 8900 won't get past the T-Mobile screen on start-up

    I am hoping that someone out there can help. My T-Mobile BlackBerry Curve 8900 does not make it past the T-Mobile screen on start-up. The battery was fully charged when this happened. Personally, I think it has to do with iHeart Radio crashing, but I could be wrong. I have tried to plug the USB cord into a rear port on my laptop and launch the Blackberry Desktop Manager to see if I could do anything, but nothing happens. The BB Desktop Manager does not connect to the phone, because it is not getting past the T-Mobile screen on start-up. Not sure what to try.

    Hey VTX1300R,
    Do you have a recent backup of you device? If so the you may want to try to do a reset to factory on the device. Have a look at this article to see how to do it. http://bit.ly/98bCNO
    -SR
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • My macbook boots up get a screen picture then screen goes blank, when boots up I get the sound then a screen then screen goes black is this a battery problem or something else?

    my macbook boots up, I get a screen picture then screen goes blank...I get the start up sound, then a picture, then the screen goes blank but computer is still on..does anyone know what the problem is...do I need a new battery or am i just screwed.

    Hello nosaint1961,
    It sounds like you are unable to successfully boot your computer to your desktop. I would use the troubleshooting from the following article to help troubleshoot what is happening named:
    Troubleshooting: My computer won't turn on
    http://support.apple.com/kb/ts1367
    If your computer won't turn on, try each of these steps:
    Verify you have a good connection from your Mac to the wall outlet by confirming the power cord and adapter if present are securely connected and plugged in. To check if the wall outlet is working, plug in a lamp or other electrical device.
    If the wall outlet is working and you continue to have no power try another power cord or adapter if available. If it works you may need a replacement cord or adapter.
    Note: See Apple Portables: Troubleshooting MagSafe adapters for further troubleshooting with MagSafe adapters.
    Disconnect all accessories that are plugged in to the computer, such as a printer, hub, or other mobile device.
    If your Mac supports user-installable memory, solid state drive, or hard drive, and you recently installed any of these, make sure they are installed correctly and are compatible with your computer. If possible, reinstall the original memory or drive into the computer to find out if the behavior persists afterwards.
    MacBook Pro: How to remove or install memory
    MacBook: How to remove or install memory
    Mac Pro: How to remove or install memory
    Mac mini: How to remove or install memory
    iMac (27-inch, Late 2012): Installing or replacing memory
    iMac: How to remove or install memory
    Reset the SMC.
    If you are still unable to start up your computer after trying each of these steps, visit an Apple Store or Apple Authorized Service Provider (AASP) for further diagnosis. If you plan to visit an Apple Retail Store, make a reservation at the Genius Bar using http://www.apple.com/retail/geniusbar/ (available in some countries only).Note: Diagnostic fees may apply for issues not covered under warranty or the AppleCare Protection Plan (APP).
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • [solved] screen dimensions & xorg config

    I've been trying (finally) to improve the appearance of fonts in my system. In the process of following the wiki font configuration guide, I checked out the dpi/screen dimensions identified by xorg. According to my calculations, xorg is getting the physical dimensions of my laptop's display wrong. It correctly identifies the native resolution as 1366x768 and then uses a dpi of 96 to calculate physical dimensions:
    $ xdpyinfo | grep -B2 reso
    screen #0:
    dimensions: 1366x768 pixels (361x203 millimeters)
    resolution: 96x96 dots per inch
    However, my laptop screen is 11.6" which I think is about 256.8x144.4 mm with a dpi of 136x135. Er... ish.
    Trying to follow the wiki instructions for configuring xorg at https://wiki.archlinux.org/index.php/Xo … ze_and_DPI, I created a /etc/X11/xorg.conf.d/20-monitors.conf:
    Section "Monitor"
    Identifier "LVDS1"
    DisplaySize 256.8 144.4 # In millimeters
    EndSection
    However, this produces pretty ugly results. Fonts look all wrong - at least in some applications - and things just generally seem too big. So I removed the config file and rebooted and everything looks OK again (actually a bit better than before - probably because I'd got through part of the font config guide). I have no non-default config files under /etc/X11/xorg.conf.d/ - just default files for evdev, quirks and synaptics.
    So now I'm confused about what dimensions I should be using.
    I would have thought that with the autogenerated settings above, I should find things not fitting onto the screen because X believes that the physical screen is larger than it really is. But that's not what happens. Everything fits fine. Plus I'm not sure how to check but the resolution looks comparable to the resolution I get in the ttys.
    I'm using the intel i915 driver with various power-saving options (which don't affect display so far as I can tell). It's one of the integrated graphics chips. There's no separate graphics card to complicate (or improve!) things.
    Could somebody explain what might be going on? Or give me a reference? I don't understand how the physical dimensions X uses can be incorrect and yet everything fit and look better than when I force it to use accurate ones.
    Last edited by cfr (2012-03-06 18:31:35)

    High resolution in the TTY means that you have KMS activated, which is a good thing.
    Of course anything bigger than 96x96 or 100x100 DPI is going to look awkward, it's an 11.6 inch screen! Or did you actually try to bring a ruler to the screen and measure a 136x136 pixel image? There's this little thing called dot (pixel) pitch: 0.39, 0.33, 0.28, 0.265 mm, etc.
    http://en.wikipedia.org/wiki/Dots_per_i … _standards
    Obviously Microsoft's sneaky little hack had very long-term consequences, when instead they should've just used a better rendering method. "However, larger graphical elements meant less screen space on which to draw" - which is what you experienced when everything looked like it was on steroids.
    Another very interesting article: http://www.tested.com/news/why-pixel-de … ution/371/

  • Mobile Screen size

    Is there any way to detect the mobile screen size of a device.  I know you can get the pixel capability but some phones now have HD screens with similar pixel capacity to tablets.  My galaxy nexus is displaying the tablet version but I would rather it do the phone version.  Not sure if there is any physical size we can pull to make a more intelligent decision on which layout to show.

    The Capabilities class provides properties that describe the screen.  I've used the dpi to help make things look correctly on these different highres smaller screens.
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabiliti es.html
    Greg

  • My ipod is smashed and i need to get a new screen, my ipod is currently black, when i get my screen fixed would i be able to change it into a white one?

    My ipod is smashed and i need to get a new screen, my ipod is currently black, when i get my screen fixed would i be able to change it into a white one? and if so how much would it cost?

    First: Apple does not replace screens or repair mobile devices in any way. They will replace the device.
    Second: No. You will get the same model you had before.

  • Mobile Screen Compress Blank Field

    Hello!
    I have a problem when opening ITS mobile transaction with windows mobile 6.1 the mobile screen compress blank field
    and compress blank line. Does anyone to suggest or solution for solved the problem.
    My SAP NW 7.02 EHP5 generate template style MOBILE4 in SICF without set ~DYNPRO_COMPRESSION.
    Regrads,
    sup

    Hello Sup,
    What are the parameter settings of your ITSMobile service?
    Have you tried using the ITSGENMOBILE:  For generating style "Mobile Devices (Preserving Layout)"      
    rather than ITSGENMOBILE4:     For generating style "Mobile Devices (Without HTML Tables)"
    See the WIKI: [Getting to know ITSmobile by Checking out the Internet Services |http://wiki.sdn.sap.com/wiki/display/HOME/GettingtoknowITSmobilebyCheckingouttheInternet+Services]
    Regards,
    Oisin

  • IOS app using AS3 not fitting screen dimensions

    I'm building an iOS app using as3 and air to package the app onto my iPhone 6. My issue is that I get a black bar above and below the app, the app itself is not going fullscreen. The stage screen is set to the iPhone 6 screen dimensions.
    I have tried by adding the following launch images into the app folder; [email protected], [email protected], and [email protected] But it's not being displayed properly.
    Does anyone have any fixes for this?

    Hi ericmathew
    iPhone 6 & iPhone6+ require different Launch Images than older phones:
    For Example,
    For iPhone 6 : Default-375w-667h@2x~iphone.png
    And iPhone6+ : Default-414w-736h@3x~iphone.png
    For more details regarding this, check out below article :
    http://blogs.adobe.com/airodynamics/2015/03/09/launch-images-on-ios-with-adobe-air/
    -Tushar,
    Adobe AIR Team

  • I have purchased a movie and it has downloaded.   Next, I get a screen the says Terms and Conditions. It says to click Agree but I. Can not find Agree anywhere in the document.  how do I move forward and access the movie?

    I have purchased a movie and downloaded it. Next I get a screen that says Terms and Conditions and tells me to read and click on Agree. I cannot find the Agree anywhere in the document.  How do I move on and view the movie?

    Go to Settings>General>Usage. How much space does it show you have?
    If you connect your phone to your computer, what does iTunes say is on your phone? Do you see a large amount of "Other"? If so, you may have a corrupted database. You'll need to sync your phone then restore it as NEW (not from back up) then re-sync your data).

  • How can I get selection screen values from outside of program?

    Hi. all.
    Now. I'm developing moritoring systems and I have problems. for getting selection screen values in runtime. Is there any function, methods or structure to know this?
    I'd like to get selection screen values while several programs working in runtime and update these values to table to show current system's status and input values for users in real time.
    For example.
    Now. 3 PGMs are working on systems.
    each PGM is ZAAA01, ZAAA02, ZAAA03.
    and ZAAA01 needs input parameter P01, ZAAA02 needs input parameter P02, ZAAA03 needs input parameter P03.
    In this case, I have to know values of P01, P02 and P03.
    The mornitoring systems will show current working status of PGMs(ZAAA01~03)' and these PGMs' input values.
    As fas as I know, the structure 'SCREEN' can be used in each PGM for runtime. Is there any SAP system structure or something else for this purpose?
    I hope your hopeful repsponse.
    Thanks.

    Umm..I need to explain more about this.
    of course I know  SET, GET PARAMETERS.
    But I'd like to minimize coding for each PGM level.
    I have over hundreds PGMs and I have to develop the PGM(including tables and structures) that mornitor
    all of those PGMs on a report in real-time.
    This PGM is kind of  Process Manager.
    First I should know dialogue job PGM and background job that pass parameters using SAP(ABAP) Memory.
    And then I have to update those PGMs' input values via screens into tables in real-time.
    So, I couldn't use SET,GET PARAMETERS for this PGM.
    I want to know methods that can be used for getting information about runtime PGMs' selection screen field values in SAP systems wide.
    Please help me some one knows this.

  • Pages 2.0 will not get past the "getting started" screen

    i just updated pages to 2.0 on ipad 2 retina (ios 7.0.2) and now i cannot open pages, it will not get past the "getting started" screen
    has anyone else experienced something similar?

    Had the same problem. This sovled it for me:
    Just let it load.
    In Keynote, I didn't have so many documents, so the freeze didn't take too long- that's how I noticed it's just a freeze while loading.
    For pages it took much longer. You can also turn off iCloud in settings for Pages, Keynote, etc. open it, re-enable iCloud in settings app again and quick switch back to pages (double-click home button). It will freeze up again, but after a while after all documents have been pulled from iCloud, it will be back to normal.

  • Unable to Edit "Get Info" Screen

    After hardware failure had to rebuild comp but the drive holding all my media is intact. After rebuild, installed latest ver of iTunes. Selected "Add folder" menu option to allow iTunes to recognize that folder and reset iTunes to use this folder for its default location going forward.
    However, it seems as I have lost my organization where the individual files for a particular show for example would show up under a single a common cover art and such "TV" shows would be in the correct location. Everything is under "Movies" and when I selected "GET INFO" everything on the screen is intact but greyed and I am no longer able to edit this information.
    Any NEW items I add however that had not been previously in iTunes or part of the "ADD FOLDER" request show up with the "GET INFO" screen fully editable.
    How do I unlock the "GET INFO" screen?

    Here's what I did to "unlock" all the files. In the directory containing the media files I changed one show' extension fm .m4v to .mp4 and attempted the add files menu selection. When the episodes showed up in "movies" category window, I found the greyed out "get info" window now active for editing. I selected the entire sequence of episodes and assigned them to "TV SHOW" under options. These parked themselves properly organized under the single cover art (where before each episode would not group and listed each episode separately using the same cover art in each instance.
    When I went back and imported the next set of files, everything was free to edit so again, without understanding the reason for this lack of or access to the ability to edit the "get info" window, unable to point anyone the reason but am able to offer the workaround experience.

Maybe you are looking for