Slovenian keyboard layout and "noseless" smileys for Android 4.0

Preface

In September 2011 I’ve switched from the Galaxy S phone to the Google Nexus S. The device was similar in specifications, but the main feature was that everything that ran on it was open source via AOSP1. It also received in November 2011 an update to the biggest Android refresh yet, version 4.0 codenamed Ice Cream Sandwich2.

Google Nexus S, running Android 4.0 Ice Cream Sandwich (Photo Credit: gsmarena.com).

Google Nexus S, running Android 4.0 Ice Cream Sandwich (Photo Credit: gsmarena.com).

This meant that you could download the whole Android OS source, build it and flash it on your device yourself. Of course that resulted that there were suddenly many modifications more easily possible. One of them I’ve personally made was adding Slovenian special characters č, ž, š, đ to the stock ICS keyboard. Another addition for the international users on the xda-developers community was removing the “nose” from the standard smileys :) instead of :-).

Same as in previous Android 2.3 Gingerbread release, ICS didn’t include special Slovenian characters for the Slovenian keyboard layout. Slovenian users had to use Croatian layout to reach č, ž, š, đ conveniently. This motivated me to make the change myself. The idea was fairly straightforward:

  1. download the source
  2. find the corresponding code and modify it
  3. build the keyboard .apk from the changes.

Building from ICS source code

There are clear instructions posted by Google for how to download and build from the source. Linux and Mac systems are the only way, but I’ve personally used Ubuntu LTS 10.04 in a VMWare Virtual Machine on the Windows 7 desktop host. The requirements for RAM usage for building in a VM are quite high in the documentation, but I’ve built a full ICS system ROM under 2 hours with Intel Core i5-2430m @ 2.4 Ghz and 4GB of RAM dedicated to the VM.

So here we setup the build environment by installing needed software and libraries. At this point we assume there’s a clean installation of Ubuntu LTS 10.04 installed. First we install Java 6 JDK.

$ sudo apt-get update
$ sudo apt-get install openjdk-6-jdk

We set it up as default, to be sure.

$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac

Then we install required packages for building.

$ sudo apt-get install git gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
  libxml2-utils xsltproc

Then we need to setup the repo tool for downloading the source:

  • We make sure bin/ is in our home directory and is included in the path.
$ mkdir ~/bin
$ PATH=~/bin:$PATH
  • We download the repo tool and make sure it’s executable.
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

Next step is creating a directory where we’ll download the source to, name it whatever you want.

$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

Now we run repo init to initialize the repository with the source code.

$ repo init -u https://android.googlesource.com/platform/manifest

If we don’t specify any branches, master will be downloaded. For now this is ok, but in the future you might want to specify a specific build number. This is for ICS running on Nexus S.

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1

Configure the repo with your full name and email at the end. Final step is now initializing the source code download.

$ repo sync

Now this is several GBs so you might want to grab a beverage of choice and come back later. After the download is done, we set up the proper build configuration.

$ source build/envsetup.sh

Then we choose a target device to build with lunch command. In case of Nexus S, we pass full_crespo-userdebug, more device configurations here.

$ lunch full_crespo-userdebug

At the end we build the code with make.

$ make -j4

Building will begin and it will take longer on the first build. After that we can build certain packages only using mmm command.

For our case, we want to build only the Latin IME package. This resides in packages/inputmethods/LatinIME/.

$ mmm packages/inputmethods/LatinIME

The build .apk can be found in ~/WORKINGDIRECTORY/out/target/product/generic/system/app, where as WORKINGDIRECTORY is the one we chose at the beginning.

Slovenian keyboard layout

I’ve decided to modify the existing en_GB and en_US layouts, since I wanted to preserve the dictionary of English words for predictions, but still type special Slovenian characters without needing to switch the keyboard. It took me quite a while to figure out the keyboard layout files, since they’re spread out through many different .xml files. Changes were quite simple after that. The keyboard source and layout files are in platform/packages/inputmethods/LatinIME.

Specific changes were made in file java/res/values-en/donottranslate-more-keys.xml.

@@ -22,8 +22,11 @@
     <string name="more_keys_for_e">3,è,é,ê,ë,ē</string>
     <string name="more_keys_for_i">8,î,ï,í,ī,ì</string>
     <string name="more_keys_for_o">9,ô,ö,ò,ó,œ,ø,ō,õ</string>
-    <string name="more_keys_for_s">ß</string>
+    <string name="more_keys_for_s">š,ß</string>
     <string name="more_keys_for_u">7,û,ü,ù,ú,ū</string>
     <string name="more_keys_for_n">ñ</string>
-    <string name="more_keys_for_c">ç</string>
+    <string name="more_keys_for_c">č,ć,ç</string>
+    <string name="more_keys_for_z">6,ž</string>
+    <string name="more_keys_for_d">đ</string>
+    <string name="more_keys_for_y"></string>
 </resources>

Then java/res/values/donottranslate-more-keys.xml, where I changed to popular domain helper key from .edu to .si.

@@ -55,7 +55,7 @@
     <string name="keyhintlabel_for_punctuation"></string>
     <string name="keylabel_for_popular_domain">".com"</string>
     <!-- popular web domains for the locale - most popular, displayed on the keyboard -->
-    <string name="more_keys_for_popular_domain">".net,.org,.gov,.edu"</string>
+    <string name="more_keys_for_popular_domain">".net,.org,.gov,.si"</string>
     <string name="keylabel_for_symbols_1">1</string>
     <string name="keylabel_for_symbols_2">2</string>
     <string name="keylabel_for_symbols_3">3</string>

And java/res/xml/kbd_qwerty.xml to change the default layout to QWERTZ.

@@ -23,5 +23,5 @@
     latin:keyboardLocale="en_GB,en_US"
 >
     <include
-        latin:keyboardLayout="@xml/kbd_rows_qwerty" />
+        latin:keyboardLayout="@xml/kbd_rows_qwertz" />
 </Keyboard>

This is the commit on GitHub, where I’ve uploaded my changes. The modification resided on a specific branch called ics_en_SI, accessible here.

I’ve also posted the work on the slo-android forum, where there were quite some users who wanted to try it out.

When Android 4.1 Jelly Bean3 arrived in July 2012, Google made the changes and included a proper Slovenian layout for the keyboard with special characters included. That way my modification wasn’t needed anymore, but it served its purpose for couple months.

Noseless smileys

There were quite some requests for this modification online and while I had the source downloaded, I’ve decided to make this one as well. People who were used writing smileys online usually skipped the dash - part, since this resulted in faster typing. But on mobile devices, smileys included this dash and looked out of place.

The change was even simpler then figuring out the special characters. Again in folder platform/packages/inputmethods/LatinIME under java/res/values/donottranslate-more-keys.xml the changes were pretty obvious. These are the values that are displayed when you long press the smiley button.

@@ -49,7 +49,7 @@
     <string name="more_keys_for_currency_euro">¢,£,$,¥,₱</string>
     <string name="more_keys_for_currency_pound">¢,$,€,¥,₱</string>
     <string name="more_keys_for_currency_general">¢,$,€,£,¥,₱</string>
-    <string name="more_keys_for_smiley">":-)|:-) ,:-(|:-( ,;-)|;-) ,:-P|:-P ,=-O|=-O ,:-*|:-* ,:O|:O ,B-)|B-) ,:-$|:-$ ,:-!|:-! ,:-[|:-[ ,O:-)|O:-) ,:-\\\\\\\\|:-\\\\\\\\ ,:\'(|:\'( ,:-D|:-D "</string>
+    <string name="more_keys_for_smiley">":)|:) ,:(|:( ,;)|;) ,:P|:P ,=O|=O ,:*|:* ,:O|:O ,B)|B) ,:$|:$ ,:!|:! ,:[|:[ ,O:)|O:) ,:\\\\\\\\|:\\\\\\\\ ,:\'(|:\'( ,:D|:D "</string>
     <string name="more_keys_for_punctuation">"\\,,\?,!,:,-,\',\",(,),/,;,+,&amp;,\@"</string>
     <integer name="mini_keyboard_column_for_punctuation">7</integer>
     <string name="keyhintlabel_for_punctuation"></string>

This is the change in java/res/xml/kbd_key_styles.xml for pressing the smiley key, that appears in place of enter key on certain input fields.

@@ -82,8 +82,8 @@
             <!-- Smiley key. -->
             <key-style
                 latin:styleName="returnKeyStyle"
-                latin:keyLabel=":-)"
-                latin:keyOutputText=":-) "
+                latin:keyLabel=":)"
+                latin:keyOutputText=":) "
                 latin:keyLabelOption="hasPopupHint"
                 latin:moreKeys="@string/more_keys_for_smiley"
                 latin:maxMoreKeysColumn="5"

This commit is also posted on GitHub. Modification is on a branch called ics_smiley1, accessible here.

After making the changes we build the Latin IME package again as shown above with mmm.

Result of our change, noseless smileys.

My work was posted on xda-developers again, where I also updated the modification when Android 4.1 JB was released in July.


Conclusion

Building for Android was a bit of a large project at first to learn, but it was very fun and resourceful. This were my first steps with Android source, but after I’ve got the hang of it, it didn’t stop there. Any time I’ve come at some limitation of what Android had to offer I started thinking in a different way, like if there are any possibilities for modifying the source and making the change. This change of perspective was really beneficial when dealing with IT and open source.