Exemplo n.º 1
0
  @Override
  public void onDrag(float dx, float dy) {

    DraweeView<GenericDraweeHierarchy> draweeView = getDraweeView();

    if (draweeView != null && !mScaleDragDetector.isScaling()) {
      mMatrix.postTranslate(dx, dy);
      checkMatrixAndInvalidate();

      ViewParent parent = draweeView.getParent();
      if (parent == null) {
        return;
      }

      if (mAllowParentInterceptOnEdge
          && !mScaleDragDetector.isScaling()
          && !mBlockParentIntercept) {
        if (mScrollEdge == EDGE_BOTH
            || (mScrollEdge == EDGE_LEFT && dx >= 1f)
            || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
          parent.requestDisallowInterceptTouchEvent(false);
        }
      } else {
        parent.requestDisallowInterceptTouchEvent(true);
      }
    }
  }
Exemplo n.º 2
0
  @Override
  public void onDrag(float dx, float dy) {
    if (mScaleDragDetector.isScaling()) {
      return; // Do not drag if we are already scaling
    }

    if (DEBUG) {
      LogManager.getLogger().d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy));
    }

    ImageView imageView = getImageView();
    mSuppMatrix.postTranslate(dx, dy);
    checkAndDisplayMatrix();

    /**
     * Here we decide whether to let the ImageView's parent to start taking over the touch event.
     *
     * <p>First we check whether this function is enabled. We never want the parent to take over if
     * we're scaling. We then check the edge we're on, and the direction of the scroll (i.e. if
     * we're pulling against the edge, aka 'overscrolling', let the parent take over).
     */
    ViewParent parent = imageView.getParent();
    if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
      if (mScrollEdge == EDGE_BOTH
          || (mScrollEdge == EDGE_LEFT && dx >= 1f)
          || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
        if (null != parent) parent.requestDisallowInterceptTouchEvent(false);
      }
    } else {
      if (null != parent) {
        parent.requestDisallowInterceptTouchEvent(true);
      }
    }
  }
Exemplo n.º 3
0
 public boolean onTouchEvent(MotionEvent ev) {
   int action = ev.getActionMasked();
   ViewParent parent = getParent(); // LinearLayout
   gestureDetector.onTouchEvent(ev);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       this.mDragHelper.processTouchEvent(ev);
       parent.requestDisallowInterceptTouchEvent(true);
       sX = ev.getRawX();
       sY = ev.getRawY();
       return true;
     case MotionEvent.ACTION_MOVE:
       float distanceX = ev.getRawX() - sX;
       float distanceY = ev.getRawY() - sY;
       sX = ev.getRawX();
       sY = ev.getRawY();
       float angle = Math.abs(distanceY / distanceX);
       angle = (float) Math.toDegrees(Math.atan(angle));
       if (angle > 30) {
         parent.requestDisallowInterceptTouchEvent(false);
         return false;
       }
       parent.requestDisallowInterceptTouchEvent(true);
       mDragHelper.processTouchEvent(ev);
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
     default:
       parent.requestDisallowInterceptTouchEvent(true);
       mDragHelper.processTouchEvent(ev);
   }
   return true; // 必须返回true,表示已经正确处理touch事件,才能继续后续的拖动*/
 }
  @Override
  public final boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      ViewParent parent = v.getParent();
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (null != parent) parent.requestDisallowInterceptTouchEvent(true);
          else Log.i(LOG_TAG, "onTouch getParent() returned null");

          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }

      if (!handled && null != parent) {
        parent.requestDisallowInterceptTouchEvent(false);
      }

      // Finally, try the Scale/Drag detector
      if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
Exemplo n.º 5
0
 /**
  * 通知父类不要拦截touch事件 Tries to claim the user's drag motion, and requests disallowing any ancestors
  * from stealing events in the drag.
  */
 private void attemptClaimDrag() {
   mParent = getParent();
   if (mParent != null) {
     // 通知父类不要拦截touch事件
     mParent.requestDisallowInterceptTouchEvent(true);
   }
 }
  /**
   * @param arg0
   * @return
   */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    ViewParent viewParent = getParent();

    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        viewParent.requestDisallowInterceptTouchEvent(true);
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        viewParent.requestDisallowInterceptTouchEvent(false);
        break;
    }
    return super.onTouchEvent(event);
  }
Exemplo n.º 7
0
  @SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      ViewParent parent = v.getParent();
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (null != parent) {
            parent.requestDisallowInterceptTouchEvent(true);
          } else {
            LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
          }

          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Try the Scale/Drag detector
      if (null != mScaleDragDetector) {
        boolean wasScaling = mScaleDragDetector.isScaling();
        boolean wasDragging = mScaleDragDetector.isDragging();

        handled = mScaleDragDetector.onTouchEvent(ev);

        boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
        boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

        mBlockParentIntercept = didntScale && didntDrag;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
Exemplo n.º 8
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
      ViewParent p = getParent();
      if (p != null) p.requestDisallowInterceptTouchEvent(true);
    }

    return false;
  }
 @Override
 public boolean onInterceptTouchEvent(MotionEvent event) {
   // FIXME: 应该只反拦截水平方向的手式
   ViewParent parent = getParent();
   if (parent != null) {
     parent.requestDisallowInterceptTouchEvent(true);
   }
   return super.onInterceptTouchEvent(event);
 }
Exemplo n.º 10
0
  @Override
  public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
    switch (ev.getAction()) {
      case MotionEvent.ACTION_MOVE:
        float deltaX = prevX - ev.getX();

        if (!drag && Math.abs(deltaX) > mTouchSlop) {
          final ViewParent parent = getParent();
          if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
          }
          drag = true;
          if (deltaX > 0) {
            deltaX -= mTouchSlop;
          } else {
            deltaX += mTouchSlop;
          }
        }
        if (drag) {
          final int oldX = getScrollX();
          final int range = getScrollRange();
          boolean canOverscroll =
              overscrollMode == OVER_SCROLL_ALWAYS
                  || (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);

          if (canOverscroll) {
            float pulledToY = oldX + deltaX;
            if (pulledToY < 0) {
              leftGlow.onPull(deltaX / getWidth(), 1.f - ev.getY() / getHeight());
              if (!rightGlow.isFinished()) rightGlow.onRelease();
            } else if (pulledToY > range) {
              rightGlow.onPull(deltaX / getWidth(), ev.getY() / getHeight());
              if (!leftGlow.isFinished()) leftGlow.onRelease();
            }
            if (leftGlow != null && (!leftGlow.isFinished() || !rightGlow.isFinished()))
              postInvalidate();
          }
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (drag) {
          drag = false;

          if (leftGlow != null) {
            leftGlow.onRelease();
            rightGlow.onRelease();
          }
        }
        break;
    }
    prevX = ev.getX();

    return super.dispatchTouchEvent(ev);
  }
Exemplo n.º 11
0
  private void requestParentTouchRecursive(
      @NonNull ViewParent argThisParent, boolean argDisallowTouch) {
    argThisParent.requestDisallowInterceptTouchEvent(argDisallowTouch);

    ViewParent nextParent = argThisParent.getParent();

    if (nextParent != null) {
      // Log.d("PlayerSeekbar", nextParent.toString() + " -> " + argDisallowTouch);
      requestParentTouchRecursive(nextParent, argDisallowTouch);
    }
  }
Exemplo n.º 12
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          ViewParent parent = v.getParent();
          if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
          }
          cancelFling();
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          ViewParent parent = v.getParent();
          if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(false);
          }
        }
        break;
    }

    boolean wasScaling = mScaleDragDetector.isScaling();
    boolean wasDragging = mScaleDragDetector.isDragging();

    boolean handled = mScaleDragDetector.onTouchEvent(event);

    boolean noScale = !wasScaling && !mScaleDragDetector.isScaling();
    boolean noDrag = !wasDragging && !mScaleDragDetector.isDragging();
    mBlockParentIntercept = noScale && noDrag;

    if (mGestureDetector.onTouchEvent(event)) {
      handled = true;
    }

    return handled;
  }
  @Override
  public void setZoomable(boolean zoomable) {
    mZoomEnabled = zoomable;
    update();

    View v = getImageView();

    if (!zoomable && v != null) {
      ViewParent parent = v.getParent();
      if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(false);
      }
    }
  }
Exemplo n.º 14
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int action = event.getAction();
   float x = event.getX();
   float y = event.getY();
   float deltaX = Math.abs(x - mFirstDownX);
   float deltaY = Math.abs(y - mFirstDownY);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       ViewParent mParent = getParent();
       if (mParent != null) {
         // 通知父控件不要拦截本view的触摸事件
         mParent.requestDisallowInterceptTouchEvent(true);
       }
       mFirstDownX = x;
       mFirstDownY = y;
       bmCurBtnPic = bmBtnPressed;
       startBtnPos = mChecked ? onBtnPos : offBtnPos;
       break;
     case MotionEvent.ACTION_MOVE:
       float time = event.getEventTime() - event.getDownTime();
       curBtnPos = startBtnPos + event.getX() - mFirstDownX;
       if (curBtnPos >= onBtnPos) {
         curBtnPos = onBtnPos;
       }
       if (curBtnPos <= offBtnPos) {
         curBtnPos = offBtnPos;
       }
       mTurningOn = curBtnPos > bgWidth / 2 - btnWidth / 2;
       break;
     case MotionEvent.ACTION_UP:
       bmCurBtnPic = bmBtnNormal;
       time = event.getEventTime() - event.getDownTime();
       if (deltaY < mTouchSlop && deltaX < mTouchSlop && time < mClickTimeout) {
         if (mPerformClick == null) {
           mPerformClick = new PerformClick();
         }
         if (!post(mPerformClick)) {
           performClick();
         }
       } else {
         startAnimation(mTurningOn);
       }
       break;
   }
   invalidate();
   return isEnabled();
 }
  private boolean touchEvent(MotionEvent ev) {
    initVelocityTrackerIfNotExists();
    mVelocityTracker.addMovement(ev);

    final int action = ev.getAction();

    switch (action & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        {
          if (getChildCount() == 0 || !inScrollArea(ev)) {
            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();
          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);
        int deltaX = mLastMotionX - x;
        if (!mIsBeingDragged && Math.abs(deltaX) > mTouchSlop) {
          final ViewParent parent = getParent();
          if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
          }
          mIsBeingDragged = true;
          if (deltaX > 0) {
            deltaX -= mTouchSlop;
          } else {
            deltaX += mTouchSlop;
          }
        }
        if (mIsBeingDragged) {
          // Scroll to follow the motion event
          mLastMotionX = x;

          final int oldX = getScrollX();
          final int oldY = getScrollY();
          final int range = getScrollRange();
          final int overscrollMode = getOverScrollMode();
          final boolean canOverscroll =
              overscrollMode == OVER_SCROLL_ALWAYS
                  || (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);

          if (overScrollBy(deltaX, 0, getScrollX(), 0, range, 0, mOverscrollDistance, 0, true)) {
            // Break our velocity if we hit a scroll barrier.
            mVelocityTracker.clear();
          }
          onScrollChanged(getScrollX(), getScrollY(), oldX, oldY);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
          final VelocityTracker velocityTracker = mVelocityTracker;
          velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
          int initialVelocity = (int) velocityTracker.getXVelocity(mActivePointerId);

          if (getChildCount() > 0) {
            if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
              fling(-initialVelocity);
            } else {
              int finalX = getScrollX();
              finalX = getScrollXFromFinalX(finalX);
              if (mScroller.springBack(getScrollX(), getScrollY(), finalX, finalX, 0, 0)) {
                postInvalidateOnAnimation();
              }
            }
          }

          mActivePointerId = INVALID_POINTER;
          mIsBeingDragged = false;
          recycleVelocityTracker();
        }
        break;
      case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged && getChildCount() > 0) {
          if (mScroller.springBack(getScrollX(), getScrollY(), 0, getScrollRange(), 0, 0)) {
            postInvalidateOnAnimation();
          }
          mActivePointerId = INVALID_POINTER;
          mIsBeingDragged = false;
          recycleVelocityTracker();
        }
        break;
      case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }
    return true;
  }
Exemplo n.º 16
0
 private void setParentDisallowInterceptTouchEvent(boolean flag) {
   for (ViewParent viewParent : viewParents) {
     viewParent.requestDisallowInterceptTouchEvent(flag);
   }
 }
Exemplo n.º 17
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float v = (value - min) / (max - min);
    float v2 = (value2 - min) / (max - min);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      int thumbX =
          (int)
              (v * (getWidth() - getPaddingLeft() - getPaddingRight() - thumbRadius * 2)
                  + getPaddingLeft()
                  + thumbRadius);
      int thumbX2 =
          (int)
              (v2 * (getWidth() - getPaddingLeft() - getPaddingRight() - thumbRadius2 * 2)
                  + getPaddingLeft()
                  + thumbRadius2);
      if (Math.abs(event.getX() - thumbX) < Math.abs(event.getX() - thumbX2)) {
        draggedThumb = 1;
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS_DRAGGED);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      } else {
        draggedThumb = 2;
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius2, THUMB_RADIUS_DRAGGED);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius2 = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      }
      ViewParent parent = getParent();
      if (parent != null) parent.requestDisallowInterceptTouchEvent(true);
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL
        || event.getAction() == MotionEvent.ACTION_UP) {
      if (draggedThumb == 1) {
        if (style == Style.Discrete) {
          float val = (float) Math.floor((value - min + step / 2) / step) * step + min;
          if (valueAnimator != null) valueAnimator.cancel();
          valueAnimator = ValueAnimator.ofFloat(value, val);
          valueAnimator.setDuration(200);
          valueAnimator.setInterpolator(interpolator);
          valueAnimator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                  value = (float) animation.getAnimatedValue();
                  int thumbX =
                      (int)
                          ((value - min)
                                  / (max - min)
                                  * (getWidth() - getPaddingLeft() - getPaddingRight())
                              + getPaddingLeft());
                  int thumbY = getHeight() / 2;
                  int radius = rippleDrawable.getRadius();
                  rippleDrawable.setBounds(
                      thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                  postInvalidate();
                }
              });
          valueAnimator.start();
        }
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      } else {
        if (style == Style.Discrete) {
          float val2 = (float) Math.floor((value2 - min + step / 2) / step) * step + min;
          if (valueAnimator != null) valueAnimator.cancel();
          valueAnimator = ValueAnimator.ofFloat(value2, val2);
          valueAnimator.setDuration(200);
          valueAnimator.setInterpolator(interpolator);
          valueAnimator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                  value2 = (float) animation.getAnimatedValue();
                  int thumbX =
                      (int)
                          ((value2 - min)
                                  / (max - min)
                                  * (getWidth() - getPaddingLeft() - getPaddingRight())
                              + getPaddingLeft());
                  int thumbY = getHeight() / 2;
                  int radius = rippleDrawable.getRadius();
                  rippleDrawable.setBounds(
                      thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                  postInvalidate();
                }
              });
          valueAnimator.start();
        }
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius2, THUMB_RADIUS);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius2 = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      }
      draggedThumb = -1;
      ViewParent parent = getParent();
      if (parent != null) parent.requestDisallowInterceptTouchEvent(false);
    }

    if (draggedThumb == 1) {
      v = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
      v = Math.max(0, Math.min(v, 1));
    } else if (draggedThumb == 2) {
      v2 = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
      v2 = Math.max(0, Math.min(v2, 1));
    }

    if (v > v2) {
      draggedThumb = 3 - draggedThumb;
      float t = v;
      v = v2;
      v2 = t;
    }
    float newValue = v * (max - min) + min;
    float newValue2 = v2 * (max - min) + min;

    if (rippleDrawable != null) {
      rippleDrawable.setHotspot(event.getX(), event.getY());
      int thumbY = getHeight() / 2;
      int radius = rippleDrawable.getRadius();
      if (draggedThumb == 1) {
        int thumbX =
            (int) (v * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
        rippleDrawable.setBounds(
            thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
      } else if (draggedThumb == 2) {
        int thumbX2 =
            (int) (v2 * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
        rippleDrawable.setBounds(
            thumbX2 - radius, thumbY - radius, thumbX2 + radius, thumbY + radius);
      }
    }

    postInvalidate();
    if (newValue != value && onValueChangedListener != null) {
      if (style == Style.Discrete) {
        int sv = stepValue(newValue);
        int sv2 = stepValue(newValue2);
        if (stepValue(value) != sv || stepValue(value2) != sv2)
          onValueChangedListener.onValueChanged(this, sv, sv2);
      } else {
        onValueChangedListener.onValueChanged(this, newValue, newValue2);
      }
      value = newValue;
    }
    super.onTouchEvent(event);
    return true;
  }
Exemplo n.º 18
0
  public boolean onInterceptTouchEvent(MotionEvent var1) {
    boolean var4 = true;
    int var2 = var1.getAction();
    if (var2 == 2 && this.mIsBeingDragged) {
      return true;
    } else if (this.getScrollY() == 0 && !ViewCompat.canScrollVertically(this, 1)) {
      return false;
    } else {
      switch (var2 & 255) {
        case 0:
          var2 = (int) var1.getY();
          if (!this.inChild((int) var1.getX(), var2)) {
            this.mIsBeingDragged = false;
            this.recycleVelocityTracker();
          } else {
            this.mLastMotionY = var2;
            this.mActivePointerId = MotionEventCompat.getPointerId(var1, 0);
            this.initOrResetVelocityTracker();
            this.mVelocityTracker.addMovement(var1);
            if (this.mScroller.isFinished()) {
              var4 = false;
            }

            this.mIsBeingDragged = var4;
            this.startNestedScroll(2);
          }
          break;
        case 1:
        case 3:
          this.mIsBeingDragged = false;
          this.mActivePointerId = -1;
          this.recycleVelocityTracker();
          this.stopNestedScroll();
          break;
        case 2:
          var2 = this.mActivePointerId;
          if (var2 != -1) {
            int var3 = MotionEventCompat.findPointerIndex(var1, var2);
            if (var3 == -1) {
              Log.e("NestedScrollView", "Invalid pointerId=" + var2 + " in onInterceptTouchEvent");
            } else {
              var2 = (int) MotionEventCompat.getY(var1, var3);
              if (Math.abs(var2 - this.mLastMotionY) > this.mTouchSlop
                  && (this.getNestedScrollAxes() & 2) == 0) {
                this.mIsBeingDragged = true;
                this.mLastMotionY = var2;
                this.initVelocityTrackerIfNotExists();
                this.mVelocityTracker.addMovement(var1);
                this.mNestedYOffset = 0;
                ViewParent var5 = this.getParent();
                if (var5 != null) {
                  var5.requestDisallowInterceptTouchEvent(true);
                }
              }
            }
          }
        case 4:
        case 5:
        default:
          break;
        case 6:
          this.onSecondaryPointerUp(var1);
      }

      return this.mIsBeingDragged;
    }
  }
Exemplo n.º 19
0
 private void attemptClaimDrag() {
   ViewParent parent = getParent();
   if (parent != null) {
     parent.requestDisallowInterceptTouchEvent(true);
   }
 }
Exemplo n.º 20
0
 /** enables intercept touchevents */
 public void enableScroll() {
   ViewParent parent = getParent();
   if (parent != null) parent.requestDisallowInterceptTouchEvent(false);
 }
Exemplo n.º 21
0
  public boolean onTouchEvent(MotionEvent var1) {
    this.initVelocityTrackerIfNotExists();
    MotionEvent var9 = MotionEvent.obtain(var1);
    int var2 = MotionEventCompat.getActionMasked(var1);
    if (var2 == 0) {
      this.mNestedYOffset = 0;
    }

    var9.offsetLocation(0.0F, (float) this.mNestedYOffset);
    ViewParent var10;
    switch (var2) {
      case 0:
        if (this.getChildCount() == 0) {
          return false;
        }

        boolean var8;
        if (!this.mScroller.isFinished()) {
          var8 = true;
        } else {
          var8 = false;
        }

        this.mIsBeingDragged = var8;
        if (var8) {
          var10 = this.getParent();
          if (var10 != null) {
            var10.requestDisallowInterceptTouchEvent(true);
          }
        }

        if (!this.mScroller.isFinished()) {
          this.mScroller.abortAnimation();
        }

        this.mLastMotionY = (int) var1.getY();
        this.mActivePointerId = MotionEventCompat.getPointerId(var1, 0);
        this.startNestedScroll(2);
        break;
      case 1:
        if (this.mIsBeingDragged) {
          VelocityTracker var11 = this.mVelocityTracker;
          var11.computeCurrentVelocity(1000, (float) this.mMaximumVelocity);
          var2 = (int) VelocityTrackerCompat.getYVelocity(var11, this.mActivePointerId);
          if (Math.abs(var2) > this.mMinimumVelocity) {
            this.flingWithNestedDispatch(-var2);
          }

          this.mActivePointerId = -1;
          this.endDrag();
        }
        break;
      case 2:
        int var4 = MotionEventCompat.findPointerIndex(var1, this.mActivePointerId);
        if (var4 == -1) {
          Log.e(
              "NestedScrollView",
              "Invalid pointerId=" + this.mActivePointerId + " in onTouchEvent");
        } else {
          int var5 = (int) MotionEventCompat.getY(var1, var4);
          var2 = this.mLastMotionY - var5;
          int var3 = var2;
          if (this.dispatchNestedPreScroll(0, var2, this.mScrollConsumed, this.mScrollOffset)) {
            var3 = var2 - this.mScrollConsumed[1];
            var9.offsetLocation(0.0F, (float) this.mScrollOffset[1]);
            this.mNestedYOffset += this.mScrollOffset[1];
          }

          var2 = var3;
          if (!this.mIsBeingDragged) {
            var2 = var3;
            if (Math.abs(var3) > this.mTouchSlop) {
              var10 = this.getParent();
              if (var10 != null) {
                var10.requestDisallowInterceptTouchEvent(true);
              }

              this.mIsBeingDragged = true;
              if (var3 > 0) {
                var2 = var3 - this.mTouchSlop;
              } else {
                var2 = var3 + this.mTouchSlop;
              }
            }
          }

          if (this.mIsBeingDragged) {
            this.mLastMotionY = var5 - this.mScrollOffset[1];
            int var6 = this.getScrollY();
            var5 = this.getScrollRange();
            var3 = ViewCompat.getOverScrollMode(this);
            boolean var12;
            if (var3 != 0 && (var3 != 1 || var5 <= 0)) {
              var12 = false;
            } else {
              var12 = true;
            }

            if (this.overScrollByCompat(0, var2, 0, this.getScrollY(), 0, var5, 0, 0, true)
                && !this.hasNestedScrollingParent()) {
              this.mVelocityTracker.clear();
            }

            int var7 = this.getScrollY() - var6;
            if (this.dispatchNestedScroll(0, var7, 0, var2 - var7, this.mScrollOffset)) {
              this.mLastMotionY -= this.mScrollOffset[1];
              var9.offsetLocation(0.0F, (float) this.mScrollOffset[1]);
              this.mNestedYOffset += this.mScrollOffset[1];
            } else if (var12) {
              this.ensureGlows();
              var3 = var6 + var2;
              if (var3 < 0) {
                this.mEdgeGlowTop.onPull(
                    (float) var2 / (float) this.getHeight(),
                    MotionEventCompat.getX(var1, var4) / (float) this.getWidth());
                if (!this.mEdgeGlowBottom.isFinished()) {
                  this.mEdgeGlowBottom.onRelease();
                }
              } else if (var3 > var5) {
                this.mEdgeGlowBottom.onPull(
                    (float) var2 / (float) this.getHeight(),
                    1.0F - MotionEventCompat.getX(var1, var4) / (float) this.getWidth());
                if (!this.mEdgeGlowTop.isFinished()) {
                  this.mEdgeGlowTop.onRelease();
                }
              }

              if (this.mEdgeGlowTop != null
                  && (!this.mEdgeGlowTop.isFinished() || !this.mEdgeGlowBottom.isFinished())) {
                ViewCompat.postInvalidateOnAnimation(this);
              }
            }
          }
        }
        break;
      case 3:
        if (this.mIsBeingDragged && this.getChildCount() > 0) {
          this.mActivePointerId = -1;
          this.endDrag();
        }
      case 4:
      default:
        break;
      case 5:
        var2 = MotionEventCompat.getActionIndex(var1);
        this.mLastMotionY = (int) MotionEventCompat.getY(var1, var2);
        this.mActivePointerId = MotionEventCompat.getPointerId(var1, var2);
        break;
      case 6:
        this.onSecondaryPointerUp(var1);
        this.mLastMotionY =
            (int)
                MotionEventCompat.getY(
                    var1, MotionEventCompat.findPointerIndex(var1, this.mActivePointerId));
    }

    if (this.mVelocityTracker != null) {
      this.mVelocityTracker.addMovement(var9);
    }

    var9.recycle();
    return true;
  }
Exemplo n.º 22
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabledInAdapterView() || !isEnabled()) return true;

    if (!isSwipeEnabled()) return super.onTouchEvent(event);

    int action = event.getActionMasked();
    ViewParent parent = getParent();

    gestureDetector.onTouchEvent(event);
    Status status = getOpenStatus();
    ViewGroup touching = null;
    if (status == Status.Close) {
      touching = getSurfaceView();
    } else if (status == Status.Open) {
      touching = getBottomView();
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mDragHelper.processTouchEvent(event);
        parent.requestDisallowInterceptTouchEvent(true);

        sX = event.getRawX();
        sY = event.getRawY();

        if (touching != null) touching.setPressed(true);

        return true;
      case MotionEvent.ACTION_MOVE:
        {
          if (sX == -1 || sY == -1) {
            // Trick:
            // When in nested mode, we need to send a constructed ACTION_DOWN MotionEvent to
            // mDragHelper, to help
            // it initialize itself.
            event.setAction(MotionEvent.ACTION_DOWN);
            mDragHelper.processTouchEvent(event);
            parent.requestDisallowInterceptTouchEvent(true);
            sX = event.getRawX();
            sY = event.getRawY();
            return true;
          }

          float distanceX = event.getRawX() - sX;
          float distanceY = event.getRawY() - sY;
          float angle = Math.abs(distanceY / distanceX);
          angle = (float) Math.toDegrees(Math.atan(angle));

          boolean doNothing = false;
          if (mDragEdge == DragEdge.Right) {
            boolean suitable =
                (status == Status.Open && distanceX > 0)
                    || (status == Status.Close && distanceX < 0);
            suitable = suitable || (status == Status.Middle);

            if (angle > 30 || !suitable) {
              doNothing = true;
            }
          }

          if (mDragEdge == DragEdge.Left) {
            boolean suitable =
                (status == Status.Open && distanceX < 0)
                    || (status == Status.Close && distanceX > 0);
            suitable = suitable || status == Status.Middle;

            if (angle > 30 || !suitable) {
              doNothing = true;
            }
          }

          if (mDragEdge == DragEdge.Top) {
            boolean suitable =
                (status == Status.Open && distanceY < 0)
                    || (status == Status.Close && distanceY > 0);
            suitable = suitable || status == Status.Middle;

            if (angle < 60 || !suitable) {
              doNothing = true;
            }
          }

          if (mDragEdge == DragEdge.Bottom) {
            boolean suitable =
                (status == Status.Open && distanceY > 0)
                    || (status == Status.Close && distanceY < 0);
            suitable = suitable || status == Status.Middle;

            if (angle < 60 || !suitable) {
              doNothing = true;
            }
          }

          if (doNothing) {
            parent.requestDisallowInterceptTouchEvent(false);
            return false;
          } else {
            if (touching != null) {
              touching.setPressed(false);
            }
            parent.requestDisallowInterceptTouchEvent(true);
            mDragHelper.processTouchEvent(event);
          }
          break;
        }
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          sX = -1;
          sY = -1;
          if (touching != null) {
            touching.setPressed(false);
          }
        }
      default:
        parent.requestDisallowInterceptTouchEvent(true);
        mDragHelper.processTouchEvent(event);
    }

    return true;
  }