Example usage for android.view MotionEvent getRawY

List of usage examples for android.view MotionEvent getRawY

Introduction

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

Prototype

public final float getRawY() 

Source Link

Document

Returns the original raw Y coordinate of this event.

Usage

From source file:com.nononsenseapps.feeder.ui.SwipeDismissTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    // offset because the view is translated during swipe
    motionEvent.offsetLocation(mTranslationX, 0);

    if (mViewWidth < 2) {
        mViewWidth = mView.getWidth();/* w  w  w .  j  a  va2s. c o m*/
    }

    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        // TODO: ensure this is a finger, and set a flag
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        if (mCallbacks.canDismiss(mToken)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        }
        return false;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss) {
            // dismiss
            mSwipingView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth)
                    //.alpha(0)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            performDismiss();
                        }
                    });
        } else if (mSwiping) {
            // cancel
            mSwipingView.animate().translationX(0)
                    //.alpha(1)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mCallbacks.onSwipeCancelled();
                        }
                    });
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mTranslationX = 0;
        mDownX = 0;
        mDownY = 0;
        mSwiping = false;
        notNotifiedSwipeStart = true;
        break;
    }

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

        mSwipingView.animate().translationX(0)
                //.alpha(1)
                .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mCallbacks.onSwipeCancelled();
                    }
                });
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mTranslationX = 0;
        mDownX = 0;
        mDownY = 0;
        mSwiping = false;
        notNotifiedSwipeStart = true;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mView.getParent().requestDisallowInterceptTouchEvent(true);

            // Cancel listview's touch
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
        }

        if (mSwiping) {
            if (notNotifiedSwipeStart) {
                notNotifiedSwipeStart = false;
                mCallbacks.onSwipeStarted(deltaX > 0);
            }
            mTranslationX = deltaX;
            mSwipingView.setTranslationX(deltaX - mSwipingSlop);
            //mView.setAlpha(mInterpolator.getInterpolation(1f - 1f * Math.abs(deltaX) / mViewWidth));
            //                    mView.setAlpha(Math.max(0f, Math.min(1f,
            //                            1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:de.mrapp.android.bottomsheet.view.DraggableView.java

@Override
public final boolean onTouchEvent(final MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        return true;
    case MotionEvent.ACTION_MOVE:
        dragHelper.update(event.getRawY());
        handleDrag();/* ww w . j ava  2  s  .c o  m*/
        return true;
    case MotionEvent.ACTION_UP:
        dragHelper.reset();

        if (dragHelper.hasThresholdBeenReached()) {
            handleRelease();
        }

        performClick();
        return true;
    default:
        break;
    }

    return super.onTouchEvent(event);
}

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

private boolean detectSwipe(float x, float y, MotionEvent e) {
    if (mState == STATE_AWAITING_RELEASE && mSwipeInProgress) {
        if (mCallback != null) {
            mSwipeListener.setSwipeLocation(this, (int) e.getX(), (int) e.getY(), (int) e.getRawX(),
                    (int) e.getRawY());
        }/*from   w  w  w.j  a  v a 2 s  . com*/
        return true;
    }
    if (mState != STATE_GESTURE_IN_PROGRESS)
        return false;
    float deltaX = Math.abs(x - mStartX);
    float deltaY = y - mStartY;
    Gesture action = detectAction(deltaX, deltaY, mMinimumMove);
    if (action != null) {
        mSwipeListener = mCallback.open(this, action, (int) x, (int) y);
        mSwipeInProgress = mSwipeListener != null;
        mState = STATE_AWAITING_RELEASE;
        return true;
    }
    return true;
}

From source file:com.test.slidebutton.SlideButton.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (slidable == false)
        return super.onTouchEvent(event);

    int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        startX = (int) event.getRawX();
        startY = (int) event.getRawY();
        break;/*from w  w  w . j a v  a2 s  . c o  m*/
    case MotionEvent.ACTION_MOVE:
        lastX = (int) event.getRawX();
        lastY = (int) event.getRawY();

        offsetX = lastX - startX;

        if (!this.canMove) {
            if (Math.abs(offsetX) > touchSlop && Math.abs(offsetX) > Math.abs(lastY - startY)) {
                this.canMove = true;
                return true;
            } else {
                return super.onTouchEvent(event);
            }
        } else {
            sliderCurrentLeft = offsetX + sliderMoveStartLeft;
            if (sliderCurrentLeft > max_left) {
                sliderCurrentLeft = max_left;
            } else if (sliderCurrentLeft < min_left) {
                sliderCurrentLeft = min_left;
            }
            alpha = (int) (255 * ((sliderCurrentLeft - min_left) / (float) (max_left - min_left)));
            caculateColor();
            invalidateView();
        }
        break;
    case MotionEvent.ACTION_UP:
        lastX = (int) event.getRawX();
        boolean toRight = (sliderCurrentLeft > max_left / 2 ? true : false);
        if (this.canMove) {
            this.canMove = false;
        } else {//
            toRight = !toRight;
        }
        moveTo(toRight);
        break;
    default:
        break;
    }
    return true;
}

From source file:com.taobao.weex.ui.view.listview.BaseBounceView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    if (action != MotionEvent.ACTION_DOWN && mIsBeingDragged) {
        return true;
    }/*from  w w  w.j  a  v a2 s  .c om*/
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mLastMotionY = ev.getRawY();
        mLastMotionX = ev.getRawX();
        //listview??listview.setPadding()getPaddingTop()scrollValue??
        mScrollValue = -getPaddingTop();
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        float x = ev.getRawX();
        float y = ev.getRawY();
        float deltaX = ev.getRawX() - mLastMotionX;
        float deltaY = ev.getRawY() - mLastMotionY;
        float degree = Math.abs(deltaY) / Math.abs(deltaX);
        //Log.v(getClass().getSimpleName(), "onInterceptTouchEvent move");
        if (Math.abs(deltaY) > mTouchSlop && degree >= 1.7f && mBounceable) {
            if (deltaY > 0 && isReadyForPullFromTop()) {
                mLastMotionX = x;
                mLastMotionY = y;
                mIsBeingDragged = true;
                mMode = Mode.PULL_FROM_TOP;
            } else if (deltaY < 0 && isReadyForPullFromBottom()) {
                mLastMotionX = x;
                mLastMotionY = y;
                mIsBeingDragged = true;
                mMode = Mode.PULL_FROM_BOTTOM;
            }

        }
        break;
    }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
    }
    }
    return mIsBeingDragged;
}

From source file:org.coursera.android.shift.ShiftIconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.shift_menu, container, false);

    mHead = layout.findViewById(R.id.head);
    final RelativeLayout.LayoutParams iconParams;
    iconParams = (RelativeLayout.LayoutParams) mHead.getLayoutParams();

    final GestureDetector gestureDetector = new GestureDetector(getActivity(), new SingleTapConfirm());

    mHead.setOnTouchListener(new View.OnTouchListener() {
        private int initialX;
        private int initialY;
        private float initialTouchX;
        private float initialTouchY;

        @Override//from w w w . ja  va 2s . c om
        public boolean onTouch(View v, MotionEvent event) {
            final int yLimit = layout.getMeasuredHeight() - mHead.getMeasuredHeight();
            final int xLimit = layout.getMeasuredWidth() - mHead.getMeasuredWidth();

            // single tap
            if (gestureDetector.onTouchEvent(event)) {
                mShiftLauncherView.showShiftMenu(getActivity());
                return true;
            }

            // drag icon
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                initialX = iconParams.leftMargin;
                initialY = iconParams.topMargin;
                initialTouchX = event.getRawX();
                initialTouchY = event.getRawY();
                return true;
            case MotionEvent.ACTION_CANCEL:
                return false;
            case MotionEvent.ACTION_UP:
                return true;
            case MotionEvent.ACTION_MOVE:
                int newX = initialX + (int) (event.getRawX() - initialTouchX);
                int newY = initialY + (int) (event.getRawY() - initialTouchY);

                iconParams.leftMargin = newX < 0 ? 0 : Math.min(newX, xLimit);
                iconParams.topMargin = newY < 0 ? 0 : Math.min(newY, yLimit);

                layout.updateViewLayout(mHead, iconParams);
                return true;
            }
            return false;
        }
    });
    return layout;
}

From source file:de.mrapp.android.bottomsheet.view.DraggableView.java

@Override
public final boolean dispatchTouchEvent(final MotionEvent event) {
    boolean handled = false;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        break;//from ww w. jav a 2 s  .  co m
    case MotionEvent.ACTION_MOVE:
        dragHelper.update(event.getRawY());

        if (isMaximized() && (event.getRawY() - dragHelper.getStartPosition() < 0
                || isScrollUpEvent(event.getRawX(), event.getRawY()))) {
            dragHelper.reset();
            break;
        }

        handled = handleDrag();
        break;
    case MotionEvent.ACTION_UP:
        dragHelper.reset();

        if (dragHelper.hasThresholdBeenReached()) {
            handleRelease();
        }

        break;
    default:
        break;
    }

    return handled || super.dispatchTouchEvent(event);
}

From source file:com.jackie.refresh.RefreshLayoutBase.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.d(TAG, "onTouchEvent() called with: " + "event = [" + event.toString() + "]");
    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE: // 
        // ??y??//from   ww w  .  j a v  a 2s .  c om
        int currentY = (int) event.getRawY();
        // ???
        mYOffset = currentY - mLastY;
        if (mCurrentStatus != STATUS_LOADING) {
            // Y?
            changeScrollY(mYOffset);
        }

        // Header View
        rotateHeaderArrow();
        // Header View?
        changeTips();
        // mLastYY??
        mLastY = currentY;
        break;

    case MotionEvent.ACTION_UP:
        if (isTop()) {
            // ?
            doRefresh();
        }

        break;
    default:
        break;
    }
    //        return super.onTouchEvent(event);
    return true;
}

From source file:com.netease.qa.emmagee.service.EmmageeService.java

/**
 * create a floating window to show real-time data.
 *//*from ww  w  .  ja va 2 s. co m*/
private void createFloatingWindow() {
    SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = shared.edit();
    editor.putInt("float", 1);
    editor.commit();
    windowManager = (WindowManager) getApplicationContext().getSystemService("window");
    wmParams = ((MyApplication) getApplication()).getMywmParams();
    wmParams.type = 2002;
    wmParams.flags |= 8;
    wmParams.gravity = Gravity.LEFT | Gravity.TOP;
    wmParams.x = 0;
    wmParams.y = 0;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = 1;
    windowManager.addView(viFloatingWindow, wmParams);
    viFloatingWindow.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            x = event.getRawX();
            y = event.getRawY() - statusBarHeight;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mTouchStartX = event.getX();
                mTouchStartY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                updateViewPosition();
                break;
            case MotionEvent.ACTION_UP:
                updateViewPosition();
                mTouchStartX = mTouchStartY = 0;
                break;
            }
            return true;
        }
    });

    btnWifi.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi);
                String buttonText = (String) btnWifi.getText();
                String wifiText = getResources().getString(R.string.open_wifi);
                if (buttonText.equals(wifiText)) {
                    wifiManager.setWifiEnabled(true);
                    btnWifi.setText(R.string.close_wifi);
                } else {
                    wifiManager.setWifiEnabled(false);
                    btnWifi.setText(R.string.open_wifi);
                }
            } catch (Exception e) {
                Toast.makeText(viFloatingWindow.getContext(), getString(R.string.wifi_fail_toast),
                        Toast.LENGTH_LONG).show();
                Log.e(LOG_TAG, e.toString());
            }
        }
    });
}

From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java

@Override
public boolean onTouch(View view, MotionEvent event) {
    if (event.getPointerCount() > 1) {
        return super.onTouchEvent(event);
    }/*  ww  w .  ja va 2  s  . c  o m*/

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();

    int action = MotionEventCompat.getActionMasked(event);
    if (view.getId() == R.id.frame_bottom || view.getId() == R.id.frame_top) {
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            initialPoint = event.getRawY();
            moving = true;
            break;
        case MotionEvent.ACTION_MOVE:
            if (moving) {
                hinter.interrupt();
                currentPoint = event.getRawY();

                DisplayMetrics displayMetrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
                int screenHeight = displayMetrics.heightPixels;

                if (view.getId() == R.id.frame_top) {
                    int new_margin = (int) (currentPoint - initialPoint);
                    params.topMargin = (new_margin > 0) ? new_margin : 0;
                    if ((new_margin > (screenHeight / 3)) && (!isFinishing())) {
                        snoozeAlarm();
                        break;
                    }
                } else {
                    int new_margin = (int) (initialPoint - currentPoint);
                    params.bottomMargin = (new_margin > 0) ? new_margin : 0;
                    if ((new_margin > (screenHeight / 3)) && (!isFinishing())) {
                        cancelAlarm();
                        break;
                    }
                }
                view.setLayoutParams(params);
                view.invalidate();
            }
            break;
        case MotionEvent.ACTION_UP:
            initialPoint = 0;
            TranslateAnimation ta;
            if (view.getId() == R.id.frame_top) {
                ta = new TranslateAnimation(0, 0, params.topMargin, 0);
                params.topMargin = 0;
            } else {
                ta = new TranslateAnimation(0, 0, -params.bottomMargin, 0);
                params.bottomMargin = 0;
            }
            ta.setDuration(100);
            view.setLayoutParams(params);
            view.startAnimation(ta);
            moving = false;
            startHinter();
            break;
        default:
            return super.onTouchEvent(event);
        }
    }
    return true;
}