コード例 #1
0
 private static boolean isTouchEventHandled(final View view, final MotionEvent event) {
   if (view instanceof RightPaneBackgroundView) return false;
   if (!(view instanceof ViewGroup)) return true;
   final MotionEvent ev = MotionEvent.obtain(event);
   final float xf = ev.getX();
   final float yf = ev.getY();
   final float scrolledXFloat = xf + view.getScrollX();
   final float scrolledYFloat = yf + view.getScrollY();
   final Rect frame = new Rect();
   final int scrolledXInt = (int) scrolledXFloat;
   final int scrolledYInt = (int) scrolledYFloat;
   final int count = ((ViewGroup) view).getChildCount();
   for (int i = count - 1; i >= 0; i--) {
     final View child = ((ViewGroup) view).getChildAt(i);
     if (child.isShown() || child.getAnimation() != null) {
       child.getHitRect(frame);
       if (frame.contains(scrolledXInt, scrolledYInt)) {
         // offset the event to the view's coordinate system
         final float xc = scrolledXFloat - child.getLeft();
         final float yc = scrolledYFloat - child.getTop();
         ev.setLocation(xc, yc);
         if (isTouchEventHandled(child, ev)) return true;
       }
     }
   }
   return false;
 }
コード例 #2
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent event) {
    if (Config.rotateScreen) {
      event.setLocation(
          (float) (getWidth() - 1) - event.getX(), (float) (getHeight() - 1) - event.getY());
    }

    return super.dispatchTouchEvent(event);
  }
 @Override
 public boolean dispatchTouchEvent(MotionEvent ev) {
   View rootView = getWindow().getDecorView();
   if (rootView.getTop() != 0) {
     // We are animating the top view, need to compensate for that in motion events.
     ev.setLocation(ev.getX(), ev.getY() - rootView.getTop());
   }
   return super.dispatchTouchEvent(ev);
 }
コード例 #4
0
ファイル: RotateLayout.java プロジェクト: szytko/OpenCamera
  @Override
  public boolean dispatchTouchEvent(MotionEvent event) {
    viewTouchPoint[0] = event.getX();
    viewTouchPoint[1] = event.getY();

    rotateMatrix.mapPoints(childTouchPoint, viewTouchPoint);
    event.setLocation(childTouchPoint[0], childTouchPoint[1]);
    return super.dispatchTouchEvent(event);
  }
コード例 #5
0
 public boolean onTouchEvent(MotionEvent motionevent) {
   if (isTouchInPinnedHeader(motionevent)) {
     motionevent.setLocation(
         motionevent.getX(),
         motionevent.getY() - (float) mPinnedHeaderOffset - (float) mNavBottom);
     return mPinnedHeaderView.dispatchTouchEvent(motionevent);
   } else {
     return super.onTouchEvent(motionevent);
   }
 }
コード例 #6
0
  /** Swaps the X and Y coordinates of your touch event. */
  private MotionEvent swapXY(MotionEvent ev) {
    float width = getWidth();
    float height = getHeight();

    float newX = (ev.getY() / height) * width;
    float newY = (ev.getX() / width) * height;

    ev.setLocation(newX, newY);

    return ev;
  }
コード例 #7
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   boolean res = false;
   float x = event.getX();
   float y = event.getY();
   for (TouchDelegate delegate : delegates) {
     event.setLocation(x, y);
     res = delegate.onTouchEvent(event) || res;
   }
   return res;
 }
コード例 #8
0
          @Override
          public boolean onTouch(View view, MotionEvent event) {
            // Work in screen coordinates.
            final float oldX = event.getX();
            final float oldY = event.getY();
            event.setLocation(event.getRawX(), event.getRawY());

            mGestureDetector.onTouchEvent(event);
            mScaleGestureDetector.onTouchEvent(event);

            switch (event.getActionMasked()) {
              case MotionEvent.ACTION_UP:
              case MotionEvent.ACTION_CANCEL:
                saveWindowParams();
                break;
            }

            // Revert to window coordinates.
            event.setLocation(oldX, oldY);
            return true;
          }
コード例 #9
0
 @Override
 public boolean dispatchTouchEvent(MotionEvent ev) {
   int barY = 80 * CommonUtil.screen_width / 480;
   if (isAnimationOpen) {
     if (ev.getY() <= barY + 15) {
       return super.dispatchTouchEvent(ev);
     }
     final int offsetY = 40 * CommonUtil.screen_width / 480;
     ev.setLocation(ev.getX(), ev.getY() - offsetY);
     return mainMenu.dispatchTouchEvent(ev);
   }
   return super.dispatchTouchEvent(ev);
 }
コード例 #10
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {

    for (int i = getChildCount() - 1; i >= 0; i--) {
      View v = getChildAt(i);
      if (v.getVisibility() != View.VISIBLE) continue;
      Matrix m = getViewMatrix(v);
      if (m != null) {
        float[] points = new float[] {ev.getX(), ev.getY()};
        RectF rect = new RectF(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());

        Matrix realM = new Matrix(m);
        realM.preTranslate(-rect.left, -rect.top);
        realM.postTranslate(rect.left, rect.top);
        realM.mapRect(rect);
        if (rect.contains((int) points[0], (int) points[1])) {
          Matrix mi = new Matrix();
          realM.invert(mi);
          if (mi != null) {
            mi.mapPoints(points);
            ev.setEdgeFlags(
                ev.getEdgeFlags() | FLAG_TRANSFORMED); // a trick to mark the event as transformed
            ev.setLocation(
                points[0], points[1]); // without the transform point the view wont receive it
            return super.dispatchTouchEvent(ev);
          }
        }
      }
    }
    Matrix m = getMyViewMatrix();
    int flag = ev.getEdgeFlags();
    if (m != null && ((flag & FLAG_TRANSFORMED) != FLAG_TRANSFORMED)) {
      float[] points = new float[] {ev.getX(), ev.getY()}; // untransformed point
      RectF rect = new RectF(getLeft(), getTop(), getRight(), getBottom()); // untransformed rect
      Matrix realM = new Matrix(m);
      realM.preTranslate(-rect.left, -rect.top);
      realM.postTranslate(rect.left, rect.top);
      realM.mapRect(rect);
      points[0] += getLeft();
      points[1] += getTop();
      if (!rect.contains(points[0], points[1]) && ev.getAction() == MotionEvent.ACTION_DOWN) {
        Log.d("FreeLayout", this + "not dispatching");
        return false;
      }
    }
    return super.dispatchTouchEvent(ev);
  }
コード例 #11
0
ファイル: CustomViewPager.java プロジェクト: tydaikho/MyManga
  private MotionEvent swapXY(MotionEvent ev) {
    if (!vertical) return ev;
    // Get display dimensions
    float displayWidth = this.getWidth();
    float displayHeight = this.getHeight();

    // Get current touch position
    float posX = ev.getX();
    float posY = ev.getY();

    // Transform (X,Y) into (Y,X) taking display dimensions into account
    float newPosX = (posY / displayHeight) * displayWidth;
    float newPosY = (1 - posX / displayWidth) * displayHeight;

    // swap the x and y coords of the touch event
    ev.setLocation(newPosX, newPosY);

    return ev;
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (mTouchInterceptionListener != null) {
      switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
          if (mIntercepting) {
            mTouchInterceptionListener.onDownMotionEvent(ev);
            duplicateTouchEventForChildren(ev);
            return true;
          }
          break;
        case MotionEvent.ACTION_MOVE:
          // ACTION_MOVE will be passed suddenly, so initialize to avoid exception.
          if (mInitialPoint == null) {
            mInitialPoint = new PointF(ev.getX(), ev.getY());
          }

          // diffX and diffY are the origin of the motion, and should be difference
          // from the position of the ACTION_DOWN event occurred.
          float diffX = ev.getX() - mInitialPoint.x;
          float diffY = ev.getY() - mInitialPoint.y;
          mIntercepting =
              mTouchInterceptionListener.shouldInterceptTouchEvent(ev, true, diffX, diffY);
          if (mIntercepting) {
            // If this layout didn't receive ACTION_DOWN motion event,
            // we should generate ACTION_DOWN event with current position.
            if (!mBeganFromDownMotionEvent) {
              mBeganFromDownMotionEvent = true;

              MotionEvent event = MotionEvent.obtainNoHistory(mPendingDownMotionEvent);
              event.setLocation(ev.getX(), ev.getY());
              mTouchInterceptionListener.onDownMotionEvent(event);

              mInitialPoint = new PointF(ev.getX(), ev.getY());
              diffX = diffY = 0;
            }

            // Children's touches should be canceled
            if (!mChildrenEventsCanceled) {
              mChildrenEventsCanceled = true;
              duplicateTouchEventForChildren(obtainMotionEvent(ev, MotionEvent.ACTION_CANCEL));
            }

            mTouchInterceptionListener.onMoveMotionEvent(ev, diffX, diffY);

            // If next mIntercepting become false,
            // then we should generate fake ACTION_DOWN event.
            // Therefore we set pending flag to true as if this is a down motion event.
            mDownMotionEventPended = true;

            // Whether or not this event is consumed by the listener,
            // assume it consumed because we declared to intercept the event.
            return true;
          } else {
            if (mDownMotionEventPended) {
              mDownMotionEventPended = false;
              MotionEvent event = MotionEvent.obtainNoHistory(mPendingDownMotionEvent);
              event.setLocation(ev.getX(), ev.getY());
              duplicateTouchEventForChildren(ev, event);
            } else {
              duplicateTouchEventForChildren(ev);
            }

            // If next mIntercepting become true,
            // then we should generate fake ACTION_DOWN event.
            // Therefore we set beganFromDownMotionEvent flag to false
            // as if we haven't received a down motion event.
            mBeganFromDownMotionEvent = false;

            // Reserve children's click cancellation here if they've already canceled
            mChildrenEventsCanceled = false;
          }
          break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          mBeganFromDownMotionEvent = false;
          if (mIntercepting) {
            mTouchInterceptionListener.onUpOrCancelMotionEvent(ev);
          }

          // Children's touches should be canceled regardless of
          // whether or not this layout intercepted the consecutive motion events.
          if (!mChildrenEventsCanceled) {
            mChildrenEventsCanceled = true;
            if (mDownMotionEventPended) {
              mDownMotionEventPended = false;
              MotionEvent event = MotionEvent.obtainNoHistory(mPendingDownMotionEvent);
              event.setLocation(ev.getX(), ev.getY());
              duplicateTouchEventForChildren(ev, event);
            } else {
              duplicateTouchEventForChildren(ev);
            }
          }
          return true;
      }
    }
    return super.onTouchEvent(ev);
  }