Code example for Handler

Methods: removeMessagessendEmptyMessageDelayed

0
        if (mFocusAreaSupported && (e.getAction() == MotionEvent.ACTION_UP)) {
            autoFocus(); 
        } else {  // Just show the indicator in all other cases. 
            updateFocusUI(); 
            // Reset the metering area in 3 seconds. 
            mHandler.removeMessages(RESET_TOUCH_FOCUS);
            mHandler.sendEmptyMessageDelayed(RESET_TOUCH_FOCUS, RESET_TOUCH_FOCUS_DELAY);
        } 
 
        return true; 
    } 
 
    public void onPreviewStarted() { 
        mState = STATE_IDLE;
    } 
 
    public void onPreviewStopped() { 
        mState = STATE_IDLE;
        resetTouchFocus(); 
        // If auto focus was in progress, it would have been canceled. 
        updateFocusUI(); 
    } 
 
    public void onCameraReleased() { 
        onPreviewStopped(); 
    } 
 
    private void autoFocus() { 
        Log.v(TAG, "Start autofocus.");
        mListener.autoFocus();
        mState = STATE_FOCUSING;
        // Pause the face view because the driver will keep sending face 
        // callbacks after the focus completes. 
        if (mFaceView != null) mFaceView.pause();
        updateFocusUI(); 
        mHandler.removeMessages(RESET_TOUCH_FOCUS);
    } 
 
    private void cancelAutoFocus() { 
        Log.v(TAG, "Cancel autofocus.");
 
        // Reset the tap area before calling mListener.cancelAutofocus. 
        // Otherwise, focus mode stays at auto and the tap area passed to the 
        // driver is not reset. 
        resetTouchFocus(); 
        mListener.cancelAutoFocus();
        if (mFaceView != null) mFaceView.resume();
        mState = STATE_IDLE;
        updateFocusUI(); 
        mHandler.removeMessages(RESET_TOUCH_FOCUS);
    } 
 
    private void capture() { 
        if (mListener.capture()) {
            mState = STATE_IDLE;