Wednesday, December 28, 2011

Good jquery plugins

Nice world vecotr map plugin
http://jvectormap.owl-hollow.net/

Picture zoom plugin
http://www.mind-projects.it/projects/jqzoom/demos.php#demo1

Tuesday, December 20, 2011

Prototype of Javascript

Recently I just try to dig my knowledge of JavaScript deeper. Prototype is a very important concept of JavaScript and is the key to program JavaScript in object-oriented way. After reading some articles I did the code snippets for experiment.

Reference articles:
Understand JavaScript Article
OO programming in JavaScript

My experiment code:

<script type="text/javascript">
    function employee(name,jobtitle,born){
       this.name=name;
       this.jobtitle=jobtitle;
       this.born=born;
    }
    var fred=new employee("Fred Flintstone","Caveman",1970);

    employee.prototype.salary=300;

    document.write(fred.name + "'s salary:" + fred.salary);
    document.write('<br/>');

    var jack = new employee("Jack","Developer",1983);
    jack.salary=100;

    document.write("Prototype(defaultsuper class static) salary: " + jack.__proto__.salary);
    document.write('<br/>');
    document.write(jack.name + "'s salary:" + jack.salary);
    document.write('<br/>');

    employee.prototype.aftertax = function(){
        return this.salary * 0.8;
    };

    document.write(jack.name + "'s after tax salary: " + jack.aftertax());
    document.write('<br/>');
</script>

Wednesday, November 9, 2011

Android crash report

There is a great library called "ARCA" for collecting android crashes on the fly.

It is open source. What you need to do is just go to the link below and use it for free and it is super easy!

http://code.google.com/p/acra/

Tuesday, October 25, 2011

Stack and Heap

Understanding the concepts of stack and heap is important for a qualified developer not matter doing .Net or Java or whatever else.

Here is a great article to read about this topic.

http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx

Thursday, October 20, 2011

How to build Android application package (.apk) from the command line using the SDK tools + continuously integrated using CruiseControl.

Original article is in here

Hello all android developers, I just want to share my experience building android apk manually using sdk tools without using Eclipse. My original goal is motivated firstly by the desire to incorporate continuous integration aspect to Android development process and secondly to ditch the ADT eclipse plugin since the plugin auto-build process blocks Eclipse UI if you have large resources, assets in your Android project, and a slow computer like mine. I am using CruiseControl as my continuous integration tool.

Below is one of the many apk build processes:

Build process

Build process

The good thing about building manually your apk is that you don’t have to name your resources directory to res, you can name it anything you want.

You can find ant scripts in: \platforms\android-1.5\templates\android-rules.xml

Step 1: Generate Resource java code and packaged Resources
aapt package -f -M ${manifest.file} -F ${packaged.resource.file} -I ${path.to.android-jar.library} -S ${android-resource-directory} [-m -J ${folder.to.output.the.R.java}]

Step 2: Compile java source codes + R.java
use javac

Step 3: Convert classes to Dalvik bytecodes
use dx.bat
dx.bat –dex –output=${output.dex.file} ${compiled.classes.directory} ${jar files..}

Step 4: Create unsigned APK
use apkbuilder

apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file}

or

apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file} -rf ${source.dir} -rj ${libraries.dir}

-rf = resources required for compiled source files?
-rj = resources required for jar files

Step 6: Generate a key
use keytool

Step 7: Sign APK
use jarsigner

jarsigner -keystore ${keystore} -storepass ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias}

Step 8: Publish
use adb
adb -d install -r ${signed.apk}

Inspecting your APK file:

aapt list -v latest.apk

Open questions:
1. Can you include more than one dex file in the apk?
2. Can you have dex file named other than classes.dex in the apk?
3. Does an apk have to have a packaged resource?

Note: If upon installing your app using adb you see this error code FAILED_INSTALL_DEXOPT then most likely that either you don’t have classes.dex or you don’t have a packaged resource in the apk


See this post

http://asantoso.wordpress.com/2009/09/15/how-to-build-android-application-package-apk-from-the-command-line-using-the-sdk-tools-continuously-integrated-using-cruisecontrol/

Saturday, October 8, 2011

Threads in android UI programming

Two rules:
  1. Do not block the UI thread
  2. Do not access the Android UI toolkit from outside the UI thread
Therefore, only use UI thread message queue to update UI components.

If task is heavy, do the heavy-lift job on another thread and create a callback on UI(main) thread for the worker thread to call back.

A better way is to use AsyncTask straight away.

Thursday, April 7, 2011

Android Activity Life Cycle on different cases

After published a game on market place, I decided to strengthen my knowledge of Android again.

First, start from Activity Life Cycle. Though the developer site of official Android explained the life cycle of activity with a lot text, it is still a little confusing or not clear enough. Thus I test it through by set break points during the whole life cycle. This is the result.

New Start:
onCreate(),
onStart(),
onResume().

Rotate Device:
onSaveInstanceState(),
onPause(),
onStop(),
onDestroy(),
onCreate(),
onStart(),
onRestoreInstanceState(),
onResume().

Other activity overlayed(e.g.Home button pressed,Calls in or other activity opened):
onSaveInstanceState(),
onPause(),
onStop().

Back from other activity(Not destroyed yet):
onRestart(),
onStart(),
onResume().

Back button pressed/finish() called:
onPause(),
onStop(),
onDestroy().

Screen Off:
onSaveInstanceSave(),
onPause().

Screen back on:
onResume().