Tag Archives: android

Windows phone 7 vs Android development

I’ve recently had attended a workshop for Windows phone 7 development. It got me started pretty quickly on WP7 development, and I’ve quickly published my first app Tippon, a tip calculator that can take a picture of the bill and keep track of your dining experiences.Afterwards, I reflected on my development experience vs my app development in Android. In a word, developing for Windows phone 7 have been a pleasure.

Visual studio Express + Expression Blend is an awesome combination of tools. My biggest weakest when it comes to application design have always been visual elements, but I was surprised at how effortless it was to create a great looking app on Expression Blend.

Comparing the development experience with Android, Eclipse is quite disappointing. A lot of designs are done manually, and the emulator is unbearably slow. I truly hope Eclipse can soon catch up to the developing experience provided by the Microsoft platform.

Tagged ,

Android “Fling” Gesture Detection

Had some issues last night trying to get my Android game to detect the fling gesture, basically a click and drag in mouse world.

I had the following code in my little View object.

private GestureDetector gestureDetector;
private View.OnTouchListener gestureListener;// Gesture detection
    gestureDetector = new GestureDetector(new MyGestureDetector());
    gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    };
this.setOnTouchListener(gestureListener);

  * Handle any fling action here
  * @author dracox
  *
  */
 protected class MyGestureDetector extends SimpleOnGestureListener {
  /**
   * We need to capture any user line drawn request here.
   */
  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   //This should only be caring about flings after init
   gameWalls.add(new FireWall(new Point((int)e1.getRawX(), (int)e1.getRawY()), new Point((int)e2.getRawX(), (int)e2.getRawY())));
   return true;
  }
 }

I fired up my emulator, but was not getting any fling action logged. However the onTouch events were been fired off.

Initially I though maybe the emulator couldn’t handle fling event, but after much searching I found the root of the problem.

Apparently, the onDown event was fired off first, which was consumed before it became a “fling”, so I had to override that too on my custom Gesture Detector class.

I was a little puzzled about returning true for the onDown handler, as the API stated return true to consume the event and false to let it pass.

/**
 * Need to let onDown pass through, otherwise it will block the onFling event
 */
 @Override
 public boolean onDown(MotionEvent event) {
 return true;
 }

Now we’re flinging!

Tagged , ,