コード例 #1
0
 /**
  * make animation to start or end when target view was be Visible or Gone or Invisible. make
  * animation to cancel when target view be onDetachedFromWindow.
  *
  * @param animStatus
  */
 public void setAnimationStatus(AnimStatus animStatus) {
   if (mAnimators == null) {
     return;
   }
   int count = mAnimators.size();
   for (int i = 0; i < count; i++) {
     Animator animator = mAnimators.get(i);
     boolean isRunning = animator.isRunning();
     switch (animStatus) {
       case START:
         if (!isRunning) {
           animator.start();
         }
         break;
       case END:
         if (isRunning) {
           animator.end();
         }
         break;
       case CANCEL:
         if (isRunning) {
           animator.cancel();
         }
         break;
     }
   }
 }
コード例 #2
0
 public static void onDestroyActivity() {
   HashSet<Animator> animators = new HashSet<Animator>(sAnimators.keySet());
   for (Animator a : animators) {
     if (a.isRunning()) {
       a.cancel();
     }
     sAnimators.remove(a);
   }
 }
コード例 #3
0
 @Override
 public boolean isRunning() {
   final ArrayList<Animator> animators = mAnimatedVectorState.mAnimators;
   final int size = animators.size();
   for (int i = 0; i < size; i++) {
     final Animator animator = animators.get(i);
     if (animator.isRunning()) {
       return true;
     }
   }
   return false;
 }
コード例 #4
0
ファイル: ItemSlideHelper.java プロジェクト: yjwfn/SlideItem
  @Override
  public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    Log.d(TAG, "onTouchEvent: " + e.getAction());

    if (mExpandAndCollapseAnim != null && mExpandAndCollapseAnim.isRunning() || mTargetView == null)
      return;

    // 如果要响应fling事件设置将mIsDragging设为false
    if (mGestureDetector.onTouchEvent(e)) {
      mIsDragging = false;
      return;
    }

    int x = (int) e.getX();
    int y = (int) e.getY();
    int action = MotionEventCompat.getActionMasked(e);
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        // RecyclerView 不会转发这个Down事件

        break;
      case MotionEvent.ACTION_MOVE:
        int deltaX = (int) (mLastX - e.getX());
        if (mIsDragging) {
          horizontalDrag(deltaX);
        }
        mLastX = x;
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
          if (!smoothHorizontalExpandOrCollapse(0) && isCollapsed()) mTargetView = null;

          mIsDragging = false;
        }

        break;
    }
  }
コード例 #5
0
ファイル: ItemSlideHelper.java プロジェクト: yjwfn/SlideItem
  @Override
  public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    Log.d(TAG, "onInterceptTouchEvent: " + e.getAction());

    int action = MotionEventCompat.getActionMasked(e);
    int x = (int) e.getX();
    int y = (int) e.getY();

    // 如果RecyclerView滚动状态不是空闲targetView不是空
    if (rv.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) {
      if (mTargetView != null) {
        // 隐藏已经打开
        smoothHorizontalExpandOrCollapse(DEFAULT_DURATION / 2);
        mTargetView = null;
      }

      return false;
    }

    // 如果正在运行动画 ,直接拦截什么都不做
    if (mExpandAndCollapseAnim != null && mExpandAndCollapseAnim.isRunning()) {
      return true;
    }

    boolean needIntercept = false;
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(e, 0);
        mLastX = (int) e.getX();
        mLastY = (int) e.getY();

        /*
         * 如果之前有一个已经打开的项目,当此次点击事件没有发生在右侧的菜单中则返回TRUE,
         * 如果点击的是右侧菜单那么返回FALSE这样做的原因是因为菜单需要响应Onclick
         * */
        if (mTargetView != null) {
          return !inView(x, y);
        }

        // 查找需要显示菜单的view;
        mTargetView = mCallback.findTargetView(x, y);

        break;
      case MotionEvent.ACTION_MOVE:
        int deltaX = (x - mLastX);
        int deltaY = (y - mLastY);

        if (Math.abs(deltaY) > Math.abs(deltaX)) return false;

        // 如果移动距离达到要求,则拦截
        needIntercept = mIsDragging = mTargetView != null && Math.abs(deltaX) >= mTouchSlop;
        break;

      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        /*
         * 走这是因为没有发生过拦截事件
         * */
        if (isExpanded()) {

          if (inView(x, y)) {
            // 如果走这那行这个ACTION_UP的事件会发生在右侧的菜单中
            Log.d(TAG, "click item");
          } else {
            // 拦截事件,防止targetView执行onClick事件
            needIntercept = true;
          }

          // 折叠菜单
          smoothHorizontalExpandOrCollapse(DEFAULT_DURATION / 2);
        }

        mTargetView = null;
        break;
    }

    return needIntercept;
  }