List of usage examples for android.view MotionEvent ACTION_POINTER_DOWN
int ACTION_POINTER_DOWN
To view the source code for android.view MotionEvent ACTION_POINTER_DOWN.
Click Source Link
From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java
/** * Handles thumb selection and movement. Notifies listener callback on certain events. *//* www . j av a 2s .co m*/ @Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (!isEnabled()) { return false; } int pointerIndex; final int action = event.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Remember where the motion event started mActivePointerId = event.getPointerId(event.getPointerCount() - 1); pointerIndex = event.findPointerIndex(mActivePointerId); mDownMotionX = event.getX(pointerIndex); pressedThumb = evalPressedThumb(mDownMotionX); // Only handle thumb presses. if (pressedThumb == null) { pressedThumb = getClosestThumb(mDownMotionX); if (pressedThumb == null) { return false; } } if (listener != null) { listener.onRangeSeekBarPressed(this, Thumb.MAX.equals(pressedThumb) ? getSelectedMaxValue() : getSelectedMinValue(), pressedThumb); } setPressed(true); invalidate(); onStartTrackingTouch(); trackTouchEvent(event); attemptClaimDrag(); break; case MotionEvent.ACTION_MOVE: if (pressedThumb != null) { if (mIsDragging) { trackTouchEvent(event); } else { // Scroll to follow the motion event pointerIndex = event.findPointerIndex(mActivePointerId); final float x = event.getX(pointerIndex); if (Math.abs(x - mDownMotionX) > mScaledTouchSlop) { setPressed(true); invalidate(); onStartTrackingTouch(); trackTouchEvent(event); attemptClaimDrag(); } } if (notifyWhileDragging && listener != null) { listener.onRangeSeekBarValueChanged(this, Thumb.MAX.equals(pressedThumb) ? getSelectedMaxValue() : getSelectedMinValue(), pressedThumb); } } break; case MotionEvent.ACTION_UP: if (mIsDragging) { trackTouchEvent(event); onStopTrackingTouch(); setPressed(false); } else { // Touch up when we never crossed the touch slop threshold // should be interpreted as a tap-seek to that location. onStartTrackingTouch(); trackTouchEvent(event); onStopTrackingTouch(); } if (listener != null) { listener.onRangeSeekBarValueChanged(this, Thumb.MAX.equals(pressedThumb) ? getSelectedMaxValue() : getSelectedMinValue(), pressedThumb); } pressedThumb = null; invalidate(); break; case MotionEvent.ACTION_POINTER_DOWN: { final int index = event.getPointerCount() - 1; // final int index = ev.getActionIndex(); mDownMotionX = event.getX(index); mActivePointerId = event.getPointerId(index); invalidate(); break; } case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(event); invalidate(); break; case MotionEvent.ACTION_CANCEL: if (mIsDragging) { onStopTrackingTouch(); setPressed(false); } invalidate(); // see above explanation break; } return true; }
From source file:com.wunderlist.slidinglayer.SlidingLayer.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { return false; }//from ww w . j a v a 2s. c om if (!mEnabled || !mIsDragging && !touchPointIsWithinBounds(mInitialX, mInitialY)) { return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { completeScroll(); // Remember where the motion event started mLastX = mInitialRawX = getViewX(ev); mLastY = mInitialRawY = getViewY(ev); mInitialX = ev.getX(); mInitialY = ev.getY(); mActivePointerId = ev.getPointerId(0); break; } case MotionEvent.ACTION_MOVE: { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (!touchPointIsWithinBounds(ev.getX(), ev.getY(), false)) return false; final float x = getViewX(ev); final float y = getViewY(ev); final float deltaX = mLastX - x; final float deltaY = mLastY - y; mLastX = x; mLastY = y; if (!mIsDragging) { final float xDiff = Math.abs(x - mInitialRawX); final float yDiff = Math.abs(y - mInitialRawY); final boolean validHorizontalDrag = xDiff > mTouchSlop && xDiff > yDiff; final boolean validVerticalDrag = yDiff > mTouchSlop && yDiff > xDiff; if (validHorizontalDrag || validVerticalDrag) { mIsDragging = true; setDrawingCacheEnabled(true); } } if (mIsDragging) { final float oldScrollX = getScrollX(); final float oldScrollY = getScrollY(); float scrollX = oldScrollX + deltaX; float scrollY = oldScrollY + deltaY; // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY)); final float leftBound, rightBound; final float bottomBound, topBound; switch (mScreenSide) { case STICK_TO_LEFT: topBound = bottomBound = rightBound = 0; leftBound = getWidth(); // How far left we can scroll break; case STICK_TO_RIGHT: rightBound = -getWidth(); topBound = bottomBound = leftBound = 0; break; case STICK_TO_TOP: topBound = getHeight(); bottomBound = rightBound = leftBound = 0; break; case STICK_TO_BOTTOM: bottomBound = -getHeight(); topBound = rightBound = leftBound = 0; break; default: topBound = bottomBound = rightBound = leftBound = 0; break; } if (scrollX > leftBound) { scrollX = leftBound; } else if (scrollX < rightBound) { scrollX = rightBound; } if (scrollY > topBound) { scrollY = topBound; } else if (scrollY < bottomBound) { scrollY = bottomBound; } // Keep the precision mLastX += scrollX - (int) scrollX; mLastY += scrollY - (int) scrollY; scrollToAndNotify((int) scrollX, (int) scrollY); } break; } case MotionEvent.ACTION_UP: { if (mIsDragging) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); final int scrollX = getScrollX(); final int scrollY = getScrollY(); final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = getViewX(ev); final float y = getViewY(ev); int nextState = determineNextStateForDrag(scrollX, scrollY, initialVelocityX, initialVelocityY, (int) mInitialRawX, (int) mInitialRawY, (int) x, (int) y); setLayerState(nextState, true, true, initialVelocityX, initialVelocityY); mActivePointerId = INVALID_VALUE; endDrag(); } else if (changeStateOnTap) { int nextState = determineNextStateAfterTap(); setLayerState(nextState, true, true); } break; } case MotionEvent.ACTION_CANCEL: if (mIsDragging) { setLayerState(mCurrentState, true, true); mActivePointerId = INVALID_VALUE; endDrag(); } break; case MotionEvent.ACTION_POINTER_DOWN: { final int pointerIndex = MotionEventCompat.getActionIndex(ev); mActivePointerId = ev.getPointerId(pointerIndex); mLastX = getViewX(ev); mLastY = getViewY(ev); break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); mLastX = getViewX(ev); mLastY = getViewY(ev); break; } } return true; }
From source file:info.bartowski.easteregg.MLand.java
@Override public boolean onTouchEvent(MotionEvent ev) { L("touch: %s", ev); final int actionIndex = ev.getActionIndex(); final float x = ev.getX(actionIndex); final float y = ev.getY(actionIndex); int playerIndex = (int) (getNumPlayers() * (x / getWidth())); if (mFlipped) playerIndex = getNumPlayers() - 1 - playerIndex; switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: poke(playerIndex, x, y);/* www . ja va2s .co m*/ return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: unpoke(playerIndex); return true; } return false; }
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getActionMasked(); boolean handled = false; switch (action) { case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_DOWN: if (DEBUG) Log.v(TAG, "*** DOWN ***"); handleDown(event);//from ww w . ja va 2s. c o m handleMove(event); handled = true; break; case MotionEvent.ACTION_MOVE: if (DEBUG) Log.v(TAG, "*** MOVE ***"); handleMove(event); handled = true; break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: if (DEBUG) Log.v(TAG, "*** UP ***"); handleMove(event); handleUp(event); handled = true; break; case MotionEvent.ACTION_CANCEL: if (DEBUG) Log.v(TAG, "*** CANCEL ***"); handleMove(event); handleCancel(event); handled = true; break; } invalidate(); return handled ? true : super.onTouchEvent(event); }
From source file:com.hippo.widget.BothScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { initVelocityTrackerIfNotExists();/* w w w.j a v a2 s. c o m*/ mVelocityTracker.addMovement(ev); final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { if (getChildCount() == 0) { return false; } if ((mIsBeingDragged = !mScroller.isFinished())) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mLastMotionX = (int) ev.getX(); mLastMotionY = (int) ev.getY(); mActivePointerId = ev.getPointerId(0); break; } case MotionEvent.ACTION_MOVE: final int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); break; } final int x = (int) ev.getX(activePointerIndex); final int y = (int) ev.getY(activePointerIndex); int deltaX = mLastMotionX - x; int deltaY = mLastMotionY - y; if (!mIsBeingDragged && (Math.abs(deltaX) > mTouchSlop || Math.abs(deltaY) > mTouchSlop)) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } mIsBeingDragged = true; if (deltaX > 0) { deltaX -= mTouchSlop; deltaX = Math.max(0, deltaX); } else { deltaX += mTouchSlop; deltaX = Math.min(0, deltaX); } if (deltaY > 0) { deltaY -= mTouchSlop; deltaY = Math.max(0, deltaY); } else { deltaY += mTouchSlop; deltaY = Math.min(0, deltaY); } } if (mIsBeingDragged) { // Scroll to follow the motion event mLastMotionX = x; mLastMotionY = y; final int oldX = getScrollX(); final int oldY = getScrollY(); final int horizontalRange = getHorizontalScrollRange(); final int verticalRange = getVerticalScrollRange(); final int overscrollMode = getOverScrollMode(); final boolean canOverscroll = overscrollMode == OVER_SCROLL_ALWAYS || (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && (horizontalRange > 0 || verticalRange > 0)); // Calling overScrollBy will call onOverScrolled, which // calls onScrollChanged if applicable. overScrollBy(deltaX, deltaY, oldX, oldY, horizontalRange, verticalRange, mOverscrollDistance, mOverscrollDistance, true); if (canOverscroll) { final int pulledToX = oldX + deltaX; final int pulledToY = oldY + deltaY; if (pulledToX < 0) { mEdgeGlowLeft.onPull((float) deltaX / getWidth()); if (!mEdgeGlowRight.isFinished()) { mEdgeGlowRight.onRelease(); } } else if (pulledToX > horizontalRange) { mEdgeGlowRight.onPull((float) deltaX / getWidth()); if (!mEdgeGlowLeft.isFinished()) { mEdgeGlowLeft.onRelease(); } } if (pulledToY < 0) { mEdgeGlowTop.onPull((float) deltaY / getHeight()); if (!mEdgeGlowBottom.isFinished()) { mEdgeGlowBottom.onRelease(); } } else if (pulledToY > verticalRange) { mEdgeGlowBottom.onPull((float) deltaY / getHeight()); if (!mEdgeGlowTop.isFinished()) { mEdgeGlowTop.onRelease(); } } if (mEdgeGlowLeft != null && (!mEdgeGlowLeft.isFinished() || !mEdgeGlowRight.isFinished() || !mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished())) { ViewCompat.postInvalidateOnAnimation(this); } } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocityX = (int) velocityTracker.getXVelocity(mActivePointerId); int initialVelocityY = (int) velocityTracker.getYVelocity(mActivePointerId); if (getChildCount() > 0) { if (Math.abs(initialVelocityX) > mMinimumVelocity || Math.abs(initialVelocityY) > mMinimumVelocity) { fling(-initialVelocityX, -initialVelocityY); } else { if (mScroller.springBack(getScrollX(), getScrollY(), 0, getHorizontalScrollRange(), 0, getVerticalScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } } } mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged && getChildCount() > 0) { if (mScroller.springBack(getScrollX(), getScrollY(), 0, getHorizontalScrollRange(), 0, getVerticalScrollRange())) { ViewCompat.postInvalidateOnAnimation(this); } mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEvent.ACTION_POINTER_DOWN: { final int index = ev.getActionIndex(); mLastMotionX = (int) ev.getX(index); mLastMotionY = (int) ev.getY(index); mActivePointerId = ev.getPointerId(index); break; } case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); final int index = ev.findPointerIndex(mActivePointerId); mLastMotionX = (int) ev.getX(index); mLastMotionY = (int) ev.getY(index); break; } return true; }
From source file:com.juick.android.MessagesFragment.java
public Boolean maybeInterceptTouchEventFromActivity(MotionEvent event) { if (rightScrollBound == 0) { Log.w("JAGP", "rightScrollBound == 0"); return null; }//w w w . j a v a2 s. c o m if (getActivity() == null || true) return null; int action = event.getAction(); int actionMasked = event.getActionMasked(); if (fragInParent == null) fragInParent = getActivity().findViewById(R.id.messagesfragment); if (action == MotionEvent.ACTION_DOWN || actionMasked == MotionEvent.ACTION_POINTER_DOWN) { if (mScrollState == SCROLL_STATE_IDLE && fragInParent.getAnimation() == null) { if (!canStartScroll(event)) { mIsUnableToDrag = true; return null; } if (event.getPointerCount() == 1) { Log.w("JAGP", "action_down 1"); navigationOpenMode = fragInParent.getLeft() > 0; mLastMotionX = mInitialMotionX = event.getX(); mLastMotionY = event.getY(); currentScrollX = 0; mActivePointerId = MotionEventCompat.getPointerId(event, 0); mIsBeingDragged = false; mIsUnableToDrag = false; } else { Log.w("JAGP", "action_down 2"); if (mIsBeingDragged) { if (!navigationOpenMode) { Log.w("JAGP", "action_down 3"); setScrollState(SCROLL_STATE_IDLE); scrollToX(0, 500); } } mIsUnableToDrag = true; } } else { Log.w("JAGP", "!(mScrollState == SCROLL_STATE_IDLE && fragInParent.getAnimation() == null)"); } } if (action == MotionEvent.ACTION_UP || actionMasked == MotionEvent.ACTION_POINTER_UP) { if (mIsUnableToDrag) return null; if (mIsBeingDragged) { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. return null; } int pointerIndex = MotionEventCompat.findPointerIndex(event, activePointerId); if (pointerIndex == event.getActionIndex()) { if (!navigationOpenMode) { // commenting needed. if (lastToXDelta != null) { if (Math.abs(lastToXDelta) < rightScrollBound / 2) { Log.w("JAGP", "action_up 1"); setScrollState(SCROLL_STATE_SETTLING); scrollToX(0, 500); } else { Log.w("JAGP", "action_up 2"); setScrollState(SCROLL_STATE_SETTLING); scrollToX((int) -rightScrollBound, 200); handler.postDelayed(new Runnable() { @Override public void run() { Log.w("JAGP", "action_up 3"); ((MainActivity) getActivity()).openNavigationMenu(false); lastToXDelta = 0; fragInParent.clearAnimation(); } }, 200); } } } else { Log.w("JAGP", "action_up 4"); mIsBeingDragged = false; setScrollState(SCROLL_STATE_SETTLING); scrollToX((int) rightScrollBound, 200); mActivePointerId = INVALID_POINTER; handler.postDelayed(new Runnable() { @Override public void run() { Log.w("JAGP", "action_up 5"); ((MainActivity) getActivity()).closeNavigationMenu(false, true); lastToXDelta = 0; fragInParent.clearAnimation(); } }, 200); } return null; } } } if (action == MotionEvent.ACTION_MOVE) { if (mIsUnableToDrag) return null; if (mScrollState == SCROLL_STATE_SETTLING) return null; /* * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check * whether the user has moved far enough from his original down touch. */ /* * Locally do absolute value. mLastMotionY is set to the y value * of the down event. */ MotionEvent ev = event; final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. return null; } int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); float x = MotionEventCompat.getX(ev, pointerIndex); float dx = x - mLastMotionX; float xDiff = Math.abs(dx); float yDiff = Math.abs(MotionEventCompat.getY(ev, pointerIndex) - mLastMotionY); if (!mIsBeingDragged) { if (isListAnyPressed()) { //Log.w("JAGP","action_move 1"); mIsUnableToDrag = true; } else if (xDiff > mTouchSlop && xDiff > yDiff) { mIsBeingDragged = true; setScrollState(SCROLL_STATE_DRAGGING); mLastMotionX = x; //Log.w("JAGP","action_move 2"); return null; } else { if (yDiff > mTouchSlop) { // The finger has moved enough in the vertical // direction to be counted as a drag... abort // any attempt to drag horizontally, to work correctly // with children that have scrolling containers. //Log.w("JAGP","action_move 3"); mIsUnableToDrag = true; } } } if (mIsBeingDragged) { //Log.w("JAGP","action_move 4"); // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = mLastMotionX - x; mLastMotionX = x; float oldScrollX = getScrollX(); float scrollX = oldScrollX + deltaX; final int width = getListView().getWidth(); final int widthWithMargin = width; final float leftBound = -widthWithMargin; if (navigationOpenMode) { if (scrollX < 0) { scrollX = 0; } else if (scrollX > rightScrollBound) { // prevent too much to left scrollX = rightScrollBound; } } else { if (scrollX > 0) { scrollX = 0; } else if (scrollX > rightScrollBound) { scrollX = rightScrollBound; } } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollToX((int) scrollX, 1); return null; } } return null; }
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.j a v a2s . c om*/ /* 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:jackson.com.slidingmenulib.MyViewDragHelper.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 w w w .j ava2 s. co m public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); final int actionIndex = ev.getActionIndex(); 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 = ev.getPointerId(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 MotionEvent.ACTION_POINTER_DOWN: { final int pointerId = ev.getPointerId(actionIndex); final float x = ev.getX(actionIndex); final float y = ev.getY(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: { if (mInitialMotionX == null || mInitialMotionY == null) break; // First to cross a touch slop over a draggable view wins. Also report edge drags. final int pointerCount = ev.getPointerCount(); for (int i = 0; i < pointerCount; i++) { final int pointerId = ev.getPointerId(i); // If pointer is invalid then skip the ACTION_MOVE. if (!isValidPointerForActionMove(pointerId)) continue; final float x = ev.getX(i); final float y = ev.getY(i); final float dx = x - mInitialMotionX[pointerId]; final float dy = y - mInitialMotionY[pointerId]; final View toCapture = findTopChildUnder((int) x, (int) y); final boolean pastSlop = toCapture != null && checkTouchSlop(toCapture, dx, dy); if (pastSlop) { // check the callback's // getView[Horizontal|Vertical]DragRange methods to know // if you can move at all along an axis, then see if it // would clamp to the same value. If you can't move at // all in every dimension with a nonzero range, bail. final int oldLeft = toCapture.getLeft(); final int targetLeft = oldLeft + (int) dx; final int newLeft = mCallback.clampViewPositionHorizontal(toCapture, targetLeft, (int) dx); final int oldTop = toCapture.getTop(); final int targetTop = oldTop + (int) dy; final int newTop = mCallback.clampViewPositionVertical(toCapture, targetTop, (int) dy); final int horizontalDragRange = mCallback.getViewHorizontalDragRange(toCapture); final int verticalDragRange = mCallback.getViewVerticalDragRange(toCapture); if ((horizontalDragRange == 0 || horizontalDragRange > 0 && newLeft == oldLeft) && (verticalDragRange == 0 || verticalDragRange > 0 && newTop == oldTop)) { break; } } reportNewEdgeDrags(dx, dy, pointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag break; } if (pastSlop && tryCaptureViewForDrag(toCapture, pointerId)) { break; } } saveLastMotion(ev); break; } case MotionEvent.ACTION_POINTER_UP: { final int pointerId = ev.getPointerId(actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { cancel(); break; } } return mDragState == STATE_DRAGGING; }
From source file:com.cw.litenote.note.Note.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { int maskedAction = event.getActionMasked(); switch (maskedAction) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: System.out.println("Note / _dispatchTouchEvent / MotionEvent.ACTION_UP / viewPager.getCurrentItem() =" + viewPager.getCurrentItem()); //1st touch to turn on UI if (picUI_touch == null) { picUI_touch = new NoteUi(act, viewPager, viewPager.getCurrentItem()); picUI_touch.tempShow_picViewUI(5000, getCurrentPictureString()); }/*from w w w . j ava2s . c om*/ //2nd touch to turn off UI else setTransientPicViewUI(); //1st touch to turn off UI (primary) if (Note_adapter.picUI_primary != null) setTransientPicViewUI(); break; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_CANCEL: break; } return super.dispatchTouchEvent(event); }