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:au.com.wallaceit.reddinator.TabWebFragment.java

@SuppressLint("SetJavaScriptEnabled")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = this.getActivity();
    if (container == null) {
        return null;
    }//from w w  w .j  ava2  s . co m
    if (mFirstTime) {
        // get shared preferences
        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(this.getActivity().getApplicationContext());
        // work out the url this instance should load
        boolean commentswv = false;
        if (this.getArguments() != null) {
            commentswv = this.getArguments().getBoolean("loadcom", false);
        }

        int fontsize;
        String url;
        if (commentswv) {
            url = "http://reddit.com" + getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_PERMALINK)
                    + ".compact";
            fontsize = Integer.parseInt(prefs.getString("commentfontpref", "22"));
        } else {
            url = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_URL);
            fontsize = Integer.parseInt(prefs.getString("contentfontpref", "18"));
        }
        // setup progressbar
        mActivity = this.getActivity();
        mActivity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
        ll = (LinearLayout) inflater.inflate(R.layout.tab1, container, false);
        mWebView = (WebView) ll.findViewById(R.id.webView1);
        // fixes for webview not taking keyboard input on some devices
        mWebView.requestFocus(View.FOCUS_DOWN);
        mWebView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
                }
                return false;
            }
        });
        mWebView.getSettings().setJavaScriptEnabled(true); // enable ecmascript
        mWebView.getSettings().setSupportZoom(true);
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setDisplayZoomControls(true);
        mWebView.getSettings().setDefaultFontSize(fontsize);
        mChromeClient = newchromeclient;
        mWebView.setWebChromeClient(mChromeClient);
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.loadUrl(url);
        mFirstTime = false;
        //System.out.println("Created fragment");
    } else {
        ((ViewGroup) ll.getParent()).removeView(ll);
    }

    return ll;
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

@Override
public boolean onInterceptTouchEvent(final RecyclerView recyclerView, final MotionEvent event) {
    if (event.getPointerCount() > 1) {
        // Ignore subsequent pointers.
        return false;
    }//from w  w  w  .  ja  v a 2s  . c om

    // We are not yet tracking a swipe gesture. Begin detection by spying on
    // touch events bubbling down to our children.
    final int action = event.getActionMasked();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (!hasGestureSwipeTarget()) {
            onGestureStart();

            mVelocityTracker.addMovement(event);
            mInitialX = event.getX();
            mInitialY = event.getY();

            final View viewAtPoint = mRecyclerView.findChildViewUnder(mInitialX, mInitialY);
            final ConversationListItemView child = (ConversationListItemView) viewAtPoint;
            if (viewAtPoint instanceof ConversationListItemView && child != null && child.isSwipeAnimatable()) {
                // Begin detecting swipe on the target for the rest of the gesture.
                mListItemView = child;
                if (mListItemView.isAnimating()) {
                    mListItemView = null;
                }
            } else {
                mListItemView = null;
            }
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (hasValidGestureSwipeTarget()) {
            mVelocityTracker.addMovement(event);

            final int historicalCount = event.getHistorySize();
            // First consume the historical events, then consume the current ones.
            for (int i = 0; i < historicalCount + 1; i++) {
                float currX;
                float currY;
                if (i < historicalCount) {
                    currX = event.getHistoricalX(i);
                    currY = event.getHistoricalY(i);
                } else {
                    currX = event.getX();
                    currY = event.getY();
                }
                final float deltaX = currX - mInitialX;
                final float deltaY = currY - mInitialY;
                final float absDeltaX = Math.abs(deltaX);
                final float absDeltaY = Math.abs(deltaY);

                if (!mIsSwiping && absDeltaY > mTouchSlop
                        && absDeltaY > (ERROR_FACTOR_MULTIPLIER * absDeltaX)) {
                    // Stop detecting swipe for the remainder of this gesture.
                    onGestureEnd();
                    return false;
                }

                if (absDeltaX > mTouchSlop) {
                    // Swipe detected. Return true so we can handle the gesture in
                    // onTouchEvent.
                    mIsSwiping = true;

                    // We don't want to suddenly jump the slop distance.
                    mInitialX = event.getX();
                    mInitialY = event.getY();

                    onSwipeGestureStart(mListItemView);
                    return true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (hasGestureSwipeTarget()) {
            onGestureEnd();
        }
        break;
    }

    // Start intercepting touch events from children if we detect a swipe.
    return mIsSwiping;
}

From source file:com.appsimobile.appsii.SidebarHotspot.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    switch (e.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        mVelocityTracker.addMovement(e);
        // remove the background to make sure it does not overlap
        // the sidebar

        mIsDragOpening = true;//from  w  w w.j a  v a 2 s . c  o  m
        setBackgroundResource(0);

        float x = e.getX();
        float y = e.getY();

        if (mCallback != null) {
            mSwipeListener = mCallback.open(this, Gesture.TO_CENTER, (int) x, (int) y);
            mSwipeInProgress = mSwipeListener != null;
            mState = STATE_AWAITING_RELEASE;
            if (mVibrate) {
                vibrate();
            }

            return true;
        }
        return false;
    }
    case MotionEvent.ACTION_MOVE:
        mVelocityTracker.addMovement(e);
        float x = e.getX();
        float y = e.getY();
        return detectSwipe(x, y, e);
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        cancelMotionHandling(e, false);
        return false;
    }

    return super.onTouchEvent(e);
}

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

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//from ww w  . j a  va 2s.c  om

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();

        if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        } else {
            return false;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
        if (activePointerIndex == -1) {
            return false;
        }

        final int y = (int) ev.getY(activePointerIndex);
        int dy = mLastMotionY - y;

        if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) {
            mIsBeingDragged = true;
            if (dy > 0) {
                dy -= mTouchSlop;
            } else {
                dy += mTouchSlop;
            }
        }

        if (mIsBeingDragged) {
            mLastMotionY = y;
            // We're being dragged so scroll the ABL
            scroll(parent, child, dy, getMaxDragOffset(child), 0);
        }
        break;
    }

    case MotionEvent.ACTION_UP:
        if (mVelocityTracker != null) {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);
            float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
            fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
        }
        // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return true;
}

From source file:android.support.designox.widget.HeaderBehavior.java

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//ww  w .  ja  va  2  s.c  o m

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();

        if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) {
            mLastMotionY = y;
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            ensureVelocityTracker();
        } else {
            return false;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (activePointerIndex == -1) {
            return false;
        }

        final int y = (int) MotionEventCompat.getY(ev, activePointerIndex);
        int dy = mLastMotionY - y;

        if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) {
            mIsBeingDragged = true;
            if (dy > 0) {
                dy -= mTouchSlop;
            } else {
                dy += mTouchSlop;
            }
        }

        if (mIsBeingDragged) {
            mLastMotionY = y;
            // We're being dragged so scroll the ABL
            scroll(parent, child, dy, getMaxDragOffset(child), 0);
        }
        break;
    }

    case MotionEvent.ACTION_UP:
        if (mVelocityTracker != null) {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);
            float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
            fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
        }
        // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return true;
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

private boolean onTouchEventTraditionalRotation(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }/*from  w  ww. j a  va2 s. c  o m*/

    final Drawable mThumb = getThumbCompat();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        setPressed(true);
        if (mThumb != null) {
            // This may be within the padding region
            invalidate(mThumb.getBounds());
        }
        onStartTrackingTouch();
        trackTouchEvent(event);
        attemptClaimDrag(true);
        break;

    case MotionEvent.ACTION_MOVE:
        if (mIsDragging) {
            trackTouchEvent(event);
        }
        break;

    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            trackTouchEvent(event);
            onStopTrackingTouch();
            setPressed(false);
        } else {
            // Touch up when we never crossed the touch slop threshold
            // should
            // be interpreted as a tap-seek to that location.
            onStartTrackingTouch();
            trackTouchEvent(event);
            onStopTrackingTouch();
            attemptClaimDrag(false);
        }
        // ProgressBar doesn't know to repaint the thumb drawable
        // in its inactive state when the touch stops (because the
        // value has not apparently changed)
        invalidate();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            onStopTrackingTouch();
            setPressed(false);
        }
        invalidate(); // see above explanation
        break;
    }
    return true;
}

From source file:ch.fhnw.comgr.GLES3Activity.java

@Override
public boolean onTouch(View v, final MotionEvent event) {
    if (event == null) {
        Log.i(TAG, "onTouch: null event");
        return false;
    }/*from  w  w w .  jav  a2  s  .c o  m*/

    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;

    try {
        if (actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN)
            return handleTouchDown(event);
        else if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP)
            return handleTouchUp(event);
        else if (actionCode == MotionEvent.ACTION_MOVE)
            return handleTouchMove(event);
        else
            Log.i(TAG, "Unhandeled Event: " + actionCode);
    } catch (Exception ex) {
        Log.i(TAG, "onTouch (Exception: " + actionCode);
    }

    return false;
}

From source file:com.anykey.balala.activity.BaseActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
            hideSoftInputView();//from ww w  . j ava 2s.c  o m
        }
    }
    return super.onTouchEvent(event);
}

From source file:br.com.cybereagle.androidwidgets.view.PagerContainer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    //We capture any touches not already handled by the ViewPager
    // to implement scrolling from a touch outside the pager bounds.
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        initialTouch.x = (int) ev.getX();
        initialTouch.y = (int) ev.getY();
    default://from   w w w .ja va2 s  .  c  om
        ev.offsetLocation(center.x - initialTouch.x, center.y - initialTouch.y);
        break;
    }

    return pager.dispatchTouchEvent(ev);
}

From source file:android.support.v13.view.DragStartHelper.java

/**
 * Handle a touch event./*  w w w .ja va  2s. com*/
 * @param v The view the touch event has been dispatched to.
 * @param event The MotionEvent object containing full information about
 *        the event.
 * @return True if the listener has consumed the event, false otherwise.
 */
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
        mLastTouchX = (int) event.getX();
        mLastTouchY = (int) event.getY();
    }
    if (event.getAction() == MotionEvent.ACTION_MOVE
            && MotionEventCompat.isFromSource(event, InputDeviceCompat.SOURCE_MOUSE)
            && (MotionEventCompat.getButtonState(event) & MotionEventCompat.BUTTON_PRIMARY) != 0) {
        return mListener.onDragStart(v, this);
    }
    return false;
}