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:cc.solart.turbo.TurboRecyclerView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) {
        return super.onInterceptTouchEvent(e);
    }//  ww w  . j a  v a 2s  . c o m

    if (dispatchOnItemTouchIntercept(e)) {
        return true;
    }

    final int action = MotionEventCompat.getActionMasked(e);
    final int actionIndex = MotionEventCompat.getActionIndex(e);
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mActivePointerId = MotionEventCompat.getPointerId(e, 0);
        mInitialMotionX = getMotionEventX(e, actionIndex);
        mInitialMotionY = getMotionEventY(e, actionIndex);
    }
        break;

    case MotionEvent.ACTION_POINTER_DOWN: {
        mActivePointerId = MotionEventCompat.getPointerId(e, actionIndex);
        mInitialMotionX = getMotionEventX(e, actionIndex);
        mInitialMotionY = getMotionEventY(e, actionIndex);
    }
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER;
        break;
    case MotionEventCompat.ACTION_POINTER_UP: {
        onPointerUp(e);
    }
        break;
    }
    return super.onInterceptTouchEvent(e);
}

From source file:cn.ieclipse.af.view.ScrollLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (debug) {/*from ww  w .jav  a  2s  .c om*/
        Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop);
    }

    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
        return true;
    }

    final float x = ev.getX();
    final float y = ev.getY();

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        final int xDiff = (int) Math.abs(mLastMotionX - x);
        if (xDiff > mTouchSlop) {
            mTouchState = TOUCH_STATE_SCROLLING;

        }
        break;

    case MotionEvent.ACTION_DOWN:
        mLastMotionX = x;
        mLastMotionY = y;
        mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
        break;

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mTouchState = TOUCH_STATE_REST;
        break;
    }

    return mTouchState != TOUCH_STATE_REST;
}

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

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        mIgnoreEvents = true;/*from  w  w w  .  j  a  v a 2s  .  c  o m*/
        return false;
    }
    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:
        int initialX = (int) event.getX();
        mInitialY = (int) event.getY();
        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:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getActionMasked();

    if (canChildScrollUp()) {
        // Fail fast if we're not in a state where a swipe is possible
        return super.onTouchEvent(ev);
    }//from  w  ww  . j  a v  a2s  .c o  m

    mVelocityTracker.addMovement(ev);

    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialTouchX = x;
        mInitialTouchY = mLastTouchY = y;
        mActivePointerId = ev.getPointerId(0);
        if (findChildUnder(mInitialTouchX, mInitialTouchY) == null && mClickOutsideListener != null) {
            mIsDragging = handled = true;
        }
        handled |= mCollapsibleHeight > 0;
        mScroller.abortAnimation();
    }
        break;

    case MotionEvent.ACTION_MOVE: {
        int index = ev.findPointerIndex(mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "Bad pointer id " + mActivePointerId + ", resetting");
            index = 0;
            mActivePointerId = ev.getPointerId(0);
            mInitialTouchX = ev.getX();
            mInitialTouchY = mLastTouchY = ev.getY();
        }
        final float x = ev.getX(index);
        final float y = ev.getY(index);
        if (!mIsDragging) {
            final float dy = y - mInitialTouchY;
            if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) {
                handled = mIsDragging = true;
                mLastTouchY = Math.max(mLastTouchY - mTouchSlop,
                        Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop));
            }
        }
        if (mIsDragging) {
            final float dy = y - mLastTouchY;
            performDrag(dy);
        }
        mLastTouchY = y;
    }
        break;

    case MotionEvent.ACTION_POINTER_DOWN: {
        final int pointerIndex = ev.getActionIndex();
        final int pointerId = ev.getPointerId(pointerIndex);
        mActivePointerId = pointerId;
        mInitialTouchX = ev.getX(pointerIndex);
        mInitialTouchY = mLastTouchY = ev.getY(pointerIndex);
    }
        break;

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
    }
        break;

    case MotionEvent.ACTION_UP: {
        mIsDragging = false;
        if (!mIsDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null
                && findChildUnder(ev.getX(), ev.getY()) == null) {
            if (mClickOutsideListener != null) {
                mClickOutsideListener.onClick(this);
                resetTouch();
                return true;
            }
        }
        if (mOpenOnClick && Math.abs(ev.getX() - mInitialTouchX) < mTouchSlop
                && Math.abs(ev.getY() - mInitialTouchY) < mTouchSlop) {
            smoothScrollTo(0, 0);
            return true;
        }
        mVelocityTracker.computeCurrentVelocity(1000);
        final float yvel = mVelocityTracker.getYVelocity(mActivePointerId);
        if (Math.abs(yvel) > mMinFlingVelocity) {
            smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel);
        } else {
            smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0);
        }
        resetTouch();
    }
        break;

    case MotionEvent.ACTION_CANCEL: {
        if (mIsDragging) {
            smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0);
        }
        resetTouch();
        return true;
    }
    }

    return handled || (action == MotionEvent.ACTION_MOVE && mCollapseOffset > 0);
}

From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_UP:
        final CalendarDay day = getDayFromLocation(event.getX(), event.getY());
        if (day != null) {
            onDayClick(day);/*from   w w  w .j  a v a2  s. c o m*/
        }
        break;
    }
    return true;
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        mIgnoreEvents = true;//ww  w  .  j  a  v  a  2  s  .c om
        return false;
    }
    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:
        int initialX = (int) event.getX();
        mInitialY = (int) event.getY();
        for (WeakReference<View> scrollableView : scrollableViews) {
            View scroll = scrollableView.get();
            if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) {
                mActivePointerId = event.getPointerId(event.getActionIndex());
                mTouchingScrollingChild = true;
                break;
            }
        }

        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.
    boolean isPointInChildBounds = false;

    for (WeakReference<View> scrollableView : scrollableViews) {
        isPointInChildBounds = scrollableView.get() != null
                && parent.isPointInChildBounds(scrollableView.get(), (int) event.getX(), (int) event.getY());
        if (isPointInChildBounds) {
            break;
        }
    }

    return action == MotionEvent.ACTION_MOVE && !mIgnoreEvents && mState != STATE_DRAGGING
            && !isPointInChildBounds && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop();
}

From source file:com.microsoft.windowsazure.mobileservices.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * //from w w  w.ja va2s .c  om
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
private void showLoginUI(final String startUrl, final String endUrl, final Context context,
        LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });
    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:com.android.volley.ui.PhotoView.java

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    final int action = e.getAction();
    boolean handled = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (mQuickScaleEnabled) {
            mDownFocusX = e.getX();//from   w  w w  . j a  v  a  2s. co m
            mDownFocusY = e.getY();
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mQuickScaleEnabled) {
            handled = scale(e);
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mQuickScaleEnabled && mDoubleTapOccurred) {
            final int deltaX = (int) (e.getX() - mDownFocusX);
            final int deltaY = (int) (e.getY() - mDownFocusY);
            int distance = (deltaX * deltaX) + (deltaY * deltaY);
            if (distance > sTouchSlopSquare) {
                mDoubleTapOccurred = false;
            }
        }
        break;

    }
    return handled;
}

From source file:com.df.kia.procedures.CarRecogniseLayout.java

private void init(final Context context) {
    rootView = LayoutInflater.from(context).inflate(R.layout.car_recognise_layout, this);

    deleteLastLicensePhoto();/* w w w .j av  a 2s.  com*/

    mCarSettings = InputProceduresLayout.mCarSettings;

    licenseRecognise = new LicenseRecognise(context, AppCommon.licensePhotoPath);

    licenseImageView = (ImageView) findViewById(R.id.licenseImage);
    licenseImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            licenseRecognise.takePhoto(mHandler);
        }
    });

    // 
    recogniseButton = (Button) rootView.findViewById(R.id.recognise_button);
    recogniseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // ???
            if (!mCarSettings.getBrandString().equals("")) {
                reRecognise(R.string.reRecognise1);
            } else if (!getEditViewText(rootView, R.id.plateNumber_edit).equals("")) {
                reRecognise(R.string.reRecognise);
            } else {
                //fillInDummyData();
                if (licensePhotoExist())
                    recogniseLicense();
                else
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT).show();
            }
        }
    });

    // vin
    Button vinConfirmButton = (Button) rootView.findViewById(R.id.vinConfirm_button);
    vinConfirmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // VIN??
            if (getEditViewText(rootView, R.id.vin_edit).equals("")) {
                Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show();
            } else {
                checkVinAndGetCarSettings();
            }
        }
    });

    // ?
    Button brandSelectButton = (Button) rootView.findViewById(R.id.brand_select_button);
    brandSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            selectCarManually();
        }
    });

    vehicleTypeEdit = (EditText) rootView.findViewById(R.id.vehicleType_edit);
    vehicleTypeEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.vehicleType_items, R.id.vehicleType_edit);
                break;
            }
            return false;
        }
    });

    useCharacterEdit = (EditText) rootView.findViewById(R.id.useCharacter_edit);
    useCharacterEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.useCharacter_items, R.id.useCharacter_edit);
                break;
            }
            return false;
        }
    });

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };

    EditText vin_edit = (EditText) findViewById(R.id.vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps(),
            new InputFilter.LengthFilter(17) });

    EditText plateNumberEdit = (EditText) findViewById(R.id.plateNumber_edit);
    plateNumberEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    EditText licenseModelEdit = (EditText) findViewById(R.id.licenseModel_edit);
    licenseModelEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(22) });

    EditText engineSerialEdit = (EditText) findViewById(R.id.engineSerial_edit);
    engineSerialEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(17) });

    vehicleModel = MainActivity.vehicleModel;
}

From source file:heartware.com.heartware_master.FriendsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_friends, container, false);

    mMeetupDialog = new MeetupDialogFragment();

    profilePictureView = (ProfilePictureView) view.findViewById(R.id.selection_profile_pic);
    profilePictureView.setCropped(true);
    bLoginButton = (LoginButton) view.findViewById(R.id.login_button);
    bLoginButton.setReadPermissions("user_friends");
    bLoginButton.setFragment(this);
    bLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override/* w  ww.ja va2  s .c om*/
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException e) {
            Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show();
        }
    });

    bMeetup = (ImageButton) view.findViewById(R.id.create_meetup);
    bMeetup.getBackground().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY);
    shareButton = (ShareButton) view.findViewById(R.id.share_button);
    listView = (ListView) view.findViewById(R.id.selection_list);
    photoThumbnail = (ImageView) view.findViewById(R.id.selected_image);

    bMeetup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });

    bMeetup.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // show interest in events resulting from ACTION_DOWN
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                bMeetup.setSelected(true);
                createMeetup();
                return true;
            }
            // don't handle event unless its ACTION_UP so "doSomething()" only runs once.

            if (event.getAction() != MotionEvent.ACTION_UP) {
                bMeetup.setSelected(false);

                return false;
            }

            return true;
        }
    });

    shareButton.registerCallback(callbackManager, shareCallback);
    shareButton.setFragment(this);

    init(savedInstanceState);
    updateWithToken(AccessToken.getCurrentAccessToken());

    return view;
}