Example usage for android.view MotionEvent getX

List of usage examples for android.view MotionEvent getX

Introduction

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

Prototype

public final float getX() 

Source Link

Document

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

Usage

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

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (getParent() != null) {
        getParent().requestDisallowInterceptTouchEvent(true);
    }// w  w  w . ja v  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);//  w w  w.java  2  s .  c  om

    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:com.aigo.kt03airdemo.ui.view.ResideLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    if (!mCanSlide) {
        return super.onTouchEvent(ev);
    }//from  w  w  w.j  av  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: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. j a va 2  s  .  c om
    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:com.android.nobug.view.pattern.PatternView.java

private void handleActionDown(MotionEvent event) {
    resetPattern();/*  www .j  a v a  2  s.c om*/
    final float x = event.getX();
    final float y = event.getY();
    final Cell hitCell = detectAndAddHit(x, y);
    if (hitCell != null) {
        setPatternInProgress(true);
        mPatternDisplayMode = DisplayMode.Correct;
        notifyPatternStarted();
    } else if (mPatternInProgress) {
        setPatternInProgress(false);
        notifyPatternCleared();
    }
    if (hitCell != null) {
        final float startX = getCenterXForColumn(hitCell.column);
        final float startY = getCenterYForRow(hitCell.row);

        final float widthOffset = mSquareWidth / 2f;
        final float heightOffset = mSquareHeight / 2f;

        invalidate((int) (startX - widthOffset), (int) (startY - heightOffset), (int) (startX + widthOffset),
                (int) (startY + heightOffset));
    }
    mInProgressX = x;
    mInProgressY = y;
    if (PROFILE_DRAWING) {
        if (!mDrawingProfilingStarted) {
            Debug.startMethodTracing("LockPatternDrawing");
            mDrawingProfilingStarted = true;
        }
    }
}

From source file:com.justone.android.main.MainActivity.java

/** 
*  // w w  w . ja va2s .  co m
*/
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

    /*System.out.println(this.tabs.getCurrentView().getLayoutDirection());
    System.out.println(R.layout.home_item);
    System.out.println(this.tabs.getCurrentView().getId());
    System.out.println(R.id.homeScrollView);
    System.out.println(this.tabs.getCurrentTab());
    System.out.println(this.homeListView.getId());
    int currentViewId = this.tabs.getCurrentView().getId();
    */
    if (e1.getX() - e2.getX() < -200) {

        if (currentId == maxId || currentId == 0) {
            viewHandler.sendMessage(Message.obtain(viewHandler, 2));
        } else {
            this.leftOrRight = 2;
            this.isUpdate = true;
        }

    } else if (e1.getX() - e2.getX() > 200) {

        if (currentId == 1)
            viewHandler.sendMessage(Message.obtain(viewHandler, 3));
        else {
            this.leftOrRight = 1;
            this.isUpdate = true;
        }

    }
    return true;
}

From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mCanSlide || !mIsSlidingEnabled) {
        return super.onTouchEvent(ev);
    }//from ww  w  .  j  a  v a2 s  . co  m

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();
    boolean wantTouchEvents = true;

    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: {
        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();
        View dragView = mDragView != null ? mDragView : mSlideableView;
        if (dx * dx + dy * dy < slop * slop && isDragViewUnder((int) x, (int) y)) {
            dragView.playSoundEffect(SoundEffectConstants.CLICK);
            if (!isExpanded() && !isAnchored()) {
                expandPane(mAnchorPoint);
            } else {
                collapsePane();
            }
            break;
        }
        break;
    }
    }

    return wantTouchEvents;
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

/**
 * Manage cursor for measurement// ww  w .j av  a 2s.c o  m
 */
private void measureEvent(MotionEvent event) {
    switch (event.getPointerCount()) {
    case 1:
        graphView.setCursor(event.getX(), event.getY());
        // TODO: if touch point is very close to boundary for a long time, move the view
        break;
    case 2:
        if (isInGraphView(event.getX(1), event.getY(1))) {
            switchMeasureAndScaleMode();
        }
    }
}

From source file:com.cssweb.android.view.TrendView.java

public void touchesEnded(MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();
    //if (x < LSpace || x > (width - LSpace))
    if (x < LSpace || x > width)
        return;/*from  w  w  w.  j a v  a 2s.  c  o m*/
    if (y < this.topTitleHeight || y > height - this.axisLabelHeight)
        return;
    isTouched = false;
    if (isTouchMoved == false) {
        isTouchMoved = false;
        isTrackStatus = !isTrackStatus;
        if (isTrackStatus) {//??
            //if (x > LSpace && x < (width - LSpace))
            if (x > LSpace && x < width)
                trackLineV = x;
            if (y > axisLabelHeight && y < (height - axisLabelHeight))
                trackLineH = y;

            int idx = (int) ((x - LSpace) / SPACE);
            if (idx < actualDataLen && idx >= 0) {
                isTrackNumber = idx;
                trackLineV = (int) (LSpace + idx * SPACE);
            } else {
                if (idx < 0) {
                    isTrackNumber = 0;
                    trackLineV = LSpace;
                }
                if (idx >= actualDataLen) {
                    isTrackNumber = actualDataLen - 1;
                    trackLineV = (int) (LSpace + (actualDataLen - 1) * SPACE);
                }
            }
        }
    }
    this.invalidate();
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    int action = event.getAction();
    action = action & MotionEvent.ACTION_MASK;

    mGestureDetector.onTouchEvent(event);
    boolean scaleInProgress = scaleInProgress();
    mScaleGestureDetector.onTouchEvent(event);
    if (mInteractionMode == InteractionMode.SCALE) {
        return true;
    }/*from   w  w w  .  j  a v  a2s  . c  o m*/
    if (!scaleInProgress() && scaleInProgress) {
        // If we were scaling, the scale will stop but we will
        // still issue an ACTION_UP. Let the subclasses know.
        mFinishedScalingOperation = true;
    }

    int ex = (int) event.getX();
    int ey = (int) event.getY();
    if (action == MotionEvent.ACTION_DOWN) {
        mInteractionMode = InteractionMode.MOVE;
        mTouchDown.x = ex;
        mTouchDown.y = ey;
        mTouchShowOriginalDate = System.currentTimeMillis();
        mShowOriginalDirection = 0;
        MasterImage.getImage().setOriginalTranslation(MasterImage.getImage().getTranslation());
    }

    if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) {
        mTouch.x = ex;
        mTouch.y = ey;

        float scaleFactor = MasterImage.getImage().getScaleFactor();
        if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) {
            float translateX = (mTouch.x - mTouchDown.x) / scaleFactor;
            float translateY = (mTouch.y - mTouchDown.y) / scaleFactor;
            Point originalTranslation = MasterImage.getImage().getOriginalTranslation();
            Point translation = MasterImage.getImage().getTranslation();
            translation.x = (int) (originalTranslation.x + translateX);
            translation.y = (int) (originalTranslation.y + translateY);
            MasterImage.getImage().setTranslation(translation);
            mTouchShowOriginal = false;
        } else if (enableComparison() && !mOriginalDisabled
                && (System.currentTimeMillis() - mTouchShowOriginalDate > mTouchShowOriginalDelayMin)
                && event.getPointerCount() == 1) {
            mTouchShowOriginal = true;
        }
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mInteractionMode = InteractionMode.NONE;
        mTouchShowOriginal = false;
        mTouchDown.x = 0;
        mTouchDown.y = 0;
        mTouch.x = 0;
        mTouch.y = 0;
        if (MasterImage.getImage().getScaleFactor() <= 1) {
            MasterImage.getImage().setScaleFactor(1);
            MasterImage.getImage().resetTranslation();
        }
    }

    float scaleFactor = MasterImage.getImage().getScaleFactor();
    Point translation = MasterImage.getImage().getTranslation();
    constrainTranslation(translation, scaleFactor);
    MasterImage.getImage().setTranslation(translation);

    invalidate();
    return true;
}