<?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>Der Gleisarbeiter &#187; Android</title>
	<atom:link href="http://www.gleisarbeiter.de/category/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gleisarbeiter.de</link>
	<description></description>
	<lastBuildDate>Wed, 19 Oct 2011 14:38:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Struggling with RSA &amp; Bouncycastle on Android</title>
		<link>http://www.gleisarbeiter.de/2011/05/16/struggling-with-rsa-bouncycastle-on-android/</link>
		<comments>http://www.gleisarbeiter.de/2011/05/16/struggling-with-rsa-bouncycastle-on-android/#comments</comments>
		<pubDate>Mon, 16 May 2011 13:33:52 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Bouncycastle]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Javax]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=173</guid>
		<description><![CDATA[Hi everyone, today I had some time taking problems with the RSA implementation on Android. I was trying to do the following: Encrypt a log file on my Android device with a RSA public key, copy the device to the server and on the server decrypt the log file with my RSA private key using [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>today I had some time taking problems with the RSA implementation on Android. I was trying to do the following:</p>
<p>Encrypt a log file on my Android device with a RSA public key, copy the device to the server and on the server decrypt the log file with my RSA private key using a small Java-App.</p>
<p>So for testing I first encrypted and decrypted on my Android device using the generated key pair, then I encrypted and decrypted a String in my Java App using the same key pair. Worked nicely.<br />
Then I tried to copy the encrypted file from the Android device and decrypt in on the server. Didn&#8217;t work. But why? I used the same key pair all the time, but always got an Exception:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">javax.<span style="color: #006633;">crypto</span>.<span style="color: #006633;">BadPaddingException</span><span style="color: #339933;">:</span> Blocktype mismatch<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span></pre></div></div>

<p>Solution:</p>
<p>Afters some hours of trying, confirming that the key pairs are the same, using different options of saving the public key in the Android filesystem, etc. I finally found a post stating that Android is using the Bouncycastle Security provider. Bouncycastle&#8217;s default RSA implementation is: &#8220;RSA/None/NoPadding&#8221;, whereas Sun&#8217;s default security provider implementation is &#8220;RSA/None/PKCS1Padding&#8221;. So, no decryption possible when just using</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Cipher.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RSA&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>because of the different paddings used.</p>
<p>So for a solution I downloaded the bouncycastle Jar, added bounycastle as a Security provider to my Java App, and now use</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Cipher.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RSA&quot;</span>, <span style="color: #0000ff;">&quot;BC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It works fine now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2011/05/16/struggling-with-rsa-bouncycastle-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Offline Maps using Mobile Atlas Creator and usage on Android</title>
		<link>http://www.gleisarbeiter.de/2011/03/18/offline-maps-using-mobile-atlas-creator-and-usage-on-android/</link>
		<comments>http://www.gleisarbeiter.de/2011/03/18/offline-maps-using-mobile-atlas-creator-and-usage-on-android/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 17:43:56 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenStreetMaps]]></category>
		<category><![CDATA[Mobile Atlas Creator]]></category>
		<category><![CDATA[offline maps]]></category>
		<category><![CDATA[osmdroid]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=163</guid>
		<description><![CDATA[In part 2 of my tutorial (here is part 1) I&#8217;ll show you how to create offline maps using Mobile Atlas Creator and how to define min and max-zoom-levels in your app. Mobile Atlas Creator is a cool open-source project, that allows you to use different map providers (OpenStreetMap, Google Maps, Bing Maps, Yahoo Maps, [...]]]></description>
			<content:encoded><![CDATA[<p>In part 2 of my tutorial (here is <a href="http://www.gleisarbeiter.de/2011/03/17/using-openstreetmaps-with-osmdroid-on-android/">part 1</a>) I&#8217;ll show you how to create offline maps using Mobile Atlas Creator and how to define min and max-zoom-levels in your app.</p>
<p>Mobile Atlas Creator is a cool open-source project, that allows you to use different map providers (OpenStreetMap, Google Maps, Bing Maps, Yahoo Maps, &#8230;), donwload these maps and export to different atlas formats. Have a look at their website (<a href="http://mobac.dnsalias.org/">http://mobac.dnsalias.org/</a>) and download the latest stable version.</p>
<p><span id="more-163"></span><br />
Just unzip, start the .jar-file and you will be presented a world map.<br />
On the left side you can choose which map provider to use, i.e. OpenStreet Mapnik, Yahoo, &#8230;<br />
Choose OpenStret Mapnik for now.</p>
<p>Now navigate and zoom in to your preferred area, I took Hamburg, Germany using the arrow keys on your keyboard and the zoom selector in the upper left corner of the map.</p>
<p>Now make a selection of the parts you want to have as an offline map.</p>
<p><a href="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/ma1.jpg"><img src="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/ma1-300x170.jpg" alt="" title="Mobile Atlas Creator 1" width="300" height="170" class="alignnone size-medium wp-image-164" /></a></p>
<p>In the left panel you may now select which zoom levels to include in your offline map. Just select the numbers you want where 18 is highest detail level and 0 is lowest. The higher detail you want, the more tiles you have to download, the higher the final size of the offline map will be.<br />
<a href="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/mobileatlas3.jpg"><img src="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/mobileatlas3.jpg" alt="" title="mobileatlas3" width="300" height="185" class="alignnone size-full wp-image-165" /></a></p>
<p>When you&#8217;re happy with your selection on the map, click &#8220;Add Selection&#8221; in the &#8220;Atlas Content&#8221; area, and for &#8220;Atlas settings&#8221; select Osmdroid ZIP.<br />
<a href="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/mobileatlas4.jpg"><img src="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/mobileatlas4-150x150.jpg" alt="" title="mobileatlas4" width="150" height="150" class="alignleft size-thumbnail wp-image-166" /></a> <a href="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/mobileatlas5.jpg"><img src="http://www.gleisarbeiter.de/wp-content/uploads/2011/03/mobileatlas5-150x150.jpg" alt="" title="mobileatlas5" width="150" height="150" class="alignleft size-thumbnail wp-image-167" /></a></p>
<p>Now start atlas creation by clicking on the &#8220;Create Atlas&#8221; button. Now the selected parts of the map will be downloaded and bundled into a Osmdroid ZIP map. After some time, depending on your internet connection and the number of tiles you want to download, creation of the offline map is ready. You can now close Mobile Atlas Creator and have a look at the Mobile Atlas Creator folder. You&#8217;ll now find a subfolder &#8220;atlases&#8221; and inside the subfolder a .zip-file containing all the map tiles (you can confirm that by unzipping the file).</p>
<p>Now let&#8217;s use this map in our app. Open the app we created in the last part.<br />
We want to make sure we&#8217;re not using any data connection to download the map tiles, so just set</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">mapView.<span style="color: #006633;">setUseDataConnection</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>somewhere after the mapView instantiation and before setContentView(mapView).</p>
<p>Let&#8217;s also delete the map cache in case you followed the last tutorial. You can find a folder &#8220;osmdroid&#8221; on your android&#8217;s sdcard, just delete everything in that folder and instead put the zip-file we created inside.</p>
<p>Now adjust the zoom level and the latitude/longitude in your app to point to a place in the map you created and start your app.</p>
<p>You should now see a map, but that map wasn&#8217;t downloaded on-the-fly, now it&#8217;s using the map tiles in the zipped-atlas you created! You can confirm that by moving outside of the area you zipped and you will just see grey map tiles.</p>
<p>Problem is: you still can zoom out of the zoom levels you downloaded or zoom closer than you wanted the user to (you provided no maps for that zoom level). That&#8217;s ugly because the user only sees grey maps and may get lost.</p>
<p>Let&#8217;s discuss how to solve that problem in the next part of the tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2011/03/18/offline-maps-using-mobile-atlas-creator-and-usage-on-android/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using OpenStreetMaps with osmdroid on Android</title>
		<link>http://www.gleisarbeiter.de/2011/03/17/using-openstreetmaps-with-osmdroid-on-android/</link>
		<comments>http://www.gleisarbeiter.de/2011/03/17/using-openstreetmaps-with-osmdroid-on-android/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 17:58:01 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenStreetMaps]]></category>
		<category><![CDATA[Maps]]></category>
		<category><![CDATA[offline]]></category>
		<category><![CDATA[osmdroid]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=150</guid>
		<description><![CDATA[In this and the following tutorials I will show you how to include a OpenStreetMap in your activity, create offline maps for OpenStreetMaps and how to define minimum and maximum Zoom Levels (because you surely don&#8217;t want to provide all zoom levels for offline mode). 1. Get the needed osmdroid&#8217;s library, I used the osmdroid-android-3.0.2.jar [...]]]></description>
			<content:encoded><![CDATA[<p>In this and the following tutorials I will show you how to include a OpenStreetMap in your activity, create offline maps for OpenStreetMaps and how to define minimum and maximum Zoom Levels (because you surely don&#8217;t want to provide all zoom levels for offline mode).</p>
<p><span id="more-150"></span></p>
<p>1. Get the needed osmdroid&#8217;s library, I used the osmdroid-android-3.0.2.jar<br />
<a href="http://code.google.com/p/osmdroid/downloads/list">here</a></p>
<p>2. Lets create a new simple Android project (you know how that is done)</p>
<p>3. Add the osmdroid-library to your Android project.<br />
Depends on the IDE you use, in IntelliJ right-click on your project and select Open Module Settings. Goto &#8220;Libraries&#8221;, create a new library and attach the osmdroid-jar to it.</p>
<p>4. Now the fun begins:</p>
<p>In our AndroidManifest.xml define the permissions needed:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.ACCESS_FINE_LOCATION&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.ACCESS_COARSE_LOCATION&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.ACCESS_WIFI_STATE&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.ACCESS_NETWORK_STATE&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.INTERNET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-feature</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.hardware.location.network&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-feature</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.hardware.location.gps&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-feature</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.hardware.wifi&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Let&#8217;s create the easiest MapView.<br />
In the Activity&#8217;s onCreate-method create a new Object of Type MapView (exactly: org.osmdroid.views.MapView) like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">MapView mapView <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MapView<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #cc66cc;">256</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That uses the context as the first parameter, and the tile size of 256px (needed later).<br />
We want to be able to zoom in and out, so let&#8217;s define that:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">mapView.<span style="color: #006633;">setClickable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mapView.<span style="color: #006633;">setBuiltInZoomControls</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And let&#8217;s set the ContentView:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">setContentView<span style="color: #009900;">&#40;</span>mapView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So that was our onCreate-method. You may now start in the emulator or on your device and you should see the OpenStreetMap of the whole world. By clicking the MapView the standard zoom-in/zoom-out buttons appear and that should work, too, given you have an internet connection.</p>
<p>5. Play around with the options<br />
Let&#8217;s set the zoom level (the standard one is funny, but not really helpful). Thats done via an instance of the MapController, you can easily grab the MapView&#8217;s MapController by calling</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">mapView.<span style="color: #006633;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setZoom</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Play around with the numbers, to see how close to earth you can get <img src='http://www.gleisarbeiter.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>But maybe you also want to set a specific point as the map&#8217;s center. That&#8217;s also done via the MapController:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">mapView.<span style="color: #006633;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCenter</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> GeoPoint<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">53.550657</span>, <span style="color: #cc66cc;">9.995499</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Use a GeoPoint to specify the coordinates (first param is latitude, second longitude) and use this as paramter for setCenter(). Start the app again and look where I directed you: the most beautiful city in the world <img src='http://www.gleisarbeiter.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>6. Have fun playing with coordinates and zoom levels.</p>
<p>7. BUT! What if you want offline maps?<br />
Let&#8217;s say you&#8217;re on holiday in the US, Germany, England, India, China, (insert your favorite country) and need a map on your mobile device, but you don&#8217;t want to pay thousands of €/$/¥/(insert your favorite currency) just for displaying a map?<br />
Also, how do we set set minimum and maximum zoom levels?</p>
<p>Next time&#8230; <img src='http://www.gleisarbeiter.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>This is the complete onCreate method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        mapView <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MapView<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #cc66cc;">256</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mapView.<span style="color: #006633;">setClickable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mapView.<span style="color: #006633;">setBuiltInZoomControls</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        mapView.<span style="color: #006633;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setZoom</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mapView.<span style="color: #006633;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCenter</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> GeoPoint<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">39.461078</span>, <span style="color: #cc66cc;">2.856445</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        setContentView<span style="color: #009900;">&#40;</span>mapView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2011/03/17/using-openstreetmaps-with-osmdroid-on-android/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Problem updating nbandroid for NetBeans to v0.8</title>
		<link>http://www.gleisarbeiter.de/2009/07/28/problem-updating-nbandroid-for-netbeans-to-v0-8/</link>
		<comments>http://www.gleisarbeiter.de/2009/07/28/problem-updating-nbandroid-for-netbeans-to-v0-8/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 20:28:12 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=128</guid>
		<description><![CDATA[I&#8217;ve had a problem after the update of the nbandroid plugin for NetBeans. After updating the debugging mode neither in emulator, nor on real device, doesn&#8217;t work anymore. To fix this, put the following lines in build-impl.xml in the debugging section. Just remove the old part and paste in the new: &#60;target depends=&#34;init,-debug-start-debuggee&#34; if=&#34;netbeans.home&#34; name=&#34;-debug-start-debugger&#34;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a problem after the update of the nbandroid plugin for NetBeans. After updating the debugging mode neither in emulator, nor on real device, doesn&#8217;t work anymore.</p>
<p>To fix this, put the following lines in build-impl.xml in the debugging section. Just remove the old part and paste in the new:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init,-debug-start-debuggee&quot;</span> <span style="color: #000066;">if</span>=<span style="color: #ff0000;">&quot;netbeans.home&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;-debug-start-debugger&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;androidproject1:nbjpdaconnect</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init,compile,-start-emulator,-wait-for-emulator,-install-app&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;-debug-start-debuggee&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${adb}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;${android.target.device}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;shell&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;am start -D -n ${main.component}/${main.class}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;getdebuggerport</span> <span style="color: #000066;">addressProperty</span>=<span style="color: #ff0000;">&quot;local.debug.port&quot;</span> <span style="color: #000066;">app</span>=<span style="color: #ff0000;">&quot;${main.component}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init,compile,-debug-start-debuggee,-debug-start-debugger&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Debug project in IDE.&quot;</span> <span style="color: #000066;">if</span>=<span style="color: #ff0000;">&quot;netbeans.home&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;debug&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init&quot;</span> <span style="color: #000066;">if</span>=<span style="color: #ff0000;">&quot;netbeans.home&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;-debug-start-debugger-stepinto&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;androidproject1:nbjpdastart</span> <span style="color: #000066;">stopclassname</span>=<span style="color: #ff0000;">&quot;${main.class}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee&quot;</span> <span style="color: #000066;">if</span>=<span style="color: #ff0000;">&quot;netbeans.home&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;debug-stepinto&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2009/07/28/problem-updating-nbandroid-for-netbeans-to-v0-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing an Android Mobile Game &#8211; Part 2</title>
		<link>http://www.gleisarbeiter.de/2009/06/24/developing-an-android-mobile-game-part-2/</link>
		<comments>http://www.gleisarbeiter.de/2009/06/24/developing-an-android-mobile-game-part-2/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 17:03:43 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Spiele]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Space Janitor]]></category>
		<category><![CDATA[Spiel]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=102</guid>
		<description><![CDATA[This is part 2 of my Android mobile game series. I want to develop a game just like my Widget game for the Vodafone Widget Runtime: Space Janitor. So, in the last part we created some parts of the UI the user sees when he starts the game. Today we want to create a small [...]]]></description>
			<content:encoded><![CDATA[<p>This is part 2 of my Android mobile game series. I want to develop a game just like my Widget game for the Vodafone Widget Runtime: <a href="http://widget.vodafone.com/de/categories/14-entertainment/widgets/32-space-janitor">Space Janitor</a>.</p>
<p>So, in the last part we created some parts of the UI the user sees when he starts the game.</p>
<p>Today we want to create a small part of the real &#8220;Game View&#8221;!<br />
First, lets change the standard layout of the Android App. The layout file can be found in res/layout/main.xml.<br />
The standard is a simple LinearLayout with a TextView, that currently just displays &#8220;Hello&#8230;&#8221; when you start the game.<br />
Let&#8217;s remove this part and change it to:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FrameLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;GameView</span></span>
<span style="color: #009900;">    	<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/game&quot;</span></span>
<span style="color: #009900;">    	<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    	<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RelativeLayout</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/text&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/space_janitor_info_text&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:visibility</span>=<span style="color: #ff0000;">&quot;visible&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_centerInParent</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:gravity</span>=<span style="color: #ff0000;">&quot;center_horizontal&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:textColor</span>=<span style="color: #ff0000;">&quot;#88ffffff&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:textSize</span>=<span style="color: #ff0000;">&quot;24sp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RelativeLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/FrameLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>First, we define a Game View that we can use later on to hold the game graphics. Second we defined a RelativeLayout that holds a TextView, we need this to display some infos later on.</p>
<p>Now let&#8217;s extend the code to use this views.</p>
<p>Create a new class called GameView in your App. The GameView extends SurfaceView and has to implement the SufaceHolder.Callback interface. Add the yet unimplemented methods and a constructor to fulfill the interface&#8217;s requirements.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GameView <span style="color: #000000; font-weight: bold;">extends</span> SurfaceView <span style="color: #000000; font-weight: bold;">implements</span> SurfaceHolder.<span style="color: #006633;">Callback</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> GameView<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context, <span style="color: #003399;">AttributeSet</span> attrs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>context, attrs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated constructor stub</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> surfaceChanged<span style="color: #009900;">&#40;</span>SurfaceHolder holder, <span style="color: #000066; font-weight: bold;">int</span> format, <span style="color: #000066; font-weight: bold;">int</span> width,
			<span style="color: #000066; font-weight: bold;">int</span> height<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> surfaceCreated<span style="color: #009900;">&#40;</span>SurfaceHolder holder<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> surfaceDestroyed<span style="color: #009900;">&#40;</span>SurfaceHolder holder<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The SurfaceView is designated to hold the game graphics. Via the SurfaceHolder.Callback we are informed about dimension changes, i.e. when the user switches to landscape mode.</p>
<p>In the Main View we now have to code a connection to the Game View, we&#8217;ll do this via an instance variable of GameView. Add a variable of the type &#8220;GameView&#8221; to your Activity.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SpaceJanitor <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MENU_START <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> GameView myGameView<span style="color: #339933;">;</span>
        ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In our &#8220;onCreate&#8221;-method we have to initialize this variable and we would like to give the GameView the ability to display some info in the TextView we recently defined in our layout file, like &#8220;Game Over&#8221;, etc. So:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   requestWindowFeature<span style="color: #009900;">&#40;</span><span style="color: #003399;">Window</span>.<span style="color: #006633;">FEATURE_NO_TITLE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   myGameView <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>GameView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">game</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   myGameView.<span style="color: #006633;">setTextView</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This implies that we have to add a method &#8220;setTextView&#8221; in the GameView class to save a reference on this TextView locally.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTextView<span style="color: #009900;">&#40;</span>TextView findViewById<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub	</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the next part we will add a thread to handle graphic updates, user actions, etc. etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2009/06/24/developing-an-android-mobile-game-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Developing an Android mobile game &#8211; Part 1</title>
		<link>http://www.gleisarbeiter.de/2009/06/01/developing-an-android-mobile-game-part-1/</link>
		<comments>http://www.gleisarbeiter.de/2009/06/01/developing-an-android-mobile-game-part-1/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 12:20:19 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spiele]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=94</guid>
		<description><![CDATA[Game development tutorial on Android &#8211; Part 1 First I have to say that I am using Eclipse and the Android plugin to program, because it really minifies the work needed. If your using another IDE you have to change some of the steps according to your IDE&#8217;s workflow, but the code stays the same. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Game development tutorial on Android &#8211; Part 1</strong></p>
<p>First I have to say that I am using Eclipse and the Android plugin to program, because it really minifies the work needed. If your using another IDE you have to change some of the steps according to your IDE&#8217;s workflow, but the code stays the same.</p>
<p>I decided that my game should have a welcome screen and an options menu to start the game (or later when playing to pause or stop the game). That is easily done with Android.<br />
First lets create a new project in Android, name it what you like, I chose &#8220;Space Janitor&#8221; (I assume that you already now how to create new Android project, otherwise refer to one of the many tutorials).</p>
<p><span id="more-94"></span><br />
You will then see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.rakery.android.spacejanitor.part1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SpaceJanitor <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We want to use the full screen for our game and don&#8217;t need the window title, so add the following to the onCreate Method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">requestWindowFeature<span style="color: #009900;">&#40;</span><span style="color: #003399;">Window</span>.<span style="color: #006633;">FEATURE_NO_TITLE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Press Cmd-Shift-O in Eclipse (sorry, only have a Mac, don&#8217;t know which keys on Win/Linux) to automatically import the needed dependencies (here android.view.Window).</p>
<p>Next, lets create the Options Menu to start the game.<br />
We don&#8217;t want to keep the Text-Strings in our code, so lets move them to the XML file in res/values/strings.xml.<br />
When using Eclipse you will be presented with the following screen after double-clicking the file:</p>
<p><img src="http://www.gleisarbeiter.de/wp-content/uploads/2009/06/strings-in-eclipse.png" alt="Editing Strings in Eclipse" /></p>
<p>So, now you can easily add a new string key-value pair. Add a key &#8220;MENU_FIRST&#8221; and as value &#8220;Start new game&#8221; to the strings.xml.<br />
We will later add more menu items, but this one is enough for now.</p>
<p>So how do we add this String as a Menu item to the options menu?<br />
On Android when an activity starts a method onCreateOptionsMenu is called automatically at some points. So we can override the normal method of the class Activity and add our own onCreateOptionsMenu-method.<br />
Lets do this by adding the following right under the onCreate Method</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> onCreateOptionsMenu<span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span> menu<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreateOptionsMenu</span><span style="color: #009900;">&#40;</span>menu<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        menu.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, MENU_START, <span style="color: #cc66cc;">0</span>, R.<span style="color: #006633;">string</span>.<span style="color: #006633;">MENU_FIRST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The add-Method takes 4 arguments: the groupId, the itemId, the order, and a title.<br />
As you can see, we set the title by reading R.string.MENU_FIRST (the key we used for the text-string).<br />
I also defined a</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MENU_START <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></div></div>

<p>for my activity, that is now set as the menu itemId, which can later be used to identify user clicks on a menu item.<br />
I&#8217;ve set the group ID to 0 because currently there is only one group with the ID zero, and I want to order the items in the order I add them to the menu, so I can set order to 0. If you would like to order in a different way you would have to set the order explicitly.</p>
<p>Now we also want to react on user clicks on a menu item. Once again we override a method defined in Activity called onOptionsItemsSelect:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> onOptionsItemsSelect<span style="color: #009900;">&#40;</span><span style="color: #003399;">MenuItem</span> item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>item.<span style="color: #006633;">getItemId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	   	<span style="color: #666666; font-style: italic;">// do something with the clicks</span>
	   	<span style="color: #000000; font-weight: bold;">case</span> MENU_START<span style="color: #339933;">:</span>
		<span style="color: #666666; font-style: italic;">// TODO: Define what to do on click</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here we can make use of the constant MENU_START we defined to compare it to the itemID.</p>
<p>Start the emulator and you will see a black screen with a text &#8220;Hello World, Space Janitor&#8221;. When clicking on the options button, the menu will show up and display the Menuitem &#8220;Start new game&#8221;.</p>
<p>So, this was part one of the game development on Android tutorial, not much game development here, but we have to start somewhere <img src='http://www.gleisarbeiter.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2009/06/01/developing-an-android-mobile-game-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Developing an Android mobile game &#8211; Introduction</title>
		<link>http://www.gleisarbeiter.de/2009/06/01/developing-an-android-mobile-game-part-introduction/</link>
		<comments>http://www.gleisarbeiter.de/2009/06/01/developing-an-android-mobile-game-part-introduction/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 10:51:24 +0000</pubDate>
		<dc:creator>gleisarbeiter</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Spiele]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.gleisarbeiter.de/?p=91</guid>
		<description><![CDATA[I am currently learning more on Android development and for me the best way to learn something new is to try it out by myself. It&#8217;s the same when I learn new ways of programming: reading books and tutorials is fine, but when I try to build my own apps I learn even more. So [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently learning more on Android development and for me the best way to learn something new is to try it out by myself. It&#8217;s the same when I learn new ways of programming: reading books and tutorials is fine, but when I try to build my own apps I learn even more.</p>
<p>So I decided to write a simple game for the Android platform, not that there aren&#8217;t already enough games in the Android Market, more because in the last weeks I mostly concentrated on developing games for the Vodafone mobile widget runtime. I made a game called &#8220;Space Janitor&#8221;, which I now want to port to the Android platform. I would like to extend the game at some points, i.e. making use of the device accelerometer sensors to move the spaceship to the left or to the right, or vibrating the mobile when being hit by an asteroid. That would be real fun.</p>
<p>Another good way to learn is to try to explain the things one learned to others. That was a great way to learn during my university time, because the professors always wanted to have something explained <img src='http://www.gleisarbeiter.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  So if one already explained the learned things to others, it was no problem to explain it again to the professor. I now decided to keep track of my development by writing some blog posts about how to develop the game, thus explaing it to others. But I would also very much appreciate your comments on how to improve the quality and the speed of my code as I would call myself just a novice in Android programming. Maybe you&#8217;ve also got some more tipps for game improvement, game handling, gameplay, etc.</p>
<p>I will somewhat unregularly post new entries in my blog, so keep in touch.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gleisarbeiter.de/2009/06/01/developing-an-android-mobile-game-part-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

