Good Android development, heck good development, requires none ui blocking interactions.

As part of that (I can’t take credit, I think Dorian Cussen came up with the original idea) I have a nice Java method in my Base Ui classes to handle making sure UI actions happen on the UI thread away from a background thread they may of been called from.

The methods are as follows: (Full gist available here)

 * Add a runnable task that can only be run during the activity being alive, things like dismissing dialogs when a background
 * task completes when the user is away from the activity.
 * @param runnable runnable to run during the ui being alive.
protected void postUiRunnable(final Runnable runnable)
    QLog.v("UiRunnables = " + runnable);
    if (null == runnable){
    if (!mIsPaused && BaseActivity.isUiThread())
    else if (!mIsPaused && !BaseActivity.isUiThread() && getActivity() != null)

The idea being  you push your UI calls onto this method which makes sure you don’t manipulate the UI outside of runtime and what is visible to the user. Simple right!
Well it would be up to this point here: BaseActivity.isUiThread()

This calls a convenance method to check which thread you are calling from.

public static boolean isUiThread()
    return Looper.getMainLooper().equals(Looper.myLooper());

Great right? Yes. But make sure that your Looper check is done in the above order.

return Looper.myLooper().equals(Looper.getMainLooper());

If the myLooper is cleared/consumed for what ever reason the execution just stops here. No not fails or errors, STOPS! I would need to look into the Android framework to give you a solid answer why.

Suffice to say, Always use the Looper.getMainLooper(), if your application IS running this this is always a valid object.

JellyBean 4.2   added a lovely little callback to the ViewPager class called the PageTransformer.  (Also available in the Compatibility Lib 11)

Big deal you may ask? Look at this:

GreenTree on Moupp – Page fades in

So the page from the right fades in and the page going left fades out! Really simple, but nice effect. Works nicely with picture pagers. Code? Sure!

            mViewPager.setPageTransformer(false, new PageTransformer()
                public void transformPage(View v, float pos)
                    final float invt = Math.abs(Math.abs(pos) - 1);

Lovely bit of code, we normalise the float coming in (so its always 0 to 1) then we apply that to the View.setAlpha(float) method. This works with any of the View transformation methods! (Alpha,setX/Y, rotateX/Y).

You can of course get a bit silly with this! So please be sensible, I don’t want to be seeing 360 spins on page transitions…  (yeah I’ve tried!)

Update: Damian Flannery made this neat little transition

Middleware project.

Sitting between your phone and gorgeous hi-res imagery is that rubbish thing called mobile internet!

There are few things you can do to get that content:

  1. Download the image and use it on your phone
    Of course this is just a very bad idea! Why?

    1. Huge file, slow internet connection; could be minutes before your user sees the image!
    2. Huge file saved to your users device, low mem phones; OutOfMemory error waiting to happen.
    3. Caching on the phone? Great! But, you are storing a large image that the user will never utilise… wasted space!
    4. Down scale on the phone.. OK, but then you are asking the phone to manipulate images which is not a fast task, so wasting the users CPU and subsequently battery!
  2. Have pre rendered different sized images and use based on screen size.
    This is of course a better solutions but only really works for iOS, where you need 4 image sizes.

    1. Will need 100′s of different picture sizes pre rendered
    2. More data in your web calls to be thrown around
    3. More data to be stored on your server
  3. Have one size image and let the device request the size it needs.

3. Is where I am going with this.

The idea is simple, you know were the orginal hi res image is. and you know what size you need to display to the user. Pass the source and size to the server and get a perfectly sized image back!

When I started writing this blog post this was just an idea, as of now this is a real service:

In the above URL is the Size you want (we cleverly work out the smallest size, you can pass height in as well) the orginal image; then the server does the rest and return it to you!



Simple! Give it a try:  source and info


So we have a requirement, where sometimes your screen needs to be one orientation for a certain situation or screen size.. So that rules out using:


As this will stop your Activity from using all orientations in other sizes/views etc.

So, what do we do?

public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState); setContentView(R.layout.main);
 //If normal do..
 //Else do something else

Job done! You can change the orientation to your hearts content. Great for, forcing your user into full screen mode landscape when playing a video for example.

So you want to add a little flare between your custom selector states on Android? As of HoneyComb 3.0+ this is pretty easy.

Take home_tile_background_selector.xml here:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="" 

  <item android:drawable="@drawable/home_tile_background_pressed" android:state_selected="true"/>
  <item android:drawable="@drawable/home_tile_background_pressed" android:state_pressed="true"/>
  <item android:drawable="@drawable/home_tile_background_pressed" android:state_focused="true"/>
  <item android:drawable="@drawable/home_tile_background_default"/>


The code highlighted above in bold is the key line, this will enable those lovely fade away selectors. Android Provides a few time periods, so have play and enjoy :)

AllJoyn is a P2P networking development kit developed by Qualcomm.

The idea is simple, provide a singular communication bus that local devices can find and talk to each other on. But without the messy and slow handshaking over the internet via a server, whilst supporting many programming languages and platforms.

Meaning? Superfast, super streamlined user experience.

We had a talk with Mitch Williams from QuIC (Qualcomm Innovation Centre) at Droidcon London 2012 about the technology. He showed us some Android apps running a demo that worked flawlessly and seamlessly. We were impressed!

What makes the technology impressive is, you need no internet connection, no expensive backend servers and the platform does not matter. Phones can quite happily talk to each other via bluetooth, WiFi or Local network. As AllJoyn is fully open source and licensed under Apache 2.0, there would be nothing to stop you expanding/implementing your own connection methods.

AllJoyn are running a peer-to-peer mobile apps challenge! To find out more click here.

Via Mubaloo

This has been talked about all over the ineternet and raised in a few stack overflow questions.

But if you filtering screen sizes in your android manifest, you will need to add:

<!-- Special case for Nexus 7 -->
<screen android:screenSize="large" android:screenDensity="213" />

This enables the Nexus 7 screen for your apps, if you don’t filter your app by screen size; no need to worry, your app will work on all devices by default.

So I had a look around for a backwards compatible GridLayout for Android only to find that it’s hidden in the android sdk extras. (As of ACL v7 ADT17)

I’m wondering if it’s not been made public yet due to it not being tested, or maybe that it only works with eclair onwards (api 7).. But anyway.

It’s under your Android sdk path:


You will need to import this as a library project as the readme suggests. Sorted.

Advantage of using this library is that ADT editor detects its included in your project and the layout editor will auto fill name space and reference the support lib.

Usage, worth looking at:
Sytling Android GridLayout
Android GridLayout API


Any questions feel free to ask.

So a few months have happened and a project has developed in wonderful ways.

Android Device App Home Screen

Originally the project wasnt meant to have a website but low and behold the project has a lovely website to administer tracking your device and setting it up.

Wifies – Location Tracking

So what can it do? Currently perform actions based on a device location, e.g. when walking into University my phone will go silent and when moving away from university it will go loud.

Due to this being a university project I can’t release it to the public just yet (IP and all that) but I intent to continue development and release the application to market to try and get some feedback and users testing it.

Please feel free to pop along to the website and register for the time being and I will place an .apk file as soon as I’m allowed too.

Stay tuned folks!

Wifies – Location Tracking

Christopher Jenkins
WiFies – JenxSolutions & University of Plymouth


So we had our poster fair today!

Oooo exciting day of projects, people, free lunch and guests!

I’m going to take this one out on a positive as I had a fairly good day.


1am-3:45am – BUG SQUASHING! That last minute panic, I will get my project presentable!

11am: Rise n shine

11:45: “Why arnt you dressed yet” – ‘Its 12:30 Batch, don’t worry!”

12:30: Free food – mmmm cheese – Free food – steal some cheese… and “Wait.. that’s a project?”

1:30: Mr Apple acount manager man! Yeah lets keep UoP in our pocket with a outdated slide show… boo mr apple boo.

2:00: *Grin* Shoulder to Shoulder, “Can we have your project for next year?”

3:00: “Oh so your a lecturer” – Mouth say hello to my foot!

3:20: Hi Saveen!

3:40: You didn’t win!

4:00: Go hom… *Gone*

Lets break this bad boy down!

Free Food

Students free food – always a winning combination – but sometimes needs must. In some cases *Cough* Ben/Russel *Cough* aquiring food to take home is allways a bonus. I comend you comitment to the cause you ledgends!

Mr Apple

Bored… oh there is more than “The App Store”. Sorry your loosing sales to Android and Ovi… Sore maybe… boring- definitely.

Hang on… thats a project?

Yes, I shall mention no names but I don’t consider a ‘ Torch App for Android’ a final year project… Please let me know if you do! (funnily enough not alot of people did)

Oh your a lecturer!

Well true foot in mouth moment, I was talking to a lecturer for a good 10 min’s who was very interested in the project. Upon asking what do you study here “I’m a new networking lecturer”. Ooooops! Well how was I meant to know? He should take it as a compliment… just saying he looks young.

We finish with 1 x don’t listen to Bob, “Use a high contrast posters, avoid large blocks of solid colour… what posters win? the ones with large blocks of solid colour! Note to self… Ignore Bob and do what you think looks awesome!

Anyway heres the poster for your amusement anyway!