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 “Implementing A Locale / Language Selector”

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 “Custom Alert Dialog With Dynamic Buttons”

Android: Importing Levels From QR Codes (Camera / File)

The Problem

In a previous post, it was discussed how to export levels from an Android game (in this case Connect Quest) so that other players could play them. Now that they’re exported, we need to be able to import them again! This post will explain how to import QR codes either directly from the camera, or embedded within an image on the file system.

Continue reading “Android: Importing Levels From QR Codes (Camera / File)”

Android: Selecting A Weighted Random Item From A List

The Problem

In Pixel Blacksmith, visitors arrive in the shop and have demands that need fulfilling. The  visitors are mostly random, but each visitor is weighted to appear more or less frequently,  to allow for rarer visitors. These weighted probabilities also need to be modifiable, to add seasonal visitors etc. Continue reading “Android: Selecting A Weighted Random Item From A List”

Android: Converting Display Pixels (dp) To Real Pixels

The Problem

Occasionally whilst developing a UI in Android, padding will have to be set programmatically, this usually happens when padding varies according to the number of items on screen. These values must be set in pixels, but the size of a pixel will vary massively, according to the density of the screen (for example, 2 1920px by 1080px and 192px by 108px screens may be the same physical size, but the former will have 10 times more pixels in any given centimetre). As such, display pixels (essentially a unit that aims to avoid this issue) must be used, however these values need converting into real pixels. Continue reading “Android: Converting Display Pixels (dp) To Real Pixels”