Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Setting child divider on an ExpandableListView causes weird flashing overlay on some Samsung phones November 29, 2011

Filed under: Android,Error — Rupert Bates @ 2:22 pm

This is a weird niche bug which I’m documenting here in case I need it in future.

Affected devices:
I have only seen it occur on a Samsung Galaxy S2 but I’m guessing it probably happens on any 2.x Samsung device running TouchWiz (it doesn’t happen on the Nexus S)

Steps to reproduce:
Create an activity with an ExpandableListView and set the childDivider property of the ExpandableListView to any colour, say red for ease of viewing

<ExpandableListView android:id="@+id/pageBundles"

Now if you scroll the list for a while, particularly if you sort of wiggle it up and down quickly and then let it go the list will be completely covered by a solid block of the colour specified in the childDivider property. This will remain for a few seconds and then disappear.

To fix this issue just remove the childDivider property setting


Phone number code puzzle November 4, 2011

Filed under: Coding,Scala — Rupert Bates @ 1:53 pm

Once upon a time I was presented with the following test in an interview:

Given a mapping of digits to an array of characters, ie.


Print out all the string permutations a given input of digits maps to.
So for instance the string “23” should return:

Another way to think of this is a function that returns all the possible combinations of letters the digits could represent if they were keypresses on a standard phone keypad.

I did a pretty bad job at this when I was asked it, partly because it was quite late at night, and partly because it’s not the sort of thing you find yourself doing that often, but today I found myself with a little bit of spare time on my hands and thought I’d give it another go.

I chose to do it in Scala rather than in Java which I had used last time and of course this led to the solution being much more elegant and succinct. If fact this is exactly the sort of problem that demonstrates the value of functional programming.

import collection.immutable.{List, Map}
import java.lang.String

object PhoneNumbers extends App {
  val input = "1234"
  val data = Map(
    0 -> List("0"),
    1 -> List("1"),
    2 -> List("a", "b", "c"),
    3 -> List("d", "e", "f"),
    4 -> List("g", "h", "i"),
    5 -> List("j", "k", "l"),
    6 -> List("m", "n", "o"),
    7 -> List("p", "q", "r", "s"),
    8 -> List("t", "u", "v"),
    9 -> List("w", "x", "y", "z")
  getCombinations(input.substring(0, 1), input.substring(1))
    .foreach(f => Console.println(f))

  def getCombinations(current: String, remaining: String): List[String] = {
    val vals = data(Integer.parseInt(current));
    if (remaining.length() == 0)
      return vals

    val restOfString = getCombinations(remaining.substring(0, 1), remaining.substring(1))

      .map(f => restOfString.map(f2 => f + f2))