May 2010 Archives

May 26 2010

Mocking a GUI (for Android)

Posted in android; by Miek Gieben; comments: 1

I'm playing with Mockingbird which allows you to create wire frames for GUIs. I want to create a little app for Android which is based on the Alarm app which is included by default.

The following images are exported from Mockingbird:

Home screen of clock app

Details of an alarm

Settings of alarms

And what is also brilliant? The source of the alarm clock is available.

The bad thing is that all android apps are written in Java... (yech).


May 24 2010

Android dev on Ubuntu 10.04

Posted in android; by Miek Gieben; comments: 0

After mocking about for a few months I decided to take the plunge and look into developing Android applications.

Almost every website I looked at was telling me I needed Eclipse and God knows what to write some little Java programs. So I tried Eclipse, downloaded 300 megs, waited 30 seconds for the thing to start up and was then greeted with the segmentation fault. W.T.F. ?

Looking further I found this great blog entry detailing development with Vim and general doing the development on a more low level — like, you know — the way it should be.

Getting the emulator up and running

I'm running the Android SDK kit on Ubuntu 10.04 (64 bits). Doing this on a 32 bits version is even easier.

You need to download and untar the dev kit from the URL above. And you'll need to add the Tools directory in the sdk to your PATH variable.

Next you'll need java and ant, for Ubuntu 10.04 this becomes:

apt-get install openjdk-6-jdk openjdk-6-jre ant

further more, a 32 bits version of libstd++ and ia32-libs is needed, because when I started the emulator I was greeted with:

SDL init failure, reason is: No available video device

So

apt-get install ia32-libs lib32stdc++6

Next you can start android

% android

And a GUI should appear. Next you should click 'Available Packages', enable the repository and just download everything. All these package will be installed in you sdk directory (where you untarred the sdk).

After this has been done you can create a new virtual device (AVD). Go to the 'Virtual Devices', select 'New' and give your need Android some nice hardware. After this is done you can start your phone (which can take quite a while). When the phone is booted you will see something like this:

Android emulator

Clicking 'Menu' will unlock your virtual device.

HelloAndroid

Create a new project

 android create project --target 4 --path ~/test_android --activity Test1 --package Hello.World

Where target 4 is the fourth target listed with android list targets, which for me is a 2.2 device.

~/test_android is just a path where your source code lives.

--package Hello.World is the Java package for you program.

android create project also puts some example code in the directory structure it creates: test_android/src/Hello/World/Test1.java

Type some code

Cut and paste the following code into Test1.java:

package Hello.World;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

Compilation

cd ~/test_android
ant debug       # this prob. builds a debug build

And then you should have a test_android/bin/Test1-debug.apk; an android package.

Getting the .apk on the emulator

Start the emulator (if it wasn't running), and use adb:

adb install ~/test_android/bin/Test1-debug.apk 

261 KB/s (13175 bytes in 0.049s)
pkg: /data/local/tmp/Test1-debug.apk
Success

This should work ok. Next on the emulator; Menu, and scroll to your app, it should be named Test1, and click it.

Tada!

Next up: build something nice and useful.


May 14 2010

Go Book

Posted in go; by Miek Gieben; comments: 2

I'm writing a book about Go. It is very much a work-in-progress, but I just wanted to mention this work and publish a snapshot. The aim is to explain Go and to provide many (many) exercises (and answers) so people may learn this wonderful language.

It is written using LaTeX (of course), see gitweb for the code.

Help is appreciated. The pdf of today (aka daily build) can be found here.

The title page looks like this: