Example usage for android.view MotionEvent ACTION_UP

List of usage examples for android.view MotionEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Usage

From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    // MotionEvent reports input details from the touch screen
    // and other input controls. In this case, you are only
    // interested in events where the touch position changed.

    switch (e.getAction()) {

    case MotionEvent.ACTION_DOWN:
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } else {//from  w w  w .  j  a  v a  2  s .  com
            mVelocityTracker.clear();
        }

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.touchHasStarted();
            }
        });

        // No break is intentional

    case MotionEvent.ACTION_MOVE:

        mVelocityTracker.addMovement(e);

        // Compute velocity in pixels per second
        mVelocityTracker.computeCurrentVelocity(1);

        final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1);
        Vector2 viewportPosition;

        Vector2 viewportVelocity = new Vector2(
                VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()),
                VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex()));

        // Add previous touch coordinates
        for (int i = 0; i < e.getHistorySize(); i++) {
            viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i));

            touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity,
                    e.getHistoricalSize(i), e.getHistoricalPressure(i)));
        }

        // Add current touch coordinates
        viewportPosition = new Vector2(e.getX(), e.getY());
        touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity,
                e.getSize(), e.getPressure()));

        // Ensure we call switchMode() on the OpenGL thread.
        // queueEvent() is a method of GLSurfaceView that will do this for us.
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.addTouchData(touchDataList);
            }
        });

        requestRender();
        break;

    case MotionEvent.ACTION_UP:

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.touchHasEnded();
            }
        });
        requestRender();
        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  .  j  av  a  2 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.project.merauke.CustomItemizedOverlay.java

@Override
public boolean onTouchEvent(MotionEvent event, MapView map) {

    if (event.getAction() == MotionEvent.ACTION_MOVE) {
        isMove = true;/*w w  w  .  j  a  v a 2s .c  om*/
    }

    if ((event.getAction() == MotionEvent.ACTION_UP) && isMove) {
        Log.d("ACTION", "UP after MOVE");
        // Toast.makeText(c, "geser-geser detected", Toast.LENGTH_SHORT).show();
        Projection projection = maps.getProjection();
        GeoPoint geoPointMin = (GeoPoint) projection.fromPixels(0, 0);
        GeoPoint geoPointMax = (GeoPoint) projection.fromPixels(maps.getWidth(), maps.getHeight());

        minLat = geoPointMin.getLatitudeE6() / 1E6;
        minLng = geoPointMin.getLongitudeE6() / 1E6;
        // Log.d("drikvy-min", minLat+"---"+minLng);// 2-3

        maxLat = geoPointMax.getLatitudeE6() / 1E6;
        maxLng = geoPointMax.getLongitudeE6() / 1E6;
        // Log.d("drikvy-max", maxLat+"---"+maxLng);// 1-4

        new FetchDataTask() {

            protected void onPreExecute() {
                whellProgress.show();
            }

            protected void onPostExecute(ArrayList<CustomOverlayItem> result) {
                if (result != null) {
                    storeAll(result);
                    whellProgress.dismiss();

                    maps.invalidate();
                }
            }
        }.execute();

        isMove = false;
    }
    return false;
}

From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onInterceptTouchEvent(event);
    }//from www. j  a v a  2 s  .c o  m

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:com.mimo.service.api.MimoOauth2Client.java

/**
 * Instantiate a webview and allows the user to login to the Api form within
 * the application/*from  www  . j  a  va2s  . c  om*/
 * 
 * @param p_view
 *            : Calling view
 * 
 * @param p_activity
 *            : Calling Activity reference
 **/

@SuppressLint("SetJavaScriptEnabled")
public void login(View p_view, Activity p_activity) {

    final Activity m_activity;
    m_activity = p_activity;
    String m_url = this.m_api.getAuthUrl();
    WebView m_webview = new WebView(p_view.getContext());
    m_webview.getSettings().setJavaScriptEnabled(true);
    m_webview.setVisibility(View.VISIBLE);
    m_activity.setContentView(m_webview);

    m_webview.requestFocus(View.FOCUS_DOWN);
    /**
     * Open the softkeyboard of the device to input the text in form which
     * loads in webview.
     */
    m_webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View p_v, MotionEvent p_event) {
            switch (p_event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!p_v.hasFocus()) {
                    p_v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    /**
     * Show the progressbar in the title of the activity untill the page
     * loads the give url.
     */
    m_webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView p_view, int p_newProgress) {
            ((Activity) m_context).setProgress(p_newProgress * 100);
            ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING);

            if (p_newProgress == 100)
                ((Activity) m_context).setTitle(m_context.getString(R.string.app_name));
        }
    });

    m_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) {
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url,
                String p_realm) {
            p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD);
        }

        public void onPageFinished(WebView p_view, String p_url) {
            if (MimoAPIConstants.DEBUG) {
                Log.d(TAG, "Page Url = " + p_url);
            }
            if (p_url.contains("?code=")) {
                if (p_url.indexOf("code=") != -1) {
                    String[] m_urlSplit = p_url.split("=");

                    String m_tempString1 = m_urlSplit[1];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "TempString1 = " + m_tempString1);
                    }
                    String[] m_urlSplit1 = m_tempString1.split("&");

                    String m_code = m_urlSplit1[0];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "code = " + m_code);
                    }
                    MimoOauth2Client.this.m_code = m_code;
                    Thread m_thread = new Thread() {
                        public void run() {
                            String m_token = requesttoken(MimoOauth2Client.this.m_code);

                            Log.d(TAG, "Token = " + m_token);

                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);

                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);

                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                } else {
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "going in else");
                    }
                }
            } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) {
                if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) {
                    String[] m_urlSplit = p_url.split("=");
                    final String m_token = m_urlSplit[1];

                    Thread m_thread = new Thread() {
                        public void run() {
                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);
                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);
                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                }
            }
        };
    });

    m_webview.loadUrl(m_url);
}

From source file:com.android.ex.photo.PhotoViewPager.java

/**
 * {@inheritDoc}//from  ww w .  ja  v a2 s .c  o  m
 * <p>
 * We intercept touch event intercepts so we can prevent switching views when the
 * current view is internally scrollable.
 */
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY)
            : InterceptType.NONE;
    final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT);
    final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT);

    // Only check ability to page if we can't scroll in one / both directions
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mActivePointerId = INVALID_POINTER;
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        if (ignoreScrollLeft || ignoreScrollRight) {
            final int activePointerId = mActivePointerId;
            if (activePointerId == INVALID_POINTER) {
                // If we don't have a valid id, the touch down wasn't on content.
                break;
            }

            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
            final float x = MotionEventCompat.getX(ev, pointerIndex);

            if (ignoreScrollLeft && ignoreScrollRight) {
                mLastMotionX = x;
                return false;
            } else if (ignoreScrollLeft && (x > mLastMotionX)) {
                mLastMotionX = x;
                return false;
            } else if (ignoreScrollRight && (x < mLastMotionX)) {
                mLastMotionX = x;
                return false;
            }
        }
        break;
    }

    case MotionEvent.ACTION_DOWN: {
        mLastMotionX = ev.getX();
        // Use the raw x/y as the children can be located anywhere and there isn't a
        // single offset that would be meaningful
        mActivatedX = ev.getRawX();
        mActivatedY = ev.getRawY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP: {
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            // Our active pointer going up; select a new active pointer
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        break;
    }
    }

    return super.onInterceptTouchEvent(ev);
}

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

private boolean onTouchEventTraditionalRotation(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }/*from  w  w  w. j  a  v a2s .  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:com.amitupadhyay.aboutexample.ui.widget.BottomSheet.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    hasInteractedWithSheet = true;/* w w  w  .  j  a va  2  s.  c o  m*/
    if (isNestedScrolling)
        return false; /* prefer nested scrolling to dragging */

    final int action = MotionEventCompat.getActionMasked(ev);
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        sheetDragHelper.cancel();
        return false;
    }
    return isDraggableViewUnder((int) ev.getX(), (int) ev.getY())
            && (sheetDragHelper.shouldInterceptTouchEvent(ev));
}

From source file:co.dift.ui.SwipeToAction.java

/** Private methods **/
private void init() {
    gestureDetector = new GestureDetectorCompat(recyclerView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override// w  w  w.  j  a v  a 2 s  .c  o  m
                public void onLongPress(MotionEvent e) {
                    logger.d("onLongPress called!");
                    if (touchedViewHolder != null) {
                        swipeListener.onLongClick(touchedViewHolder.getItemData());
                    }
                }

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    logger.d("onSingleTapUp called!");
                    if (touchedViewHolder != null) {
                        swipeListener.onClick(touchedViewHolder.getItemData());
                        return true;
                    }
                    return super.onSingleTapUp(e);
                }
            });

    recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {
            gestureDetector.onTouchEvent(ev);

            switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN: {
                // starting point
                downX = ev.getX();
                downY = ev.getY();

                downTime = new Date().getTime();

                // which item are we touching
                resolveItem(downX, downY);

                break;
            }

            case MotionEvent.ACTION_UP: {
                upX = ev.getX();
                upY = ev.getY();
                upTime = new Date().getTime();

                resolveState();
                break;
            }

            case MotionEvent.ACTION_MOVE: {
                final float x = ev.getX();
                final float dx = x - downX;

                if (!shouldMove(dx))
                    break;

                // current position. moving only over x-axis
                frontViewLastX = frontViewX + dx + (dx > 0 ? -getRevealThreshold() : getRevealThreshold());
                //                        logger.d("dx: %f, frontViewLastX: %f", dx, frontViewLastX);
                if (maxSwipeXPosition != null) {
                    if (frontViewLastX > 0 && frontViewLastX > maxSwipeXPosition) {
                        frontViewLastX = maxSwipeXPosition;
                    } else if (frontViewLastX <= -maxSwipeXPosition) {
                        frontViewLastX = -maxSwipeXPosition;
                    }
                }
                frontView.setX(frontViewLastX);

                if (frontViewLastX > 0) {
                    revealRight();
                } else {
                    revealLeft();
                }

                break;
            }

            case MotionEvent.ACTION_CANCEL: {
                resolveState();

                break;
            }
            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
            logger.d("onTouchEvent called");
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
            logger.d("onRequestDisallowInterceptTouchEvent called");
        }
    });
}

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  ww w  .j  a v a 2 s.  c  om
        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);
}