Creating a custom Android ActionBar

By default, new Android projects have an ActionBar at the top (also known as a title bar), which usually contains a title, an optional back button on the left, and optional action(s) on the right. For many cases, minor customisations to colour are enough, but if a project requires exactly meeting a client’s design more advanced functionality will need to be utilised.

This tutorial will walk through the steps needed to turn a default ActionBar into a fully customised area of the screen, whilst keeping useful functionality like displaying a back button intact. Kotlin is used for this sample project, but all code can be easily converted to Java.

Continue reading →

Getting OneSignal Working On A Multi-Module Project

Recently, upon attempting to implement OneSignal for user notifications (and following their installation instructions), a wide variety of intriguing and mysterious build errors were encountered.

The root cause of these seemed to be their gradle plugin (ironically intended to simplify the dependency process, and solve any Google Play Services issues) causing issues when attempting to be applied to a project with 10+ modules inside it. Luckily, the fix was pretty straight forward.

Continue reading →

Getting Started with Sugar ORM

Sugar is a very easy to use ORM library used to make handling databases on Android hassle-free. Whilst it lacks some features, it is ideally suited to smaller projects due to the simple syntax.

There is official documentation, but it misses a few key points, so this article will serve as an alternative “Getting Started” guide. It also highlights a few vital options that aren’t mentioned in the official guide, and is geared towards those new to Android who want an easy way to setup a local database. Continue reading →

Auto-detecting Device Orientation Whilst Allowing User to Override

The Problem

When creating games (and other apps), screen orientation is very important. In general, more casual games use portrait, whilst more hardcore / intense games use landscape. However, some games may be inbetween these two categories, or may wish to reach a wider audience by supporting both. Automatically rotating to match device orientation is easy, but allowing the user to “lock” one orientation is a little trickier.
Continue reading →

Selectively Playing Tracks Whilst Game Is Active / Open

The Problem

Playing background music on Android is pretty easy: just start a service with a media player. Great, that was easy! However, when the user presses the home button, the music… continues. This is good for music apps, but awful for games. In this example, Blacksmith Slots had one music track for the intro, and one for the main game. Continue reading →

Implementing A Locale / Language Selector

The Problem

Android applications are distributed to users around the world, and these users aren’t always going to speak the same languages as you. Luckily, Android has excellent built-in support for automatically applying the right language, however this isn’t always enough. Sometimes a user may want to choose their language, and unfortunately there’s no built-in way to support this. The game Pixel Blacksmith uses the technique described in this article. Continue reading →

Custom Alert Dialog With Dynamic Buttons

The Problem

Alert Dialogs are an excellent way of providing a confirmation screen, or letting users select from a set of options. However, customising them can be tricky, and they have a maximum of 3 buttons (positive, neutral, negative), all of which are positioned differently in different Android versions. If advanced customisation or more than 3 buttons are required, the usual method of modifying colours etc (styles) isn’t enough! Continue reading →