List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide) { return super.onTouchEvent(ev); }//ww w . j a va2 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: { 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(mSlideableView, 0); break; } } break; } } return wantTouchEvents; }
From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { try {// www . j av a2 s. com 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()); } } 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; } catch (ArrayIndexOutOfBoundsException e) { LogManager.logE(BugFixedSlidingPaneLayout.class, "internal bug in SlidingPaneLayout,this bug can be ignored in most cases.", e); return false; } }
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;/*from w w w . ja v a2s . 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.kit.swipeback.ViewDragHelper.java
/** * Check if this event as provided to the parent view's * onInterceptTouchEvent should cause the parent to intercept the touch * event stream.//from ww w.ja v a2 s . co m * * @param ev MotionEvent provided to onInterceptTouchEvent * @return true if the parent view should return true from * onInterceptTouchEvent */ public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. tryCaptureViewForDrag(toCapture, pointerId); final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); break; } case MotionEvent.ACTION_MOVE: { if (mDragState == STATE_JUDGING) { final int i = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[mActivePointerId]; final float dy = y - mInitialMotionY[mActivePointerId]; reportNewEdgeDrags(dx, dy, mActivePointerId); final View toCapture = findTopChildUnder((int) x, (int) y); int slop = checkTouchSlop(toCapture, dx, dy); if (slop == -1) cancel(); else if (slop > 0 && tryCaptureViewForDrag(toCapture, mActivePointerId)) { break; } saveLastMotion(ev); } break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { cancel(); break; } } return mDragState == STATE_DRAGGING; }
From source file:cnedu.ustcjd.widget.MultiSlider.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!mIsUserSeekable || !isEnabled()) { return false; }//from ww w .j a v a2 s . c o m final int xx = Math.round(event.getX()); final int yy = Math.round(event.getY()); int pointerIdx = event.getActionIndex(); Thumb currThumb = null; if (event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { LinkedList<Thumb> closestOnes = getClosestThumb((int) event.getX(pointerIdx)); if (isInScrollingContainer() && mDraggingThumbs.size() == 0 && exactTouched != null && pointerIdx > 0) { //we have been here before => we want to use the bar Thumb prevThumb = exactTouched.getFirst(); onStartTrackingTouch(prevThumb); exactTouched = null; } if (closestOnes != null && !closestOnes.isEmpty()) { if (closestOnes.size() == 1) { currThumb = closestOnes.getFirst(); if (isInScrollingContainer() && mDraggingThumbs.size() == 0) { exactTouched = closestOnes; } } else { //we have more than one thumb at the same place and we touched there exactTouched = closestOnes; } } } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { if (exactTouched != null && !exactTouched.isEmpty()) { currThumb = getMostMovableThumb(event); //check if move actually changed value // if (currThumb == null) return false; } else if (mDraggingThumbs.size() > pointerIdx) { currThumb = mDraggingThumbs.get(pointerIdx); } } else if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) { if (mDraggingThumbs.size() > pointerIdx) { currThumb = mDraggingThumbs.get(pointerIdx); } //else we had a candidate but was never tracked else if (exactTouched != null && exactTouched.size() > 0) { currThumb = getMostMovableThumb(event); exactTouched = null; } } // else { // LinkedList<Thumb> closestOnes = getClosestThumb((int) event.getX()); // currThumb = closestOnes.getFirst(); // } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: if (isInScrollingContainer() && mDraggingThumbs.size() == 0) { mTouchDownX = event.getX(pointerIdx); } else { onStartTrackingTouch(currThumb); setThumbValue(currThumb, getValue(event, currThumb), true); setHotspot(xx, yy, currThumb); } break; //with move we dont have pointer action so set them all case MotionEvent.ACTION_MOVE: if (mDraggingThumbs.contains(currThumb)) { //need the index for (int i = 0; i < mDraggingThumbs.size(); i++) { if (mDraggingThumbs.get(i) != null && mDraggingThumbs.get(i).getThumb() != null) { invalidate(mDraggingThumbs.get(i).getThumb().getBounds()); } setThumbValue(mDraggingThumbs.get(i), getValue(event, i, mDraggingThumbs.get(i)), true); } setHotspot(xx, yy, currThumb); } else { final float x = event.getX(pointerIdx); if (Math.abs(x - mTouchDownX) > mScaledTouchSlop) { onStartTrackingTouch(currThumb); exactTouched = null; setThumbValue(currThumb, getValue(event, currThumb), true); setHotspot(xx, yy, currThumb); } } break; case MotionEvent.ACTION_UP: setPressed(false); //there are other pointers left case MotionEvent.ACTION_POINTER_UP: if (currThumb != null) { boolean toUnPress = false; if (!isPressed()) { setPressed(true); toUnPress = true; } setThumbValue(currThumb, getValue(event, currThumb), true); setHotspot(xx, yy, currThumb); onStopTrackingTouch(currThumb); if (toUnPress) { setPressed(false); } } else { // currThumb = getClosestThumb(newValue); // // Touch up when we never crossed the touch slop threshold should // // be interpreted as a tap-seek to that location. // onStartTrackingTouch(currThumb); // setThumbValue(currThumb, newValue, true); // onStopTrackingTouch(currThumb); } // ProgressBar doesn't know to repaint the thumb drawable // in its inactive state when the touch stops (because the // value has not apparently changed) invalidate(); break; case MotionEvent.ACTION_CANCEL: if (mDraggingThumbs != null) { onStopTrackingTouch(); setPressed(false); } invalidate(); // see above explanation break; } return true; }
From source file:com.android.volley.ui.PhotoView.java
private boolean scale(MotionEvent e) { boolean handled = false; if (mDoubleTapToZoomEnabled && mTransformsEnabled && mDoubleTapOccurred) { if (!mDoubleTapDebounce) { float currentScale = getScale(); float targetScale = currentScale * DOUBLE_TAP_SCALE_FACTOR; // Ensure the target scale is within our bounds targetScale = Math.max(mMinScale, targetScale); targetScale = Math.min(mMaxScale, targetScale); mScaleRunnable.start(currentScale, targetScale, e.getX(), e.getY()); handled = true;/*from w w w . ja va2 s .c o m*/ } mDoubleTapDebounce = false; } mDoubleTapOccurred = false; return handled; }
From source file:com.aidy.bottomdrawerlayout.DrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { Log.i(TAG, "onTouchEvent()"); mLeftDragger.processTouchEvent(ev);/*from w w w . jav a 2 s .co m*/ mRightDragger.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { Log.i(TAG, "onTouchEvent() -- ACTION_DOWN"); final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_UP: { Log.i(TAG, "onTouchEvent() -- ACTION_UP"); final float x = ev.getX(); final float y = ev.getY(); boolean peekingOnly = true; final View touchedView = mLeftDragger.findTopChildUnder((int) x, (int) y); if (touchedView != null && isContentView(touchedView)) { final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mLeftDragger.getTouchSlop(); if (dx * dx + dy * dy < slop * slop) { // Taps close a dimmed open drawer but only if it isn't // locked open. final View openDrawer = findOpenDrawer(); if (openDrawer != null) { peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN; } } } closeDrawers(peekingOnly); mDisallowInterceptRequested = false; break; } case MotionEvent.ACTION_CANCEL: { Log.i(TAG, "onTouchEvent() -- ACTION_CANCEL"); closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } } boolean result = wantTouchEvents; Log.i(TAG, "onTouchEvent() -- result = " + result); return result; }
From source file:com.architjn.acjmusicplayer.ui.widget.slidinguppanel.ViewDragHelper.java
/** * Check if this event as provided to the parent view's onInterceptTouchEvent should * cause the parent to intercept the touch event stream. * * @param ev MotionEvent provided to onInterceptTouchEvent * @return true if the parent view should return true from onInterceptTouchEvent *//*from www . ja v a2 s. c o m*/ public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. if (toCapture == mCapturedView && mDragState == STATE_SETTLING) { tryCaptureViewForDrag(toCapture, pointerId); } final int edgesTouched = mInitialEdgesTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); // A ViewDragHelper can only manipulate one view at a time. if (mDragState == STATE_IDLE) { final int edgesTouched = mInitialEdgesTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } } else if (mDragState == STATE_SETTLING) { // Catch a settling view if possible. final View toCapture = findTopChildUnder((int) x, (int) y); if (toCapture == mCapturedView) { tryCaptureViewForDrag(toCapture, pointerId); } } break; } case MotionEvent.ACTION_MOVE: { // First to cross a touch slop over a draggable view wins. Also report edge drags. final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount && mInitialMotionX != null && mInitialMotionY != null; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[pointerId]; final float dy = y - mInitialMotionY[pointerId]; reportNewEdgeDrags(dx, dy, pointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag break; } final View toCapture = findTopChildUnder((int) mInitialMotionX[pointerId], (int) mInitialMotionY[pointerId]); if (toCapture != null && checkTouchSlop(toCapture, dx, dy) && tryCaptureViewForDrag(toCapture, pointerId)) { break; } } saveLastMotion(ev); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { cancel(); break; } } return mDragState == STATE_DRAGGING; }
From source file:com.android.kit.swipeback.ViewDragHelper.java
/** * Process a touch event received by the parent view. This method will * dispatch callback events as needed before returning. The parent view's * onTouchEvent implementation should call this. * * @param ev The touch event received by the parent view *///from www . j av a 2s . c o m public void processTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. tryCaptureViewForDrag(toCapture, pointerId); final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); break; } case MotionEvent.ACTION_MOVE: { if (mDragState == STATE_JUDGING) { final int i = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[mActivePointerId]; final float dy = y - mInitialMotionY[mActivePointerId]; reportNewEdgeDrags(dx, dy, mActivePointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag. break; } final View toCapture = findTopChildUnder((int) x, (int) y); int slop = checkTouchSlop(toCapture, dx, dy); if (slop == -1) cancel(); else if (slop > 0 && tryCaptureViewForDrag(toCapture, mActivePointerId)) { break; } saveLastMotion(ev); } if (mDragState == STATE_DRAGGING) { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); //???????? if (index == -1) break; final float x = MotionEventCompat.getX(ev, index); final float y = MotionEventCompat.getY(ev, index); final int idx = (int) (x - mLastMotionX[mActivePointerId]); final int idy = (int) (y - mLastMotionY[mActivePointerId]); dragTo(mCapturedView.getLeft() + idx, mCapturedView.getTop() + idy, idx, idy); saveLastMotion(ev); } break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: { if (mDragState == STATE_DRAGGING) { releaseViewForPointerUp(); } cancel(); break; } case MotionEvent.ACTION_CANCEL: { if (mDragState == STATE_DRAGGING) { dispatchViewReleased(0, 0); } cancel(); break; } } }
From source file:com.albedinsky.android.support.ui.widget.ViewDragHelper.java
/** * Check if this event as provided to the parent view's onInterceptTouchEvent should * cause the parent to intercept the touch event stream. * * @param ev MotionEvent provided to onInterceptTouchEvent * @return true if the parent view should return true from onInterceptTouchEvent *//* ww w.j a va 2 s .co m*/ public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. if (toCapture == mCapturedView && mDragState == STATE_SETTLING) { tryCaptureViewForDrag(toCapture, pointerId); } final int edgesTouched = mInitialEdgesTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); // A ViewDragHelper can only manipulate one view at a time. if (mDragState == STATE_IDLE) { final int edgesTouched = mInitialEdgesTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } } else if (mDragState == STATE_SETTLING) { // Catch a settling view if possible. final View toCapture = findTopChildUnder((int) x, (int) y); if (toCapture == mCapturedView) { tryCaptureViewForDrag(toCapture, pointerId); } } break; } case MotionEvent.ACTION_MOVE: { // First to cross a touch slop over a draggable view wins. Also report edge drags. final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[pointerId]; final float dy = y - mInitialMotionY[pointerId]; reportNewEdgeDrags(dx, dy, pointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag break; } final View toCapture = findTopChildUnder((int) x, (int) y); if (toCapture != null && checkTouchSlop(toCapture, dx, dy) && tryCaptureViewForDrag(toCapture, pointerId)) { break; } } saveLastMotion(ev); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { cancel(); break; } } return mDragState == STATE_DRAGGING; }