Friday, January 11, 2013

Android: Getting Started developing for Google TV

If you are an Android developer and want to get started developing for Google TV you came to the right place. I'm getting started on Google TV right now I want to share codes with you. So, let's get start.


Google TV limitations:

The thirst thing to keep in mind about Google TV app is that it's an Android app yet! However, we need consider some little things:

- Google TV is NOT a touch device;
- Google TV is large screen device;
- Google TV doesn't have sensors like accelerometer and compass;
- Google TV doesn't support camera, GPS, Bluetooth, microphone;
- Google TV doesn't support NDK;

As we can see, we are talking about a special kind of Android device and so we need consider some special features for that can work. To know the complete list of unsupported features of Google TV see the official report.

After remember that Google TV is a kind of special device we need to know that it needs a specific Android SDK version to work. Until today, the unique version of Android API compatible with Google TV is the 12 (Android 3.1). Another thing about developing for Google TV is that besides the API, it's necessary install the Google TV Addon (which is available on Android SDK Manager as well), what can be a problem is: this runs just on Linux!

So, if as me you have no problem about work with Linux (or even prefer it) neither about the Google TV hardware limitations, congratulations, you are able to keeping forward! =)

How to configure the Android Virtual Device to emulate the Google TV:

The process to emulate Google TV is the same as any Android device, but you have to select the Google TV Addon option on the Target field of the Android Virtual Device edit screen from Android Virtual Device Manager and a tvdpi or xhdpi device on Device field. Know more about Google TV AVDs.

Android Virtual Device edit screen
Android Virtual Device edit screen

After create your AVD following the specification of the image above, you'll need to do some manual adjusts on that. So, open the ~/.android/avd/GoogleTV.avd/config.ini file and overwrite the follow lines:

skin.name=720p
skin.path=add-ons/addon-google_tv_addon-google-12/skins/720p
skin.dynamic=no

Now you'd be able to run the Google TV emulation. Yet if you get the follow message error, that means you can't read or write in /dev/kvm what is required for that the emulator can run.

Failed to load libGL.so
ioctl(KVM_CREATE_VM) failed: Interrupted system call
error libGL.so: cannot open shared object file: No such file or directory

ko:failed to initialize KVM
Failed to load libGL.so
error libGL.so: cannot open shared object file: No such file or directory

To correct that, open your Linux terminal and do:

sudo chmod a+rw /dev/kvm

So now you can start developing you first Google TV application as well.

Google TV emulator booting
Google TV emulator booting

Some important notes before starting coding:

I'm assuming that you are already an Android developer, so I'll not show you how to start a new Android project. However, it's important remember that the Android system assumes that all application require a touchscreen, so we need to say the oppose for it. For that we can put the follow code in the AndroidManifest.xml file:

<uses-feature
android:name="android.hardware.touchscreen"
android:required="false"/>

Another important note is that if you are doing an application to runs both on Google TV and smartphones or tablets you can use layout-large-notouch for layouts and drawable-land-xhdpi (1080p) or drawable-land-tvdpi (720p) for drawables to target Google TV. Even you can determine if the app is running on Google TV by testing:

if (getPackageManager().hasSystemFeature("com.google.android.tv")) {
    Log.d("TV Test", "Running on Google TV!");
}

A very simple test app running in the emulator
A very simple test app running in the emulator

Hope this help you, til next code!


The follows links are consulted to write this post:
https://developers.google.com/tv/
http://oncelinux.blogspot.com.br/2013/01/googletv-emulator-hang-on-logo-screen.html

I would like to specially thanks to +David Carver who helped me a lot with some emulator's problems.

Thursday, January 3, 2013

Grails: How to Read Properties Files in a Groove Class

Reading value from a *.properties file on a *.gpg page is very easy. Also, the scaffold generated CRUD pages have a lot of example what can be consulted as a start point.
Let’s suppose that we have a <my project>/i18n/parameters.properties file which has line
myparameter.something=My Value
So, if we want to get the ‘My Value’ value on a *.gpg page we just need write:
${message(code: 'myparameter.something', default: 'Some default value')}
But, what to do if it’s necessary reading a property’s value in a Groove Class? The answer is quite easy! Supposing the same parameters.properties file we supposed before, we can do:
import org.springframework.context.i18n.LocaleContextHolder as LCH
class MyClass {
 /** Dependency injection for getMessage. */
 def messageSource

 public def getMyParameter(){
  return messageSource.getMessage('myparameter.something', null, 'Some default value', LCH.getLocale())
 }
}
That's all folks!

Wednesday, January 2, 2013

Canonical Annouces Ubuntu for Phones

After a one-day-counting-down, which read 'So close, you can almost touch it.', Canonical, the Ubuntu developer, has announced Ubuntu for Phones, a new Smartphone SO running Linux. According to the official website, the newest smartphone SO will be shows up on CES 2013 and must run native apps as well as web apps.

Even according to the Ubuntu's page, developers will be able to write apps compatible between desktop and smartphone Ubuntu versions by using the Ubuntu SDK.

Ubuntu for Phone: Official pictures

Sure it's very early to say anything about Ubuntu for Phone, so let's follow the next steps...

Find out more on http://www.ubuntu.com/devices/phone.