<?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>Charles Harley</title>
	<atom:link href="http://www.charlesharley.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.charlesharley.com</link>
	<description>Sharing is caring</description>
	<lastBuildDate>Sun, 03 Mar 2013 16:01:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F&amp;language=en_US&amp;category=text&amp;title=Charles+Harley&amp;description=Sharing+is+caring&amp;tags=blog" type="text/html" />
		<item>
		<title>Getting Xcode static libraries to work</title>
		<link>http://www.charlesharley.com/2013/programming/getting-xcode-static-libraries-to-work/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-xcode-static-libraries-to-work</link>
		<comments>http://www.charlesharley.com/2013/programming/getting-xcode-static-libraries-to-work/#comments</comments>
		<pubDate>Sun, 03 Mar 2013 16:01:17 +0000</pubDate>
		<dc:creator>bigboss</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=210</guid>
		<description><![CDATA[Getting Xcode static library dependencies to work is way harder than it should be! This weekend I setup a new Xcode OS X workspace with 2 child projects. One project was the app and the other a static library used by the app. Setting the static library as a dependency of the app project took [...]]]></description>
				<content:encoded><![CDATA[<p>Getting Xcode static library dependencies to work is way harder than it should be! This weekend I setup a new Xcode OS X workspace with 2 child projects. One project was the app and the other a static library used by the app. Setting the static library as a dependency of the app project took ages. Part of the reason was my lack of knowledge but Xcode should really give a bit more help.</p>
<p>Anyway, for the good of the people here are 2 blog posts I found helpful. I was using Xcode 4.6.</p>
<p><a href="http://blog.stevex.net/2012/04/static-libraries-in-xcode">http://blog.stevex.net/2012/04/static-libraries-in-xcode</a> &#8211; I found this the most useful for setting up the dependency, however steps 10 to 16 weren&#8217;t needed for Xcode 4.6. Probably because Apple fixed a bug.</p>
<p><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4">http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4</a> &#8211; The instructions for setting up a dependency didn&#8217;t quite work for some reason. However, the section on creating a static library is useful.</p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=210&amp;md5=ed83d200e105ce338a1cfeeb92514676" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2013/programming/getting-xcode-static-libraries-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2013%2Fprogramming%2Fgetting-xcode-static-libraries-to-work%2F&amp;language=en_GB&amp;category=text&amp;title=Getting+Xcode+static+libraries+to+work&amp;description=Getting+Xcode+static+library+dependencies+to+work+is+way+harder+than+it+should+be%21+This+weekend+I+setup+a+new+Xcode+OS+X+workspace+with+2+child+projects.+One+project...&amp;tags=xcode%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Using AndroVM</title>
		<link>http://www.charlesharley.com/2013/programming/using-androvm/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-androvm</link>
		<comments>http://www.charlesharley.com/2013/programming/using-androvm/#comments</comments>
		<pubDate>Mon, 14 Jan 2013 10:30:31 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=202</guid>
		<description><![CDATA[AndroVM is a novel alternative to the Android emulator with Android running in a virtual machine (VM) using VirtualBox. It works quite well and for some requirements can be significantly faster than the Android emulator. Installing and setting up is as simple as installing VirtualBox and importing the Android VirtualBox images available here. To debug [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://androvm.org/">AndroVM</a> is a novel alternative to the Android emulator with Android running in a virtual machine (VM) using VirtualBox. It works quite well and for some requirements can be significantly faster than the Android emulator.</p>
<p>Installing and setting up is as simple as installing VirtualBox and importing the Android VirtualBox images available <a href="http://androvm.org/blog/download/">here</a>.</p>
<p>To debug and install your apps using adb:</p>
<ol>
<li>Get the IP address of the VM from the AndroVM Config app running in the VM. If the app doesn&#8217;t show an IP address make sure you&#8217;ve created a host only network in the VirtualBox preferences and configured the VM to use that host only adapter as &#8220;Adapter 1&#8243;.</li>
<li>Execute &#8216;adb connect &lt;IP address&gt;&#8217;</li>
<li>From this point the standard adb commands (such as &#8216;adb install&#8217;) should work.</li>
</ol>
<p>AndroVM is still in it&#8217;s infancy and as such does have a few bigger limitations:</p>
<ul>
<li>Only Android 4.1 images are available.</li>
<li>The available screen resolutions are limited but can be easily selected using the AndroVM Config app running in the VM.</li>
</ul>
<p>On the plus side, the team behind AndroVM have promised configuration management software to make it easier to create and run different Android configurations. Additionally the software will also automatically connect adb with the VM.</p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=202&amp;md5=7774e10f9b495da07d625a80231b21e1" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2013/programming/using-androvm/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2013%2Fprogramming%2Fusing-androvm%2F&amp;language=en_GB&amp;category=text&amp;title=Using+AndroVM&amp;description=AndroVM+is+a+novel+alternative+to+the+Android+emulator+with+Android+running+in+a+virtual+machine+%28VM%29+using+VirtualBox.+It+works+quite+well+and+for+some+requirements+can+be+significantly...&amp;tags=android%2Cmobile%2Cblog" type="text/html" />
	</item>
		<item>
		<title>UIButton in UITableViewCell has no highlight state</title>
		<link>http://www.charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uibutton-in-uitableviewcell-has-no-highlight-state</link>
		<comments>http://www.charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state/#comments</comments>
		<pubDate>Tue, 08 Jan 2013 19:18:49 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=195</guid>
		<description><![CDATA[I recently created a custom UITableViewCell with a UIButton as a subview. Pretty standard except that the highlight state of the button was only activated if you held your finger on the button for more than some fraction of a second. The solution is quite straight forward but is subtle enough to justify a quick [...]]]></description>
				<content:encoded><![CDATA[<p>I recently created a custom UITableViewCell with a UIButton as a subview. Pretty standard except that the highlight state of the button was only activated if you held your finger on the button for more than some fraction of a second. The solution is quite straight forward but is subtle enough to justify a quick blog post.<span id="more-195"></span></p>
<p>Table view cells are displayed using a UITableView which is a subclass of UIScrollView and as such inherits the ability to scroll. A scroll view intercepts touch events and has a short delay to check if the touch event is part of a scroll gesture. If it isn&#8217;t then the touch event is passed onto the corresponding view. That explains the delay in the button highlight state.</p>
<p>We can remove the delay by setting UIScrollView.delaysContentTouches to NO. A side effect of this change is that scroll gestures cannot start from the buttons. Depending on how big your buttons are this might not be ideal. The work around for this is to override the (BOOL)touchesShouldCancelInContentView:(UIView *)view method in your UITableView subclass like so:</p>
<pre class="brush: c; gutter: true">- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    // Because we set delaysContentTouches = NO, we return YES for UIButtons 
    // so that scrolling works correctly when the scroll gesture 
    // starts in the UIButtons.
    if ([view isKindOfClass:[UIButton class]]) {
        return YES;
    }

    return [super touchesShouldCancelInContentView:view];
}</pre>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=195&amp;md5=f2d99016d83b689ea6f79c94b539ff2e" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2013%2Fprogramming%2Fuibutton-in-uitableviewcell-has-no-highlight-state%2F&amp;language=en_GB&amp;category=text&amp;title=UIButton+in+UITableViewCell+has+no+highlight+state&amp;description=I+recently+created+a+custom+UITableViewCell+with+a+UIButton+as+a+subview.+Pretty+standard+except+that+the+highlight+state+of+the+button+was+only+activated+if+you+held+your+finger...&amp;tags=ios%2Cmobile%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Custom drawable states in Android</title>
		<link>http://www.charlesharley.com/2012/programming/custom-drawable-states-in-android/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=custom-drawable-states-in-android</link>
		<comments>http://www.charlesharley.com/2012/programming/custom-drawable-states-in-android/#comments</comments>
		<pubDate>Thu, 07 Jun 2012 21:24:36 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=139</guid>
		<description><![CDATA[A state list drawable is a really useful Android resource for displaying different drawables for a view depending on the state of that view. e.g. we can define a state list drawable for the background of a button that defines a colour for both pressed and unpressed states. The button takes care of switching between [...]]]></description>
				<content:encoded><![CDATA[<p>A <a href="http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList">state list drawable</a> is a really useful Android resource for displaying different drawables for a view depending on the state of that view. e.g. we can define a state list drawable for the background of a button that defines a colour for both pressed and unpressed states. The button takes care of switching between the two drawables depending on the state, saving us the effort.</p>
<p>You can make state list drawables even more useful by defining custom states.<span id="more-139"></span></p>
<p>This is a screenshot of a hypothetical email client, notice the difference between read and unread messages.</p>
<p><a href="http://www.charlesharley.com/wp-content/uploads/2012/06/custom_drawable_states_screenshot1.png"><img class=" wp-image-145 alignnone" title="Custom drawable states screenshot" src="http://www.charlesharley.com/wp-content/uploads/2012/06/custom_drawable_states_screenshot1.png" alt="Custom drawable states screenshot" width="240" height="400" /></a></p>
<p>The recommended implementation for a screen like this would be to use a <a href="http://developer.android.com/reference/android/widget/ListView.html">ListView</a>. In this example, each item in the list is a <a href="http://developer.android.com/reference/android/widget/RelativeLayout.html">RelativeLayout</a> containing an <a href="http://developer.android.com/reference/android/widget/ImageView.html">ImageView</a> and a <a href="http://developer.android.com/reference/android/widget/TextView.html">TextView</a>. When displaying each item you could manually switch between the two images used and set the background colour accordingly. However, by defining a custom state you can make it simpler and easier to maintain.</p>
<h2>Step 1: declare the custom state attribute</h2>
<p>The custom state is declared in the &#8216;attrs.xml&#8217; file in the application&#8217;s &#8216;res/values&#8217; directory.</p>
<pre class="brush: xml; gutter: true">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;

    &lt;declare-styleable name=&quot;MessageState&quot;&gt;
        &lt;attr name=&quot;state_message_unread&quot; format=&quot;boolean&quot;/&gt;
    &lt;/declare-styleable&gt;

&lt;/resources&gt;</pre>
<h2>Step 2: use the custom state in the state list drawables</h2>
<p>In the message list example there are two state list drawables.</p>
<p>One for the list item background:</p>
<pre class="brush: xml; gutter: true">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
          xmlns:example=&quot;http://schemas.android.com/apk/res/com.charlesharley.example.android.customdrawablestates&quot;
          &gt;

    &lt;!--
    We make the pressed and focused selector items transparent so the ListView&#039;s own selector states show through.
    --&gt;

    &lt;item android:state_pressed=&quot;true&quot;
          android:drawable=&quot;@android:color/transparent&quot;
          /&gt;

    &lt;item android:state_focused=&quot;true&quot;
          android:drawable=&quot;@android:color/transparent&quot;
          /&gt;

    &lt;item example:state_message_unread=&quot;true&quot;
          android:drawable=&quot;@color/message_list_item_background_unread&quot;
          /&gt;

&lt;/selector&gt;</pre>
<p>And one for the message status icon:</p>
<pre class="brush: xml; gutter: true">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
          xmlns:example=&quot;http://schemas.android.com/apk/res/com.charlesharley.example.android.customdrawablestates&quot;
          android:constantSize=&quot;true&quot;
          &gt;

    &lt;item example:state_message_unread=&quot;true&quot;
          android:drawable=&quot;@drawable/message_read_status_unread&quot;
          /&gt;

    &lt;item android:drawable=&quot;@drawable/message_read_status_read&quot; /&gt;

&lt;/selector&gt;</pre>
<p>To use the custom state all you need to do is declare a new XML namespace using your application&#8217;s package name and prefix the custom state attribute with the new namespace.</p>
<h2>Step 3: update the view&#8217;s drawable state to include the custom state</h2>
<p>Each view provides a number of existing states that can be used by its drawables where applicable, e.g. a <a href="http://developer.android.com/reference/android/widget/CheckBox.html">CheckBox</a> has a checked state. By overriding <a href="http://developer.android.com/reference/android/view/View.html#onCreateDrawableState(int)">View.onCreateDrawableState()</a> a custom view can inject its own states, which are then made available to the view&#8217;s drawables.</p>
<p>In the message list example, the relative layout that contains the image view and the text view is a custom implementation that maintains an unread state, which when set, updates the view&#8217;s drawable states resulting in the different look for read and unread messages.</p>
<pre class="brush: java; gutter: true">public class MessageListItemView extends RelativeLayout {

    private static final int[] STATE_MESSAGE_UNREAD = {R.attr.state_message_unread};

    private boolean messageUnread;

    // Constructors, view loading etc...

    @Override
    protected int[] onCreateDrawableState(int extraSpace) {
        // If the message is unread then we merge our custom message unread state into
        // the existing drawable state before returning it.
        if (messageUnread) {
            // We are going to add 1 extra state.
            final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);

            mergeDrawableStates(drawableState, STATE_MESSAGE_UNREAD);

            return drawableState;
        } else {
            return super.onCreateDrawableState(extraSpace);
        }
    }

    public void setMessageUnread(boolean messageUnread) {
        if (this.messageUnread != messageUnread) {
            this.messageUnread = messageUnread;

            // Refresh the drawable state so that it includes the message unread
            // state if required.
            refreshDrawableState();
        }
    }

}</pre>
<p>What about the message status image view? Good question! Because the image view is a child of our custom view we tell it to duplicate its parent state using <a href="http://developer.android.com/reference/android/view/View.html#setDuplicateParentStateEnabled(boolean)">View.setDuplicateParentStateEnabled()</a>. Any state in the parent is passed down to the children including custom states. Brilliant!</p>
<p>The example Android application used for this tutorial is hosted <a href="https://github.com/CharlesHarley/Example-Android-CustomDrawableStates">here</a> on Github.</p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=139&amp;md5=407ad3936476665b14e089c3cf9a2a13" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2012/programming/custom-drawable-states-in-android/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2012%2Fprogramming%2Fcustom-drawable-states-in-android%2F&amp;language=en_GB&amp;category=text&amp;title=Custom+drawable+states+in+Android&amp;description=A+state+list+drawable+is+a+really+useful+Android+resource+for+displaying+different+drawables+for+a+view+depending+on+the+state+of+that+view.+e.g.+we+can+define+a+state...&amp;tags=android%2Cmobile%2Cui%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Tiny Stopwatch for Android</title>
		<link>http://www.charlesharley.com/2012/misc/tiny-stopwatch-for-android/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tiny-stopwatch-for-android</link>
		<comments>http://www.charlesharley.com/2012/misc/tiny-stopwatch-for-android/#comments</comments>
		<pubDate>Tue, 08 May 2012 22:59:18 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=93</guid>
		<description><![CDATA[Today I released my first personal Android app into the Google Play Store. It is a stopwatch app that supports multiple stopwatches and is designed to work across phones and tablets. It is also built from the ground up to fit in with the new design paradigms used in the latest versions of Android such [...]]]></description>
				<content:encoded><![CDATA[<p>Today I released my first personal Android app into the Google Play Store. It is a stopwatch app that supports multiple stopwatches and is designed to work across phones and tablets. It is also built from the ground up to fit in with the new design paradigms used in the latest versions of Android such as the action bar. I also just wanted a better looking stopwatch app.</p>
<p>Check it out here: <a href="https://play.google.com/store/apps/details?id=com.tinystopwatch.android">https://play.google.com/store/apps/details?id=com.tinystopwatch.android</a></p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=93&amp;md5=38da26805fd9f2a588c1170cb5d1634d" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2012/misc/tiny-stopwatch-for-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2012%2Fmisc%2Ftiny-stopwatch-for-android%2F&amp;language=en_GB&amp;category=text&amp;title=Tiny+Stopwatch+for+Android&amp;description=Today+I+released+my+first+personal+Android+app+into+the+Google+Play+Store.+It+is+a+stopwatch+app+that+supports+multiple+stopwatches+and+is+designed+to+work+across+phones+and...&amp;tags=android%2Cmobile%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Android screen utility class</title>
		<link>http://www.charlesharley.com/2012/programming/android-screen-utility-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-screen-utility-class</link>
		<comments>http://www.charlesharley.com/2012/programming/android-screen-utility-class/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 23:48:40 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=84</guid>
		<description><![CDATA[There are a few common operations I infrequently perform related to the Android screen: Converting a pixels value to the corresponding density independent pixels (DIP) value and vice versa Getting the screen dimensions Checking what orientation the device is in Getting the screen size (small, normal, large, extra-large) They&#8217;re not difficult but it is annoying [...]]]></description>
				<content:encoded><![CDATA[<p>There are a few common operations I infrequently perform related to the Android screen:</p>
<ul>
<li>Converting a pixels value to the corresponding density independent pixels (DIP) value and vice versa</li>
<li>Getting the screen dimensions</li>
<li>Checking what orientation the device is in</li>
<li>Getting the screen size (small, normal, large, extra-large)</li>
</ul>
<p>They&#8217;re not difficult but it is annoying having to remember exactly how they&#8217;re done so I created a utility class to make it a bit easier. Here it is:<span id="more-84"></span><br />
<script type="text/javascript" src="https://gist.github.com/2504204.js?file=ScreenUtils.java"></script></p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=84&amp;md5=c515461e6270f99d5998256d20bbefb6" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2012/programming/android-screen-utility-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2012%2Fprogramming%2Fandroid-screen-utility-class%2F&amp;language=en_GB&amp;category=text&amp;title=Android+screen+utility+class&amp;description=There+are+a+few+common+operations+I+infrequently+perform+related+to+the+Android+screen%3A+Converting+a+pixels+value+to+the+corresponding+density+independent+pixels+%28DIP%29+value+and+vice+versa+Getting...&amp;tags=android%2Cmobile%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Views saving instance state in Android</title>
		<link>http://www.charlesharley.com/2012/programming/views-saving-instance-state-in-android/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=views-saving-instance-state-in-android</link>
		<comments>http://www.charlesharley.com/2012/programming/views-saving-instance-state-in-android/#comments</comments>
		<pubDate>Sat, 03 Mar 2012 18:06:09 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=58</guid>
		<description><![CDATA[The activity lifecycle is central to Android development. Although it is quite well defined, it does take a bit of getting used to. One aspect new developers perhaps struggle with is that rotating the device will by default destroy and recreate the activity. A well behaved activity will restore its state after a rotation so [...]]]></description>
				<content:encoded><![CDATA[<p>The activity <a href="http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle">lifecycle</a> is central to Android development. Although it is quite well defined, it does take a bit of getting used to. One aspect new developers perhaps struggle with is that rotating the device will by default destroy and recreate the activity.</p>
<p>A well behaved activity will restore its state after a rotation so the user can continue using the application with no lose of state. e.g. <a href="http://developer.android.com/reference/android/widget/EditText.html">EditText</a> widgets should restore the text they contained when the device was rotated and a long running operation should resume without restarting.</p>
<p>There are a few topics to understand to achieve this effectively but one that I&#8217;d like to talk about is views saving and restoring their instance state. In most cases saving state is actually very simple but when creating compound views a couple extra steps are required. Compound views combine multiple views into a single convenient reusable view, e.g. the <a href="http://developer.android.com/reference/android/widget/NumberPicker.html">NumberPicker</a>.<span id="more-58"></span></p>
<h2>Saving individual views</h2>
<p>For individual views, saving instance state is as simple as defining a unique <a title="Android documentation on View IDs" href="http://developer.android.com/reference/android/view/View.html#attr_android:id">ID</a> for each view that you want to save its state. The activity will take care of the rest!</p>
<p>Note: IDs only need to be unique within the activity where they are used.</p>
<h2>How saving instance state works</h2>
<p>The instance state of each view within an activity is saved in shared persisted data with the state for each view referenced using the view&#8217;s ID. Hence why the IDs need to be unique.</p>
<p>To save state the activity traverses the layout hierarchy and for each view it encounters it calls <a href="http://developer.android.com/reference/android/view/View.html#saveHierarchyState(android.util.SparseArray&lt;android.os.Parcelable&gt;)">View.saveHierarchyState()</a> which in turn calls <a href="http://developer.android.com/reference/android/view/View.html#dispatchSaveInstanceState(android.util.SparseArray&lt;android.os.Parcelable&gt;)">View.dispatchSaveInstanceState()</a>. If the view has an ID this method calls <a href="http://developer.android.com/reference/android/view/View.html#onSaveInstanceState()">View.onSaveInstanceState()</a>, which saves its state to a <a href="http://developer.android.com/reference/android/os/Parcelable.html">Parcelable</a> object and returns it. View.dispatchSaveInstanceState() then takes the Parcelable and saves it to the shared persisted data using the ID of the view.</p>
<p>Restoring state is a very similar process with the activity traversing the layout hierarchy and for each view it calls <a href="http://developer.android.com/reference/android/view/View.html#restoreHierarchyState(android.util.SparseArray&lt;android.os.Parcelable&gt;)">View.restoreHierarchyState()</a> which in turn calls <a href="http://developer.android.com/reference/android/view/View.html#dispatchRestoreInstanceState(android.util.SparseArray&lt;android.os.Parcelable&gt;)">View.dispatchRestoreInstanceState()</a>. If the view has an ID this method retrieves the corresponding Parcelable from the shared persisted data and passes it through to <a href="http://developer.android.com/reference/android/view/View.html#onRestoreInstanceState(android.os.Parcelable)">View.onRestoreInstanceState()</a>, which then restores the view&#8217;s state.</p>
<p><a href="http://developer.android.com/reference/android/view/ViewGroup.html">ViewGroup</a>, which extends View, modifies the process slightly to pass the call to View.dispatchSaveInstanceState() onto its child views.</p>
<p>Simple really! <img src='http://www.charlesharley.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Saving compound views</h2>
<p>Saving instance state for compound views works in the same way as individual views but does require a little extra work when creating them to ensure that if an activity contains more than one instance of the same compound view, its state is correctly saved.</p>
<p>Compound views contain one or more child views and if an activity contains multiple instances of the same compound view then the IDs of the child views are no longer unique. To resolve this issue, the compound view class needs to take on the responsibility of saving and restoring the state of its child views.</p>
<p>To make it easier to understand I&#8217;ve created an example project that defines a compound view that correctly saves and restores the state of its child views. The project is hosted <a href="https://github.com/CharlesHarley/Example-Android-SavingInstanceState">here</a> on Github. The project contains various files to make the application work but if you want to skip to the important bit take a look at the <a href="https://github.com/CharlesHarley/Example-Android-SavingInstanceState/blob/master/src/com/example/android/savinginstancestate/views/LockCombinationPicker.java">LockCombinationPicker</a> class. It contains 4 overridden methods that ensure the state of the child views are correctly saved and restored.</p>
<pre class="brush: java; gutter: true">@Override
protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    return new SavedState(superState, numberPicker1.getValue(), numberPicker2.getValue(), numberPicker3.getValue());
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState) state;
    super.onRestoreInstanceState(savedState.getSuperState());

    numberPicker1.setValue(savedState.getNumber1());
    numberPicker2.setValue(savedState.getNumber2());
    numberPicker3.setValue(savedState.getNumber3());
}

@Override
protected void dispatchSaveInstanceState(SparseArray container) {
    super.dispatchFreezeSelfOnly(container);
}

@Override
protected void dispatchRestoreInstanceState(SparseArray container) {
    super.dispatchThawSelfOnly(container);
}</pre>
<p>LockCombinationPicker saves and restores the state of its children by overriding View.onSaveInstanceState() and View.onRestoreInstanceState() much as you would expect. In addition to this we need to ensure the compound view&#8217;s children aren&#8217;t then called to save their state as well. We do this by overriding View.dispatchSaveInstanceState() and View.dispatchRestoreInstanceState() and calling <a href="http://developer.android.com/reference/android/view/ViewGroup.html#dispatchFreezeSelfOnly(android.util.SparseArray&lt;android.os.Parcelable&gt;)">ViewGroup.dispatchFreezeSelfOnly()</a> and <a href="http://developer.android.com/reference/android/view/ViewGroup.html#dispatchThawSelfOnly(android.util.SparseArray&lt;android.os.Parcelable&gt;)">ViewGroup.dispatchThawSelfOnly()</a> respectively. These methods ensure that View.onSaveInstanceState() and View.onRestoreInstanceState() are called on the compound view class and not on the child views.</p>
<p>And that is it! To then save and restore the state of the compound view(s) within an activity just give it a unique ID.</p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=58&amp;md5=810d262d33244cd5cfda814f3a350b64" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2012/programming/views-saving-instance-state-in-android/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2012%2Fprogramming%2Fviews-saving-instance-state-in-android%2F&amp;language=en_GB&amp;category=text&amp;title=Views+saving+instance+state+in+Android&amp;description=The+activity+lifecycle+is+central+to+Android+development.+Although+it+is+quite+well+defined%2C+it+does+take+a+bit+of+getting+used+to.+One+aspect+new+developers+perhaps+struggle+with...&amp;tags=android%2Cmobile%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Android vs iOS development presentation</title>
		<link>http://www.charlesharley.com/2012/programming/android-vs-ios-development-presentation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-vs-ios-development-presentation</link>
		<comments>http://www.charlesharley.com/2012/programming/android-vs-ios-development-presentation/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 20:52:06 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[kotikan]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=51</guid>
		<description><![CDATA[Last week my colleague, Nick Street, and I gave an &#8216;Android vs iOS Development&#8217; presentation for Edinburgh Student Techmeetup on behalf of Kotikan. We only had about 25 minutes so didn&#8217;t go into too much depth. Was good fun and worth a watch just to find out who wins. Android v iOS App Development from [...]]]></description>
				<content:encoded><![CDATA[<p>Last week my colleague, Nick Street, and I gave an &#8216;Android vs iOS Development&#8217; presentation for Edinburgh Student Techmeetup on behalf of <a title="Kotikan" href="http://www.kotikan.com" target="_blank">Kotikan</a>. We only had about 25 minutes so didn&#8217;t go into too much depth. Was good fun and worth a watch just to find out who wins.</p>
<p><iframe src="http://player.vimeo.com/video/36492043?title=0&amp;byline=0&amp;portrait=0" frameborder="0" width="400" height="225"></iframe></p>
<p><a href="http://vimeo.com/36492043">Android v iOS App Development</a> from <a href="http://vimeo.com/kotikan">Kotikan</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=51&amp;md5=e99d0afa5f20ccc444a110d9cd6889fa" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2012/programming/android-vs-ios-development-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2012%2Fprogramming%2Fandroid-vs-ios-development-presentation%2F&amp;language=en_GB&amp;category=text&amp;title=Android+vs+iOS+development+presentation&amp;description=Last+week+my+colleague%2C+Nick+Street%2C+and+I+gave+an+%26%238216%3BAndroid+vs+iOS+Development%26%238217%3B+presentation+for+Edinburgh+Student+Techmeetup+on+behalf+of+Kotikan.+We+only+had+about+25+minutes+so...&amp;tags=android%2Cios%2Ckotikan%2Cmobile%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Book review: Application Security for the Android Platform</title>
		<link>http://www.charlesharley.com/2012/programming/book-review-application-security-android-platform/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=book-review-application-security-android-platform</link>
		<comments>http://www.charlesharley.com/2012/programming/book-review-application-security-android-platform/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 22:03:52 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=45</guid>
		<description><![CDATA[Just finished reading &#8216;Application Security for the Android Platform: Processes, Permissions, and Other Safeguards&#8217; by Jeff Six. The book is essentially a high level introduction to application security when programming for the Android platform but does go into sufficient depth to give you a decent understanding. It covers the following key topics: Risk assessment Android [...]]]></description>
				<content:encoded><![CDATA[<p>Just finished reading &#8216;Application Security for the Android Platform: Processes, Permissions, and Other Safeguards&#8217; by Jeff Six.</p>
<p><iframe src="http://rcm-uk.amazon.co.uk/e/cm?lt1=_blank&#038;bc1=E7E9EB&#038;IS2=1&#038;npa=1&#038;bg1=E7E9EB&#038;fc1=000000&#038;lc1=0000FF&#038;t=charharl-21&#038;o=2&#038;p=8&#038;l=as4&#038;m=amazon&#038;f=ifr&#038;ref=ss_til&#038;asins=1449315070" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
<p><span id="more-45"></span></p>
<p>The book is essentially a high level introduction to application security when programming for the Android platform but does go into sufficient depth to give you a decent understanding. It covers the following key topics:</p>
<ul>
<li>Risk assessment</li>
<li>Android permissions system</li>
<li>Storing data securely</li>
<li>Securing server communication</li>
</ul>
<p>Having studied computer science at university the last two key topics were familiar but it is amazing how much you forget! By far the most useful chapters were on the Android permissions systems. I don&#8217;t have sufficient knowledge on application security to properly review the book (hence why I bought it). However, at just under 100 pages it is a good introduction to the topic and very easy to read.</p>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=45&amp;md5=2f47ac44fda5557af67a32336d91d9cc" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2012/programming/book-review-application-security-android-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2012%2Fprogramming%2Fbook-review-application-security-android-platform%2F&amp;language=en_GB&amp;category=text&amp;title=Book+review%3A+Application+Security+for+the+Android+Platform&amp;description=Just+finished+reading+%26%238216%3BApplication+Security+for+the+Android+Platform%3A+Processes%2C+Permissions%2C+and+Other+Safeguards%26%238217%3B+by+Jeff+Six.+The+book+is+essentially+a+high+level+introduction+to+application+security+when+programming...&amp;tags=android%2Cbook%2Creview%2Csecurity%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Disabling Android TextView suggestions</title>
		<link>http://www.charlesharley.com/2011/programming/disabling-android-textview-suggestions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=disabling-android-textview-suggestions</link>
		<comments>http://www.charlesharley.com/2011/programming/disabling-android-textview-suggestions/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 23:36:06 +0000</pubDate>
		<dc:creator>charles</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.charlesharley.com/?p=19</guid>
		<description><![CDATA[Android TextViews provide suggestions to the user as they type. Although the user can disable this feature in the system settings there are cases where the developer wants to always have suggestions disabled for certain TextViews.  To achieve this, the documentation indicates that you should use: XML: &#60;TextView android:inputType="textNoSuggestions" /&#62; Java: TextView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) Annoyingly some HTC [...]]]></description>
				<content:encoded><![CDATA[<p>Android TextViews provide suggestions to the user as they type. Although the user can disable this feature in the system settings there are cases where the developer wants to always have suggestions disabled for certain TextViews. <span id="more-19"></span></p>
<p>To achieve this, the documentation indicates that you should use:</p>
<p>XML:</p>
<pre class="brush: xml; gutter: false; first-line: 1; highlight: []; html-script: false">&lt;TextView android:inputType="textNoSuggestions" /&gt;</pre>
<p>Java:</p>
<pre class="brush: java; gutter: false; first-line: 1; highlight: []; html-script: false">TextView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)</pre>
<p>Annoyingly some HTC devices ignore this option and so a common approach has been instead to use:</p>
<p>XML:</p>
<pre class="brush: xml; gutter: false; first-line: 1; highlight: []; html-script: false">&lt;TextView android:inputType="textVisiblePassword" /&gt;</pre>
<p>Java:</p>
<pre class="brush: java; gutter: false; first-line: 1; highlight: []; html-script: false">TextView.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)</pre>
<p>Although this does work, it will restrict the keyboard language on some HTC devices to English. A better approach, that appears to work across all devices, is:</p>
<p>XML:</p>
<pre class="brush: xml; gutter: false; first-line: 1; highlight: []; html-script: false">&lt;TextView android:inputType="textFilter" /&gt;</pre>
<p>Java:</p>
<pre class="brush: java; gutter: false; first-line: 1; highlight: []; html-script: false">TextView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER)</pre>
 <p><a href="http://www.charlesharley.com/?flattrss_redirect&amp;id=19&amp;md5=c4d40524d0d295cf61accd979e65e4ab" title="Flattr" target="_blank"><img src="http://www.charlesharley.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.charlesharley.com/2011/programming/disabling-android-textview-suggestions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=GeneralC&amp;popout=1&amp;url=http%3A%2F%2Fwww.charlesharley.com%2F2011%2Fprogramming%2Fdisabling-android-textview-suggestions%2F&amp;language=en_GB&amp;category=text&amp;title=Disabling+Android+TextView+suggestions&amp;description=Android+TextViews+provide+suggestions+to+the+user+as+they+type.+Although+the+user+can+disable+this+feature+in+the+system+settings+there+are+cases+where+the+developer+wants+to+always...&amp;tags=android%2Cmobile%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>
