Archive for May, 2012

Professional Android 4 Application Development – by Reto Meier

May 29, 2012 3 comments


Cover: Professional Android 4 Application Development

Cover: Professional Android 4 Application Development

Cover: Professional Android 4 Application Development


* ISBN: 978-1-1181-0227-5
* Paperback
* 864 pages
* May 2012
* Format: hard-copy, ebook
Pete Houston
Categories: Books & Materials Tags:

Common array clone mistake in Java

May 29, 2012 1 comment

While working on my application, I’ve found one bug whereas the cause is very common in practice.

Assuming, you have an two dimensional array storing data, and you want to copy or clone it to another storage variable, this is what somebody often does:

boolean data[][] = ... // original data

// common use of clone()
boolean copied[][] = data.clone();

The problem is that, it’s not gonna working as a new fresh copy data but a reference to the original data.
The fix for this is pretty much straight forward.

public static boolean[][] cloneData(boolean[][] from) {
	boolean[][] to = new boolean[from.length][];
	for (int i = 0; i < from.length; i++) {
		to[i] = from[i].clone();
	return to;

Pete Houston

Categories: Tricks & Tips Tags: ,

Long hours for custom ROMs Resurrection Remix v1.9.1

I’ve been troubling for several hours long to root and flash my SGS2 to Resurrection Remix ICS v1.9.1.

Finally it’s done..lots of cool stuffs to try and start to dig in ICS 4.0.4 environment…

@Samsung Kies: is one of the worst application ever seen; I swear to never use it again!!!

Categories: Of Diary Tags: , ,

Improve finger/multi-touch on ViewGroup

I’ve been working on an application that users can take many touch operations on screen (ViewGroup) like: Click, LongClick, Swipe-Up, Swipe-Down, Fling-Left, Fling-Right, Pinch-In, Pinch-Out, DoubleTap…

However, my application has a problem, that is, the Pinch-In and Fling-Left/-Right process at the same time.

The process is like:


-> (1) GestureListener : TRUE -> fire onFling() , FALSE -> go to (2)

-> (2) ACTION_POINTER_UP (DOWN) -> TRUE/FALSE: return super.onInterceptTouchEvent()

This process somehow makes difficult to Pinch-In. Trouble for 2 days, found a way to improve this:

protected boolean onInterceptTouchEvent(MotionEvent me) {
    // whatever check before...

    // if one finger only
    if(me.getPointerCount() == 1) {
        return super.onInterceptTouchEvent(me);
    } else {
        // do something else
        return false;

This really does the trick.

Pete Houston

Detect screen type and apply the correct orientation to application

Long ago, I had to detect screen type in order to apply correct orientation for my application.

In some devices, the width is smaller than the height, however, some others having the width is greater. As you can see this property clearly in the differences between smartphone and tablets.

This is my code.

public void onCreate(Bundle savedState) {

    if(isScreenLarge()) {
        // width > height, better to use Landscape
    } else {

public boolean isScreenLarge() {
    final int screenSize = getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK;
    return screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE
            || screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE;


Pete Houston

Categories: Tricks & Tips Tags: , ,

Detect when mobile is booted completely

Some applications are designed to run or do something automatically right after the phone is booted, like services…

This is what I use to run services in my applications after boot

public class BootReceiver extends BroadcastReceiver {
    Context mContext;
    private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";

    public void onReceive(Context context, Intent intent) {
        mContext = context;
        String action = intent.getAction();
        if (action.equalsIgnoreCase(BOOT_ACTION)) {
            // do what you need to do here

Pete Houston

Categories: Tricks & Tips Tags: , , ,

Disable vertical scrolling of GridView

May 1, 2012 1 comment

Working on an application, and find a way to disable the annoying vertical scrolling on GridView when users touch and move finger upward. This is the trick I’d like to share you all.

gridview.setOnTouchListener(new OnTouchListener(){

    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_MOVE){
            return true;
        return false;


Interesting, isn’t it?
As you can see, this will handle the ACTION_MOVE, well, no need to care about it anymore. Have fun!

Pete Houston