Example usage for android.view MotionEvent getY

List of usage examples for android.view MotionEvent getY

Introduction

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

Prototype

public final float getY() 

Source Link

Document

#getY(int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:com.android.documentsui.DocumentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);//w  w w.  ja  va2 s .c o  m

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        getWindow().getDecorView().setBackground(after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
    } else {
        buildDefaultState();
    }

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = getIntent().getType();
        final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_GET_CONTENT) {
        final Intent moreApps = new Intent(getIntent());
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), moreApps);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) {
        RootsFragment.show(getFragmentManager(), null);
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = getIntent().getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (getParent() != null) {
        getParent().requestDisallowInterceptTouchEvent(true);
    }/*from  w  w w .  j  av a  2s .  c  o m*/

    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (mScroller.computeScrollOffset()) {
            mScroller.abortAnimation();
            invalidate();
        }
        stopLongClick();
        triggleLongClick(event.getX(), event.getY());
        touchBegan(event);
        return true;
    case MotionEvent.ACTION_MOVE:
        touchMoved(event);
        return true;
    case MotionEvent.ACTION_UP:
        touchEnded(event);
        stopLongClick();
        return true;
    }

    return false;
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    virtualIntent.addCategory(Intent.CATEGORY_OPENABLE);
    virtualIntent.setType("*/*");
    virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);//  ww  w .jav  a2  s . com

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        getWindow().getDecorView().setBackground(after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
    } else {
        if (DEBUG) {
            Log.i(TAG, "mState");
        }
        buildDefaultState();
    }

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = virtualIntent.getType();
        final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_GET_CONTENT) {
        final Intent moreApps = new Intent(virtualIntent);
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), moreApps);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) {
        RootsFragment.show(getFragmentManager(), null);
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = virtualIntent.getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }
}

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

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        return false;
    }//from w w w  . ja v  a2  s.  c  o m
    int action = MotionEventCompat.getActionMasked(event);
    if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) {
        return true;
    }
    mViewDragHelper.processTouchEvent(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
    // to capture the bottom sheet in case it is not captured and the touch slop is passed.
    if (action == MotionEvent.ACTION_MOVE) {
        if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) {
            mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
        }
    }
    return true;
}

From source file:com.carlosyzy.newsclient.View.HorizontalListView.java

/** Registers the gesture detector to receive gesture notifications for this view */
private void bindGestureDetector() {
    // Generic touch listener that can be applied to any view that needs to process gestures
    final OnTouchListener gestureListenerHandler = new OnTouchListener() {
        private double xDistance = 0;
        private double yDistance = 0;

        @Override/*from  w  ww  . j av a  2s.  c  om*/
        public boolean onTouch(final View v, final MotionEvent ev) {
            switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                xDistance = ev.getX();
                yDistance = ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                double moveX = ev.getX() - xDistance;
                double moveY = ev.getY() - yDistance;
                if ((20 * Math.abs(moveX) > Math.abs(ev.getY() - moveY))) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                } else {
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                }
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
            return mGestureDetector.onTouchEvent(ev);
        }
    };

    setOnTouchListener(gestureListenerHandler);
}

From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    if (!mCanSlide) {
        return super.onTouchEvent(ev);
    }//w w w.  j a  v a2  s  .c  o m

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (isDimmed(mSlideableView)) {
            final float x = ev.getX();
            final float y = ev.getY();
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mDragHelper.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) {
                // Taps close a dimmed open pane.
                closePane();
                break;
            }
        }
        break;
    }
    }

    return true;
}

From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

    if (!isEnabled() || canChildScrollUp()) {
        return false;
    }/*from w  w w. j  a  va  2s  . c  o m*/
    mIsBeingDropped = mWaveView.isDisappearCircleAnimatorRunning();

    final int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Here is not called from anywhere
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId);
        return pointerIndex >= 0 && onMoveTouchEvent(event, pointerIndex);

    case MotionEvent.ACTION_UP:
        if (mIsBeingDropped) {
            mIsBeingDropped = false;
            return false;
        }

        final float diffY = event.getY() - mFirstTouchDownPointY;
        final float waveHeightThreshold = diffY
                * (5f - 2 * diffY / Math.min(getMeasuredWidth(), getMeasuredHeight())) / 1000f;
        mWaveView.startWaveAnimation(waveHeightThreshold);

    case MotionEvent.ACTION_CANCEL:
        if (mActivePointerId == INVALID_POINTER) {
            return false;
        }

        if (!isRefreshing()) {
            mCircleView.setProgressStartEndTrim(0f, 0f);
            mCircleView.showArrow(false);
            mCircleView.setVisibility(GONE);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    return true;
}

From source file:org.openremote.android.console.GroupActivity.java

/**
 * Detect the gesture and handle it.//from   w w  w  . j a va2 s  .co  m
 * Support fling type: "right to left", "left to right", "bottom to top" and "top to bottom".
 * 
 * @see android.view.GestureDetector.OnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)
 */
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    // The panel or group is empty.
    if (currentGroupView == null) {
        return false;
    }
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        Log.i("OpenRemote-FLING", "right to left");
        onScreenGestureEvent(Gesture.GESTURE_SWIPE_TYPE_RIGHT2LEFT);
        return moveRight();
    } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        Log.i("OpenRemote-FLING", "left to right");
        onScreenGestureEvent(Gesture.GESTURE_SWIPE_TYPE_LEFT2RIGHT);
        return moveLeft();
    } else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
        Log.i("OpenRemote-FLING", "bottom to top");
        onScreenGestureEvent(Gesture.GESTURE_SWIPE_TYPE_BOTTOM2TOP);
        return true;
    } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
        Log.i("OpenRemote-FLING", "top to bottom");
        onScreenGestureEvent(Gesture.GESTURE_SWIPE_TYPE_TOP2BOTTOM);
        return true;
    }
    return false;
}

From source file:com.bright.cloudutils.view.ResideLayout.java

@SuppressLint("ClickableViewAccessibility")
@Override/*w  ww . j  ava  2 s .c  om*/
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    if (!mCanSlide) {
        return super.onTouchEvent(ev);
    }

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (isDimmed(mSlideableView)) {
            final float x = ev.getX();
            final float y = ev.getY();
            final float dx = x - mInitialMotionX;
            final float dy = y - mInitialMotionY;
            final int slop = mDragHelper.getTouchSlop();
            if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) {
                // Taps close a dimmed open pane.
                closePane();
                break;
            }
        }
        break;
    }
    }

    return true;
}

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

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        return false;
    }/*from   w w  w .ja  va 2 s.c  o m*/
    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();
}