Wednesday 17 October 2012

App in a Day #1 - Drum Roll

With all this malarkey engines and OpenGL's, I've noticed that I've been straying farther and farther away from what makes the Android framework what it is. In order to make sure that I don't lose that "special touch" that took so long to gain, I've decided that every now and again, I'm going to create a simple app in the space of less than a day that will challenge the areas that I feel are getting a bit rusty.

Today's app is...... (queue drum roll)....... Drum Roll!!!.... wait, what?

Yep, a simple app that plays a drum roll followed by a symbol when you finish.
The key to this app was to take advantage on the fact that 60-80% of an apps worth is in its presentation. I cracked out Photoshop and took a few royalty free images of a snare and added some drumsticks for animation effect. What caught me with the animation though, was that because my thread was running independently  it had no interaction with the UI thread at all. This meant that I couldn't actually access any of my ImageView's, which threw up a buttload of runtime errors (yes Chrome, buttload is a word).

To rectify this, I ended up creating another thread within my thread and as much as I'll say threadsception only leads to bad practice, I was at my wits end and just wanted it to work. "But what about not being allowed access all my lovely shiny Views I spent minutes rotating in Photoshop" you say? Well if you pass this inner thread to runOnUiThread(java.lang.Runnable), the Activity class you're extending will actually run the thread on the UI thread (who needs javadoc's when you've got methods with names like this?).

The second problem I had was with the custom ROM I was running. I decided to add ads and upload it for free, not that it will generate much revenue, but testing the new AdMob jar to make sure I have it right before I end up uploading it without any ads proved just as frustrating. Eventually, and I mean EVENTUALLY, I noticed that the webserver that my phone was trying to contact to pull the ads from, was resolving to 127.0.0.1. But how? why? Well I did a quick little SSH on to my phone and checked /etc/hosts and low and behold, hundreds and hundreds of address being redirected to localhost, including all of the ad ones. The guy who made this ROM, blocked all chance of ads ever appearing which is a mixed bag of dicks if you ask me. On the one hand, I never have to look at an ad which as a consumer, is wonderful. But the guy who made whatever app for free is getting absolutly nothing from me, not even an impression, which as a developer, is blasphemy.

Last but not least, I managed to update my ancient splash screen with a fancy schmancy new one featuring my new logo (thanks to James) with a really cool transparent background.
What I did was, set the background colour of the the parent layout in my spash screen xml to #00XXXXXX. This sets the alpha of the colour to 0 so it doesnt really matter what colour you choose. This then lets you see through to the default background behind it, which is black. To then get rid of this, I created a new style in res/values/styles.xml which removes stuff like the title bar and set the background of the Activity to transparent:


<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>

</resources>
(I'll set up syntax highlighting later, I promise)

I then assigned this theme to my splash screen in application tag in the manifest:


    <application
        android:icon="@drawable/ic_launcher_drum2"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >





Regardless of all of the above, the app has been finished and uploaded and can be downloaded here:



No comments:

Post a Comment