Example usage for android.view MotionEvent getAction

List of usage examples for android.view MotionEvent getAction

Introduction

In this page you can find the example usage for android.view MotionEvent getAction.

Prototype

public final int getAction() 

Source Link

Document

Return the kind of action being performed.

Usage

From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float eventX = event.getX();
    final float eventY = event.getY();
    int degrees;// w w  w.  ja v  a  2  s  . co  m
    Timepoint value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mInputEnabled) {
            return true;
        }

        mDownX = eventX;
        mDownY = eventY;

        mLastValueSelected = null;
        mDoingMove = false;
        mDoingTouch = true;
        // If we're showing the AM/PM, check to see if the user is touching it.
        if (!mIs24HourMode) {
            mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
        } else {
            mIsTouchingAmOrPm = -1;
        }
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT
            // in case the user moves their finger quickly.
            mController.tryVibrate();
            mDownDegrees = -1;
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm);
                    mAmPmCirclesView.invalidate();
                }
            }, TAP_TIMEOUT);
        } else {
            // If we're in accessibility mode, force the touch to be legal. Otherwise,
            // it will only register within the given touch target zone.
            boolean forceLegal = mAccessibilityManager.isTouchExplorationEnabled();
            // Calculate the degrees that is currently being touched.
            mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle);
            Timepoint selectedTime = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false);
            if (mController.isOutOfRange(selectedTime, getCurrentItemShowing()))
                mDownDegrees = -1;
            if (mDownDegrees != -1) {
                // If it's a legal touch, set that number as "selected" after the
                // TAP_TIMEOUT in case the user moves their finger quickly.
                mController.tryVibrate();
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mDoingMove = true;
                        mLastValueSelected = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false);
                        mLastValueSelected = roundToValidTime(mLastValueSelected, getCurrentItemShowing());
                        // Redraw
                        reselectSelector(mLastValueSelected, true, getCurrentItemShowing());
                        mListener.onValueSelected(mLastValueSelected);
                    }
                }, TAP_TIMEOUT);
            }
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (!mInputEnabled) {
            // We shouldn't be in this state, because input is disabled.
            Log.e(TAG, "Input was disabled, but received ACTION_MOVE.");
            return true;
        }

        float dY = Math.abs(eventY - mDownY);
        float dX = Math.abs(eventX - mDownX);

        if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) {
            // Hasn't registered down yet, just slight, accidental movement of finger.
            break;
        }

        // If we're in the middle of touching down on AM or PM, check if we still are.
        // If so, no-op. If not, remove its pressed state. Either way, no need to check
        // for touches on the other circle.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            mHandler.removeCallbacksAndMessages(null);
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            if (isTouchingAmOrPm != mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPmPressed(-1);
                mAmPmCirclesView.invalidate();
                mIsTouchingAmOrPm = -1;
            }
            break;
        }

        if (mDownDegrees == -1) {
            // Original down was illegal, so no movement will register.
            break;
        }

        // We're doing a move along the circle, so move the selection as appropriate.
        mDoingMove = true;
        mHandler.removeCallbacksAndMessages(null);
        degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle);
        if (degrees != -1) {
            value = roundToValidTime(getTimeFromDegrees(degrees, isInnerCircle[0], false),
                    getCurrentItemShowing());
            reselectSelector(value, true, getCurrentItemShowing());
            if (value != null && mLastValueSelected != null && !mLastValueSelected.equals(value)) {
                mController.tryVibrate();
                mLastValueSelected = value;
                mListener.onValueSelected(value);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (!mInputEnabled) {
            // If our touch input was disabled, tell the listener to re-enable us.
            Log.d(TAG, "Input was disabled, but received ACTION_UP.");
            mListener.enablePicker();
            return true;
        }

        mHandler.removeCallbacksAndMessages(null);
        mDoingTouch = false;

        // If we're touching AM or PM, set it as selected, and tell the listener.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            mAmPmCirclesView.setAmOrPmPressed(-1);
            mAmPmCirclesView.invalidate();

            if (isTouchingAmOrPm == mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm);
                if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) {
                    Timepoint newSelection = new Timepoint(mCurrentTime);
                    if (mIsTouchingAmOrPm == AM)
                        newSelection.setAM();
                    else if (mIsTouchingAmOrPm == PM)
                        newSelection.setPM();
                    newSelection = roundToValidTime(newSelection, HOUR_INDEX);
                    reselectSelector(newSelection, false, HOUR_INDEX);
                    mCurrentTime = newSelection;
                    mListener.onValueSelected(newSelection);

                }
            }
            mIsTouchingAmOrPm = -1;
            break;
        }

        // If we have a legal degrees selected, set the value and tell the listener.
        if (mDownDegrees != -1) {
            degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle);
            if (degrees != -1) {
                value = getTimeFromDegrees(degrees, isInnerCircle[0], !mDoingMove);
                value = roundToValidTime(value, getCurrentItemShowing());
                reselectSelector(value, false, getCurrentItemShowing());
                mCurrentTime = value;
                mListener.onValueSelected(value);
                mListener.advancePicker(getCurrentItemShowing());
            }
        }
        mDoingMove = false;
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.bright.cloudutils.view.ResideLayout.java

@SuppressLint("ClickableViewAccessibility")
@Override//w w w  .  ja v a  2s .c  o m
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    if (!mCanSlide) {
        return super.onTouchEvent(ev);
    }

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (isDimmed(mSlideableView)) {
            final float x = ev.getX();
            final float y = ev.getY();
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mDragHelper.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) {
                // Taps close a dimmed open pane.
                closePane();
                break;
            }
        }
        break;
    }
    }

    return true;
}

From source file:com.albedinsky.android.ui.widget.SearchView.java

/**
 */// w w  w .  ja va2 s.  c o  m
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    // SearchView is expected to be used mainly above or at the place of toolbar so it will handle
    // touch events like the Toolbar widget.
    final int action = event.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_DOWN) {
        this.mEatingTouch = false;
    }
    if (!mEatingTouch) {
        final boolean handled = super.onTouchEvent(event);
        if (action == MotionEvent.ACTION_DOWN && !handled) {
            this.mEatingTouch = true;
        }
    }
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        this.mEatingTouch = false;
    }
    return true;
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

@SuppressLint("ClickableViewAccessibility")
@Override//  w ww  .  j  ava  2  s. c  om
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
        case ACTION_DOWN:
            // First, disable the Parent from intercepting the touch
            // event
            if (null != parent) {
                parent.requestDisallowInterceptTouchEvent(true);
            } else {
                LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
            }

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case ACTION_CANCEL:
        case ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (null != rect) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}

From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java

/*****************************  Activity Methods  ********************************
 * //from ww w  .  j  a v  a  2 s .  com
 *
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    controllerActContext = this;

    AnalyticsUtils.getInstance(this).trackPageView("/Controllers");

    /**
     * The handler in this case only gets the list of active controllers
     * then creates a swipeable tab-view for each.
     */
    mHandler = new NotifyingAsyncQueryHandler(getContentResolver(), this);

    /**
     * The main view is a left/right scroll button a title and a workspace below it for content
     */
    setContentView(R.layout.activity_controllers);
    mLeftIndicator = findViewById(R.id.indicator_left);
    mWorkspaceTitleView = (TextView) findViewById(R.id.controller_ws_title);
    mRightIndicator = findViewById(R.id.indicator_right);
    mWorkspace = (Workspace) findViewById(R.id.workspace);

    getActivityHelper().setupActionBar("empty", 0);

    /**
     * Add click listeners for the scroll buttons.
     */
    mLeftIndicator.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if ((motionEvent.getAction() & MotionEventUtils.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                mWorkspace.scrollLeft();
                return true;
            }
            return false;
        }
    });
    mLeftIndicator.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mWorkspace.scrollLeft();
        }
    });

    mRightIndicator.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if ((motionEvent.getAction() & MotionEventUtils.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                mWorkspace.scrollRight();
                return true;
            }
            return false;
        }
    });
    mRightIndicator.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mWorkspace.scrollRight();
        }
    });

    /**
     * Need at least one tab-view for the next step to continue
     * so put a dummy one in.  We'll swap this out when we get real data.
     */
    setupCtlr(new Ctlr(), null);

    /**
     * Set the scroll listener for the workspace
     */
    mWorkspace.setOnScrollListener(new Workspace.OnScrollListener() {
        public void onScroll(float screenFraction) {
            updateWorkspaceHeader(Math.round(screenFraction));
        }
    }, true);

    /**
     * Interface to the database which is passed into the remoteExecutor.  Is there an advantage to
     * having a centralized one rather than each getting there own???  Might want to look at this more.
     * Seems like the answer is that you need the context to get the resolver
     */
    dbResolverControllerAct = getContentResolver();

    /**
     * Setup stuff below for the ApexExecutor that will handle the spinner-select and outlet change function
     */

    /**
     * helper class for defaultHttpClient seen below
     */
    final HttpClient httpClient = getHttpClient(this);

    /**
     * Create the executor for the controller of choice.  Now it is just the apex but I can see using
     * other ones like the DA.  Pass in the http client and database resolver it will need to do its job.
     */
    mRemoteExecutor = new ApexExecutor(this, httpClient, dbResolverControllerAct);

    /** 
     * For the status update messages from the syncService thread
     */
    statusIntentReceiver = new MyIntentReceiver();
}

From source file:com.base.view.slidemenu.SlideMenu.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final float x = event.getX();
    final float y = event.getY();
    final int currentState = mCurrentState;

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;//from w  w w.j av a  2 s.  co m
        mPressedY = y;
        mIsTapInContent = isTapInContent(x, y);
        mIsTapInEdgeSlide = isTapInEdgeSlide(x, y);

        if (mIsTapInContent) {
            mScroller.abortAnimation();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        mVelocityTracker.addMovement(event);

        if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) {
            return false;
        }

        if (Math.abs(x - mPressedX) >= mTouchSlop && mIsTapInContent && currentState != STATE_DRAG) {
            getParent().requestDisallowInterceptTouchEvent(true);
            setCurrentState(STATE_DRAG);
        }
        if (STATE_DRAG != currentState) {
            mLastMotionX = x;
            return false;
        }
        drag(mLastMotionX, x);
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        if (STATE_DRAG == currentState) {
            mVelocityTracker.computeCurrentVelocity(1000);
            endDrag(x, mVelocityTracker.getXVelocity());
        } else if (mIsTapInContent && MotionEvent.ACTION_UP == action) {
            performContentTap();
        }
        mVelocityTracker.clear();
        getParent().requestDisallowInterceptTouchEvent(false);
        mIsTapInContent = mIsTapInEdgeSlide = false;
        break;
    }
    return true;
}

From source file:co.vn.e_alarm.customwiget.SlidingLayer.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
        return false;
    }/*from  w ww. j ava2s  .  co  m*/

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        /*
         * Return event touch to children view.
         */
        mIsDragging = false;
        mIsUnableToDrag = false;

        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsDragging) {
            return true;
        } else if (mIsUnableToDrag) {
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            break;
        }

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        if (pointerIndex == -1) {
            mActivePointerId = INVALID_POINTER;
            break;
        }

        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float dx = x - mLastX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float dy = y - mLastY;
        final float yDiff = Math.abs(y - mLastY);

        if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) {
            // mIsDragging = true;
            mLastX = x;
            setDrawingCacheEnabled(true);
        } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) {
            // mIsDragging = true;
            mLastY = y;
            setDrawingCacheEnabled(true);
        }
        float matY = (float) Math.abs(corY - ev.getRawY());
        float matX = (float) Math.abs(corX - ev.getRawX());
        if (matY - 100 > 0) {
            mIsDragging = true;
            setDrawingCacheEnabled(true);
            // Dang di chuyen len
        } else if (matX - 100 > 0) {
            mIsDragging = false;
        }
        if (matY == 0) {
            setDrawingCacheEnabled(false);
        }

        /*   }else{
        mIsDragging = false;
        setDrawingCacheEnabled(true);
           }*/
        /* }else if(corX +150 > ev.getRawX()){
        mIsDragging = false;
        setDrawingCacheEnabled(true);
        }else if(corX +150 < ev.getRawX()){
        mIsDragging = false;
        setDrawingCacheEnabled(true);
        }*/
        // double corY = ev.getY();

        break;

    case MotionEvent.ACTION_DOWN:
        corX = ev.getRawX();
        corY = ev.getRawY();
        mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK
                : MotionEventCompat.ACTION_POINTER_INDEX_MASK);
        mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId);
        mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId);
        if (allowSlidingFromHereX(ev, mInitialX)) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // If nobody else got the focus we use it to close the layer
            return super.onInterceptTouchEvent(ev);
        } else if (allowSlidingFromHereY(ev, mInitialY)) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // If nobody else got the focus we use it to close the layer
            return super.onInterceptTouchEvent(ev);
        } else {
            mIsUnableToDrag = true;
        }
        break;
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

    if (!mIsDragging) {
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        }
        mVelocityTracker.addMovement(ev);
    }

    return mIsDragging;
}

From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    checkFirstLaunch();/*from  w w  w  .jav  a 2 s.  com*/

    if (isFirstLaunch) {
        setDefaultPreferences();
    }

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.capture);
    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    cameraButtonView = findViewById(R.id.camera_button_view);
    resultView = findViewById(R.id.result_view);

    statusViewBottom = (TextView) findViewById(R.id.status_view_bottom);
    registerForContextMenu(statusViewBottom);
    statusViewTop = (TextView) findViewById(R.id.status_view_top);
    registerForContextMenu(statusViewTop);

    handler = null;
    lastResult = null;
    hasSurface = false;
    beepManager = new BeepManager(this);

    // Camera shutter button
    if (DISPLAY_SHUTTER_BUTTON) {
        shutterButton = (ShutterButton) findViewById(R.id.shutter_button);
        shutterButton.setOnShutterButtonListener(this);
    }

    ocrResultView = (TextView) findViewById(R.id.ocr_result_text_view);
    registerForContextMenu(ocrResultView);
    translationView = (TextView) findViewById(R.id.translation_text_view);
    registerForContextMenu(translationView);

    progressView = (View) findViewById(R.id.indeterminate_progress_indicator_view);

    cameraManager = new CameraManager(getApplication());
    viewfinderView.setCameraManager(cameraManager);

    // Set listener to change the size of the viewfinder rectangle.
    viewfinderView.setOnTouchListener(new View.OnTouchListener() {
        int lastX = -1;
        int lastY = -1;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = -1;
                lastY = -1;
                return true;
            case MotionEvent.ACTION_MOVE:
                int currentX = (int) event.getX();
                int currentY = (int) event.getY();

                try {
                    Rect rect = cameraManager.getFramingRect();

                    final int BUFFER = 50;
                    final int BIG_BUFFER = 60;
                    if (lastX >= 0) {
                        // Adjust the size of the viewfinder rectangle. Check if the touch event occurs in the corner areas first, because the regions overlap.
                        if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top left corner: adjust both top and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top right corner: adjust both top and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom left corner: adjust both bottom and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom right corner: adjust both bottom and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BUFFER && currentX <= rect.left + BUFFER)
                                || (lastX >= rect.left - BUFFER && lastX <= rect.left + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting left side: event falls within BUFFER pixels of left side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BUFFER && currentX <= rect.right + BUFFER)
                                || (lastX >= rect.right - BUFFER && lastX <= rect.right + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting right side: event falls within BUFFER pixels of right side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.top + BUFFER && currentY >= rect.top - BUFFER)
                                || (lastY <= rect.top + BUFFER && lastY >= rect.top - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting top side: event falls within BUFFER pixels of top side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.bottom + BUFFER && currentY >= rect.bottom - BUFFER)
                                || (lastY <= rect.bottom + BUFFER && lastY >= rect.bottom - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting bottom side: event falls within BUFFER pixels of bottom side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        }
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "Framing rect not available", e);
                }
                v.invalidate();
                lastX = currentX;
                lastY = currentY;
                return true;
            case MotionEvent.ACTION_UP:
                lastX = -1;
                lastY = -1;
                return true;
            }
            return false;
        }
    });

    isEngineReady = false;
    aq = new AQuery(this);
    beerQuery = new BeerQuery();

}

From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled)
        return false;

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (DEBUG)/*from   www. j a va 2s.c om*/
        if (action == MotionEvent.ACTION_DOWN)
            Log.v(TAG, "Received ACTION_DOWN");

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP
            || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) {
        endDrag();
        return false;
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        determineDrag(ev);
        break;
    case MotionEvent.ACTION_DOWN:
        int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        if (mActivePointerId == INVALID_POINTER)
            break;
        mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
        mLastMotionY = MotionEventCompat.getY(ev, index);
        if (thisTouchAllowed(ev)) {
            mIsBeingDragged = false;
            mIsUnableToDrag = false;
            if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
                mQuickReturn = true;
            }
        } else {
            mIsUnableToDrag = true;
        }
        break;
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

    if (!mIsBeingDragged) {
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        }
        mVelocityTracker.addMovement(ev);
    }
    return mIsBeingDragged || mQuickReturn;
}

From source file:aksha.upcomingdemo.HorizontalListView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Detect when the user lifts their finger off the screen after a touch
    if (event.getAction() == MotionEvent.ACTION_UP) {
        // If not flinging then we are idle now. The user just finished a finger scroll.
        if (mFlingTracker == null || mFlingTracker.isFinished()) {
            setCurrentScrollState(OnScrollStateChangedListener.ScrollState.SCROLL_STATE_IDLE);
        }/*from  w  w  w .  j  a va  2  s . c o  m*/

        // Allow the user to interact with parent views
        requestParentListViewToNotInterceptTouchEvents(false);

        releaseEdgeGlow();
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
        unpressTouchedChild();
        releaseEdgeGlow();

        // Allow the user to interact with parent views
        requestParentListViewToNotInterceptTouchEvents(false);
    }

    return super.onTouchEvent(event);
}