Tuesday, October 26, 2010

Random notes on android keyboard and date/number picker

This whole investigation of mine started when I first saw the keyboard that is shown for a month textbox in the froyo date picker. I only noticed this after upgrading to froyo, so not sure if it was not there before:

image

So I kind of wanted this for my custom date picker, and I have to say I failed to figure out within few evenings what to set up on my EditText/NumberPicker in order to get to this “Month” keyboard.

What I tried was to look through the source code: git://android.git.kernel.org/platform/frameworks/base.git

Plus reverse engineering from binaries on the device: adb pull /system/framework

And still I can’t see the connection between “Month” keyboard and NumberPicker with range of months setup:

           DateFormatSymbols dfs = new DateFormatSymbols();
            String[] months = dfs.getShortMonths();
            
            if (months[0].startsWith("1")) {
                for (int i = 0; i < months.length; i++) {
                    months[i] = String.valueOf(i + 1);
                }
            }
 
            _startMonthTextBox.setRange(1, 12, months);

I should be overlooking something ;(;(

Have to say I just used my custom NumberPicker by copying the internal source for it. But still didn’t see anything special for the original one in android markup or code source.

At the end I decided to skip on this one. Why? By chance I changed to Swype at some moment and there is no “Month” keyboard there. What more, input is identified as non-numeric and when you try to input a month number it is not even accepted. Interesting!

image

And this all regardless the following code in NumberPicker:

        InputFilter inputFilter = new NumberPickerInputFilter();
        mNumberInputFilter = new NumberRangeKeyListener();
        .......
 
        mText.setFilters(new InputFilter[] {inputFilter});
        mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
 
       .....

Another small lesson for me on the devices/features diversion!

No comments: