Archive for May, 2009

Change Adobe AIR window size dynamically

May 28, 2009

This changes your AIR app (main app’s window) to 100 px by 100 px.

Application.application.width = 100;
Application.application.height = 100;

Android SDK 1.5 with Eclipse 3.4 on Ubuntu 8.x

May 23, 2009

1. I am on Ubuntu 8.10 which seems to only support Eclipse 3.2 from Synaptic Package Manager. Since I installed both Eclipse and the IcedTea OpenJDK/JRE from Synaptic, I found out later that Android Dev tool actually needed the Sun JDK in order to use its Layout Editor (otherwise you won’t be able to use Android Layout Editor to edit xml files under res/layout folder. The error was java.awt.font wasn’t found something like that.) What I ended up doing was I uninstalled both Eclipse and IcedTea distribution of JDK (openjdk-6-jdk) from Synaptic, otherwise the newly updated Eclipse will continue to use openjdk which prevented me from using Android Layout Editor.

2. Install Sun’s Java (both jre and jdk).

Every step described in the above article worked for me except I couldn’t get the first step work which was:

sudo apt-get install sun-java6-jdk

apt-get said it could not locate sun-java6-jdk something like that.

So I went with this:

sudo aptitude search sun-java

Which told also me it wasn’t able to find sun-java first time I ran it. But after I did

sudo aptitude

and ->Actions->Update package list

I got to install sun java:

sudo aptitude install sun-java6-jre sun-java6-jdk sun-java6-plugin sun-java6-fonts

I was very happy with aptitude as compared to Synaptic package manager because of the exotic flavor of the former. Besides it seems to be more stable and responsive to me based on my judgement.;)

However, during the adventure, I got confused as to how I could single/full-heartedly accept the license agreement which showed up as a pop up within shell. It turned out  I had to maximize the whole thing and scroll down and use TAB key to select “OK” in order to advance.

After all this settled down, I rebooted Ubuntu and made sure that icedTea no longer took over the java world:

java -version

I get

java version "1.6.0_13"

Java(TM) SE Runtime Environment (build 1.6.0_13-b03)

Java HotSpot(TM) Server VM (build 11.3-b02, mixed mode)

3. Install and setup Eclipse 3.4.

I manually downloaded Eclipse 3.4 from their site and unzip it into /usr/lib folder. Android dev page recommends Eclipse IDE for Java EE Developers, Eclipse IDE for Java Developers, or Eclipse for RCP/Plug-in Developers.

You may want to temporarily change the owner of the/usr/lib folder to yourself instead of root:

chown <user> /usr/lib

After you are done, go to Eclipse->Help->About Eclipse Platform->Configuration Details, you can see Eclipse is now using the Sun jdk/jre:

java.library.path=/usr/lib/jvm/java-6-sun- SE Runtime Environment




4. Install Android Development Tool for Eclipse. I personally found/suspected that the http url is faster/more stable(?) than the https one, esp if you are in slow connection. If you are behind some firewall, you may want to set Eclipse’s proxy. Eclispe->Window->Preferences->General->Network Connections->…

5. Configure BASH to export the JAVA_HOME env variable, as well as path to Eclipse like so:

sudo gedit /home/<user>/.bashrc

# ~~~~~~~~~~~~~~~~~ JAVA (JDK,JRE) ~~~~~~~~~~~~~~~~~~~~~

export JAVA_HOME=’/usr/lib/jvm/java-6-sun-′

export ANDROID_HOME=’/usr/lib/android-sdk-linux_x86-1.5_r2′


alias eclipse=’java -jar /usr/lib/eclipse/startup.jar’

6. (Optional) Configure Eclipse JRE to the one we just installed from Sun. Eclipse->Window->Preferences->Java->Installed JREs->Add->Standard VM->/usr/lib/jvm/java-6-sun- And check this new one we just added.

7. You may want to run

Eclipse -clean

if you had some trouble with it during the process.

8. I guess that’s pretty much about it(?)!

9. Have a great weekend/holiday!

Android on Eclipse 101: Google MapView

May 21, 2009

In order to get MapView, you will need to first have your application target Google API 1.5. Then you would abtain a google maps API for your android application:

1.  Generating MD5 Fingerprint of the SDK Debug Certificate . This is under Windows XP:

cd C:\Program Files\Java\jdk1.6.0_13\bin
keytool -list -alias androiddebugkey -keystore “C:\Documents and Settings\username\.android\debug.keystore” -storepass android -keypass android
I got something like:
androiddebugkey, May 18, 2009, PrivateKeyEntry,
Certificate fingerprint (MD5): 94:1E:43:49:87:73:BB:E6:A6:88:D7:20:F1:8E:B5:98
Then I go to here:
to get the api key.
2. Now you can get the map view up and running. The catch is that it  seems that you need to use/subclass MapActivity in order to use a MapView. The MapView could be mixed up with other views (not necessarily need to be the top node in your view layout). Also you need to declare in your manifest.xaml that you are using google map and internet permission. For example:

<!–Manifest xml–>
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”;
<uses-sdk android:minSdkVersion=”4″
android:targetSdkVersion=”4″ />
<application android:icon=”@drawable/icon” android:label=”@string/app_name”>
<activity android:label=”@string/app_name” android:name=”MyTestMain”>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
<activity android:name=”.googlemaptest.MapTest1″></activity>
<uses-library android:name=”” />
</application><uses-permission android:name=”android.permission.INTERNET” />

<?xml version=”1.0″ encoding=”utf-8″?>



//import relavent classes
public class MapTest1 extends MapActivity {

WebView mWebView;
MapView mMapView;
protected void onCreate(Bundle savedInstanceState) {

mWebView = (WebView) findViewById(;

mMapView = (MapView) findViewById(;

protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;

Android on Eclipse 101: “Instrument TestRunner not specified”

May 20, 2009

Hello Android,

I started poking into Android this Monday. I installed Android SDK and Eclipse  for JEE developers v3.4.2, following the instructions at the official Android dev site. “Hello Android” went pretty smoothly as I recall except for some minor confusions when I launched the project. I think it was something in regards to the “Android virtual device” but somehow I got thorough. Today when I tried to do the “Notepad” tutorial I got the same error. It was something like this:

“ERROR: Application does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner” 

I googled this post here which seems to post back when the 1.5pre was out. And it turned out to be much easier with 1.5. So here is the trick.

The problem is that Eclipse doesn’t recoginize the AVD I created under DOS commandline:

android create avd –target 2 –name my_avd

What I did was I clicked the little mobile phone icon (the 16 bit color style somehow reminds me of DOOM II? on DOS) on the toolbar under the menue which says “Opens Android Virtual Device (AVD) Manager” (or alternatively you can go to Window->Android AVD Manager) -> “Create AVD” -> “Finish”.

From then on, the compiler hasn’t complained about the InstrumentationTestRunner.

Convert Excel file with unicode characters to MySQL

May 17, 2009

Scenario: It takes you the whole morning to try to get data in an Excel file into MySQL table. You found out there were special characters such as “5µm” inside it.

Solution: Save the file as .txt (Tab delimited or MS-DOS or Machintosh) and make sure it’s encoded in utf-8, etc.


  1. Create table in MySQL db using the sample (with only headers trimming off the content) csv file saved from the .xls file;
  2. Save the .xls as Tab delimited .txt;
  3. Load data into MySQL using the following statement (as produced on Windows for tab delimited, double quote inclosing fields.) See here for details:
  4. LOAD DATA LOCAL INFILE '/STUFF/Projects/_tmp/reference.txt' INTO TABLE reference

  5. Clean up the table: You may need to delete the some rows if the Excel table/sheet headers appear as data rows, etc.


May 17, 2009

This is a nice little online tool that allows you to convert *.dbf or *.csv to MySQL “create table/import” statements.

How to get scrollbars inside background image in Container

May 11, 2009

Unlike a List based component, in which scrollbars always appear _inside_ a background image provided you have one, in a mx:Container subclassed component, such as a Canvas, the scrollbars always go _outside_ of your background image.

So say if the Canvas has a width of 200 px, the background image has a width of 200 px when there is no scrollbar. If the scrollbar is 16 pixels wide, the background image would become 200 – 16 = 184 px, as opposed to staying 200px wide. Sort of reminisentant of the DOM box model in IE vs. that in Firebox?

Solution? use nested containers. Say one called “innerBox” and the other “outerBox”:

For “outerBox”, you have full scaled background image and scroll policy to “off“;

For “innerBox”, you have background image set to null and scroll policy to “on“, plus, set both percentage width and percentage height to 100%. You may also want to setbackgroundAttachment to “fixed“;

See the sample CSS below:

background-image: Embed(source=”img/gradientPaneBkg.png”,
scaleGridTop=”7″, scaleGridBottom=”96″,
scaleGridLeft=”7″, scaleGridRight=”148″);
background-size: “100%”;
background-image: null;
vertical-scroll-bar-style-name: “myScrollBarStyle”;
thumbSkin: Embed(source=”assets/scrollThumb_r.png”,
scaleGridLeft=”5″, scaleGridTop=”6″,
scaleGridRight=”7″, scaleGridBottom=”46″);
trackSkin: Embed(source=”assets/null_17_18.png”,
scaleGridLeft=”4″, scaleGridTop=”4″, scaleGridRight=”10″, scaleGridBottom=”170″);
upArrowSkin: Embed(source=”assets/null_17_18.png”);
downArrowSkin: Embed(source=”assets/null_17_18.png”);

Now here is the catch: since we have switched off the scrollbar on our component, each time you are are dealing with scrolling, you probably meant to deal with the innerBox’s scrolling. Like so:

override public function set verticalScrollPosition(value:Number):void
innerBox.verticalScrollPosition = value;
override public function get verticalScrollPosition():Number
return innerBox.verticalScrollPosition;

SmartSVN vs. TortoiseSVN

May 9, 2009

I just installed SmartSVN (version 6) today and I am very happy with it so far. It was much easier than I thought when migrating from TortoisSVN. Currently I still have tortoise installed but I probably will ditch it in the future. (Sorry tortoise!) Here are some comparisons (opinions may be inaccurate since this is my first couple of hours of using SmartSVN):

The first three are “thumbs-ups” and the last three are “less satisfactory” (Some customers are never happy, even it’s FREE!):

  • Project manager is the central hub for managing projects. This makes it easy for you to access all your working copies in one place without hunting around/drilling down into your filesystem, if you have multiple working copies scattered around.
  • “Project->Create From Directory” allows you to register existing working copies on your filesystem with the SVN Project Manager. The cool thing is you can keep on this registration process until all your working copies end up into the Project Manager view.
  • With Project Manager, you can “group” your projects. Go to “Project->Project Manager->Create Group” to create a new entry for grouping your projects.
  • In the most current version (v6), You cannot drag/drop inside the project manager tree view to group/re-group/re-order the projects; instead you need to use the “Move Up/Down” buttons, located on the right side of the tree view, along with the “<placeholder>” (which appended to the end of each group, on the left part of the tree view) and “Sorted project area, …”(which serves as the entry point where you insert your project, also on the left part). It’s kinda old school (similar to the way you traverse a tree structure using cursor) but once you figure it out, it’s no big deal.
  • SmartSVN is integrated with the Shell/filesystem, meaning if you have a working copy in your hdd, SmartSVN provides right-click/context menu for you to access the commands the way you do on TortoiseSVN. But there is no icon overlays as TortoiseSVN(?).
  • I kinda miss the big tortoise spinning around thing, when you export something directly form your repository. but i think i can live without it;)

“backgroundAttachment” for mx:Container

May 7, 2009

It seems that mx:Container and subclasses have a style named “backgroundAttachment” which has a value of either “fixed” or “scroll“. “fixed” means the background image (if there is any) will be fixed with regard to the viewport; “scroll” means the background image will scroll with the content (fixed with the content as opposed to the viewport).