Archive

Archive for April, 2009

We won Honorable Mention w/ our iPhone app: Congress Bills in Sunlight Labs Apps for America Contest!

April 20th, 2009

My iPhone app has just won Honorable Mentions from Sunlight Labs Apps For America Contest!
It’s out of a pool of 45 apps/websites ^_^
Here’s the winner announcement and list:
Winner List
Here is how they determined the winner. Looks like Congress Bills are ranked number 11th among all 45 entries. Pretty good considering we did it in our spare time comparing to some relatively large team working on their complete feature-rich websites. In that sense, we are happy about the results. Though I did have some suggestions for the next contest as I replied to their blog:
First, thanks for your all GREAT efforts in making this happen!

I do have suggestions in the next round to have a mobile-specific category. Our app, Congress Bills is an iPhone app. Since it was still during Apple’s review during the judging period, we offered Ad Hoc version of the app providing that judges send their iPhone UUIDs to us. But none of the judges did that. Might be due to the fact that they don’t have iPhones. But the truth is that they had to judge the app purely based on the video on vimeo, screenshots, and blog descriptions. Since the mobile device is a very different kind of media than website, there are unique features/advantages exhibited from them. It’s sad that the the app did not get a complete look (from our opinion) to be rated.

We are also having an Android version of the app running btw.

I would suggest that in the next contest, state whether you will have sufficient resources in judging mobile applications. Resources such as the availability of the mobile phones, and the models of them. Since the contest rules said any platform, I was actually thinking of building a robot that can etch laser on the wall showing the current activities of the congressmen. Oh well, that went a bit too far :)

Thanks again!

*It’s an open source iPhone app with LAMP backend. I will update more on details later…

iPhone Mobile, iPhone , , , , ,

How to detect shake motion in Android – part I

April 17th, 2009

Gesture/Motion-based detection is fast becoming an integral part of many mobile applications.

One neat usage of it is to shake to erease.  The first one I’ve encountered is SketchUp from the early days of jailbreak iPhone.  Then there are shake to delete done-items on your todo/shopping list, etc.

There are many approaches to detect shake motion, one is from ClingMarks.  Basically it calculates the total delta (changes) in all 3 axises: x, y and z between the current even time and the previous one, and divide by the time elapsed to find its psudo-velocity.  (I call it psudo because it’s not actually a velocity in any direction; it’s more like a mixed-up velocity from 3 axises).  If this velocity is greater than a pre-defined threshold, it’s been viewed as a shake motion.

From the code point of view, you need to implement the SensorListener:

public class ShakeActivity extends Activity implements SensorListener

You will need to acquire a SensorManager:

sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);

And register this sensor with desired flags:

ensorMgr.registerListener(this,
SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_GAME);

In your onSensorChange() method, you determine whether it’s a shake or not:

public void onSensorChanged(int sensor, float[] values) {
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
long curTime = System.currentTimeMillis();
// only allow one update every 100ms.
if ((curTime - lastUpdate) > 100) {
long diffTime = (curTime - lastUpdate);
lastUpdate = curTime;

x = values[SensorManager.DATA_X];
y = values[SensorManager.DATA_Y];
z = values[SensorManager.DATA_Z];

float speed = Math.abs(x+y+z – last_x – last_y – last_z) / diffTime * 10000;

if (speed > SHAKE_THRESHOLD) {
Log.d(“sensor”, “shake detected w/ speed: ” + speed);
Toast.makeText(this, “shake detected w/ speed: ” + speed, Toast.LENGTH_SHORT).show();
}
last_x = x;
last_y = y;
last_z = z;
}
}
}

The shake threshold is defined as:

private static final int SHAKE_THRESHOLD = 800;

This is pretty straightforward. So if your app just simply needs a shake motion detection, w/o needing to know on which direction it’s shaken, this code is good enough. However, there are situations where a non-shake motion would be detected as shake due to the fact that the formula is not actually the correct or should I say a precise formula for determining the shake motion. I call this a coarse-grain approach.

In my next post, I will show you a more fine-grain approach, something I learned from iPhone SDK programming :)

You can download this sample here

Happy Coding!

Android Shogun Android, Mobile, iPhone , , ,

How to implement Swipe action in Android

April 16th, 2009

To implement swipe action in Android, such as the one used in iPhone homescreen unlock, actually Android SDK provides native support for gestures. Swipe is actually called Fling ^_^

You will need to extend SimpleOnGestureListener to implement your own handling on swipe/fling action:

class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
}

To determine if it’s a valid swipe, you will need to make sure the fling falls into an almost straight path, with at least certain length of touch duration, so it’s a continuous touch, and with certain velocity of course.

So let’s define some constants:

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

The max off path is to make sure the fling still falls within a somewhat straight path.

If onFling() method, you can do this:

if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
}

The viewFlipper is used to show how fling/swipe make the view animation/transition from one to the other.

At last, you need to make sure in your activity, you catch the gesture event by overriding onTouch() method:

@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
return true;
else
return false;
}

Here’s a screenshot of the view in transition:

Android Swipe View Flipper in Action

Android Swipe View Flipper in Action

The sample source is attached here.

Android Shogun Android, Mobile , , , ,

Porting Android to Beagle Board

April 15th, 2009

Recently I got a Beagle Board rev C2. It’s a pretty nice hardware piece:
Beagle Board Hareware Specs

embinux has done a pretty good job of porting android to beagle board, and made it open source, here’s the link for the guide to port android.

Using Ubuntu, first compile the kernel, it’s pretty easy. You will need to install git and git-core if you haven’t used git before.

Then clone the git for android, and then compile. The source for android comes down to about 2.7GB. So prepare for a length download. Also note, you need at least 1GB~1.5GB of RAM to actually compile android. The JVM during compilation will eat up a lot of the RAM. If you don’t have sufficient RAM, the compilation will stuck at a random point during the process and never finish. I’ve encountered this problem on 2 different machines and finally switched to a 4GB MacBook 467 to finished the compilation.

Then apply the patches stated in the above porting guide.
Make a bootable SD card following instruction here
Partition 1 is for the uImage and boot loader; partition 2 is for the actual android file system.

Boot up the beagle board w/o inserting the SD card, then at prompt (using minicom/kermit under ubuntu or Tera Term/Hyper Terminal under windows), type in:
mmcinit // init mmc
fatload mmc 0 0×80300000 uImage // load uImage into memory address of 0×80300000
set boot arguments:
setenv bootargs console=ttyS2,115200n8 root=/dev/nfs rw nfsroot=192.168.1.5:/data/target ip=192.168.1.1::255.255.255.0 nolock,rsize=1024,wsize=1024 rootdelay=2
video=omapfb:mode:1280×720@50 init=/init
bootm 0×80300000 // boot up the loaded uImage

If everything goes well, u should see Android booting up ^_^

Android Shogun Android , ,

Android: programmatically toggle wifi on/off

April 15th, 2009

To toggle wifi within your application, you will first need the following permissions:
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.WAKE_LOCK

Then in your code, you need to get an WifiMananger:

wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

To toggle wifi on/off:

if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
} else {
wifiManager.setWifiEnabled(true);
}

That’s it ^_^! It’s really simple!
You can download the sample project here

Android Shogun Android, Mobile ,

Install Android Cupcake on Nokia N800

April 1st, 2009

NITdroid is a kernel and userspace port from scratch of the Android operating system (by Google and the Open Handset Alliance) to the NITs hardware. It is a software alternative to the Maemo platform that ships with the Internet Tablets.

This project is an ongoing effort to make Android usable/useful on NIT devices (N770, N800, N810, N810WE).

You can follow a pretty good installation shell script here to do everything:
http://www.internettablettalk.com/forums/showthread.php?t=25736

I encountered a few problems and finally got it working, here’s my comment on the above thread:

I’ve successfully flashed my N800 with NITdroid. I’m a newbie in the Linux world so I will offer a few of my findings and mistakes so that others might find useful:
*one problem with open source stuff is lack of documentation or I should say thorough documentation.

In the nitdroid_complete.sh:
“echo NOTE: This program should NOT be run as root.
echo It has specific parts that need to run as root.”
What does this mean? confusing huh? What I found out is that… I’m logged in as my own username, but the shell script uses sudo (so the user will be root after the sudo command). There’s this $USER variable that refers to the current user. So essentially I’m running part of the script on my username/Desktop while other stuff is running on root/Desktop, one way or another. An easy fix is to replace $USER with your current username in the .sh file. Save and run as: sudo ./nitdroid_complete.sh so everything will be in your own home / Desktop folders.

I have this N800 from the early days so the internal SDK card (the one besides the battery) has only 128MB of memory. I thought I should flash/install the OS into the external SD card since the internal one is less than 512MB. So that’s my mistake #2.
Make sure you use the internal SD w/ at least 512MB of RAM and remove the external SD. My internal SD shows as /dev/sdc1 and the external shows as /dev/sdd1 if plugged in.

First boot of android, showing a few force close exception due to MMS, Alarm, etc.
Then black screen. Took out battery and reboot, much better now. Wifi works like a charm. However, the soft keyboard crashes all the time. So install this one instead:
http://code.google.com/p/netgents/

Now I got some hacking to do on it, besides my G1… ^_^

Thanks NITdroid team!!!

Android Shogun Android, Mobile , , , , ,