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.

Setup

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!


Implementation

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.



Permissions

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.




BroadcastReceiver

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



Registration

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.


Screen

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.


Camera

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.


Performance

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

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

Thursday, May 16, 2013

Google IO Day One - Keynote



Google IO kicked off yesterday with the keynote at the Moscone Center in San Francisco. They keynote is always an exciting event with the big names on center stage filling your ears with all the great new and upcoming tech. While this years keynote steered away from hardware and Key-lime Pie it was till jam packed with a tonne of stuff. Here are the bits of the Keynote that I found interesting:


Android Studio

This took me as a bit of a surprise to be honest and quite a good surprise at that. Google is moving from Eclipse to IntelliJ. This is very interesting because b2cloud has just made this transition about two months ago after struggling with Juno for months. With the Android tools team putting it's resources behind intelliJ for Android, some of the weaker aspects to IntelliJ have been improved, namely the Visual Editor. Prior to Google's input the visual editor bordered on horrible to unusual, now it has the multi-screen size comparison Eclipse has.


Galaxy S4 Nexus Edition

I had heard rumors about a Galaxy S4 Nexus Edition prior to the keynote starting, but I was a bit skeptical. Sure enough though, the announcement came. This is very interesting and promising, basically it's opening up the doors for any manufacturer to step up to the plate, put Vanilla Android on their flagship phone and submit it as a Nexus Edition to be purchased on Google Play. I'm hoping the HTC One will follow suite! Come on HTC, the Android community has been waiting for another HTC Nexus devices for a long time!


Translation Services

Google has now integrated translation services into Google Play. This is a paid feature that has string resources submitted to a human or humans who then go through them and translate them. In the keynote they said the turn around was a week.


Beta Testing and Staged Rollouts

The developer console is now letting you manage your beta testing by giving you the ability to setup a beta testing team who will get access to your app. It also allows the user to do a staged rollout of updates by selecting the percentage of users you want to include in the rollout. Staged rollouts are a great way of minimizing the potential impact of a accidental bad release. While as developers we try to ensure that this doesn't occur, sometimes bugs occur and sometimes they occur with disastrous impact. 


Google Music - All Access

Google has entered the music streaming wars, with a fresh new music app, and a $9.99 a month subscription rate ($7.99 if you get in early). I don't think most people will find this interesting as Spotify, MOG and Pandora has a large hold on this market. For me however this is great as I already have a large number of songs uploaded and purchased from Google Music. Unfortunately this service is for the US only, however if you work a bit of Google Plus magic you might be able to access this from other countries, hint hint!

There's much more in the keynote that I wanted to add but these are the big topics that interested me the most. I strongly recommend watching the keynote yourself on youTube

Saturday, March 23, 2013

9-patch Transparency Gotcha

This is from a post I put up at b2cloud

Recently I had a project design which required borders around each image displayed. To avoid overdraw I used a 9-patch image resource with a transparent center in which the image would be placed. This would theoretically avoiding overdraw completely. So after a quick session in Photoshop I knocked a 9-patch, turned on “Show Overdraw” on my Dev phone and did a test run.


Not quite the results I was hoping for! If you look very carefully, you will notice that while almost everything is blue (good), there is a thin border of green around each image which signifies overdraw. The obvious place the overdraw could have come from is the content patches along to the bottom and right hand side. If they happened to be too long and overlapped the border then overdrawing would occur. A quick examination of the resource proved that was not the issue, the content images were correct.


Given that the content patches were correct, that only left the stretch patches. That raised the question, What if the stretch patches not only told Android where to stretch the image, but also told it where to stop drawing due to transparency. With that question in mind, I set out to test the theory.


After extending the stretch patches across the entire transparency section I fired up the app once again.


Success!

There you have it, if you’re going to use transparency in 9-patch resources to reduce overdraw be sure that your stretch patches encompass the whole transparent area.

If your interested on more tips for UI performance check out Romain Guys post at curious-creature.org





Monday, December 24, 2012

Nexus 4 Review


I have to admit, when I heard the news that the next Nexus branded phone was going to be be coming from LG I was pretty quick to dismiss it. The last LG phone I had was an old horrible plastic flip phone from Telstra with little to no functionality. Even taking calls was a stretch for it at times! However, I can admit when I'm wrong and boy did LG wipe that nasty little smirk of my grubby little face. They've really done a wonderful job with the Nexus 4. The phone feels amazingly solid in the hand, with the cold touch of the back glass panel adding to that high quality feel. From the front you could be excused for for confusing the Nexus 4 with the Galaxy Nexus, however on closer inspection it becomes immediately clear that they are two very different beasts. The most noticeable difference is that the Nexus 4 has shrugged of that plastic throw away feeling by replacing the flexible back battery cover with a black glass back. The glass back has undergone a Crystal Reflective Process which adds a glitter like effect when the light hits it from the right angle. The glitter effect is quite subtle and is really only seen when you're in direct sun sun or trying to angle the phone the right way to show some body. One issue I have noticed is that the back is quite susceptible to scratching, within my first couple of days I noticed small surface scratches. Not a big deal I suppose but an annoyance none the less.


The screen on the Nexus 4 is a IPS LCD panel, which is a bit of a change compared to the AMOLED based screens found in all previous versions of the Nexus phone line. Like others I found the screen to be a little washed out, however this is more to do with the average calibration and less with the screen quality itself. After rooting my device and installing FauxClock I was able to calibrate the screen to a point where it's comparable in color depth and contrast to that of the iPHone 5. It's a bit of a shame that LG didn't take the time to calibrate the screen a bit better during the manufacturing process. Aside from the calibration issues the screen is really very good. Text is sharp, and blacks are very black for an LCD display. The other thing I really like about the screen is the bevels on the left and right of the screen are small and curved giving the impression that the screen is above the glass and not below it.


The performance is a great improvement over it's older sibling. As much as I love the Galaxy Nexus every so often I would experience UI stutters, particularly if I was installing or updating an app in the background. With the Nexus 4 I haven't noticed this at all, UI animations are fluid and apps that include animations now run extremely well. Even Commonwealth Bank's Kaching app now "almost" preforms at an acceptable level. Saying that I think Kaching would need a quantum processor to function at any reasonable speed, but that's getting off topic.

The camera has also has a much needed bump in quality, it's still not top of the line but it's reasonable a marked improvement on the Galaxy Nexus, and by far the best seen on a Nexus device. Hardware HDR is also a welcome inclusion and performs extremely well. My favorite new feature, while not strictly limited to the Nexus 4, is Photoshere. Photosphere is a 720 degree panorama which is taken by moving the camera to specific places around you. All the different photos taken are then stitched together to form a 3D sphere in which you can move around in using a special Photoshere viewer. Photoshere photos can be shared between other Android devices and in Google Plus which has the ability to display them in 3D. The thing I love the most about Photoshere is the memory emersion, it feels in a small way that you're back in the place the Photoshere was taken all over again. Just a bit of a heads up on Photosheres, while taking them is fairly easy, getting a perfectly stitched Photoshere is a little more difficult, particularly if you're taking it in an environment where things are closer to you. Most of the stitching issues I get is because I've tilted the phone to the side a little and things no longer match up correctly.

The Nexus 4 has a non-removable Battery and while the battery life gets me through the on most days, I do feel a little uncomfortable with being able to carry around a spare battery if I get into a tight spot. This might not be a problem for most, but I'm a fairly heavy user and have been known to drain a full Galaxy Nexus in as little as two and a half hours. For the average user though, I think the battery would see them through the day with a little to spare.

The Good
  • Looks and feels great
  • Top quality screen
  • Fast
  • Good Camera
  • Access to early updates


  • The Bad
  • Non-removable battery
  • Stock screen calibration appears washed out
  • Back panel is prone to scratching



  • Although the Nexus 4 has its niggles, it's an amazing phone that not only looks great but has the performance to match. This phone does justice to the Nexus name and I personally congratulate LG for proving to the doubters that it has the quality to mix it with the best.