This is part #2 of my blog series ‘Supporting BlackBerry Classic’ as native BlackBerry10 developer.
Please read about screen sizes and first steps here.
Shortcuts
Shortcuts are a powerful concept to help users to navigate through your app using the keyboard. BlackBerry Q10 and Q5 were the first devices with full QWERTY / QWERTZ keyboard for BlackBerry 10 followed by BlackBerry Passport. Read about differences between Q10 and Passport here.
Device Shortcuts
Doing a long-press on a key using OS 10.2 / 10.3.0 you could add a speed-dial – shortcut.
OS 10.3.1 and BlackBerry Classic are offering much more options what to do from long-pressing a key:
YES gives you some options:
From Settings | Shortcuts …
… it’s easy to get an overview of all assigned keys:
It’s a good idea to explain to your users HowTo define a shortcut to open your app with a single longpress.
Shortcuts inside your APP
The easiest way to use Shortcuts inside your App is to add them to your Actions:
actions: [ ActionItem { title: qsTr("Edit Pos") + Retranslate.onLanguageChanged imageSource: "asset:///images/ic_view_list.png" ActionBar.placement: ActionBarPlacement.Signature onTriggered: { // do your stuff } shortcuts: [ SystemShortcut { type: SystemShortcuts.Edit } ] }, ActionItem { title: qsTr("Map of this site") + Retranslate.onLanguageChanged imageSource: "asset:///images/ic_map.png" ActionBar.placement: ActionBarPlacement.InOverflow onTriggered: { // do your stuff } shortcuts: [ Shortcut { key: qsTr("m") } ] } ]
There are two different types of shortcuts:
- SystemShortcut
- Shortcut
SystemShortcuts will be translated by Cascades – to avoid collisions it’s recommended to translate your custom Shortcuts using qsTr(“xxx”)
Opening the Menu, Users will see the small letter of the shortcut – so it’s easy to learn and understand them:
You can add Shortcuts also to Tabs, Images, Pages, …
Here’s a (simplified) Layout from one of my apps where Shortcuts are defined at Page level and working great on OS 10.2.x (Q5, Q10) and also OS 10.3.0 (Passport):
Running the same app on OS 10.3.1 and BlackBerry Classic the Shortcuts stopped working.
BlackBerry Classic and Trackpad are changing the way UI Controls can be focussed or selected. (Will blog about this in Part #3)
So I tried to place the Shortcuts at the Container and it still didn’t work. Then I tried to place them at the ListView because the ListView is the UI Control the TrackPad is using to scroll and to focus. Voilá: This was working on BlackBerry Classic:
But it only works on 10.3.1 and Classic – not on 10.3.0 and Passport – so I added a switch like this:
// ... attachedObjects: [ ComponentDefinition { id: myShortcutComponent SystemShortcut { type: SystemShortcuts.Search onTriggered: { // do your stuff } } } ] // ... if (app.isPassport()){ myPage.shortcuts = [myShortcutComponent.createObject()] } else { myListView.shortcuts = [myShortcutComponent.createObject()] } ]
Now my app is working fine on 10.3.0 / 10.3.1 and Passport or Classic.
There were no problems using KeyListeners. Shortcuts are bound to a specific UI Control, where KeyListeners can be everywhere and if a Key wasn’t catched it goes up to the parent until root object is reached. I’m using KeyListener for attached external Keyboards and handling ESC for Back, Arrows etc.
Sample at Github
To see Shortcuts in action I created a sample at Github.
Curious: Now from this small sample app OS 10.3.1 and Classic also work fine using Shortcuts at Page level. Haven’t figured out what makes it different in my more complex app. At Cascades Forum I noticed that other’s also have some problems with Shortcuts on 10.3.1 / Classic. So if you’re running into this try to move the Shortcuts to the UI Control getting the focus from Trackpad.
Have Fun with the Classic and stay tuned for Part #3 about Focus and TrackPad.