<?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>SamColes.co.uk</title>
	<atom:link href="http://www.samcoles.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.samcoles.co.uk</link>
	<description>Android and stuff</description>
	<lastBuildDate>Thu, 19 Apr 2012 13:21:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Take Photo Using ACTION_IMAGE_CAPTURE Intent</title>
		<link>http://www.samcoles.co.uk/mobile/take-photo-using-action_image_capture-intent/</link>
		<comments>http://www.samcoles.co.uk/mobile/take-photo-using-action_image_capture-intent/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 10:01:54 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[ACTION_IMAGE_CAPTURE]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Camera]]></category>
		<category><![CDATA[Intent]]></category>
		<category><![CDATA[Photo]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=612</guid>
		<description><![CDATA[In this post we will build a working sample app that allows the user to press a button to take a photo using the phone&#8217;s camera app (or any other available) and then loads this photo into an ImageView. You could of course do anything you like with the photo such as upload it to [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we will build a working sample app that allows the user to press a button to take a photo using the phone&#8217;s camera app (or any other available) and then loads this photo into an ImageView. You could of course do anything you like with the photo such as upload it to a web service or save it to permanent storage.</p>
<p>Begin by creating a new Android project, then open up your main.xml layout file and edit it. The below xml creates an ImageButton and an ImageView. Everything we need for the sample. The ImageView references a placeholder image.. just a little snap of someone I spotted the last time I was at the beach. <img src='http://www.samcoles.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:background="#FFFFFF"&gt;

    &lt;ImageButton
    	android:id="@+id/btn_take_photo"
    	android:src="@android:drawable/ic_menu_camera"
    	android:layout_width="60dp"
    	android:layout_height="60dp"
    	android:layout_marginTop="10dp"
    	android:layout_marginBottom="5dp" /&gt;

    &lt;ImageView
    	android:id="@+id/img_main"
    	android:src="@drawable/kiss_from_a_rose"
    	android:layout_height="wrap_content"
		android:layout_width="fill_parent"
    	android:scaleType="fitXY"
    	android:adjustViewBounds="true"
    	android:padding="5dp" /&gt;

&lt;/LinearLayout&gt;</pre>
<p>In your Activity&#8217;s onCreate() method, attach a listener to the button. When the button is clicked we want to start an ACTION_IMAGE_CAPTURE Intent using startActivityForResult().</p>
<pre class="brush:java">findViewById(R.id.btn_take_photo).setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {
		Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		startActivityForResult(i, REQ_CODE_PHOTO_TAKE);
	}
});</pre>
<p>You&#8217;ll also need to create the REQ_CODE_PHOTO_TAKE constant. This value will be returned in the resultCode.</p>
<pre class="brush:java">private static final int REQ_CODE_PHOTO_TAKE = 1;</pre>
<p>Next up push Alt+Shift+S and click &#8220;Override/Implement Methods&#8221; from the menu. Choose to Override onActivityResult() and click ok.</p>
<p>You&#8217;ll notice this method has three parameters. &#8216;resultCode&#8217; is self explanatory &#8211; if this is anything other than RESULT_OK we&#8217;ll want to return immediately. An example where this might happen is if the user were to push the button to take a photo but then push their phone&#8217;s back button immediately rather than take one. requestCode contains the value that we passed in during startActivityForResult(), in our case this is REQ_CODE_PHOTO_TAKE. Lastly is the returned Intent. We can use this to get a Uri to the data by calling getData().</p>
<pre class="brush:java">@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	super.onActivityResult(requestCode, resultCode, data);	

	if(resultCode != RESULT_OK) return;

	switch (requestCode) {
	case REQ_CODE_PHOTO_TAKE:
		Uri u = data.getData();
		onPhotoReturned(u);
    	break;
	default:
		break;
	}
}</pre>
<p>Lastly we&#8217;ll want to display the photo in our ImageView. Create the new method, onPhotoReturn(Uri u). We use the Uri to open an InputStream and from this we can create a BitmapDrawable which can be used to set the Drawable for the ImageView.</p>
<pre class="brush:java">private void onPhotoReturned(Uri u) {
	InputStream is = null;
	try {
		ContentResolver cResolver = getContentResolver();
		is = cResolver.openInputStream(u);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
	BitmapDrawable bmp = new BitmapDrawable(is);
	ImageView mainImage = (ImageView)findViewById(R.id.img_main);
	mainImage.setImageDrawable(bmp);
}</pre>
<p>Working code for this app can be found on my <a title="github" href="https://github.com/SamColes/Android-Samples/tree/master/TakePhotoExample">github</a> and a screenshot of it in action is below:</p>
<div id="attachment_613" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/take-photo-using-action_image_capture-intent/attachment/takephotoexample/" rel="attachment wp-att-613"><img class="size-medium wp-image-613" title="TakePhotoExample" src="http://www.samcoles.co.uk/uploads/TakePhotoExample-180x300.png" alt="TakePhotoExample" width="180" height="300" /></a><p class="wp-caption-text">TakePhotoExample</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/take-photo-using-action_image_capture-intent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do not use City Main Administrators or The Fone Clinic</title>
		<link>http://www.samcoles.co.uk/mobile/do-not-use-www-thefoneclinic-com/</link>
		<comments>http://www.samcoles.co.uk/mobile/do-not-use-www-thefoneclinic-com/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 14:27:58 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Citymain Administrators]]></category>
		<category><![CDATA[Cracked Screen]]></category>
		<category><![CDATA[Insurance]]></category>
		<category><![CDATA[Mobile Phone]]></category>
		<category><![CDATA[Repair]]></category>
		<category><![CDATA[The Fone Clinic]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=581</guid>
		<description><![CDATA[Since purchasing my HTC Desire nearly 18 months&#8217; ago I&#8217;ve had insurance through Citymain Administrators. It&#8217;s £5.99 a month and covers me for theft and accidents. The service from their call centre has been all in all quite good since I dropped and broke the screen on my phone on September 15th 2011, unfortunately the [...]]]></description>
			<content:encoded><![CDATA[<p>Since purchasing my HTC Desire nearly 18 months&#8217; ago I&#8217;ve had insurance through Citymain Administrators. It&#8217;s £5.99 a month and covers me for theft and accidents. The service from their call centre has been all in all quite good since I dropped and broke the screen on my phone on September 15th 2011, unfortunately the company they use for repairs has now taken almost three weeks to repair my phone. I was told last Friday that my phone was finally being repaired &#8211; after being told this I kind of expected it to arrive Saturday or Monday. That&#8217;s a reasonable expectation in a world that expects good customer service, no? Monday 3rd October I was told it was repaired but waiting to be posted to me. Today, Wednesday 5th October I was told that it was <em>still</em> waiting to be posted to me and this should hopefully happen tomorrow. If this holds true &#8211; and I have my doubts &#8211; then I&#8217;ll get my phone back on Friday which makes it three weeks. The worst part is the length of time that I know <em>my phone has been sat idle</em>.</p>
<p>They don&#8217;t appear to be a small outfit either, covering units 18 &#8211; 20 in the picture below. You&#8217;d think someone could post a phone for a customer regularly chasing and specifically requesting it be returned in time for <a title="DroidCon" href="http://uk.droidcon.com/">Droidcon</a> tomorrow?</p>
<div id="attachment_582" class="wp-caption alignnone" style="width: 310px"><a href="http://www.samcoles.co.uk/mobile/do-not-use-www-thefoneclinic-com/attachment/screenshot-2/" rel="attachment wp-att-582"><img class="size-medium wp-image-582" title="thefoneclinic" src="http://www.samcoles.co.uk/uploads/Screenshot-2-300x110.png" alt="thefoneclinic" width="300" height="110" /></a><p class="wp-caption-text">thefoneclinic</p></div>
<p>From this experience I will soon be cancelling my policy with <a title="Citymain" href="http://www.citymain.com">Citymain Administrators</a> and do not recommend you use either them or <a title="The Fone Clinic" href="http://www.thefoneclinic.com/">The Fone Clinic</a> in Southend-On-Sea.</p>
<p>If anyone can recommend to me a UK phone insurance policy that doesn&#8217;t let you down when it comes to needing a repair, please let me know&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/do-not-use-www-thefoneclinic-com/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Android: Use GreenDroid to implement an ActionBar</title>
		<link>http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 15:19:44 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[ActionBar]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[GreenDroid]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=557</guid>
		<description><![CDATA[This post covers the basics of setting up a project using the GreenDroid library including pulling it from GitHub and how to use the ActionBar it provides. GreenDroid is a useful UI library for Android developed by Cyril Mottier. You can check out all the features it provides by downloading the GDCatalog app from the [...]]]></description>
			<content:encoded><![CDATA[<p>This post covers the basics of setting up a project using the GreenDroid library including pulling it from GitHub and how to use the ActionBar it provides. GreenDroid is a useful UI library for Android developed by <a href="http://twitter.com/#!/cyrilmottier">Cyril Mottier</a>. You can check out all the features it provides by downloading the <a href="https://market.android.com/details?id=com.cyrilmottier.android.gdcatalog">GDCatalog app</a> from the Android Market.</p>
<blockquote><p>The action bar:</p>
<ul>
<li>is located at the top of the screen to support navigation and highlight important functionalities</li>
<li>replaces the title bar (which is often included into it)</li>
<li>is best used for actions across your app, like search, refresh and compose</li>
<li>can provide a quick link to app home by tapping the app logo</li>
<li>is preferably not contextual, but actions can differ from page to page</li>
</ul>
<p><a href="http://www.androidpatterns.com/uap_pattern/action-bar">Android Patterns</a></p></blockquote>
<p>If you don’t have EGit in Eclipse. You’ll need to install it. See <a href="http://eclipse.org/egit/">here</a>. Begin by opening the “Git Repository Exploring” perspective. Window &gt; Open Perspective. Click the button for “Clone a Git Repository and add the clone to this view” and paste in this to the URI field: <strong>https://github.com/cyrilmottier/GreenDroid.git</strong> &#8211; the rest of the details should be filled in automatically, so hit next and follow the wizard through. It’s likely you won’t need to change anything.</p>
<p>You’ll notice the GreenDroid repository is now available to you. Open out the branches GreenDroid &gt; Working directory, right click the folder ‘GreenDroid’ and select ‘Import Projects’. Follow the dialog through and click finish. Switch back to the Java Perspective and you will now have the GreenDroid project imported. You will likely have a problem with the project’s ‘gen’ folder or R.java. If you do (an exclamation mark or cross next to the project name), delete it and then recreate a new folder called gen, if not, create the folder. I also had to right click the project, Android Tools &gt; Fix Project Properties to get it working as it was targeting a different compiler version to mine.</p>
<p>Next up create your new Android Project, the build target will need to be a minimum of 1.6 to use GreenDroid. Right click on your newly created project, select Properties, then select Android on the left hand side of the dialog. At the bottom of the window you can click “Add..” and you should have the option to select GreenDroid as a library. Click OK.</p>
<p>Change your default Activity to extend GDActivity. Wherever you want to use the GreenDroid ActionBar your class will need to extend GDActivity, GDListActivity or GDTabActivity. You will also need to remember to no longer call setContentView() to set your layout and instead use setActionBarContentView(). The former will crash your Activity. Change these and hit ctrl+shift+o to organise your imports.</p>
<pre class="brush:java">public class GreenDroidActionBarExampleActivity extends GDActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setActionBarContentView(R.layout.main);
    }
}</pre>
<p>Next add a new class to your project that extends GDApplication. Override the getHomeActivityClass() method and the getMainApplicationIntent() methods. The former will need to return your main home/launcher activity and the latter will return an Intent to view the relevant website for your app:</p>
<pre class="brush:java">public class GDActionBarExampleApplication extends GDApplication {

    @Override
    public Class&lt;?&gt; getHomeActivityClass() {
        return GreenDroidActionBarExampleActivity.class;
    }

    @Override
    public Intent getMainApplicationIntent() {
        return new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_url)));
    }

}</pre>
<p>You will also need to add the the app_url string to your res/values/strings.xml file:</p>
<pre class="brush:xml">&lt;string name="app_url"&gt;http://www.samcoles.co.uk&lt;/string&gt;</pre>
<p>Next update your AndroidManifext.xml to use your new Application class:</p>
<pre class="brush:xml">&lt;application android:icon="@drawable/icon"
     			android:label="@string/app_name"
     			android:name=".GDActionBarExampleApplication"&gt;</pre>
<p>Right click your res/values folder and create a new xml values file, call it themes.xml. In here we will specify some app-wide styles for your ActionBar. Ignore the error on the gdActionBarApplicationDrawable and gdActionBarBackground value for now:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
	&lt;style name="Theme.GDActionBarExample" parent="@style/Theme.GreenDroid.NoTitleBar"&gt;
		&lt;item name="gdActionBarTitleColor"&gt;#FFFDD0&lt;/item&gt;
		&lt;item name="gdActionBarBackground"&gt;@drawable/action_bar_background&lt;/item&gt;
		&lt;item name="gdActionBarDividerWidth"&gt;2px&lt;/item&gt;
		&lt;item name="gdActionBarApplicationDrawable"&gt;@drawable/application_logo&lt;/item&gt;
	&lt;/style&gt;
&lt;/resources&gt;</pre>
<p>Again, update the application tag in your AndroidManifest.xml to use this theme:</p>
<pre class="brush:xml">&lt;application android:icon="@drawable/icon"
     			android:label="@string/app_name"
     			android:theme="@style/Theme.GDActionBarExample"
     			android:name=".GDActionBarExampleApplication"&gt;</pre>
<p>Back to the error in themes.xml. It is clear that you could just place an image into your drawable folders called application_logo. But we are going to use a StateDrawable xml so that the logo behaves like a button. Create a folder, /res/drawable and within here create two new xml files called application_logo.xml and action_bar_background.xml, the latter will be a ShapeDrawable for our ActionBar’s background. In application_logo.xml place your state drawable code that defines the image to use for pressed, focused and normal states:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;selector
	xmlns:android="http://schemas.android.com/apk/res/android"&gt;

	&lt;item
		android:state_pressed="true"
		android:drawable="@drawable/application_logo_alt" /&gt;

	&lt;item
		android:state_focused="true"
		android:drawable="@drawable/application_logo_alt" /&gt;

	&lt;item
		android:drawable="@drawable/application_logo_normal" /&gt;

&lt;/selector&gt;</pre>
<p>and in action_bar_background.xml the ShapeDrawable code. This is just a solid block of colour, but you could specify a gradient or even use an image:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;shape
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:shape="rectangle"&gt;

	&lt;solid android:color="#708090" /&gt;

&lt;/shape&gt;</pre>
<p>Next you will need to place the images you’ve specified in the application_logo.xml StateDrawable into your project. The GDCatalog app uses the dimensions of 205&#215;51 pixels for the hdpi versions and 135&#215;34 for the mdpi version. I haven’t yet needed to experiment with different sizes so mine are the same dimensions, and these suit the ActionBar proportions well. Place these into the relevant res/drawable-hdpi and res/drawable-mdpi folders.</p>
<p>You should now be able to run the project and test it out! It won’t look much but you can tap the logo and it should open the URL specified in your app_url string. Notice also that it changes to your application_logo_alt.png image when touched or selected.</p>
<p>Next we will make the ActionBar a little more useful by adding a button to it that will take us to our application’s info activity. Back in GreenDroidActionBarExampleActivity, simply add an info button by placing this call in your onCreate() method:</p>
<pre class="brush:java">addActionBarItem(Type.Info, ACTION_BAR_INFO);</pre>
<p>Also add that constant to the top of your class:</p>
<pre class="brush:java">private static final int ACTION_BAR_INFO = 0;</pre>
<p>Go ahead and run it again. The info button is in! But you’ll notice that nothing happens when you click it.</p>
<p>To enable this button to do something we need to override onHandleActionBarItemClick(). Right click your Activity, source &gt; Override/Implement methods and choose it from the options under GDActivity. You can get the value of the id that was passed in the second parameter of addActionBarItem  by calling getItemId() on the item. So create a switch block on this value and start InfoActivity (we’ll create this next) if the info button has been pressed:</p>
<pre class="brush:java">@Override
public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
	switch(item.getItemId()) {
	case ACTION_BAR_INFO:
		startActivity(new Intent(this, InfoActivity.class));
		break;
	default:
		return super.onHandleActionBarItemClick(item, position);
	}
	return true;
}</pre>
<p>Create the new class InfoActivity that extends GDActivity, and don’t forget to add it to your manifest.</p>
<pre class="brush:xml">&lt;activity android:name=".InfoActivity"&gt;&lt;/activity&gt;</pre>
<p>In your onCreate() method of InfoActivity set the title to be displayed in the Action Bar:</p>
<pre class="brush:java">@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActionBarContentView(R.layout.main);
    setTitle(R.string.info_activity_title);
}</pre>
<p>Remember to add this string to your strings.xml file also:</p>
<pre class="brush:xml">&lt;string name="info_activity_title"&gt;App Info&lt;/string&gt;</pre>
<p>Now run your app! Notice that the InfoActivity Action Bar has a home button and a title in place of the application logo. Tap the home button to return to the home activity you just came from.</p>
<p>Working Android 1.6 source for this post is <a href="https://github.com/SamColes/Android-Samples/tree/master/GreenDroidActionBarExample">available on github</a>. To checkout the other features of GreenDroid you can also import the project for the GDCatalog app from the GreenDroid github repository.</p>
<div>
<div style="float: left;">
<div id="attachment_558" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/attachment/actionbarexample/" rel="attachment wp-att-558"><img class="size-medium wp-image-558" title="Action Bar Using GreenDroid" src="http://www.samcoles.co.uk/uploads/actionbarexample-180x300.png" alt="Action Bar Using GreenDroid" width="180" height="300" /></a><p class="wp-caption-text">Action Bar Using GreenDroid</p></div>
</div>
<div style="float: left; padding-left: 10px;">
<div id="attachment_565" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/attachment/actionbarexampleinfo/" rel="attachment wp-att-565"><img class="size-medium wp-image-565" title="InfoActivity" src="http://www.samcoles.co.uk/uploads/actionbarexampleinfo-180x300.png" alt="InfoActivity" width="180" height="300" /></a><p class="wp-caption-text">InfoActivity</p></div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-use-greendroid-to-implement-an-actionbar/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Android: Simple Full Screen Image Viewer Activity</title>
		<link>http://www.samcoles.co.uk/mobile/android-simple-full-screen-image-viewer-activity/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-simple-full-screen-image-viewer-activity/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 09:12:06 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[ImageView]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=545</guid>
		<description><![CDATA[Here&#8217;s the code for a simple full screen ImageViewerActivity. It uses the SDImageLoader from this post to load the image asynchronously from the SD card. public class ImageViewerActivity extends Activity { public static final String IMAGE_PATH = "imagevieweractivityfilepath"; private final SDImageLoader mImageLoader = new SDImageLoader(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.imageviewer); Bundle extras [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the code for a simple full screen ImageViewerActivity. It uses <a title="SDImagerLoader" href="http://www.samcoles.co.uk/mobile/android-asynchronously-load-image-from-sd-card/">the SDImageLoader from this post</a> to load the image asynchronously from the SD card.</p>
<pre class="brush:java">public class ImageViewerActivity extends Activity {

	public static final String IMAGE_PATH = "imagevieweractivityfilepath";

	private final SDImageLoader mImageLoader = new SDImageLoader();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.imageviewer);
		Bundle extras = getIntent().getExtras();
		if(extras != null) {
			String imagePath = extras.getString(IMAGE_PATH);
			if(imagePath != null) {
				ImageView i = (ImageView)findViewById(R.id.image_viewer_image);
				mImageLoader.load(this, imagePath, i);
			}
		}
	}

}</pre>
<p>Here&#8217;s an example of how to use this activity:</p>
<pre class="brush:java">//load the filepath from the database
Cursor c = mDbHelper.fetchCapture(info.id);
String filePath = c.getString(c.getColumnIndexOrThrow(SpecimenHunterDatabaseAdapter.KEY_CAPTURES_PHOTO));
//create the new intent
Intent it = new Intent(this, ImageViewerActivity.class);
//put the filepath into the extras bundle
it.putExtra(ImageViewerActivity.IMAGE_PATH, filePath);
//start activity.
startActivity(it);</pre>
<p>Here&#8217;s the xml layout file. Use the src of the ImageView to set the image to use as a placeholder while the image you wish to display loads from the SD card.</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:layout_weight="1"
	android:layout_gravity="center"
	android:gravity="center"&gt;

	&lt;ImageView
		android:id="@+id/image_viewer_image"
		android:src="@drawable/thumbnail_placeholder"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent"
		android:adjustViewBounds="true"
		android:layout_gravity="center"
		android:gravity="center" /&gt;

&lt;/LinearLayout&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-simple-full-screen-image-viewer-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android: ‘Specimen Hunter’ &#8211; Fishing App for UK Coarse Anglers</title>
		<link>http://www.samcoles.co.uk/mobile/android-%e2%80%98specimen-hunter%e2%80%99-fishing-app-for-uk-coarse-anglers/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-%e2%80%98specimen-hunter%e2%80%99-fishing-app-for-uk-coarse-anglers/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 15:51:46 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[angling]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[barbel]]></category>
		<category><![CDATA[carp]]></category>
		<category><![CDATA[fishing]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=466</guid>
		<description><![CDATA[A short while back I built an Android app for UK (&#38; European) Coarse Anglers. More recently I&#8217;ve had it tarted up with some nice graphics by Olie Kay and pushed it to the Android Market. The current fish capture logging apps that are out there for Android quite admirably try to achieve &#8216;the kitchen [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://market.android.com/details?id=com.samcoles.specimenhunter"><img src="http://www.android.com/images/brand/60_avail_market_logo2.png" alt="Available in Android Market" /><br />
</a></p>
<p>A short while back I built an Android app for UK (&amp; European) Coarse Anglers. More recently I&#8217;ve had it tarted up with some nice graphics by <a title="OlieKay.com" href="http://www.oliekay.com" target="_blank">Olie Kay</a> and pushed it to the Android Market.</p>
<p>The current fish capture logging apps that are out there for Android quite admirably try to achieve &#8216;the kitchen sink&#8217;, but end up being quite heavy and difficult to use. <em>Specimen Hunter</em> aims to simplify things and focuses on your targets and tracking personal bests.</p>
<p>Please check out the app and see what you think. It&#8217;s free &#8211; if you like it, you can offer your support simply by rating it or reccomending it to friends. It&#8217;s actively being developed, so if you have any suggestions, feature requests or spot any bugs please leave a comment on this post, or contact me via email or <a title="@SamColes" href="http://www.twitter.com/samcoles">twitter</a> and I&#8217;ll get back to you ASAP.</p>
<p><strong style="display: block; padding-top: 20px;">Features:</strong></p>
<ul>
<li>Set yourself specimen targets</li>
<li>Log your specimen captures</li>
<li>Review and sort your logged captures</li>
<li>Automatically review all your personal bests</li>
<li>Share info with other apps (email/twitter etc.)</li>
<li>Post your captures to your facebook wall from within the app</li>
<li>Active development &#8211; contact the dev with your ideas and suggestions!</li>
</ul>
<p>&nbsp;</p>
<h4></h4>
<h4></h4>
<h4><a title="Download and Install Specimen Hunter" href="https://market.android.com/details?id=com.samcoles.specimenhunter" target="_blank">Click here to install <em>Specimen Hunter</em></a>.</h4>
<p>&nbsp;</p>
<div>
<div style="float: left; padding-right: 10px;">
<div id="attachment_468" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/android-%e2%80%98specimen-hunter%e2%80%99-fishing-app-for-uk-coarse-anglers/attachment/dashboarda/" rel="attachment wp-att-468"><img class="size-medium wp-image-468" title="dashboarda" src="http://www.samcoles.co.uk/uploads/dashboarda-180x300.png" alt="Specimen Hunter Dashboard" width="180" height="300" /></a><p class="wp-caption-text">Specimen Hunter Dashboard</p></div>
</div>
<div style="float: left; padding-right: 10px;">
<div id="attachment_488" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/android-%e2%80%98specimen-hunter%e2%80%99-fishing-app-for-uk-coarse-anglers/attachment/targets/" rel="attachment wp-att-488"><img class="size-medium wp-image-488" title="Specimen Hunter Targets" src="http://www.samcoles.co.uk/uploads/Targets-180x300.png" alt="Specimen Hunter Targets" width="180" height="300" /></a><p class="wp-caption-text">Specimen Hunter Targets</p></div>
</div>
<div style="float: left; padding-right: 5px;">
<div id="attachment_489" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/android-%e2%80%98specimen-hunter%e2%80%99-fishing-app-for-uk-coarse-anglers/attachment/personalbests/" rel="attachment wp-att-489"><img class="size-medium wp-image-489" title="Specimen Hunter Personal Bests" src="http://www.samcoles.co.uk/uploads/PersonalBests-180x300.png" alt="Specimen Hunter Personal Bests" width="180" height="300" /></a><p class="wp-caption-text">Specimen Hunter Personal Bests</p></div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-%e2%80%98specimen-hunter%e2%80%99-fishing-app-for-uk-coarse-anglers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android: Using a custom font</title>
		<link>http://www.samcoles.co.uk/mobile/android-using-a-custom-font/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-using-a-custom-font/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 13:37:54 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[font]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=456</guid>
		<description><![CDATA[Can you set a custom font from XML? As far as I&#8217;ve managed to find, the answer is no. So instead, how do you do this programatically? First start by creating an &#8216;assets&#8217; folder in your project, within this create a folder called &#8216;fonts&#8217;. &#8216;assets&#8217; should be on the same level as &#8216;res&#8217; and not [...]]]></description>
			<content:encoded><![CDATA[<p>Can you set a custom font from XML? As far as I&#8217;ve managed to find, the answer is no.</p>
<p>So instead, how do you do this programatically?</p>
<p>First start by creating an &#8216;assets&#8217; folder in your project, within this create a folder called &#8216;fonts&#8217;. &#8216;assets&#8217; should be on the same level as &#8216;res&#8217; and not within it. Drag your font file in here. Need a font? Lots of free, open source ones available here: <a title="http://www.google.com/webfonts/v2" href="http://www.google.com/webfonts/v2">http://www.google.com/webfonts/v2</a>.</p>
<p>Setting the font on a <span style="color: #888888;">View</span> couldn&#8217;t be simpler, here&#8217;s an example using the Lobster font from Google webfonts</p>
<pre class="brush:java">TextView someTextView = (TextView)findViewById(R.id.some_text_view_id);

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Lobster.ttf");
someTextView.setTypeface(tf);</pre>
<p>If needing to set the font in a list item, I load the font to a member variable within the constructor of my <span style="color: #888888;">ListAdapter</span> so that it can be used in my overridden <span style="color: #888888;">newView()</span> rather than loading it every time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-using-a-custom-font/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android: Retain values on orientation change</title>
		<link>http://www.samcoles.co.uk/mobile/android-retain-values-on-orientation-change/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-retain-values-on-orientation-change/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 09:31:17 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[onRetainNonConfigurationInstance()]]></category>
		<category><![CDATA[Orientation]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=448</guid>
		<description><![CDATA[When you change the orientation of your phone. The current activity is destroyed via onDestroy() and then recreated with onCreate() being called. This presented a problem for me with a list that has different ways of sorting &#8211; I wanted this sorted order to persist while the current activity was open, but there was no [...]]]></description>
			<content:encoded><![CDATA[<p>When you change the orientation of your phone. The current activity is destroyed via <span style="color: #888888;">onDestroy()</span> and then recreated with <span style="color: #888888;">onCreate()</span> being called. This presented a problem for me with a list that has different ways of sorting &#8211; I wanted this sorted order to persist while the current activity was open, but there was no need for it to do so when coming to the activity again. Here&#8217;s a quick demonstration of how to achieve this.</p>
<p>The type of sort to do is stored in a member variable. This uses constants from my Database Adapter class. When the data is pulled from the database, this sort code is passed in and used by the DB Adapter, data is returned sorted correctly. When the phone&#8217;s orientation is changed we want the list to remain sorted in the same order.</p>
<pre class="brush:java">private Integer mListSortCode;</pre>
<p>Next in your activity, override <span style="color: #888888;">onRetainNonConfigurationInstance()</span>. This method is called just before <span style="color: #888888;">onDestroy()</span>. In my example I need only one value so I made the mListSortCode an Integer object. It&#8217;s easy to see how you could create an inner class that would hold all the data you need to retain and use it here.</p>
<pre class="brush:java">@Override
public Object onRetainNonConfigurationInstance() {
    final Integer sortcode = mListSortCode;
    return sortcode;
}</pre>
<p>In your <span style="color: #888888;">onCreate()</span> method call <span style="color: #888888;">getLastNonConfigurationInstance()</span> to get a reference to this object and cast it to the correct type. If <span style="color: #888888;">onCreate()</span> is being called because of any reason other than an orientation change it will be null, so check for this and handle appropriately:</p>
<pre class="brush:java">final Integer previousConfigSortCode = (Integer)getLastNonConfigurationInstance();
if (previousConfigSortCode != null) {
    mListSortCode = previousConfigSortCode;
} else {
    //set to default
    mListSortCode = SpecimenHunterDatabaseAdapter.SORT_NONE;
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-retain-values-on-orientation-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android: populate a Spinner from a SQLite database</title>
		<link>http://www.samcoles.co.uk/mobile/android-populate-a-spinner-from-your-sqlite-database/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-populate-a-spinner-from-your-sqlite-database/#comments</comments>
		<pubDate>Tue, 24 May 2011 09:56:48 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Cursor]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[SimpleCursorAdapter]]></category>
		<category><![CDATA[Spinner]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=430</guid>
		<description><![CDATA[Here&#8217;s a bit of code to populate a spinner with data from a database. The database table contains info about all the different species of fish within my app. I want the user to choose the species from the spinner and then the ID of that species is then stored as a foreign key within [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a bit of code to populate a spinner with data from a database. The database table contains info about all the different species of fish within my app. I want the user to choose the species from the spinner and then the ID of that species is then stored as a foreign key within my &#8216;captures&#8217; table.</p>
<p>First start by defining the spinner in your xml layout, here&#8217;s the example from my layout:</p>
<pre class="brush:xml">&lt;Spinner
    android:id="@+id/spinner_species"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:prompt="@string/addcapture_species_prompt" /&gt;</pre>
<p>From your Activity, within your <span style="color: #888888;">onCreate()</span> method, get a reference to the spinner and a <span style="color: #888888;">Cursor</span> to all your species from your database. Pass your cursor into <span style="color: #888888;">startManagingCursor()</span> to let your <span style="color: #888888;">Activity</span> take care of it:</p>
<pre class="brush:java">Spinner speciesSpinner = (Spinner)findViewById(R.id.spinner_species);
Cursor speciesCursor = mDbAdapter.fetchAllSpecies();
startManagingCursor(speciesCursor);</pre>
<p>Create a <span style="color: #888888;">SimpleCursorAdapter</span> to bind the text you want to be displayed on your spinner to the textview display on your spinner and set this to the spinner. SpecimenHunterDatabaseAdapter.KEY_SPECIES_NAME is a String constant of the name of the column in my database containing the name. <span style="color: #888888;">android.R.layout.simple_spinner_item</span> is a predefined Android layout for the spinner and <span style="color: #888888;">android.R.id.text1</span> is the textview defined within this. <span style="color: #888888;">android.R.layout.simple_spinner_dropdown_item</span> is our layout for the items in the menu that appears when you tap the spinner.</p>
<pre class="brush:java">String[] from = new String[] { SpecimenHunterDatabaseAdapter.KEY_SPECIES_NAME };
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter speciesSpinnerAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, speciesCursor, from, to);
speciesSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
speciesSpinner.setAdapter(speciesSpinnerAdapter);</pre>
<p>When the user selects an option on the spinner, we need store that somewhere. Create a member in your <span style="color: #888888;">Activity</span> to hold the value:</p>
<pre class="brush:java">private int mSpinnerSpeciesId;</pre>
<p>Lastly, back in your <span style="color: #888888;">onCreate()</span> method below the call to <span style="color: #888888;">setAdapter()</span> we need to attach an <span style="color: #888888;">OnItemSelectedListener</span> to the spinner. The method <span style="color: #888888;">onItemSelected()</span> will be called when the selected item on the spinner changes &#8211; it&#8217;s also called when your activity starts with the first value on the spinner&#8217;s list.</p>
<pre class="brush:java">speciesSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) {
        Cursor c = (Cursor)parent.getItemAtPosition(pos);
        mSpinnerSpeciesId = c.getInt(c.getColumnIndexOrThrow(SpecimenHunterDatabaseAdapter.KEY_SPECIES_ROWID));
    }
    @Override
        public void onNothingSelected(AdapterView&lt;?&gt; parent) {
    }
});</pre>
<p>Here&#8217;s the spinner in action after being pressed:</p>
<div id="attachment_431" class="wp-caption alignnone" style="width: 190px"><a rel="attachment wp-att-431" href="http://www.samcoles.co.uk/mobile/android-populate-a-spinner-from-your-sqlite-database/attachment/spinnerinaction/"><img class="size-medium wp-image-431" title="Spinner In Action" src="http://www.samcoles.co.uk/uploads/SpinnerInAction-180x300.png" alt="Spinner In Action" width="180" height="300" /></a><p class="wp-caption-text">Spinner In Action</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-populate-a-spinner-from-your-sqlite-database/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Android: Asynchronously Load Image from SD card</title>
		<link>http://www.samcoles.co.uk/mobile/android-asynchronously-load-image-from-sd-card/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-asynchronously-load-image-from-sd-card/#comments</comments>
		<pubDate>Sun, 22 May 2011 14:18:55 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[AsyncTask]]></category>
		<category><![CDATA[ImageView]]></category>
		<category><![CDATA[ListActivity]]></category>
		<category><![CDATA[ListView]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=416</guid>
		<description><![CDATA[Trying to load images from the SD card into my listview within the UI thread (directly in bindView())made scrolling the listview very jerky and slow &#8211; it worked but was barely acceptable. My initial attempt at asynchronously loading the images from the SD card ran into a bit of a problem when I discovered that [...]]]></description>
			<content:encoded><![CDATA[<p>Trying to load images from the SD card into my listview within the UI thread (directly in <span style="color: #888888;">bindView()</span>)made scrolling the listview very jerky and slow &#8211; it worked but was barely acceptable. My initial attempt at asynchronously loading the images from the SD card ran into a bit of a problem when I discovered that the Views for each row on a list are reused when they go off screen as initialising the Views is a costly process. This meant with the way I&#8217;d written my code that quickly scrolling the list would cause the ImageView to flicker between all the other images I&#8217;d loaded into it before settling on the final one. This is because all the <span style="color: #888888;">AsyncTask</span>s that&#8217;d been created were yet to finish and calling <span style="color: #888888;">onPostExecute()</span> binding the view before a new one was created!</p>
<p>So I looked into how to solve this problem. The code/tutorial in the post, <a title="Multithreading For Performance" href="http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html">Multithreading For Performance</a> on the Android Developer blog, asynchronously downloads/binds an image from the Internet. I&#8217;ve adapted this to load the image from the SD card. Here&#8217;s my class, <span style="color: #888888;">SDImageLoader</span>:</p>
<pre class="brush:java">package com.samcoles.specimenhunter.ui;

import java.lang.ref.WeakReference;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.widget.ImageView;

public class SDImageLoader {

	public void load(String filePath, ImageView v) {
		if(cancelPotentialSDLoad(filePath, v)) {
			SDLoadImageTask task = new SDLoadImageTask(v);
			SDLoadDrawable sdDrawable = new SDLoadDrawable(task);
			v.setImageDrawable(sdDrawable);
			task.execute(filePath);
		}
	}

	private Bitmap loadImageFromSDCard(String filePath) {

		BitmapFactory.Options bfo = new BitmapFactory.Options();
        bfo.inSampleSize = 4;
        bfo.outWidth = 150;
        bfo.outHeight = 150;
		Bitmap photo = BitmapFactory.decodeFile(filePath, bfo);
		return photo;
	} 

	private static boolean cancelPotentialSDLoad(String filePath, ImageView v) {
		SDLoadImageTask sdLoadTask = getAsyncSDLoadImageTask(v);

		if(sdLoadTask != null) {
			String path = sdLoadTask.getFilePath();
			if((path == null) || (!path.equals(filePath))) {
				sdLoadTask.cancel(true);
			} else {
				return false;
			}
		}
		return true;
	}

	private static SDLoadImageTask getAsyncSDLoadImageTask(ImageView v) {
		if(v != null) {
			Drawable drawable = v.getDrawable();
			if(drawable instanceof SDLoadDrawable) {
				SDLoadDrawable asyncLoadedDrawable = (SDLoadDrawable)drawable;
				return asyncLoadedDrawable.getAsyncSDLoadTask();
			}
		}
		return null;
	}

	private class SDLoadImageTask extends AsyncTask&lt;String, Void, Bitmap&gt; {

		private String mFilePath;
		private final WeakReference&lt;ImageView&gt; mImageViewReference;

		public String getFilePath() {
			return mFilePath;
		}

		public SDLoadImageTask(ImageView v) {
			mImageViewReference = new WeakReference&lt;ImageView&gt;(v);
		}

		@Override
		protected void onPostExecute(Bitmap bmp) {
			if(mImageViewReference != null) {
				ImageView v = mImageViewReference.get();
				SDLoadImageTask sdLoadTask = getAsyncSDLoadImageTask(v);
				// Change bitmap only if this process is still associated with it
				if(this == sdLoadTask) {
					v.setImageBitmap(bmp);
				}
			}
		}

		@Override
		protected Bitmap doInBackground(String... params) {
			mFilePath = params[0];
			return loadImageFromSDCard(mFilePath);
		}
	}

	private class SDLoadDrawable extends ColorDrawable {
		private final WeakReference&lt;SDLoadImageTask&gt; asyncSDLoadTaskReference;

		public SDLoadDrawable(SDLoadImageTask asyncSDLoadTask) {
			super(Color.BLACK);
			asyncSDLoadTaskReference = new WeakReference&lt;SDLoadImageTask&gt;(asyncSDLoadTask);
		}

		public SDLoadImageTask getAsyncSDLoadTask() {
			return asyncSDLoadTaskReference.get();
		}

	}
}</pre>
<p>To use this, within your list adapter create an <span style="color: #888888;">SDImageLoader</span> as a member:</p>
<pre class="brush:java">private final SDImageLoader mImageLoader = new SDImageLoader();</pre>
<p>and within your overridden <span style="color: #888888;">bindView()</span> method simply call the method load, passing it a string representing the absolute filepath and the <span style="color: #888888;">ImageView </span>you want it to be loaded into. e.g.</p>
<pre class="brush:java">mImageLoader.load(photoFilePath, photoView);</pre>
<p>Here&#8217;s that in action:</p>
<div id="attachment_417" class="wp-caption alignnone" style="width: 190px"><a href="http://www.samcoles.co.uk/mobile/android-asynchronously-load-image-from-sd-card/attachment/asyncimageviewlistview/" rel="attachment wp-att-417"><img class="size-medium wp-image-417" title="Asynchronously Loaded Images in ListView" src="http://www.samcoles.co.uk/uploads/AsyncImageViewListView-180x300.png" alt="Asynchronously Loaded Images in ListView" width="180" height="300" /></a><p class="wp-caption-text">Asynchronously Loaded Images in ListView</p></div>
<p>A working example project based on this post can be found on <a href="https://github.com/SamColes/Android-Samples/tree/master/AsyncSDCardImageLoaderExample">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-asynchronously-load-image-from-sd-card/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Android: Lock and unlock screen orientation</title>
		<link>http://www.samcoles.co.uk/mobile/android-lock-and-unlock-screen-orientation/</link>
		<comments>http://www.samcoles.co.uk/mobile/android-lock-and-unlock-screen-orientation/#comments</comments>
		<pubDate>Fri, 20 May 2011 11:29:49 +0000</pubDate>
		<dc:creator>Sam Coles</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Orientation]]></category>

		<guid isPermaLink="false">http://www.samcoles.co.uk/?p=413</guid>
		<description><![CDATA[Need to temporarily lock the screen orientation on your app? When calling setRequestedOrientation() on your activity, it will no longer allow the orientation to change even when the phone is rotated. So check what the current orientation of the screen is and set it to the same orientation with setRequestedOrientation() public static void lockCurrentScreenOrientation(Activity a) [...]]]></description>
			<content:encoded><![CDATA[<p>Need to temporarily lock the screen orientation on your app? When calling <span style="color: #888888;">setRequestedOrientation()</span> on your activity, it will no longer allow the orientation to change even when the phone is rotated. So check what the current orientation of the screen is and set it to the same orientation with <span style="color: #888888;">setRequestedOrientation()<br />
</span></p>
<pre class="brush:java">public static void lockCurrentScreenOrientation(Activity a) {

	if(a.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
		a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	} else {
		a.setRequestedOrientation(a.getRequestedOrientation());
	}
}</pre>
<p>To unlock it again, pass <span style="color: #888888;">ActivityInfo.SCREEN_ORIENTATION_USER</span>:</p>
<pre class="brush:java">public static void unlockScreenOrientation(Activity a) {
	a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.samcoles.co.uk/mobile/android-lock-and-unlock-screen-orientation/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

