@Override public boolean onTouch(View v, MotionEvent event) { builder.setLength(0); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: builder.append("down, "); break; case MotionEvent.ACTION_MOVE: builder.append("move, "); break; case MotionEvent.ACTION_CANCEL: builder.append("cancel, "); break; case MotionEvent.ACTION_UP: builder.append("up, "); break; } builder.append(event.getX()); builder.append(", "); builder.append(event.getY()); String text = builder.toString(); Log.d("TouchTest", text); textView.setText(text); return true; }
@Override public boolean dispatchTouchEvent(MotionEvent event) { //// System.out.println("flipStarted" + flipStarted); if (flipStarted) return true; // if (header.isSourceSelectMode()) { if (header.dispatchTouchEvent(event)) { return true; } // if (pageIndexView.dispatchTouchEvent(event)) { // return true; // } // } if (enlargedMode) { current.onTouchEvent(event); } switch (event.getAction()) { case MotionEvent.ACTION_UP: return current.dispatchTouchEvent(event); case MotionEvent.ACTION_MOVE: { if (!enlargedMode) onTouchEvent(event); else current.onTouchEvent(event); } } return super.dispatchTouchEvent(event); }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { super.dispatchTouchEvent(ev); boolean consumed = gesturedetector.onTouchEvent(ev); if (!consumed && ev.getAction() == MotionEvent.ACTION_DOWN) return true; else return consumed; }
public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { Toast.makeText(HandleEvent.this, "Touch Event Received", Toast.LENGTH_SHORT).show(); return true; } return false; }
@Override public boolean onTouchEvent(MotionEvent event) { //// System.out.println("flipStarted" + flipStarted); if (flipStarted) { return false; } // if (header.isSourceSelectMode()) { // header.onTouchEvent(event); // } if (enlargedMode) { current.onTouchEvent(event); } switch (event.getAction()) { case MotionEvent.ACTION_MOVE: if (event.getHistorySize() > 0 && !flipStarted) { if (GestureUtil.flipRight(event)) { lastFlipDirection = ACTION_HORIZONTAL; flipPage(false); } else if (GestureUtil.flipUp(event)) { lastFlipDirection = ACTION_VERTICAL; flipPage(false); } else if (GestureUtil.flipLeft(event)) { lastFlipDirection = ACTION_HORIZONTAL; flipPage(true); } else if (GestureUtil.flipDown(event)) { lastFlipDirection = ACTION_VERTICAL; flipPage(true); } } else { // if (header.isSourceSelectMode()) header.onTouchEvent(event); // pageIndexView.onTouchEvent(event); } break; default: break; } return true; }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentActivityScaleX = ViewHelper.getScaleX(viewActivity); if (currentActivityScaleX == 1.0f) setScaleDirectionByRawX(ev.getRawX()); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: lastActionDownX = ev.getX(); lastActionDownY = ev.getY(); isInIgnoredView = isInIgnoredView(ev) && !isOpened(); pressedState = PRESSED_DOWN; break; case MotionEvent.ACTION_MOVE: if (isInIgnoredView || isInDisableDirection(scaleDirection)) break; if (pressedState != PRESSED_DOWN && pressedState != PRESSED_MOVE_HORIZONTAL) break; int xOffset = (int) (ev.getX() - lastActionDownX); int yOffset = (int) (ev.getY() - lastActionDownY); if (pressedState == PRESSED_DOWN) { if (yOffset > 25 || yOffset < -25) { pressedState = PRESSED_MOVE_VERTICAL; break; } if (xOffset < -50 || xOffset > 50) { pressedState = PRESSED_MOVE_HORIZONTAL; ev.setAction(MotionEvent.ACTION_CANCEL); } } else if (pressedState == PRESSED_MOVE_HORIZONTAL) { if (currentActivityScaleX < 0.95) showScrollViewMenu(scrollViewMenu); float targetScale = getTargetScale(ev.getRawX()); if (mUse3D) { int angle = scaleDirection == DIRECTION_LEFT ? -ROTATE_Y_ANGLE : ROTATE_Y_ANGLE; angle *= (1 - targetScale) * 2; ViewHelper.setRotationY(viewActivity, angle); ViewHelper.setScaleX(imageViewShadow, targetScale - shadowAdjustScaleX); ViewHelper.setScaleY(imageViewShadow, targetScale - shadowAdjustScaleY); } else { ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX); ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY); } ViewHelper.setScaleX(viewActivity, targetScale); ViewHelper.setScaleY(viewActivity, targetScale); ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f); lastRawX = ev.getRawX(); return true; } break; case MotionEvent.ACTION_UP: if (isInIgnoredView) break; if (pressedState != PRESSED_MOVE_HORIZONTAL) break; pressedState = PRESSED_DONE; if (isOpened()) { if (currentActivityScaleX > 0.56f) closeMenu(); else openMenu(scaleDirection); } else { if (currentActivityScaleX < 0.94f) { openMenu(scaleDirection); } else { closeMenu(); } } break; } lastRawX = ev.getRawX(); return super.dispatchTouchEvent(ev); }
@Override public boolean onTouchEvent(MotionEvent event) { if (lockScrollWhileRefreshing && (state == State.REFRESHING || getAnimation() != null && !getAnimation().hasEnded())) { return true; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (getFirstVisiblePosition() == 0) previousY = event.getY(); else previousY = -1; break; case MotionEvent.ACTION_UP: if (previousY != -1 && (state == State.RELEASE_TO_REFRESH || getFirstVisiblePosition() == 0)) { switch (state) { case RELEASE_TO_REFRESH: setState(State.REFRESHING); bounceBackHeader(); break; case PULL_TO_REFRESH: resetHeader(); break; default: break; } } break; case MotionEvent.ACTION_MOVE: if (previousY != -1) { float y = event.getY(); float diff = y - previousY; if (diff > 0) diff /= PULL_RESISTANCE; previousY = y; int newHeaderPadding = Math.max(Math.round(headerPadding + diff), -header.getHeight()); if (newHeaderPadding != headerPadding && state != State.REFRESHING) { setHeaderPadding(newHeaderPadding); if (state == State.PULL_TO_REFRESH && headerPadding > 0) { setState(State.RELEASE_TO_REFRESH); image.clearAnimation(); image.startAnimation(flipAnimation); } else if (state == State.RELEASE_TO_REFRESH && headerPadding < 0) { setState(State.PULL_TO_REFRESH); image.clearAnimation(); image.startAnimation(reverseFlipAnimation); } return true; } } break; } return super.onTouchEvent(event); }
public boolean onTouchEvent(MotionEvent ev) { if (mapThreadRunning) return false; // no updates when download is running if (gestureDetector.onTouchEvent(ev)) return true; final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mLastTouchX = ev.getX(); mLastTouchY = ev.getY(); mActivePointerId = ev.getPointerId(0); break; } case MotionEvent.ACTION_POINTER_DOWN: { mLastTouchX2 = ev.getX(); mLastTouchY2 = ev.getY(); if (ev.getPointerCount() > 1) mActivePointerId2 = ev.getPointerId(1); break; } case MotionEvent.ACTION_MOVE: { int pointerIndex; float x = 0.0f, y = 0.0f; try { if ((mActivePointerId != INVALID_POINTER_ID) || (mActivePointerId2 != INVALID_POINTER_ID)) { pointerIndex = ev.findPointerIndex(mActivePointerId); x = ev.getX(pointerIndex); y = ev.getY(pointerIndex); } if ((mActivePointerId != INVALID_POINTER_ID) && (mActivePointerId2 != INVALID_POINTER_ID)) { double d1, d2; pointerIndex = ev.findPointerIndex(mActivePointerId2); if (pointerIndex < 0) return false; float x2 = ev.getX(pointerIndex); float y2 = ev.getY(pointerIndex); d1 = java.lang.Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); d2 = java.lang.Math.sqrt( (mLastTouchX - mLastTouchX2) * (mLastTouchX - mLastTouchX2) + (mLastTouchY - mLastTouchY2) * (mLastTouchY - mLastTouchY2)); /* if ((Math.abs(d1)>300) || (Math.abs(d2)>300)) { int i=0; i=i; }*/ if ((d1 > 0) && (d2 > 0)) { float w, h, s; s = (float) (d1 / d2); mScaleFactor *= s; matrix.postScale(s, s); w = scrWidth / 2.0f; h = scrHeight / 2.0f; matrix.postTranslate(w, h); imgOffsetX += w; imgOffsetY += h; } mLastTouchX2 = x2; mLastTouchY2 = y2; } else if (mScaleFactor == 1.0) { mScaleFactor = 1.0f; imgOffsetX += (x - mLastTouchX); imgOffsetY += (y - mLastTouchY); matrix.setTranslate(imgOffsetX, imgOffsetY); } if ((mActivePointerId != INVALID_POINTER_ID) || (mActivePointerId2 != INVALID_POINTER_ID)) { mLastTouchX = x; mLastTouchY = y; } } catch (Exception e) { // can be caused by // pointerIndex= ev.findPointerIndex(mActivePointerId); // x= ev.getX(pointerIndex); // above which seems to be a Android bug } invalidate(); break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: { breakMapThread = true; mActivePointerId = INVALID_POINTER_ID; mActivePointerId2 = INVALID_POINTER_ID; restartMap(); break; } } return true; }