views:

21

answers:

0

The following routine has been working fine and the code has not changed. The layout for the Activity is identical but for unknown reasons the behaviour has changed. I'm wondering if it is my handset memory (HTC Magic). What happens is that the drawn gesture is lost from the GesturesOverlay after leaving the routine, which clears the gesture from the screen. If I do getGesture() after this, the gesture is null.

The workaround below is to put the gesture back if it disappears. Can anyone think of what might cause the GesturesOverlay to lose its gesture?

    public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {
        mGesture = overlay.getGesture();
        AppGlobal.logDebug("Gesture length = %f; overlay threshold = %f.", mGesture.getLength(), LENGTH_THRESHOLD);
        if (mGesture.getLength() < LENGTH_THRESHOLD) {
            overlay.clear(false);
        }
        mDoneButton.setEnabled(true);

        // This block is a fix for my HTC device which suddenly started losing the 
        // gesture from the Overlay after drawing it.
        final GestureOverlayView fixOverlay = overlay;
        fixOverlay.post(new Runnable() {
            public void run() {
                if (fixOverlay.getGesture() == null) {
                    fixOverlay.setGesture(mGesture);
                }
            }
        });
    }

PS I'm not talking about when the gesture length is less than the threshold, which would be logical. The code simply exits from the handler block and on return the GestureOverlayView has no gesture, just as if it had been cleared. It doesn't happen on the emulator, only on my phone.