Example usage for android.view MotionEvent getRawX

List of usage examples for android.view MotionEvent getRawX

Introduction

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

Prototype

public final float getRawX() 

Source Link

Document

Returns the original raw X coordinate of this event.

Usage

From source file:io.github.hidroh.materialistic.widget.NavFloatingActionButton.java

@Synthetic
void startDrag(float startX, float startY) {
    mVibrator.vibrate(VIBRATE_DURATION_MS * 2);
    Toast.makeText(getContext(), R.string.hint_drag, Toast.LENGTH_SHORT).show();
    //noinspection Convert2Lambda
    super.setOnTouchListener(new OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override//from   w w w.j a  va2  s . c om
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_MOVE:
                view.setX(motionEvent.getRawX() - startX); // TODO compensate shift
                view.setY(motionEvent.getRawY() - startY);
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                bindNavigationPad();
                break;
            default:
                return false;
            }
            return true;
        }
    });
}

From source file:com.yamin.kk.fragment.AudioMiniPlayer.java

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

    // Initialize the children
    mCover = (ImageView) v.findViewById(R.id.cover);
    mTitle = (TextView) v.findViewById(R.id.title);
    mArtist = (TextView) v.findViewById(R.id.artist);
    mPlayPause = (ImageButton) v.findViewById(R.id.play_pause);
    mForward = (ImageButton) v.findViewById(R.id.forward);
    mBackward = (ImageButton) v.findViewById(R.id.backward);
    mPlayPause.setOnClickListener(onMediaControlClickListener);
    mForward.setOnClickListener(onMediaControlClickListener);
    mBackward.setOnClickListener(onMediaControlClickListener);
    mProgressBar = (ProgressBar) v.findViewById(R.id.timeline);

    final LinearLayout root = (LinearLayout) v.findViewById(R.id.root_node);

    root.setOnTouchListener(new View.OnTouchListener() {
        @Override/*www. j  av a 2  s.  c  o  m*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mTouchX = event.getRawX();
                mTouchY = event.getRawY();
                break;
            case MotionEvent.ACTION_UP:
                if (mTouchY - event.getRawY() > root.getHeight()) {
                    Toast.makeText(AudioMiniPlayer.this.getActivity(), "AudioMiniPlayer swipe up",
                            Toast.LENGTH_SHORT).show();
                    return true;
                } else if (Math.abs(mTouchY - event.getRawY()) < 5 && Math.abs(mTouchX - event.getRawX()) < 5) {
                    // effectively a click
                    AudioPlayerFragment.start(getActivity());
                    return true;
                } else
                    return false;
            }
            return true;
        }
    });

    registerForContextMenu(v);
    return v;
}

From source file:com.tmall.wireless.tangram.view.LinearScrollView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    int action = ev.getAction();
    float x = ev.getRawX();
    float y = ev.getRawY();

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        xDown = x;/* ww  w  . ja v a 2s. com*/
        yDown = y;
        break;
    case MotionEvent.ACTION_MOVE:
        int xDistance = (int) (x - xDown);
        int yDistance = (int) (y - yDown);

        if (Math.abs(xDistance) > touchSlop && Math.abs(xDistance) > Math.abs(yDistance)) {
            if (!recyclerView.canScrollHorizontally(-1) && xDistance > 0
                    || (!recyclerView.canScrollHorizontally(1) && xDistance < 0)) {
                enableOverScrollPull = true;
                return true;
            } else {
                enableOverScrollPull = false;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (enableOverScrollPull) {
            return true;
        }
        break;
    }

    return false;
}

From source file:com.kerkr.edu.recycleView.SwipeToDismissTouchListener.java

private boolean down(MotionEvent motionEvent) {
    if (mPaused)//from ww w  .ja v a  2  s.  co m
        return false;

    mDownX = motionEvent.getRawX();
    mDownY = motionEvent.getRawY();
    mSwipeView = mRecyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
    if (mSwipeView == null)
        return false;
    int pos = mRecyclerView.getChildPosition(mSwipeView);
    mAllowedSwipeDirection = mCallbacks.canDismiss(pos);
    if (mAllowedSwipeDirection != SwipeDirection.NONE) {

        mVelocityTracker = VelocityTracker.obtain();
        mVelocityTracker.addMovement(motionEvent);
        return false;
    }
    resetMotion();
    return false;
}

From source file:com.iutiao.sdk.views.PasswordEditText.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mDrawableSide == null) {
        return super.onTouchEvent(event);
    }//from   w ww.j a  v  a  2s  . c o  m
    final Rect bounds = mDrawableSide.getBounds();
    final int x = (int) event.getRawX(); // ?

    int iconX = (int) getTopRightCorner().x;

    // Icon?
    int leftIcon = iconX - bounds.width();

    Log.e(TAG, "x: " + x + ", leftIcon: " + leftIcon);

    // Icon?, ??
    if (x >= leftIcon) {
        togglePasswordIconVisibility(); // ???
        event.setAction(MotionEvent.ACTION_CANCEL);
        return false;
    }
    return super.onTouchEvent(event);
}

From source file:com.example.androidx.media.VideoViewTest.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        int screenWidth = getResources().getDisplayMetrics().widthPixels;
        if (ev.getRawX() < (screenWidth / 2.0f)) {
            // TODO: getSpeed() not needed?
            mSpeed -= 0.1f;/*from  ww w.j a va 2s . c  o m*/
        } else {
            mSpeed += 0.1f;
        }
        mVideoView.setSpeed(mSpeed);
        Toast.makeText(this, "speed rate: " + String.format("%.2f", mSpeed), Toast.LENGTH_SHORT).show();
    }
    return super.onTouchEvent(ev);
}

From source file:ir.mhp.twowayrecycler.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionUp(MotionEvent motionEvent) {
    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;//  w w w  . ja  v  a2 s.c om
        dismissRight = deltaX > 0;
    } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
            && absVelocityY < absVelocityX && mSwiping) {
        // dismiss only if flinging in the same direction as dragging
        dismiss = (velocityX < 0) == (deltaX < 0);
        dismissRight = mVelocityTracker.getXVelocity() > 0;
    }
    if (dismiss && mDownPosition != INVALID_POSITION) {
        // dismiss
        final View downView = mDownView; // mDownView gets null'd before animation ends
        final int downPosition = mDownPosition;
        ++mDismissAnimationRefCount;
        animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        performDismiss(downView, downPosition);
                    }
                });
    } else {
        // cancel
        animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
    }
    mVelocityTracker.recycle();
    mVelocityTracker = null;
    mDownX = 0;
    mDownY = 0;
    mDownView = null;
    mDownPosition = INVALID_POSITION;
    mSwiping = false;
}

From source file:com.codingfeel.sm.views.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionUp(MotionEvent motionEvent) {
    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;//from   w  w  w .  j  a v  a  2 s .co  m
        dismissRight = deltaX > 0;
    } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
            && absVelocityY < absVelocityX && mSwiping) {
        // dismiss only if flinging in the same direction as dragging
        dismiss = (velocityX < 0) == (deltaX < 0);
        dismissRight = mVelocityTracker.getXVelocity() > 0;
    }
    if (dismiss && mDownPosition != INVALID_POSITION) {
        // dismiss
        final View downView = mDownView; // mDownView gets null'd before animation ends
        final int downPosition = mDownPosition;
        ++mDismissAnimationRefCount;
        animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                .setDuration(mAnimationTime)
                .setListener(new com.nineoldandroids.animation.AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) {
                        super.onAnimationEnd(animation);
                        performDismiss(downView, downPosition);
                    }
                });
    } else {
        // cancel
        animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
    }
    mVelocityTracker.recycle();
    mVelocityTracker = null;
    mDownX = 0;
    mDownY = 0;
    mDownView = null;
    mDownPosition = INVALID_POSITION;
    mSwiping = false;
}

From source file:com.example.tt.pullrefresh.widget.SwipItemLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN://???
        getParent().requestDisallowInterceptTouchEvent(true);
        startX = (int) ev.getRawX();
        startY = (int) ev.getRawY();
        break;//from w  ww . j  ava  2s.c om
    case MotionEvent.ACTION_MOVE://
        int endX = (int) ev.getRawX();
        int endY = (int) ev.getRawY();
        //?
        //3.?ListView??
        if (Math.abs(endX - startX) < (Math.abs(endY - startY))) {
            getParent().requestDisallowInterceptTouchEvent(false);
        }
        break;
    }
    sheetDragHelper.processTouchEvent(ev);
    return sheetDragHelper.getCapturedView() != null || super.onTouchEvent(ev);
}

From source file:com.google.cloud.solutions.griddler.android.ui.game.GameActivity.java

/**
 * Occurs when the game surface has been touched
 *///ww  w .ja  v a  2s  .  co  m
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (this.gameState == GameStateType.PLAYING) {
        float x = event.getRawX();
        float y = event.getRawY();
        switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE:
            for (IGameView gameView : this.views) {
                gameView.onTouchMove((int) x, (int) y);
            }
            break;
        case MotionEvent.ACTION_UP:
            simulate();
            break;
        }
    }
    return false;
}