Archive for the ‘BlackBerry’ Category

oliverm

The Gist of Code Sharing

Wednesday, April 17th, 2013

Agile development teams often need to share code while in the heat of battle.

At the high end of the scale, there are publicly-accessible repositories, such as GitHub. Creating a GitHub project is obviously overkill for those wishing to simply pass a few key lines of code to their buddy in the next seat.

For stand-alone, runnable demo code, sites like Plunker and JSFiddle  are great. You will see references to these sites wherever HTML, CSS and JavaScript bugs are reported; for example stackoverflow and the AngularJS Google Group.

But again, maybe overkill for just a few lines.

So what are the other options for code sharing?

  • Email – I suppose, but there may be delays in receiving the email if your server is slow.
  • Skype or other messaging service – Alright, but you lose history eventually.
  • USB Key (sneaker-net) – It works, but it is hard to share it with a lot of people and history is also an issue.
  • Gist – This has been around a couple of years but I’ve only just discovered it since it is baked into IntelliJ/WebStorm. Gist is a GitHub sub-project and is associated with your GitHub account. For example, my GitHub account is at https://github.com/oliverm2112 and my Gists are at https://gist.github.com/oliverm2112. Gist allows developers to post snippets of code in various languages and features in-place editing and syntax highlighting.

Here is a Gist home page and a code sample:

 

 

 

 

Here is a shot of IntelliJ/WebStorm’s abilitity to create a Gist from within the IDE:

Hopefully you will find this a useful way to share information.

bslack

BlackBerry 10/Qt Libraries and Namespaces

Tuesday, April 2nd, 2013

A quick note for those developing C++ libraries with Qt (hopefully for BlackBerry 10). You should use a namespace(s) to group your library code together and to avoid conflict with other libraries and the users’ code. When working with Qt however, some extra considerations need to be taken into account if you plan on using Qt’s signal/slot mechanisms. In Qt 4.x (the latest version of Qt available for BlackBerry 10), your function signal/slot prototype declarations must match exactly. This can cause issues for users of your library if you assume that your namespace is global within your header definition. Take for instance the following code sample:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace mycompany {
namespace mylibrary {

class LibData;
class LibraryManager : public QObject {
Q_OBJECT
public:
LibraryManager(QObject *parent = NULL);
virtual ~LibraryManager();

Q_SIGNAL void dataRead(LibData &d);

};

}
}

In the above sample, the ‘dataRead’ signal provides one parameter when emitted, the LibData pointer. The LibData object is part of the mycompany::mylibrary namespace. While this will work, it potentially causes an issue for a user of your library. It forces the library user to make your namespace global within their own header file (which may or may not be intended). As an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include
#include

using namespace mycompany::mylibrary;

class MyClientClass : public QObject {
Q_OBJECT
public:
MyClientClass();
virtual ~MyClientClass();

Q_SLOT void onDataRead(LibData &d);
}

In the above case, the MyClientClass onDataRead slot must match the LibraryManager classes ‘dataRead’ signal signature, exactly. This forces the user to make the namespace global within the header file, which can somewhat defeat the purposes of namespaces. A better implementation would be to always explicitly set your namespace in your signal prototype declarations. The below snippet shows a better implementation of both the library and client code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
namespace mycompany {
namespace mylibrary {

class LibData;
class LibraryManager : public QObject {
Q_OBJECT
public:
LibraryManager(QObject *parent = NULL);
virtual ~LibraryManager();

Q_SIGNAL void dataRead(mycompany::mylibrary::LibData &d);

};

}
}
1
2
3
4
5
6
7
8
9
10
11
#include
#include

class MyClientClass : public QObject {
Q_OBJECT
public:
MyClientClass();
virtual ~MyClientClass();

Q_SLOT void onDataRead(mycompany::mylibrary::LibData &d);
}

Note how in the above example, the LibData objects namespace is explicitly declared. This eliminates the need to have the ‘using namespace mycompany::mylibrary’ definition.

Rod Nolan

Getting repetitive tasks done quickly and efficiently

Wednesday, February 20th, 2013

I’m working on a project right now where I often have to grab a master copy of a single file, paste it into my current working directory and open it for editing. My environment is Windows 7.

Since the master file exists in a static location, I wrote a batch script to copy the file into my current directory and open it.

  copy %ANT_HOME%\..\..\build.xml . /-Y
  build.xml

The first line of this script will copy the master version of build.xml into whatever directory I run it from from. The -Y option prompts me to overwrite if a file named build.xml happens to be present. The second line will open the local file in the system default editor for .xml files (if you have one configured). So it’s just two lines. Nice and simple and it sure beats doing this manually.

To make this script callable from anywhere on my file system, I placed it in a directory that is included in my PATH and I called it getBuild.bat.

At this stage, calling the script requires me to SHIFT+right-click > Open Command Prompt Here and type the name of the batch file. Too many clicks and keystrokes for my liking.

Ideally, I’d like to be able to access this functionality from the context menu and bypass the need to open the command window at all. Here’s how I did it.

  • Open regedit.exe
  • Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell
  • Add a new key called getBuild
  • Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\getBuild
  • Add a new key called command
  • Modify the (Default) value and set it to C:\Windows\System32\cmd.exe /c getBuild.bat
editing the registry to add an item to the Windows Explorer context menu

editing the registry to add an item to the Windows Explorer context menu

  • Save and close the registry editor
  • Open Windows Explorer and right click on a file in any directory to see the new context menu item. I haven’t bothered to try to make it work by right clicking anywhere so as it stands, you have to right click a file.
using the new context menu

using the new context menu

  • Next, you’ll see the prompt to overwrite the .existing file.
the batch file doing its job

the batch file doing its job

  • Answering ‘y’ opens the file in my editor.
so I can do my job

so I can do my job

 

If you’re wondering why I need to copy build.xml so often, keep an eye on this space for my next blog post. I’ll be talking about the ANT build script I wrote  to package and deploy WebWorks apps to the upcoming BB10 smartphone. But until then, happy copying. :-)

BlackBerry 10 App Dev Training Now Available!

Wednesday, December 19th, 2012

We would like to announce that detailed instructor-led BlackBerry 10 Application Development training is now available from NTG. The training is available for both WebWorks and Native Development Using Cascades and is current to the latest versions of the SDK’s on both development platforms.

For more information on the two courses, click on Developing Applications Using the BlackBerry 10 Native SDK and Cascades or Developing Applications Using the BlackBerry 10 WebWorks SDK.

We have delivered this training already to many students and have received excellent feedback.

The training can be delivered in a public NTG Learning Centre, at a private client site, or even online, whichever is most preferred. The training can also be customized in length to fit a client’s particular needs.

The training is also closely linked to the new BlackBerry 10 Developer Certification program and will provide considerable assistance for people wishing to prepare to write the upcoming App Dev certification exams.

Rod Nolan

Virtual directories with RippleSites? Sort of, sure.

Tuesday, October 16th, 2012

By Rod Nolan – consultant

I’ve always used IIS or Apache when I needed a web server in my development environment. But as a BlackBerry developer, the Ripple Mobile Environment Emulator has become a more important part of my toolkit. And the latest version includes a built in web server. So I recently put IIS on the shelf and decided to trade port 80 for port 9910.

I make regular use of virtual directories because:

  1. I don’t want to store my web sites in wwwroot/ or htdocs/ since
  2. My git repo contains EVERYTHING related to a project, not just .htm, .css and .js files and I don’t want it all accessible via http so
  3. It’s cleaner to keep the repo in one location (not wwwroot/ or htdocs/) and use virdirs to point to the “website” subsection of my  repo

But Ripple doesn’t provide any sort of standard way to configure virdirs using a GUI or config files. Fortunately, neither of these options is required when you have Windows 7, a “Run as administrator” command prompt and the mklink command.

Here’s how it works:

C:\>cd \Users\<You>\RippleSites
C:\>mklink /J siteName "C:\SomePathTo\MyRepositories\MyProject\WebRoot"

This command will create a new directory junction called

siteName

in:

C:\Users\<You>\RippleSites\

which looks and acts like a directory but is really nothing more than a pointer to the real physical location:

C:\SomePathTo\MyRepositories\MyProject\WebRoot

So that when I browse to:

http://localhost:9910/siteName/index.html

it’s this file gets served:

C:\SomePathTo\MyRepositories\MyProject\WebRoot\index.html

I can still keep everything related to the project in my repo, store that repo anywhere I choose on my local system and enable http access to only the web-related assets via Ripple’s web server. I can develop and test and emulate my mobile brains out… without using virtual directories and without manually copying files between my repo’s folder and my web server’s document root folder.

This post http://ipggi.wordpress.com/2009/09/07/windows-file-junctions-symbolic-links-and-hard-links/ helped to clarify the difference between symbolic links, hard links, soft links and junctions.

 

Ryan R

Getting Started with BB10 Development

Tuesday, July 17th, 2012

BB10 is expected to power the next-generation of RIM handsets and tablets. With four different development approaches supported, many people may wonder which approach is right for them.

The development options avaliable to BB10 developers each have pros and cons, but many developers will want to jump into development as fast as possible. To get up and running quickly, you may want to choose a path that is the most similar to your current style of development.

 

What type of developer are you?

 

 Web Developers

Web developers will feel right at home with WebWorks. WebWorks is a runtime which bundles HTML, JavaScript and (eventually) native plug-ins into a native BB10 application. Along with the provided WebWorks JavaScript API, you are free to use most of the web technologies you are already comfortable with.

 Adventurous Web Developers

If you don’t want to feel too comfortable in your new development environment, consider jumping right into Cascades. While the initial learning curve may be steeper for those without C++ experience, the payoff will be big when you realize how transferable your JavaScript skills are. Cascade applications can be created completed in QML (a declarative language used to construct UI) and JavaScript, with minimal C++ code to glue it all together.

Flash Developers

Like the PlayBook, BB10 can run Adobe AIR applications. ActionScript developers can use the same Adobe tools they are comfortable with and publish their AIR apps right onto a BB10 device with minimal effort.

Java Developers

Java Developers may find themselves torn when migrating to BB10. The only supported path to write in Java is by taking advantage of the Android Runtime bundled into BB10. However, this path should only be considered for Java developers with extensive Android experience as it has some  big drawkbacks. The biggest one being that the Android Runtime is limited to to apps built on the Android 2.3 SDK. The Android 2.3 SDK was built first and formost for Android phones, and is now almost two years old.

In my opinion, the best path forward for a Java developer wanting to get started on BB10 is to jump headfirst into Cascades development. As with the others who aren’t as comfortable with C++ there will be a learning curve, but you’ll find a lot to like about Qt (which Cascades is built ontop of) and QML.

C/C++ Developers

Anyone who’s already familiar with C or C++ should definitely jump into native development on BB10. Those comfortable with low-level C may even want to stick with it by using the NDK, especially for Game Development. Otherwise, Cascades will development will be very easy to get into, and those with Qt experience will have an even easier time. The biggest task for developers familiar with C or C++ will be exploring all the components provided by the Cascades UI library.

Porting Tips

For those lucky (or unlucky) enough to have a pre-existing code base they intend to port, the development path will depend on the original platform. Below are some additional tips for developers looking to bring over various types of projects to BB10.

WebWorks for PlayBook for BB7 (and below)

WebWorks applications built for BB7 or Playbook OS will require minimal changes to prepare for BB10. The most important change is that neither Java and ActionScript plug-ins are supported on BB10, and will need to be rewritten as (C/C++) native plug-ins.

WebOS Applications

Developers with exisiting WebOS projects can migrate them successfully to WebWorks with some reworking. WebWorks uses pure HTML and CSS to style its UI and doesn’t rely on any native elements, to reproduce the look and feel of a Cascades application in WebWorks check out the BBUI project: https://github.com/blackberry/bbUI.js/ Most functionality proviced by Enyo is provided by the blackberry object in JavaScript. 3rd party libraries, like jQuery, are recommended to fill in the missing pieces, more informaiton can be found here: https://developer.blackberry.com/html5/documentation/ww_developing/porting_webos_apps_1952251_11.html

 OpenGL-based Games

With BB10, the NDK is provided to write code completely in low level C. This, with BB10′s support for all POSIX compliant libraries, makes BB10 a great target for porting OpenGL games written in C or C++.

C Libraries

Similarly C libraries should be very easy to get compiling on BB10.

Qt Applications

Qt developers will find that QtQuick has been replaced. Existing applications will have to be adapted to the components and architecture of Cascades UI. Currently drawing shapes is not supported and only Cascades UI elements can be drawn onto the screen. Luckily Cascades supports a component called ForeignView, which can be used to drop down to the use of OpenGL drawing operations.

Android Applications

For those that do have existing Android 2.3 applications targeting the Android Runtime should take a minimal amount of effort. This is provided that your application isn’t heavily reliant on the Google Play store, or a few sensor APIs which the Android Runtime for BB10 does not support. See this API support guide for more information: https://developer.blackberry.com/android/apisupport/ .

 Everything Else

Finally, many multi-platform development toolsets like Unity and Appcelerator have begun to announce support for BB10. With these plethora of options avaliable to developers, BB10 is promising to be one of the most flexible and developer friendly mobile platforms to develop for.

 

Rod Nolan

Getting started with AIR and BB10

Wednesday, May 23rd, 2012

I just started to play with the latest BB10 SDK for Adobe AIR. I had a couple of issues right away so I’m going to document them here to save you the headache.

First, make sure you download the correct SDK. Sounds simple, I know, but it wasn’t immediately apparent that there are currently two different SDKs available for download.

  • BlackBerry PlayBook SDK for Adobe AIR, easy to find but not the one I wanted
  • BlackBerry 10 SDK for Adobe AIR beta, the one I wanted but tucked out of the way

The Tools link in the bottom half of the page points to Tablet OS SDK for Adobe AIR v2.0 which is not the right version. If you’re after the BB10 SDK, you have to click on the rotating banner above the Tools link when it comes around to the “BlackBerry 10 SDK for Adobe AIR beta now available” section. That will eventually bring you to the page where you can download the BlackBerry 10 SDK for Adobe AIR v3.0 beta. Here’s the page https://bdsc.webapps.blackberry.com/air/beta/download/sdk/ where you’ll also find the link to download the new simulator. Moral of the story: don’t ignore rotating banners.

After installing the SDK and the BB10 simulator, I tried to run the Hello World sample as described here https://bdsc.webapps.blackberry.com/air/beta/documentation/aa_getting_started_bb10/Create_your_first_application_FB_ms_2006005_11.html and I got some errors on the imports for classes from the qnx.dialog package.

I had checked this option: Project Properties > ActionScript Build Packaging > BlackBerry > Add platform specific libraries to the class path so I went on the hunt for qnx.dialog. This is what I found.

all four swcs are present...

... but there's no qnx.dialog package anywhere

I found two entries in the forums which led me to the solution but to summarize, here’s what you have to do in Flash Builder 4.6:

  • Project Properties > ActionScript Build Path > Add Folder > C:\Program Files (x86)\Research In Motion\blackberry-tablet-sdk-3.0.0\frameworks\libs\qnx\ane
  • Project Properties > ActionScript Build Packaging > BlackBerry > Native Extensions tab > turn on all the Package checkboxes (might have to scroll horizontally to see them)
This links in the additional extensions required to use all the APIs.

Read this for the background story: http://supportforums.blackberry.com/t5/Adobe-AIR-Development/BB10-Error-1065-SkinAssets-is-not-defined/td-p/1720721

You may have to rework some imports in the sample code to refer to the qnx classes instead of the flash classes but that should do it. It’s also worth noting that this doesn’t seem to be a problem with FDT, only Flash Builder.

Happy coding.

 

 

oliverm

BlackBerry Hackathons – Come out and Play(Book)!

Wednesday, May 16th, 2012

I’m currently in Bogotá, Colombia taking part in my third Hackathon on behalf of RIM. These hackathons are two-day events where local developers get the opportunity to interact directly with experts in PlayBook development. They also get a free PlayBook just for showing up!

We typically have a team of three experts covering AIR, HTML5/WebWorks and Native development. Most of the events have been focused on game development, but I’ve also done one centred around business apps using WebWorks.

Developers, either in teams or individually, work some long hours over the two day period. At the end of the second day, their apps are judged and winners awarded additional prizes. Nothing like a bit of competition to bring out the best in a dev team!

And with BB10 on the horizon, there’s a lot of anticipation from developers. Keep your eyes open for an event coming to your city this summer. Hope to see you there!

oliverm

Links roundup

Friday, November 4th, 2011

Here are a few unrelated links I’d like to pass on for your reading pleasure.

  1. Opportunistic Refactoring by Martin Fowler, author of the best programming book ever (Refactoring).  I’ve been preaching this one for a long time: “while you’re in there, refactor any smelly code, but don’t get caught in a death spiral”.
    http://martinfowler.com/bliki/OpportunisticRefactoring.html 

  2. jQuery4u – lots of great jQuery plug-in round-ups. I’m starting to visit this almost daily now.
    http://www.jquery4u.com/ 

  3. Finally, for you old KDE 3 fans, the beast is still alive and well. I loaded this onto a VM and started feeling very sentimental for the old days when KDE didn’t suck and I didn’t have to settle for Gnome.
    http://www.osnews.com/story/25283/KDE_3_5_Fork_Trinity_Releases_Third_Major_Update 

As usual, I look forward to your comments on any of these.

Oliver

Chad Upton

Example: Tracking Multiple Simultaneous Touchscreen Interactions in Adobe AIR

Tuesday, October 18th, 2011

By Chad Upton – senior consultant

If you’re building AIR apps for Android, iOS or BlackBerry PlayBook then you definitely need to handle touchscreen input. Many apps treat your finger just like a mouse, and by default that’s how AIR handles it.

Since you have more fingers than mice, you may want to plan for the case when a user touches the screen with more than one finger at a time. If you hold one finger on the screen and then touch it with a second, AIR will ignore any finger after the first one, unless you enable “TOUCH_POINT” mode in actionscript.

To show you how this works, I spun up a demonstration app that will track each of your fingers as you move them around on the screen. The app will place a circle below each finger. I made the circle nice and fat to accommodate the chubbiest of code hammers. I’m not sure what the maximum number of inputs is; I was able to get 11 circles on the screen (10 fingers plus 1 nose) — seriously. In this screenshot, you can see 8 touch points.

NOTE – If you’re running iOS 5 for iPad and have Multitasking Gestures enabled, using more than 3 touch points simultaneously can be a challenge since the OS uses four and five fingers for the Multitasking Gestures. If you’re targeting iOS devices, you may want to keep this in mind and even plan to use a maximum of three touch points at once.

Now for the code. Create a new “flex mobile project” in flash builder and paste over the default mxml with this code below. For best results, run it on your mobile device. The screenshot above shows it running on an iPad.

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application 

xmlns:fx=”http://ns.adobe.com/mxml/2009″

xmlns:s=”library://ns.adobe.com/flex/spark”

backgroundColor=”#333333″

creationComplete=”creationCompleteHandler()” >

<fx:Script>

<![CDATA[

import flash.ui.Multitouch;

import flash.ui.MultitouchInputMode;

import spark.core.SpriteVisualElement;

public const CIRCLE_RADIUS:int = 50;

 

public function creationCompleteHandler():void {

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

touch.addEventListener(TouchEvent.TOUCH_BEGIN, eventHandler);

touch.addEventListener(TouchEvent.TOUCH_MOVE, eventHandler);

touch.addEventListener(TouchEvent.TOUCH_ROLL_OUT, eventHandler);

}

 

public function eventHandler(event:TouchEvent):void {

if (event.type == TouchEvent.TOUCH_BEGIN) {

addCircle(event);

} else if (event.type == TouchEvent.TOUCH_MOVE) {

moveCircle(event);

} else if (event.type == TouchEvent.TOUCH_ROLL_OUT) {

removeCircle(event);

}

}

 

public function addCircle(event:TouchEvent):void {

var sprite:SpriteVisualElement = new SpriteVisualElement();

sprite.name = event.touchPointID.toString();

sprite.graphics.beginFill(0xB1B247);

sprite.graphics.drawCircle(CIRCLE_RADIUS / 2, CIRCLE_RADIUS / 2, CIRCLE_RADIUS);

sprite.graphics.endFill();

sprite.x = event.localX - CIRCLE_RADIUS / 2;

sprite.y = event.localY - CIRCLE_RADIUS / 2;

paint.addElement(sprite);

}

 

public function moveCircle(event:TouchEvent):void {

paint.getChildByName(event.touchPointID.toString()).x = event.localX-CIRCLE_RADIUS/2;

paint.getChildByName(event.touchPointID.toString()).y = event.localY-CIRCLE_RADIUS/2;

}

 

public function removeCircle(event:TouchEvent):void {

paint.removeElementAt(paint.getChildIndex(paint.getChildByName(event.touchPointID.toString())));

} ]]>

</fx:Script>

<s:Group

id=”paint”

width=”100%”

height=”100%”

/>

<s:Group

id=”touch”

width=”100%”

height=”100%”

/>

</s:Application>

Each time your finger touches the screen, a TOUCH_BEGIN event fires off. In the event object there is a touchPointID (integer). Each new finger to touch the screen gets a new ID. This allows you to keep track of each finger as it moves around or is removed from the screen. You’ll see that I give each circle a name that matches this ID. This allows me to move and remove the circle when the finger moves around or is removed from the screen. It’s quite straightforward and elegant.

If you’re interested in Flex or iOS training online or in-person, checkout our course selector for upcoming courses.