Saturday, December 15, 2012

നമസ്കാരം ലോകമേ!! എന്തെര് API?

I am currently in the workshop of an android application as a personal project and for that there is a requirement to present text in Malayalam for better impact. Right from the onset, the obvious solution for me was to create jpeg or png images with the text scanned and present that as an ImageView in the application. But later on as I completed a prototype, it occurred to me that putting it as text in Malayalam font was an easier way. A cleaner approach which enables copy/paste as users would expect implicitly and which also makes the application design enhancement friendly. But the biggest benefit would be that the application download size will be much smaller this way if the application goes to Google Play or Android Market. 

This post is about how I managed to do this and some philosophy around it. Doing it was pretty straightforward to be honest. The actual implementation was far less time consuming than all the time spent on pondering, analysing, doubting and then procrastinating and then finally fighting inertia.
The implementation process started with a google search. Either the 12-13 years of extensive use has created in me a subconscious skill to pick up the right keywords or the omniscient google server read my mind for what my need was. Whichever it is, the first search result was a stackoverflow query on the exact same thing. The good samaritan over there had proposed to install any malayalam font, put it in the assets folder of the android project and then create a Typeface object from that font file.
Like this:

Typeface typeFace = Typeface.createFromAsset(getAssets(),"anjalioldmalayalam.ttf");
// To save you one google search - Typeface is defined in

Next set this Typeface that you created onto the TextView object:     tv.setTypeface(typeFace);

In my vanity I thought that the problem has been conquered but it was not over yet. I had to actually type the matter for the application in Malayalam in my Eclipse project. I started thinking of bronze-age Lipi software and all the other hassles that's associated - installing it from a CD, overlaying a Malayalam keyboard and the pains of typing it actually. Ah! The pain of finding letters which you know is there somewhere in the 12*6 inches of keyboard space right in front of you, but still unseen. (Feels like it could be secretly enjoying the game). Once I realised the difficulty, I started thinking of using an online keyboard. We can do away with the pains of installation and keyboard overlay. But then with that typing is even more painful. One painful click for each letter and then scores of editing and formatting after all the trial and error with the Malayalam spellings. And then with God's grace, it was time for the best solution to occur - Google Transliteration. Type in Malayalam text with English letters and Transliteration will give a choice of Malayalam words to pick from. And till now I have observed that it's fairly accurate. Type in English, select the best fit from choices that pop-up after each word. Once you complete the sentence to your satisfaction, copy/paste it to your application. 

It's become so seamless now.  All applications are taking malayalam text in easily once the font is installed. I remember how tough doing all this was just a few years ago when I was trying to solve a similar problem for Papa. And I am amazed with the pace with which the technology world is surging ahead. 

The down side of such pace is that the average brain might get boggled trying to catch up and will give up. It's hard to understand the capabilities and prowess of the state of the art and that itself could be the biggest "limits to growth" structure in times to come. The only way out for a common person in my humble opinion is to gather a crystal clear understanding of what his underlying need is and keep that in mind always.

No comments: