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
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint
Accepted Solution

Display Keep-Alive in Cascades

Hey all,

 

Just finished my first Cascades app. Love it!

The one thing I'm still looking for is some way to keep the display alive while certain things are happening in my app (playing an animation). Is there a way to (Temporarily) tell the device to not put the display to sleep in Cascades?

 

Thanks!

 

Marco

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Display Keep-Alive in Cascades

[ Edited ]

Searching for "keepawake" instead of "keepalive" leads me here: https://developer.blackberry.com/cascades/reference/bb__cascades__window.html#screenidlemode

 

(And by the way, no, I don't think that's a complete answer yet. I'm not sure how it would be used to address your question but it's going to be involved in the answer, unless you dive down to non-Cascades native stuff.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Display Keep-Alive in Cascades

That looks like what I need. Question is though: Where would I put it?

 

I have a 'Sheet' which comes up at certain times. Only when this sheet is shown I want to keep the screen alive.

I tried putting it inside the Page {}, Container{} and WebView{} (got these three nested) but for all three Momentix complains ScreenIdleMode being an unknown property.

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Display Keep-Alive in Cascades

Well, it appears you'd be expected to do this:

# presumed intended use
Application.mainWindow.screenIdleMode = ScreenIdleMode.KeepAwake;

# possible workaround for non-exported (?) name ScreenIdleMode
Application.mainWindow.screenIdleMode = 1;

That's using the fact that the main window is exposed via https://developer.blackberry.com/cascades/reference/bb__cascades__application.html#mainwindow

 

So far, it appears to be working in a "study" app I have here for experimentation.  Not when the app is minimized, mind you, which appears to be a change in behaviour from pre-BB10 where having any portion of the app's window visible was enough (when set to KeepAwake) to keep the screen from blanking. (I don't disagree with the change... having the screen controlled by apps which aren't fullscreen is a dubious situation.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Display Keep-Alive in Cascades

Sorry if this sounds ignorant but: in which file would I put this line?

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Display Keep-Alive in Cascades

Think you can put that any where as its referencing the application instance, which is a global singleton to your application

Like all of my posts
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Display Keep-Alive in Cascades

I think you could probably put that just about anywhere, Marco.

I threw it in a separate .qml component which I'm loading dynamically only when the user hits a particular button.

When I run this app and don't hit that button, the backlight dims (with my current settings) after 30s. If I hit the button and that line executes (for me, it's in an onCreationCompleted handler in the dynamically loaded .qml), then the screen doesn't blank.

You'd need to turn the idle mode back to Normal (0) again when you're done with it, since it's a global setting for the app and won't be changed back just because the Page that was visible when you set it to KeepAwake has now disappeared.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Display Keep-Alive in Cascades

Ok I now feel like an even bigger **bleep**... 

 

Can you post a QML snipped with this in it? I can't seem to figure it out :smileysad: :smileysad:

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Display Keep-Alive in Cascades

Complete QML:

import bb.cascades 1.0

Page {
    Container {
        Label {
            id: label
            text: "KeepAwake is " + (Application.mainWindow.screenIdleMode ? "ON" : "OFF")
        }

        ToggleButton {
            onCheckedChanged: Application.mainWindow.screenIdleMode = checked ? 1 : 0;
        }
    }
}

 


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Display Keep-Alive in Cascades

By the way, it appears there's a good reason why the ScreenIdleMode enum is not available to us yet.  I believe it's because it's been made private, probably by mistake:

class QT_CASCADES_EXPORT ScreenIdleMode
{
private:
    Q_GADGET
    Q_ENUMS (Type)

...

I could be wrong... not sure how things get exposed to QML in general, but I've checked some other enums to which we do have access and they have Q_ENUMS() under "public".


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.