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:com.apptentive.android.sdk.util.image.PreviewImageView.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    gestureDetector.onTouchEvent(event);
    scaleGestureDetector.onTouchEvent(event);

    float x = 0, y = 0;
    // Get multiple touch points
    final int pointerCount = event.getPointerCount();
    // Calculate average x and y
    for (int i = 0; i < pointerCount; i++) {
        x += event.getX(i);/*  w  w  w  . j av a2s  .co m*/
        y += event.getY(i);
    }
    x = x / pointerCount;
    y = y / pointerCount;

    /**
     * Reset lastX and lastY
     */
    if (pointerCount != lastPointerCount) {
        isCanDrag = false;
        lastX = x;
        lastY = y;
    }

    lastPointerCount = pointerCount;

    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE:
        float dx = x - lastX;
        float dy = y - lastY;

        if (!isCanDrag) {
            isCanDrag = isCanDrag(dx, dy);
        }
        if (isCanDrag) {
            RectF rectF = getMatrixRectF();
            if (getDrawable() != null) {
                isCheckLeftAndRight = isCheckTopAndBottom = true;
                // No left/right translation if image width is less than screen width
                if (rectF.width() < getWidth()) {
                    dx = 0;
                    isCheckLeftAndRight = false;
                }
                // No Up/Down translation if image height is less than screen height
                if (rectF.height() < getHeight()) {
                    dy = 0;
                    isCheckTopAndBottom = false;
                }
                scaleMatrix.postTranslate(dx, dy);
                checkMatrixBounds();
                setImageMatrix(scaleMatrix);
            }
        }
        lastX = x;
        lastY = y;
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        lastPointerCount = 0;
        break;
    }
    return true;
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private void onTouchDragEvent(int action, MotionEvent ev) {
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        }/* w ww .  j  a v a2s. c  om*/

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mIsDragging = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            mScaleDragGestureListener.onDrag(dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;

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

    case MotionEvent.ACTION_CANCEL: {
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mIsDragging) {
            if (null != mVelocityTracker) {
                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mScaleDragGestureListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }
}

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

private boolean onTouchEventUseViewRotation(MotionEvent event) {
    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        attemptClaimDrag(true);//ww w . j a va  2s. com
        break;

    case MotionEvent.ACTION_UP:
        attemptClaimDrag(false);
        break;
    }

    return super.onTouchEvent(event);
}

From source file:com.example.castCambot.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));

    // When the user clicks on the button, use Android voice recognition to
    // get text//w w  w .j a v a2 s .c  o  m

    Button voiceButton = (Button) findViewById(R.id.voiceButton);
    voiceButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startVoiceRecognitionActivity();
        }
    });

    Button buttonOK = (Button) findViewById(R.id.buttonOK);
    buttonOK.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //startVoiceRecognitionActivity();
            EditText editText1 = (EditText) findViewById(R.id.editText1);
            cambotIP = editText1.getText().toString();
            Button buttonOK = (Button) findViewById(R.id.buttonOK);
            buttonOK.setVisibility(View.INVISIBLE);

            /*
            WebView   mWebView = (WebView) findViewById(R.id.webView1);
            mWebView.getSettings().setJavaScriptEnabled(true);     
            mWebView.getSettings().setLoadWithOverviewMode(true);
            mWebView.getSettings().setUseWideViewPort(true);     
            //mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
            mWebView.loadUrl("file:///android_asset/cambot.html");
            */
        }
    });

    Button button2 = (Button) findViewById(R.id.button2);
    button2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("go_forward");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button4 = (Button) findViewById(R.id.button4);
    button4.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("turn_left");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button6 = (Button) findViewById(R.id.button6);
    button6.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("turn_right");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    Button button8 = (Button) findViewById(R.id.button8);
    button8.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN)
                //System.out.println("Touch");
                myHttpPost("go_backward");
            else if (action == MotionEvent.ACTION_UP)
                //System.out.println("Release");
                myHttpPost("stop");
            return false; //  the listener has NOT consumed the event, pass it on
        }
    });

    // Configure Cast device discovery
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
            CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();
    mMediaRouterCallback = new MyMediaRouterCallback();
}

From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean isIntercepted = super.onInterceptTouchEvent(ev);
    int action = ev.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mDownX = mLastX = (int) ev.getX();
        mDownY = (int) ev.getY();
        isIntercepted = false;/*from  w ww .ja v a 2 s.co  m*/
        break;
    case MotionEvent.ACTION_MOVE:
        int disX = (int) (ev.getX() - mDownX);
        int disY = (int) (ev.getY() - mDownY);
        isIntercepted = Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY);
        break;
    case MotionEvent.ACTION_UP:
        isIntercepted = false;
        if (isMenuOpen() && mSwipeCurrentHorizontal.isClickOnContentView(getWidth(), ev.getX())) {
            smoothCloseMenu();
            isIntercepted = true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        isIntercepted = false;
        if (!mScroller.isFinished())
            mScroller.abortAnimation();
        break;
    }
    return isIntercepted;
}

From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java

@SuppressLint("ClickableViewAccessibility")
@Override//w w  w .java  2s  . c om
public boolean onTouchEvent(MotionEvent e) {
    if (!mScaleEnable)
        return super.onTouchEvent(e);
    boolean superResult = false;
    // 
    if (e.getPointerCount() >= 2) {
        // 
        if (!mScaleBegin) {
            // ACTION_UP
            final int action = e.getAction();
            e.setAction(MotionEvent.ACTION_UP);
            setForceInterceptDispatchOnScrollStateChanged(true);
            superResult = super.onTouchEvent(e);
            setForceInterceptDispatchOnScrollStateChanged(false);
            e.setAction(action);
            mScaleBegin = true;
        }
        superResult = mScaleGestureDetector.onTouchEvent(e) || superResult;
    } else {
        // ?
        final int action = e.getAction();
        boolean dispatch = false;
        if (action == MotionEvent.ACTION_UP && getScrollState() == SCROLL_STATE_IDLE) {
            dispatch = true;
        }
        if (mScaleBegin) {
            mScaleBegin = false;
            // ?ACTION_DOWN
            e.setAction(MotionEvent.ACTION_DOWN);
            super.onInterceptTouchEvent(e);
            e.setAction(action);
        }
        superResult = super.onTouchEvent(e);
        if (dispatch) {
            dispatchOnScrollStateChanged(SCROLL_STATE_IDLE);
        }
    }
    return superResult;
}

From source file:com.hackensack.umc.activity.DependentDetailsActivity.java

private void inflateXml() {
    mGenderAdapter = new SpecialtyListAdapter(DependentDetailsActivity.this, mGenderArray, true);
    mGender = (EditText) findViewById(R.id.gender_edt);
    mGender.setOnTouchListener(new View.OnTouchListener() {

        @Override//from   w  w w.  ja  va  2 s  .  co m
        public boolean onTouch(View v, MotionEvent event) {

            //                if((alert == null || !alert.isShowing()) && count == 0)
            if (event.getAction() == MotionEvent.ACTION_UP)
                showGenderDialog();

            return false;
        }
    });
    bDateLayout = (LinearLayout) findViewById(R.id.date_ll);
    bDateLayout.setOnClickListener(this);
    findViewById(R.id.addr_rl).setOnClickListener(this);
    findViewById(R.id.insurance_rl).setOnClickListener(this);
    btnAddPhone = (TextView) findViewById(R.id.add_phone);
    btnAddPhone.setOnClickListener(this);

    mFname = (EditText) findViewById(R.id.reg_fname);
    mLname = (EditText) findViewById(R.id.reg_lname);
    mEmail = (EditText) findViewById(R.id.reg_email);
    txtBirthDate = ((TextView) bDateLayout.findViewById(R.id.date_tv));
    edtLicense = ((EditText) findViewById(R.id.reg_license));
    btnProceed = (Button) findViewById(R.id.btnProceed);
    btnProceed.setOnClickListener(this);

    inflatePhoneNumbersLayout();
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

@SuppressLint({ "NewApi", "SimpleDateFormat" })
public VerticalSingleItemView(final DataMgr dataMgr, final Context context, final String uid, final View menu,
        final VerticalItemViewCtrl itemViewCtrl) {
    this.dataMgr = dataMgr;
    this.context = context;
    this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION);
    this.fontSize = new SettingFontSize(dataMgr).getData();
    this.theme = new SettingTheme(dataMgr).getData();
    this.showTop = false;
    this.showBottom = false;
    this.menu = menu;
    this.itemViewCtrl = itemViewCtrl;
    this.imageClickTime = 0;

    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.view = inflater.inflate(R.layout.single_item_view, null);
    // Disable hardware acceleration on Android 3.0-4.1 devices.
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
            && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }//from w w  w  .ja va2 s  .com

    lastItemView = view.findViewById(R.id.LastItemView);
    nextItemView = view.findViewById(R.id.NextItemView);
    itemScrollView = (OverScrollView) view.findViewById(R.id.ItemScrollView);
    itemScrollView.setTopScrollView(lastItemView);
    itemScrollView.setBottomScrollView(nextItemView);
    itemScrollView.setOnScrollChangeListener(this);
    itemScrollView.setOnTouchListener(this);

    final View btnShowOriginal = view.findViewById(R.id.BtnShowOriginal);
    btnShowOriginal.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            boolean ret = false;
            final TextView txt = (TextView) view.findViewById(R.id.BtnText);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                txt.setTextColor(0xFF787878);
                ret = true;
                break;
            case MotionEvent.ACTION_MOVE:
                ret = true;
                break;
            case MotionEvent.ACTION_CANCEL:
                txt.setTextColor(0xBB787878);
                ret = false;
                break;
            case MotionEvent.ACTION_UP:
                txt.setTextColor(0xBB787878);
                final SettingBrowserChoice setting = new SettingBrowserChoice(dataMgr);
                if (setting.getData() == SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL) {
                    final Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.setData(Uri.parse(item.getHref()));
                    context.startActivity(intent);
                } else if (VerticalSingleItemView.this.listener != null) {
                    VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), false);
                }
                break;
            default:
            }
            return ret;
        }
    });

    final View btnShowMobilized = view.findViewById(R.id.BtnShowMobilized);
    btnShowMobilized.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            boolean ret = false;
            final TextView txt = (TextView) view.findViewById(R.id.BtnText);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                txt.setTextColor(0xFF787878);
                ret = true;
                break;
            case MotionEvent.ACTION_MOVE:
                ret = true;
                break;
            case MotionEvent.ACTION_CANCEL:
                txt.setTextColor(0xBB787878);
                ret = false;
                break;
            case MotionEvent.ACTION_UP:
                txt.setTextColor(0xBB787878);
                if (VerticalSingleItemView.this.listener != null) {
                    VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), true);
                }
                ret = true;
                break;
            default:
            }
            return ret;
        }
    });

    {
        final ListItemItem lastItem = itemViewCtrl.getLastItem(item.getUid());
        final TextView txt = (TextView) lastItemView.findViewById(R.id.LastItemTitle);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
        if (lastItem == null) {
            lastUid = null;
            menu.findViewById(R.id.BtnPrevious).setEnabled(false);
            final ImageView img = (ImageView) lastItemView.findViewById(R.id.LastItemArrow);
            img.setImageResource(R.drawable.no_more_circle);
            txt.setText(R.string.TxtNoPreviousItem);
        } else {
            lastUid = lastItem.getId();
            final View btnLast = menu.findViewById(R.id.BtnPrevious);
            btnLast.setEnabled(true);
            btnLast.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View view) {
                    if (listener != null) {
                        listener.showLastItem();
                    }
                }
            });
            txt.setText(lastItem.getTitle());
        }
    }

    {
        final ListItemItem nextItem = itemViewCtrl.getNextItem(item.getUid());
        final TextView txt = (TextView) nextItemView.findViewById(R.id.NextItemTitle);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
        if (nextItem == null) {
            nextUid = null;
            menu.findViewById(R.id.BtnNext).setEnabled(false);
            final ImageView img = (ImageView) nextItemView.findViewById(R.id.NextItemArrow);
            img.setImageResource(R.drawable.no_more_circle);
            txt.setText(R.string.TxtNoNextItem);
        } else {
            nextUid = nextItem.getId();
            final View btnNext = menu.findViewById(R.id.BtnNext);
            btnNext.setEnabled(true);
            btnNext.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View view) {
                    if (listener != null) {
                        listener.showNextItem();
                    }
                }
            });
            txt.setText(nextItem.getTitle());
        }
    }

    final TextView title = (TextView) view.findViewById(R.id.ItemTitle);
    title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3);
    title.setText(item.getTitle());
    final TextView info = (TextView) view.findViewById(R.id.ItemInfo);
    info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5);
    final StringBuilder infoText = new StringBuilder();
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    sdf.setTimeZone(TimeZone.getDefault());
    infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp())));
    if (item.getAuthor() != null && item.getAuthor().length() > 0) {
        infoText.append(" | By ");
        infoText.append(item.getAuthor());
    }
    if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) {
        infoText.append(" (");
        infoText.append(item.getSourceTitle());
        infoText.append(")");
    }
    info.setText(infoText);

    webView = (WebView) view.findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setBackgroundColor(context.getResources()
            .getColor(theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground));
    webView.setFocusable(false);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            if (VerticalSingleItemView.this.imageClickTime > System.currentTimeMillis() - 1000) {
                return true;
            }
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse(url));
            context.startActivity(intent);
            return true;
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(final WebView view, final String url, final String message,
                final JsResult result) {
            if (VerticalSingleItemView.this.listener != null) {
                if (message.endsWith(".erss")) {
                    VerticalSingleItemView.this.listener
                            .onImageViewRequired(item.getStoragePath() + "/" + message);
                } else {
                    VerticalSingleItemView.this.listener.onImageViewRequired(message);
                }
            }
            VerticalSingleItemView.this.imageClickTime = System.currentTimeMillis();
            result.cancel();
            return true;
        }
    });

    updateButtonStar();
    updateButtonSharing();
    updateButtonOpenLink();

    if (!item.getState().isRead()) {
        dataMgr.markItemAsReadWithTransactionByUid(uid);
        NetworkMgr.getInstance().startImmediateItemStateSyncing();
    }
}

From source file:CustomSwipeDismissBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    switch (MotionEventCompat.getActionMasked(event)) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        // Reset the ignore flag
        if (mIgnoreEvents) {
            mIgnoreEvents = false;/*from   ww w  .  j a  v a2  s.co m*/
            return false;
        }
        break;
    default:
        mIgnoreEvents = !parent.isPointInChildBounds(child, (int) event.getX(), (int) event.getY());
        break;
    }

    if (mIgnoreEvents) {
        return false;
    }

    ensureViewDragHelper(parent);
    return mViewDragHelper.shouldInterceptTouchEvent(event);
}

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

/**
 * Observes motion events and determines when to start forwarding.
 *
 * @param srcEvent motion event in source view coordinates
 * @return true to start forwarding motion events, false otherwise
 *///  w ww  .  j av  a 2s  .c o m
private boolean onTouchObserved(MotionEvent srcEvent) {
    final View src = mSrc;
    if (!src.isEnabled()) {
        return false;
    }

    final int actionMasked = MotionEventCompat.getActionMasked(srcEvent);
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = srcEvent.getPointerId(0);

        if (mDisallowIntercept == null) {
            mDisallowIntercept = new DisallowIntercept();
        }
        src.postDelayed(mDisallowIntercept, mTapTimeout);

        if (mTriggerLongPress == null) {
            mTriggerLongPress = new TriggerLongPress();
        }
        src.postDelayed(mTriggerLongPress, mLongPressTimeout);
        break;
    case MotionEvent.ACTION_MOVE:
        final int activePointerIndex = srcEvent.findPointerIndex(mActivePointerId);
        if (activePointerIndex >= 0) {
            final float x = srcEvent.getX(activePointerIndex);
            final float y = srcEvent.getY(activePointerIndex);

            // Has the pointer moved outside of the view?
            if (!pointInView(src, x, y, mScaledTouchSlop)) {
                clearCallbacks();

                // Don't let the parent intercept our events.
                src.getParent().requestDisallowInterceptTouchEvent(true);
                return true;
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        clearCallbacks();
        break;
    }

    return false;
}