<?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>stealthcopter.com &#187; eclipse</title>
	<atom:link href="http://www.stealthcopter.com/blog/tag/eclipse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stealthcopter.com/blog</link>
	<description>Android, Linux, Python and stealthcopters</description>
	<lastBuildDate>Sat, 24 Jul 2010 00:01:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Android: Grouping onClickListeners together by implementation in an activity</title>
		<link>http://www.stealthcopter.com/blog/2010/04/android-grouping-onclicklisteners-together-by-implementation-in-an-activity/</link>
		<comments>http://www.stealthcopter.com/blog/2010/04/android-grouping-onclicklisteners-together-by-implementation-in-an-activity/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 00:06:16 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=857</guid>
		<description><![CDATA[Here is a quick tip for better organisation of your program by grouping all onClickListeners into a simple switch statement. The problem If you have lots of buttons or view that you are linking to OnClickListener events you can quickly end up with some cumbersome code. This can be changed very simply by implementing a [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick tip for better organisation of your program by grouping all onClickListeners into a simple switch statement.</p>
<p><strong>The problem</strong><br />
If you have lots of buttons or view that you are linking to OnClickListener events you can quickly end up with some cumbersome code. This can be changed very simply by implementing a method in your activity and switching between View ID&#8217;s. </p>
<p>Below is an example the typical method for creating an OnClickListener for a View.</p>
<pre name="code" class="java">

final ImageButton Ibutton = (ImageButton) findViewById(R.id.button_1);
Ibutton.setOnClickListener(new OnClickListener() {
	public void onClick(View v) {
		Toast.makeText(testActivity.this, "Button 1 pressed ", Toast.LENGTH_SHORT).show();
	}
});

final ImageButton Ibutton2 = (ImageButton) findViewById(R.id.button_2);
Ibutton2.setOnClickListener(new OnClickListener() {
	 public void onClick(View v) {
		Toast.makeText(testActivity.this, "Button 2 pressed", Toast.LENGTH_SHORT).show();
	}
});
</pre>
<p><strong>The Solution</strong><br />
We can get our activity to handle the OnClick events itself, we do this we implementing OnClickListener:</p>
<pre name="code" class="java">
public class testActivity extends Activity implements OnClickListener {
</pre>
<p>If your write this in eclipse you can hover over the error this produces and click Add unimplemented methods to automatically create a stub for the next part.</p>
<div id="attachment_858" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.stealthcopter.com/blog/2010/04/android-grouping-onclicklisteners-together-by-implementation-in-an-activity/onclicklistner/" rel="attachment wp-att-858"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/04/onclicklistner-600x115.png" alt="eclipse auto suggesting to implement the onclicklistener method" title="eclipse auto suggesting to implement the onclicklistener method" width="600" height="115" class="size-medium wp-image-858" /></a><p class="wp-caption-text">eclipse auto suggesting to implement the onclicklistener method</p></div>
<p>We now create our buttons similar to before, but for the setOnClickListener we pass this as an argument, so that our implemented method is called.</p>
<pre name="code" class="java">

ImageButton Ibutton = (ImageButton) findViewById(R.id.button_1);
Ibutton.setOnClickListener(this);      

ImageButton Ibutton2 = (ImageButton) findViewById(R.id.button_2);
Ibutton2.setOnClickListener(this);      
</pre>
<p>We now create the implemented method for our activity (onClick) and we use a switch statement to find which View fired the onclick event and preform an action accordingly.</p>
<pre name="code" class="java">

@Override
public void onClick(View v) {
	switch(v.getId()){
	case R.id.button_1:
		// action to preform on button 1
		Toast.makeText(testActivity.this, "Button 1 pressed ", Toast.LENGTH_SHORT).show();
		break;
	case R.id.button_2:
		// action to preform on button 1
		Toast.makeText(testActivity.this, "Button 2 pressed ", Toast.LENGTH_SHORT).show();
		break;
	}
}		
</pre>
<p>And it&#8217;s as simple as that!<br />
Feel free to post comments or questions</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/04/android-grouping-onclicklisteners-together-by-implementation-in-an-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android: Context menu example (on long press, gridview)</title>
		<link>http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/</link>
		<comments>http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 10:41:44 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=582</guid>
		<description><![CDATA[I received several requests regarding how I created a context menu (the menu activated on a long press) using a gridview and how to call functions such as saving a sound file from this. So I have created a quick example to explain this: Tutorial To implement a context menu (long press menu) you first [...]]]></description>
			<content:encoded><![CDATA[<p>I received several requests regarding how I created a context menu (the menu activated on a long press) using a gridview and how to call functions such as saving a sound file from this. So I have created a quick example to explain this:</p>
<p><strong>Tutorial</strong></p>
<p>To implement a context menu (long press menu) you first need to include the following imports:</p>
<pre name="code" class="java">
import android.view.ContextMenu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
</pre>
<p>We start a very simple project, with the layout having a single button named button_example:</p>
<div id="attachment_854" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/cm1/" rel="attachment wp-att-854"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/04/cm1.png" alt="Android context menu example" title="Android context menu example" width="320" height="484" class="size-full wp-image-854" /></a><p class="wp-caption-text">Android context menu example</p></div>
<p>We then use registerForContextMenu in the onCreate of the activity to tell android that we want this view to create a menu when it is long pressed. This is not limited to buttons, this will work for other views too. You must register each view that you want to have associated with the context menu.</p>
<pre name="code" class="java">
Button btn = (Button) findViewById(R.id.button_example);
registerForContextMenu(btn);
</pre>
<p>You then need to override the onCreateContextMenu method to create the menu:</p>
<pre name="code" class="java">
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
		menu.setHeaderTitle("Context Menu");
		menu.add(0, v.getId(), 0, "Action 1");
		menu.add(0, v.getId(), 0, "Action 2");
	}
</pre>
<div id="attachment_852" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/cm2/" rel="attachment wp-att-852"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/04/cm2.png" alt="android context menu example" title="android context menu example" width="320" height="484" class="size-full wp-image-852" /></a><p class="wp-caption-text">android context menu example</p></div>
<p>And override onContextItemSelected to preform the action when an option is selected from this menu:</p>
<pre name="code" class="java">
    @Override
	public boolean onContextItemSelected(MenuItem item) {
       	if(item.getTitle()=="Action 1"){function1(item.getItemId());}
    	else if(item.getTitle()=="Action 2"){function2(item.getItemId());}
    	else {return false;}
	return true;
	}
</pre>
<p>function1 and function2 are just place-holders at the moment that toast a message when they are used. In the above example we are choosing between Action 1 and Action 2 which define which function will be run when an item is selected. We have passed the ID of the view through the context menu and into this function so we can tell what the user was pressing when the context menu was created.</p>
<div id="attachment_853" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/cm3/" rel="attachment wp-att-853"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/04/cm3.png" alt="calling a function after a context menu item was pressed" title="calling a function after a context menu item was pressed" width="320" height="484" class="size-full wp-image-853" /></a><p class="wp-caption-text">calling a function after a context menu item was pressed</p></div>
<p><strong>Examples</strong></p>
<p>If you create a gridview and give each item a unique ID then you can use this method to preform actions based on each item. This is the method I use for my soundboard applications to save the sounds to the SD card as a notification or ringtone:</p>
<div id="attachment_855" class="wp-caption aligncenter" style="width: 330px"><a href="http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/cssb_cm/" rel="attachment wp-att-855"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/04/cssb_cm.png" alt="counterstrike 1.6 soundboard context menu" title="counterstrike 1.6 soundboard context menu" width="320" height="482" class="size-full wp-image-855" /></a><p class="wp-caption-text">counterstrike 1.6 soundboard context menu</p></div>
<div id="attachment_856" class="wp-caption aligncenter" style="width: 331px"><a href="http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/utsb_cm/" rel="attachment wp-att-856"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/04/utsb_cm.png" alt="Unreal Tournament soundboard context menu" title="Unreal Tournament soundboard context menu" width="321" height="481" class="size-full wp-image-856" /></a><p class="wp-caption-text">Unreal Tournament soundboard context menu</p></div>
<p><strong>Source</strong></p>
<p>Below is the source code:</p>
<pre name="code" class="java">
package com.contextmenu.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Button;
import android.widget.Toast;

public class test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btn = (Button) findViewById(R.id.button_example);
        registerForContextMenu(btn);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
		menu.setHeaderTitle("Context Menu");
		menu.add(0, v.getId(), 0, "Action 1");
		menu.add(0, v.getId(), 0, "Action 2");
	}

    @Override
	public boolean onContextItemSelected(MenuItem item) {
       	if(item.getTitle()=="Action 1"){function1(item.getItemId());}
    	else if(item.getTitle()=="Action 2"){function2(item.getItemId());}
    	else {return false;}
	return true;
	}

    public void function1(int id){
    	Toast.makeText(this, "function 1 called", Toast.LENGTH_SHORT).show();
    }
    public void function2(int id){
    	Toast.makeText(this, "function 2 called", Toast.LENGTH_SHORT).show();
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/04/android-context-menu-example-on-long-press-gridview/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Supporting multiple phones and screensizes in your android applications</title>
		<link>http://www.stealthcopter.com/blog/2010/02/supporting-multiple-phones-and-screensizes-in-your-android-applications/</link>
		<comments>http://www.stealthcopter.com/blog/2010/02/supporting-multiple-phones-and-screensizes-in-your-android-applications/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 22:38:33 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=655</guid>
		<description><![CDATA[When releasing an android application it is often desirable to release your application to the largest amount of users as possible. By developing an application with android 1.5 as the target, later versions are automatically supported (1.6, 2.0, and 2.1). However different screen-sizes were introduced with android 1.6 so by default an application will not [...]]]></description>
			<content:encoded><![CDATA[<p>When releasing an android application it is often desirable to release your application to the largest amount of users as possible. By developing an application with android 1.5 as the target, later versions are automatically supported (1.6, 2.0, and 2.1). However different screen-sizes were introduced with android 1.6 so by default an application will not support smaller screens (larger screens are automatically supported). </p>
<p><strong>Android Versions Marketshare</strong><br />
The image below shows the current market share for the different version of android:</p>
<div id="attachment_660" class="wp-caption aligncenter" style="width: 410px"><a href="http://www.stealthcopter.com/blog/2010/02/supporting-multiple-phones-and-screensizes-in-your-android-applications/android-1-6-users-access-the-android-market-most-2/" rel="attachment wp-att-660"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/02/Android-1-6-Users-Access-the-Android-Market-Most-2.jpg" alt="Android version percentages" title="Android_version_percentages" width="400" height="400" class="size-full wp-image-660" /></a><p class="wp-caption-text">Android version marketshare</p></div>
<p><code></p>
<table>
<tr>
<td>Android Platform</td>
<td>Percentage of Devices</td>
</tr>
<tr>
<td>1.1</td>
<td>0.3%</td>
</tr>
<tr>
<td>1.5</td>
<td>27.7%</td>
</tr>
<tr>
<td>1.6</td>
<td>54.2%</td>
</tr>
<tr>
<td>2.0</td>
<td>2.9%</td>
</tr>
<tr>
<td>2.0.1</td>
<td>14.8%</td>
</tr>
</table>
<p></code></p>
<p>Devices with small screens include the following phones T-Mobile G1, Samsung I7500, and the HTC Tattoo. Unfortunately I cannot find any statistics regarding the percentage of small screen android users (if you can please let me know). However as the fix is very simple it seems stupid not to.</p>
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.<br />
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.
<p><strong>Adding Support</strong><br />
To add support for different screen sizes we need to add a supports-screens tag in our android_manifest.xml. This should look like the following:</p>
<pre name="code" class="xml">
  &lt;supports-screens
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:anyDensity="false" /&gt;
</pre>
<p>This tells android that the application should work on large, normal and small screens. Note that only setting small to false will prevent it from been visible in the market to small screened phones, for normal and large it will simply change the method of which android interprets the display of this application. anyDensity  fix me</p>
<p>However in order to use the supports-screens tag the target of your application must be android 1.6 (or Sdk version 4). We can allow our program which is now targetted for android 1.6 still be avaliable for android 1.5 (Sdk version 3) by adding android:minSdkVersion=&#8221;3&#8243; to our uses-sdk tag.</p>
<pre name="code" class="xml">
&lt;uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/&gt;
</pre>
<p>Now your application can be built for 1.6 supporting smaller screen sizes and still work on 1.5. </p>
<p><strong>Demonstration</strong><br />
Below are screenshots from two AVD&#8217;s, one with a normal screen size, and one with a small screen size:</p>
<div id="attachment_691" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.stealthcopter.com/blog/2010/02/supporting-multiple-phones-and-screensizes-in-your-android-applications/android_small_screen/" rel="attachment wp-att-691"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/02/android_small_screen-600x388.png" alt="android small screen wordcube" title="android_small_screen" width="600" height="388" class="size-medium wp-image-691" /></a><p class="wp-caption-text">small screen android AVD running wordcube</p></div>
<div id="attachment_692" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.stealthcopter.com/blog/2010/02/supporting-multiple-phones-and-screensizes-in-your-android-applications/android_small_medium/" rel="attachment wp-att-692"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/02/android_small_medium-600x502.png" alt="android medium screen wordcube" title="android_medium_screen" width="600" height="502" class="size-medium wp-image-692" /></a><p class="wp-caption-text">Medium screen android AVD running wordcube</p></div>
<p><strong>Note: Eclipse bug</strong><br />
Unfortunately eclipse currently does not acknowledge minSdkVersion and will not give you the option to test your application in any android virtual devices (AVD&#8217;s), while this is not fixed you can manually install the package into your AVD. For this you need to know the name of your emulator instance, to do this first run the AVD and then use the followin command to find out the name.</p>
<pre name="code" class="bash">
$adb devices
List of devices attached
emulator-5554   device
</pre>
<p>So we can see that the emulator instance I need is called emulator-5554. We can now use adb to install a package into this emulator. The below example shows installing wordcubefree from the bin folder in my project to my AVD using adb.</p>
<pre name="code" class="bash">
adb -s emulator-5554 install ~/android/workspace/WordCubeFree/bin/WordCubeFree.apk
1019 KB/s (39683 bytes in 0.038s)
Can't dispatch DDM chunk 46454154: no handler defined
Can't dispatch DDM chunk 4d505251: no handler defined
        pkg: /data/local/tmp/WordCubeFree.apk
Success
</pre>
<p>Note that this will fail if the application is already installed and you will need to uninstall the application before using this command (if anyone knows a switch to force install or alternative method please let me know)</p>
<p><strong>Going Further</strong><br />
It is possible to delve into this is more detail by providing layouts for small, medium and large screen sizes. This can be explored in more detail in the <a href="http://developer.android.com/guide/practices/screens_support.html">google dev support guide</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/02/supporting-multiple-phones-and-screensizes-in-your-android-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android: Using SVN with your app&#8217;s project (and eclipse)</title>
		<link>http://www.stealthcopter.com/blog/2010/02/android-using-svn-with-your-apps-project-and-eclipse/</link>
		<comments>http://www.stealthcopter.com/blog/2010/02/android-using-svn-with-your-apps-project-and-eclipse/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 17:04:15 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=513</guid>
		<description><![CDATA[When creating any non-trivial program using a versioning system is essential, especially when working in part of a group. This guide aims to be a quick tutorial to the SVN (subversion) tool for versioning and how to use it with an android project. Assumptions You will need SVN installed on your computer. This can be [...]]]></description>
			<content:encoded><![CDATA[<p>When creating any non-trivial program using a versioning system is essential, especially when working in part of a group. This guide aims to be a quick tutorial to the SVN (subversion) tool for versioning and how to use it with an android project.</p>
<p><strong>Assumptions</strong></p>
<ul>
<li>
You will need SVN installed on your computer. This can be done using your package manager or by the following command in ubuntu / debian based systems:</p>
<pre name="code" class="bash">sudo apt-get install subversion</pre>
</li>
<li>
You already have an SVN repository configured. If not please view a tutorial like <a href="http://www.systhread.net/texts/200607subver.php">this</a> or if you have a nice webhost like me (thanks <a href="http://www.dreamhost.com/r.cgi?543037">dreamhost</a> <img src='http://www.stealthcopter.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ) there may be a simple tool to do this automatically for you in your panel.
</li>
</ul>
<p><strong></strong></p>
<p><strong>Note</strong><br />
Don&#8217;t include the files inside /bin or /gen as they are just build from the source code and will simply fill up a lot space in your SVN. But do include the folders themselves as the project will fail to build without them.</p>
<p><strong>Command line (recommended)</strong><br />
For SVN, I am a great fan of the command line. From the few SVN GUI applications that I have used in the past I can recommend Turtoise SVN for windows and kdesvn for linux (kde) but I still prefer the command line.</p>
<p>The following code will checkout the project from your server. This will create a new folder called &#8220;projectname&#8221; on your computer and download the project from your server (at this point it is most likely an empty folder).</p>
<pre name="code" class="bash">
# Checkout the SVN directory
svn co svn.yourdomain.com/projectname projectname
</pre>
<p>You can then copy or create your android project in this directory. In our project folder there are two folders which contain generated files (as opposed to source files) there is no point uploading these to the svn as you will simply take up space and bandwidth. Before you decided to upload your changes to the server you should empty the bin and gen folders:</p>
<pre name="code" class="bash">
# Empty bin and gen folders
rm -rf ./projectname/bin/*
rm -rf ./projectname/gen/*
</pre>
<p>Each time you add a new file to the project you will need to add (`svn add filename` for single files or `svn add *` for all files):</p>
<pre name="code" class="bash">
# Tell SVN we want to be versioning these files
svn add projectname/*
</pre>
<p>When you are happy with your changes you can commit (`svn commit -m &#8220;message&#8221;`) your changes to the svn to create a new version, it is mandatory to include a message with each revision and it is best to be as detailed as possible with the changes made. This makes it much easier to hunt down where a bug or regression was introduced.</p>
<pre name="code" class="bash">
# Save the changes and upload to repository
svn commit -m "Initial import of projectname"
</pre>
<p>Each time you commit or wish to upgrade what is stored locally to the latest version on the server you need to use the following:</p>
<pre name="code" class="bash">
# Update the locally stored version
svn update projectname
</pre>
<p><strong>Further points</strong><br />
Eclipse has a plugin to manage SVN download and install instructions can be found <a href="http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/02/android-using-svn-with-your-apps-project-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to tell android which volume (media/ringtone etc.) should be controlled by your app</title>
		<link>http://www.stealthcopter.com/blog/2010/02/how-to-tell-android-which-volume-mediaringtone-etc-should-be-controlled-by-your-app/</link>
		<comments>http://www.stealthcopter.com/blog/2010/02/how-to-tell-android-which-volume-mediaringtone-etc-should-be-controlled-by-your-app/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 21:14:39 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=602</guid>
		<description><![CDATA[In my android apps I was getting annoying problems that whilst playing sound the volume buttons would control the media volume, but when no sound was playing they would control the ringtone volume. I found the following by trial and error, hopefully this post will help people with the same problem. This is done by [...]]]></description>
			<content:encoded><![CDATA[<p>In my android apps I was getting annoying problems that whilst playing sound the volume buttons would control the media volume, but when no sound was playing they would control the ringtone volume. I found the following by trial and error, hopefully this post will help people with the same problem.</p>
<p>This is done by placing a call of setVolumeControlStream in the onCreate part of your activity which takes on of the following values</p>
<ul>
<li>AudioManager.STREAM_MUSIC</li>
<li>AudioManager.STREAM_RING</li>
<li>AudioManager.STREAM_ALARM</li>
<li>AudioManager.STREAM_NOTIFICATION</li>
<li>AudioManager.STREAM_SYSTEM</li>
<li>AudioManager.STREAM_VOICECALL</li>
</ul>
<p>Below shows the code required to set your applications default volume control to any of the above values:</p>
<p><strong>Media Volume</strong></p>
<pre name="code" class="java">
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
</pre>
<p><strong>Ringtone Volume</strong></p>
<pre name="code" class="java">
this.setVolumeControlStream(AudioManager.STREAM_RING);
</pre>
<p><strong>Alarm Volume</strong></p>
<pre name="code" class="java">
this.setVolumeControlStream(AudioManager.STREAM_ALARM);
</pre>
<p><strong>Notification Volume</strong></p>
<pre name="code" class="java">
this.setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
</pre>
<p><strong>System Volume</strong></p>
<pre name="code" class="java">
this.setVolumeControlStream(AudioManager.STREAM_SYSTEM);
</pre>
<p><strong>Voicecall Volume</strong></p>
<pre name="code" class="java">
this.setVolumeControlStream(AudioManager.STREAM_VOICECALL);
</pre>
<p>I imagine this is also possible via and XML settings, if anyone knows of this I&#8217;d be very grateful to know how!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/02/how-to-tell-android-which-volume-mediaringtone-etc-should-be-controlled-by-your-app/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Android: Saving a sound file to SD from resource and setting as ringtone</title>
		<link>http://www.stealthcopter.com/blog/2010/01/android-saving-a-sound-file-to-sd-from-resource-and-setting-as-ringtone/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/android-saving-a-sound-file-to-sd-from-resource-and-setting-as-ringtone/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 23:26:46 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sdk]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=559</guid>
		<description><![CDATA[Quite a few people have been asking how to save a file to the SD card in order to register it as a ringtone. The following example creates a function that will save a resource to the SD card (ie: from R.raw.soundfile to /sdcard/media/audio/ringtones/soundfile.wav) and register it as a ringtone. I have split this example [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a few people have been asking how to save a file to the SD card in order to register it as a ringtone. The following example creates a function that will save a resource to the SD card (ie: from R.raw.soundfile to /sdcard/media/audio/ringtones/soundfile.wav) and register it as a ringtone. </p>
<p>I have split this example into two parts, the first part goes through the code a section at a time with a brief explanation of what it does, the second half is just the code that you can copy and paste and then edit to your hearts content.</p>
<p><strong>Parts</strong></p>
<p>We first setup our function to return a boolean depicting if we have failed or if we are successful. We accept in an integer which corresponds to the raw sound file.</p>
<pre name="code" class="java">
public boolean saveas(int ressound){

}
</pre>
<p>So this function would be called in the following fashion:</p>
<pre name="code" class="java">saveas(R.raw.soundfile);</pre>
<p>or utilising its boolean return:</p>
<pre name="code" class="java">
if (saveas(R.raw.soundfile)){
// Code if successful
}
else
{
// Code if unsuccessful
}
</pre>
<p>The following chunk of code creates an inputstream from the raw sound resource and loads it into a buffer. We add in the mandatory try/catch clause around these operations and return false if an exception is raised (to indicate failure to the rest of our program and to prevent trying to continue act upon this sound).</p>
<pre name="code" class="java">
 byte[] buffer=null;
 InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
 int size=0;

 try {
  size = fIn.available();
  buffer = new byte[size];
  fIn.read(buffer);
  fIn.close();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  return false;
 }
</pre>
<p>The following saves the buffer to a file on the SD card. It first ensures the folder exists and if not it is created. Then as before the writing operations are surrounded with try/catches</p>
<pre name="code" class="java">
 String path="/sdcard/media/audio/ringtones/";
 String filename="examplefile"+".wav";

 boolean exists = (new File(path)).exists();
 if (!exists){new File(path).mkdirs();}

 FileOutputStream save;
 try {
  save = new FileOutputStream(path+filename);
  save.write(buffer);
  save.flush();
  save.close();
 } catch (FileNotFoundException e) {
  // TODO Auto-generated catch block
  return false;
 } catch (IOException e) {
  // TODO Auto-generated catch block
  return false;
 }
</pre>
<p>The following code sends an intent to tell the Media Scanner that we have added a new file, and sets up its properties in the media database:</p>
<pre name="code" class="java">
 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));

 File k = new File(path, filename);

 ContentValues values = new ContentValues();
 values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
 values.put(MediaStore.MediaColumns.TITLE, "exampletitle");
 values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
 values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
 values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
 values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
 values.put(MediaStore.Audio.Media.IS_ALARM, true);
 values.put(MediaStore.Audio.Media.IS_MUSIC, false);

 //Insert it into the database
 this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
</pre>
<p><strong>Final code</strong><br />
Putting all this code together gives us our final functions:</p>
<pre name="code" class="java">
public boolean saveas(int ressound){
 byte[] buffer=null;
 InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
 int size=0;

 try {
  size = fIn.available();
  buffer = new byte[size];
  fIn.read(buffer);
  fIn.close();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  return false;
 }

 String path="/sdcard/media/audio/ringtones/";
 String filename="examplefile"+".wav";

 boolean exists = (new File(path)).exists();
 if (!exists){new File(path).mkdirs();}

 FileOutputStream save;
 try {
  save = new FileOutputStream(path+filename);
  save.write(buffer);
  save.flush();
  save.close();
 } catch (FileNotFoundException e) {
  // TODO Auto-generated catch block
  return false;
 } catch (IOException e) {
  // TODO Auto-generated catch block
  return false;
 }    

 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));

 File k = new File(path, filename);

 ContentValues values = new ContentValues();
 values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
 values.put(MediaStore.MediaColumns.TITLE, "exampletitle");
 values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
 values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
 values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
 values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
 values.put(MediaStore.Audio.Media.IS_ALARM, true);
 values.put(MediaStore.Audio.Media.IS_MUSIC, false);

 //Insert it into the database
 this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

 return true;
}
</pre>
<p>Comments, suggestions etc. are always welcome. Hope this has been helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/android-saving-a-sound-file-to-sd-from-resource-and-setting-as-ringtone/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Android: Eclipse and problems with dynamic tables (adding rows)</title>
		<link>http://www.stealthcopter.com/blog/2010/01/android-eclipse-and-problems-with-dynamic-tables-adding-rows/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/android-eclipse-and-problems-with-dynamic-tables-adding-rows/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 21:42:48 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[sdk]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=494</guid>
		<description><![CDATA[When using TableLayout with LayoutParams Eclipse will automatically (and wrongly) add the following import: import android.view.ViewGroup.LayoutParams; However if you try to use this you will notice that nothing changes. You need to replace the import with the ollowingL import android.widget.TableRow.LayoutParams; Now if you rerun your code, you will see that your tables are updating. See [...]]]></description>
			<content:encoded><![CDATA[<p>When using TableLayout with LayoutParams Eclipse will automatically (and wrongly) add the following import:</p>
<pre name="code" class="python">
import android.view.ViewGroup.LayoutParams;
</pre>
<p>However if you try to use this you will notice that nothing changes. You need to replace the import with the ollowingL</p>
<pre name="code" class="python">
import android.widget.TableRow.LayoutParams;
</pre>
<p>Now if you rerun your code, you will see that your tables are updating. See below for an example of the code to generate a table</p>
<pre name="code" class="python">
int sizey=10;
int sizex=10;
int btnwidth=24;
TableLayout tl = (TableLayout)findViewById(R.id.MyTableLayout); 

for (int y=0;y&lt;sizey;y++){

// Rows
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

//Cells
for (int x=0;x&lt;sizex;x++){
// Create new cell
	// new button
	Button b = new Button(this);
	b.setText(x+""+y);
	b.setLayoutParams(new LayoutParams(
		LayoutParams.FILL_PARENT,
		LayoutParams.WRAP_CONTENT));
	b.setHeight(btnwidth);
	b.setBackgroundResource(R.drawable.btn_blue);
	b.setOnClickListener(new PegOnClickListener(y,x));
	// add button to row
	tr.addView(b);
	}
// add row to layout
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/android-eclipse-and-problems-with-dynamic-tables-adding-rows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android: Blurring and dimming background windows from dialogs</title>
		<link>http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 22:32:03 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[WordCube]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=463</guid>
		<description><![CDATA[The android SDK has lots of nice goodies built in to make your applications look sexier. One such feature is the blurring of windows. This effect looks particularly nice if a background window is blurred while a dialog box is shown above which can really make it stand out. Below shows the application such an [...]]]></description>
			<content:encoded><![CDATA[<p>The android SDK has lots of nice goodies built in to make your applications look sexier. One such feature is the blurring of windows. This effect looks particularly nice if a background window is blurred while a dialog box is shown above which can really make it stand out. Below shows the application such an example; on the left is the default about box (for WordCube Pro) and on the right is with added blur and no dimming.</p>
<div id="attachment_466" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_dim_both.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_dim_both-300x221.png" alt="android blur dim, before, after" title="android_dim_both" width="300" height="221" class="size-medium wp-image-466" /></a><p class="wp-caption-text">android bluring and dimming effect before and after</p></div>
<p>I am using the AlterDialog.Builder to create my dialog, however this method will work with all kinds of dialog providing you can access it via getWindow.</p>
<pre name="code" class="java">
   dialog = new AlertDialog.Builder(WordCube.this)
   .setTitle(WordCube.this.getResources().getString(R.string.app_name))
   .setMessage(s)
   .setIcon(R.drawable.logo)
   .setPositiveButton(R.string.btn_close, null)
   .show();
</pre>
<p>Below shows the code needed to add blur and remove dimming of the background (as I think the blur looks nicer when the background is well lit).</p>
<pre name="code" class="java">
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount=0.0f;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
</pre>
<p>The blur is simply created using the last line (line 4) which sets a flag for the dialog telling android that we want windows below this one to be blurred. To achieve the dimming, we need to retrieve the layout parameters for the dialog window, set the dim amount to zero, update these parameters with setAttributes (lines 1-3).</p>
<p>Any comments, questions, or improvements please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Android: Improving Interfacing with twitter applications</title>
		<link>http://www.stealthcopter.com/blog/2010/01/android-improving-interfacing-with-twitter-applications/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/android-improving-interfacing-with-twitter-applications/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 15:03:52 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=447</guid>
		<description><![CDATA[This post builds upon the ideas shown in this post to create a complete function that will do the follow: Accept a string input for the message Try to open twidroidpro to send this tweet If failed, try to open twidroid to send this tweet If failed, bring up a list of applications that can [...]]]></description>
			<content:encoded><![CDATA[<p>This post builds upon the ideas shown in <a href="http://www.stealthcopter.com/blog/2010/01/android-interfacing-with-twitter-applications/">this post</a> to create a complete function that will do the follow:</p>
<ul>
<li>Accept a string input for the message</li>
<li>Try to open twidroidpro to send this tweet</li>
<li>If failed, try to open twidroid to send this tweet</li>
<li>If failed, bring up a list of applications that can send this information</li>
<li>Return a boolean indicating success of displaying the intent</li>
</ul>
<p><strong>Code</strong></p>
<pre name="code" class="java">
public boolean intentTwitter(String message){
 // Boolean to show if we succeeded or not
 // we assume we did until proven otherwise.
 boolean success=true;

 //Try twidroidpro first
 Intent intent = new Intent("com.twidroidpro.SendTweet");
 intent.putExtra("com.twidroidpro.extra.MESSAGE", message);
 intent.setType("application/twitter");
   try{
    startActivityForResult(intent, 1);
   }
   catch(ActivityNotFoundException e){
    success=false;
   }

 // Then twidroid if we failed
 if (!success){
  success=true;
  intent = new Intent("com.twidroid.SendTweet");
  intent.putExtra("com.twidroid.extra.MESSAGE", message);
  intent.setType("application/twitter");
    try{
     startActivityForResult(intent, 1);
    }
    catch(ActivityNotFoundException e){
     success=false;
    }
 }

 //Then send general intent if we failed again
 if (!success){
  success=true;
   try {
    intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, d);
    intent.setType("application/twitter");
    startActivity(Intent.createChooser(intent, null));
   } catch (ActivityNotFoundException e) {
    success=false;
   }
 }
// return indicating if we were successful in bringing up an intent
// of some description
return success;
}
</pre>
<p><strong>Example</strong><br />
Below is a screenshot from the wordcube (available on market) application using this function to make the application interact with twitter.</p>
<div id="attachment_429" class="wp-caption aligncenter" style="width: 345px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_twidroid.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_twidroid.png" alt="twidroid intent screenshot" title="android_twidroid" width="335" height="492" class="size-full wp-image-429" /></a><p class="wp-caption-text">twidroid intent called from wordcube</p></div>
<p><strong>What&#8217;s next?</strong><br />
In a future post I will be demonstrating how to interact with the android market, this can be use in conjunction with something similar to above to try and run a program and if the program is not installed the user can be taken to the market to download a program.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/android-improving-interfacing-with-twitter-applications/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Android: Counter-Strike 1.6 SoundBoard released</title>
		<link>http://www.stealthcopter.com/blog/2010/01/android-counter-strike-1-6-soundboard-released/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/android-counter-strike-1-6-soundboard-released/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 01:15:08 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sdk]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=433</guid>
		<description><![CDATA[A soundboard is a very simple application to make, and I was given the idea to make a counter-strike 1.6 version by a friend. It seemed like a good idea as no one had made one yet, and it&#8217;s quite hard to find something that hasn&#8217;t already been done before. The buttons are aligned in [...]]]></description>
			<content:encoded><![CDATA[<p>A soundboard is a very simple application to make, and I was given the idea to make a counter-strike 1.6 version by a friend. It seemed like a good idea as no one had made one yet, and it&#8217;s quite hard to find something that hasn&#8217;t already been done before.</p>
<div class="wp-caption aligncenter" style="width: 190px"><img alt="counter-strike 1.6 soundboard promo image" src="http://www.stealthcopter.com/android/apps/counterstrikesb/icon.png" title="counter-strike 1.6 soundboard promo image" width="180" height="120" /><p class="wp-caption-text">counter-strike 1.6 soundboard</p></div>
<p>The buttons are aligned in a grid view, with the buttons made transparent so that the background can be seen.</p>
<div class="wp-caption aligncenter" style="width: 330px"><img alt="screenshot of counter-strike 1.6 soundboard android application" src="http://www.stealthcopter.com/android/apps/counterstrikesb/ss1.png" title="counter-strike 1.6 soundboard android application 1" width="320" height="480" /><p class="wp-caption-text">screenshot of counter-strike 1.6 soundboard</p></div>
<div class="wp-caption aligncenter" style="width: 330px"><img alt="another screenshot of counter-strike 1.6 soundboard android application" src="http://www.stealthcopter.com/android/apps/counterstrikesb/ss2.png" title="counter-strike 1.6 soundboard android application 2" width="320" height="480" /><p class="wp-caption-text">screenshot of counter-strike 1.6 soundboard</p></div>
<p>I am very pleased with the final look of the app, however it was getting poor reviews due to people wanting to save the sounds for use as a ringtone. To alleviate this problem I have updated the app to have this option as a context menu avaliable by long pressing on a button. This will then save the file on the sd card and update the mediastore to tell android a new ringtone and notification has been added.</p>
<p>The code to load a ringtone into android from an application is shown below. If you see any problems with this code, or have an improvements please let me know!</p>
<pre name="code" class="java">
File k = new File(path, filename);

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, filesnames[pos]);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

//Insert it into the database
this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
</pre>
<p>Ratings, reviews, feedback and feature requests are most welcome.</p>
<p><a href="http://www.stealthcopter.com/android/apps/counterstrikesb/counterstrikesb.apk">Download Link</a></p>
<p><a href="market://details?id=com.sc.counterstrikesb">Android Market Link</a> (For android phones)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/android-counter-strike-1-6-soundboard-released/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Android: Interfacing with twitter applications</title>
		<link>http://www.stealthcopter.com/blog/2010/01/android-interfacing-with-twitter-applications/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/android-interfacing-with-twitter-applications/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 13:59:29 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=422</guid>
		<description><![CDATA[Below are some code snippets for sending messages to twitter from your application by utilizing a twitter application. The following code will create a new intent(a request to android for something to happen) for the twidroid application and pass it the message we wish to send. It is important to set the type of the [...]]]></description>
			<content:encoded><![CDATA[<p>Below are some code snippets for sending messages to twitter from your application by utilizing a twitter application.</p>
<p>The following code will create a new intent(a request to android for something to happen) for the twidroid application and pass it the message we wish to send. It is important to set the type of the intent as it will fail without it (from at least android 1.5). It will then start the activity and we use a try/catch encase twidroid is not found.</p>
<pre name="code" class="java">
	Intent intent = new Intent("com.twidroid.SendTweet");
	intent.putExtra("com.twidroid.extra.MESSAGE",
	"@stealthcopter Example tweet from android application");
	intent.setType("application/twitter");
	try {
		startActivity(intent);
	}
	catch (ActivityNotFoundException e) {
		/* Handle Exception if Twidroid is not installed */
		Toast.makeText(this, "Twidroid not found.", Toast.LENGTH_SHORT).show();
	}
</pre>
<p>But what if someone has a different twitter application installed? this can be solved by offering the user a choice of application to open.</p>
<pre name="code" class="java">
	Intent intent = new Intent(Intent.ACTION_SEND);
	intent.putExtra(Intent.EXTRA_TEXT,
	"@stealthcopter Example tweet from android application");
	intent.setType("application/twitter");
	try {
		startActivity(Intent.createChooser(intent, null));
	}
	catch (ActivityNotFoundException e) {
		/* Handle Exception if no suitable apps installed */
		Toast.makeText(this, "No suitable apps found.", Toast.LENGTH_SHORT).show();
	}
</pre>
<p>By combining these two solutions we can make the choice dialog only pop up if the system cannot find the twidroid application. This can be then taken even further by asking the user if they wish to visit the market place to install a twitter application if none is found.</p>
<pre name="code" class="java">
   new AlertDialog.Builder(WordCube.this)
   .setTitle("Get Twitter")
   .setMessage("No twitter Application not found. Goto market and install one now?")
   .setIcon(R.drawable.logo)
   .setNegativeButton(R.string.dialog_no, null)
                   .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                	intentMarket("market://search?q=twitter");
                }
            })
   .show();
</pre>
<p>Where intentMarket() is defined a to open up the market and search for the specified application passed to it as a string.</p>
<pre name="code" class="java">
public void intentMarket(String url){
	Intent i = new Intent(Intent.ACTION_VIEW);
	Uri u = Uri.parse(url);
	i.setData(u);
	try {
		startActivity(i);
	} catch (ActivityNotFoundException e) {
		toastMessage("Market not found.");
	}
}
</pre>
<p>Below shows two screenshots from the <a href="http://www.stealthcopter.com/wordcube">wordcube</a> application. This application is avaliable for android, see <a href="http://www.stealthcopter.com/android">here</a> for more information and download link (or visit market on your android device).</p>
<div id="attachment_429" class="wp-caption aligncenter" style="width: 345px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_twidroid.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_twidroid.png" alt="twidroid intent screenshot" title="android_twidroid" width="335" height="492" class="size-full wp-image-429" /></a><p class="wp-caption-text">twidroid intent called from wordcube</p></div>
<div id="attachment_431" class="wp-caption aligncenter" style="width: 339px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_choice_intent.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_choice_intent.png" alt="choice box after intent" title="android_choice_intent" width="329" height="491" class="size-full wp-image-431" /></a><p class="wp-caption-text">choice box for twitter applications</p></div>
<p><strong>Update:</strong> This is now taken into a complete function in <a href="http://www.stealthcopter.com/blog/2010/01/android-improving-interfacing-with-twitter-applications/">this post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/android-interfacing-with-twitter-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming Android Apps: SDK and Eclipse (ubuntu)</title>
		<link>http://www.stealthcopter.com/blog/2010/01/programming-android-apps-sdk-and-eclipse-ubuntu/</link>
		<comments>http://www.stealthcopter.com/blog/2010/01/programming-android-apps-sdk-and-eclipse-ubuntu/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 13:59:43 +0000</pubDate>
		<dc:creator>mat</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.stealthcopter.com/blog/?p=382</guid>
		<description><![CDATA[Android is a brilliant smart phone operating system, this is the start of a short series of guides for starting to program applications for it using the android SDK. Android SDK Download the android SDK Once downloaded untar the SDK tar xvzf android-sdk_r04-linux_86.tgz The SDK is not complete as additional files need to be downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>Android is a brilliant smart phone operating system, this is the start of a short series of guides for starting to program applications for it using the android SDK.</p>
<p><strong>Android SDK</strong><br />
Download the <a href="http://developer.android.com/sdk/index.html">android SDK</a></p>
<p>Once downloaded untar the SDK</p>
<blockquote><p>
tar xvzf android-sdk_r04-linux_86.tgz
</p></blockquote>
<p>The SDK is not complete as additional files need to be downloaded in order to compile for different versions of android. Open the SDK and AVG management application by moving into the SDK folder and running the following.</p>
<blockquote><p>
sh tools/android
</p></blockquote>
<p>In the <strong>avaliable packages</strong> select the android versions you wish to develop for, and begin downloading them. Should this fail please read the next section, otherwise skip ahead.</p>
<p><strong>Failing to download</strong><br />
If you cannot download from the google website, goto settings and select &#8220;force https://&#8230; source to be fetched using  http://&#8221; and click save and apply. </p>
<div id="attachment_388" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_force_http.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_force_http-300x174.png" alt="android force http" title="android_force_http" width="300" height="174" class="size-medium wp-image-388" /></a><p class="wp-caption-text">forcing SDK and AVD manager http instead of https for android </p></div>
<p>If this still does not work (as was the case for me) it is possible that for some reason a configuration file was not created for this program, this can be solved by creating it manually:</p>
<blockquote><p>
echo sdkman.force.http=true > ~/.android/androidtool.cfg
</p></blockquote>
<p><strong>Creating Android Virtual Devices</strong><br />
You can create virtual android phones using the SDK and AVD manager, click the Virtual Device tab and select new. Enter a name for the device, and a size for the sd card and simply click create AVD.</p>
<div id="attachment_391" class="wp-caption aligncenter" style="width: 230px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_create_avd.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_create_avd-220x300.png" alt="android create avd" title="android_create_avd" width="220" height="300" class="size-medium wp-image-391" /></a><p class="wp-caption-text">creation of an android virtual device</p></div>
<p>Once you&#8217;ve created you Virtual Device(s) it should look like the following:</p>
<div id="attachment_392" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_avds.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_avds-300x174.png" alt="android avd&#039;s" title="android_avds" width="300" height="174" class="size-medium wp-image-392" /></a><p class="wp-caption-text">Android Virtual Devices</p></div>
<p>You can test these virtual devices and see how nicely the phones are emulated. This is much more useful once you begin writing applications.</p>
<div id="attachment_394" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_virtual_device.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_virtual_device-300x251.png" alt="Android virtual device" title="android_virtual_device" width="300" height="251" class="size-medium wp-image-394" /></a><p class="wp-caption-text">Android Virtual Device in action</p></div>
<p><strong>Eclipse</strong></p>
<p>I would highly recommend using eclipse as it, along with the android plugin, greatly simplifies production and testing of applications.</p>
<p>Download eclipse from the ubuntu repositories (or from <a href="http://www.eclipse.org/downloads/">the eclipse website</a>)</p>
<blockquote><p>
sudo apt-get install eclipse
</p></blockquote>
<p>If you do not already have java installed then you will need to install it.</p>
<blockquote><p>
sudo apt-get install sun-java6-jdk sun-java6-jre
</p></blockquote>
<p>You will need to add the following line to your .bashrc in your home folder so that the android tools can be used in eclipse (and other programs).</p>
<blockquote><p>
export PATH=${PATH}:/home/user/android/sdk/tools
</p></blockquote>
<p><strong>* replace /home/user/android/sdk with the path to where you downloaded the SDK</strong></p>
<p><strong>Installing the android plugin for eclipse</strong><br />
Google&#8217;s eclipse plugin <a href="https://dl-ssl.google.com/android/eclipse/">install guide</a>.</p>
<p>In eclipse goto help then Install new software and then add the google plugin url</p>
<blockquote>
<p>https://dl-ssl.google.com/android/eclipse/</p>
</blockquote>
<div id="attachment_412" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/eclipse_addnew.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/eclipse_addnew-300x278.png" alt="Install software" title="eclipse_addnew" width="300" height="278" class="size-medium wp-image-412" /></a><p class="wp-caption-text">Install new software in eclipse</p></div>
<p>Then install Android DDMS and Android Development Tools.</p>
<p>Should you receive errors (like I did) relating to a missing package you will need to add the eclipse repository and install the missing packages.</p>
<blockquote>
<p>http://download.eclipse.org/releases/galileo</p>
</blockquote>
<p>You should then have a fully working eclipse with android plugin.</p>
<div id="attachment_409" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_eclipse_main.png"><img src="http://www.stealthcopter.com/blog/wp-content/uploads/2010/01/android_eclipse_main-300x180.png" alt="Eclipse main window" title="android_eclipse_main" width="300" height="180" class="size-medium wp-image-409" /></a><p class="wp-caption-text">Eclipse main window</p></div>
<p><strong>What next?</strong><br />
Now you should have everything setup in order to develop and android applications. I would recommend the google tutorials:</p>
<ul>
<li><a href="http://developer.android.com/guide/tutorials/hello-world.html">Hello World</a></li>
<li><a href="http://developer.android.com/guide/tutorials/notepad/index.html">Notepad</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.stealthcopter.com/blog/2010/01/programming-android-apps-sdk-and-eclipse-ubuntu/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
