📜 ⬆️ ⬇️

2GIS for Blackberry 10

2GIS always strives to satisfy user requests, trying to be present on all key platforms. Especially, if we are talking about countries in which we plan to leave in the future.

November 12, the number of platforms on which there are 2GIS, replenished with one more - Blackberry 10 .


In connection with this significant event, I want to share some points related to the experience of porting.

The task was set simply and concisely: “try to port the existing code base to a new platform”.
')
Realizing that the adaptation of a large code base to a new platform, as a rule, is associated with a different set of difficulties, you begin to unwittingly calculate the terrible pictures of long hard work and complete hopelessness. But it is at first. The eyes are afraid, and the hands are doing.

After going to the site with the documentation, you can be pleasantly surprised by the support of several popular development platforms at once. Namely AIR SDK, WebWorks SDK, Android SDK and Native SDK.

The first two, I hope, for obvious reasons, were not considered.



Having a ready application for Android, we are looking at what can be done.
In fact, it turns out that the ability of BlackBerry OS 10.1 to run Android applications, unfortunately, does not apply to programs written using the NDK .

But it is no secret for anyone that most of our mobile products are tied to the Qt framework to one degree or another, which completely deprives the possibility of launching the application after a banal repackaging of the installation package.

After examining the possibilities of "native" tools, we understand that the task of porting is greatly simplified, since BlackBerry 10 includes a large set of libraries , including the Qt framework.

In general, BlackBerry 10 offers 2 + 1 basic ways to create a native application.

Native core offers enhanced interaction with the system and hardware, but in our case it makes no sense to use it, since there is a good wrapper in the form of Qt.

Unfortunately, upon closer inspection, unpleasant nuances emerge.
BlackBerry created a stunning graphical Qca-based Cascades framework that is slightly less than completely incompatible with QApplication.

The 2GIS interface, in general, is self-sufficient and can survive the lack of native user interaction mechanisms. At least at first.

But not Cascades united. Fortunately, the BlackBerry 10 was left unfairly deprived of attention the possibility of creating applications based on QtGui. In our case, this toolkit is convenient because there is no need to radically rework the code base. There remains the flexible ability to interact with core native components or with some parts of Cascades.



The porting process itself was relatively simple. As an assembly environment is used:


A lot has already been said about setting up the build environment, so I won’t repeat much, just to remind you once again that NDK is 32-bit. For linux 64-bit, 32-bit libraries are required. On Ubuntu, this is solved like this: "sudo apt-get install ia32-libs".

Since the application was originally designed as a cross-platform, most of the work comes down to adding the necessary libraries and twisting the settings. For example, due to the slow work of QGLWidget, it was necessary to temporarily abandon the smoothing in the form of multisampling, but due to the high dpi it does not interfere.

A small number of problems fell on QNX features, such as using gulliver.h instead of endian.h.

In general, most of the time was spent searching for platform settings evenly scattered throughout the code by various teams.

After the first successful launch of optimism has increased significantly.
Correction of the theme required only "square" screens 720x720. This screen is now equipped with two devices from the Bold series: Q10 and Q5. The program automatically selects the pre-loaded start screen saver, with this, too, especially no problems have arisen.

Porting the existing codebase is a big deal, but this is only half the battle. The program should be able to receive information from various sensors, positioning systems and be able to interact with the user through some system tools, such as “send SMS” or “dial a number”.

Working with sensors is very conveniently implemented through Qt Mobility. More information about working with a compass and other sensors can be found on this page .

Positioning is done through the QtLocationSubset API.
Thanks to Qt's convenient wrapper around native methods , working with navigation also causes no problems.

To interact with embedded applications, the Invocation framework is used .

The call mechanism is quite simple.
For example, you can use the following code to preview and send e-mail:

bool SendMail(QString addr, QString subject, QString text) { InvokeRequest request; request.setTarget("sys.pim.uib.email.hybridcomposer"); request.setAction("bb.action.SENDEMAIL"); request.setMimeType("text/plain"); request.setUri(QUrl(QString("mailto:%1?&subject=%2&body=%3").arg(addr,subject,text))); InvokeManager invokeManager; return invokeManager.invoke(request); } 


In general, despite the majority of positives, there are a couple of fly in the ointment a number of problems associated with the flaws / features of the QPA plug-in.

The first problem is the non-working / missing “cover frame” (miniature of the window in a minimized state) in QtGui applications, which, along with the general styling, is out of tune.

Realizing that the problems lie somewhere in the depths of the plugin we are looking for and find the following lines of code:

  case NAVIGATOR_WINDOW_STATE: { const navigator_window_state_t state = navigator_event_get_window_state(event); const QByteArray id(navigator_event_get_groupid(event)); switch (state) { case NAVIGATOR_WINDOW_FULLSCREEN: mNavigatorEventHandler->handleWindowGroupStateChanged(id, Qt::WindowFullScreen); break; case NAVIGATOR_WINDOW_THUMBNAIL: mNavigatorEventHandler->handleWindowGroupStateChanged(id, Qt::WindowMinimized); break; case NAVIGATOR_WINDOW_INVISIBLE: mNavigatorEventHandler->handleWindowGroupDeactivated(id); break; } break; } 


If there is no desire to rebuild the plugin, this problem can be circumvented using QAbstractEventDispatcher.

 #include <bps/bps.h> #include <bps/navigator.h> #include <bps/screen.h> #include <QAbstractEventDispatcher> #include <QApplication> static QAbstractEventDispatcher::EventFilter previous_event_filter = 0; static bool blackberry_event_filter(void *message) { bps_event_t* const event = static_cast<bps_event_t*>(message); if (event && bps_event_get_domain(event) == navigator_get_domain()) { if (bps_event_get_code(event) == NAVIGATOR_WINDOW_STATE) { if(navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_THUMBNAIL) { return false; } } } if (previous_event_filter) { return previous_event_filter(message); } else { return false; } } int main(int argc, char *argv[]) { QApplication a(argc, argv); previous_event_filter = QAbstractEventDispatcher::instance()->setEventFilter(blackberry_event_filter); /* -  PROFIT!!!!! */ return a.exec(); } 


The second problem is the keyboard. Rather, support for a physical keyboard, or more precisely, a change in layout. Changing the layout is simply not supported in QtGui applications. Salvation comes from the crutches, with which, if you really need, you can not disdain. The essence of the crutch is reduced to the interception of key combinations and broadcasting the events of clicks with the desired locale.

Despite minor inconveniences and shortcomings on the part of the QPA plugin, the platform leaves a lot of positive emotions. As evidence of the viability of this platform, it can be said that the main work on porting and bringing to the alpha release took less than two weeks of efforts by a single developer.

The application is available in the BlackBerry App World , and on November 29 the first update was released for it.

You can download applications for other platforms in the respective stores: iOS , WP , Android .

If you accidentally missed the fact that we have released a new 2GIS (beta) , then we suggest that you familiarize yourself with it.

And yes, Kiev will also be, but later .

Source: https://habr.com/ru/post/204646/


All Articles