Ejemplo n.º 1
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    Log.e("dispatchTouchEvent", " " + ev.getAction());
    boolean handled = false;
    mOnScrollListener.onTouch(getEmptyView(), ev);
    Log.e("dispatchTouchEvent22", " " + onMove + getEvent);
    if (onMove) handled = onTestMove(ev);

    if (getEvent) {
      Log.e("mOnItemMoveListener", " " + ev.getAction());
      handled = mOnItemMoveListener.onTouch(getEmptyView(), ev);
    } else {
      handled = mGesture.onTouchEvent(ev);
    }

    return handled;
  }
Ejemplo n.º 2
0
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
      boolean flag = false;
      if (touchListener != null) {
        flag = touchListener.onTouch(this, ev);
      }

      return flag || super.onTouchEvent(ev);
    }
Ejemplo n.º 3
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mOnTouchListener != null && mOnTouchListener.onTouch(this, ev)) {
      return true;
    }
    if (Configure.isMove) return false; // 拦截分发给子控件
    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE) && (mTouchState == TOUCH_STATE_SCROLLING)) {
      return true;
    }

    final float x = ev.getX();
    final float y = ev.getY();

    switch (action) {
      case MotionEvent.ACTION_MOVE:
        final int xDiff = (int) Math.abs(mLastMotionX - x);
        final int yDiff = (int) Math.abs(mLastMotionY - y);
        if (mTouchState == TOUCH_STATE_CHILD_SCROLL || mTouchState == TOUCH_STATE_SCROLLING) {
          break;
        }
        if (xDiff > mTouchSlop || yDiff > mTouchSlop) {
          if ((xDiff * 1f) > X_Y_SCROLL * yDiff) {
            mTouchState = TOUCH_STATE_SCROLLING;
          } else {
            mTouchState = TOUCH_STATE_CHILD_SCROLL;
          }
        }

        break;
      case MotionEvent.ACTION_DOWN:
        mLastMotionX = x;
        mLastMotionY = y;
        if (mTouchState == TOUCH_STATE_CHILD_SCROLL) {
          mTouchState = TOUCH_STATE_REST;
        } else {
          mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
        }
        break;

      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        mTouchState = TOUCH_STATE_REST;
        break;
    }
    return mTouchState == TOUCH_STATE_SCROLLING;
  }
Ejemplo n.º 4
0
 @Override
 public boolean onTouch(View view, MotionEvent motionEvent) {
   int x = (int) motionEvent.getX();
   int y = (int) motionEvent.getY();
   boolean isInnerWidth =
       (x > getWidth() - getPaddingRight() - mClearDrawable.getIntrinsicWidth());
   // && x <= getWidth() - getPaddingRight());
   boolean isInnerHeight =
       (y >= mClearDrawable.getBounds().top && y <= mClearDrawable.getBounds().bottom);
   // 当清楚按钮可见,并且点触摸在图标范围内
   if (mClearDrawable.isVisible() && isInnerWidth) {
     // 触摸释放后清楚内容
     // if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
     setError(null);
     setText("");
     // }
     return true;
   }
   return mOnTouchListener != null && mOnTouchListener.onTouch(view, motionEvent);
 }
Ejemplo n.º 5
0
  /** {@inheritDoc} */
  @Override
  public boolean dispatchTouchEvent(@NonNull MotionEvent event) {
    // Viewが表示されていなければ何もしない
    if (getVisibility() != View.VISIBLE) {
      return true;
    }

    // タッチ不能な場合は何もしない
    if (!mIsDraggable) {
      return true;
    }

    // 現在位置のキャッシュ
    mScreenTouchX = event.getRawX();
    mScreenTouchY = event.getRawY();
    final int action = event.getAction();
    // 押下
    if (action == MotionEvent.ACTION_DOWN) {
      // アニメーションのキャンセル
      cancelAnimation();
      mScreenTouchDownX = mScreenTouchX;
      mScreenTouchDownY = mScreenTouchY;
      mLocalTouchX = event.getX();
      mLocalTouchY = event.getY();
      mIsMoveAccept = false;
      setScale(SCALE_PRESSED);
      // タッチトラッキングアニメーションの開始
      mAnimationHandler.updateTouchPosition(getXByTouch(), getYByTouch());
      mAnimationHandler.removeMessages(FloatingAnimationHandler.ANIMATION_IN_TOUCH);
      mAnimationHandler.sendAnimationMessage(FloatingAnimationHandler.ANIMATION_IN_TOUCH);
      // 長押し判定の開始
      mLongPressHandler.removeMessages(LongPressHandler.LONG_PRESSED);
      mLongPressHandler.sendEmptyMessageDelayed(LongPressHandler.LONG_PRESSED, LONG_PRESS_TIMEOUT);
      // 押下処理の通過判定のための時間保持
      // mIsDraggableやgetVisibility()のフラグが押下後に変更された場合にMOVE等を処理させないようにするため
      mTouchDownTime = event.getDownTime();
    }
    // 移動
    else if (action == MotionEvent.ACTION_MOVE) {
      // 移動判定の場合は長押しの解除
      if (mIsMoveAccept) {
        mIsLongPressed = false;
        mLongPressHandler.removeMessages(LongPressHandler.LONG_PRESSED);
      }
      // 押下処理が行われていない場合は処理しない
      if (mTouchDownTime != event.getDownTime()) {
        return true;
      }
      final float moveThreshold = MOVE_THRESHOLD_DP * mMetrics.density;
      // 移動受付状態でない、かつX,Y軸ともにしきい値よりも小さい場合
      if (!mIsMoveAccept
          && Math.abs(mScreenTouchX - mScreenTouchDownX) < moveThreshold
          && Math.abs(mScreenTouchY - mScreenTouchDownY) < moveThreshold) {
        return true;
      }
      mIsMoveAccept = true;
      mAnimationHandler.updateTouchPosition(getXByTouch(), getYByTouch());
    }
    // 押上、キャンセル
    else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
      // 判定のため長押しの状態を一時的に保持
      final boolean tmpIsLongPressed = mIsLongPressed;
      // 長押しの解除
      mIsLongPressed = false;
      mLongPressHandler.removeMessages(LongPressHandler.LONG_PRESSED);
      // 押下処理が行われていない場合は処理しない
      if (mTouchDownTime != event.getDownTime()) {
        return true;
      }
      // アニメーションの削除
      mAnimationHandler.removeMessages(FloatingAnimationHandler.ANIMATION_IN_TOUCH);
      // 拡大率をもとに戻す
      setScale(SCALE_NORMAL);

      // 動かされていれば画面端に戻す
      if (mIsMoveAccept) {
        moveToEdge(true);
      }
      // 動かされていなければ、クリックイベントを発行
      else {
        if (!tmpIsLongPressed) {
          final int size = getChildCount();
          for (int i = 0; i < size; i++) {
            getChildAt(i).performClick();
          }
        }
      }
    }

    // タッチリスナを通知
    if (mOnTouchListener != null) {
      mOnTouchListener.onTouch(this, event);
    }

    return true;
  }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   // use the pie- and radarchart listener own listener
   if (mTouchEnabled && mListener != null) return mListener.onTouch(this, event);
   else return super.onTouchEvent(event);
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (mSkipCallingOnTouchListener) {
      return super.onTouchEvent(event);
    }

    if (mOnTouchListener instanceof SwipeOnTouchListener) {
      if (((SwipeOnTouchListener) mOnTouchListener).isSwiping()) {
        mSkipCallingOnTouchListener = true;
        boolean retVal = mOnTouchListener.onTouch(this, event);
        mSkipCallingOnTouchListener = false;
        return retVal || super.onTouchEvent(event);
      }
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        mDownX = (int) event.getX();
        mDownY = (int) event.getY();
        mActivePointerId = event.getPointerId(0);

        mDynamicTouchChildTouched = false;
        if (mResIdOfDynamicTouchChild != 0) {
          mIsParentHorizontalScrollContainer = false;

          int position = pointToPosition(mDownX, mDownY);
          int childNum = (position != INVALID_POSITION) ? position - getFirstVisiblePosition() : -1;
          View itemView = (childNum >= 0) ? getChildAt(childNum) : null;
          View childView =
              (itemView != null) ? itemView.findViewById(mResIdOfDynamicTouchChild) : null;
          if (childView != null) {
            final Rect childRect = getChildViewRect(this, childView);
            if (childRect.contains(mDownX, mDownY)) {
              mDynamicTouchChildTouched = true;
              getParent().requestDisallowInterceptTouchEvent(true);
            }
          }
        }

        if (mIsParentHorizontalScrollContainer) {
          // Do it now and don't wait until the user moves more than the
          // slop factor.
          getParent().requestDisallowInterceptTouchEvent(true);
        }
        break;
      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER_ID) {
          break;
        }

        int pointerIndex = event.findPointerIndex(mActivePointerId);

        mLastEventY = (int) event.getY(pointerIndex);
        mLastEventX = (int) event.getX(pointerIndex);
        int deltaY = mLastEventY - mDownY;
        int deltaX = mLastEventX - mDownX;

        if (!mCellIsMobile && mDynamicTouchChildTouched) {
          if (Math.abs(deltaY) > mSlop && Math.abs(deltaY) > Math.abs(deltaX)) {
            makeCellMobile();

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(event);
            cancelEvent.setAction(
                MotionEvent.ACTION_CANCEL
                    | (event.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            super.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
          }
        }

        if (mCellIsMobile) {
          mHoverCellCurrentBounds.offsetTo(
              mHoverCellOriginalBounds.left, mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
          mHoverCell.setBounds(mHoverCellCurrentBounds);
          invalidate();

          handleCellSwitch();

          mIsMobileScrolling = false;
          handleMobileCellScroll();
        }
        break;
      case MotionEvent.ACTION_UP:
        mDynamicTouchChildTouched = false;
        touchEventsEnded();
        break;
      case MotionEvent.ACTION_CANCEL:
        mDynamicTouchChildTouched = false;
        touchEventsCancelled();
        break;
      case MotionEvent.ACTION_POINTER_UP:
        /*
         * If a multitouch event took place and the original touch dictating
         * the movement of the hover cell has ended, then the dragging event
         * ends and the hover cell is animated to its corresponding position
         * in the listview.
         */
        pointerIndex =
            (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = event.getPointerId(pointerIndex);
        if (pointerId == mActivePointerId) {
          mDynamicTouchChildTouched = false;
          touchEventsEnded();
        }
        break;
      default:
        break;
    }

    if (mCellIsMobile) {
      return false;
    } else if (mOnTouchListener != null) {
      mSkipCallingOnTouchListener = true;
      boolean retVal = mOnTouchListener.onTouch(this, event);
      mSkipCallingOnTouchListener = false;
      if (retVal) {
        return true;
      }
    }
    return super.onTouchEvent(event);
  }
Ejemplo n.º 8
0
  public boolean onTestMove(MotionEvent event) {

    float xInit = event.getHistoricalX(0);
    float yInit = event.getHistoricalY(0);

    float xNow = event.getX();
    float yNow = event.getY();

    Rect viewRect = new Rect();
    if (!isMove) {
      for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        int left = child.getLeft();
        int right = child.getRight();
        int top = child.getTop();
        int bottom = child.getBottom();
        viewRect.set(left, top, right, bottom);
        if (viewRect.contains((int) xInit, (int) yInit)) {
          if (yNow > yInit) {

            Log.d("relache", "pass� in ");
            if (mOnItemMoveListener != null) {
              mOnItemMoveListener.onTouch(child, event);
              this.childSelected = child;
            }

            if (mOnItemClicked != null) {
              mOnItemClicked.onItemClick(
                  HorizontalListView.this,
                  child,
                  mLeftViewIndex + 1 + i,
                  mAdapter.getItemId(mLeftViewIndex + 1 + i));
            }

            isMove = true;
            return true;
          }
        }
      }
    } else {
      mOnItemMoveListener.onTouch(childSelected, event);

      if (event.getAction() == MotionEvent.ACTION_UP) {
        int left = this.getLeft();
        int right = this.getRight();
        int top = this.getTop();
        int bottom = this.getBottom();
        Rect rect = new Rect(left, top, right, bottom);

        if (!rect.contains((int) xNow, (int) yNow)) {

          if (mOnItemOutListener != null) {
            mOnItemOutListener.onTouch(this.childSelected, event);
          }
        }

        isMove = false;
        return false;
      }

      return true;
    }

    return false;
  }