Motivated with this new technology, I decided to program a simple application for the new operating system. This post explains a little bit about the experience, describing the application and some parts of the code. As always, you can find the source code in my GitHub account, released with Apache 2.0. The project was a simple game, called SmartSeq. The game challenges the user with a sequence of letters, letting the user to guess the intrinsic pattern.
As part of the game, I programmed three different sequences:
- Natural sequence: abcdefghi.....
- Even sequence: acegik....
- Fibonacci sequence: aabceh....
Nonetheles it can be extended very easily with other mathematical sequences. In addition, to be more complete, the game should include offline storage of the scores, and some social integration. However, the initial release is enough to evaluate the development environment for BlackBerry 10.
Programming UI with Cascades
Cascades is a new framework, based on Native SDK and using Qt Libraries. The QNX Momentics IDE allows developers to create great user interfaces, highly integrated with C++ code. User Interfaces are programmed using QML, standing for Qt Modeling Language. Basic UI looks like this:import bb.cascades 1.0
// creates one page with a label
Page {
// Binding with c++ code
property alias sequenceText: sequence.text
// Basic container declaration
Container{
layout: StackLayout {}
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
}
}
You can take a look of the whole code here. Basically, the user interface includes some labels for information output and two input fields: a text field and a button. You have an UI diagram below:
property alias sequenceText: sequence.text
property alias scoreText: score.text
property alias clueText: clue.text
property alias answerText: answer.text
property alias answerEnable: answer.enabled
Then, you can read / write values from these fields from C++ simply coding:
_root->setProperty("clueText",_clue_format.arg(initialSeq)); _root->setProperty("sequenceText",_sequence); _root->setProperty("scoreText",QString("%1 pts").arg(_score));
Do publishvariables/objects in C++ code is simple. That makes them accessible from QML. You only have to code:
// create scene document from main.qml asset
// set parent to created document to ensure it exists for the whole application lifetime
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
// create root object for the UI
_root = qml->createRootObject();
qml->setContextProperty("SmartSeq",this);
Logic with pure C++
Regarding underlying logic, all is C++ code. In the case of our game, it is pretty simple. You can find all the declaration at SmarSeq.hpp file. The class diagram is below:- SmartSeq::startGame
- SmartSeq::updateGame
- SmartSeq::resetGUI
Conclusions
Honestly, I have found the new framework very interesting. I have to say that my mother programming language is C++, so there are many common ideas which are part of my developer bagage. However, for most of the mobile developers, coming mainly from existing platforms and web programming, this new languages and frameworks can mean high entry barriers. Luckily, they have alternative ways to take advantage of their knowledge in HTML5, Java or Android.In any case, the documentation, code snippets and IDE (an Eclipse customised) are very appealing. In addition, QNX is a real operating system, without many of the limitation you can find in other customized mobile platforms. My feelings are that all of this could help Blackberry to engage an even bigger developer community.
My only concern is that you will need to pay a VMware Fusion license to use the BB10 simulator. Even though it is a cheap software, it could introduce an unnecessary entry barrier. However, maybe that is precisely what Blackberry is looking for: developers who are willing to pay.
So congrats Blackberry team.
You have done a very good job.
No hay comentarios:
Publicar un comentario