<?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/"
	>

<channel>
	<title>Substance of Code &#187; Tips and Tricks</title>
	<atom:link href="http://www.substanceofcode.com/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.substanceofcode.com</link>
	<description>Software Artisan Tommi Laukkanen</description>
	<lastBuildDate>Mon, 26 Dec 2011 19:36:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Flipboard page flip with Qt QML</title>
		<link>http://www.substanceofcode.com/2011/03/14/flipboard-page-flip-with-qt-qml/</link>
		<comments>http://www.substanceofcode.com/2011/03/14/flipboard-page-flip-with-qt-qml/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 21:26:31 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Qt]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[flipboard]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[qml]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=938</guid>
		<description><![CDATA[If there&#8217;s one app that would make me to buy iPad that would be Flipboard. Their social magazine have such a beautiful user experience which others could really learn from. I&#8217;d like to see more apps like that on other &#8230; <a href="http://www.substanceofcode.com/2011/03/14/flipboard-page-flip-with-qt-qml/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If there&#8217;s one app that would make me to buy iPad that would be <a href="http://flipboard.com/" onclick="pageTracker._trackPageview('/outgoing/flipboard.com/?referer=');">Flipboard</a>. Their social magazine have such a beautiful user experience which others could really learn from. I&#8217;d like to see more apps like that on other tablets as well.</p>
<p>I thought about trying to mimic the Flipboard&#8217;s page turn effect with the QML script. The page turn is pretty simple and a bit more modern then traditional paper like curly page turn. In Flipboard the page rotates from the center like folding the screen.</p>
<p>I created this effect with <a href="http://doc.qt.nokia.com/latest/qml-flipable.html" onclick="pageTracker._trackPageview('/outgoing/doc.qt.nokia.com/latest/qml-flipable.html?referer=');">Flipable</a> element which is clipped with parent Item element so that only the half of the flipable is visible at all times. The flipable element contains a duplicate page content as the underlying element which is just created with HTML formatted Text element. I also added a flavor of shadow to the Transition animation so that inner part of the fold seems a bit darker. Shadow was created with transparent gradient image.</p>
<p>Here you can see the page turn (or fold) in action with the Nokia N900. Rendering speed wasn&#8217;t that fast when I used &#8220;raster&#8221; rendering and might have been way faster if &#8220;opengl&#8221; would have been used.</p>
<p><iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/GKONUZaFQho?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe></p>
<p>You can download the QML code from <a href="http://www.substanceofcode.com/downloads/flipboard_page_turn_with_qml.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2011/03/14/flipboard-page-flip-with-qt-qml/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Saturday Night App: NewsFlow</title>
		<link>http://www.substanceofcode.com/2010/10/09/saturday-night-app-newsflow/</link>
		<comments>http://www.substanceofcode.com/2010/10/09/saturday-night-app-newsflow/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 19:19:04 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Runtime]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wrt]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=803</guid>
		<description><![CDATA[There can&#8217;t be a better way of spending your Saturday night other then crafting and knitting new apps for your mobile devices. This Saturday I was missing a nice news reader for my Nokia N900. I tried to follow the &#8230; <a href="http://www.substanceofcode.com/2010/10/09/saturday-night-app-newsflow/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There can&#8217;t be a better way of spending your Saturday night other then crafting and knitting new apps for your mobile devices. This Saturday I was missing a nice news reader for my Nokia N900. I tried to follow the <a href="http://www.forum.nokia.com/" onclick="pageTracker._trackPageview('/outgoing/www.forum.nokia.com/?referer=');">Forum Nokia</a> workflow: Design, Develop, Distribute. Here&#8217;s what happened:</p>
<h1>Design</h1>
<div id="attachment_806" class="wp-caption alignright" style="width: 210px"><a href="http://www.substanceofcode.com/wp-content/uploads/2010/10/palette.png" rel="lightbox[803]"><img class="size-full wp-image-806" title="The First Raindrop" src="http://www.substanceofcode.com/wp-content/uploads/2010/10/palette.png" alt="" width="200" height="41" /></a><p class="wp-caption-text">Palette for news reader app</p></div>
<p>The first<strong> </strong>thing that I had to do was to get my app a decent color palette so that app would feel nice and consistent through out the views. I tend to use <a href="http://www.colourlovers.com" onclick="pageTracker._trackPageview('/outgoing/www.colourlovers.com?referer=');">colourlovers.com</a> to either create or browse good palettes. This time I decided to use nice blueish palette, <a href="http://www.colourlovers.com/palette/490780/The_First_Raindrop" onclick="pageTracker._trackPageview('/outgoing/www.colourlovers.com/palette/490780/The_First_Raindrop?referer=');">The First Raindrop</a>.</p>
<p>Now it was time to do the actual fun part and design the overall view of the apps user interface. As I tend to use <a href="http://labs.qt.nokia.com/2010/07/19/the-qt-web-runtime-journey-begins/" onclick="pageTracker._trackPageview('/outgoing/labs.qt.nokia.com/2010/07/19/the-qt-web-runtime-journey-begins/?referer=');">Qt Web Runtime</a> for development it&#8217;s pretty easy to do the UI drafts with simple static HTML page. These drafts can easily be extended to be used in the final app.</p>
<p>I really wanted to have horizontal panels this time around. Maybe to provide a book-like user interaction where you go to the next page to the right and back to the left. The following image shows the mockup of the UI.</p>
<div id="attachment_807" class="wp-caption alignnone" style="width: 650px"><a href="http://www.substanceofcode.com/wp-content/uploads/2010/10/proto.png" rel="lightbox[803]"><img class="size-full wp-image-807" title="User interface prototype" src="http://www.substanceofcode.com/wp-content/uploads/2010/10/proto.png" alt="" width="640" height="299" /></a><p class="wp-caption-text">User interface mockup for news reader app</p></div>
<p>As the mobile device display is quite small I thought that I&#8217;d show only one panel on one screen. If this would be created for a tablet like device then it could be wise to show e.g. all three or two panels at once on a display. I&#8217;ll have to test that when I get the first <a href="http://meego.com/" onclick="pageTracker._trackPageview('/outgoing/meego.com/?referer=');">MeeGo </a>tablet in my hands :)</p>
<h1>Develop</h1>
<p>Now that I had a draft UI HTML I started knitting the functionality with JavaScript to my new app which I would call <strong>NewsFlow</strong>. I used<a href="http://jquery.com/" onclick="pageTracker._trackPageview('/outgoing/jquery.com/?referer=');"> jQuery</a> library to do all the heavy lifting like loading and parsing the RSS feeds.</p>
<p>As a small detail I used CSS animation for the panel switching so when user e.g. selects a feed from a feed list then view is switched to feed items page. With jQuery the CSS animations can be easily created with the <em>animate</em> method:</p>
<pre class="brush:javascript">...
$(left).css("left", "0");
$(left).css("position", "fixed");
$(left).animate(
    // What CSS value(s) to animate
    {left:"-" + width + "px"},
    // Animation time in milliseconds
    1000,
    // Function to call when animation is finished
    function() {
		$(window).scrollTop();
		$(left).css("position", "relative");
	});
...</pre>
<p>Then was the time to do the normal widget packaging and upload the app to the device. Here is what it turned out to be:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="505" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/OC7HmGoxeSQ?fs=1&amp;hl=en_US&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="505" src="http://www.youtube.com/v/OC7HmGoxeSQ?fs=1&amp;hl=en_US&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>I have to say that I like it a lot as a simple news reader. This was again a good reminder on how fast the Qt WRT is to develop with. Now I just hope that Ovi Store would also start supporting Qt WRT apps soon so that the <strong>Distribute</strong> part would be easier.</p>
<p>What features you&#8217;d like to have in your news reader app?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2010/10/09/saturday-night-app-newsflow/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Crafting Qt Web Runtime Widgets</title>
		<link>http://www.substanceofcode.com/2010/10/05/crafting-qt-web-runtime-widgets/</link>
		<comments>http://www.substanceofcode.com/2010/10/05/crafting-qt-web-runtime-widgets/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 21:30:38 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Runtime]]></category>
		<category><![CDATA[clock]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[flip]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wrt]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=789</guid>
		<description><![CDATA[It&#8217;s amazing how simple it is to create desktop widgets with Qt Web Runtime. I was able to create this &#8220;flip clock&#8221; widget in less then hour and most of that time I spent tweaking the background image pixels in &#8230; <a href="http://www.substanceofcode.com/2010/10/05/crafting-qt-web-runtime-widgets/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s amazing how simple it is to create desktop widgets with Qt Web Runtime. I was able to create this &#8220;flip clock&#8221; widget in less then hour and most of that time I spent tweaking the background image pixels in Pixelmator :)</p>
<p><img class="alignleft size-full wp-image-790" title="Flip clock widget for Nokia N900" src="http://www.substanceofcode.com/wp-content/uploads/2010/10/flip_clock_widget_nokia_n900-e1286225667679.png" alt="" width="640" height="384" /></p>
<p>The code behind this widget is only around 20 lines of HTML, 20 lines of JavaScript, 35 lines of CSS and one config file.</p>
<p>In HTML I only create divs for hours, minutes and date. In JavaScript I refresh the view to show current time and date and start the timer which updates the values in every 60s. Layout is done with a background PNG image and hours, minutes and date DIVs are placed on top of the image in CSS with position:fixed styling.</p>
<p><em>index.html</em></p>
<pre class="brush:html">
<script type="text/javascript">
$(function() {
	refresh();
	autoRefresh = setInterval("refresh()", 60000);		
});
</script>
...
<body>
<div id="widgetContent">
<div id="hours">00</div>
<div id="minutes">00</div>
<div id="date">-</div>
</div>

</body>
</pre>
<p><em>JavaScript (script.js)</em></p>
<pre class="brush:javascript">function refresh() {
	var time = new Date();
	var hours = time.getHours();
	if(hours&lt;10) {
		hours = "0" + hours;
	}
	var minutes = time.getMinutes();
	if(minutes&lt;10){
		minuts = "0" + minutes;
	}
	$("#hours").text(hours);
	$("#minutes").text(minutes);

	var day = time.getDay();
	var month = time.getMonth();
	var weekday = ["Sunday", "Monday",
"Tuesday", "Wednesday",
"Thursday", "Friday",
"Saturday"];
	var months = [
"Jan", "Feb", "Mar",
"Apr", "May", "June",
"July", "Aug", "Sep",
"Oct", "Nov", "Dec"];	

	$("#date").text(weekday[day] + ", " + time.getDate() + " " + months[month]);
}</pre>
<p>You can download the source code in ZIP <a href="http://www.substanceofcode.com/downloads/widgets/Clock.zip">here</a>. You can install the widget directly to your Nokia N900 <a href="http://www.substanceofcode.com/downloads/widgets/Clock.wgt">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2010/10/05/crafting-qt-web-runtime-widgets/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Storing Objects to HTML5 Client-side Storage</title>
		<link>http://www.substanceofcode.com/2010/08/30/storing-objects-to-html5-client-side-storage/</link>
		<comments>http://www.substanceofcode.com/2010/08/30/storing-objects-to-html5-client-side-storage/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 17:58:03 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Runtime]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[storage]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=756</guid>
		<description><![CDATA[Here is a handy tip on how to store your JavaScript objects into HTML5 client-side storage which is basically a simple key/value hashtable. You can easily store objects into a storage in JSON format. Code that I&#8217;m using for storing &#8230; <a href="http://www.substanceofcode.com/2010/08/30/storing-objects-to-html5-client-side-storage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is a handy tip on how to store your JavaScript objects into <a href="http://dev.w3.org/html5/webstorage/" onclick="pageTracker._trackPageview('/outgoing/dev.w3.org/html5/webstorage/?referer=');">HTML5 client-side storage</a> which is basically a simple key/value hashtable. You can easily store objects into a storage in <a href="http://www.json.org/" onclick="pageTracker._trackPageview('/outgoing/www.json.org/?referer=');">JSON</a> format.</p>
<p><a title="W3C Development with TextMate and Chrome by tlaukkanen, on Flickr" href="http://www.flickr.com/photos/tlaukkanen/4941960399/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/tlaukkanen/4941960399/?referer=');"><img src="http://farm5.static.flickr.com/4082/4941960399_20fd9a852c_z.jpg" alt="W3C Development with TextMate and Chrome" width="640" height="384" /></a></p>
<p>Code that I&#8217;m using for storing the &#8220;Task&#8221; objects in my GTD app:</p>
<pre class="brush:javascript">var jsonTasks = JSON.stringify( tasks );
localStorage.tasks = jsonTasks;</pre>
<p>That&#8217;s it. That is quite easy and can&#8217;t really think of many languages where you can persist objects with only few lines of code.</p>
<p>Code that I&#8217;m using for retrieving objects from storage:</p>
<pre class="brush:javascript">tasks = JSON.parse( localStorage.tasks );</pre>
<p>I hope you find this helpful. It works great on <a href="http://labs.trolltech.com/blogs/2010/07/19/the-qt-web-runtime-journey-begins/" onclick="pageTracker._trackPageview('/outgoing/labs.trolltech.com/blogs/2010/07/19/the-qt-web-runtime-journey-begins/?referer=');">Qt Web Runtime</a> running on my Nokia N900.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2010/08/30/storing-objects-to-html5-client-side-storage/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Labyrinth Game with W3C Widget, Accelerometer API and Nokia N900</title>
		<link>http://www.substanceofcode.com/2010/08/21/labyrinth-game-with-w3c-widget-accelerometer-api-and-nokia-n900/</link>
		<comments>http://www.substanceofcode.com/2010/08/21/labyrinth-game-with-w3c-widget-accelerometer-api-and-nokia-n900/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 18:03:29 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Runtime]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[labyrinth]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[w3c]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=744</guid>
		<description><![CDATA[I&#8217;ve been crafting the W3C Widgets for Qt Web Runtime (WRT) from the day Qt guys released the version for my Nokia N900. I haven&#8217;t been so productive on any other platform. This time I crafted a small game of &#8230; <a href="http://www.substanceofcode.com/2010/08/21/labyrinth-game-with-w3c-widget-accelerometer-api-and-nokia-n900/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been crafting the W3C Widgets for <a href="http://labs.trolltech.com/blogs/2010/07/19/the-qt-web-runtime-journey-begins/" onclick="pageTracker._trackPageview('/outgoing/labs.trolltech.com/blogs/2010/07/19/the-qt-web-runtime-journey-begins/?referer=');">Qt Web Runtime</a> (WRT) from the day Qt guys released the version for my Nokia N900. I haven&#8217;t been so productive on any other platform.</p>
<p>This time I crafted a small game of <a href="http://en.wikipedia.org/wiki/Labyrinth_(game)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Labyrinth_game?referer=');">Labyrinth</a>. The idea of game should be pretty familiar to everyone. You&#8217;ll need to guide the metal ball to goal by tilting the game board. I made it so that on each level there is one hole more compared to previous level. Levels are created randomly.</p>
<p><a title="My Labyrinth game for Nokia N900 by tlaukkanen, on Flickr" href="http://www.flickr.com/photos/tlaukkanen/4913005749/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/tlaukkanen/4913005749/?referer=');"><img src="http://farm5.static.flickr.com/4135/4913005749_0567fe6dfc_z.jpg" alt="My Labyrinth game for Nokia N900" width="640" height="384" /></a></p>
<p>On the technical side it was easy to use device sensor in JavaScript to track the tilt angles:</p>
<pre class="brush:javascript">// Ball's acceleration
var ballAccX = 0.0;
var ballAccY = 0.0;

// Initialize sensors
wrtSensors = nokia.device.load("sensors");
wrtSensors.startChannel(callback, "AccelerometerAxis", errorCallback);

// Callback function for sensors
// The 2.5 is a magic number that felt good :)
function callback(data) {
	ballAccX = parseFloat(data.axisX) / 2.5;
	ballAccY = parseFloat(data.axisY) / 2.5;
} 

function errorCallback(err) {
}</pre>
<p>The animation and simple ball physics are done in JavaScript timer:</p>
<pre class="brush:javascript">// Initialize timer to be run on every 50ms
animate = setInterval("animateBall()", 50);

// Timer function contains most of game logic like
// checking if ball have reached the goal or hole.
// Ball movement and physics are also calculated here
function animateBall() {
	if(gameover==false &amp;&amp; goal==false) {
		ballVelX = ballVelX - ballAccX;
		ballX = ballX + ballVelX;
		ballVelY = ballVelY - ballAccY;
		ballY = ballY + ballVelY;	

		checkLimits();
		checkGoal();		

		// Move the ball DIV
		$("#ball").css("left", ballX);
		$("#ball").css("top", ballY);
	} else {
		if(goal) {
			$("#gameover").text("Creating next level!");
			$("#gameover").show();
			clearInterval(animate);
			level++;
			setTimeout("reset()", 1500);
		} else {
			$("#gameover").text("GAME OVER!");
			$("#gameover").show();
			level = 1;
			clearInterval(animate);
		}
	}
}</pre>
<p>Here is a small video of what it looks like in action on my Nokia N900:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="505" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/kEPP0bbSarA?fs=1&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="505" src="http://www.youtube.com/v/kEPP0bbSarA?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>There are still few known issues in the game:</p>
<ul>
<li>It can create a level where goal is unreachable.</li>
<li>Another issue I&#8217;m having with the game is that I haven&#8217;t found out how the <strong>backlight</strong> could be forced to stay on. I wrote a <a href="http://developer.qt.nokia.com/forums/viewthread/534/" onclick="pageTracker._trackPageview('/outgoing/developer.qt.nokia.com/forums/viewthread/534/?referer=');">question</a> on Qt Web Runtime forum but haven&#8217;t received any answers. If you know how to do it, please <a href="http://developer.qt.nokia.com/forums/viewthread/534/" onclick="pageTracker._trackPageview('/outgoing/developer.qt.nokia.com/forums/viewthread/534/?referer=');">respond</a> to my thread.</li>
<li>It would be nice to have <strong>fullscreen</strong> mode in games like this. If you know how to create fullscreen widget, please <a href="http://developer.qt.nokia.com/forums/viewthread/380/" onclick="pageTracker._trackPageview('/outgoing/developer.qt.nokia.com/forums/viewthread/380/?referer=');">respond to this thread</a> in Qt Forum.</li>
</ul>
<p>Finally, if you&#8217;d like to try it out yourself you can download the widget (ChromeBall.wgt) <a href="http://bit.ly/labyrinth-n900" onclick="pageTracker._trackPageview('/outgoing/bit.ly/labyrinth-n900?referer=');">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2010/08/21/labyrinth-game-with-w3c-widget-accelerometer-api-and-nokia-n900/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Check Screen Orientation with jQuery in W3C Widget</title>
		<link>http://www.substanceofcode.com/2010/08/13/check-screen-orientation-with-jquery-in-w3c-widget/</link>
		<comments>http://www.substanceofcode.com/2010/08/13/check-screen-orientation-with-jquery-in-w3c-widget/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 17:55:28 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Runtime]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wrt]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=733</guid>
		<description><![CDATA[Here is a small tip for your W3C Widget on how you can identify when screen orientation have changed. It&#8217;s simple to use additional JavaScript libraries in widgets so it makes sense to use something like jQuery in your widgets. &#8230; <a href="http://www.substanceofcode.com/2010/08/13/check-screen-orientation-with-jquery-in-w3c-widget/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is a small tip for your W3C Widget on how you can identify when screen orientation have changed.</p>
<p><a title="Screen rotation tutorial by tlaukkanen, on Flickr" href="http://www.flickr.com/photos/tlaukkanen/4885650601/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/tlaukkanen/4885650601/?referer=');"><img src="http://farm5.static.flickr.com/4143/4885650601_5c2f17d348_z.jpg" alt="Screen rotation tutorial" width="640" height="480" /></a></p>
<p>It&#8217;s simple to use additional JavaScript libraries in widgets so it makes sense to use something like jQuery in your widgets. You can do so by downloading the latest jQuery library from their site and adding that to your ZIP file as separate js file.</p>
<p>With jQuery you can add an event handler for the screen resize event. In the event you can easily check the window dimensions and with those you can define the screen orientation. This makes it easy to change the overall UI to match the landscape and portrait views. Like in some apps you may want to have your toolbar in left side in landscape view and on the bottom when on portrait view.</p>
<p>Here is the code how this can be done with jQuery:</p>
<pre class="brush:html">&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
 &lt;head&gt;
  &lt;title&gt;Rotation Test&lt;/title&gt;
  &lt;link type="text/css" href="css/style.css" rel="stylesheet"&gt;&lt;/style&gt;
  &lt;script src="js/jquery-1.4.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;

  $(window).resize( function(){
    var height = $(window).height();
    var width = $(window).width();

    if(width&gt;height) {
      // Landscape
      $("#mode").text("LANDSCAPE");
    } else {
      // Portrait
      $("#mode").text("PORTRAIT");
    }

   });
  &lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;
   &lt;div id="mode"&gt;LANDSCAPE&lt;/div&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>You can download the whole widget here: <a href="http://www.substanceofcode.com/downloads/widgets/Rotate.wgt">Rotate.wgt</a></p>
<p>Here is a sample how widget works in action on Nokia N900:<br />
<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/ByIo0RSBVpw?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ByIo0RSBVpw?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2010/08/13/check-screen-orientation-with-jquery-in-w3c-widget/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Create Simple W3C Widget</title>
		<link>http://www.substanceofcode.com/2010/08/10/how-to-create-simple-w3c-widget/</link>
		<comments>http://www.substanceofcode.com/2010/08/10/how-to-create-simple-w3c-widget/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:20:51 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[w3c]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wrt]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=719</guid>
		<description><![CDATA[Here are instructions how you can create a simple W3C widget that runs on Qt Web Runtime (WRT) e.g. on Nokia N900. Widgets are just ZIP packages containing at least two files: Configuration file (config.xml) and resource files (index.html and &#8230; <a href="http://www.substanceofcode.com/2010/08/10/how-to-create-simple-w3c-widget/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here are instructions how you can create a simple W3C widget that runs on Qt Web Runtime (WRT) e.g. on Nokia N900.</p>
<p>Widgets are just ZIP packages containing at least two files: Configuration file (config.xml) and resource files (index.html and other HTML, CSS, JavaScript and image files).</p>
<ul>
<li>widget.wgt &#8211; <span style="color: #999999;"><em><span style="color: #999999;">zip archive renamed to *.wgt, containing:</span><br />
</em></span></p>
<ul>
<li>config.xml <em>- <span style="color: #999999;">configurations</span></em></li>
<li>index.html <em>- <span style="color: #999999;">content</span></em></li>
</ul>
</li>
</ul>
<p><span style="color: #000000;">Configuration file contains information about the widget like name, version, author, icon etc. Example of simple config.xml file:</span></p>
<pre class="brush:xml">&lt;?xml version="1.0" ?&gt;
&lt;widget xmlns="http://www.w3.org/ns/widgets" id="http://www.substanceofcode.com/hellowidget" version="0.1.0"&gt;
  &lt;!-- Name of the widget --&gt;
  &lt;name&gt;Hello World&lt;/name&gt;
  &lt;!-- Description is shown when installing widget --&gt;
  &lt;description&gt;Simple hello world widget&lt;/description&gt;
  &lt;!-- Start page for widget --&gt;
  &lt;content src="index.html" /&gt;
  &lt;!-- Default icon for widget --&gt;
  &lt;icon src="icon.png" /&gt;
  &lt;!-- Widget author --&gt;
  &lt;author&gt;Tommi Laukkanen&lt;/author&gt;
&lt;/widget&gt;
</pre>
<p>Content is good old HTML, CSS, JavaScript etc. files. For example simple HTML page like this:</p>
<pre class="brush:html">&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Hello!&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Hello W3C Widget World!&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>When these two files are packaged into a ZIP archive and renamed to Hello.wgt you can install it on your Nokia N900 just by clicking the file in file browser. When you run the app it&#8217;ll look something like this:</p>
<div class="wp-caption alignnone" style="width: 650px"><a title="Hello World W3C Widget by tlaukkanen, on Flickr" href="http://www.flickr.com/photos/tlaukkanen/4879451450/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/tlaukkanen/4879451450/?referer=');"><img title="Widget running on Nokia N900 with Qt Web Runtime" src="http://farm5.static.flickr.com/4095/4879451450_2408a52832_z.jpg" alt="Hello World W3C Widget" width="640" height="384" /></a><p class="wp-caption-text">Widget running on Nokia N900 with Qt Web Runtime</p></div>
<p>I hope that you find this tutorial helpful and start crafting your own widgets!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2010/08/10/how-to-create-simple-w3c-widget/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>LWUIT 1.1 for Java ME Developers</title>
		<link>http://www.substanceofcode.com/2009/10/18/lwuit-1-1-for-java-me-developers/</link>
		<comments>http://www.substanceofcode.com/2009/10/18/lwuit-1-1-for-java-me-developers/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 17:42:52 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[MIDlet]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[javame]]></category>
		<category><![CDATA[lwuit]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=621</guid>
		<description><![CDATA[One of the problems with Java ME applications containing more advanced UI components have been that it is really painful to have it rendered consistently across different platforms and devices. I&#8217;ve used to implement my own set of practices on &#8230; <a href="http://www.substanceofcode.com/2009/10/18/lwuit-1-1-for-java-me-developers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the problems with Java ME applications containing more advanced UI components have been that it is really painful to have it rendered consistently across different platforms and devices. I&#8217;ve used to implement my own set of practices on displaying lists of tweets in <a href="http://www.substanceofcode.com/software/mobile-twitter-client-twim/">Twim</a> or todo lists in <a href="http://www.substanceofcode.com/software/mobile-task-manager/">Mobile Task Manager</a>. Now I came across a nice looking UI library for Java ME called <a href="https://lwuit.dev.java.net/" onclick="pageTracker._trackPageview('/outgoing/lwuit.dev.java.net/?referer=');">LWUIT</a>.</p>
<p><a href="http://moby.to/ikb5mu" target="_blank" onclick="pageTracker._trackPageview('/outgoing/moby.to/ikb5mu?referer=');"><img src="http://img.mobypicture.com/06854b2b58ab84a31801a85e3e697712_view.jpg" alt="Posted using Mobypicture.com" /></a></p>
<p>LWUIT supports such nice things like theming, transitions and animation. It also includes new UI components like TabbedPane and Dialogs.</p>
<p>I just got a new book to review, <a href="http://www.packtpub.com/lwuit-1-1-for-java-me-developers?utm_source=Substanceofcode.com&amp;utm_medium=bookrev&amp;utm_content=blog&amp;utm_campaign=mdb_000381" onclick="pageTracker._trackPageview('/outgoing/www.packtpub.com/lwuit-1-1-for-java-me-developers?utm_source=Substanceofcode.com_amp_utm_medium=bookrev_amp_utm_content=blog_amp_utm_campaign=mdb_000381&amp;referer=');">LWUIT 1.1 for Java ME Developers</a>, written by <a href="http://java.net/pub/au/491" onclick="pageTracker._trackPageview('/outgoing/java.net/pub/au/491?referer=');">Biswajit Sarkar</a>. If you think that LWUIT could scratch your itch then I&#8217;d recommend on having this book on your desk as it works pretty nicely as a reference as well as good introduction to the whole library.</p>
<p>Book contains lots of emulator screenshots which help to understand the concepts very well. This combined with lots of sample code makes it really easy to learn all features of LWUIT library. Only one oddity is that it&#8217;s referencing to Sprint SDK where it could as well be the Sun&#8217;s original WTK but that doesn&#8217;t really have any affect on code samples.</p>
<p>Book&#8217;s first chapter is a good introduction to the library. The following chapters explain the default components and then there is one chapter on how to create a custom component. Last chapters dig into resources, LWUIT designer, themes, animations and transitions, painters, effects and logging. The index is also very complete which makes the book work well as a good resource in the bookshelf even after the first reading.</p>
<p>Check out the <a href="http://www.packtpub.com/lwuit-1-1-for-java-me-developers?utm_source=Substanceofcode.com&amp;utm_medium=bookrev&amp;utm_content=blog&amp;utm_campaign=mdb_000381" onclick="pageTracker._trackPageview('/outgoing/www.packtpub.com/lwuit-1-1-for-java-me-developers?utm_source=Substanceofcode.com_amp_utm_medium=bookrev_amp_utm_content=blog_amp_utm_campaign=mdb_000381&amp;referer=');">publisher site</a> for more information about the book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2009/10/18/lwuit-1-1-for-java-me-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Task Manager Video</title>
		<link>http://www.substanceofcode.com/2009/09/29/mobile-task-manager-video/</link>
		<comments>http://www.substanceofcode.com/2009/09/29/mobile-task-manager-video/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 19:17:05 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[MIDlet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[gtd]]></category>
		<category><![CDATA[mobile-task]]></category>
		<category><![CDATA[mobile-task-manager]]></category>
		<category><![CDATA[todo]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=637</guid>
		<description><![CDATA[Pali Madra from E71 by Nokia blog created a very nice video of Mobile Task Manager running on Nokia E71. Check out the full review that he wrote on his blog, here.]]></description>
			<content:encoded><![CDATA[<p>Pali Madra from <a href="http://e71bynokia.blogspot.com/" onclick="pageTracker._trackPageview('/outgoing/e71bynokia.blogspot.com/?referer=');">E71 by Nokia</a> blog created a very nice video of Mobile Task Manager running on Nokia E71. Check out the full review that he wrote on his blog, <a href="http://e71bynokia.blogspot.com/2009/09/mobile-smartphone-software-for-e71.html" onclick="pageTracker._trackPageview('/outgoing/e71bynokia.blogspot.com/2009/09/mobile-smartphone-software-for-e71.html?referer=');">here</a>.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/9iML32sMjKo&#038;hl=en&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/9iML32sMjKo&#038;hl=en&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2009/09/29/mobile-task-manager-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Touchscreen Scrolling in Java ME</title>
		<link>http://www.substanceofcode.com/2009/07/29/coding-touchscreen-scrolling-in-java-me/</link>
		<comments>http://www.substanceofcode.com/2009/07/29/coding-touchscreen-scrolling-in-java-me/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 20:27:38 +0000</pubDate>
		<dc:creator>Tommi Laukkanen</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[MIDlet]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[scrolling]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[touch]]></category>
		<category><![CDATA[touchscreen]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.substanceofcode.com/?p=590</guid>
		<description><![CDATA[Here&#8217;s the trick how you can add touchscreen scrolling to your J2ME applications. The key to touchscreen support is the Canvas class and its&#8217; methods pointerPressed, pointerDragged and pointerReleased. These events are called when user puts finger on the screen &#8230; <a href="http://www.substanceofcode.com/2009/07/29/coding-touchscreen-scrolling-in-java-me/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the trick how you can add touchscreen scrolling to your J2ME applications. The key to touchscreen support is the Canvas class and its&#8217; methods <em>pointerPressed, pointerDragged </em>and <em>pointerReleased</em>. These events are called when user puts finger on the screen (pressed) and drags the finger (dragged) and finally when removes the finger (released). Each method has the x and y coordinates for the pointer action.</p>
<p>The scrolling is implemented with the pointerDragged event. We store the current location of the canvas to variables <em>verticalLoc</em> and <em>horizontalLoc</em>. When finger (pointer) is dragged then location is changed according to the dragged amount. Variables are used on <em>paint</em> method to draw the area so that it is scrolled that correctly. You can also see from the sample code how you can draw background with repeatable pattern image.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> ScrollingCanvas <span class="kw2">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ACanvas+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3ACanvas+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">Canvas</span></a> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Current location</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">private</span> <span class="kw4">int</span> verticalLoc, horizontalLoc;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;<span class="co1">// Last pointer (finger) location</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">private</span> <span class="kw4">int</span> lastX, lastY;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Background image size</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw4">int</span> IMAGE_WIDTH = <span class="nu0">183</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">private</span> <span class="kw2">static</span> <span class="kw2">final</span> <span class="kw4">int</span> IMAGE_HEIGHT = <span class="nu0">183</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> ScrollingCanvas<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;verticalLoc = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;horizontalLoc = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;setFullScreenMode<span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">protected</span> <span class="kw4">void</span> paint<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AGraphics+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3AGraphics+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">Graphics</span></a> g<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Draw background with pattern image</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp;<span class="kw4">int</span> x = horizontalLoc % IMAGE_WIDTH;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>x&gt;<span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;x -= IMAGE_WIDTH;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">int</span> origX = x;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">int</span> y = verticalLoc % IMAGE_HEIGHT;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>y&gt;<span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;y -= IMAGE_HEIGHT;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">boolean</span> verticalDone = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">while</span><span class="br0">&#40;</span>!verticalDone<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw4">boolean</span> horizontalDone = <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">while</span><span class="br0">&#40;</span>!horizontalDone<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp;g.<span class="me1">drawImage</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ImageRepository.<span class="me1">getBackground</span><span class="br0">&#40;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x, y, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AGraphics+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky" onclick="pageTracker._trackPageview('/outgoing/www.google.com/search?hl=en_amp_q=allinurl_3AGraphics+java.sun.com_amp_btnI=I_27m_20Feeling_20Lucky&amp;referer=');"><span class="kw3">Graphics</span></a>.<span class="me1">LEFT</span>|Graphics.<span class="me1">TOP</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;x += IMAGE_WIDTH;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>x&gt;getWidth<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;horizontalDone = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;x = origX;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;y += IMAGE_HEIGHT;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span>y&gt;getHeight<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;verticalDone = <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Finger is pressed on screen</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @param x coordinate</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @param y coordinate</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">protected</span> <span class="kw4">void</span> pointerPressed<span class="br0">&#40;</span><span class="kw4">int</span> x, <span class="kw4">int</span> y<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;lastX = x;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;lastY = y;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Finger is dragged on screen</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @param x coordinate</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @param y coordinate</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">protected</span> <span class="kw4">void</span> pointerDragged<span class="br0">&#40;</span><span class="kw4">int</span> x, <span class="kw4">int</span> y<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Calculate how much we moved horizontally</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">int</span> deltaHorizontal = lastX &#8211; x;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;horizontalLoc -= deltaHorizontal;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp;lastX = x;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Calculate how much we moved vertically</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">int</span> deltaVertical = lastY &#8211; y;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;verticalLoc -= deltaVertical;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp;lastY = y;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Repaint the screen since we have scrolled</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;repaint<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Here is a video of running this demonstration app in Nokia N97 SDK emulator:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/tJ0X-uPJsmk&amp;hl=en&amp;fs=1&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/tJ0X-uPJsmk&amp;hl=en&amp;fs=1&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.substanceofcode.com/2009/07/29/coding-touchscreen-scrolling-in-java-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

