<?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>a walking city &#187; mobile</title>
	<atom:link href="http://awalkingcity.com/blog/category/mobile/feed/" rel="self" type="application/rss+xml" />
	<link>http://awalkingcity.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 13 Dec 2011 17:23:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>HoneyGram: Instagram Browser For Honeycomb</title>
		<link>http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/</link>
		<comments>http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 03:55:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=797</guid>
		<description><![CDATA[Direct Link To HoneyGram In The Android Market I&#8217;ve been meaning to learn all of the new Android 3.0(Honeycomb) APIs but due to the emulator being excrutiatingly slow(understandable as it is emulating an actual system image, unlike the iPad simulator that is basically just running an OS X app in an iPad shaped window), and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="https://market.android.com/details?id=com.awc.browsograma">Direct Link To HoneyGram In The Android Market</a></p>
<p>I&#8217;ve been meaning to learn all of the new Android 3.0(Honeycomb) APIs but due to the emulator being excrutiatingly slow(understandable as it is emulating an actual system image, unlike the iPad simulator that is basically just running an OS X app in an iPad shaped window), and not wanting to shell out money for a data plan, I have had to wait to get my hands on a Xoom Wifi.</p>
<p style="text-align: left;">For my first Honeycomb application I wanted to create an app that took advantage of the form factor, processing power, and faster network connection of the device.  I also wanted something that could exercise all of the new APIs and UI widgets that are included in Honeycomb. I had been dabbling with the Instagram API and figured an image browser would take advantage of all of these features.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram3.png"><img class="aligncenter size-full wp-image-799" title="honeygram3" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram3.png" alt="" width="640" height="400" /></a><br />
Popular images</p>
<p>The application allows everyone to view the popular feed on instagram, as well as query images nearby your location, and search through tagged images.  If you have an Instagram account the fun really begins.  Authenticated users can view their friend feed, their own pictures, favorite images, comment on images, and follow/unfollow other users.</p>
<p>The Instagram API uses OAuth 2.0 which was a snap to implement compared to OAuth 1.x!  It also has a rate limit on how many queries can be made per key(users that are not logged in all share the same key, which can cause problems if the app gets popular).  I created a simple app using App Engine that uses the memcache API to cache query results for a period of time.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram4.png"><img class="aligncenter size-full wp-image-798" title="honeygram4" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram4.png" alt="" width="640" height="400" /></a></p>
<p style="text-align: center;">Nearby Images</p>
<p>As for building the app itself, Honeycomb provides a nice default theme and widget set up that makes building your app quick and good looking right out of the box.  Setting up a tabbed application with menu actions and subsections is a snap using the ActionBar.  I decided to use fragments as much as possible as it seemed like the most difficult new API to grasp.  After some trouble with Activity/Fragment lifecycles I got the hang of things and found it to be an incredibly powerful new set of tools.  I found Fragments to be a mixture of an activities, views, and services.  The activity portion is because of the various lifecycle methods and considerations.  Views because much of the fragment lifecycle involves view creation/modification.  Services because you have to go through the FragmentManager to manipulate fragments. You should never try to interact with a fragment through something like an instance/class variable.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/picdevice.png"><img class="size-full wp-image-812" title="picdevice" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/picdevice.png" alt="" width="640" height="400" /></a></p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/picdevice.png"></a>Image Detail</p>
<p>One of my favorite features is the Image AppWidget.  It uses the new StackView widget that provides a really nice looking and animated &#8220;stack&#8221; of views that automatically scroll and also let the user interact with through touching and dragging.  HoneyGram lets you add an Image widget for popular, friend, self, and tag feeds.  I also found that you could use the StackView in normal application layouts, although I plan on developing some other ways to visualize images.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/instacool.png"><img class="aligncenter size-full wp-image-803" title="instacool" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/instacool.png" alt="" width="640" height="400" /></a></p>
<p style="text-align: center;">AppWidget Dashboard Overkill!</p>
<p>Another feature I am proud of is the &#8220;interactive&#8221; surface view.  This view uses OpenGL ES to present any set of images in a randomly generated &#8220;pile.&#8221; The user can then use multitouch to move, rotate, bring to top, and hide any of the images.  Users can then save their work in the Gallery as well as share the image through any app on Android that allows image sharing.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram_interactive.png"><img class="size-full wp-image-801" title="honeygram_interactive" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram_interactive.png" alt="" width="640" height="400" /></a></p>
<p style="text-align: center;">Interactive Surface</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram2.png"><img class="aligncenter size-full wp-image-800" title="honeygram2" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram2.png" alt="" width="640" height="400" /></a></p>
<p style="text-align: center;">Instructions</p>
<p><strong>Uptake? </strong></p>
<p>Overall I had a really positive experience developing this application, but there are some issues with the Android Market that are preventing this app from reaching its target audience(people that own Android tablets).</p>
<p>The biggest issue is that there is no way to filter applications that are designed specifically for Honeycomb from within the Android Market application.  The only Tablet specific applications are in the &#8220;Featured Tablet Applications&#8221; list and that only contains 30 or so applications(most of which are just games that have been tweaked to work on the larger screen).  When you view other application categories it gives you a list of all the available Android applications in that category.  Anyone who has released an application on the Android Market knows that the &#8220;Just In&#8221; section of any category cycles so quickly it is practically impossible for anyone to see your application in that list.</p>
<p>Now I can understand that there simply aren&#8217;t enough Honeycomb specific applications to warrant a &#8220;Recent Tablet Applications&#8221; section but it is still difficult to find any outside of the featured apps.  Tablet applications will also never be able to be in the Top Paid/Free Applications sections because they will never get enough sales/downloads as their phone counterparts.</p>
<p>Another big issue is that users cannot directly rate or review applications through the Honeycomb version of the Android Market.  I admit I spent a good amount of time mindlessly tapping each part of my application description trying to find the right widget to rate and review.  It turns out you can leave a review and rating(but not just a rating) through the web interface for the Android Market</p>
<p>&nbsp;</p>
<p>I am still really excited about Honeycomb and designing and developing applications for Android tablets, but I am going to hold off on releasing any new applications until a) there are more devices in circulation and b) the Android Market improves its tablet sections</p>
<p>Gallery:</p>

<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/honeygram4/' title='honeygram4'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram4.png" class="attachment-thumbnail" alt="honeygram4" title="honeygram4" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/honeygram3/' title='honeygram3'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram3.png" class="attachment-thumbnail" alt="honeygram3" title="honeygram3" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/honeygram2/' title='honeygram2'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram2.png" class="attachment-thumbnail" alt="honeygram2" title="honeygram2" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/honeygram_interactive/' title='honeygram_interactive'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/honeygram_interactive.png" class="attachment-thumbnail" alt="honeygram_interactive" title="honeygram_interactive" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/mypictures/' title='mypictures'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/mypictures.png" class="attachment-thumbnail" alt="mypictures" title="mypictures" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/instacool/' title='instacool'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/instacool.png" class="attachment-thumbnail" alt="instacool" title="instacool" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/user/' title='user'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/user.png" class="attachment-thumbnail" alt="user" title="user" /></a>
<a href='http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/picdevice/' title='picdevice'><img width="150" height="93" src="http://awalkingcity.com/blog/wp-content/uploads/2011/04/picdevice.png" class="attachment-thumbnail" alt="picdevice" title="picdevice" /></a>

]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2011/04/10/honeygram-instagram-browser-for-honeycomb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android OpenGL ES 2.0 Progress</title>
		<link>http://awalkingcity.com/blog/2010/02/26/android-opengl-es-2-0-progress/</link>
		<comments>http://awalkingcity.com/blog/2010/02/26/android-opengl-es-2-0-progress/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 00:45:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=379</guid>
		<description><![CDATA[As I mentioned in my previous post I have been working through  the OpenGL ES 2.0 book and have been porting many of the examples to Android. I am going to go through some of the progress I have made so far. Besides getting the various Android side of things set up the biggest annoyance [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my previous post I have been working through  the OpenGL ES 2.0 book and have been porting many of the examples to Android. I am going to go through some of the progress I have made so far.</p>
<p>Besides getting the various Android side of things set up the biggest annoyance I found was that all of the shaders in the examples were hard coded.  They all look something like this inlined in the code:</p>
<pre name="code" class="c">

GLbyte vShaderStr[] =
&quot;attribute vec4 vPosition;    \n&quot;
&quot;void main()                  \n&quot;
&quot;{                            \n&quot;
&quot;   gl_Position = vPosition;  \n&quot;
&quot;}                            \n&quot;;

GLbyte fShaderStr[] =
&quot;precision mediump float;\n&quot;\
&quot;void main()                                  \n&quot;
&quot;{                                            \n&quot;
&quot;  gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n&quot;
&quot;}
</pre>
<p>Obviously this makes it fairly difficult to edit and test shaders in an external program so the first thing I did was create a mechanism to load a shader from the res/raw/ resource directory, drop it into native code, and compile/link into a shader program .  These code snippets should get you started:</p>
<p>In Android/Dalvik land load a shader into a string:</p>
<pre name="code" class="java">

String vShader = readFileAsString(GL2JNIView.this.getContext().getResources()
.openRawResource(R.raw.vshader));
</pre>
<p>Send the string to native land and load it into a character array, compile/link the shader program, and free the pointer:</p>
<pre name="code" class="c">

char *vertexShader = env-&gt;GetStringUTFChars(vShader, 0);

//load shader program

env-&gt;ReleaseStringUTFChars(vShader, vertexShader);
</pre>
<p>Here is a quick overview of some of the examples I have been working on, screen shots are straight from my Nexus One:</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/spincube.png"><img class="size-full wp-image-382  aligncenter" title="spincube" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/spincube.png" alt="" width="400" height="240" /></a></p>
<p>The mighty spinning cube demo, with a simple vertex and color fragment shader.  One major difference between ES 1.x and 2.0 is that all of the transformation functions have been done away with, instead you must manually manipulate a matrix and pass it into the vertex shader and multiply all the vertices by this matrix, fortunately the ES 2.0 book sample code comes with functions that map the old functions to the new approach.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/mt.png"><img class="aligncenter size-full wp-image-383" title="mt" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/mt.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/mt.png"></a>Here is the multi texturing example from Chapter 10 of the ES 2.0 book, multitexturing becomes a fairly simple formula which is performed inside of the fragment shader.</p>
<p style="text-align: center;">
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/cubemap.png"><img class="aligncenter size-full wp-image-388" title="cubemap" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/cubemap.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;">The Cube Map texturing example from Chapter 9 of the book.  ES 2.0 provides a straight forward method for rendering things like reflections on objects by using a cube texture map.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/particles.png"><img class="aligncenter size-full wp-image-387" title="particles" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/particles.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;">This is a shot of the Particle System demo from Chapter 13 of the book.  It is difficult to get a good screen shot of all of the particle movement.  All of the particle parameter are passed into the shaders and calculations are performed by the GPU.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/ship.png"><img class="aligncenter size-full wp-image-389" title="ship" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/ship.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;">One of the first things I wanted to do after I got done with the basics was to load a textured .obj model in dalvik/Android and load it into native code and render it using vertex/fragment shaders.  This is a sample model from this very cool <a href="http://code.google.com/p/android-gamedev/">OpenGL ES android tutorial/project</a>.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/sepia.png"><img class="aligncenter size-full wp-image-385" title="sepia" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/sepia.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;">The ES 2.0 book assumes that you already know how to do graphics programming with OpenGL as well as program Shaders , so I have been using many other resources for learning GLSL and graphics programming in general.  I have found that the best resources are usually just OpenGL books from 5 years ago.  This is an example of a sepia filter from this great book: <a href="http://books.google.com/books?id=iggJf7oIly8C&amp;lpg=PP1&amp;ots=kqZk-SuOcN&amp;dq=Shaders%20for%20Game%20Programmers&amp;pg=PP1#v=onepage&amp;q=&amp;f=false">Shaders For Game Programmers And Artists</a>.  The flag also waves using a simple sin() method on the z coord in the vertex shader.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/blur.png"><img class="aligncenter size-full wp-image-386" title="blur" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/blur.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;">This is a simple 4-sample blur shader from the above book.</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/mb.png"><img class="aligncenter size-full wp-image-384" title="mb" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/mb.png" alt="" width="173" height="288" /></a></p>
<p style="text-align: center;">This is my attempt at creating a motion blur shader. It renders the cube to a Frame Buffer Object then interpolates between a previous frame.  I haven&#8217;t gotten it to perform the proper blending of the two frames but I am pretty close to getting it to work.</p>
<p style="text-align: center;">
<p style="text-align: center;">Per-Pixel Lighting</p>
<p style="text-align: center;">I have been trying to get the per pixel lighting example from the ES 2.0 book to work but unfortunately they only provide the Shaders and a RenderMonkey workspace which leaves out some fairly crucial elements for actually getting it to run in code.</p>
<p style="text-align: center;">
<p style="text-align: left;">Next up I want to get familiar with all the various lighting effects you can do with shaders.  Shaders provide a much more flexible lighting model than the fixed function lighting options in ES 1.x, but it also makes doing lighting not as straight forward as it was.  After that I would like to put together some scenes and maybe get a simple game engine going with flexible shader options.</p>
<p>Here is a fur shader I made a while ago, I am having a hard time remembering the details of the implementation but it is based off of this <a href="http://www.sgtconker.com/2009/10/article-fur-rendering/">post</a>.<br />
<a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/fur-shader-with-shadowing-effects-variable-length-strands-some-other-effects...-...png"><img src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/fur-shader-with-shadowing-effects-variable-length-strands-some-other-effects...-...png" alt="" title="fur shader with shadowing effects, variable length strands, some other effects... .." width="240" height="400" class="aligncenter size-full wp-image-780" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2010/02/26/android-opengl-es-2-0-progress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using OpenGL ES 2.0 With Android 2.0 and up</title>
		<link>http://awalkingcity.com/blog/2010/02/05/using-opengl-es-2-0-with-android-2-0-and-up/</link>
		<comments>http://awalkingcity.com/blog/2010/02/05/using-opengl-es-2-0-with-android-2-0-and-up/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 00:27:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=365</guid>
		<description><![CDATA[* Update: r3 of the Android NDK has been released with OpenGL ES 2.0 support get it here * The Motorola Droid and the Nexus One are the first Android phones with graphics hardware that support OpenGL ES 2.0.  Developers have not yet had access to the advanced graphics API in the latest Android SDK/NDK [...]]]></description>
			<content:encoded><![CDATA[<p>* Update: r3 of the Android NDK has been released with OpenGL ES 2.0 support get it <a href="http://android-developers.blogspot.com/2010/03/android-ndk-r3.html">here</a> *</p>
<p>The Motorola Droid and the Nexus One are the first Android phones with graphics hardware that support OpenGL ES 2.0.  Developers have not yet had access to the advanced graphics API in the latest Android SDK/NDK , but it looks like official support for ES 2.0 in the Android NDK is imminent as the latest NDK code in the Android Open Source Project includes the libraries needed to access the OpenGL ES 2.0 API.  If you are impatient like I am and would like to dip your toes into the strange world of vertex and fragment shaders,  here is a quick way of getting OpenGL ES 2.0 support up and running in the current release of the Android SDK. ( This has been tested on OS X and a Nexus One, I would imagine it would work with Linux and the Droid too, no idea about Windows)</p>
<p>The first step is to <a href="http://source.android.com/download">download</a> the latest Android source code from <a href="http://source.android.com">AOSP</a>.  The project we are interested in is in: development/ndk.  Copy the ndk directory wherever you want.  The NDK is  missing the platform specific ARM toolchain binaries so we are just going to get those from the 1.6 release of the NDK which you can find <a href="http://d.android.com/sdk/ndk/1.6_r1/index.html">here</a>.  Copy the build/prebuilt/  directory of the 1.6 NDk to the build/ directory of the 2.0 NDK.</p>
<p>The next step is to run the host-setup.sh script in build/</p>
<blockquote><p>sh build/host-setup.sh</p></blockquote>
<p>After the set up script runs we are ready to build the sample hello-gl2 that conveniently comes with the new NDK.  This project contains all the code you need to set up the application and native parts to support ES 2.0.</p>
<blockquote><p>make APP=hello-gl2</p></blockquote>
<p>This will compile all of the native code and copy the binary to the libs/ directory of the Android project.</p>
<p>After this is finished we can build and install the application found in apps/hello-gl2/project/ onto our Android 2.0+ device and see ES 2.0 in action!</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/hax.png"><img class="size-full wp-image-367  aligncenter" title="hax" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/hax.png" alt="" width="240" height="400" /></a></p>
<p>Pretty awesome right?  I will save actual OpenGL ES 2.0 walkthroughs for later as I go through the<a href="http://opengles-book.com/"> ES 2.0 book</a>, but the source included in the hello-gl2 project should be enough to get you started.  Obviously this is all unsupported and unofficial and you should more than likely not release apps using these APIs onto the market until the Official SDK is updated.</p>
<p>You certainly wouldn&#8217;t want to release a Live Wallpaper using this code because it would probably get 1 star as most users are unimpressed that you got ES 2.0 working <img src='http://awalkingcity.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/wpaper.png"><img class="size-full wp-image-368  aligncenter" title="wpaper" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/wpaper.png" alt="" width="240" height="400" /></a><a href="http://awalkingcity.com/blog/wp-content/uploads/2010/02/red.png"><img class="aligncenter size-full wp-image-374" title="red" src="http://awalkingcity.com/blog/wp-content/uploads/2010/02/red.png" alt="" width="400" height="240" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2010/02/05/using-opengl-es-2-0-with-android-2-0-and-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QR Codes Made Easy In Android</title>
		<link>http://awalkingcity.com/blog/2008/08/25/qr-codes-made-easy-in-android/</link>
		<comments>http://awalkingcity.com/blog/2008/08/25/qr-codes-made-easy-in-android/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 04:59:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=39</guid>
		<description><![CDATA[QR Codes are a great way to share information with mobile phones. Originally used to track car parts, QR codes are now used to quickly and easily spread information to mobile users. For example a company can put a QR code in a magazine that contains the URL to their website. Instead of the user [...]]]></description>
			<content:encoded><![CDATA[<p>QR Codes are a great way to share information with mobile phones.  Originally used to track car parts, QR codes are now used to quickly and easily spread information to mobile users.  For example a company can put a QR code in a magazine that contains the URL to their website.  Instead of the user having to type in a long URL on their phone they can simply take a picture of the QR Code with their camera phone and have their decoding software open the link for them.  For more uses of QR Codes check out this <a href="http://mobile.kaywa.com/">blog</a>.</p>
<p>I am going to go through a quick example of encoding and decoding QR codes in Android.</p>
<p><strong>Encoding</strong></p>
<p>There are a number of services and libraries available for encoding QR Codes.  The actual encoding process is a bit more involved than I would like to go through for this entry and we generally would not want to do the actual encoding on the client.  Instead we will harness the power of the &#8220;cloud&#8221; to do the heavy lifting for us.  In this case we will use the <a href="http://code.google.com/apis/chart/#qrcodes">Google Charts API</a> which just recently expanded to include QR codes.  The API allows for a number of options such as size, error correction type, encoding type, and margins (the general rule for QR Codes is to have a 4 column/row white border around the barcode so that the decoding software can get a better &#8220;lock&#8221; on it)</p>
<p>The code below makes an http request to the Google Charts API with the URL encoded text we entered in the EditText view and populates our ImageView with the resulting image. </p>
<pre name="code" class="java">

encodeButton.setOnClickListener(new OnClickListener(){

public void onClick(View arg0) {
    img.setImageBitmap(QR.this.encodeString(edit.getText().toString()));
}

});

private Bitmap encodeString(String input) {
     URL aURL;
     try {
      aURL = new URL(&quot;http://chart.apis.google.com/chart?chs=300x300&amp;cht=qr&amp;choe=UTF- 8chl=&quot;+URLEncoder.encode(input, &quot;UTF-8&quot;));
      URLConnection conn = aURL.openConnection();
      conn.connect();
      InputStream is = conn.getInputStream();
      BufferedInputStream bis = new BufferedInputStream(is);
      Bitmap bm = BitmapFactory.decodeStream(bis);
      bis.close();
      is.close();
      return bm;
      } catch (MalformedURLException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }
     return null;
}
</pre>
<p><center><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/08/qrfest.png"><img class="aligncenter size-medium wp-image-40" title="qrfest" src="http://awalkingcity.com/blog/wp-content/uploads/2008/08/qrfest.png" alt="" width="320" height="480" /></a></center></p>
<p><strong>Decoding</strong></p>
<p>The <a href="http://code.google.com/p/zxing/">ZXing</a> library is an open source Java library for decoding numerous 1D and 2D barcodes.  We will be using the core library but there is also an Android specific application that provides hooks into the camera.  Since the emulator does not support capturing images just yet we will settle for using the image we just encoded.  We will need one class specific to the Android ZXing library, RGBMonochromeBitmapSource which lets us convert Android bitmaps to the format that ZXing uses.</p>
<p>The code below takes the bitmap image from the ImageView and pushes it through the decoder populating a TextView.</p>
<pre name="code" class="java">

decodeButton.setOnClickListener(new OnClickListener(){

public void onClick(View arg0) {

     try {
      tv.setText(((QR.this.decode(img.getDrawingCache()))));
     } catch (ReaderException e) {
      e.printStackTrace();
     }
}
});

private String decode(Bitmap bm) throws ReaderException {
     QRCodeReader reader = new QRCodeReader();
     Result r = reader.decode( new RGBMonochromeBitmapSource(bm));
     return r.getText();
}
</pre>
<p>We can use our friend Linkify to automatically make any text of the correct format (http://, mailto:, and even map locations) into a link that launches the appropriate application.</p>
<pre name="code" class="java">

textView.setAutoLinkMask(Linkify.ALL);
</pre>
<p><center><br />
<a href="http://awalkingcity.com/blog/wp-content/uploads/2008/08/device.png"><img class="aligncenter size-medium wp-image-43" title="device" src="http://awalkingcity.com/blog/wp-content/uploads/2008/08/device.png" alt="" width="320" height="480" /></a><br />
</center></p>
<p>I have even been experimenting with integrating the decoder with the built in WebView class which lets us decode images directly from the web browser.  As you can see in this example I have clicked on a QR Code and a dialog pops up with the decoded information.</p>
<p><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/08/qrbrowse1.png"><img class="aligncenter size-medium wp-image-41" title="qrbrowse1" src="http://awalkingcity.com/blog/wp-content/uploads/2008/08/qrbrowse1.png" alt="" width="320" height="480" /></a><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/08/qrbrowse2.png"><img class="aligncenter size-medium wp-image-42" title="qrbrowse2" src="http://awalkingcity.com/blog/wp-content/uploads/2008/08/qrbrowse2.png" alt="" width="320" height="480" /></a></p>
<p>The code to do this is a little hackish but involves using the WebView.requestImageRef(msg) mechanism and calling decode from the handler that receives that message.</p>
<p>I know of a number of decoders being developed for android but hopefully there will be a standard one that can be called using Intents so that developers can just fire off an intent in their application and get text back, not having to worry about dealing with the camera or the decoder libraries.  </p>
]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2008/08/25/qr-codes-made-easy-in-android/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Build Your Own Micro Location Sharing Service With Google&#8217;s AppEngine&#8230; and use it with android</title>
		<link>http://awalkingcity.com/blog/2008/04/09/build-your-own-micro-location-sharing-service-with-googles-appengine-and-use-it-with-android/</link>
		<comments>http://awalkingcity.com/blog/2008/04/09/build-your-own-micro-location-sharing-service-with-googles-appengine-and-use-it-with-android/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 01:21:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=23</guid>
		<description><![CDATA[In case you hadn&#8217;t heard, Google has released a preview of AppEngine, it&#8217;s cloud/platform service. It provides a full application development and deployment stack that has access to google services like email, login, and datastore. It also provides a python-based application development environment called webapp as well as supporting other python web frameworks, like django. [...]]]></description>
			<content:encoded><![CDATA[<p>In case you hadn&#8217;t heard, Google has released a preview of <a href="http://googleappengine.blogspot.com/2008/04/introducing-google-app-engine-our-new.html">AppEngine</a>, it&#8217;s cloud/platform service.  It provides a full application development and deployment stack that has access to google services like email, login, and datastore.   It also provides a python-based application development environment called <a href="http://code.google.com/appengine/docs/webapp/">webapp</a> as well as supporting other python web frameworks, like <a href="http://www.djangoproject.com/">django</a>.</p>
<p>Since location-based services for mobile phones are all the rage, I thought I would walk through how to create a simple location sharing web service on AppEngine and interact with it in Android.  I will show you how to create a simple REST-ish API that consumes HTTP requests and outputs simple XML data.  It probably won&#8217;t be exciting for people interested in shiny web applications, but using this approach provides a flexible protocol for interacting with remote service from a mobile phone, allowing the data to be consumed and displayed in a native phone application.  </p>
<p>After that, I will show you how to use Android&#8217;s LBS and networking APIs to interact with the service.</p>
<p><strong>Setup</strong><br />
Create a new AppEngine project and create a file called location.py.  First, we need to configure the app.yml with the url mapping for our service.  For this example I will simply use &#8220;/endpoint&#8221; as my mapping to the location.py handler.</p>
<pre name="code" class="python">

application: location
version: 1
runtime: python
api_version: 1

handlers:
- url: /endpoint
  script: location.py
</pre>
<p>There are many more ways to define your url mapping to provide RESTful urls for your app, <a href="http://code.google.com/appengine/docs/configuringanapp.html#Script_Handlers">see here for more info</a>.</p>
<p><strong>location.py</strong><br />
The source for the service can be found <a href='http://awalkingcity.com/blog/wp-content/uploads/2008/04/location.py'>here</a>.  I am going to step through the file from the top down.</p>
<p><strong>Model </strong><br />
We want to create a location domain model that can be used with the datastore api.  To do this we define a Location class that inherits from db.Model.  We will create fields for latitude, longitude, and date.</p>
<pre name="code" class="python">

class Location(db.Model):
  lat = db.IntegerProperty()
  lon = db.IntegerProperty()
  date = db.DateTimeProperty(auto_now_add=True)
</pre>
<p>lat and lon are stored as Integers because it makes things a little easier to use with some of the Android Map and Location APIs.</p>
<p>Since we want to be able to output our model as XML we make a helper method that makes a one line XML element with lat and lon as attributes:</p>
<pre name="code" class="python">

def printloc(self,location):
      return '&lt;location lat=\'%(lat)s\' lon=\'%(lon)s\'&gt;&lt;/location&gt;\n' % {'lat':location.lat, 'lon':location.lon} 
</pre>
<p>Models in AppEngine/webapp have a to_xml() method that allows them to be exported to XML automatically, the format is much more verbose than I would like to deal with in this tutorial, but they do provide an interesting look as to how the data is stored and read in the datastore/BigTable.  </p>
<p><strong>Methods</strong><br />
The next two methods get called when a request is made.  They are mapped to the GET and POST http methods, this makes it easy to design RESTful interfaces for our web service.  In our example we want a POST to create a new location, while GET will fetch a list of the 10 most recent locations.</p>
<p><strong>Post</strong></p>
<pre name="code" class="python">

  def post(self):
      location = Location()
      location.lat = int(self.request.get('lat'))
      location.lon = int(self.request.get('lon'))
      location.put()
      self.response.out.write(self.printloc(location))
</pre>
<p>This creates a new location object and stores the two parameter values in it and saves the location to the data store.  We then write the location out to the response.  </p>
<p>The output of this method will look something like this:</p>
<pre name="code" class="xml">

&lt;location lat=&quot;37422375&quot; lon=&quot;-122096532&quot;/&gt;
</pre>
<p><strong>Get</strong></p>
<pre name="code" class="python">

def get(self):
    locations = db.GqlQuery(&quot;SELECT * FROM Location ORDER BY date DESC LIMIT 10&quot;)
    self.response.headers['Content-Type'] = 'text/xml'
    self.response.out.write('&lt;list&gt;')
    for l in locations:
        self.response.out.write(self.printloc(l))
    self.response.out.write('&lt;/list&gt;')
</pre>
<p>This code fetches the latest 10 locations using a <a href="http://code.google.com/appengine/docs/datastore/queryclass.html">GQL</a> query and wraps them in a
<list> element.  </p>
<p>The output of this call will look something like this:</p>
<pre name="code" class="xml">

&lt;list&gt;
&lt;location lat=&quot;37422375&quot; lon=&quot;-122096532&quot;/&gt;
&lt;location lat=&quot;37429756&quot; lon=&quot;-122100756&quot;/&gt;
&lt;location lat=&quot;37428218&quot; lon=&quot;-122101459&quot;/&gt;
&lt;location lat=&quot;37422383&quot; lon=&quot;-122096532&quot;/&gt;
&lt;location lat=&quot;37422378&quot; lon=&quot;-122096531&quot;/&gt;
&lt;location lat=&quot;37422384&quot; lon=&quot;-122096533&quot;/&gt;
&lt;location lat=&quot;37449370&quot; lon=&quot;-122119525&quot;/&gt;
&lt;location lat=&quot;37449355&quot; lon=&quot;-122119523&quot;/&gt;
&lt;location lat=&quot;37454563&quot; lon=&quot;-122130219&quot;/&gt;
&lt;location lat=&quot;37454443&quot; lon=&quot;-122130012&quot;/&gt;
&lt;/list&gt;
</pre>
<p><strong>main</strong></p>
<pre name="code" class="python">

def main():
  application = webapp.WSGIApplication(
                                       [('/endpoint', LocationService)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == &quot;__main__&quot;:
  main()
</pre>
<p>This code binds our handler to the /endpoint address, and runs the service.</p>
<p><strong>Android integration</strong><br />
I will now briefly demonstrate how to interact with the service from within Android.  If you are like me, and were a little late trying to sign up for the AppEngine preview program,  you are running your web service locally. You need to run the development server with the &#8220;-a ADDRES&#8221;  where ADDRESS is your internal network address.  Android has an internal network loopback that loops any requests made from the phone to &#8220;localhost&#8221; back to the phone so you won&#8217;t be able to access your service if it is running on localhost.  </p>
<p>Our first step is to build a new MapActivity that contains a MapView and two menu actions &#8220;Update Location&#8221; and &#8220;Fetch Locations&#8221;.  The source for this activity can be found <a href='http://awalkingcity.com/blog/wp-content/uploads/2008/04/minilocationmap.java'>here</a>.</p>
<p>Update Location:<br />
The definition of our Post Current Location menu item which is defined inside of public boolean onCreateOptionsMenu(Menu menu):</p>
<pre name="code" class="java">

menu.add(0, 1, &quot;Post Current Location&quot;, new Runnable(){

			public void run() {

				// get current location and use it as params to our API call
				LocationManager locMan = (LocationManager) MiniLocationMap.this
						.getSystemService(Context.LOCATION_SERVICE);
				Location loc = locMan.getCurrentLocation(&quot;gps&quot;);

				 Map headers = new HashMap();

		        String text= &quot;lat=&quot; +(int)(loc.getLatitude()*1E6) + &quot;&amp;lon=&quot; + (int)(loc.getLongitude()*1E6;
		        byte[] bytes = text.getBytes();
		        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
				mRequestQueue.queueRequest(
		                &quot;http://10.0.0.199:8080/endpoint&quot;,
		                &quot;POST&quot;, headers, new LocationEventHandler(mHandler), bais, bytes.length, false);
			}

		});
</pre>
<p>This gets your current location in the same way that we did in our <a href="http://awalkingcity.com/blog/?p=13">fire eagle example</a>.  It then constructs a POST request with the latitude and longitude as parameters for our web service.  You need to convert the latitude and longitude to integers, there is probably a simpler way to do it than above.  This example uses the RequestQueue class which provides an interface for making http requests.  For more information on performing these requests you should definitely check out this <a href="http://davanum.wordpress.com/">blog</a>, which is full of great android examples. </p>
<p>The LocationEventHandler class handles the data returned from the request.  In my example the EventHandler uses the  XML pull parser to parse the XML data into a DemoLocation object which is then passed back to the Map Activity using it&#8217;s handler.  In the Handler the location is extracted from the Message object and used to center the map on the location just posted:</p>
<pre name="code" class="java">

public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);

			if(msg.what == 123){
				DemoLocation currentLocation = (DemoLocation) msg.getData().get(&quot;location&quot;);
				mMapController.centerMapTo(new Point(currentLocation.lat, currentLocation.lon), true);

			}
				}
		}
</pre>
<p>Retrieving Locations</p>
<pre name="code" class="java">

menu.add(0, 0, &quot;Retrieve Locations&quot;, new Runnable(){

			public void run() {
				 Map headers = new HashMap();
				mRequestQueue.queueRequest(
		                &quot;http://10.0.0.199:8080/endpoint&quot;,
		                &quot;GET&quot;, headers, new LocationListHandler(mHandler), null, 0, false);
			}

		});
</pre>
<p>This creates a GET http request and uses LocationListHandler to create an ArrayList of locations that can be used by our map.  To keep the tutorial short I won&#8217;t actually do anything with the list of locations, but they could be used with an overlay to draw points on the map of all the places you have recently been.<br />
<center><br />
<a href='http://awalkingcity.com/blog/wp-content/uploads/2008/04/lbs.png'><img src="http://awalkingcity.com/blog/wp-content/uploads/2008/04/lbs.png" alt="" title="lbs" width="320" height="480" class="alignnone size-medium wp-image-24" /></a></center></p>
<p>This fairly primitive implementation should be enough to get you started creating web services in AppEngine and using them in android.  Security is obviously an issue I ignored.  The built-in google user account api is built around user authentication using web forms and http redirects, similar to <a href="http://awalkingcity.com/blog/?p=18">OpenID</a>.  This makes it a little difficult to create APIs using just google accounts.  Implementing OAuth and having the web-based authorizorization part of the process use the google user api, then having a seperate table storing a reference to the user&#8217;s account, applications, and access tokens would be one approach to solving this problem.    </p>
<p>Overall, AppEngine was easy to use and provides a nice set of functionality to build on top of.  Having your web stack and client stack all under the google umbrella is kind of interesting.  The barrier of entry to developing and deploying a web app is now so low that I can see people building their own personal web services for things like their desktop and mobile phones.  You now control your personal information and can use open standards for sharing that information.  </p>
]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2008/04/09/build-your-own-micro-location-sharing-service-with-googles-appengine-and-use-it-with-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android and Fire Eagle; OAuth and Java</title>
		<link>http://awalkingcity.com/blog/2008/03/13/android-and-fire-eagle-oauth-and-java/</link>
		<comments>http://awalkingcity.com/blog/2008/03/13/android-and-fire-eagle-oauth-and-java/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 07:02:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[identity]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=13</guid>
		<description><![CDATA[Update 2 See this post or just skip straight to this excellent library for all of your OAuth and Java needs *Update* The code in this entry no longer works with the Android SDK because of the upgrade to HttpClient 4. The OAuth Java library has been updated to work with HttpClient 4 but I [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 2</strong> See this <a href="http://awalkingcity.com/blog/2009/06/27/java-oauth-signpost/">post</a> or just skip straight to this excellent <a href="http://code.google.com/p/oauth-signpost/">library</a> for all of your OAuth and Java needs</p>
<p><strong>*Update*</strong> The code in this entry no longer works with the Android SDK because of the upgrade to HttpClient 4.  The <a href="http://oauth.googlecode.com/svn/code/java/core/">OAuth Java library</a> has been updated to work with HttpClient 4 but I have not looked at it recently <strong>*Update*</strong><br />
<a href="http://fireeagle.com">Fire eagle</a> is a Yahoo! location sharing service that provides an API that allows external clients and services to update and query user location information.  Besides the obvious interesting connection between a location sharing service and <a href="http://code.google.com/android/toolbox/apis/lbs.html">Android&#8217;s Location-Based-Services API</a>,  I became more interested in how fire eagle uses <a href="http://oauth.net/">OAuth</a> as it&#8217;s authorization scheme and how it can be used on a smart mobile device.  </p>
<p>      OAuth is an open authentication protocol that allows access to web service resources from other web services as well as desktop applications.  Other open authentication schemes, like OpenID, use http redirects and require users input credentials onto a web page in order to authorize clients.  This isn&#8217;t very useful for a desktop or mobile client that would like direct access to a web API.  OAuth still requires the user to enter their credentials into a website, but this is only done during the initial application authorization step,  after that step is complete the application can make authorized API calls directly without needing user intervention.  </p>
<p>      A web service that uses OAuth will let application developers to register for a consumer key which is paired with a consumer secret.  The consumer key is used to identify the client application and the consumer secret is used to sign requests made by the client application which is then verified by the host web service.  </p>
<p>Here is a general outline of the OAuth process from a client application&#8217;s perspective:<br />
1.  The client requests a request token from the service.  They include their consumer key and a few other OAuth specific parameters including a hash signature using the consumer secret.The service replies with a request token.<br />
2.   The client application then directs the user to the service&#8217;s authorization page, with the request token as a parameter, where the user can log into the service and authorize the application to access their information.<br />
3.  Once the user is finished authorizing, the client application needs to request an access token which will be used to make authorized calls to the service&#8217;s API.  The service replies to the request with an access token and access secret.  The application needs to save both of these securely.<br />
4.  The client application can now make API calls by including the user&#8217;s access token, and signing the oauth parameters with the access secret.</p>
<p><strong>Laserbeak</strong><br />
I am going to attempt to walk through a &#8220;simple&#8221; android application that performs the request and authorization steps of OAuth as well as makes an update call to fire eagle with the current location of the phone.  </p>
<p><strong>Setup</strong><br />
The first step will be getting your own application key and secret token from the fireeagle service. Fire eagle is currently invite-only but there are plenty of invites floating around.     </p>
<p>The second step is to setup a new android project and give it GPS and LOCATION permissions.  </p>
<p>      The third step will be getting the OAuth java libraries from the <a href="http://oauth.googlecode.com/svn/code/java/core/">OAuth Java repository</a>.  Since the libraries use the apache-commons and http libraries that are already included in android you can simply drop the net.oauth, net.oauth.client, and net.oauth.signature into your source directory.  Note:  The OAuth java libraries aren&#8217;t &#8220;finished&#8221; and not as well documented as the libraries for other languages but I have found them to be fairly straight forward and functional.</p>
<p><strong>The Application</strong><br />
We will create a simple application that consists of an activity with three buttons.  Each button&#8217;s onClick event will trigger a step in our authorization process.  Complete source code for this activity can be found <a href='http://awalkingcity.com/blog/wp-content/uploads/2008/03/laserbeak.java' title='laserbeak'>here</a></p>
<p>Initializing the OAuth provider, consumer, and accessor in the Activity&#8217;s OnCreate method:</p>
<pre name="code" class="java">

		serviceProvider = new OAuthServiceProvider(OAUTH_REQUEST,
				OAUTH_AUTHORIZE, OAUTH_ACCESS);

		consumer = new OAuthConsumer(&quot;http://www.noredirectfordesktop.com&quot;,
				CONSUMER_KEY, CONSUMER_SECRET, serviceProvider);

		accessor = new OAuthAccessor(consumer);

		httpClient = new OAuthHttpClient(new HttpClientPool() {

			public HttpClient getHttpClient(URL server) {
				return new HttpClient();
			}
		});
</pre>
<p>Here we initialize the classes that will be used to make OAuth requests to the Fire eagle service, we include the three URLs as well as the consumer key and consumer secret.  All of the OAuth specific parameters and operations will be performed by these classes.</p>
<p>The request token button:</p>
<pre name="code" class="java">

Button requestButton = (Button) this.findViewById(R.id.req_button);
		requestButton.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {

				try {
					httpClient.getRequestToken(accessor);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				// manually set the access token to the request token...not sure
				// why
				accessor.accessToken = accessor.requestToken;

				// start browser application so user can authorize your
				// application
				Intent authIntent = new Intent(Intent.VIEW_ACTION);
				authIntent.setData(Uri.parse(FIRE_EAGLE_AUTHORIZE_URL
						+ accessor.requestToken));
				Laserbeak.this.startActivity(authIntent);
			}

		});
</pre>
<p>Here we use the built in getRequestToken method to make a token request to the service.  If all goes well the token is stored in the requestToken field of the accessor, for the authorization step we need to manually set the accessToken field on the accessor to equal the requestToken.<br />
The next step is interesting in that we need to have the user manually authorize our application, android makes it easy to launch the browser to the authorization URL using a VIEW_ACTION intent.  This will launch a browser that the user can use and once they are finished they can simply close the browser and return to the application which is still running in the background.<br />
<a href='http://awalkingcity.com/blog/wp-content/uploads/2008/03/laserbeak.png'><img src="http://awalkingcity.com/blog/wp-content/uploads/2008/03/laserbeak.png" alt="" title="laserbeak" width="320" height="480" class="alignnone size-medium attachment wp-att-14" /></a><a href='http://awalkingcity.com/blog/wp-content/uploads/2008/03/laserbeak3.png'><img src="http://awalkingcity.com/blog/wp-content/uploads/2008/03/laserbeak3.png" alt="" title="laserbeak3" width="320" height="480" class="alignnone size-medium attachment wp-att-16" /></a></p>
<p>The authorize button:</p>
<pre name="code" class="java">

Button authButton = (Button) this.findViewById(R.id.auth_button);
		authButton.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {

				try {

					OAuthResponseMessage response = (OAuthResponseMessage) httpClient
							.invoke(accessor.newRequestMessage(&quot;GET&quot;,
									serviceProvider.accessTokenURL, null));

					// manually set these fields on the accessor from the
					// response
					accessor.accessToken = response.getParameter(&quot;oauth_token&quot;);
					accessor.tokenSecret = response
							.getParameter(&quot;oauth_token_secret&quot;);

					//at this point you should store the accessToken and tokenSecret
					//somewhere secure
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

		});
</pre>
<p>Our application is now authorized to make API calls, lets try calling update with the current Lat/Lon of our phone</p>
<pre name="code" class="java">

Button updateButton = (Button) this.findViewById(R.id.update_button);
		updateButton.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {

					// get current location and use it as params to our API call
					LocationManager locMan = (LocationManager) Laserbeak.this
							.getSystemService(Context.LOCATION_SERVICE);
					Location loc = locMan.getCurrentLocation(&quot;gps&quot;);

					HashMap params = new HashMap();
					params.put(&quot;lat&quot;, loc.getLatitude());
					params.put(&quot;lon&quot;, loc.getLongitude());
					try {

						OAuthResponseMessage response2 = (OAuthResponseMessage) httpClient
								.invoke(accessor.newRequestMessage(&quot;POST&quot;,
										FIRE_EAGLE_UPDATE_URL, params
												.entrySet()));
					} catch (Exception e) {
						e.printStackTrace();
					}

			}
		});
</pre>
<p>Here we get the LocationManager and get the user&#8217;s current latitude and longitude and put them in a parameter map to be used in the request.  </p>
<p>      Those are the basic steps for using OAuth and fire eagle.  There are a number of things I left out like saving and accessing the access token and access secret from a secure place, as well as saving the state of the accessor for when your application gets interrupted by an incoming call.  You could also create a service that updates your location periodically in the background instead of explicitly updating it in an activity.    </p>
<p>      Unfortunately due to security issues, desktop and mobile applications are only allowed to access the user and update API calls.  The more interesting calls that allow you to query all the users of your application and create a social location network are restricted to web applications.  </p>
<p>      Now that you know how to authorize an application in OAuth you can use the above steps to interact with any other OAuth capable API, like <a href="http://pownce.pbwiki.com/API%20Documentation2-0#Authentication">pownce</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2008/03/13/android-and-fire-eagle-oauth-and-java/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Android: Extending WikiNotes</title>
		<link>http://awalkingcity.com/blog/2008/03/05/android-extending-wikinotes/</link>
		<comments>http://awalkingcity.com/blog/2008/03/05/android-extending-wikinotes/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 10:36:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://awalkingcity.com/blog/?p=7</guid>
		<description><![CDATA[Yesterday, the android team released WikiNotes , a personal wiki(like voodoopad), to help developers new to the platform get the hang of the flow of a typical android application. It provides a nice example of using intents to trigger activities directly, and associating activities with intents for the viewing of URI referenced content from a [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, the android team <a href="http://android-developers.blogspot.com/2008/03/announcing-apps-for-android.html">released WikiNotes</a> , a personal wiki(like <a href="http://flyingmeat.com/voodoopad/">voodoopad</a>), to help developers new to the platform get the hang of the flow of a typical android application.  It provides a nice example of using intents to trigger activities directly, and associating activities with intents for the viewing of URI referenced content from a content provider.  It also shows how to implement a content provider that allows the resolution of a URI on a field that isn&#8217;t the data&#8217;s ID column as well as perform searches via URI.</p>
<p>WikiNotes already provides support for automatically creating links for things like websites, phone numbers, and CamelCase formatted WikiNotes.  Since android uses URIs to identify content on the phone, you can create links  to any kind of content inside of WikiNotes.</p>
<p>I will provide a quick example of using the Linkify class to create a clickable link in a WikiNote that points to a contact in your address book.(hopefully, I am not stepping on anyone&#8217;s toes)</p>
<p>Before we start, since we will be accessing contacts on our phone we need to add the permission android.permission.READ_CONTACTS to our AndroidManifest.xml</p>
<p>Contacts are identified by the URI: content://contacts/people/#.  I don&#8217;t think anyone would want to have to type out that whole thing on their handset keyboard so I will use the short hand &#8220;C:#&#8221; to identify a clickable contact in our WikiNote.  This doesn&#8217;t make it any easier to identify who the contact actually is, but the contact provider currently only allows you to reference them by id number, plus its just easier to use a number for now.</p>
<p>Linkify uses a pattern matcher to identify which part of the string of a TextView to make into a clickable link so our first step is to define a wiki contact regex Pattern.  If you open up WikiNotes you will see the declaration and definition for WIKI_WORD_MATCHER.  Just under that we will add code for our wiki contact pattern.</p>
<pre name="code" class="java">

private static final Pattern WIKI_WORD_MATCHER;
private static final Pattern WIKI_CONTACT_MATCHER;
static {

// Compile the regular expression pattern that will be used to
// match WikiWords in the body of the note
WIKI_WORD_MATCHER = Pattern.compile(&quot;\\b[A-Z]+[a-z0-9]+[A-Z][A-Za-z0-9]+\\b&quot;);
//match shorthand C:# for a wiki contact
WIKI_CONTACT_MATCHER =Pattern.compile(&quot;\\b[C]+[:]+[1-90-9]+\\b&quot;);
</pre>
<p>The next step is to Linkify the TextView so that when it is clicked it resolves to the full contact URI.  Inside of the ShowWikiNotes() we want to add the following below the second Linkify.addLinks()</p>
<pre name="code" class="java">

//add custom linkify match for contacts
Linkify.addLinks(noteView, WIKI_CONTACT_MATCHER,

android.provider.Contacts.People.CONTENT_URI.toString()+&quot;/&quot;, null, new TransformFilter(){

public String transformUrl(Matcher matcher, String url) {

String ret = url.substring(2); //parse out the number

return ret;
}

});
</pre>
<p>This uses the method:</p>
<blockquote><p>addLinks(TextView text, Pattern p, String scheme, MatchFilter matchFilter, TransformFilter transformFilter)</p></blockquote>
<p>Where the first two parameter are obvious. Scheme is the uri to prepend to the matched text. MatchFilter which lets you further filter the matched text, and TransformFilter which takes the matched text and lets you change it before it is added to the scheme.  In this case the string that is passed to the filter is &#8220;C:#&#8221; and we want to parse out the number part of the string.</p>
<p>Once you have done this you should be able to type C:1 into your WikiNote, confirm it and it will display a clickable link that will take you to the Contact viewing activity.</p>
<p><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/03/err2.png"></a><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/03/mcnutty.png"><img src="http://awalkingcity.com/blog/wp-content/uploads/2008/03/mcnutty.png" title="mcnutty" class="alignnone size-medium attachment wp-att-9" height="480" width="320" /> </a><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/03/erreal.png"><img class="alignnone size-medium attachment wp-att-11" title="erreal" src="http://awalkingcity.com/blog/wp-content/uploads/2008/03/erreal.png" height="480" width="320" /></a></p>
<p>Woops&#8230;  Well this is an interesting error in that it shows a little of how intent filters work.  When the link is clicked in the TextView an intent with the View action and Browesable category is launched with it&#8217;s data set to the contact URI.  The issue is that the ContactViewer activity does not have the the android.intent.category.BROWSABLE intent filter so when the intent is triggered the system can&#8217;t find an activity that matches it.  Now if it did have that filter it would have displayed the following (hopefully):</p>
<p style="text-align: center;"><a href="http://awalkingcity.com/blog/wp-content/uploads/2008/03/mcnutty2.png"><img src="http://awalkingcity.com/blog/wp-content/uploads/2008/03/mcnutty2.png" title="mcnutty2" class="alignnone size-medium attachment wp-att-10" height="480" width="320" /></a></p>
<p>As the number of content providers grows we can link to many different kinds of content in the wiki and have android automate the viewing of the content by calling the appropriate view activities.  You can have links to music, videos, and images, but interestingly with a little modification you could launch all kinds of applications and intent actions from wiki links.  You now have a wiki user interface  where your users can easily design their own <b>wiki-based navigation for their phone and it&#8217;s content. </b></p>
]]></content:encoded>
			<wfw:commentRss>http://awalkingcity.com/blog/2008/03/05/android-extending-wikinotes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

