<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>BlackBerry Developer Blog &#187; sample code</title>
	<atom:link href="http://devblog.blackberry.com/tag/sample-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Fri, 17 May 2013 17:47:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devblog.blackberry.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9ef0a66c09615fa946c4179662398878?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>BlackBerry Developer Blog &#187; sample code</title>
		<link>http://devblog.blackberry.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devblog.blackberry.com/osd.xml" title="BlackBerry Developer Blog" />
	<atom:link rel='hub' href='http://devblog.blackberry.com/?pushpress=hub'/>
		<item>
		<title>Adding Gamepad Support to Your BlackBerry 10 Game</title>
		<link>http://devblog.blackberry.com/2013/02/blackberry-10-gamepad-support/</link>
		<comments>http://devblog.blackberry.com/2013/02/blackberry-10-gamepad-support/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 17:22:02 +0000</pubDate>
		<dc:creator>SeanPaulT</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Platform Services]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamepads]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[sample code]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=13882</guid>
		<description><![CDATA[I&#8217;ve heard a lot of people claim that the gamepad is dead &#8211; doomed to be replaced by touch screens. I disagree with this sentiment.  There’s nothing wrong with mobile games using cool new control schemes that make good use of touch screens – but if I’m playing a game that was designed with gamepads [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=13882&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://rimdevblog.files.wordpress.com/2013/02/blackberry10_gamepadsupport.jpg"><img class="aligncenter size-full wp-image-13896" alt="BlackBerry10_GamepadSupport" src="http://rimdevblog.files.wordpress.com/2013/02/blackberry10_gamepadsupport.jpg?w=598&#038;h=147" width="598" height="147" /></a></p>
<p>I&#8217;ve heard a lot of people claim that the <a href="http://en.wikipedia.org/wiki/Gamepad" target="_blank">gamepad</a> is dead &#8211; doomed to be replaced by touch screens. I disagree with this sentiment.  There’s nothing wrong with mobile games using cool new control schemes that make good use of touch screens – but if I’m playing a game that was designed with gamepads in mind, like <a href="http://appworld.blackberry.com/webstore/content/18561355" target="_blank">Shadowgun</a>, why can’t I just use a real controller?</p>
<p>Well, now I can &#8211; and so can you. Check out gamepad support now being added in upcoming <a href="http://unity3d.com/promo/unity4/?gclid=CPXA9bH0x7UCFUXf4AodJm0Aig" target="_blank">Unity 4</a> for BlackBerry 10:</p>
<p><span id="more-13882"></span></p>
<p style="text-align:center;"><a href="http://rimdevblog.files.wordpress.com/2013/02/blackberry10_gamepadsupport.jpg"><a href="http://rimdevblog.files.wordpress.com/2013/02/unity_gamepadsupport.jpg"><img class="aligncenter size-full wp-image-13898" alt="TITLE_IMAGE" src="http://rimdevblog.files.wordpress.com/2013/02/unity_gamepadsupport.jpg?w=598&#038;h=219" width="598" height="219" /></a></a></p>
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/d9SEYTlFsIM?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span>
<p>&nbsp;</p>
<p>After years of being frustrated by touch screen gamepads, I’m excited about bringing physical gamepad support to the <a href="developer.blackberry.com/native/" target="_blank">Native SDK</a> for BlackBerry 10. By making use of the new Gamepad API features developers can make their games work with physical controllers, giving their players the tactile responsiveness they’re used to from consoles and desktop PCs. When this is combined with BlackBerry 10’s built-in HDMI connectivity, you end up with a console experience in your pocket!</p>
<p>Here is another video showcasing gamepad pairing instructions and a racer sample on <a href="http://gameplay3d.org/">GamePlay3D</a> that now supports not only desktop gamepad support but also BlackBerry 10:</p>
<p><a href="http://rimdevblog.files.wordpress.com/2013/02/gameplay3d_gamepadsupport.jpg"><img class="aligncenter size-full wp-image-13897" alt="GamePlay3D_GamepadSupport" src="http://rimdevblog.files.wordpress.com/2013/02/gameplay3d_gamepadsupport.jpg?w=433&#038;h=132" width="433" height="132" /></a></p>
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/B4NGAp2O2sM?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span>
<p>&nbsp;</p>
<p>Before you get started implementing this in your own game, I want to answer a few of the most common questions people ask me about the API.</p>
<ol start="1">
<li>What gamepads are supported right now?
<ol start="1">
<li>The <a href="http://steelseries.com/products/other/steelseries-free-mobile-wireless-controller">SteelSeries Free</a>.</li>
<li>The <a href="http://www.gametel.se/">Gametel</a>.</li>
<li>The Wii Remote.  Note that currently only the core buttons on the remote itself are supported – that means no attachments and no motion controls, just the D-Pad and other buttons.</li>
</ol>
</li>
<li>If new gamepads come out, do I have to update my game to support them?
<ol start="1">
<li>No, you don’t!  When new controllers become available, we’ll update the mappings in a system update and your game will start receiving gamepad inputs from the new hardware.  Because the Gamepad API is an abstraction above HID, and because we map each gamepad’s unique HID report format to the Gamepad API, you don’t need to write any code that’s specific to a single controller.</li>
</ol>
</li>
<li>Do users need to install anything to set up or configure their gamepads?
<ol start="1">
<li>No.  The Gamepad API is integrated into the Screen library, the same library you are already using to handle touch, keyboard, and other input events.  All users have to do is pair their device through the Bluetooth settings screen for it to start sending inputs to your game.</li>
</ol>
</li>
</ol>
<p>We realize there are other gamepads out there and continue to work towards supporting as many devices as possible. If you know of a Bluetooth, HID-compatible game controller that’s not supported yet, please let us know in the comments. Meanwhile, the fact that you won’t have to change your code when we add more devices to the list means you only help yourself (and your users) by starting to use this new feature right away.</p>
<p><a href="http://developer.blackberry.com/native/documentation/bb10/create_the_gamepad_app.html">Here’s a tutorial</a> that should get you up and running. It includes plenty of code snippets and is based on <a href="https://github.com/blackberry/NDK-Samples/tree/master/Gamepad">this open-source sample project</a>, which started as a little app I whipped up to test the new API. It eventually turned into a demo of two-player connectivity and a configuration screen.  I hope you find it useful.</p>
<p>Please, for the sake of everyone who’s ever been frustrated by touch controls, try this new feature and leave your feedback – I’m eager to do what I can to help if you have any trouble.  Most of all, I’m looking forward to playing your games with a real gamepad!</p>
<p>Links:</p>
<ul>
<li><a href="http://developer.blackberry.com/native/documentation/bb10/create_the_gamepad_app.html">Tutorial</a></li>
<li><a href="https://github.com/blackberry/NDK-Samples/tree/master/Gamepad">Sample code</a></li>
<li><a href="http://steelseries.com/products/other/steelseries-free-mobile-wireless-controller">SteelSeries Free</a></li>
<li><a href="http://www.gametel.se/">Gametel</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/13882/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/13882/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=13882&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/02/blackberry-10-gamepad-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/588de8e9ded23b503ae5fb589bf35159?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">seanpaultaylor</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/02/blackberry10_gamepadsupport.jpg" medium="image">
			<media:title type="html">BlackBerry10_GamepadSupport</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/02/unity_gamepadsupport.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/02/gameplay3d_gamepadsupport.jpg" medium="image">
			<media:title type="html">GamePlay3D_GamepadSupport</media:title>
		</media:content>
	</item>
		<item>
		<title>Improper use of CSS background-size</title>
		<link>http://devblog.blackberry.com/2013/01/improper-use-of-css/</link>
		<comments>http://devblog.blackberry.com/2013/01/improper-use-of-css/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 16:39:23 +0000</pubDate>
		<dc:creator>Rory C-B</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[BlackBerry 10 browser]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=13252</guid>
		<description><![CDATA[Order and omissions matter when it comes to CSS. Until recently there was a quirk in the WebKit rendering engine related to the shorthand background property. The good news is that it has been fixed; the bad news is that it potentially breaks legacy code. If the background-size property is set prior to declaring background [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=13252&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Order and omissions matter when it comes to CSS. Until recently there was a quirk in the WebKit rendering engine related to the shorthand background property. The good news is that it has been fixed; the bad news is that it potentially breaks legacy code. If the background-size property is set prior to declaring background property it no longer behaves in the same fashion. The simplest solution is to declare the size of a background image in the background property.</p>
<p>code:</p>
<pre>a.icon.good2 {
	background: #215387 url(test-sprite@2x.png) 4px -6px / 40px 82px no-repeat;
	}</pre>
<p>Note: Including the size in the background property is not supported in older browsers. See example 2 below for a more backwards compatible solution.</p>
<p><span id="more-13252"></span></p>
<p><strong>Issue:</strong></p>
<p>The W3C spec for the background shorthand property specifies that when declared without a size property it initializes size to &#8216;background-size: auto auto;&#8217;. Previously there was quirk with WebKit where if size was omitted it just didn&#8217;t initialize the size property for the background. This allowed for a previously declared background-size declaration to remain intact, displaying the image at its proper size. This quirk has since been removed and the latest release of WebKit now follows the W3C spec.</p>
<p><i>Bad code</i></p>
<pre>a.icon {
	background-size: 40px 82px;
	}
a.icon.bad {
	background: #215387 url(test-sprite@2x.png) 4px -6px no-repeat;
	}</pre>
<p><i>Produces</i></p>
<p><img class="alignnone size-full wp-image-13253" alt="" src="http://rimdevblog.files.wordpress.com/2013/01/impropercss.jpg?w=127&#038;h=91" width="127" height="91" /></p>
<p><strong>Solution</strong></p>
<p>1. Add size to the background short-hand property and eliminate the background-size property</p>
<p><i>Code</i></p>
<pre>a.icon.good2 {
     background: #215387 url(test-sprite@2x.png) 4px -6px / 40px 82px no-repeat;
}</pre>
<p><i>Produces</i></p>
<p><img class="alignnone size-full wp-image-13254" alt="" src="http://rimdevblog.files.wordpress.com/2013/01/impropercsspic2.jpg?w=127&#038;h=91" width="127" height="91" /></p>
<p>2. If you must resize a background-image via a background-size property declare background size after the background property so it isn&#8217;t overridden.</p>
<p>Code</p>
<pre>a.icon.good {
	background: #215387 url(test-sprite@2x.png) 4px -6px no-repeat;
	}
a.icon.good {
	background-size: 40px 82px;
	}</pre>
<p>Produces</p>
<p><img class="alignnone size-full wp-image-13255" alt="" src="http://rimdevblog.files.wordpress.com/2013/01/impropercsspic3.png?w=127&#038;h=91" width="127" height="91" /></p>
<p><strong>References:</strong></p>
<p><a href="http://www.w3.org/TR/css3-background/#the-background" target="_new">http://www.w3.org/TR/css3-background/#the-background</a><br />
<a href="https://bugs.webkit.org/show_bug.cgi?id=97761" target="_new">https://bugs.webkit.org/show_bug.cgi?id=97761</a><br />
<a href="http://lists.w3.org/Archives/Public/www-style/2012Oct/0112.html" target="_new">http://lists.w3.org/Archives/Public/www-style/2012Oct/0112.html</a><br />
<a href="http://caniuse.com/#search=background-size" target="_new">http://caniuse.com/#search=background-size</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/13252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/13252/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=13252&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/01/improper-use-of-css/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/242389c732166964f7406def92b0a476?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rcraigbarnes</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/impropercss.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/impropercsspic2.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/01/impropercsspic3.png" medium="image" />
	</item>
		<item>
		<title>Introducing Proximity Gaming with NFC</title>
		<link>http://devblog.blackberry.com/2012/10/proximity-gaming-nfc/</link>
		<comments>http://devblog.blackberry.com/2012/10/proximity-gaming-nfc/#comments</comments>
		<pubDate>Tue, 16 Oct 2012 17:06:03 +0000</pubDate>
		<dc:creator>mdwrim</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[BlackBerry 7]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[Near Field Communications]]></category>
		<category><![CDATA[nfc]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[Proximity Gaming]]></category>
		<category><![CDATA[sample code]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10865</guid>
		<description><![CDATA[Amongst the many interesting things I’m lucky enough to get involved with in my role on the RIM® Developer Relations team, Near Field Communications (NFC) has become very much center stage for me over the last year. Some readers of this post may be familiar with the NFC-related articles and code samples that I’ve co-authored [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10865&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Amongst the many interesting things I’m lucky enough to get involved with in my role on the RIM® Developer Relations team, Near Field Communications (NFC) has become very much center stage for me over the last year. Some readers of this post may be familiar with the NFC-related articles and code samples that I’ve co-authored with my buddy John Murray (<a href="http://twitter.com/jcmrim" target="_new">@jcmrim</a>), which you can find listed in our <a href="http://supportforums.blackberry.com/t5/Java-Development/NFC-Article-and-Code-Index/ta-p/1538775" target="_new">NFC Article and Code Index</a>.</p>
<p>Now it has to be said that it wasn’t the best summer here in the UK (though fortunately the weather gave us a break just in time for the Olympics!) and so I occasionally found myself at the weekend with “fine weather-dependent plans” cancelled and time on my hands. One such weekend, I was thinking about NFC and my thoughts turned to discussions I’d had with John about whether NFC could enrich games and the gaming experience in some way.</p>
<p>The world of computer games has changed somewhat in the 30-something years I’ve been playing them! It’s gone from text-based adventure games (“go north!”) played on a PDP-11 with a teletype and no screen, through the block graphics of Lunar Lander on a Commodore Pet, and onwards through Space Quest, Civilisation I, the Monkey Island series and (many) more favourites.</p>
<p>In the beginning and for many years, games were single-player &#8212; or at least they were single machine games. More than one player could play, but you’d have to share the keyboard or take turns. Then came LAN games, and this evolved into Internet-based gaming with huge online gaming communities (without whom, I have no doubt, the world would now be over-run with zombies). The truly great thing about online gaming is that you need never know that “goreslayer765” who just destroyed you in your favourite game is actually a 9-year-old with far more knowledge of automatic weapons than can possibly be healthy. I mean, whose fragile ego could handle knowing that?</p>
<p>So, both extreme ends of the single player vs. multiplayer spectrum are well catered to these days. But in what way might NFC enrich the gaming experience, and in what kind of games? I had a quick brainstorm with John on IM and we came up with a few use cases:</p>
<p><span id="more-10865"></span></p>
<table border="5">
<tbody>
<tr>
<td><strong>Start Game</strong></td>
<td>Two-player games could be kicked off by the two players touching devices. This could trigger an NFC based interaction which your application drives, the outcome of which could be the decision as to which of the players is “Player 1” and which is “Player 2” for example.</td>
</tr>
<tr>
<td><strong>Your Turn</strong></td>
<td>Turn based games would work well with NFC being used to indicate “it’s your turn now,” with a player taking their turn and then touching the other player’s device with theirs.</td>
</tr>
<tr>
<td><strong>Pass it on</strong></td>
<td>It could be cool to create digital tokens of some sort that you could pass to other players by touching their device with yours. With a web component of your game, you could perhaps track your token as it moves from player to player and perhaps travels the world!</td>
</tr>
<tr>
<td><strong>Been there</strong></td>
<td>Games involving visiting physical locations could use NFC tags to allow players to “prove” they’ve been to a place and found the item with the tag. Each tag would contain unique content, including perhaps clues on how to find the next game location. Touching and reading the tag from your application would establish the “been there” credentials required.</td>
</tr>
</tbody>
</table>
<p>But why would you want to do this? After all, there are plenty of other ways to trigger “new game” or “it’s your turn now” and to share data across a network. Well, the appeal of using NFC is simply this: it adds a physical, tactile element to the game. You’re sitting right next to the person you’re playing with, and having to touch devices at intervals in the game could add a novel and fun element to the experience.</p>
<p>We then realized our most important task. We needed a name for the phenomenon of NFC-enabled games that we were now thinking about. In a flash, I had it! Please welcome “<strong>Proximity Gaming</strong>” to the world!</p>
<p>Armed with a few ideas, we decided to develop a game as a proof of concept and set about thinking about what the first game would be and how it would work. We decided we’d develop an NFC-enabled version of “tic tac toe” or “noughts and crosses” as it’s known in the UK.</p>
<p>We decided to use NFC in two places. Firstly, players would have to touch devices to start a game, and secondly, they’d touch devices to indicate “it’s your turn now”.</p>
<p>We had to consider a few issues regarding the implementation. It was immediately apparent that we’d have to pass some kind of message from device A to device B and that we’d probably need several message types. In other words, we’d need a simple protocol.</p>
<p>We could also see several technical ways of sending a message from one device to another. We could use virtual target emulation in theory, or maybe we could use one of the two NFC peer-to-peer APIs, SNEP (Simple NDEF Exchange Protocol) or LLCP (Logical Link Control Protocol).</p>
<p>We dismissed target emulation and focused on the peer-to-peer options, since this was clearly a peer-to-peer scenario. We concluded that either SNEP or LLCP could be used, but that SNEP would be a little easier to work with &#8212; LLCP being a lower-level connection-oriented protocol whereas SNEP is a higher-level message-oriented protocol. We’d worked with both in the past, so we had a pretty good feel for what the coding would be like.</p>
<p>In conclusion, we decided to invent a simple message-oriented protocol and use SNEP as the NFC protocol, which would transport game messages between devices. The UI design was to be basic: an initial screen that prompted players to touch devices to start a new game; a screen for “player 1” to choose either noughts or crosses; and the main game screen upon which to place noughts and crosses.</p>
<p>We also decided to implement the game for both BlackBerry® 7 OS using Java®, and our BlackBerry® 10 Dev Alpha devices using C++/Qt/Cascades. Being able to play the game between a BlackBerry 7 device and a BlackBerry 10 device would be a nice proof of the interoperability of NFC between generations of BlackBerry technology.</p>
<p>Here are some screen shots from the proof of concept game, first from the BlackBerry 7 version of the game:</p>
<p><img class="aligncenter size-full wp-image-10868" title="" alt="TITLE_IMAGE" src="http://rimdevblog.files.wordpress.com/2012/08/proximity-gaming-1.jpg?w=507&#038;h=382" height="382" width="507" /></p>
<p style="text-align:center;"><i>Figure 1 &#8211; New game screen</i></p>
<p><img class="aligncenter size-full wp-image-10867" title="" alt="" src="http://rimdevblog.files.wordpress.com/2012/08/proximity-gaming-2.jpg?w=507&#038;h=382" height="382" width="507" /></p>
<p style="text-align:center;"><i>Figure 2 &#8211; Player 1, choose nought or cross</i></p>
<p><img class="aligncenter size-full wp-image-10866" title="" alt="" src="http://rimdevblog.files.wordpress.com/2012/08/proximity-gaming-3.jpg?w=507&#038;h=382" height="382" width="507" /></p>
<p style="text-align:center;"><i>Figure 3 &#8211; Main game screen</i></p>
<p>And here are some screen shots from the proof of concept game, from the BlackBerry 10 version of the game:</p>
<p style="text-align:center;"><img title="" alt="" src="http://rimdevblog.files.wordpress.com/2012/10/proximity-gaming-4.jpg?w=155" width="155" /> <img title="" alt="" src="http://rimdevblog.files.wordpress.com/2012/10/proximity-gaming-5.jpg?w=155" width="155" /> <img title="" alt="" src="http://rimdevblog.files.wordpress.com/2012/10/proximity-gaming-6.jpg?w=155" width="155" /><br />
<i>Figure 4 &#8211; New game screen; Figure 5 &#8211; In game; Figure 6 &#8211; Game over</i></p>
<p>Thoughts on the “game protocol” crystalized properly as we worked through prototyping the game and we found we needed the following message types in the simple protocol:</p>
<table border="5">
<tbody>
<tr>
<td><strong>Bid for player 1</strong></td>
<td>The act of requesting a new game by touching devices would also determine which of the two players would be Player 1 and get to choose which of noughts or crosses to play with. The “bid” message would be exchanged by both devices and contain a random number. The device that had produced the highest number would “win” the bid and become Player 1.</td>
</tr>
<tr>
<td><strong>End of turn</strong></td>
<td>After placing their nought or cross on the board, players would touch devices so that the other player’s game instance would be informed it could now let the player update the game screen. The protocol message to indicate “end of turn” would need to include information about the turn taken by the current player; specifically, which square on the board they had updated in their turn.</td>
</tr>
<tr>
<td><strong>Reset</strong></td>
<td>There would be occasions where the game state in a device would need to be reset and a suitable message type in the protocol would allow this.</td>
</tr>
</tbody>
</table>
<p>We’d like to tell you how we went about coding the game.</p>
<p>If you want to know how to use SNEP in general terms, we’ve written articles on the subject for both BlackBerry 7 and BlackBerry 10 and sample code too. You’ll find details here:</p>
<p><a href="http://supportforums.blackberry.com/t5/Java-Development/NFC-Peer-to-Peer-Communications-with-SNEP/ta-p/1532841" target="_new">BlackBerry 7 – Peer to Peer Communication with SNEP</a><br />
<a href="http://supportforums.blackberry.com/t5/Native-Development/NFC-on-BlackBerry-10-peer-to-peer-communication-using-SNEP/ta-p/1758859" target="_new">BlackBerry 10 – Peer to Peer Communication with SNEP</a></p>
<p>There’s a key point here: you could implement your Proximity Gaming ideas for either BlackBerry 7 or BlackBerry 10 because both have the specific types of NFC peer-to-peer capabilities that you will need.<br />
Harnessing NFC SNEP in the way we wanted for our game was easy. The APIs themselves are very straightforward to use. For BlackBerry 7 we designed some Java classes, which represent the various message types in the game protocol. This was standard stuff if you’re accustomed to working with protocols, and we ended up with an abstract class called ProtocolMessage and a series of concrete sub-classes, one for each message type. Each of these classes implemented a marshall and demarshall method so that we could easily swap between byte array representations, which would be exchanged over NFC SNEP and Java objects for internal use in the application.</p>
<p>Here&#8217;s an example of one of the protocol message classes:</p>
<pre>public class ProtocolMessageMasterBid extends ProtocolMessage {

    private int bid;

    public ProtocolMessageMasterBid() {
        message_id = Constants.PROTOCOL_MASTER_BID;
        Random rand = new Random(System.currentTimeMillis());
        bid = rand.nextInt(1000000);
    }

    public byte[] marshall() {
        byte [] bid_bytes = Utilities.toBytes(bid);
        byte [] bytes = new byte[1+bid_bytes.length];
        bytes [0] = message_id;
        System.arraycopy(bid_bytes, 0, bytes, 1, bid_bytes.length);
        return bytes;
    }

    public void demarshall(byte[] bytes) {
        if (bytes.length != 5) {
            Utilities.log("XXXX invalid parameter length passed to ProtocolMessageMasterBid demarshall:"+ bytes.length);
            return;
        }
        message_id = bytes[0];
        bid = Utilities.toInt(bytes,1);
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String toString() {
        String string = super.toString() + ",ProtocolMessageMasterBid" + ",bid="+bid;
        return string;
     }
}</pre>
<p>We also implemented classes called NfcReceiver and NfcSender, which implemented NDEFMessageListener and NDEFMessageBuilder respectively and provided the basic mechanism for sending and receiving my protocol messages.</p>
<p>For BlackBerry 10, life was actually simpler and we just needed to create message using the Qt QbyteArray class and then utilize the BlackBerry 10 native APIs for NFC, as shown below:</p>
<pre>void NfcWorker::sendTurnData(bps_event_t *bps_event) {
	nfc_event_t *nfc_event;
	nfc_target_t* target;
	nfc_ndef_record_t* myNdefRecord;
	nfc_ndef_message_t* myNdefMessage;
	// Obtain NFC target object from our BPS NFC event object
	//------------------------------------------------------------------------------
	CHECK(nfc_get_nfc_event(bps_event, &amp;nfc_event));
	CHECK(nfc_get_target(nfc_event, &amp;target));
	//------------------------------------------------------------------------------

	QByteArray ba;
	ba.resize(9);
	ba[0] = 2; // turn over message ID
	// tile changed
	ba[1] = 0;
	ba[2] = 0;
	ba[3] = 0;
	ba[4] = _state-&gt;lastSelection();
	int ls = _state-&gt;lastSelection();
	// symbol changed
	ba[5] = 0;
	ba[6] = 0;
	ba[7] = 0;
	ba[8] = _state-&gt;mySymbol();
	int ms = _state-&gt;mySymbol();
	_state-&gt;mySymbol();
	myNdefRecord = makeTurnOverRecord(ba.constData());
	//------------------------------------------------------------------------------
	CHECK(nfc_create_ndef_message(&amp;myNdefMessage));
	//------------------------------------------------------------------------------
	CHECK(nfc_add_ndef_record(myNdefMessage, myNdefRecord));
	qDebug() &lt;&lt; "XXXX Pushing NDEF message over SNEP";
	//------------------------------------------------------------------------------
	CHECK(nfc_push_ndef_message(target, myNdefMessage));
	//------------------------------------------------------------------------------
	CHECK(nfc_delete_ndef_message(myNdefMessage, true));
	CHECK(nfc_destroy_target(target));
}</pre>
<p>So, having designed and implemented a message-oriented protocol and coded classes which used NFC SNEP to transport those messages between devices, the rest of the effort that rainy weekend was spent on standard game development issues like creating the UI. The UI was really easy to create for the BlackBerry 10 version using Cascades™, and took a fraction of the time and effort we spent on the BlackBerry 7 Java version of the game. In both cases, the NFC part was also quite easy and took relatively little effort as a portion of the whole application.</p>
<p>The next step was to find some guinea pigs to test the application out. (Not real guinea pigs, of course &#8212; their paws are too small and they have claws that make working with a touch screen problematic. So instead, we decided to use humans &#8212; our respective friends and family to be precise. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<p>Testing was informal. In my case, I explained I’d developed a two-player game that allowed you to take certain actions just by touching the two devices back to back. My guinea pigs generally looked a bit blank or even cynical at this point. “Just touch them together? Really?!” But with a little coaxing I got them started and watched them carefully.</p>
<p>At the very start of the game, the two players are instructed to touch devices to start the game. Looking a little unsure at first, the players touched devices and held them together for a second. The devices responded, vibrating to indicate an NFC message had been received, and the game moved on to the next screen to allow the selected Player 1 to choose noughts or crosses. At this point, the expressions on the players’ faces changed &#8212; from expressions that suggested they were being asked to participate in a black magic ritual to sheer delight with big smiles all around! And from that point, there was no stopping them. They were each playing on devices with touch screens – the BlackBerry® Bold™ 9900 and 9790 smartphones, to be precise – so selecting a place to put their mark on the game “board” was simply a case of touching the screen. And passing turns to the other player? They just touched the devices together, of course!</p>
<p>Here’s a video showing the game in use:</p>
<p style="text-align:center;"><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='560' height='315' src='http://www.youtube.com/embed/ApEO_WJWlZM?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span></p>
<p style="text-align:center;">[ <a href="http://www.youtube.com/watch?v=ApEO_WJWlZM" target="_new">YouTube link for mobile viewing</a> ]</p>
<p>The verdict was very positive. Players liked the idea in general and enjoyed the tactile element of the game play. It seemed that Proximity Gaming was a big hit!</p>
<p>The two versions of our NFC-enabled tic tac toe games are available with full source code from our github repositories here:</p>
<p><a href="https://github.com/blackberry/Samples-for-Java/tree/master/NFC/TouchTicTacToe" target="_new">https://github.com/blackberry/Samples-for-Java/tree/master/NFC/TouchTicTacToe</a><br />
<a href="https://github.com/blackberry/Cascades-Community-Samples/tree/master/TouchTicTacTen" target="_new">https://github.com/blackberry/Cascades-Community-Samples/tree/master/TouchTicTacTen</a></p>
<p>So over to you, BlackBerry developers! How could you use NFC in your BlackBerry smartphone game?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10865/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10865/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10865&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/10/proximity-gaming-nfc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d86c7fdd0d15b754b2760af4536923b3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mdwrim</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/proximity-gaming-1.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/proximity-gaming-2.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/proximity-gaming-3.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/10/proximity-gaming-4.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/10/proximity-gaming-5.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/10/proximity-gaming-6.jpg" medium="image" />
	</item>
		<item>
		<title>Get Your Invoke On: BlackBerry 10 Invocation Framework</title>
		<link>http://devblog.blackberry.com/2012/08/blackberry-10-invocation-framework/</link>
		<comments>http://devblog.blackberry.com/2012/08/blackberry-10-invocation-framework/#comments</comments>
		<pubDate>Fri, 17 Aug 2012 14:18:52 +0000</pubDate>
		<dc:creator>Shadid</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[BlackBerry 10 invocation framework]]></category>
		<category><![CDATA[bound invocation]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[invoke]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[target]]></category>
		<category><![CDATA[unbound invocation]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10749</guid>
		<description><![CDATA[BlackBerry® apps have always been known for their ability to deeply integrate with core applications as well as with other third-party apps. With BlackBerry® 10, we are taking that experience to the next level with our Invocation Framework. It enables one application to request another to perform a specific task. For example, BlackBerry® Messenger (BBM™) [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10749&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>BlackBerry® apps have always been known for their ability to deeply integrate with core applications as well as with other third-party apps. With BlackBerry® 10, we are taking that experience to the next level with our Invocation Framework. It enables one application to request another to perform a specific task. For example, BlackBerry® Messenger (BBM™) may request an app to open a .DOC file that it received in a chat session. But that’s just the tip of the iceberg &#8211; the framework streamlines the communication between apps and provides a consistently smooth and jitter-free user experience.</p>
<p>First and foremost, there are two kinds of invocations – unbound and bound. An unbound invocation is performed when an app does not specify a specific target app that should get invoked, and hence relies on the invocation framework to select the best target. For example, if there are three apps that can open .DOC files, the framework chooses the best one based on its own target selection logic. So, for unbound invocations, the framework provides automatic brokering to find the best-fit targets and also performs target selection to choose the best among the best. This is very powerful because the client application does not need to know any target applications at all, and yet it can discover and invoke them via the invocation framework.</p>
<p><span id="more-10749"></span></p>
<p><img class="aligncenter size-full wp-image-10751" title="" src="http://rimdevblog.files.wordpress.com/2012/08/invocation-framework-1.jpg?w=600&#038;h=422" alt="TITLE_IMAGE" width="600" height="422" /></p>
<p>On the other hand, a bound invocation is performed when the target app is specified by the client application while sending an invocation request. For example, a client app may request that Docs to Go® should be invoked for opening a .doc file. In this case, the invocation framework does not provide any brokering (or target selection) and blindly invokes the specified target app with the request parameters. Extra care must be taken when performing a bound invocation because an app may be sending a request to a target that the target does not understand at all. One thing is clear &#8212; bound invocation assumes that the client knows the target well.</p>
<p><img class="aligncenter size-full wp-image-10750" title="" src="http://rimdevblog.files.wordpress.com/2012/08/invocation-framework-2.jpg?w=600&#038;h=191" alt="" width="600" height="191" /></p>
<p>There are really two ways you can know a target. First, you might have had a conversation with the author of the target app and have an agreement on the invocation request parameters. In return, they have made you aware of their target ID that you can use to perform a bound invocation. Second, you can query the invocation framework with an invocation request to get a list of best-fit targets and programmatically parse their attributes (capabilities) including their target IDs and invoke one programmatically. Note that querying is another way to discover apps without knowing them and is even more powerful and flexible than unbound invocations. As long as you have a valid target ID, you can perform a bound invocation with the appropriate parameters.</p>
<p>So far so good, but how does the invocation framework know about all the target apps? It does because each target app is required to register with the framework if they wish to be considered by the framework. While registering with the framework, targets must specify a target id which alone makes them candidates for bound invocation. However if a target wants to make itself available for unbound invocations or invocation queries, it must define one or more invoke filters. Each filter is a combination of the following attributes.</p>
<ul>
<li>Actions (e.g. bb.action.OPEN) that describes the action it can perform</li>
<li>MIME types (e.g. application/pdf) describing the content type it can perform the action on</li>
<li>URIs (e.g. <a href="http://" rel="nofollow">http://</a>, file://) specifying the protocols it can handle to retrieve the data</li>
<li>EXTs describing the file extensions it can handle if the URI scheme is file://</li>
</ul>
<p>Note that at least one action and one MIME type is mandatory for each filter definition, and if the URI is file://, at least one EXT must be specified. Filters are what really allow the invocation framework to broker between clients and potential targets as well as target selection that lead to successful invocations.</p>
<p>Well, that’s a 30,000 feet overview of the invocation framework but as a developer I know your hands are itching for some real code. The good news is I have that covered &#8212; I have already uploaded a few sample applications on Github that you may find very (very) useful.</p>
<ul>
<li><a href="https://github.com/blackberry/Cascades-Samples/tree/master/invokeclient" target="_new">InvokeClient</a> – An application that demos different ways to invoke and to query for targets</li>
<li><a href="https://github.com/blackberry/Cascades-Community-Samples/tree/master/InvokeTarget1" target="_new">InvokeTarget1</a> – A dummy target app that can be used with InvokeClient</li>
<li><a href="https://github.com/blackberry/Cascades-Community-Samples/tree/master/InvokeTarget2" target="_new">InvokeTarget2</a> – A second dummy target app that can also be used with InvokeClient</li>
</ul>
<p>Samples are great, but so are documentations (if we read them) for a solid understanding. Please refer to our <a href="https://developer.blackberry.com/cascades/documentation/device_platform/invocation/index.html" target="_new">App Integration</a> development guide for a comprehensive guide with code snippets for both invoke clients and targets.</p>
<p>I am more excited than ever before to introduce the invocation framework as part of the <a href="https://developer.blackberry.com/cascades/download" target="_new">BlackBerry 10 Native SDK beta 2</a> and have no doubt that this will help most app developers out there to provide a deeply integrated user experience. Invocation is one of the core aspects of the BlackBerry 10 experience and come launch, it is going to be hard to find an app that does not invoke or get invoked. I will keep everyone posted on new features as we add them to this framework but more importantly, I am all ears to your feedbacks at shaque[at]rim[dot]com, <a href="http://twitter.com/BlackBerryDev" target="_new">@BlackBerryDev</a> and <a href="http://twitter.com/shadidhaque" target="_new">@shadidhaque</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10749/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10749/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10749&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/08/blackberry-10-invocation-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/25ee80c29143f159bad70d24df820bc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shadidhaque</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/invocation-framework-1.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/invocation-framework-2.jpg" medium="image" />
	</item>
		<item>
		<title>The BlackBerry 10 User Agent String Has Arrived!</title>
		<link>http://devblog.blackberry.com/2012/08/blackberry-10-user-agent-string/</link>
		<comments>http://devblog.blackberry.com/2012/08/blackberry-10-user-agent-string/#comments</comments>
		<pubDate>Thu, 16 Aug 2012 19:50:58 +0000</pubDate>
		<dc:creator>Alex Kinsella</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[BlackBerry 10 browser]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[user agent]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10780</guid>
		<description><![CDATA[Guest post from Steve W. detailing a change in our BlackBerry® 10 browser user agent &#8211; Ed. We have been busy making the BlackBerry® 10 browser one of the most advanced browsers on the market with class leading HTML5, CSS3, and WebGL support. However, even if you build one of the greatest browsers to ever [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10780&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>Guest post from Steve W. detailing a change in our BlackBerry® 10 browser user agent &#8211; Ed.</em></p>
<p>We have been busy making the BlackBerry® 10 browser one of the most advanced browsers on the market with class leading HTML5, CSS3, and WebGL support. However, even if you build one of the greatest browsers to ever hit the mobile web, you still need content providers to serve up a rich mobile experience. To help ensure our users receive high quality content, we have changed our user agent string. It’s not an ideal solution, but feature detection and responsive design have not yet become the norm among web designers, and we needed an interim solution.</p>
<p><span id="more-10780"></span></p>
<p style="text-align:center;"><a href="http://rimdevblog.files.wordpress.com/2012/05/bb10_devalpha2.png"><img class="aligncenter  wp-image-9144" title="bb10_devalpha2" alt="TITLE_IMAGE" src="http://rimdevblog.files.wordpress.com/2012/05/bb10_devalpha2.png?w=317&#038;h=614" width="317" height="614" /></a></p>
<p>Thus, without further ado, I introduce to you the new and improved BlackBerry user agent string!</p>
<p><code>Mozilla/5.0 (BB10; &lt;Device Model&gt;) AppleWebKit/&lt;WebKit Version&gt; (KHTML, like Gecko) Version/&lt;BB Version #&gt; Mobile Safari/&lt;WebKit Version&gt;</code></p>
<p><!--more--></p>
<h3><strong>Explained</strong></h3>
<ol>
<li><code>Mozilla/5.0</code> Mostly customary, historically used to indicate Mozilla compatible browser</li>
<li><code>BB10</code> The primary identifier of a BlackBerry 10 device</li>
<li><code>&lt;Device Family&gt;</code> Device product family name</li>
<li><code>AppleWebKit/&lt;WebKit Version&gt;</code> The WebKit Version number</li>
<li><code>KHTML, like Gecko</code> The engine WebKit originated from</li>
<li><code>Version/&lt;BB Version #&gt;</code> The software version number</li>
<li><code>Mobile</code> Indicates the device is mobile; it may have a small physical screen and potentially limited bandwidth</li>
<li><code>Safari/&lt;WebKit Version&gt;</code> Mostly customary, historically used to indicate Safari-compatible browser</li>
</ol>
<h3><strong>What has changed?</strong></h3>
<ol>
<li>Many websites are filtering on the word “BlackBerry” and providing our very capable browser with the most basic of mobile web pages, while rich content is being pushed to our competitors. To avoid this pitfall, we removed the word “BlackBerry” from our user agent and replaced it with “BB10”. This change will require web administrators to add this new identifier to their user agent detecting scripts</li>
<li>We cleaned up the user agent string by removing both the locale (e.g. “en-US”) and the strong encryption indicator (e.g. “U”) [don’t worry, we still support strong encryption]</li>
</ol>
<h3><strong>Suggested Identification Pattern</strong></h3>
<ul>
<li>BlackBerry10 Smartphone: <code>'BB10' + 'Mobile'</code></li>
</ul>
<h3><strong>Example: htaccess file</strong></h3>
<pre>RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} BB10.+Mobile 
RewriteRule ^$    http://www.example.com/mobile [L]</pre>
<p>So there you have it, our updated BlackBerry 10 user agent string!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10780/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10780&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/08/blackberry-10-user-agent-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d0e94a7e96e80d5911732d43f31a39c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Alex K.</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/05/bb10_devalpha2.png?w=528" medium="image">
			<media:title type="html">bb10_devalpha2</media:title>
		</media:content>
	</item>
		<item>
		<title>Using bbUI.js Scroll-Panel</title>
		<link>http://devblog.blackberry.com/2012/08/scroll-panel/</link>
		<comments>http://devblog.blackberry.com/2012/08/scroll-panel/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 17:07:17 +0000</pubDate>
		<dc:creator>Tom Anderson</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bbUI]]></category>
		<category><![CDATA[bbui.js]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[Scroll-Panel]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10685</guid>
		<description><![CDATA[A tutorial on how to use the new Scroll-Panel feature in bbUI.js 0.9.3.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10685&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>With the release of <a href="https://github.com/blackberry/bbUI.js" target="_blank">bbUI.js 0.9.3</a>, a new feature appeared called the Scroll-Panel. The idea is simple enough: have a section of your application that scrolls independently of the items around it. I was waiting for this feature to be released for two reasons: First, I was there when the idea was conceived and implemented. Second, I need this feature in my ZenLottery application.</p>
<p>The idea was conceived and implemented at the <a href="http://www.blackberryjamworldtour.com" target="_new">BlackBerry Jam World Tour</a> in Toronto, where Tim Neil (<a href="http://twitter.com/brcewane" target="_new">@brcewane</a>) was scheduled to present. If you didn’t know, Tim is one of the main authors of bbUI.js. During one of the breaks, an attendee approached Tim with the idea of adding an independently scrolling panel to the bbUI.js. Funny thing is, Tim thought it was a great idea and produced the initial branch over lunch! Right there in front of us, the birth of a new feature.</p>
<p>I have been waiting for this feature for my application: ZenLottery. With ZenLottery, you can generate lottery numbers based on your location. One feature of ZenLottery is the ability to save the sets of generated numbers. If you can save the numbers, then you should be able to delete them as well. The design called for the numbers to be displayed and a delete button at the bottom. Without the Scroll-Panel feature, the delete button may be off the bottom of the screen, if the user chooses to generate more than 8 sets of lottery numbers.</p>
<p><span id="more-10685"></span></p>
<p><img class="aligncenter size-full wp-image-10688" title="" src="http://rimdevblog.files.wordpress.com/2012/08/bbui-scroll-panel-1.jpg?w=309&#038;h=600" alt="TTILE_IMAGE" width="309" height="600" /></p>
<p>That’s not a good user experience. How do they even know the Delete button is there? The solution is to have a scrollable panel for the sets of numbers. Then, the user can scroll through the numbers without losing the Delete button off the bottom of the screen. With the new scroll-panel feature in bbUI.js, I was ready to rock n&#8217; roll!</p>
<p>The code for showing the sets of numbers is pretty simple. There are two divs: the outer and the inner div. The two divs work together to make sure the numbers are centered on the screen:</p>
<p><code> &lt;div class="centerOuter"&gt;<br />
&lt;div id="numberDiv" class="centerInner"&gt;&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>For completeness, here’s the centerOuter and centerInner CSS:</p>
<p><code>.centerOuter<br />
{<br />
width: 100%;<br />
text-align: center;<br />
}</code></p>
<p>.centerInner<br />
{<br />
display: inline-block;<br />
}</p>
<p>As with the other elements in the bbUI.js, the scroll-panel is a div that gets a special tag. The tag used is data-bb-type and the value is “scroll-panel”. I figured I would add this to the outer div and all would be grand:</p>
<p><code> &lt;div data-bb-type=”scroll-panel” style=”height: 800px” class="centerOuter"&gt;<br />
&lt;div id="numberDiv" class="centerInner"&gt;&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>Notice I also added a style tag to specify the height of the panel. This style tag limits the height of the div and helps to create the scrolling affect I wanted. Now the numbers could scroll and the delete button could stay put. However, there was an unforeseen side effect: I lost the centering of the numbers.</p>
<p><img class="aligncenter size-full wp-image-10687" title="" src="http://rimdevblog.files.wordpress.com/2012/08/bbui-scroll-panel-2.jpg?w=309&#038;h=600" alt="" width="309" height="600" /></p>
<p>It turns out that the only formatting you can add to the scroll panel is <code>style=”height: ###px”</code>. This tag is necessary so the panel knows its boundaries. Without this style, the panel would occupy the whole screen. At first I thought: no center, bummer. But not to worry! There is a simple solution: keep the centerOuter and centerInner divs the way they were and add the scrolling panel as a wrapper:</p>
<p><code> &lt;div data-bb-type="scroll-panel" id="scrollPanel" style="height: 800px"&gt;<br />
&lt;div class="centerOuter"&gt;<br />
&lt;div id="numberDiv" class="centerInner"&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>Voila! I now have the centered, scrollable sets of numbers while the delete button stays right where it is. Groovy!</p>
<p><img class="aligncenter size-full wp-image-10686" title="" src="http://rimdevblog.files.wordpress.com/2012/08/bbui-scroll-panel-3.jpg?w=309&#038;h=600" alt="" width="309" height="600" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10685/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10685/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10685&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/08/scroll-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/f39ae628054ae183cf8b25746979ec67?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">noctivagan</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/bbui-scroll-panel-1.jpg" medium="image">
			<media:title type="html">TTILE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/bbui-scroll-panel-2.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/bbui-scroll-panel-3.jpg" medium="image" />
	</item>
		<item>
		<title>Hello OggVorbis</title>
		<link>http://devblog.blackberry.com/2012/08/hello-oggvorbis/</link>
		<comments>http://devblog.blackberry.com/2012/08/hello-oggvorbis/#comments</comments>
		<pubDate>Tue, 07 Aug 2012 16:48:39 +0000</pubDate>
		<dc:creator>Ramprasad Madhavan</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[OggVorbis]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[OpenAL]]></category>
		<category><![CDATA[sample code]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10567</guid>
		<description><![CDATA[Using a sample project to show how to set up and use OpenAL and OggVorbis with the BlackBerry 10 Native SDK.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10567&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The audio portion of a native game or app has traditionally been a land of &#8220;#ifdefs&#8221; and low-level platform specific code. This is especially true when targeting different devices supporting differing audio formats.</p>
<p>OpenAL, from Khronos, is designed to solve that exact problem. It is an open source, cross platform 3D Sound API for use in games and multimedia apps. Thankfully, OpenAL 1.1 is readily available on BlackBerry® 10. It is supported on multiple platforms and due to its API looking strikingly similar its 3D graphics cousin OpenGL API, it has proved to be very easy to learn and integrate. OpenAL, however, does not directly support compressed audio formats out-of-the-box. This could result in games having bigger audio files and hence a bigger memory footprint.</p>
<p>Enter OggVorbis.</p>
<p>There are several compressed audio formats and associated libraries available and I recommend OggVorbis for the following reasons:</p>
<ul>
<li>It’s lightweight</li>
<li>It’s open source</li>
<li>It’s professional quality audio encoding</li>
<li>It’s streaming support</li>
</ul>
<p>If you need further convincing, please visit <a href="http://www.vorbis.com/faq/" target="_new">their site</a>.</p>
<p>This blog post uses a sample project to show how to set up and use OpenAL and OggVorbis with the BlackBerry 10 Native SDK. The sample is forked off the famous &#8220;cascades cowbell app&#8221; and minor modifications have been made to show how to load and play .ogg and .wav files. Assuming you are already familiar with the BlackBerry 10 Native SDK, here are the main steps to follow:</p>
<p><span id="more-10567"></span></p>
<h3><strong>Convert your assets</strong></h3>
<p>Download a tool of your choice from <a href="http://www.vorbis.com/software" target="_new">http://www.vorbis.com/software</a> to convert the heavy WAV PCM files to the slender OGG files.</p>
<h3><strong>Add the OggVorbis library to your project</strong></h3>
<p>OggVorbis is already ported and available at the BlackBerry Github community, so go ahead download the <a href="https://github.com/blackberry/OggVorbis" target="_new">source code</a> <code>()</code> and compile it using BlackBerry 10 Native SDK. Once compiled, add the library (example: libvorbis.a) and the headers into a folder inside the cowbell application project directory. Let&#8217;s call it &#8220;external-lib&#8221;. Now modify the cowbell.pro project to include the header and library files.</p>
<pre>LIBS   += -lOpenAL -lalut -L../external-lib/oggvorbis/lib/qnx/arm/ -L../external-lib/oggvorbis/lib/qnx/x86/ -lvorbis

INCLUDEPATH += ../src ../external-lib/oggvorbis/include
SOURCES += ../src/*.cpp 
HEADERS += ../src/*.h</pre>
<p>Now that we have the project setting done, we can focus on loading and playing the .ogg file.</p>
<h3><strong>Open the OGG file</strong></h3>
<p>The function that opens up the access to the OggVorbis file is <code>ov_open</code>. Declare an <code>OggVorbis_File</code> file type that is returned by the ov_open. This file will be used to decode the OggVorbis file.</p>
<pre>OggVorbis_File ogg_file;
ALenum format;
int result;
unsigned int size = 0;

rewind(file);

// Open the ogg file
if (ov_open(file, &amp;ogg_file, NULL, 0) &lt; 0)
fclose(file);</pre>
<h3><strong>Calculate the unpacked audio file size</strong></h3>
<p>In order to load the uncompressed data into an OpenAL buffer, we need to store the audio data in a temporary buffer. The size of the audio buffer can be found using a simple formula: (<em>number of channels</em>) * (<em>number of samples</em>) * (<em>number of bytes per packet</em>)</p>
<p>The number of channels info can be retrieved into vorbis_info using the ov_info function. The number of samples can be found using the ov_pcm_total function.</p>
<pre>vorbis_info* info;
// Get the file info for creating the audio buffer
info = ov_info(&amp;ogg_file, -1);

if (info-&gt;channels == 1)
	format = AL_FORMAT_MONO16;
else
	format = AL_FORMAT_STEREO16;

// buffer size = (no. of channels) * (no. of samples) * 2 (for 16 bit)
unsigned int data_size = ov_pcm_total(&amp;ogg_file, -1) * info-&gt;channels * 2;</pre>
<h3><strong>Decode the audio file</strong></h3>
<p>Once we have a temp buffer allocated, the <code>ov_read</code> function can be used to read and decode blocks of audio data.</p>
<pre>char* data = new char[data_size];

// Read the Ogg file into audio buffer
while (size &lt; data_size) {
	result = ov_read(&amp;ogg_file, data + size, data_size - size, 0, 2, 1, &amp;section);
	if (result &gt; 0)
		size += result;
	else if (result &lt; 0) {
		delete data;
		return false;
	}
	else {
		break;
	}
}</pre>
<h3><strong>Load the data into an OpenAL buffer</strong></h3>
<p>Assuming we have already initialized OpenAL context and audio buffers to hold audio data, we can now upload the unpacked data into it.</p>
<pre>// Load PCM data into OpenAL buffer.
alBufferData(buffer, format, data, data_size, info-&gt;rate);

ALenum error = alGetError();
if (error != AL_NO_ERROR)
	reportOpenALError(error);</pre>
<p>Playing the audio is no different than playing regular PCM audio data.</p>
<p>The full sample is available under an Open Source license at <a href="https://github.com/blackberry/Cascades-Community-Samples/tree/master/HelloOggVorbis" target="_new">here</a>. Enjoy and consider participating in our Open Source community</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10567/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10567/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10567&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/08/hello-oggvorbis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/ba5492209a7823e5998202d3e638830d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rmadhavan</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Write a Push-Enabled Application using BlackBerry WebWorks for BlackBerry 10</title>
		<link>http://devblog.blackberry.com/2012/08/blackberry-10-webworks-push-app/</link>
		<comments>http://devblog.blackberry.com/2012/08/blackberry-10-webworks-push-app/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 17:49:40 +0000</pubDate>
		<dc:creator>Alex Kinsella</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Native SDK Development]]></category>
		<category><![CDATA[BlackBerry 10]]></category>
		<category><![CDATA[BlackBerry 10 WebWorks]]></category>
		<category><![CDATA[blackberry webworks]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[invoke]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[Push app]]></category>
		<category><![CDATA[Push Service API]]></category>
		<category><![CDATA[Push-Enabled]]></category>
		<category><![CDATA[sample code]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=10546</guid>
		<description><![CDATA[Explaining how to write a good application using the BlackBerry WebWorks SDK.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10546&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><i>Guest post from Matthew D&#8217;Andrea &#8211; Ed.</i></p>
<p>You might have heard the terms “push” and “push notifications” thrown around before. So in a nutshell, what’s push good for? Push does pretty much what the name implies: it allows you to push information to BlackBerry® smartphones the moment it is available, and the user gets the push message almost immediately after it’s sent.</p>
<p>Push is an interesting technology because you need to write two applications for it to work:</p>
<p>1)	You have to write a server-side push application (sometimes called a <strong>Push Initiator</strong>) so that you can send out push messages to BlackBerry smartphones.<br />
2)	You also have to write a client-side push application (sometimes called a <strong>push-enabled application</strong>) so that users can receive those push messages on a BlackBerry smartphone.</p>
<p>I highly recommend that you look at the Push Service SDK to write your Push Initiator. You can download and find information on that SDK here: <a href="https://developer.blackberry.com/services/push" target="_new">https://developer.blackberry.com/services/push</a></p>
<p>The rest of this blog post concentrates on the push-enabled application, and explains how to write a good application using the BlackBerry® WebWorks™ SDK.</p>
<p><span id="more-10546"></span></p>
<p>The Push Service APIs that are part of the BlackBerry WebWorks SDK are brand new for BlackBerry® 10. When we created the APIs, our goal was to start fresh – to make things clean and simple. We also wanted to make sure that the Push Service APIs would work well with other new APIs introduced for BlackBerry 10, like invoke events (that is, the blackberry.invoked feature).</p>
<p>There are only two classes that you have to worry about in the Push Service APIs:</p>
<p>1)	<i>PushService</i> has the business logic that you need to start receiving push messages in your app</p>
<p>and</p>
<p>2)	<i>PushPayload</i> is essentially a value object containing the content and headers of your push message.</p>
<p>Now that you want your app to start receiving pushes, where do you start? The first question to ask yourself is whether or not you’re developing this app for the general public. If you are, you should register to evaluate the Push Service at this link: <a href="https://www.blackberry.com/profile/?eventId=8121" target="_new">https://www.blackberry.com/profile/?eventId=8121</a>  After registering, you’ll receive an email with all the information that you need to write your push-enabled application, including your application ID, password, and the PPG URL you will be pushing messages to. If you’re developing your app for enterprise users, you don’t have to worry about registering.</p>
<p>Alright, what’s next?</p>
<p>At some point, you should check out the <strong>Push Capture</strong> sample app available here: <a href="https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/pushCapture" target="_new">https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/pushCapture</a>. The sample is a fully functional app that uses the Push Service APIs.</p>
<p>The UI for the sample app looks like this:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks.jpg?w=289&#038;h=480" alt="TITLE_IMAGE" title="" width="289" height="480" class="aligncenter size-full wp-image-10550" /></p>
<p>There are also a lot of good examples and information in the API Reference about the <i>PushService</i> and <i>PushPayload</i> classes. For information about the <i>PushService</i> class, see <a href="https://developer.blackberry.com/html5/apis/blackberry.push.PushService.html" target="_new">https://developer.blackberry.com/html5/apis/blackberry.push.PushService.html</a> For information about the <i>PushPayload</i> class, see <a href="https://developer.blackberry.com/html5/apis/blackberry.push.PushPayload.html" target="_new">https://developer.blackberry.com/html5/apis/blackberry.push.PushPayload.html</a></p>
<p>In order to use the Push Service APIs, you need to update your application’s <i>config.xml</i>:</p>
<p>1)	You need to reference the blackberry.push feature:</p>
<p><code>&lt;feature id=”blackberry.push” /&gt;</code></p>
<p>2)	You need to add a feature tag for blackberry.invoked:</p>
<p><code>&lt;feature id=“blackberry.invoked” /&gt;</code></p>
<p>This feature tag relates to the handling of invoke events. A push notification comes into your application as an invoke event.</p>
<p>3)	Finally, you need to have an entry relating to the invoke events that you receive for push messages:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks-2.jpg?w=600&#038;h=148" alt="" title="" width="600" height="148" class="aligncenter size-full wp-image-10549" /></p>
<p>Take note of the id attribute (also known as the “invoke target id”). This attribute has to match the <i>options.invokeTargetID</i> that is passed in to the call to the static <i>create</i> function of the <i>PushService</i> class (more about the create function in a moment). Another important detail is that the action tag is set to “<code>bb.action.PUSH</code>”. This setting makes it clear that the invoke relates specifically to push messages.</p>
<p>Now, here’s a quick rundown of the Push Service APIs. Don’t worry, there aren’t many.</p>
<p>1)	Call the static <i>create</i> function on the <i>PushService</i> class to get a <i>PushService</i> object you can start using. If the <i>create</i> call fails, you won’t have access to a <i>PushService</i> object. That’s why the <i>create</i> function has success and fail callbacks. You’ll need a lot of the info from the email you received when you registered to evaluate the Push Service (for public apps), so have that info handy for this call.</p>
<p>2)	If your application is not running, one of the major advantages of push is to allow your application to be launched when a new push comes in, and to have your app continue to run in the background. This allows valuable device resources to be saved because your app doesn’t have to be running all the time to be able to receive push messages.</p>
<p>The default behavior for your application is to not have it launch when a new push comes in. That’s where the <i>launchApplicationOnPush</i> function comes in (from the <i>PushService</i> class). If you call it with a value of true, then it will activate the launch functionality. You can turn this functionality off at any time by calling <i>launchApplicationOnPush</i> again with a value of false.</p>
<p>3)	Call the <i>createChannel</i> function on your <i>PushService</i> object to allow pushes to start coming to your app.</p>
<p>When that’s done, how does the server-side Push Initiator know who to push to? There’s something we call a “token” that you get back when you do a <i>createChannel</i>. You need to pass the toke along to the Push Initiator so it knows who to address a push to. If you’re using the Push Service SDK I recommended above, then you just simply pass this token to the Push Initiator using an HTTP request (we call it a subscribe operation).</p>
<p>4)	Ok, you’re now ready to receive pushes (you created the channel) and you’re ready to send pushes (the Push Initiator has the token). Fire off a push to the token using your Push Initiator.</p>
<p>5)	In BlackBerry 10, the push comes to the app as an invoke event using the new blackberry.invoked feature in BlackBerry WebWorks. We register for the event with the following call:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks-3.jpg?w=600&#038;h=33" alt="" title="" width="600" height="33" class="aligncenter size-full wp-image-10548" /></p>
<p>Now that we have the invoke request in our invokedCallbackFunc callback, how do we get the push out of it? Simply call the <i>PushService</i> object’s <i>extractPushPayload</i> function passing in the invoke request and it will give you back a <i>PushPayload</i> object.</p>
<p>(<strong>Quick side note:</strong> You’ll probably want to make sure the invoke event you received was for a push. The invoke event can be for other various reasons too. It’s easy to check though. Just make sure </p>
<p><img src="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks-4.jpg?w=600&#038;h=28" alt="" title="" width="600" height="28" class="aligncenter size-full wp-image-10547" /></p>
<p>before you call <i>extractPushPayload</i>).</p>
<p>Here’s a link to the blackberry.invoked API Reference if you want to check it out: <a href="https://developer.blackberry.com/html5/apis/blackberry.invoked.html" target="_new">https://developer.blackberry.com/html5/apis/blackberry.invoked.html</a></p>
<p>6)	And there you go. You have the <i>PushPayload object</i>, and you can do whatever you want with the data.</p>
<p>You might have noticed that the “data” property of the <i>PushPayload</i> object is of type Blob. Look at the <i>extractPushPayload</i> function in the API Reference for <i>PushService</i> (see the link I gave above). It shows examples of how to convert that Blob into something that you can actually display to users.</p>
<p>7)	From this point onwards, you app will continue to receive push messages. If at any time you want your app to stop receiving push messages, simply call the <i>destroyChannel</i> function on your <i>PushService</i> object.</p>
<p>Sure, using push requires some extra effort. You do need to write two applications, but the benefits to your users are huge. Just imagine displaying notifications in your app the moment an event of interest happens in the real world. That’s a pretty powerful thing.</p>
<p>And that’s why the BlackBerry WebWorks SDK for the client-side application (and Push Service SDK for the server-side application) is there to help make your life easier and to use push to its full potential.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/10546/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/10546/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=10546&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/08/blackberry-10-webworks-push-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d0e94a7e96e80d5911732d43f31a39c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Alex K.</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks-2.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks-3.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/08/r6-webworks-4.jpg" medium="image" />
	</item>
		<item>
		<title>Best Practices for Internationalizing your BlackBerry WebWorks App</title>
		<link>http://devblog.blackberry.com/2012/06/internationalizing-webworks-app/</link>
		<comments>http://devblog.blackberry.com/2012/06/internationalizing-webworks-app/#comments</comments>
		<pubDate>Mon, 18 Jun 2012 14:09:53 +0000</pubDate>
		<dc:creator>Naveen</dc:creator>
				<category><![CDATA[Java Development]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[blackberry webworks]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[texts]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=9764</guid>
		<description><![CDATA[Demonstrating the best ways to internationalize your BlackBerry WebWorks application.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=9764&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="text-align:center;"><img class="aligncenter size-full wp-image-9769" src="http://rimdevblog.files.wordpress.com/2012/06/webworks.jpg?w=550&#038;h=255" alt="TITLE_IMAGE" width="550" height="255" /></p>
<p>Last month, we looked at <a href="http://devblog.blackberry.com/2012/05/app-internationalization" target="_new">how to internationalize your BlackBerry® Java® application</a>. In this post, we will look at how to internationalize your BlackBerry® WebWorks™ application. There are a few options for accomplishing this – let’s take a look.</p>
<h3><strong>Using JavaScript and storing all the texts locally</strong></h3>
<p>One common way to internationalize your web application is to remove all strings from your code and have them all in an object with key-value pairs. All the code exists locally and nothings get stored on the server side.</p>
<p>This looks something like:</p>
<pre>var strings = {
	"en" : {
		"BUTTON_CANCEL" : "Cancel",
		"BUTTON_SAVE" : "Save"
	},
	nl: {
		"BUTTON_CANCEL" : "Annuleer",
		"BUTTON_SAVE" : "Opslaan"
	}
}</pre>
<p>Now let&#8217;s assume you keep the chosen language somewhere in a variable called language. You can then access the right string for the user language, like with the cancel button text for example:</p>
<p>Strings[language].BUTTON_CANCEL</p>
<p>That will give you either &#8216;Cancel&#8217; or &#8216;Annuleer&#8217; depending on whether the language variable contains &#8216;en&#8217; or &#8216;nl&#8217;.</p>
<p><span id="more-9764"></span></p>
<h3><strong>Using JavaScript and storing all the texts on a remote server</strong></h3>
<p>Another way of internationalizing your application in BlackBerry WebWorks platform is to use the server side code. Unfortunately, JavaScript does not have the concept of a resource file, and strings that will be generated by JavaScript must be defined in the code.</p>
<p>The easiest approach to deal with this issue is to define your JavaScript strings dynamically in server-side code (Java/JSP, ASPX, PHP, etc.). The following example defines some string resources in a JavaScript script block at the top of a JSP page:</p>
<p><img class="alignnone size-full wp-image-9768" title="" src="http://rimdevblog.files.wordpress.com/2012/06/webworks-1.jpg?w=600&#038;h=142" alt="" width="600" height="142" /></p>
<p>Assuming the currentLocale object is set to English (US), the resulting block should look like this:</p>
<p><img class="alignnone size-full wp-image-9767" title="" src="http://rimdevblog.files.wordpress.com/2012/06/webworks-2.jpg?w=600&#038;h=216" alt="" width="600" height="216" /></p>
<p>When currentLocale is set to German (Germany) it should change to this:</p>
<p><img class="alignnone size-full wp-image-9766" title="" src="http://rimdevblog.files.wordpress.com/2012/06/webworks-3.jpg?w=600&#038;h=195" alt="" width="600" height="195" /></p>
<p>There are a couple things to keep in mind with this approach. First, any strings that are embedded in the files, whether JSP/ASPX/PHP/etc. or JavaScript .js files, must be externalized, i.e. the strings should be moved into the string resource block as demonstrated above, and replaced in the code with their variable names. Second, the JavaScript string resource block should be defined before any other embedded blocks or .js file includes that make use of these externalized strings. For example, the resource block should be defined before the following function is called:</p>
<p><img class="alignnone size-full wp-image-9765" title="" src="http://rimdevblog.files.wordpress.com/2012/06/webworks-4.jpg?w=500&#038;h=272" alt="" width="500" height="272" /></p>
<h3><strong>Using JavaScript Object Notation (JSON)</strong></h3>
<p>Finally, another way to add multi-language support to your BlackBerry WebWorks application is to use JSON objects. Here is a sample which illustrates the use of JSON objects and changes the text dynamically based on the user’s language selection:</p>
<pre>&lt;html&gt;
&lt;body&gt;
&lt;h2&gt;Internationalization Sample in WebWorks&lt;/h2&gt;
&lt;h3&gt;Select a language:&lt;/h3&gt;
&lt;p&gt;

&lt;select id="languagechoice" onChange="displayGreeting()" &gt;
  &lt;option value="1"&gt;English&lt;/option&gt;
  &lt;option value="2"&gt;French&lt;/option&gt;
  &lt;option value="3"&gt;Spanish&lt;/option&gt;
  &lt;option value="4"&gt;German&lt;/option&gt;
&lt;/select&gt;

&lt;br/&gt; 
&lt;br/&gt;
&lt;br/&gt;

 &lt;span id="greetings"&gt;&lt;/span&gt; &lt;br/&gt;
&lt;/p&gt;

&lt;script type="text/javascript"&gt;

function displayGreeting(){

 var lang = document.getElementById("languagechoice");
 var lang_value = lang.options[lang.selectedIndex].value; 

 var JSONObject_en = {"hello":"Hello, Welcome to Internalization of WebWorks Applications in English!"};
 var JSONObject_fr = {"hello":"Hello, Welcome to Internalization of WebWorks Applications in French!"};
 var JSONObject_es = {"hello":"Hello, Welcome to Internalization of WebWorks Applications in Spanish!"};
 var JSONObject_de = {"hello":"Hello, Welcome to Internalization of WebWorks Applications in German!"};

 if(lang_value == 1){
   document.getElementById("greetings").innerHTML=JSONObject_en.hello 
 }
 else if (lang_value == 2 ){
   document.getElementById("greetings").innerHTML=JSONObject_fr.hello
 }
 else if (lang_value == 3 ){
   document.getElementById("greetings").innerHTML=JSONObject_es.hello
 }
 else{
   document.getElementById("greetings").innerHTML=JSONObject_de   .hello
 }
}

&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/9764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/9764/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=9764&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/06/internationalizing-webworks-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/83a3304d7f99cd7e5d2323b7338f7305?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">naveenm1</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/06/webworks.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/06/webworks-1.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/06/webworks-2.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/06/webworks-3.jpg" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2012/06/webworks-4.jpg" medium="image" />
	</item>
		<item>
		<title>QML/Cascades tip of the day: Managing Properties of an Existing Component</title>
		<link>http://devblog.blackberry.com/2012/06/cascades-tip-qml/</link>
		<comments>http://devblog.blackberry.com/2012/06/cascades-tip-qml/#comments</comments>
		<pubDate>Thu, 07 Jun 2012 18:46:47 +0000</pubDate>
		<dc:creator>Alex Kinsella</dc:creator>
				<category><![CDATA[Cascades]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Mario Boikov]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[QML]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[Slider]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=9733</guid>
		<description><![CDATA[A QML-language feature tip for Cascades that demonstrates the ability to add new properties to an already-existing component.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=9733&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>We&#8217;ve got a guest post from Mario Boikov to show you a great tip for QML! &#8211; Ed.</em></p>
<p><a href="http://rimdevblog.files.wordpress.com/2012/06/cascades.jpg"><img class="aligncenter size-full wp-image-9745" title="cascades" src="http://rimdevblog.files.wordpress.com/2012/06/cascades.jpg?w=502&#038;h=58" alt="TITLE_IMAGE" width="502" height="58" /></a></p>
<p>Today&#8217;s tip will demonstrate a QML-language feature: the ability to add new properties to an already-existing component. The example is based on the Slider control in <a href="http://devblog.blackberry.com/2012/05/blackberry-10-cascades-available-now/" target="_new">Cascades™</a> and gives a hint on how the feature can be used, at least for this particular situation.</p>
<p>If you read the Slider control documentation, you&#8217;ll find a property named value of type “float” &#8212; which, of course, holds a Slider&#8217;s current value. If you bind the value property to a Label&#8217;s text property, you&#8217;d expect the text to change as soon as you start to drag the Slider&#8217;s handle, but that is not how the Slider is implemented in Cascades. The slider will only notify value changes when the user removes the finger from the Slider. If you want to track changes to the Slider&#8217;s value while the user is moving the handle, you need to connect to the valueChanging signal.</p>
<p>The following is a typical Slider scenario where the Slider&#8217;s value is tracked. The code isn&#8217;t complete in the following two examples because I only want to highlight the relevant parts. You&#8217;ll find a complete example at the end of the article.</p>
<p><span id="more-9733"></span></p>
<pre>ImageView {
    id: imageView
}

Slider {
    id: imageScaleSlider

    fromValue: 0.5
    toValue: 2.5
    value: 1.0

    onValueChanging: {
        scaleValueLabel.text = "Scale: " + value.toFixed(2)
        imageView.scaleX = value
        imageView.scaleY = value
    }
}

Label {
    id: scaleValueLabel
    text: "Scale: " + imageScaleSlider.value.toFixed(2)
}</pre>
<p>The example above does the job. The Slider will update the label&#8217;s text property and also the ImageView&#8217;s scale factor, but personally, I don&#8217;t think this is a good solution. First of all, the code doesn&#8217;t utilize property bindings well which is one of the major advantages with QML. Secondly, the dependencies are inverted. The Slider has a strong coupling to both imageView and the scaleValueLabel. It should be the other way around &#8212; imageView and scaleValueLabel should bind to a property on imageScaleSlider.</p>
<p>So let&#8217;s take a look on how we can re-factor the code above, and try creating a more QMLified solution which makes use of proper property binding by adding a new property to the Slider control.</p>
<pre>ImageView {
    scaleX: imageScaleSlider.scaleValue
    scaleY: imageScaleSlider.scaleValue
}

Slider {
    id: imageScaleSlider

    // Introducing the trackable scale value property
    property real scaleValue: value

    fromValue: 0.5
    toValue: 2.5
    value: 1.0

    onValueChanging: scaleValue = value
}

Label {
    text: "Scale: " + imageScaleSlider.scaleValue.toFixed(2)
}</pre>
<p>So what happened? Well, we actually managed to remove imageScaleSlider&#8217;s dependency to the ImageView and the Label and we only have one line left of imperative code in the onValueChanging callback. Now the responsibility of how the scale value is used is given back to ImageView and Label. For example, the formatting of two decimals is handled by the expression in the Label&#8217;s text property on not in the onValueChanging callback.</p>
<p>I&#8217;m always trying to use property bindings as much as possible because it really fits well with the declarative QML language. Also, it often results in a more maintainable code and it&#8217;s easier to tell where a component gets its value from.</p>
<p>Finally, here’s the complete example:</p>
<pre>import bb.cascades 1.0

Page {
    id: mainPage

    content: Container {
        background: Color.create ("#262626")

        layout: StackLayout {
            leftPadding: 16
            rightPadding: 16
        }

        Container {
            layoutProperties: StackLayoutProperties {
                horizontalAlignment: HorizontalAlignment.Fill
                spaceQuota: 1
            }

            clipContentToBounds: true

            ImageView {
                imageSource: "asset:///image.jpg"

                layoutProperties: StackLayoutProperties {
                    verticalAlignment: VerticalAlignment.Center
                    horizontalAlignment: HorizontalAlignment.Center
                    spaceQuota: 1
                }

                scaleX: imageScaleSlider.scaleValue
                scaleY: imageScaleSlider.scaleValue
                scalingMethod: ScalingMethod.AspectFit
            }
        }

        Divider {}

        Container {

            Slider {
                id: imageScaleSlider

                property real scaleValue: value

                fromValue: 0.5
                toValue: 4
                value: 1.0

                onValueChanging: scaleValue = value
            }

            Label {
                id: label

                layoutProperties: StackLayoutProperties {
                    horizontalAlignment: HorizontalAlignment.Center
                }

                text: "Scale: " + imageScaleSlider.scaleValue.toFixed(2)
            }
        }
    }
}</pre>
<p>And that’s it! Let me know if you have any questions in the comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/9733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/9733/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=9733&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/06/cascades-tip-qml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d0e94a7e96e80d5911732d43f31a39c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Alex K.</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/06/cascades.jpg" medium="image">
			<media:title type="html">cascades</media:title>
		</media:content>
	</item>
	</channel>
</rss>
