When your content is so riveting that your users can’t take their eyes off the screen, the last thing you want is the screen dimming and breaking that immersion. Thankfully, BlackBerry 10 offers a simple API to keep the screen from dimming, which conveniently handles things like the user putting the application in the background. Just a few weeks ago, I wrapped up this simple API in a WebWorks Extension using our new Extension Template. I’ve already heard from a few happy developers who have included it in their apps, but there are plenty of use cases, so I figured it would be good to share with the wider developer community. Just remember to use this one properly – turn it on only when displaying content where the user is going to be viewing the screen but not interacting with it. Your users will thank you for being able to see your content, and also for not keeping the screen on when it’s not necessary.

var setting = true; // boolean
var result = community.preventsleep.setPreventSleep(setting);
// Result is a string value for debugging
var currentSetting = community.preventsleep.isSleepPrevented;
// boolean value for the state of the screen

Thanks for checking it out and if you’ve got any issues, please post them on GitHub. Now your slideshow app of animated cat gifs can be realized in all its deserving glory.

]]>http://devblog.blackberry.com/2013/03/stop-sleep-webworks-apps/feed/0timwin1Sublime BlackBerry 10 WebWorks Developmenthttp://devblog.blackberry.com/2013/02/sublime-blackberry-10-webworks-development/
http://devblog.blackberry.com/2013/02/sublime-blackberry-10-webworks-development/#commentsThu, 28 Feb 2013 19:28:00 +0000http://devblog.blackberry.com/?p=13978/ Read More]]>At the risk of broaching a topic that is potentially more volatile than politics, religion, or semi-colons in JavaScript, let’s talk a little bit about development environments for BlackBerry 10 WebWorks. Now, while I’m going to talk about one development environment in particular in this blog post, one of the great things about BlackBerry 10 WebWorks development is that you can use any tool you want.

What I’d like to present is one option and some suggestions for being productive in it, but I’d very much like to hear from you through the comments or email what you use, and if you are interested I’d like to collaborate on a blog post about using your favourite IDE and how to get the most out of it. My goal is to make developing BlackBerry 10 HTML5 apps as easy as this:

The editor that I want to talk about today is called Sublime. You can evaluate it for free, it’s fully cross platform, and even has portable versions so you can keep it on a USB key. There are plenty of cool features and I could never cover them all, but the first thing you want to do is install the package control plugin, and then all the other packages are just keystrokes away: Ctrl-Shift-P and choose “Package Control: Install Package”.

Some recommended packages to get you started are as follows:

SublimeLinter

All Autocomplete

Markdown Preview

Color Schemes by carlcalderon (Stereokai is my choice)

One of my favourite capabilities of Sublime is its Build System integration. I put together a video showing how to setup our BlackBerry 10 WebWorks Ant Build Script with Sublime, so you can see how easy it is:

In the interest of full disclosure, I admit that the BlackBerry 10 WebWorks extensions scared me a little when I first looked at them. It’s been a long time since I really wrote C++ code. We won’t dwell on how long it’s been, but let’s say it’s been long enough. And, when I looked at the memory sample, it didn’t get me to the point of being really confident in how to approach extensions. Though we called it a template, it was more accurately a small example. That said, the potential of extensions, and the cool native APIs that we could be accessing in WebWorks apps kept me thinking about ways to get better at them, and make it easier. Now, after consulting with the experts in the WebWorks team, and studying the source of many core extensions, I’m quite happy to say that we have a new template for WebWorks Extensions.

Now the template is designed as a real starting point for creating extensions, with examples for all the most common ways that the JavaScript layer needs to talk to the native layer. We haven’t changed the fact that you will be writing C, C++, or Qt code on the other end, but we have made it much easier to get right to that code instead of learning about what’s in the middle. Here’s what the template provides:

Synchronous and Asynchronous method templates

Sending and receiving text and numeric values

Sending and receiving JSON values

Starting and stopping native threads

Receiving ongoing callback events from native

Defining a custom property in the extension

Ant Build Script for packaging and installation in the WebWorks SDK

The results from the developers who have used the new template are superb – not only do we have some new extensions being built and contributed, but developers have confidence in what they need to do and the possibilities unlocked are immediately visible in their faces when they get coding. And, when you can focus on the code, it turns out that native code isn’t so bad after all: The rabbit hole turns out to be an underground railway with free WiFi. So, give it a shot and let’s create some cool extensions for BlackBerry 10 WebWorks.

When we first released our porting guide for webOS developers, it was admittedly more focused on migrating from Enyo to standard HTML5. However, since both Enyo 1.0 and 2.0 are open source and run on the BlackBerry® WebKit Browser, it’s actually even easier to get Enyo applications running on the BlackBerry platform, and we’ll be updating our guide in the next couple weeks as well. All you need to get started is available right now though, so let’s take a look.

Enyo 1.0 comes directly from the webOS platform and is designed specifically for that OS, but its main requirement is WebKit, so it’s possible to make it work with BlackBerry 6 OS and up, including the BlackBerry PlayBook™ tablet and BlackBerry 10. At approximately 7MB, Enyo 1.0 is pretty large, and this can be a problem on our OS 6 and BlackBerry 7 OS phones as it’s approaching the size limit for an application install on those phones. However, that’s not an issue on the BlackBerry PlayBook tablet and BlackBerry 10. View this sample on Github to see how to create a BlackBerry® WebWorks™ config.xml for the Enyo Style Matters sample.

Enyo 2.0 is a new framework based on the ideas behind Enyo 1.0, but now built with cross-platform and mobile targets in mind first. It’s light-weight, highly extensible, and works great on BlackBerry. See this sample on Github for the Enyo Onyx Sampler as a BlackBerry WebWorks application.

If you have an Enyo application and you are looking for a profitable market place, the BlackBerry App World™ storefront should be top of your list. Enyo based applications are well received and BlackBerry App World is a marketplace where developers do well, with 13% making more than $100,000. I’d love to hear from you if you have any questions and to take a look at your applications. Drop me a line at twindsor at rim dot com, or @timothywindsor on Twitter.