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:cl.ipp.katbag.fragment.Player.java

public void setSensing(String[] line, int lineNumber) {
    switch (Integer.parseInt(line[3])) {
    case 0:/* w w w. j  a va2 s . co  m*/
        boolean ex = false;
        for (int z = 0; z < touchEventId.size(); z++) {
            if (line[0].contentEquals(String.valueOf(touchEventId.get(z)))) {
                ex = true;
                break;
            }
        }

        if (!ex) {
            int last = -1;
            for (int i = lineNumber + 1; i < develop.size(); i++) {
                String[] it = develop.get(i).split("&&");

                last = i;
                if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) {
                    last--;
                    break;
                }
            }

            if ((lineNumber + 1) <= last) {
                touchEventId.add(Integer.valueOf(line[0]));
                touchEventDrawing.add(Integer.valueOf(line[4])); // drawing
                touchEventBgn.add(lineNumber + 1); // begin in
                touchEventLst.add(last); // ends

                final KatbagDrawing drawing = (KatbagDrawing) v.findViewById(Integer.valueOf(line[4]));
                if (drawing != null) {
                    drawing.setOnTouchListener(new OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            switch (event.getAction()) {
                            case MotionEvent.ACTION_DOWN:
                                for (int i = 0; i < touchEventDrawing.size(); i++) {
                                    if (touchEventDrawing.get(i) == drawing.getId()) {
                                        setBranchTreeCondition(touchEventId.get(i), 1);
                                        if (checkTreeCondition(touchEventId.get(i))) {
                                            Log.d("ply", "touchEventDrawing - ini:" + touchEventBgn.get(i)
                                                    + ", last:" + touchEventLst.get(i));
                                            play(touchEventBgn.get(i), touchEventLst.get(i) + 1);
                                            break;
                                        }
                                    }
                                }

                                break;

                            case MotionEvent.ACTION_UP:
                                for (int i = 0; i < touchEventDrawing.size(); i++) {
                                    if (touchEventDrawing.get(i) == drawing.getId()) {
                                        setBranchTreeCondition(touchEventId.get(i), 0);
                                        break;
                                    }
                                }

                                break;
                            }

                            return true;
                        }
                    });

                    Log.d("ply",
                            "setSensing - touchEvent add! count:" + touchEventId.size() + ", drawing:"
                                    + touchEventDrawing.get(touchEventDrawing.size() - 1) + " ini:"
                                    + touchEventBgn.get(touchEventBgn.size() - 1) + " last:"
                                    + touchEventLst.get(touchEventLst.size() - 1));
                }
            }

            if (last > -1)
                if ((last + 1) < develop.size())
                    play((last + 1), develop.size());
        }

        break;

    case 1:
        boolean ex1 = false;
        for (int z = 0; z < shakeId.size(); z++) {
            if (line[0].contentEquals(String.valueOf(shakeId.get(z)))) {
                ex1 = true;
                break;
            }
        }

        if (!ex1) {
            int last1 = -1;
            for (int i = lineNumber + 1; i < develop.size(); i++) {
                String[] it = develop.get(i).split("&&");

                last1 = i;
                if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) {
                    last1--;
                    break;
                }
            }

            if ((lineNumber + 1) <= last1) {
                shakeId.add(Integer.valueOf(line[0]));
                shakeBgn.add(lineNumber + 1); // begin in
                shakeLst.add(last1); // ends

                sensorManager = (SensorManager) mainActivity.context.getSystemService(Context.SENSOR_SERVICE);
                accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
                sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_FASTEST);
                useAccelerometer = true;

                Log.d("ply", "setSensing - shake add! count:" + shakeId.size() + ", ini:"
                        + shakeBgn.get(shakeBgn.size() - 1) + " last:" + shakeLst.get(shakeLst.size() - 1));
            }

            if (last1 > -1)
                if ((last1 + 1) < develop.size())
                    play((last1 + 1), develop.size());
        }

        break;
    }
}

From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

    if (!isEnabled() || canChildScrollUp()) {
        return false;
    }/*w  w  w.ja  va 2  s .  co  m*/
    mIsBeingDropped = mWaveView.isDisappearCircleAnimatorRunning();

    final int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Here is not called from anywhere
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId);
        return pointerIndex >= 0 && onMoveTouchEvent(event, pointerIndex);

    case MotionEvent.ACTION_UP:
        if (mIsBeingDropped) {
            mIsBeingDropped = false;
            return false;
        }

        final float diffY = event.getY() - mFirstTouchDownPointY;
        final float waveHeightThreshold = diffY
                * (5f - 2 * diffY / Math.min(getMeasuredWidth(), getMeasuredHeight())) / 1000f;
        mWaveView.startWaveAnimation(waveHeightThreshold);

    case MotionEvent.ACTION_CANCEL:
        if (mActivePointerId == INVALID_POINTER) {
            return false;
        }

        if (!isRefreshing()) {
            mCircleView.setProgressStartEndTrim(0f, 0f);
            mCircleView.showArrow(false);
            mCircleView.setVisibility(GONE);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    return true;
}

From source file:it.angrydroids.epub3reader.TextSelectionSupport.java

private void createSelectionLayer(Context context) {
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSelectionDragLayer = (DragLayer) inflater.inflate(R.layout.selection_drag_layer, null);
    mDragController = new DragController(context);
    mDragController.setDragListener(this);
    mDragController.addDropTarget(mSelectionDragLayer);
    mSelectionDragLayer.setDragController(mDragController);
    mStartSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.startHandle);
    mStartSelectionHandle.setTag(HandleType.START);
    mEndSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.endHandle);
    mEndSelectionHandle.setTag(HandleType.END);
    final OnTouchListener handleTouchListener = new OnTouchListener() {
        @Override/*from   www  .j av  a  2 s  .  co  m*/
        public boolean onTouch(View v, MotionEvent event) {
            boolean handledHere = false;
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                handledHere = startDrag(v);
                mLastTouchedSelectionHandle = (HandleType) v.getTag();
            }
            return handledHere;
        }
    };
    mStartSelectionHandle.setOnTouchListener(handleTouchListener);
    mEndSelectionHandle.setOnTouchListener(handleTouchListener);
}

From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;// w  w  w. ja  v a  2s.  c om
        mDownEvent = MotionEvent.obtain(event);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart && !mRefreshing && !mUserInteracting) {
            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
                    mUserInteracting = true;
                    startRefresh();
                    handled = true;
                    break;
                }
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updatePositionTimeout();
                handled = true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mUserInteracting = false;
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

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

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
        return false;
    }/*from w w  w  . j  a va2  s .c  om*/

    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:com.androidinspain.deskclock.alarms.AlarmActivity.java

@Override
public boolean onTouch(View view, MotionEvent event) {
    if (mAlarmHandled) {
        LOGGER.v("onTouch ignored: %s", event);
        return false;
    }/*from w  w  w  .jav  a2  s .co m*/

    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN) {
        LOGGER.v("onTouch started: %s", event);

        // Track the pointer that initiated the touch sequence.
        mInitialPointerIndex = event.getPointerId(event.getActionIndex());

        // Stop the pulse, allowing the last pulse to finish.
        mPulseAnimator.setRepeatCount(0);
    } else if (action == MotionEvent.ACTION_CANCEL) {
        LOGGER.v("onTouch canceled: %s", event);

        // Clear the pointer index.
        mInitialPointerIndex = MotionEvent.INVALID_POINTER_ID;

        // Reset everything.
        resetAnimations();
    }

    final int actionIndex = event.getActionIndex();
    if (mInitialPointerIndex == MotionEvent.INVALID_POINTER_ID
            || mInitialPointerIndex != event.getPointerId(actionIndex)) {
        // Ignore any pointers other than the initial one, bail early.
        return true;
    }

    final int[] contentLocation = { 0, 0 };
    mContentView.getLocationOnScreen(contentLocation);

    final float x = event.getRawX() - contentLocation[0];
    final float y = event.getRawY() - contentLocation[1];

    final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft();
    final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight();

    final float snoozeFraction, dismissFraction;
    if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x);
        dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x);
    } else {
        snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x);
        dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x);
    }
    setAnimatedFractions(snoozeFraction, dismissFraction);

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
        LOGGER.v("onTouch ended: %s", event);

        mInitialPointerIndex = MotionEvent.INVALID_POINTER_ID;
        if (snoozeFraction == 1.0f) {
            snooze();
        } else if (dismissFraction == 1.0f) {
            dismiss();
        } else {
            if (snoozeFraction > 0.0f || dismissFraction > 0.0f) {
                // Animate back to the initial state.
                AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator);
            } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) {
                // User touched the alarm button, hint the dismiss action.
                hintDismiss();
            }

            // Restart the pulse.
            mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
            if (!mPulseAnimator.isStarted()) {
                mPulseAnimator.start();
            }
        }
    }

    return true;
}

From source file:cn.colink.commumication.swipelistview.SwipeListView.java

/**
 * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent)
 *//*  w ww . jav  a2 s.c  o m*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (touchState == TOUCH_STATE_SCROLLING_X) {
        return touchListener.onTouch(this, ev);
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        checkInMoving(x, y);
        return touchState == TOUCH_STATE_SCROLLING_Y;
    case MotionEvent.ACTION_DOWN:
        touchListener.onTouch(this, ev);
        touchState = TOUCH_STATE_REST;
        lastMotionX = x;
        lastMotionY = y;
        return false;
    case MotionEvent.ACTION_CANCEL:
        touchState = TOUCH_STATE_REST;
        break;
    case MotionEvent.ACTION_UP:
        touchListener.onTouch(this, ev);
        return touchState == TOUCH_STATE_SCROLLING_Y;
    default:
        break;
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java

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

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int x = (int) (event.getX() + 0.5f);
    final int y = (int) (event.getY() + 0.5f);

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mDownX = x;/*from   w w  w .j  a  v  a2s . c  om*/
        mDownY = y;

        mInitialTarget = getDayAtLocation(mDownX, mDownY);

        if (mInitialTarget < 0) {
            return false;
        }

        if (mPendingCheckForTap == null) {
            mPendingCheckForTap = new CheckForTap();
        }
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        break;
    case MotionEvent.ACTION_MOVE:
        if (!isStillAClick(x, y)) {
            if (mPendingCheckForTap != null) {
                removeCallbacks(mPendingCheckForTap);
            }

            mInitialTarget = -1;

            if (mTouchedItem >= 0) {
                mTouchedItem = -1;
                invalidate();
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        onDayClicked(mInitialTarget);
        // Fall through.
    case MotionEvent.ACTION_CANCEL:
        if (mPendingCheckForTap != null) {
            removeCallbacks(mPendingCheckForTap);
        }
        // Reset touched day on stream end.
        mTouchedItem = -1;
        mInitialTarget = -1;
        invalidate();
        break;
    }
    return true;
}