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
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: Orientation - Landscape

*Bump*

 

Does anyone know how to fix this? i've read all the docs, nothing helps.

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

Re: Orientation - Landscape

I know we're using it in the camera app.  If anyone can post a simple sample, that would be appreciated.  I can probably find time to do one by the weekend.

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

Has anyone managed to figure this out yet?

Has anyone managed to figure this out yet?

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: Has anyone managed to figure this out yet?

Can a development advisor please answer this question? Orientation doesnt seem to be functioning correctly, is this a bug?

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

Re: Has anyone managed to figure this out yet?

It works fine for me.

here is the sample code I just wrote for you.

 

// Default empty project template
#include "Orientation.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Container>
#include <bb/cascades/Label>
#include <bb/cascades/OrientationSupport>
#include <bb/cascades/DockLayout>
#include <bb/cascades/Page>

using namespace bb::cascades;

// qDebug() now logs to slogger2, which I find inconvenient since the NDK does not pick this up in the console,
// so I am installing a custom handler to log to stderr.
static void log_to_stderr(QtMsgType msgType, const char *msg)
{
    (void)msgType;  // go away, warning!
    fprintf(stderr, "%s\n", msg);
}

Orientation::Orientation(bb::cascades::Application *app)
: QObject(app)
{
    qInstallMsgHandler(log_to_stderr);

    // attach handlers for pre-rotation and post-rotation debugging
    QObject::connect(
            OrientationSupport::instance(),
            SIGNAL(orientationAboutToChange(bb::cascades::UIOrientation::Type)),
            this,
            SLOT(onOrientationAboutToChange(bb::cascades::UIOrientation::Type)));

    QObject::connect(
            OrientationSupport::instance(),
            SIGNAL(orientationChanged(bb::cascades::UIOrientation::Type)),
            this,
            SLOT(onOrientationChanged(bb::cascades::UIOrientation::Type)));

    QObject::connect(
            OrientationSupport::instance(),
            SIGNAL(displayDirectionChanged(bb::cascades::DisplayDirection::Type)),
            this,
            SLOT(onDisplayDirectionChanged(bb::cascades::DisplayDirection::Type)));

    // indicate all orientations are supported
    OrientationSupport::instance()->setSupportedDisplayOrientation(
                SupportedDisplayOrientation::All);

    mLabel = Label::create("ORIENTATION?");

    Container* container = Container::create()
        .layout(DockLayout::create())
        .add(mLabel);

   app->setScene(Page::create().content(container));
}


void Orientation::onOrientationAboutToChange(bb::cascades::UIOrientation::Type orientation)
{
    qDebug() << "onOrientationAboutToChange() " << OrientationSupport::instance()->displayDirection();
    mLabel->setText(QString("onOrientationAboutToChange: ") +
                    QString::number(OrientationSupport::instance()->displayDirection()));
}


void Orientation::onOrientationChanged(bb::cascades::UIOrientation::Type orientation)
{
    qDebug() << "onOrientationChanged() " << OrientationSupport::instance()->displayDirection();
    mLabel->setText(QString("onOrientationChanged: ") +
                    QString::number(OrientationSupport::instance()->displayDirection()));
}


void Orientation::onDisplayDirectionChanged(bb::cascades::DisplayDirection::Type direction)
{
    qDebug() << "onDisplayDirectionChanged() " << direction;
    mLabel->setText(QString("onDisplayDirectionChanged: ") +
                    QString::number(direction));
}

 

I even gave you handlers for the "orientationAboutToChange", "orientationChanged" and "displayDirectionChanged" signals.

The latter is what you will need to listen to to catch changes between 90 and 270 degrees, as the other events do not fire in that case.

It should be sufficient for you to just key off of this in most cases I presume.

 

All of this was documented in the Cascades docs and I just implemented almost verbatim from the example code on this page:

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

 

Make sure your bar descriptor includes:

    <initialWindow>
        <autoOrients>true</autoOrients>

 

 

Cheers,

Sean

 

 

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

Re: Has anyone managed to figure this out yet?

[ Edited ]

Thanks, I already had something similar but it does not work.

 

Your example works for all screen orientations. I only want to support both landscape orientations.

 

If you add in <autoOrients>true</autoOrients> to the descriptor then the app starts in portrait mode even with <aspectRatio>landscape</aspectRatio>.

 

If you take out autoOrients and support only Landscape orientations:

 

 OrientationSupport::instance()->setSupportedDisplayOrientation(SupportedDisplayOrientation::DisplayLandscape);

You can rotate the screen sucessfully once and the app will rotate to the alternative landscape mode and then it refuses to rotate again, giving the error:

 

Warning: bb::cascades::OrientationSupport(0x149770) onOrientationCompleted: Wrong state when receiving orientation completed: 1 

 So, how can I only support landscape orientations?

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

Re: Has anyone managed to figure this out yet?

okay.

I can reproduce the same problem.  I will open a bug internally to track.

 

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

Re: Has anyone managed to figure this out yet?

So there is no fix at present?

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

I Re: Has anyone managed to figure this out yet?

Let's just go with "no" until I get some responses on this.

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

Re: I Re: Has anyone managed to figure this out yet?

Ok thanks, keep me updated. 

 

Cheers for looking in to this!

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