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:com.androtex.viewpagerindicator.CirclePageIndicator.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        final int count = mViewPager.getAdapter().getCount();
        final int longSize = (mOrientation == HORIZONTAL) ? getWidth() : getHeight();
        final float halfLongSize = longSize / 2;
        final float halfCircleLongSize = (count * 3 * mRadius) / 2;
        final float pointerValue = (mOrientation == HORIZONTAL) ? event.getX() : event.getY();

        if ((mCurrentPage > 0) && (pointerValue < halfLongSize - halfCircleLongSize)) {
            setCurrentItem(mCurrentPage - 1);
            return true;
        } else if ((mCurrentPage < count - 1) && (pointerValue > halfLongSize + halfCircleLongSize)) {
            setCurrentItem(mCurrentPage + 1);
            return true;
        }//ww  w  .  ja  v  a  2 s. co  m
    }

    return super.onTouchEvent(event);
}

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

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!mCanPickRange) {
        return super.onInterceptTouchEvent(ev);
    }//from w w  w.ja  v a2 s.c  o  m

    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        if (Config.DEBUG) {
            Log.i(TAG, "OITE: DOWN");
        }

        mInitialDownX = ev.getX();
        mInitialDownY = ev.getY();

        if (mCheckForLongPress == null) {
            mCheckForLongPress = new CheckForLongPress();
        }

        postDelayed(mCheckForLongPress, ViewConfiguration.getLongPressTimeout());
    } else if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
        if (Config.DEBUG) {
            Log.i(TAG, "OITE: (UP || CANCEL)");
        }

        if (mCheckForLongPress != null) {
            removeCallbacks(mCheckForLongPress);
        }

        mIsLongPressed = false;
        mInitialDownX = -1;
        mInitialDownY = -1;
    } else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
        if (Config.DEBUG) {
            Log.i(TAG, "OITE: MOVE");
        }

        if (!isStillALongPress((int) ev.getX(), (int) ev.getY())) {
            if (Config.DEBUG) {
                Log.i(TAG, "OITE: MOVED TOO MUCH, CANCELLING CheckForLongPress Runnable");
            }

            if (mCheckForLongPress != null) {
                removeCallbacks(mCheckForLongPress);
            }
        }
    }

    return mIsLongPressed || super.onInterceptTouchEvent(ev);
}

From source file:android.support.design.widget.SheetBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        return false;
    }//w w  w.j  av a 2 s . co  m
    int action = MotionEventCompat.getActionMasked(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchingScrollingChild = false;
        mActivePointerId = MotionEvent.INVALID_POINTER_ID;
        // Reset the ignore flag
        if (mIgnoreEvents) {
            mIgnoreEvents = false;
            return false;
        }
        break;
    case MotionEvent.ACTION_DOWN:
        mInitialY = (int) event.getY();
        int initialX = (int) event.getX();
        View scroll = mNestedScrollingChildRef.get();
        if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) {
            mActivePointerId = event.getPointerId(event.getActionIndex());
            mTouchingScrollingChild = true;
        }
        mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID
                && !parent.isPointInChildBounds(child, initialX, mInitialY);
        break;
    }
    if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) {
        return true;
    }
    // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
    // it is not the top most view of its parent. This is not necessary when the touch event is
    // happening over the scrolling content as nested scrolling logic handles that case.
    View scroll = mNestedScrollingChildRef.get();
    return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING
            && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
            && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop();
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPageView.java

/**
 * View.//from  w ww  .ja v  a  2 s. c o  m
 *
 * @param view the view
 */
public void addNextView(View view) {
    addView(view, 1, getLayoutParams());
    view.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showNext();
            }

        }
    });

    view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEvent.ACTION_DOWN == event.getAction()) {
                showNext();
            }
            return false;
        }
    });
}

From source file:com.timemachine.controller.ControllerActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Detect the general touch event of the entire screen
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        try {/*from ww w .j  av  a  2  s.c  o m*/
            if (isEditorEnabled)
                stopHideEditorTimer();
            else
                locationSlider.loadUrl("javascript:stopScreenIdleTimeout()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (!isAutoModeDelayTimeoutRunning && event.getAction() == MotionEvent.ACTION_UP) {
        try {
            if (isEditorEnabled)
                runHideEditorTimer();
            else
                locationSlider.loadUrl("javascript:startScreenIdleTimeout()");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.librelio.activity.StartupActivity.java

private void setOnAdvertisingImageClickListener(final String link) {
    if (advertisingImage != null) {
        advertisingImage.setOnTouchListener(new OnTouchListener() {
            //            @Override
            //            public void onClick(View v) {
            //               advertisingClickPerformed = true;
            ///*from   ww w. ja v  a2  s.  c  o m*/
            //               startAdsActivity(link);
            //            }

            @Override
            public boolean onTouch(View pView, MotionEvent pEvent) {
                if (pEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    // check the Y coordinates of the touch event
                    float pY = pEvent.getY();
                    int pHeight = pView.getHeight();
                    if (Math.round(pY / 0.2) <= pHeight) {
                        // Skip ads
                        if (mStartupAdsTimer != null)
                            mStartupAdsTimer.cancel();
                        startMainMagazineActivity();
                    } else {
                        // Show ads
                        if (mStartupAdsTimer != null)
                            mStartupAdsTimer.cancel();
                        startAdsActivity(link);
                    }
                }
                return false;
            }
        });
    }
}

From source file:com.intel.xdk.multitouch.MultiTouch.java

public void queueMultitouchData(String js, int id, int maskedAction) {
    //Log.i("[appMobi]", "queueMultitouchData:"+js);

    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN || maskedAction == MotionEvent.ACTION_DOWN) {
        //touchstart: create list
        //this.multitouchMap.put(id, new ArrayList<String>());

    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP || maskedAction == MotionEvent.ACTION_UP) {
        //touchend: remove list
        this.multitouchMap.remove(id);

    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
        //touchmove: flush stale touchmove events and and update list
        String stale = this.multitouchMap.get(id);
        this.multitouchQueue.remove(stale);
        this.multitouchMap.put(id, js);
    }/*ww  w.  j  av a 2 s.  c o m*/

    this.multitouchQueue.add(js);
}

From source file:cn.com.hgh.view.SlideSwitch.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (slideable == false)
        return super.onTouchEvent(event);
    int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        eventStartX = (int) event.getRawX();
        break;// w  w w .  ja v a2s.c  o  m
    case MotionEvent.ACTION_MOVE:
        //         eventLastX = (int) event.getRawX();
        //         diffX = eventLastX - eventStartX;
        //         int tempX = diffX + frontRect_left_begin;
        //         tempX = (tempX > max_left ? max_left : tempX);
        //         tempX = (tempX < min_left ? min_left : tempX);
        //         if (tempX >= min_left && tempX <= max_left) {
        //            frontRect_left = tempX;
        //            alpha = (int) (255 * (float) tempX / (float) max_left);
        //            invalidateView();
        //         }
        break;
    case MotionEvent.ACTION_UP:
        int wholeX = (int) (event.getRawX() - eventStartX);
        frontRect_left_begin = frontRect_left;
        toRight = (frontRect_left_begin > max_left / 2 ? true : false);
        if (Math.abs(wholeX) < 3) {
            toRight = !toRight;
        }
        //x??
        float eventx = event.getX();
        if (isOpen) {
            //?
            if (eventx < width / 2) {
                //            switchBusinessStatus();
                switchStatus();

            }
        } else {
            //?
            if (eventx > width / 2) {
                //               switchBusinessStatus();
                switchStatus();

            }
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:com.funzio.pure2D.demo.particles.NovaActivity.java

@Override
public boolean onTouch(final View v, final MotionEvent event) {
    final int action = event.getAction() & MotionEvent.ACTION_MASK;

    // null check
    if (mNovaFactory == null) {
        return false;
    }/*  w  w  w . j  a  v  a2  s .  c om*/

    if (action == MotionEvent.ACTION_DOWN) {
        mStage.queueEvent(new Runnable() {
            @Override
            public void run() {
                final int pointerCount = event.getPointerCount();
                for (int i = 0; i < pointerCount; i++) {
                    // for demo, limit the number of emitters
                    if (mScene.getNumGrandChildren() < mNovaFactory.getPoolSize()) {
                        addObject(event.getX(i), mDisplaySize.y - event.getY(i));
                    }
                }
            }
        });
    }

    return true;
}

From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java

private boolean resetDispatchTouchEvent(MotionEvent ev) {
    MotionEvent newEvent = MotionEvent.obtain(ev);

    ev.setAction(MotionEvent.ACTION_CANCEL);
    dispatchTouchEvent(ev);//from w  w w  .  j  av  a 2  s . c om

    newEvent.setAction(MotionEvent.ACTION_DOWN);
    return dispatchTouchEvent(newEvent);
}