Friday, May 30, 2014

StreetView in Android

As part of the 4.4 Play Store Services release Google has extended the Maps API to include Native StreetView. I’m super excited about this, in fact I would go so far as to say that if your app has a map it needs StreetView! I know that’s a big claim and the reason I make this claim is that while a map is great at showing a user where a landmark is and how to get from one point to another, it does a very bad job of showing you what to expect when you get there. This, of course, is where StreetView excels!  Providing users access to StreetView as part of your maps solution not only gives your users the ability to see what the landmark looks like before they get there, but also what landmarks surround it, what type of road it’s on, whether or not it has curb side parking available, etc, etc. The best part about it is that StreetView can be embedded inside your app with very little effort.

So let us begin! In this tutorial we’ll  be using the SupportStreetViewPanoramaFragment to create a self contained fragment that takes a set of longitude and latitude coordinates, positions you at the street near your coordinates, and points you in the direction of your coordinates.


As with all my tutorials I’m going to assume you’re using Android Studio, or at least using the Gradle build system. The first step is to setup Google Play Services Maps, now I could take you through each step but Google already has done this better than I could have. You can find Googles setup page here

You’re back, great, now open up the Android SDK manager and ensure you have the latest version of Play Service and ensure you have added the latest version as a dependency and we’re ready to begin!


The first thing we’ll do is create a new SupportFragment called StreetViewFragment that extends the SupportStreetViewPanoramaFragment, this will allow us to keep all custom StreetView logic inside our fragment class. While we’re at it we’ll create a newInstance method that take a set of latitude and longitude coordinates and returns a new instance of the StreetViewFragment.

The newInstance methods is fairly simple, it stores the geo coordinates in the fragment arguments for use later, and returns a new StreetViewFragment instance.

The next step is to override the onCreateView so we can start to setup and position the StreetView camera.

Just a quick note on positioning the StreetView panorama, while this might be obvious the position of your panorama will not be the location you pass in but the closes road side position. What’s not obvious is that the panorama will not point towards your target location, but instead will point to 0 degrees or North. So while the code thus far will position the panorama correctly it will more than likely be pointing the wrong way. In order to fix that we’ll first create a helper method that will tell us the angle between two locations.

Before we can use the above method we need to get the camera location, unfortunately the camera location is not set until after the onCreateView method as been called. Luckily for us we can get the camera location by listening to the onStreetViewPanoramaChange event onCreateView. Just remember to remove the listener unless you want StreetView to point towards your coordinates every time the user moves the camera.

Wednesday, January 29, 2014

Listening to bluetooth connections

In this quick tutorial I'm going to lead you through creating a BroadcastReceiver that will listening for bluetooth device connections and disconnections.


The first though we'll do is add a few permissions in the AndroidManifest, we need both the Bluetooth and the Bluetooth Admin permission for listening to connections/disconnections.


The next step is to create a BroadcastReceiver that receives ACL_CONNECTED and ACL_DISCONNECTED broadcast actions.


The last step is to register the BroadcastReceiver in the AndroidManifest so it can start receiving the broadcasts automatically. Alternatively you can handle this by registering the receiver in an Activity or Fragment when needed.

Monday, January 13, 2014

Does the Galaxy S4 deserve the hate

The Galaxy S4 has been copping quite a lot of flack over the last couple of months as higher powered devices are pushed out in time for the christmas rush. I’ve heard the lag word thrown around a bit, as well as sound issues however, I’m always fairly sceptical of peoples opinions, particularly tech people and power users who are renowned for getting caught up in the boredom factor. There’s nothing wrong with that, I fall into the same trap time and time again. After 5 or 6 months with a phone I’m pretty well over it and looking for the next flagship phone to lay my hard earned on. Luckily I work in a great field where I have access to many different mobile devices including the Galaxy S4, so I thought I’d use it for my daily driver and see if it’s deserving of all the hate.

First boot experience

The first thing that sticks out when reaching the Android homescreen for the first time is Samsung’s big push to their own ecosystem. Each screen is full of average looking “samsung content” widgets, and most Google Play services apps are buried in the app drawer. This makes perfect sense, there’s a lot of money to be made for the company that controls the ecosystem. The problem is Samsung’s ecosystem barely a shadow of Google Play.

Another annoyance is the rounded square icons Samsung has enforced. This really gets under my skin, as I know the effort some designers put into their launcher icons, only to be so quickly disregarded by Samsung for the sake of outdated design language.

I think it’s safe to say I really don’t like touchwiz, the fundamental design language just doesn’t sit well with me. It’s glossy, outdated, and chock full of skeuomorphic design. It feels like a bridge for transitioning iOS 6 users who aren’t quite yet ready to shrug off the chains of the past and take on a real Android experience. I can really see why Apple wasn’t overly impressed with how close Samsung has flown to pre iOS 7 design language.

Customisation required

There are many things I love about Android, but in the case of the Galaxy S4 there’s none better than the ease of dropping in a new launcher. My launcher of choice is the “Google Experience Launcher” (GEL) found on the Nexus 5. It has Google Now built in, and doesn’t play with the launcher icons. Not only that it offers some nice extra features over the standard launcher without losing the look and feel of Android.

I also switched the keyboard out, this isn’t the fault of Samsung. Keyboards are a very personal thing, some people swear by Swiftkey, others Swype, I’m definitely a standard Google Keyboard guy. I’m sure I could have gotten used to the default keyboard, but I didn’t have the interest or the time.


The screen on the Galaxy S4 I found was way over saturated, which seems to be a AMOLED traite, however after setting the screen to movie mode it was much more color accurate and didn’t tire my eyes as much. The screen itself is very sharp at 441 ppi, and outdoor usage was acceptable. Even though the screen isn’t Super AMOLED Plus, meaning it uses pentile matrix arrangement, there wasn’t any noticeable banding throughout the range of brightness levels.


The camera on the Galaxy S4 is quite good, again it’s not DSLR quality but in good lightly it creates vibrant snaps. Even in low light the photo quality was surprisingly good, there was definitely noise in the photo but nothing unacceptable. The autofocus is fast and accurate, and the camera app is feature packed with some useful and interesting modes. Some features take a bit of setup and probably too much foresight to be useful aka the eraser mode which removes background people.

Sound quality

Normally the phone speaker quality wouldn’t get a mention, however ever since HTC launched the HTC One with boom sound I’ve become a little more interested. Unfortunately it feels like Samsung didn’t even try in this department. The speaker internal speaker is weak, tinny and overall horrible. Though it’s probably not an issue for most, as those that care have the HTC One already, it is a pretty pathetic speaker.

Headphones are another story, when listening to music through the Galaxy S4 bass appeared to have a little more punch and crispness than my beloved Nexus 5 through the same headphones, and the highs and mids seem to have more “clarity”. I suspect this has a fair bit to do with the equalizer curve in use rather than the hardware itself, and could most likely be replicated through an equalizer app. Out of the box though the Galaxy S4 has a pleasing balanced sound.

I have heard and read a lot of complaints about sound quality with Google Play music, I used All Access heavily throughout my time with the phone and noticed no issues in any of the music I listened too. The phone was factory reset prior to me using it so maybe that played some part.


The overall performance was a bit luck-luster to be honest, there was a lot of random lag, and jenkiness in places that lesser phones (in hardware and cost) ran quite fine. I don’t it’s fair to blame the Snapdragon 600 either, while it’s not as fast as the Snapdragon 800 there are other phones running the same platform with out the jenk. I have a feeling that touchwiz isn’t as efficient as it probably could be and that Samsung is just trying to do too much with all it’s extra features.


Overall I think Galaxy S4 is quite a good phone with a great screen and a feature packed camera. I’d pull up short of saying it’s a great phone though, it’s full of half baked features, and average quality bloatware that noticeably slow down the phone. Then there's the issue of it running TouchWiz, a UI that is in desperate need of a make over and a good performance tune. As such I couldn’t and wouldn’t recommend it to anybody I knew. The bottom line is there are better phones to be had at the same cost point like the HTC One, or below it like the Nexus 5 or Moto X.

Saturday, January 11, 2014

Virgin Usage Meter - An end is a new beginning

The Virgin Usage Meter has always been my favourite app, it taught me a lot about Android Development, but even more so about people. Virgin Usage Meter started out as a small app I wrote for myself which was never intended for release, in fact it wasn't until I saw a thread on Whirlpool requesting somebody write one, 3 months later, that I started to entertain the idea of releasing the app. After a few beta tests by the kind people in the Whirlpool thread I released the app which, for an app on the play store at that time, became a quick success. Within the first few days I had 1000 active users shooting past my very low expectations and steady growth over three years saw me topping 92000. Even more remarkable was that the app never dropped lower than a 4.5 star rating, and had a 5 star rating for the first 18 months.

So what did it teach me about people? It taught me that a very small minority of people expect that every developer owes them 24/7 support, instant fixes and can be incredibly condescending and rude. Luckily and more importantly it taught me that a large majority of people are encouraging, extremely accommodating, will step in to defend you against the above small minority. Even with all the time I spent developing the app, it was the users who shaped it into the app it eventually turned out to be.

Retiring the app wasn't as tough a decision as I thought it might have been. Three years is a long time for a single person to maintain a hobby app, and VMA's constant plan and website changes meant a lot of late night bug fixes and updates. I also started to receive a larger proportion of demanding emails, of which many grew abusive and threatening if I didn't respond within a few hours. So when Virgin approached me to sell the app to them and help rebuild it into an official app with official APIs, I saw a win/win scenario for myself and users and jumped at the opportunity.

I am really very pleased with how My Account turned out, there's a lot of my app lurking in there but with the new API's it's much more reliable and the new polish has made it much easier to use better to look at. It's still early days for My Account and I know Virgin have some great ideas for the future, and I'm happy to still be a part of an app that helped to carve out my career as an Android developer.

Virgin Mobile Australia - My Account