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

Native Development

Reply
Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Orientation - Landscape

I've checked out the docs, and it appears that there is only one reference to displayLandcape and no mention of which way the phone is round.

 

How can I get it so that my app supports both right-landscape and left-landscape, so when you turn the phone upside down (but still landscape) the app screen rotates.

 

Thanks

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Orientation - Landscape

You can use OrientationHandler for that, like this:

 

OrientationHandler {
   onOrientationAboutToChange: {
     if (orientation == UIOrientation.Landscape) {
        //do stuff
     } else {
         //do other stuff
     }
   }
 }

 (you can check this out in Ekkes open source app, see https://ekkescorner.wordpress.com/ )

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Bluenoser
Posts: 313
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Orientation - Landscape

It's handled automatically with absolute postioning. He is what I used for testing. Just add a 300 x 300 png and try it out.

 

// Default empty project template
import bb.cascades 1.0

// creates one page with a label
Page {
    Container {
        id: rootContainer
        background: background.imagePaint
        attachedObjects: [
            ImagePaintDefinition {
                id: background
                repeatPattern: RepeatPattern.XY
                imageSource: "asset:///pattern/grasstile.png"
            },
            OrientationHandler {
                id: handler
                onOrientationAboutToChange: {
                    if (orientation == UIOrientation.Portrait) {
                        logo.preferredWidth = 150.0
                        logo.preferredHeight = 150.0
                    } else if (orientation == UIOrientation.Landscape) {
                        logo.preferredWidth = 300.0
                        logo.preferredHeight = 300.0
                    }
                }
                onOrientationChanged: {
                }
                onDisplayDirectionChanged: {
                }
            }       
            
        ]
        layout: AbsoluteLayout {
        }
        ImageView {
            id: logo
            imageSource: "asset:///images/logo300.png"
            scalingMethod: ScalingMethod.None
            layoutProperties: AbsoluteLayoutProperties {
                positionX: 50.0
                positionY: 50.0
            }
            preferredWidth: 150.0
            preferredHeight: 150.0
        }
        onCreationCompleted: {
            OrientationSupport.supportedDisplayOrientation =
            SupportedDisplayOrientation.All;
        }
    }
}

 

Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Orientation - Landscape

Sorry, this does not answer my question, you appear to have portrait orientation too. i want to know how to support both types of LANDSCAPE orientation, ideally in C++ too.
--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Developer
Bluenoser
Posts: 313
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Orientation - Landscape

If you try out the code, you will see that you get the same look whether left or right landscape mode. At least it works that way on my Alpha Dev device.

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Orientation - Landscape

it's entirely valid to want to know whether you are in a clockwise rotated landscape orientation or a counter-clockwise rotated landscape orientation.

for example, you may care about which way the accelerometers on the physical device are now oriented, or which way the camera is now positioned so that you can take pictures correctly.

 

in any event, search the Cascades docs for DisplayDirection.  You will see that this property is exposed in various orientation-related objects and handlers, etc.

 

Cheers,

Sean

 

Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Orientation - Landscape

[ Edited ]
 
--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Orientation - Landscape

[ Edited ]

I have orientation working. I can do one rotation and the display changes etc. Any subsequent orientation changes have no effect with the error:

 

Warning: bb::cascades::smileysurprised:rientationSupport(0x172668) onOrientationCheck: Wrong state when receiving orientation check: 1 

 

Any ideas?

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Orientation - Landscape

There is some sample code in the docs you might want to look at.

 

https://developer.blackberry.com/cascades/reference/bb__cascades__qmlorientationhandler.html

 

 

Super Contributor
JeffLemon
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook

Re: Orientation - Landscape

[ Edited ]

But that's for QML, not C++.

 

I converted it to C++ and I still get the same error:

 

Warning: bb::cascades::smileysurprised:rientationSupport(0x190668) onOrientationCompleted: Wrong state when receiving orientation completed: 1 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone