<?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>Mike Plate &#187; android</title>
	<atom:link href="http://www.mikeplate.com/category/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikeplate.com</link>
	<description>Freelance web and mobile developer</description>
	<lastBuildDate>Thu, 24 Nov 2011 15:43:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Install Android development environment on Windows 7</title>
		<link>http://www.mikeplate.com/2010/11/01/install-android-development-environment-on-windows-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=install-android-development-environment-on-windows-7</link>
		<comments>http://www.mikeplate.com/2010/11/01/install-android-development-environment-on-windows-7/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 20:37:25 +0000</pubDate>
		<dc:creator>mikeplate</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.mikeplate.com/?p=367</guid>
		<description><![CDATA[About a year ago I wrote a blog post about how to get started with Android development on Windows. At lot of new versions has been released since then, even though the basic packages needed are the same. This is a recap of what to download and how to set it up in order to [...]]]></description>
			<content:encoded><![CDATA[<p>About a year ago I wrote a blog post about how to get started with Android development on Windows. At lot of new versions has been released since then, even though the basic packages needed are the same. This is a recap of what to download and how to set it up in order to develop Android applications on Windows 7 (64-bit).<span id="more-367"></span></p>
<p>My background is primarily in Microsoft.NET and Microsoft Visual Studio, so it did feel a little different when I first entered the world of Java and Android development. But once you get past those initial hurdles, it isn&#8217;t as different as you first might have thought.</p>
<p>These are the steps to get started with Android development on Windows. Should work on any Windows version, but I&#8217;m using Windows 7 64-bit.</p>
<ol>
<li>Download and install Java SDK.</li>
<li>Download and unzip Android SDK.</li>
<li>Run &#8220;SDK Manager&#8221; from Android SDK to download the platform versions.</li>
<li>Download and unzip Eclipse.</li>
<li>Install the Android plugin for Eclipse and point to the Android SDK.</li>
</ol>
<p>You can read the instructions here, or watch a screencast I made describing the same procedure:</p>
<p><a href="http://vimeo.com/16392228">http://vimeo.com/16392228</a></p>
<h3>Download and install Java SDK</h3>
<p>You&#8217;ll find the Java SDK here:</p>
<p><a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a></p>
<p>Click the &#8220;Download JDK&#8221; button and choose the Windows version you have from the Platform combobox. You don&#8217;t have to register to download. I ended up downloading a file called &#8220;jdk-6u22-windows-x64.exe&#8221;. Run it and accept all defaults to complete the installation.</p>
<h3>Download and unzip Android SDK</h3>
<p>The Android SDK doesn&#8217;t have an install executable, but rather a zip file and a utility called &#8220;SDK Manager.exe&#8221;. Begin by downloading the sdk from here:</p>
<p><a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a></p>
<p>Unzip the file to any location you want. I put it in &#8220;C:\Android\SDK&#8221;. Inside that folder, you&#8217;ll find the executable &#8220;SDK Manager.exe&#8221;. Run it. Every time you run that application, it will look for updates to anything you&#8217;ve downloaded previously with the same tool. The first time it will default to download all platform versions of Android except the Google specific ones. I&#8217;d recommend selecting Cancel at this initial update dialog, and then download what you need from &#8220;Available packages&#8221; instead.</p>
<p>The Android platform has been released in several versions since its initial offering of version 1.0. Every Android application will require a specific version, but will of course work on all subsequent versions too (at least in a perfect world). Today, I recommend that you target version 2.1 as the least common denominator. But note that there might still be users and phones of at least version 1.6 that might be of interest to you. Anyway, this means that I would download version 2.1 and the latest version 2.2. They don&#8217;t really take up that much disk space (maybe ~100MB per version?), so it won&#8217;t hurt you too much to download them all either.</p>
<p>Also, every Android platform version comes in a &#8220;Android plain vanilla&#8221; variant and a &#8220;Google APIs&#8221; variant. The only differences between those two are that &#8220;Google APIs&#8221; variant will include the ability to use Google Maps component and some other Google specific APIs that some Android devices might not support. I found this naming to be a little strange at first, but note that &#8220;Google APIs&#8221; includes everything in &#8220;Android plain vanilla&#8221; too.</p>
<p>The point is that if your application doesn&#8217;t need things such as Google Map component, you will be targeting more devices if you choose to develop for &#8220;Android plain vanilla&#8221;. As far as I know, all commonly sold Android phones support the Google APIs and it is only simpler media players and maybe cheap tablets that might not have chosen to support Google APIs (since I assume the manufacturer pays licensing fees to Google for that).</p>
<h3>Run &#8220;SDK Manager&#8221; from Android SDK to download the platform versions</h3>
<p>So, running &#8220;SDK Manager&#8221;, cancelling on the first update dialog box, you&#8217;ll move on to &#8220;Available packages&#8221;. I recommend checking the following items and then click &#8220;Install selected&#8221;: (revision numbers can of course have changed since I wrote this)</p>
<ul>
<li>SDK Platform Android 2.2, API 8, revision 2</li>
<li>SDK Platform Android 2.1, API 7, revision 2</li>
<li>Samples for SDK API 8, revision 1</li>
<li>Google APIs by Google Inc., Android API 8, revision 2</li>
<li>Google APIs by Google Inc., Android API 7, revision 1</li>
<li>Usb Driver package, revision 3</li>
<li>Market Licensing package, revision 1</li>
</ul>
<p>You&#8217;ll need to &#8220;Accept all&#8221; licenses and then the download should start. You might get a question if it is ok to restart ADB at the end of the installation procedure, which it is!</p>
<h3>Download and unzip Eclipse</h3>
<p>You don&#8217;t have to use Eclipse. You could stop here and use a command line utility from the Android SDK to create project skeletons and edit the files with any text file editor. But I think you&#8217;ll enjoy the full development environment of Eclipse, even though it seems to have gotten its share of complaints over the years.</p>
<p>Download Eclipse from here:</p>
<p><a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a></p>
<p>The first option of &#8220;Eclipse IDE for Java Developers&#8221; is what you want, and click the link to the right depending on what Windows version you&#8217;re on. I ended up downloading &#8220;eclipse-java-helios-SR1-win32-x86_64.zip&#8221;.</p>
<p>Eclipse doesn&#8217;t have an install at all. Just unzip the files into any folder you like and start the environment with &#8220;eclipse.exe&#8221;.</p>
<h3>Install the Android plugin for Eclipse and point to the Android SDK</h3>
<p>Inside Eclipse, you need to do a few things before you can create your first Android project. When you start Eclipse, you choose your &#8220;Workspace&#8221;. Just accept the default. This is the base folder where you will put all of your projects, and can of course be changed later on.</p>
<p>Now, do the following:</p>
<ol>
<li>Select Help menu</li>
<li>Install new software</li>
<li>Add</li>
<li>Type any Name, like &#8220;Android&#8221;</li>
<li>Paste this address in Location: https://dl-ssl.google.com/android/eclipse/</li>
<li>OK</li>
<li>After a few seconds, the list should contain &#8220;Developer Tools&#8221; and there you&#8217;ll find &#8220;Android DDMS&#8221; and &#8220;Android Development Tools&#8221;.</li>
<li>Select both and then Next</li>
<li>Continue with the download and install. You&#8217;ll be asked to restart Eclipse at the end. Do that.</li>
</ol>
<p>Back in Eclipse with the Android plugin now installed, you also need to:</p>
<ol>
<li>Select Window menu</li>
<li>Preferences</li>
<li>Android</li>
<li>Click Browse button next to &#8220;SDK Location&#8221;</li>
<li>Point to the folder where you unzipped the Android SDK previously. For me, that would be &#8220;C:\Android\SDK&#8221; (where the &#8220;SDK Manager.exe&#8221; is located)</li>
<li>OK</li>
<li>Apply</li>
<li>After a few seconds the list should fill with the Android platforms you chose to download with &#8220;SDK Manager&#8221; previously</li>
<li>OK</li>
</ol>
<p>That&#8217;s it!</p>
<h3>Create your first Android project</h3>
<p>Now you should be able to create your first Android project. Still in Eclipse:</p>
<ol>
<li>Select File menu</li>
<li>New</li>
<li>Project</li>
<li>Android, Android Project</li>
<li>Next</li>
<li>Project name: My first project</li>
<li>Build Target, Target Name: check any platform version you&#8217;d like to start with</li>
<li>Application name: MyFirstProject</li>
<li>Package name: com.myname.MyFirstProject</li>
<li>Create Activity: (checked) MainActivity</li>
<li>Min SDK Version: (can be left empty)</li>
<li>Next</li>
<li>Finish (no test project for your first attempt)</li>
</ol>
<p>Now, right-click the project name in the left pane and choose &#8220;Run as&#8221; and then &#8220;1 Android Application&#8221;. The emulator should start and after some time (it IS really slow to start), you&#8217;ll be running your first Android application. If the emulator starts, but not your application, just keep the emulator running and switch back to Eclipse and execute the &#8220;Run as&#8221; command again. Sometimes it fails on the first attempt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeplate.com/2010/11/01/install-android-development-environment-on-windows-7/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Show a context menu for long-clicks in an Android ListView</title>
		<link>http://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=show-a-context-menu-for-long-clicks-in-an-android-listview</link>
		<comments>http://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 11:26:28 +0000</pubDate>
		<dc:creator>mikeplate</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[contextmenu]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[listview]]></category>
		<category><![CDATA[ListViewDemo]]></category>

		<guid isPermaLink="false">http://www.mikeplate.com/?p=246</guid>
		<description><![CDATA[Coming from a Windows and .NET background, I had some trouble understanding how to interact with the ListView control and context menu creation in Android. Context menus are supposed to be shown on your mobile device when you touch/click the screen and hold on for a longer time. So here is how to determine which [...]]]></description>
			<content:encoded><![CDATA[<p>Coming from a Windows and .NET background, I had some trouble understanding how to interact with the ListView control and context menu creation in Android. Context menus are supposed to be shown on your mobile device when you touch/click the screen and hold on for a longer time. So here is how to determine which item is long-clicked and how to show a context menu for it.<span id="more-246"></span></p>
<p>Source code for this blog post is available as a complete Eclipse project at<a title="Link to source code on Github" href="http://github.com/mikeplate/ListViewDemo"> http://github.com/mikeplate/ListViewDemo</a> (zip download link in upper right corner).</p>
<h2>An Activity with an expanding ListView and a docked TextView</h2>
<p>If you have an activity that will only contain a single ListView control, you can derive your activity from the ListActivity instead of Activity. However, I think I might like to show some extra info below my ListView so I chose to have a separate ListView object. My activity layout looks like this:</p>
<pre class="brush:xml;gutter:false">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  &gt;
  &lt;ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="0px"
    android:layout_weight="1"
    /&gt;
  &lt;TextView
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:text="@string/footer"
    android:padding="4dip"
    android:background="#FF666666"
    /&gt;
&lt;/LinearLayout&gt;</pre>
<p>And I need the layout for items in the ListView (listitem.xml):</p>
<pre class="brush:xml;gutter:false">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;TextView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textSize="24dip"
  android:padding="8dip"
  /&gt;</pre>
<p>Note a nice trick that I&#8217;ve used to get the TextView to &#8220;dock&#8221; at the bottom with a definied height, and have the ListView automatically fill out the rest of the height. This kind of thinking is important since Android devices can have different resolutions. The trick is to set the layout_height to zero pixels and the layout_weight to one (default is zero). Not sure about the logic behind that, but it works!</p>
<p><a href="http://www2.mikeplate.com/wp-content/uploads/2010/01/ListViewDemo01.png"><img class="alignnone size-full wp-image-260" title="ListViewDemo01" src="http://www2.mikeplate.com/wp-content/uploads/2010/01/ListViewDemo01.png" alt="Screen capture of a selected=" height="480" /></a></p>
<p>In order to have something to put into my ListView, I created a few country names in a string array as a resource and I sort that array before adding it to the ListView with the ArrayAdapter object. (Check out source code link above for this content.)</p>
<pre class="brush:java">public class ListViewDemoActivity extends Activity {
  private String[] Countries;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Countries = getResources().getStringArray(R.array.countries);
    Arrays.sort(Countries);

    ListView list = (ListView)findViewById(R.id.list);
    ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.listitem, Countries);
    list.setAdapter(adapter);
    registerForContextMenu(list);
  }
}</pre>
<h2>Creating a ContextMenu in Android</h2>
<p>When the user long-clicks, the event onCreateContextMenu is fired for the control that the user is clicking. For me, that is the ListView control. But since I don&#8217;t want to write a custom ListView-derived class, I want to catch that event in my activity. There does not seem to be any bubbling going on. Events fired in a child control does not bubble up to the parent if they are unhandled.</p>
<p>But obviously, the api designers have thought of this since there is a special method for this situation. Call the registerForContextMenu in your activity for this! This will actually make sure your overridden methods for both onCreateContextMenu and onContextItemSelected is called for the ListView-events as we&#8217;ll see soon.</p>
<p>Next, we&#8217;ll provide the implementation of onCreateContextMenu. Here I want to ensure that the event comes from the ListView and if so, I want to determine on which item in the ListView the user long-clicked.</p>
<pre class="brush:java">@Override
public void onCreateContextMenu(ContextMenu menu, View v,
    ContextMenuInfo menuInfo) {
  if (v.getId()==R.id.list) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
    menu.setHeaderTitle(Countries[info.position]);
    String[] menuItems = getResources().getStringArray(R.array.menu);
    for (int i = 0; i&lt;menuItems.length; i++) {
      menu.add(Menu.NONE, i, i, menuItems[i]);
    }
  }
}</pre>
<p>As you can see, the argument of type ContextMenuInfo can actually change depending on what type of control is sending the event. For ListViews, the class you need to type cast into is AdapterView.AdapterContextMenuInfo. From there I used the position, which in my case corresponds to the index into the string-array. From the array I retrieve the string for that particular item and use as title for the menu. Then you can of course add all the menu commands you like. For the demo, I defined another string array as a resource with the commands I want to add.</p>
<p>When creating the menu items with the add-call, I specify that I don&#8217;t want any grouping of the items (Menu.NONE) and that the order and id of the item is the same (i). The last argument to add is the text to display for the item.</p>
<p><a href="http://www2.mikeplate.com/wp-content/uploads/2010/01/ListViewDemo02.png"><img class="alignnone size-full wp-image-262" title="ListViewDemo02" src="http://www2.mikeplate.com/wp-content/uploads/2010/01/ListViewDemo02.png" alt="Screen capture of the context menu with commands" width="320" height="480" /></a></p>
<h2>Responding to selected MenuItem</h2>
<p>If the user dismisses the context menu (for instance, by back button) you don&#8217;t need to do anything. But for catching the actual selection of one of the items, you need to override onContextItemSelected.</p>
<pre class="brush:java">@Override
public boolean onContextItemSelected(MenuItem item) {
  AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
  int menuItemIndex = item.getItemId();
  String[] menuItems = getResources().getStringArray(R.array.menu);
  String menuItemName = menuItems[menuItemIndex];
  String listItemName = Countries[info.position];

  TextView text = (TextView)findViewById(R.id.footer);
  text.setText(String.format("Selected %s for item %s", menuItemName, listItemName));
  return true;
}</pre>
<p>The MenuItem argument holds all information that you need. The ContextMenuInfo object that got sent to onCreateContextMenu is still there and still needs type casting. Or I guess you could have saved that info in the activity between the calls, but I didn&#8217;t.</p>
<p>The id of the menu item selected is the same as the index into the string array of menu item texts for me. Instead of just outputting the menu command name and the list item text in a TextView, you would most likely have a big switch statement on menuItemIndex.</p>
<p>This was my first blog post and code demo for the Android platform. I hope it won&#8217;t be the last! The goal is to build upon this demo and/or other demos in my investigations of the Android platform. Please let me know in the comments if you have even better methods or code patterns that solves problems like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Getting ready for Android development</title>
		<link>http://www.mikeplate.com/2009/10/27/getting-ready-for-android-development/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-ready-for-android-development</link>
		<comments>http://www.mikeplate.com/2009/10/27/getting-ready-for-android-development/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 21:44:23 +0000</pubDate>
		<dc:creator>mikeplate</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.mikeplate.com/?p=44</guid>
		<description><![CDATA[Here are the steps I took to get my Android development environment set up on my Windows 7 64-bit box. Download and install Java Development Kit SE: JDK 6 Update 16. File name I ended up downloading was jdk-6u16-windows-x64. Download and unpack Eclipse IDE for Java Developers. File name I ended up downloading was eclipse-SDK-3.5.1-win32-x86_64.zip. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are the steps I took to get my Android development environment set up on my Windows 7 64-bit box.<span id="more-44"></span></p>
<ul>
<li>Download and install <a href="http://java.sun.com/javase/downloads/index.jsp">Java Development Kit SE: JDK 6 Update 16</a>.<br />
File name I ended up downloading was jdk-6u16-windows-x64.</li>
<li>Download and unpack <a href="http://download.eclipse.org/eclipse/downloads/">Eclipse IDE for Java Developers</a>.<br />
File name I ended up downloading was eclipse-SDK-3.5.1-win32-x86_64.zip.</li>
<li>Download and unpack <a href="http://developer.android.com/sdk/index.html">Android SDK</a>.<br />
File name I ended up downloading was android-sdk_r3-windows.zip.</li>
<li>Changed android.bat inside Android SDK according to <a href="http://code.google.com/p/android/issues/detail?id=3917">this tip</a>.</li>
<li>Start a command prompt as administrator and run the following command from the tools folder of the Android SDK:<br />
android update sdk</li>
<li>Fixed error &#8220;Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml, reason: HTTPS SSL error. You might want to force download through HTTP in the settings.&#8221; by doing as it says and then clicking Update all button under Installed packages. Not sure why this was needed because the https link loaded fine in my browser.</li>
<li>Select &#8220;SDK Platform Android 1.5&#8243;, Accept and then Install Accepted. Actually I ended up downloading all platforms (not sure why, but I have room so what the heck). This means 1.1, 1.5, 1.6, 2.0, documentation</li>
<li>Start Eclipse and accept the default workspace location (or change &#8211; it is just the place to put your projects and files). Choose Help, Install new software. Input the following link and click Add button.
<p>https://dl-ssl.google.com/android/eclipse/</p>
<p>Type a name for the link/source and ok. Check &#8220;Developer Tools&#8221; once it appears in the list and click Next, Next, I Accept and Finish. I got a warning about unsigned content, but accepted with OK. Also, a Yes for restarting Eclipse.</li>
<li>Choose Window, Preferences inside Eclipse. Under Android, Browse for the location where you unpacked the Android SDK. I clicked Apply, but it seemed to take a while and maybe another click and/or another Browse attempt before the list filled up with my targets &#8220;Android 1.1&#8243;, &#8220;Android 1.5&#8243; etc. OK.</li>
<li>Choose Window, Android SDK and AVD Manager inside Eclipse. Click New under Virtual Devices. Type a name for your phone emulator and select your target platform, Android 1.5 for me. Type a size for your emulated SD card, I chose 200 MiB. I did not create any additional hardware abstractions (yet, will probably come back later). Then Create AVD and close the dialog box.</li>
<li>Choose File, New, Project inside Eclipse. Select Android Project and Next. Type a name for your project and select your target platform. I&#8217;m going for Android 1.5 which is on my HTC Hero at the time of this writing. Also input values for the following fields, for example:<br />
Application name: My App<br />
Package name: com.mycompany.myapp<br />
Create Activity: MainActivity<br />
And complete with a click on Finish. Now, you may think nothing has happed, but it has. Just click icon on right which saids &#8220;Workbench&#8221; when you hover on it. There you have your project and source files to work with!</li>
<li>Click Debug button in toolbar in order to test the application in the emulator. Select Android Application and off you go. Even on my Intel Core i7 processor it takes some time to get the app running inside the emulator, about 1 minute! Note however, that if you keep the emulator running, it only takes about 5 seconds to launch a new version of my application from within Eclipse.</li>
</ul>
<p>That&#8217;s it. Now off for some educational reading in how to write Android applications. I hope to get back on that matter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeplate.com/2009/10/27/getting-ready-for-android-development/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.mikeplate.com @ 2012-02-06 04:54:01 -->
