Example usage for android.view MotionEvent ACTION_MOVE

List of usage examples for android.view MotionEvent ACTION_MOVE

Introduction

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

Prototype

int ACTION_MOVE

To view the source code for android.view MotionEvent ACTION_MOVE.

Click Source Link

Document

Constant for #getActionMasked : A change has happened during a press gesture (between #ACTION_DOWN and #ACTION_UP ).

Usage

From source file:com.example.aaron.test.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent e) {

    float x = e.getX();
    float y = e.getY();

    int cc = 0;/*  w  w w  .ja  v  a 2s  .c  o m*/

    /*
            float xGL=(width1/2-x)/(float)(height1/1.85);
            float yGL=( height1/2+30-y)/(float)(height1/1.85);
    */

    float xGL = (width1 / 2 - x) / (float) (height1 / 2);
    float yGL = (height1 / 2 - y) / (float) (height1 / 2);

    workspace = -(width1 - 115) / (height1 * 2) + .15f - mRenderer.slider;

    mRenderer.tempFun(xGL, yGL);

    switch (e.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        mRenderer.tToggle = 1;

        for (int i = 0; i < maxBots; i++) {
            if (tList[i].getOn() == 1) {
                cc = cc + 1;
                if (Math.abs(tList[i].getX() * getScale() + mRenderer.dragX * mRenderer.scale - xGL) < .1f
                        && Math.abs(
                                tList[i].getY() * getScale() + mRenderer.dragY * mRenderer.scale - yGL) < .1f) {
                    if (state[i] == 0) {
                        state[i] = 1;
                    } else {
                        state[i] = 0;
                    }
                    v.vibrate(50);
                }
            }
        }

        if (antispam > 1) {

            if (xGL < .85 && xGL > .65 && yGL > -.95 && yGL < -.75) {
                mRenderer.scale = mRenderer.scale + .5f;
                mRenderer.textList.get(1).setText("Scale: " + truncateDecimal(mRenderer.scale, 1) + "x");
                mRenderer.textList.get(2).setText(truncateDecimal(2 / mRenderer.scale, 2) + " ft");
                v.vibrate(75);
                break;
            }
            if (xGL < 1.2f && xGL > .95f && yGL > -.85f && yGL < -.75 && mRenderer.scale > .5f) {
                mRenderer.scale = mRenderer.scale - .5f;
                mRenderer.textList.get(1).setText("Scale: " + truncateDecimal(mRenderer.scale, 1) + "x");
                mRenderer.textList.get(2).setText(truncateDecimal(2 / mRenderer.scale, 2) + " ft");
                v.vibrate(75);
                break;
            }

            if (mRenderer.commit.blocked == false && xGL < mRenderer.commit.left - mRenderer.slider
                    && xGL > mRenderer.commit.right - mRenderer.slider && yGL > mRenderer.commit.down
                    && yGL < mRenderer.commit.up)
                if (mRenderer.commit.active == true) {
                    mRenderer.commit.active = false;
                    newAction = true;
                    v.vibrate(50);
                } else {
                    mRenderer.commit.active = true;
                    if (mRenderer.customFormation.active) {
                        mRenderer.justifyRelativePositions();
                        mRenderer.resetScaleAndRotation();
                        mRenderer.formation.send = true;
                    }
                    newAction = true;
                    v.vibrate(50);
                }

            //Turn on voronoi toggle
            if (buttonPush(xGL, yGL, mRenderer.vorToggle))
                if (mRenderer.getvToggle() == 1) {
                    mRenderer.setvToggle(0);
                    v.vibrate(500);
                } else {
                    mRenderer.setvToggle(1);
                    v.vibrate(500);
                }
            vFlag = mRenderer.getvToggle();

            //Turn on Free Draw Toggle
            if (buttonPush(xGL, yGL, mRenderer.freeDrawToggle))
                if (mRenderer.getfToggle() == 1) {
                    mRenderer.setfToggle(0);
                    fFlag = mRenderer.getfToggle();
                } else {
                    mRenderer.setfToggle(1);
                    mRenderer.eraseFreeLine();
                    freeDrawCount = 0;
                    previousy = 0;
                    previousx = 0;
                    connectable = 0;
                    firstPointFreeDraw[0] = -1000;
                    firstPointFreeDraw[1] = -1000;
                    fFlag = mRenderer.getfToggle();
                }

            //Toggable swarm for Path Follower
            /*if (mRenderer.getfToggle()==1 && xGL<mRenderer.swarmToggle.left- mRenderer.slider&& xGL>mRenderer.swarmToggle.right-mRenderer.slider&& yGL > mRenderer.swarmToggle.down && yGL < mRenderer.swarmToggle.up)
                if (mRenderer.swarmToggle.active == true) {
                    mRenderer.swarmToggle.active =  false;
                    v.vibrate(50);
                } else {
                    mRenderer.swarmToggle.active =  true;
                    v.vibrate(50);
                }
            */ //THIS FEATURE CAN BE ADDED LATER IF WE WANT

            //Turn on Way Point Toggle
            if (buttonPush(xGL, yGL, mRenderer.wayPointToggle))
                if (mRenderer.getpToggle() == 1) {
                    mRenderer.setpToggle(0);
                    pFlag2 = 0;
                    mRenderer.setpToggle2(pFlag2);
                    mRenderer.tToggle = 1;
                    pX = 0;
                    pY = 0;
                } else {
                    mRenderer.tToggle = 0;
                    mRenderer.setpToggle(1);
                    mRenderer.voronoiDeploymentToggle.active = false;
                    pX = 0;
                    pY = 0;
                }
            pFlag = mRenderer.getpToggle();

            //Turn on AndroneToggle
            if (buttonPush(xGL, yGL, mRenderer.ardronePrefToggle))
                if (mRenderer.getAPToggle() == 1) {
                    mRenderer.setAPToggle(0);
                    mRenderer.SINFO_FLAG = true;
                } else {
                    mRenderer.setAPToggle(1);
                    mRenderer.SINFO_FLAG = false;
                }

            if (buttonPush(xGL, yGL, mRenderer.gaussianTrackToggle)) {
                if (mRenderer.gaussianTrackToggle.active == true) {
                    mRenderer.gaussianTrackToggle.active = false;

                } else {
                    mRenderer.gaussianTrackToggle.active = true;

                }
                v.vibrate(50);
            }

            if (buttonPush(xGL, yGL, mRenderer.formation)) {
                if (mRenderer.formation.active == true) {
                    mRenderer.formation.active = false;
                    mRenderer.formation.send = false;
                } else {
                    mRenderer.formation.active = true;
                    mRenderer.formation.send = true;
                    mRenderer.refreshFormationtext();
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.formationToggleTransform)) {
                if (mRenderer.formationToggleTransform.active == true) {
                    mRenderer.formationToggleTransform.active = false;
                } else {
                    mRenderer.formationToggleTransform.active = true;
                    mRenderer.customFormation.active = false;
                    mRenderer.commit.blocked = true;
                    mRenderer.refreshFormationtext();
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.customFormation)) {
                if (mRenderer.customFormation.active == true) {
                    mRenderer.customFormation.active = false;
                    mRenderer.commit.blocked = true;
                } else {
                    mRenderer.customFormation.active = true;
                    mRenderer.resetFormation();
                    mRenderer.refreshCenter();
                    mRenderer.formationToggleTransform.active = false;
                    mRenderer.commit.blocked = false;
                    mRenderer.commit.active = false;
                    mRenderer.refreshFormationtext();
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.ardroneAddToggle)) {
                dummyFlag = 1;
            }

            if (buttonPush(xGL, yGL, mRenderer.addToggle)) {
                mRenderer.formation.val1 = mRenderer.formation.val1 + 1;
                mRenderer.refreshFormationtext();
                mRenderer.formation.send = true;
            }

            if (buttonPush(xGL, yGL, mRenderer.subtractToggle)) {
                mRenderer.formation.val1 = mRenderer.formation.val1 - 1;
                mRenderer.refreshFormationtext();
                mRenderer.formation.send = true;
            }

            if (buttonPush(xGL, yGL, mRenderer.freeBoundarytoggle)) {
                if (mRenderer.freeBoundarytoggle.active == true) {
                    mRenderer.freeBoundarytoggle.active = false;
                    freeBoundaryFlag = true;
                    closedBoundaryFlag = false;
                } else {
                    mRenderer.freeBoundarytoggle.active = true;
                    closedBoundaryFlag = true;
                    freeBoundaryFlag = false;
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.obstacleLineToggle)) {
                System.out.println("obstacle Line Pushed");

                addObstacleFlag = true;
                mRenderer.makeObstacle();
                mRenderer.fToggle = 0;
                fFlag = mRenderer.fToggle;
            }

            //IF GAUSS TOGGLE SELECTED
            if (buttonPush(xGL, yGL, mRenderer.gaussToggle))
                if (mRenderer.getgToggle() == 1) {
                    mRenderer.setgToggle(0);
                    gFlag2 = 0;
                    mRenderer.setgToggle2(gFlag2);
                } else {
                    mRenderer.setgToggle(1);
                }
            gFlag = mRenderer.getgToggle();

            //IF GAUSSPATH TOGGLE SELECTED
            /*if (xGL<mRenderer.temptoggle.left- mRenderer.slider&& xGL>mRenderer.temptoggle.right-mRenderer.slider&& yGL > mRenderer.temptoggle.down && yGL < mRenderer.temptoggle.up)
                if (mRenderer.getgpToggle() == 1) {
                    mRenderer.setgpToggle(0);
                    mRenderer.eraseGaussLine();
                    v.vibrate(50);
                } else {
                    mRenderer.setgpToggle(1);
                    mRenderer.makeGaussPoints();
                    v.vibrate(50);
                }*/
            gpFlag = mRenderer.getgpToggle();

            //Toggle for voronoi deployment
            if (buttonPush(xGL, yGL, mRenderer.voronoiDeploymentToggle))
                if (mRenderer.voronoiDeploymentToggle.active == true) {
                    mRenderer.voronoiDeploymentToggle.active = false;
                    newAction = true;
                } else {
                    newAction = true;
                    mRenderer.voronoiDeploymentToggle.active = true;
                    mRenderer.setpToggle(0);
                    mRenderer.setpToggle2(0);
                }

            if (buttonPush(xGL, yGL, mRenderer.dragToggle)) {
                addedTurtleNumber = 0;
                addedTurtleX = .1f;
                addedTurtleY = .1f;
                for (int j = 41; j < 44; j++) {
                    if (tList[j].getOn() != 1) {
                        addedTurtleNumber = j;
                    }
                }
                if (addedTurtleNumber == 0) {
                    addTurtleFlag = false;
                } else {
                    addTurtleFlag = true;

                }
            }

            if (buttonPush(xGL, yGL, mRenderer.addTurtle)) {
                addedTurtleNumber = 0;
                addedTurtleX = .1f;
                addedTurtleY = .1f;
                for (int j = 1; j < 11; j++) {
                    if (tList[j].getOn() != 1) {
                        addedTurtleNumber = j;
                    }
                }
                if (addedTurtleNumber == 0) {
                    addTurtleFlag = false;
                } else {
                    addTurtleFlag = true;

                }
            }

            if (buttonPush(xGL, yGL, mRenderer.dragRobotToggle)) {
                if (mRenderer.dragRobotToggle.active == false) {
                    mRenderer.dragRobotToggle.active = true;
                } else {
                    mRenderer.dragRobotToggle.active = false;
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.gaussianPathToggle)) {
                if (mRenderer.gaussianPathToggle.active == true) {
                    mRenderer.gaussianPathToggle.active = false;
                    mRenderer.gaussPathPlay.active = false;
                } else {
                    mRenderer.gaussianPathToggle.active = true;
                    if (mRenderer.getfToggle() == 1) {//
                        mRenderer.gaussPathPlay.active = true;
                        mRenderer.updateGauss(
                                mRenderer.pathArray.pose[0].x * mRenderer.scale
                                        + mRenderer.dragX * mRenderer.scale,
                                mRenderer.pathArray.pose[0].y * mRenderer.scale
                                        + mRenderer.dragY * mRenderer.scale,
                                0);
                        gaussianPathArrayIteration = 1;
                        deltaX = (mRenderer.pathArray.pose[gaussianPathArrayIteration].x
                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].x)
                                / (float) Math.sqrt(Math
                                        .pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].x
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].x, 2)
                                        + Math.pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].y
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].y,
                                                2));
                        deltaY = (mRenderer.pathArray.pose[gaussianPathArrayIteration].y
                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].y)
                                / (float) Math.sqrt(Math
                                        .pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].x
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].x, 2)
                                        + Math.pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].y
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].y,
                                                2));

                    }
                }
            }

            if (xGL < mRenderer.clearAll.left - mRenderer.slider
                    && xGL > mRenderer.clearAll.right - mRenderer.slider && yGL > mRenderer.clearAll.down
                    && yGL < mRenderer.clearAll.up) {
                if (mRenderer.clearAll.active == true) {
                    mRenderer.clearAll.active = false;
                    v.vibrate(50);
                } else {
                    mRenderer.clearAll.active = true;
                    v.vibrate(50);
                }
            }

            if (xGL < mRenderer.resetToggle.left - mRenderer.slider
                    && xGL > mRenderer.resetToggle.right - mRenderer.slider && yGL > mRenderer.resetToggle.down
                    && yGL < mRenderer.resetToggle.up) {
                if (mRenderer.resetToggle.active == true) {
                    mRenderer.resetToggle.active = false;
                    v.vibrate(50);
                } else {
                    mRenderer.resetToggle.active = true;
                    v.vibrate(50);
                }
            }

            /*                    if (xGL<-(width1-90)/height1+.05f && xGL>-(width1-90)/height1 && yGL >-(height1-10)/(height1)-mRenderer.slider  && yGL < -(height1-10)/(height1)+05f-mRenderer.slider ){
                    
            }*/

            //Clear button
            if (xGL < mRenderer.clear.left - mRenderer.slider && xGL > mRenderer.clear.right - mRenderer.slider
                    && yGL > mRenderer.clear.down && yGL < mRenderer.clear.up) {
                if (mRenderer.getgToggle() == 1) {
                    gInd = 0;
                    mRenderer.clearGauss();

                }
                if (mRenderer.dragToggle.active == true) {
                    obsticle.on = 0;
                }

                deleteTurtleNumber = -1;
                for (int i = 0; i < maxBots; i++) {
                    if (tList[i].getState() == 1) {
                        deleteTurtleNumber = i;
                    }
                }
                if (deleteTurtleNumber != -1) {
                    deleteTurtleFlag = true;
                } else {
                    deleteTurtleFlag = false;
                }

                v.vibrate(75);
                mRenderer.clear.active = true;

            }

        }

        if (pFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            pX = xGL - mRenderer.dragX * mRenderer.scale;
            pY = yGL - mRenderer.dragY * mRenderer.scale;
            pFlag2 = 1;
            mRenderer.setpToggle2(pFlag2);
            mRenderer.setWayPointValues(pX, pY);
        }

        if (gFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            //pX=xGL;
            //pY=yGL;
            gFlag2 = 1;
            mRenderer.setgToggle2(gFlag2);

            //System.out.println("GAUSSIAN INDEX: " +gInd);
            //mRenderer.setWayPointValues(xGL, yGL);
            //mRenderer.setGaussValues(xGL, yGL, gInd);
            //mRenderer.setGaussScale(1f);
            if (gInd < 99) {
                //mRenderer.addGaussStuff(xGL, yGL, 1f,gInd);
                //TEMP FIX
                mRenderer.addGaussStuff(xGL, yGL, 1f, 0);
            }
            gInd++;
        }

        if (mRenderer.gToggle == 0 && mRenderer.fToggle == 0 && mRenderer.directionalDrag.active == true
                && (mRenderer.directionalDrag.active == true
                        && xGL < mRenderer.directionalDrag.left - mRenderer.slider
                        && xGL > mRenderer.directionalDrag.right - mRenderer.slider
                        && yGL > mRenderer.directionalDrag.down && yGL < mRenderer.directionalDrag.up)) {
            v.vibrate(50);
            if (xGL > mRenderer.directionalDrag.left
                    + (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX - .01f;
            }
            if (xGL < mRenderer.directionalDrag.left
                    + 2 * (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX + .01f;
            }

            if (yGL > mRenderer.directionalDrag.up
                    + (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY - .01f;
            }
            if (yGL < mRenderer.directionalDrag.up
                    + 2 * (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY + .01f;
            }
        }

    case MotionEvent.ACTION_POINTER_DOWN:
        //System.out.println("GAUSS 0");
        if (e.getActionIndex() == 1) {

            if (gFlag == 1) {
                float gaussX = e.getX(1);

                float gaussY = e.getY(1);

                float gauss_xGL = (width1 / 2 - gaussX) / (float) (height1 / 1.85);
                float gauss_yGL = (height1 / 2 + 30 - gaussY) / (float) (height1 / 1.85);

                float gauss_dx = gauss_xGL - xGL;
                float gauss_dy = gauss_yGL - yGL;

                float dgauss = (float) Math.sqrt(Math.pow(gauss_dx, 2) + Math.pow(gauss_dy, 2));

                gaussScale = dgauss / .2f;
                //System.out.println("SCALE");
                //mRenderer.addGaussStuff(xGL, yGL, gaussScale,gInd-1);
                //mRenderer.setGaussScale(gInd-1, gaussScale);
                //TEMP FIX
                mRenderer.setGaussScale(0, gaussScale);
            }
        }

    case MotionEvent.ACTION_MOVE:

        mRenderer.tToggle = 1;
        float dx = x - mPreviousX;
        float dy = y - mPreviousY;

        if (mRenderer.dragRobotToggle.active) {
            for (int i = 0; i < maxBots; i++) {
                if (tList[i].getOn() == 1) {
                    if (Math.abs(tList[i].getX() * getScale() + mRenderer.dragX * mRenderer.scale - xGL) < .1f
                            && Math.abs(tList[i].getY() * getScale() + mRenderer.dragY * mRenderer.scale
                                    - yGL) < .1f) {
                        addedTurtleNumber = i;
                        addedTurtleX = xGL / getScale() - mRenderer.dragX;
                        addedTurtleY = yGL / getScale() - mRenderer.dragY;
                        addTurtleFlag = true;
                        v.vibrate(50);
                    }
                }
            }

        }
        //pX+(float)Math.cos(formation.val4)*.3f+dragX*scale, pY+(float)Math.sin(formation.val4)*.3f+dragY*scale, 0);
        if (mRenderer.formation.active && mRenderer.formationToggleTransform.active) {

            if (Math.abs(mRenderer.formation.x * mRenderer.scale
                    + (float) Math.cos(mRenderer.formation.val4) * .3f * mRenderer.scale
                    + mRenderer.dragX * mRenderer.scale - xGL) < .15f
                    && Math.abs(mRenderer.formation.y * mRenderer.scale
                            + (float) Math.sin(mRenderer.formation.val4) * .3f * mRenderer.scale
                            + mRenderer.dragY * mRenderer.scale - yGL) < .15f) {
                mRenderer.formation.val4 = (float) Math.atan2(
                        yGL - (mRenderer.formation.y * mRenderer.scale + mRenderer.dragY * mRenderer.scale),
                        xGL - (mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale));
                mRenderer.refreshFormationtext();
                mRenderer.justifyFormationLocations();
                mRenderer.rotation_block.active = true;
                mRenderer.formation.send = true;
            } else {
                mRenderer.rotation_block.active = false;
            }
        }

        if (mRenderer.formation.active && mRenderer.formationToggleTransform.active) {

            if (Math.abs(
                    mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale - xGL) < .15f
                    && Math.abs(mRenderer.formation.y * mRenderer.scale + mRenderer.dragY * mRenderer.scale
                            - yGL) < .15f) {
                pX = xGL - mRenderer.scale * mRenderer.dragX;
                pY = yGL - mRenderer.scale * mRenderer.dragY;
                mRenderer.setWayPointValues(pX, pY);
                mRenderer.refreshFormationtext();
                mRenderer.justifyFormationLocations();
                mRenderer.center_block.active = true;
                mRenderer.formation.send = true;
            } else {
                mRenderer.center_block.active = false;
            }
        }

        if (mRenderer.formation.active && mRenderer.formationToggleTransform.active) {

            if (Math.abs(mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale
                    + mRenderer.formation.val3 * .2f * mRenderer.scale - xGL) < .15f
                    && Math.abs(mRenderer.formation.y * mRenderer.scale + mRenderer.dragY * mRenderer.scale
                            - yGL) < .15f) {
                mRenderer.formation.val3 = (xGL
                        - (mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale)) / .2f
                        / mRenderer.scale;
                mRenderer.refreshFormationtext();
                mRenderer.justifyFormationLocations();
                mRenderer.scale_block.active = true;
                mRenderer.formation.send = true;
            } else {
                mRenderer.scale_block.active = false;
            }
        }

        if (mRenderer.formation.active && mRenderer.customFormation.active) {
            for (int i = 0; i < mRenderer.formation.val1; i++) {
                if (target(convertToScreenPosition(mRenderer.formation_locations.x[i], true), xGL,
                        convertToScreenPosition(mRenderer.formation_locations.y[i], false), yGL, .15f)) {
                    //mRenderer.formation.x=mRenderer.formation.x*mRenderer.formation.val1-mRenderer.formation_locations.x[i];
                    //mRenderer.formation.y=mRenderer.formation.y*mRenderer.formation.val1-mRenderer.formation_locations.y[i];

                    mRenderer.formation_locations.x[i] = convertToGlobalPosition(xGL, true);
                    mRenderer.formation_locations.y[i] = convertToGlobalPosition(yGL, false);

                    //mRenderer.formation.x=mRenderer.formation.x+mRenderer.formation_locations.x[i];
                    //mRenderer.formation.x=mRenderer.formation.x/mRenderer.formation.val1;

                    //mRenderer.formation.y=mRenderer.formation.y+mRenderer.formation_locations.y[i];
                    //mRenderer.formation.y=mRenderer.formation.y/mRenderer.formation.val1;
                    mRenderer.refreshCenter();
                    break;
                }
            }
        }

        if (mRenderer.dragToggle.active == true && xGL > workspace && xGL < mapLeft && yGL < mapTop
                && yGL > mapBottom) {
            obsticle.x = xGL / getScale() - mRenderer.dragX;
            obsticle.y = yGL / getScale() - mRenderer.dragY;
            obsticle.Aw = 1;
            obsticle.on = 1;
            newObstacle = true;
        }

        if (mRenderer.gToggle == 0 && mRenderer.fToggle == 0 && mRenderer.directionalDrag.active == true
                && (mRenderer.directionalDrag.active == true
                        && xGL < mRenderer.directionalDrag.left - mRenderer.slider
                        && xGL > mRenderer.directionalDrag.right - mRenderer.slider
                        && yGL > mRenderer.directionalDrag.down && yGL < mRenderer.directionalDrag.up)) {
            v.vibrate(50);
            if (xGL > mRenderer.directionalDrag.left
                    + (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX - .01f;
                System.out.println("LEFT");

            }
            if (xGL < mRenderer.directionalDrag.left
                    + 2 * (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX + .01f;
                System.out.println("RIGHT");
            }

            if (yGL > mRenderer.directionalDrag.up
                    + (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY - .01f;
                System.out.println("UP");
            }
            if (yGL < mRenderer.directionalDrag.up
                    + 2 * (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY + .01f;
                System.out.println("DOWN");
            }
        }

        if (fFlag == 1 && (Math.abs(xGL - previousx) > .03f || Math.abs(yGL - previousy) > .03f)
                && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            if (previousx != 0 && previousy != 0) {
                if (firstPointFreeDraw[0] == -1000) {
                    firstPointFreeDraw[0] = previousx;
                    firstPointFreeDraw[1] = previousy;
                } else if (xGL > firstPointFreeDraw[0] + .1f || xGL < firstPointFreeDraw[0] - .1f
                        || yGL > firstPointFreeDraw[1] + .1f || yGL < firstPointFreeDraw[1] - .1f) {
                    connectable = 1;
                } else if (connectable == 1) {
                    fFlag = 0;
                    setFreeDrawCoordinates(firstPointFreeDraw[0], firstPointFreeDraw[1], previousx, previousy,
                            true);
                    v.vibrate(50);
                }

                if (fFlag == 1) {
                    setFreeDrawCoordinates(xGL - mRenderer.dragX * mRenderer.scale,
                            yGL - mRenderer.dragY * mRenderer.scale,
                            previousx - mRenderer.dragX * mRenderer.scale,
                            previousy - mRenderer.dragY * mRenderer.scale, false);
                }

            }

            previousx = xGL;
            previousy = yGL;
        }

        // reverse direction of rotation above the mid-line
        if (y > getHeight() / 2) {
            dx = dx * -1;
        }

        // reverse direction of rotation to left of the mid-line
        if (x < getWidth() / 2) {
            dy = dy * -1;
        }

        if (yGL > -.15f && yGL < .15f && xGL > -(width1 - 115) / (height1 * 2) - mRenderer.slider
                && xGL < -(width1 - 115) / (height1 * 2) - mRenderer.slider + .15f) {
            mRenderer.slider = -(width1 - 115) / (height1 * 2) - xGL;
            if (mRenderer.slider < .1f) {
                mRenderer.slider = 0;
            } else if (mRenderer.slider > -.1f + (width1 - 115) / (height1 * 2)) {
                mRenderer.slider = (width1 - 115) / (height1 * 2);
            }
        }

        mRenderer.setAngle(mRenderer.getAngle() + ((dx + dy) * TOUCH_SCALE_FACTOR)); // = 180.0f / 320
        requestRender();

        if (pFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            pX = xGL - mRenderer.scale * mRenderer.dragX;
            pY = yGL - mRenderer.scale * mRenderer.dragY;
            pFlag2 = 1;
            mRenderer.setpToggle2(pFlag2);
            mRenderer.setWayPointValues(pX, pY);
        }

        //moving gauss
        if (gFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            pX = xGL;
            pY = yGL;
            gFlag2 = 1;
            mRenderer.setpToggle2(gFlag2);
            //TEMP FIX
            mRenderer.updateGauss(xGL, yGL, 0);
            //mRenderer.updateGauss(xGL, yGL, gInd-1);
        }

        if (mRenderer.gToggle == 1 && xGL < mRenderer.bar.left + .04f - mRenderer.slider
                && xGL > mRenderer.bar.right - .04f - mRenderer.slider && yGL > mRenderer.dial.down
                && yGL < mRenderer.dial.up) {
            mRenderer.dial1 = -(xGL - mRenderer.bar.left - mRenderer.slider) / .6f;
            if (mRenderer.dial1 < 0.05) {
                mRenderer.dial1 = 0;
            } else if (mRenderer.dial1 > 1) {
                mRenderer.dial1 = 1;
            } else if (mRenderer.dial1 < .15) {
                mRenderer.dial1 = .1f;
            } else if (mRenderer.dial1 < .25) {
                mRenderer.dial1 = .2f;
            } else if (mRenderer.dial1 < .35) {
                mRenderer.dial1 = .3f;
            } else if (mRenderer.dial1 < .45) {
                mRenderer.dial1 = .4f;
            } else if (mRenderer.dial1 < .55) {
                mRenderer.dial1 = .5f;
            } else if (mRenderer.dial1 < .65) {
                mRenderer.dial1 = .6f;
            } else if (mRenderer.dial1 < .75) {
                mRenderer.dial1 = .7f;
            } else if (mRenderer.dial1 < .85) {
                mRenderer.dial1 = .8f;
            } else if (mRenderer.dial1 < .95) {
                mRenderer.dial1 = .9f;
            } else {
                mRenderer.dial1 = 1;
            }
            mRenderer.textListGaussian.get(1).setText(" " + truncateDecimal(mRenderer.dial1, 1));
            mRenderer.dial.active = true;
            v.vibrate(50);
        }

        if (mRenderer.gToggle == 1 && xGL < mRenderer.bar_2.left + .04f - mRenderer.slider
                && xGL > mRenderer.bar_2.right - .04f - mRenderer.slider && yGL > mRenderer.dial_2.down
                && yGL < mRenderer.dial_2.up) {
            mRenderer.dial2 = -(xGL - mRenderer.bar_2.left - mRenderer.slider) / .6f;
            if (mRenderer.dial2 < 0.05) {
                mRenderer.dial2 = 0;
            } else if (mRenderer.dial2 > 1) {
                mRenderer.dial2 = 1;
            } else if (mRenderer.dial2 < .15) {
                mRenderer.dial2 = .1f;
            } else if (mRenderer.dial2 < .25) {
                mRenderer.dial2 = .2f;
            } else if (mRenderer.dial2 < .35) {
                mRenderer.dial2 = .3f;
            } else if (mRenderer.dial2 < .45) {
                mRenderer.dial2 = .4f;
            } else if (mRenderer.dial2 < .55) {
                mRenderer.dial2 = .5f;
            } else if (mRenderer.dial2 < .65) {
                mRenderer.dial2 = .6f;
            } else if (mRenderer.dial2 < .75) {
                mRenderer.dial2 = .7f;
            } else if (mRenderer.dial2 < .85) {
                mRenderer.dial2 = .8f;
            } else if (mRenderer.dial2 < .95) {
                mRenderer.dial2 = .9f;
            } else {
                mRenderer.dial2 = 1;
            }
            mRenderer.textListGaussian.get(3).setText(" " + truncateDecimal(mRenderer.dial2, 1));
            mRenderer.dial_2.active = true;
            v.vibrate(50);
        }

        if (mRenderer.gToggle == 1 && xGL < mRenderer.bar_3.left + .04f - mRenderer.slider
                && xGL > mRenderer.bar_3.right - .04f - mRenderer.slider && yGL > mRenderer.dial_3.down
                && yGL < mRenderer.dial_3.up) {
            mRenderer.dial3 = -(xGL - mRenderer.bar_3.left - mRenderer.slider) / .6f;
            if (mRenderer.dial3 < 0.05) {
                mRenderer.dial3 = 0;
            } else if (mRenderer.dial3 > 1) {
                mRenderer.dial3 = 1;
            } else if (mRenderer.dial3 < .15) {
                mRenderer.dial3 = .1f;
            } else if (mRenderer.dial3 < .25) {
                mRenderer.dial3 = .2f;
            } else if (mRenderer.dial3 < .35) {
                mRenderer.dial3 = .3f;
            } else if (mRenderer.dial3 < .45) {
                mRenderer.dial3 = .4f;
            } else if (mRenderer.dial3 < .55) {
                mRenderer.dial3 = .5f;
            } else if (mRenderer.dial3 < .65) {
                mRenderer.dial3 = .6f;
            } else if (mRenderer.dial3 < .75) {
                mRenderer.dial3 = .7f;
            } else if (mRenderer.dial3 < .85) {
                mRenderer.dial3 = .8f;
            } else if (mRenderer.dial3 < .95) {
                mRenderer.dial3 = .9f;
            } else {
                mRenderer.dial3 = 1;
            }
            mRenderer.textListGaussian.get(5).setText(" " + truncateDecimal(mRenderer.dial3, 1));
            mRenderer.dial_3.active = true;
            v.vibrate(50);
        }

    case MotionEvent.ACTION_UP:

        mRenderer.tToggle = 1;
        //mRenderer.clear.active = false;

    }

    mPreviousX = x;
    mPreviousY = y;

    antispam = 0;
    return true;
}

From source file:com.android.nobug.view.pattern.PatternView.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    if (!mInputEnabled || !isEnabled()) {
        return false;
    }/*from   w  w  w  . ja v a 2 s  .co m*/

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        handleActionDown(event);
        return true;
    case MotionEvent.ACTION_UP:
        handleActionUp();
        return true;
    case MotionEvent.ACTION_MOVE:
        handleActionMove(event);
        return true;
    case MotionEvent.ACTION_CANCEL:
        if (mPatternInProgress) {
            setPatternInProgress(false);
            resetPattern();
            notifyPatternCleared();
        }
        if (PROFILE_DRAWING) {
            if (mDrawingProfilingStarted) {
                Debug.stopMethodTracing();
                mDrawingProfilingStarted = false;
            }
        }
        return true;
    }
    return false;
}

From source file:cn.ieclipse.af.view.refresh.SwipyRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    try {//from www  .j av  a2  s  . co  m
        final int action = MotionEventCompat.getActionMasked(ev);

        if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
            mReturningToStart = false;
        }

        switch (mDirection) {
        case BOTTOM:
            if (!isEnabled() || mReturningToStart || canChildScrollDown() || mRefreshing) {
                // Fail fast if we're not in a state where a swipe is possible
                return false;
            }
            break;
        case TOP:
        default:
            if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) {
                // Fail fast if we're not in a state where a swipe is possible
                return false;
            }
            break;
        }

        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            mIsBeingDragged = false;
            break;

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

            final float y = MotionEventCompat.getY(ev, pointerIndex);

            float overscrollTop;
            switch (mDirection) {
            case BOTTOM:
                overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
                break;
            case TOP:
            default:
                overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
                break;
            }
            if (mIsBeingDragged) {
                mProgress.showArrow(true);
                float originalDragPercent = overscrollTop / mTotalDragDistance;
                if (originalDragPercent < 0) {
                    return false;
                }
                float dragPercent = Math.min(1f, Math.abs(originalDragPercent));
                float adjustedPercent = (float) Math.max(dragPercent - .4, 0) * 5 / 3;
                float extraOS = Math.abs(overscrollTop) - mTotalDragDistance;
                float slingshotDist = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                        : mSpinnerFinalOffset;
                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 = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
                int targetY;
                if (mDirection == SwipyRefreshLayoutDirection.TOP) {
                    targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
                } else {
                    targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
                }
                // where 1.0f is a full circle
                if (mCircleView.getVisibility() != View.VISIBLE) {
                    mCircleView.setVisibility(View.VISIBLE);
                }
                if (!mScale) {
                    ViewCompat.setScaleX(mCircleView, 1f);
                    ViewCompat.setScaleY(mCircleView, 1f);
                }
                if (overscrollTop < mTotalDragDistance) {
                    if (mScale) {
                        setAnimationProgress(overscrollTop / mTotalDragDistance);
                    }
                    if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                            && !isAnimationRunning(mAlphaStartAnimation)) {
                        // Animate the alpha
                        startProgressAlphaStartAnimation();
                    }
                    float strokeStart = (float) (adjustedPercent * .8f);
                    mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                    mProgress.setArrowScale(Math.min(1f, adjustedPercent));
                } else {
                    if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                        // Animate the alpha
                        startProgressAlphaMaxAnimation();
                    }
                }
                float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
                mProgress.setProgressRotation(rotation);
                setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop, true /* requires update */);
            }
            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) {
                if (action == MotionEvent.ACTION_UP) {
                }
                return false;
            }
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float y = MotionEventCompat.getY(ev, pointerIndex);

            float overscrollTop;
            switch (mDirection) {
            case BOTTOM:
                overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
                break;
            case TOP:
            default:
                overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
                break;
            }
            mIsBeingDragged = false;
            if (overscrollTop > mTotalDragDistance) {
                setRefreshing(true, true /* notify */);
            } else {
                // cancel refresh
                mRefreshing = false;
                mProgress.setStartEndTrim(0f, 0f);
                AnimationListener listener = null;
                if (!mScale) {
                    listener = new AnimationListener() {

                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            if (!mScale) {
                                startScaleDownAnimation(null);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {
                        }

                    };
                }
                animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
                mProgress.showArrow(false);
            }
            mActivePointerId = INVALID_POINTER;
            return false;
        }
        }
    } catch (Exception e) {
        Log.e(TAG, "An exception occured during SwipyRefreshLayout onTouchEvent " + e.toString());
    }

    return true;
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    // Return if animation is running
    if (mAnimator.isRunning())
        return true;
    // If is not idle state, return
    if (mScrollState != ViewPager.SCROLL_STATE_IDLE)
        return true;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // Action down touch
        mIsActionDown = true;/*from  w w w  .j  av a2 s . com*/
        if (!mIsViewPagerMode)
            break;
        if (!mIsSwiped)
            break;
        // Detect if we touch down on pointer, later to move
        if (mIsHorizontalOrientation)
            mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex;
        else
            mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex;
        break;
    case MotionEvent.ACTION_MOVE:
        // If pointer touched, so move
        if (mIsPointerActionDown) {
            if (mIsHorizontalOrientation)
                mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true);
            else
                mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true);
            break;
        }
        if (mIsActionDown)
            break;
    case MotionEvent.ACTION_UP:
        // Press up and set model index relative to current coordinate
        if (mIsActionDown) {
            playSoundEffect(SoundEffectConstants.CLICK);
            if (mIsHorizontalOrientation)
                setModelIndex((int) (event.getX() / mModelSize));
            else
                setModelIndex((int) (event.getY() / mModelSize));
        }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
    default:
        // Reset action touch variables
        mIsPointerActionDown = false;
        mIsActionDown = false;
        break;
    }

    return true;
}

From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    Log.i(TAG, "onInterceptTouchEvent()");
    final int action = MotionEventCompat.getActionMasked(ev);
    final boolean interceptForDrag = mBottomDragger.shouldInterceptTouchEvent(ev);

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN");
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;/*w w  w.ja  v  a 2  s  . com*/
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE");
        if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2");
            mBottomCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }
    boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    Log.i(TAG, "onInterceptTouchEvent() -- result = " + result);
    return result;
}

From source file:com.aidy.launcher3.support.views.bottomdrawer.BottomDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    Log.i(TAG, "onInterceptTouchEvent()");
    final int action = MotionEventCompat.getActionMasked(ev);
    final boolean interceptForDrag = mBottomDragger.shouldInterceptTouchEvent(ev);

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN");
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;/*from w  w  w  .  ja  v  a  2  s. co m*/
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;

        break;
    }

    case MotionEvent.ACTION_MOVE: {
        Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE");
        if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2");
            mBottomCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }
    boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    Log.i(TAG, "onInterceptTouchEvent() -- result = " + result);
    return result;
}

From source file:com.common.view.slidingfinish.CustomSlidingPaneLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    // Preserve the open state based on the last view that was touched.
    if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) {
        // After the first things will be slideable.
        final View secondChild = getChildAt(1);
        if (secondChild != null) {
            mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY());
        }/*from w w w . j  a va  2s  .c  o m*/
    }

    if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

    boolean interceptTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;

        if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) {
            interceptTap = true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        if (adx > slop && ady > adx) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
    }
    }

    final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev);

    return interceptForDrag || interceptTap;
}

From source file:atownsend.swipeopenhelper.SwipeOpenItemTouchHelper.java

/**
 * Checks whether we should select a View for swiping.
 *///from ww w  . j a  va  2s.  co m
private boolean checkSelectForSwipe(int action, MotionEvent motionEvent, int pointerIndex) {
    if (selected != null || action != MotionEvent.ACTION_MOVE) {
        return false;
    }
    if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
        return false;
    }
    final RecyclerView.ViewHolder vh = findSwipedView(motionEvent);
    if (vh == null || !(vh instanceof SwipeOpenViewHolder)) {
        return false;
    }

    final int movementFlags = callback.getAbsoluteMovementFlags(recyclerView, vh);

    final int swipeFlags = (movementFlags & ACTION_MODE_SWIPE_MASK) >> (DIRECTION_FLAG_COUNT
            * ACTION_STATE_SWIPE);

    if (swipeFlags == 0) {
        return false;
    }

    // dX and dY are only set in allowed directions. We use custom x/y here instead of
    // updateDxDy to avoid swiping if user moves more in the other direction
    final float x = MotionEventCompat.getX(motionEvent, pointerIndex);
    final float y = MotionEventCompat.getY(motionEvent, pointerIndex);

    // Calculate the distance moved
    final float dx = x - initialTouchX;
    final float dy = y - initialTouchY;
    // swipe target is chose w/o applying flags so it does not really check if swiping in that
    // direction is allowed. This why here, we use dX dY to check slope value again.
    final float absDx = Math.abs(dx);
    final float absDy = Math.abs(dy);

    if (absDx < slop && absDy < slop) {
        return false;
    }
    if (absDx > absDy) {
        if (dx < 0 && (swipeFlags & LEFT) == 0) {
            return false;
        }
        if (dx > 0 && (swipeFlags & RIGHT) == 0) {
            return false;
        }
    } else {
        if (dy < 0 && (swipeFlags & UP) == 0) {
            return false;
        }
        if (dy > 0 && (swipeFlags & DOWN) == 0) {
            return false;
        }
    }
    dX = dY = 0f;
    activePointerId = MotionEventCompat.getPointerId(motionEvent, 0);
    select((SwipeOpenViewHolder) vh, ACTION_STATE_SWIPE);
    return true;
}

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

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

    // Preserve the open state based on the last view that was touched.
    if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) {
        // After the first things will be slideable.
        final View secondChild = getChildAt(1);
        if (secondChild != null) {
            mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY());
        }//w ww  .  j a  v  a 2s  .  c o  m
    }

    if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

    boolean interceptTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;

        if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) {
            interceptTap = true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float adx = Math.abs(x - mInitialMotionX);
        final float deltaX = x - mInitialMotionX;
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        if ((adx > slop && ady > adx) || deltaX < 0) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
    }
    }

    final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev);

    return interceptForDrag || interceptTap;
}

From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

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

    // "|" used deliberately here; both methods should be invoked.
    final boolean interceptForDrag = mTopDragger.shouldInterceptTouchEvent(ev)
            | mBottomDragger.shouldInterceptTouchEvent(ev);

    boolean interceptForTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;/*from  ww w  . j  ava2s.c  o  m*/
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mTopDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        // If we cross the touch slop, don't perform the delayed peek for an edge touch.
        if (mTopDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            mTopCallback.removeCallbacks();
            mBottomCallback.removeCallbacks();
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }

    return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
}