Tuesday 24 December 2019

ASCII, ISO and UTF

I struggle to remember what the ASCII, ISO and UTF acronyms stand for so I'm typing them up here in the hope that they stick!
  • ASCIIAmerican Standard Code for Information Interchange: this is the 7-bit character encoding system (7 bits so a total of 127 characters) and forms the basis of the other two systems.
  • ISOInternational Organisation for Standardisation: this is the 8-bit character encoding system which has a number of different versions each supporting a different set of languages (e.g. ISO-8859-1, ISO-8859-2 etc).
  • UTFUnicode Transformation Format: this is the system which uses a variable number of bytes (usually 1-4) to encode a character and hence supports a significantly larger number of characters than the other two systems.

Friday 11 October 2019

iOS: Natural text alignment doesn't mean what you think it means

So it turns out that natural text alignment in iOS doesn't mean "left-align left-to-right text and right-align right-to-left text" as it does in Android. For example, if I put English text in a UILabel I'd expect it to be left-aligned and if I put Arabic text in a UILabel I'd expect it to be right-aligned. But no. This is not how it works in iOS. Instead natural text alignment in iOS means "left-align text if the device's language is set to a left-to-right language and right-align text if the device's language is set to a right-to-left language". So, for example, if I set the device's language to English then the text in the UILabel will be left-aligned regardless of its content and if I set the device's language to Arabic then the text in the UILabel will be right-aligned regardless of its content.

For a super simple iOS application which demonstrates this see here.

Friday 9 August 2019

Quran SDK (library) for iOS

I mentioned a good while previously that I'd extracted code out from my Hifdh Tracker and Hifdh Tester Android apps into a Quran SDK for Android. Well I've just started porting these apps to iOS and as a first step I've ported the Quran SDK for Android to its iOS equivalent. The Android and iOS SDKs are essentially Kotlin and Swift (respectively) wrappers around the Quran database which make it super easy to get data out of the database. You can find the repository for the SDKs here. The README in the repository explains how to incorporate and make use of the SDKs in your own Android and iOS projects.

Friday 5 April 2019

Android: Display bulleted list in a TextView

The BulletSpan class in Android has some quirks about it which makes it a little difficult to use. For example, each character sequence which is to be bulleted has to be preceded by a new line character. And using BulletSpan alone you're not able to specify how much vertical space you want between each bulleted character sequence. For this reason I've put together a Kotlin extension function on the SpannableStringBuilder class named appendBulletSpans(...) which takes the difficulty away from creating a bulleted list.

You can use this extension function as follows:

val spannableStringBuilder = SpannableStringBuilder()

spannableStringBuilder.append("Here is a list of fruits:")

spannableStringBuilder.appendBulletSpans(
    paragraphs = arrayOf("apple", "banana", "carrot"),
    putVerticalSpaceBeforeFirstParagraph = true,
    verticalSpaceToPutBetweenParagraphs = verticalSpaceInPixels,
    horizontalSpaceToPutBetweenBulletPointAndParagraph = horizontalSpaceInPixels,
    bulletPointColor = Color.BLACK
)

textView.text = spannableStringBuilder

This will render the text in a TextView as follows:
You can find the source code for this extension function in the SpannableStringBuilderExtensions.kt file in this repository.