Example usage for android.support.v4.view MotionEventCompat getY

List of usage examples for android.support.v4.view MotionEventCompat getY

Introduction

In this page you can find the example usage for android.support.v4.view MotionEventCompat getY.

Prototype

public static float getY(MotionEvent event, int pointerIndex) 

Source Link

Document

Call MotionEvent#getY(int) .

Usage

From source file:danonino.danonino_the_game.Core.Labels.PowerUp.java

public int onTouch(MotionEvent event) {
    int index = MotionEventCompat.getActionIndex(event);
    int x;//  w  w w  .j av a2  s . com
    int y;

    if (event.getPointerCount() > 1) {
        // The coordinates of the current screen contact, relative to
        // the responding View or Activity.
        x = (int) MotionEventCompat.getX(event, index);
        y = (int) MotionEventCompat.getY(event, index);

    } else {
        // Single touch event
        x = (int) MotionEventCompat.getX(event, index);
        y = (int) MotionEventCompat.getY(event, index);
    }

    if (this.usePowerUpBtn.btn_rect.contains(x, y) || ((event.getActionMasked() == MotionEvent.ACTION_UP
            || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) && usePowerUpBtnPressed)) {
        this.usePowerUpBtnPressed = !this.usePowerUpBtnPressed;
        this.usePowerUpBtn.onTouch(event);
        return 1;
    }
    return 0;
}

From source file:com.duy.pascal.ui.view.BaseRecycleView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    final int action = MotionEventCompat.getActionMasked(e);
    final int actionIndex = MotionEventCompat.getActionIndex(e);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
        mInitialTouchX = (int) (e.getX() + 0.5f);
        mInitialTouchY = (int) (e.getY() + 0.5f);
        return super.onInterceptTouchEvent(e);

    case MotionEventCompat.ACTION_POINTER_DOWN:
        mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex);
        mInitialTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
        mInitialTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
        return super.onInterceptTouchEvent(e);

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId);
        if (index < 0) {
            return false;
        }//from   w ww.j  a va2s .  co m

        final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f);
        final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
        if (getScrollState() != SCROLL_STATE_DRAGGING) {
            final int dx = x - mInitialTouchX;
            final int dy = y - mInitialTouchY;
            final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally();
            final boolean canScrollVertically = getLayoutManager().canScrollVertically();
            boolean startScroll = false;
            if (canScrollHorizontally && Math.abs(dx) > mTouchSlop
                    && (Math.abs(dx) >= Math.abs(dy) || canScrollVertically)) {
                startScroll = true;
            }
            if (canScrollVertically && Math.abs(dy) > mTouchSlop
                    && (Math.abs(dy) >= Math.abs(dx) || canScrollHorizontally)) {
                startScroll = true;
            }
            return startScroll && super.onInterceptTouchEvent(e);
        }
        return super.onInterceptTouchEvent(e);
    }

    default:
        return super.onInterceptTouchEvent(e);
    }
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private float getActiveY(MotionEvent ev) {
    try {//from w w  w . j a va2s .c  o  m
        return MotionEventCompat.getY(ev, mActivePointerIndex);
    } catch (Exception e) {
        return ev.getY();
    }
}

From source file:com.greenkee.pokeADot.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // tell system to use the layout defined in our XML file
    setContentView(com.greenkee.pokeADot.R.layout.activity_game_screen);

    mView = (GameView) findViewById(com.greenkee.pokeADot.R.id.gameScreen);
    mThread = mView.getThread();/*from   www .jav  a2 s.c om*/
    mView.setActivity(this);
    ((GameView) mView).setTextViews((TextView) findViewById(com.greenkee.pokeADot.R.id.status_display),
            (TextView) findViewById(com.greenkee.pokeADot.R.id.score_display),
            (TextView) findViewById(com.greenkee.pokeADot.R.id.combo_display));

    if (savedInstanceState == null) {
        System.out.println("STATE SET");
        mThread.doStart();
    } else {
        super.onRestoreInstanceState(savedInstanceState);
        mThread.restoreState(savedInstanceState);

    }
    mView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = MotionEventCompat.getActionMasked(event);
            final int pointerIndex;
            final float x;
            final float y;
            switch (action) {
            case (MotionEvent.ACTION_DOWN): {
                //  System.out.println("ACTION_DOWN");
                if (((GameView.GameThread) mThread).getCurrentState() == GameView.GameThread.STATE_RUNNING) {
                    int index = MotionEventCompat.getActionIndex(event);
                    p1ID = MotionEventCompat.getPointerId(event, index);
                    if (p1ID != -1) {
                        int p1Index = MotionEventCompat.findPointerIndex(event, p1ID);
                        ((GameView.GameThread) mThread).checkTouch(MotionEventCompat.getX(event, p1Index),
                                MotionEventCompat.getY(event, p1Index));
                        //DO SOMETHING HERE

                    }
                } else if (!(mView.dialogOpen) && (!(((GameView.GameThread) mThread).gameOver))
                        && (((GameView.GameThread) mThread)
                                .getCurrentState() == GameView.GameThread.STATE_READY)
                        || (((GameView.GameThread) mThread)
                                .getCurrentState() == GameView.GameThread.STATE_LOSE)) {
                    ((GameView.GameThread) mThread).startGame();

                    // System.out.println("START GAME");

                } else if (((GameView.GameThread) mThread)
                        .getCurrentState() == GameView.GameThread.STATE_PAUSE) {
                    mThread.unpause();
                }

                return true;
            }
            case (MotionEvent.ACTION_MOVE): {
                //  System.out.println("ACTION_MOVE");
                if (((GameView.GameThread) mThread).getCurrentState() == GameView.GameThread.STATE_RUNNING) {
                    if (p1ID != -1) {
                        int p1Index = MotionEventCompat.findPointerIndex(event, p1ID);
                        //DO SOMETHING HERE

                    }
                }

                return true;
            }
            case (MotionEvent.ACTION_UP): {
                // System.out.println("ACTION_UP");

                reset();
                return true;
            }
            case (MotionEvent.ACTION_CANCEL): {
                // System.out.println("ACTION_CANCEL");
                reset();
                return true;
            }
            case (MotionEvent.ACTION_OUTSIDE): {
                return true;

            }
            }

            return false;
        }

        private void reset() {
            numTouches = 0;
            p1ID = -1;
            p2ID = -1;
        }
    }

    );
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private void onTouchActivePointer(int action, MotionEvent ev) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = ev.getPointerId(0);
        break;// w w w. ja v a 2 s  .co m
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mActivePointerId = INVALID_POINTER_ID;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
            mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
        }

        break;
    }

    mActivePointerIndex = MotionEventCompat.findPointerIndex(ev,
            mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}

From source file:de.gobro.andreas.pa.pa_cleint_java.SendTouch.java

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

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.d("down", "action_down");
        break;/* ww  w.j  ava  2  s .co  m*/
    }
    case MotionEvent.ACTION_MOVE: {
        for (Integer i = 0; (i < ev.getPointerCount()) && (i < maxPoints); i++) {
            //final Integer pointerIndex = MotionEventCompat.getActionIndex(ev);

            Integer id = ev.getPointerId(i);
            Log.d("ind", "pinterindex" + i.toString());
            Log.d("ind", "ID" + id.toString());
            Log.d("pos", "(" + String.valueOf(MotionEventCompat.getX(ev, i)) + ";"
                    + String.valueOf(MotionEventCompat.getY(ev, i)) + ")");
            Log.d("test", "action_move");

            try {
                serializer.startTag("", "touch");
                serializer.startTag("", "dx");
                serializer.text(String.valueOf(MotionEventCompat.getX(ev, i) / size.x));
                serializer.endTag("", "dx");
                serializer.startTag("", "dy");
                serializer.text(String.valueOf(MotionEventCompat.getY(ev, i) / size.y));
                serializer.endTag("", "dy");
                serializer.startTag("", "id");
                serializer.text(id.toString());
                serializer.endTag("", "id");
                serializer.endTag("", "touch");

            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            //             try {
            //               writer.writeStartElement("touch");
            //                  writer.writeStartElement("dx");
            //                     writer.writeCharacters(String.valueOf(MotionEventCompat.getX(ev, i)/size.x));
            //                  writer.writeEndElement();
            //                  writer.writeStartElement("dy");
            //                     writer.writeCharacters(String.valueOf(MotionEventCompat.getY(ev, i)/size.y));
            //                  writer.writeEndElement();
            //                  writer.writeStartElement("id");
            //                     writer.writeCharacters(id.toString());
            //                  writer.writeEndElement();                  
            //               writer.writeEndElement();
            //            } catch (XMLStreamException e) {
            //               // TODO Auto-generated catch block
            //               e.printStackTrace();
            //            }

        }

        //write the stuff to the network
        try {
            serializer.flush();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            finish();

        }
        break;
    }
    case MotionEvent.ACTION_UP: {
        Log.d("test", "action_up");
        break;
    }
    case MotionEvent.ACTION_CANCEL: {
        Log.d("test", "action_cancel");
        break;
    }
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.d("down", "action_p_down");
        break;
    }
    case MotionEvent.ACTION_POINTER_UP: {
        Log.d("test", "action_p_up");
        break;
    }
    }
    return true;
}

From source file:com.kuloud.android.unity.ui.widget.steprefresh.PullToRefreshView.java

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

    //        if (!mIsBeingDragged) {
    //            return super.onTouchEvent(ev);
    //        }//from  w w  w .  ja va 2s.c om

    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            return false;
        }

        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = y - mInitialMotionY;
        final float scrollTop = yDiff * DRAG_RATE;
        mCurrentDragPercent = scrollTop / mTotalDragDistance;
        if (mCurrentDragPercent < 0) {
            return false;
        }
        float boundedDragPercent = Math.min(1f, Math.abs(mCurrentDragPercent));
        float extraOS = Math.abs(scrollTop) - mTotalDragDistance;
        float slingshotDist = mTotalDragDistance;
        float tensionSlingshotPercent = Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
        float tensionPercent = (float) ((tensionSlingshotPercent / 4)
                - Math.pow((tensionSlingshotPercent / 4), 2)) * 2f;
        float extraMove = (slingshotDist) * tensionPercent / 2;
        int targetY = (int) ((slingshotDist * boundedDragPercent) + extraMove);

        mBaseRefreshView.setPercent(mCurrentDragPercent, true);
        setTargetOffsetTop(targetY - mCurrentOffsetTop);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN:
        final int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        if (mActivePointerId == INVALID_POINTER) {
            return false;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float overScrollTop = (y - mInitialMotionY) * DRAG_RATE;
        mIsBeingDragged = false;
        if (overScrollTop > mTotalDragDistance) {
            setRefreshing(true, true);
        } else {
            mRefreshing = false;
            animateOffsetToPosition(mAnimateToStartPosition, false);
        }
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    }

    return true;
}

From source file:cc.solart.turbo.TurboRecyclerView.java

private int getMotionEventY(MotionEvent e, int pointerIndex) {
    return (int) (MotionEventCompat.getY(e, pointerIndex) + 0.5f);
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.MeasurementsView.java

private boolean hitTest(MotionEvent event) {
    final int pointerIndex = MotionEventCompat.getActionIndex(event);
    final float x = MotionEventCompat.getX(event, pointerIndex);
    final float y = MotionEventCompat.getY(event, pointerIndex);

    boolean selected = false;
    if (x >= mTopLeft.x && x <= mTopLeft.x + BOX_WIDTH && y >= mTopLeft.y && y <= mTopLeft.y + BOX_HEIGHT) {
        selected = true;//from   ww w.  j  av a2s.c om
    }

    return selected;
}

From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_anm);
    orgnlImageView = (ImageView) findViewById(R.id.imageView);
    orgnlImageView.setMaxHeight(800);/*from w  ww .j  av  a  2s.  c  om*/
    orgnlImageView.setMaxWidth(600);
    crt_ctx = this;

    BitmapFactory.Options bmp_opt = new BitmapFactory.Options();
    bmp_opt.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;

    // - Now we need to set the GUI ImageView data with data read from the picked file.
    DcodRszdBmpFil dcodRszdBmpFil = new DcodRszdBmpFil();
    Bitmap bmp = dcodRszdBmpFil.DcodRszdBmpFil(SelectImageActivity.orgFil, bmp_opt);

    // Now we need to set the GUI ImageView data with the orginal file selection.
    orgnlImageView.setImageBitmap(bmp);
    orgnl_iv_wdth = bmp.getWidth();
    orgnl_iv_hght = bmp.getHeight();
    final RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo);
    scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener());

    orgnlImageView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getPointerCount() > 1 || flgInScale) {

                scaleGestureDetector.onTouchEvent(event);
                return true;
            }

            int end_hrz;
            int end_vrt;
            final int pointerIndex;

            switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                bgn_hrz = (int) MotionEventCompat.getX(event, pointerIndex);
                bgn_vrt = (int) MotionEventCompat.getY(event, pointerIndex);

                String log_str = "Beginning coordinates: Horz = " + String.valueOf(bgn_hrz) + "; Vert = "
                        + String.valueOf(bgn_vrt);

                Log.d("OnTouchListener", log_str);
                orlp = (RelativeLayout.LayoutParams) orgnlImageView.getLayoutParams();
                bgn_top = (int) orlp.topMargin;
                bgn_lft = (int) orlp.leftMargin;

                // To prevent an initial jump of the magnifier, aposX and aPosY must
                // have the values from the magnifier frame
                if (aPosX == 0)
                    aPosX = orgnlImageView.getX();
                if (aPosY == 0)
                    aPosY = orgnlImageView.getY();
                break;

            case MotionEvent.ACTION_MOVE:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                float crt_hrz = MotionEventCompat.getX(event, pointerIndex);
                float crt_vrt = MotionEventCompat.getY(event, pointerIndex);
                final float dx = crt_hrz - bgn_hrz;
                final float dy = crt_vrt - bgn_vrt;
                aPosX += dx;
                aPosY += dy;
                orgnlImageView.setX(aPosX);
                orgnlImageView.setY(aPosY);

                log_str = "Current Position: Horz = " + String.valueOf(crt_hrz) + "; Vert = "
                        + String.valueOf(crt_vrt);

                Log.d("OnTouchListener", log_str);

                break;

            case MotionEvent.ACTION_UP:

                pointerIndex = MotionEventCompat.getActionIndex(event);
                end_hrz = (int) MotionEventCompat.getX(event, pointerIndex);
                end_vrt = (int) MotionEventCompat.getY(event, pointerIndex);
            }

            rel_anm_lo.invalidate();
            return true;
        }
    });

    sav_anm_btn = (Button) findViewById(R.id.sav_btn);

    sav_anm_btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View vw) {

            onClickFlg = 1;
            RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo);
            rel_anm_lo.removeView(vw);
            Bitmap tnBmp = getWrtBmp("thumbnail", rel_anm_lo, 40);
            tnBmp.recycle();
            int vw_nmbr = anmViews.size();

            for (int vw_mbr = 1; vw_mbr < vw_nmbr; vw_mbr += 1) {

                anim_view = anmViews.get(vw_mbr);

                if (anim_view != null) {

                    Animation crt_anm = anim_view.getAnimation();

                    if (crt_anm != null)
                        crt_anm.cancel();

                    anim_view.setAnimation(null);
                    rel_anm_lo.removeView(anim_view);

                    // Garbage collect the bitmap
                    Drawable drawable = anim_view.getDrawable();

                    if (drawable instanceof BitmapDrawable) {
                        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
                        Bitmap anim_bmp = bitmapDrawable.getBitmap();
                        anim_bmp.recycle();
                    }
                }
            }

            Bitmap orgnlImageBmp = getWrtBmp("bgimg", rel_anm_lo, 90);
            orgnlImageWdth = Integer.toString(orgnlImageBmp.getWidth());
            orgnlImageHght = Integer.toString(orgnlImageBmp.getHeight());
            anmViews.clear();
            unbindDrawables(rel_anm_lo);
            ((RelativeLayout) rel_anm_lo).removeAllViews();
            orgnlImageBmp.recycle();
            crt_ctx = null;
            orgnlImageView = null;

            Intent intent = new Intent(AnimActivity.this, com.acceleratedio.pac_n_zoom.SaveAnmActivity.class);

            startActivity(intent);
        }
    });

    progress = ProgressDialog.show(crt_ctx, "Loading the animation", "dialog message", true);
    GetRequest get_svg_img = new GetRequest();
    get_svg_img.execute("");
}