Example usage for android.view MotionEvent ACTION_DOWN

List of usage examples for android.view MotionEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

To view the source code for android.view MotionEvent ACTION_DOWN.

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has started, the motion contains the initial starting location.

Usage

From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();//from   w  w w  . j  av a  2  s .c  o m
    boolean handled = false;
    if (mReturningToStart && ev.getAction() == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;
    }
    // enable?||??||?View?
    if (isEnabled() && !mReturningToStart && !canChildScrollUp()) {
        handled = onTouchEvent(ev);
    }
    return !handled ? super.onInterceptTouchEvent(ev) : handled;
}

From source file:com.android.mail.browse.ConversationContainer.java

/**
 * Touch slop code was copied from {@link ScrollView#onInterceptTouchEvent(MotionEvent)}.
 *//* w  ww .  j a  va 2 s  .  c  o  m*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mTouchInitialized) {
        mTouchInitialized = true;
    }

    // no interception when WebView handles the first DOWN
    if (mWebView.isHandlingTouch()) {
        return false;
    }

    boolean intercept = false;
    switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_POINTER_DOWN:
        LogUtils.d(TAG, "Container is intercepting non-primary touch!");
        intercept = true;
        mMissedPointerDown = true;
        requestDisallowInterceptTouchEvent(true);
        break;

    case MotionEvent.ACTION_DOWN:
        mLastMotionY = ev.getY();
        mActivePointerId = ev.getPointerId(0);
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);
        final float y = ev.getY(pointerIndex);
        final int yDiff = (int) Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mLastMotionY = y;
            intercept = true;
        }
        break;
    }

    //        LogUtils.v(TAG, "in Container.InterceptTouch. action=%d x/y=%f/%f pointers=%d result=%s",
    //                ev.getActionMasked(), ev.getX(), ev.getY(), ev.getPointerCount(), intercept);
    return intercept;
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/*  ww  w  . j ava 2  s . c  om*/
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;
        if (mTouchMode == TOUCH_MODE_FLINGING) {
            // Catch!
            mTouchMode = TOUCH_MODE_DRAGGING;
            return true;
        }
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
            return true;
        }
    }
    }

    return false;
}

From source file:com.example.SmartBoard.DrawingView.java

public boolean drawPoint(float x, float y, int action, int color, String mode, int brushSize, String clientID) {

    mX = x;//from ww w  . j a v a 2  s.  co  m
    mY = y;

    Path path = clientPaths.get(clientID);
    if (path == null) {
        path = new Path();
        clientPaths.put(clientID, path);
    }
    drawPathRecv = path;

    setDrawPaintRecv(color, mode, brushSize);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        drawPathRecv.moveTo(x, y);
        break;
    case MotionEvent.ACTION_MOVE:
        drawPathRecv.lineTo(x, y);
        break;
    case MotionEvent.ACTION_UP:
        drawCanvas.drawPath(drawPathRecv, drawPaintSender);
        drawPathRecv.reset();
        break;
    case CLEAR_SCREEN:
        drawCanvas.drawColor(Color.WHITE);
        break;
    default:
        //draw nothing
    }

    invalidate();
    return true;
}

From source file:android.support.v7.widget.FastScroller.java

@Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent me) {
    if (mState == STATE_HIDDEN) {
        return;//from  w  w  w . j a v a  2  s  .c  o  m
    }

    if (me.getAction() == MotionEvent.ACTION_DOWN) {
        boolean insideVerticalThumb = isPointInsideVerticalThumb(me.getX(), me.getY());
        boolean insideHorizontalThumb = isPointInsideHorizontalThumb(me.getX(), me.getY());
        if (insideVerticalThumb || insideHorizontalThumb) {
            if (insideHorizontalThumb) {
                mDragState = DRAG_X;
                mHorizontalDragX = (int) me.getX();
            } else if (insideVerticalThumb) {
                mDragState = DRAG_Y;
                mVerticalDragY = (int) me.getY();
            }
            setState(STATE_DRAGGING);
        }
    } else if (me.getAction() == MotionEvent.ACTION_UP && mState == STATE_DRAGGING) {
        mVerticalDragY = 0;
        mHorizontalDragX = 0;
        setState(STATE_VISIBLE);
        mDragState = DRAG_NONE;
    } else if (me.getAction() == MotionEvent.ACTION_MOVE && mState == STATE_DRAGGING) {
        show();
        if (mDragState == DRAG_X) {
            horizontalScrollTo(me.getX());
        }
        if (mDragState == DRAG_Y) {
            verticalScrollTo(me.getY());
        }
    }
}

From source file:geeshang.nasaimage.MainActivity.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        v.setAlpha(0);/*from  w  w  w .  ja  va 2  s  .c  o  m*/
    }
    if (event.getAction() == MotionEvent.ACTION_UP) {
        v.setAlpha(255);
    }
    return false;
}

From source file:com.edible.ocr.CaptureActivity.java

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

    checkFirstLaunch();//from  ww w  .java 2 s .com

    if (isFirstLaunch) {
        setDefaultPreferences();
    }
    currentContext = this;
    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);

    }
    settingButton = (Button) findViewById(R.id.setting_button);
    settingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(currentContext, PreferencesActivity.class);
            startActivity(intent);
        }
    });

    aboutButton = (Button) findViewById(R.id.about_button);
    aboutButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(currentContext, HelpActivity.class);
            intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY, HelpActivity.ABOUT_PAGE);
            startActivity(intent);
        }
    });
    final EditText editText = (EditText) findViewById(R.id.typed_result);
    editText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // add capture button function 
                Intent openDetail = new Intent(currentContext, DetailInfo.class);
                String req = editText.getText().toString();
                //             openDetail.putExtra("request", "Filet Steak");
                openDetail.putExtra("request", req);
                editText.setText("");
                startActivity(openDetail);
                handled = true;
            }
            return handled;
        }
    });
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    //DB_textview = (TextView)findViewById(R.id.DB_text_view);
    //new HttpAsyncTask().execute("https://www.googleapis.com/language/translate/v2?key=" + KEY + "&q=hello%20world&source=en&target=de");
    /* For Client Server Connection */
    getButton = (Button) findViewById(R.id.get_text_button);
    getButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent openDetail = new Intent(currentContext, DetailInfo.class);
            String req = (String) ocrResultView.getText();
            //         openDetail.putExtra("request", "Filet Steak");
            openDetail.putExtra("request", req);
            startActivity(openDetail);

        }

    });
    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;

}

From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;//from   ww  w. j  av  a  2 s. c o m
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {//?
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {//??
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    //content????
                    updateContentOffsetTop((int) (offsetTop * mResistance));
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    } else {
                        updatePositionTimeout();
                    }
                    mPrevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.jest.phone.PhoneActivity.java

@Override
public boolean onTouch(View arg0, MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // Start gesture
        firstFinger = new PointF(event.getX(), event.getY());
        mode = ONE_FINGER_DRAG;//ww w .  j  a  v  a2s. c o m
        stopThread = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_POINTER_DOWN: // second finger
        distBetweenFingers = spacing(event);
        // the distance check is done to avoid false alarms
        if (distBetweenFingers > 5f) {
            mode = TWO_FINGERS_DRAG;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == ONE_FINGER_DRAG) {
            PointF oldFirstFinger = firstFinger;
            firstFinger = new PointF(event.getX(), event.getY());
            scroll(oldFirstFinger.x - firstFinger.x);
            sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
            sensorHistoryPlot.redraw();

        } else if (mode == TWO_FINGERS_DRAG) {
            float oldDist = distBetweenFingers;
            distBetweenFingers = spacing(event);
            zoom(oldDist / distBetweenFingers);
            sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
            sensorHistoryPlot.redraw();
        }
        break;
    }
    return true;
}

From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);//from  ww w  .  j a  v  a 2s.  c  o m
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;
        if (mTouchMode == TOUCH_MODE_FLINGING) {
            // Catch!
            setTouchMode(TOUCH_MODE_DRAGGING);
            return true;
        }
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            setTouchMode(TOUCH_MODE_DRAGGING);
            return true;
        }
    }
    }

    return false;
}