/**
   * Back alphabet.
   *
   * @param isSelected 是否是选中的字母周围弹出的字母
   */
  protected void backAlphabet(boolean isSelected) {
    if (mAlphabetList.size() < POP_LIMIT_NUM) {
      return;
    }

    int halfMoveCount = (mMoveCount + 1) / 2;
    for (int i = 0; i < mAlphabetList.size(); i++) {
      ValueAnimator vaAnim = mAnimMap.get(i);
      if (vaAnim != null) {
        vaAnim.cancel();
      }
      // Back around the selected alphabet place.
      if (isSelected
          && i > mCurrentSelection - halfMoveCount
          && i < mCurrentSelection + halfMoveCount) {
        View view = getChildAt(i);

        float tX = view.getTranslationX();
        if (tX < 0f || tX > 0f) {
          doBackAnim(view);
        }
        // Back the unselected alphabet place.
      } else if (i <= mCurrentSelection - halfMoveCount || i >= mCurrentSelection + halfMoveCount) {
        View view = getChildAt(i);

        float tX = view.getTranslationX();
        if (tX < 0f || tX > 0f) {
          doBackAnim(view);
        }
      }
    }
  }
Пример #2
1
 private float determinePos(View animView, float velocity) {
   final float newPos;
   if (velocity < 0
       || (velocity == 0 && animView.getTranslationX() < 0)
       // if we use the Menu to dismiss an item in landscape, animate up
       || (velocity == 0 && animView.getTranslationX() == 0 && mSwipeDirection == Y)) {
     newPos = -getSize(animView);
   } else {
     newPos = getSize(animView);
   }
   return newPos;
 }
  private int supportGetTranslationX(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      return (int) v.getTranslationX();
    }

    return 0;
  }
  /**
   * Creates an animator that can be used for x and/or y translations. When interrupted, it sets a
   * tag to keep track of the position so that it may be continued from position.
   *
   * @param view The view being moved. This may be in the overlay for onDisappear.
   * @param values The values containing the view in the view hierarchy.
   * @param viewPosX The x screen coordinate of view
   * @param startX The start translation x of view
   * @param endX The end translation x of view
   * @param interpolator The interpolator to use with this animator.
   * @return An animator that moves from (startX, startY) to (endX, endY) unless there was a
   *     previous interruption, in which case it moves from the current position to (endX, endY).
   */
  static Animator createAnimation(
      View view,
      TransitionValues values,
      int viewPosX,
      float startX,
      float endX,
      TimeInterpolator interpolator,
      Transition transition) {
    float terminalX = view.getTranslationX();
    Integer startPosition = (Integer) values.view.getTag(R.id.transitionPosition);
    if (startPosition != null) {
      startX = startPosition - viewPosX + terminalX;
    }
    // Initial position is at translation startX, startY, so position is offset by that
    // amount
    int startPosX = viewPosX + Math.round(startX - terminalX);

    view.setTranslationX(startX);
    if (startX == endX) {
      return null;
    }
    Path path = new Path();
    path.moveTo(startX, 0);
    path.lineTo(endX, 0);
    ObjectAnimator anim =
        ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, path);

    TransitionPositionListener listener =
        new TransitionPositionListener(view, values.view, startPosX, terminalX);
    transition.addListener(listener);
    anim.addListener(listener);
    anim.addPauseListener(listener);
    anim.setInterpolator(interpolator);
    return anim;
  }
 private void doBackAnim(final View view) {
   ValueAnimator tmpAnimator =
       ObjectAnimator.ofFloat(view, "translationX", view.getTranslationX(), 0);
   tmpAnimator.setDuration(mBackAnimTime);
   tmpAnimator.setRepeatCount(0);
   tmpAnimator.start();
 }
  /** Pop alphabet */
  protected void popAlphabet() {
    if (mAlphabetList.size() < POP_LIMIT_NUM) {
      return;
    }
    backAlphabet(false); // first, back alphabet, and pop alphabet

    isPoped = true;
    changeTextColor(mCurrentSelection, false);
    isShowSelected = false;
    invalidate();

    int position;
    int halfMoveCount = (mMoveCount + 1) / 2;
    for (int i = 0; i < mMoveCount; i++) {
      position = mCurrentSelection - halfMoveCount + 1 + i;
      if (position >= 0 && position < getChildCount()) {
        View view = getChildAt(position);
        ValueAnimator tmpAnimator =
            ObjectAnimator.ofFloat(
                view,
                "translationX",
                view.getTranslationX(),
                -mMaxOffset * (float) Math.sin((i + 1) * Math.PI / (mMoveCount + 1)));
        // Math.sin((i + 1) * Math.PI / (mMoveCount + 2))区间是[0,1],如移动的字母数(mMoveCount=3),
        // 那么取sin曲线上5个点,1和5点无动画,只创建中间3点动画,值是0.7071、1.0、0.7071。
        tmpAnimator.setDuration(mPopAnimTime);
        tmpAnimator.setRepeatCount(0);
        tmpAnimator.setInterpolator(mInterpolator);
        tmpAnimator.start();
        mAnimMap.put(position, tmpAnimator);
      }
    }
  }
  /**
   * TODO: Make this work using a decent animation shadows / newer Robolectric
   *
   * @throws Exception
   */
  @Ignore
  @Test
  public void onTouchUpAction_eventWhenLeftOverscrolling_smoothScrollBackToRightEnd()
      throws Exception {

    // Arrange

    // Bring UUT to a left-overscroll state
    MotionEvent moveEvent = createShortLeftMoveEvent();

    when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
    when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);

    HorizontalOverScrollBounceEffectDecorator uut = getUUT();
    uut.onTouch(mView, moveEvent);
    reset(mView);

    // Make the view as though it's been moved by the move event
    float viewX = moveEvent.getX();
    when(mView.getTranslationX()).thenReturn(viewX);

    MotionEvent upEvent = createDefaultUpActionEvent();

    // Act

    boolean ret = uut.onTouch(mView, upEvent);

    // Assert

    assertTrue(ret);

    verify(mView, atLeastOnce()).setTranslationX(anyFloat());
  }
Пример #8
0
  /**
   * Crop the image based on the position of the view on the window. Either the View or one of its
   * ancestors might have scrolled or translated. This value should be taken into account while
   * mapping the View to the Bitmap.
   *
   * @param view The view requesting a cropped bitmap.
   */
  private Bitmap getCroppedBitmap(View view) {
    if (mBitmap == null || view == null) {
      return null;
    }

    // Get the global position of the view on the entire screen.
    Rect rect = new Rect();
    view.getGlobalVisibleRect(rect);

    // Get the activity's window position. This does an IPC call, may be expensive.
    Rect window = new Rect();
    view.getWindowVisibleDisplayFrame(window);

    // Calculate the coordinates for the cropped bitmap.
    int screenWidth = view.getContext().getResources().getDisplayMetrics().widthPixels;
    int left = mBitmap.getWidth() - screenWidth + rect.left;
    int right = mBitmap.getWidth() - screenWidth + rect.right;
    int top = rect.top - window.top;
    int bottom = rect.bottom - window.top;

    int offsetX = 0;
    int offsetY = 0;

    // Find if this view or any of its ancestors has been translated or scrolled.
    ViewParent parent;
    View curView = view;
    do {
      offsetX += (int) curView.getTranslationX() - curView.getScrollX();
      offsetY += (int) curView.getTranslationY() - curView.getScrollY();

      parent = curView.getParent();

      if (parent instanceof View) {
        curView = (View) parent;
      }

    } while (parent instanceof View);

    // Adjust the coordinates for the offset.
    left -= offsetX;
    right -= offsetX;
    top -= offsetY;
    bottom -= offsetY;

    // The either the required height may be less than the available image height or more than it.
    // If the height required is more, crop only the available portion on the image.
    int width = right - left;
    int height = (bottom > mBitmap.getHeight() ? mBitmap.getHeight() - top : bottom - top);

    // There is a chance that the view is not visible or doesn't fall within the phone's size.
    // In this case, 'rect' will have all values as '0'. Hence 'top' and 'bottom' may be negative,
    // and createBitmap() will fail.
    // The view will get a background in its next layout pass.
    try {
      return Bitmap.createBitmap(mBitmap, left, top, width, height);
    } catch (Exception e) {
      return null;
    }
  }
 private void slideBack(final View slideInView, final int downPosition, final int direction) {
   mPendingDismisses.add(new PendingDismissData(downPosition, direction, slideInView));
   slideInView.setTranslationX(slideInView.getTranslationX());
   slideInView
       .animate()
       .translationX(0)
       .alpha(1)
       .setDuration(mAnimationTime)
       .setListener(createAnimatorListener(slideInView.getHeight()));
 }
 private TransitionPositionListener(
     View movingView, View viewInHierarchy, int startX, float terminalX) {
   mMovingView = movingView;
   mViewInHierarchy = viewInHierarchy;
   mStartX = startX - Math.round(mMovingView.getTranslationX());
   mTerminalX = terminalX;
   mTransitionPosition = (Integer) mViewInHierarchy.getTag(R.id.transitionPosition);
   if (mTransitionPosition != null) {
     mViewInHierarchy.setTag(R.id.transitionPosition, null);
   }
 }
Пример #11
0
 private static int determineDuration(View animView, float newPos, float velocity) {
   int duration = MAX_ESCAPE_ANIMATION_DURATION;
   if (velocity != 0) {
     duration =
         Math.min(
             duration,
             (int) (Math.abs(newPos - animView.getTranslationX()) * 1000f / Math.abs(velocity)));
   } else {
     duration = DEFAULT_ESCAPE_ANIMATION_DURATION;
   }
   return duration;
 }
Пример #12
0
 private float getTextAlphaForOffset(View view) {
   float viewSize = getSize(view);
   final float fadeSize = ALPHA_TEXT_FADE_START * viewSize;
   float result = 1.0f;
   float pos = view.getTranslationX();
   if (pos >= 0) {
     result = 1.0f - pos / fadeSize;
   } else if (pos < 0) {
     result = 1.0f + pos / fadeSize;
   }
   return Math.max(0, result);
 }
 public Builder setX(@CoordinationMode String mode, float... x) {
   if (mode.equals(COORDINATES)) {
     objectAnimations.add(new AnimationParams.Builder(View.X, x).build());
   } else if (mode.equals(TRANSITION)) {
     addTranslation(x, view.getTranslationX());
     x = deleteZeroFromArray(x);
     objectAnimations.add(new AnimationParams.Builder(View.TRANSLATION_X, x).build());
   } else {
     throw new RuntimeException("Can't support this mode");
   }
   return this;
 }
Пример #14
0
 private float getAlphaForOffset(View view) {
   float viewSize = getSize(view);
   final float fadeSize = ALPHA_FADE_END * viewSize;
   float result = 1.0f;
   float pos = view.getTranslationX();
   if (pos >= viewSize * ALPHA_FADE_START) {
     result = 1.0f - (pos - viewSize * ALPHA_FADE_START) / fadeSize;
   } else if (pos < viewSize * (1.0f - ALPHA_FADE_START)) {
     result = 1.0f + (viewSize * ALPHA_FADE_START + pos) / fadeSize;
   }
   float minAlpha = 0.5f;
   return Math.max(minAlpha, result);
 }
Пример #15
0
  private boolean handleRowTouch(View view, MotionEvent event) {
    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = event.getPointerId(0);
        mLastDownXlat = view.getTranslationX();
        mLastDraggingView = view;
        mLastDownX = event.getRawX();

        mVelocityTracker = VelocityTracker.obtain();
        mVelocityTracker.addMovement(event);

        int idx = mViews.indexOf(mLastDraggingView);
        mSpringChain.setControlSpringIndex(idx);

        mSpringChain.getControlSpring().setCurrentValue(mLastDownXlat);
        break;
      case MotionEvent.ACTION_MOVE:
        {
          final int pointerIndex = event.findPointerIndex(mActivePointerId);
          if (pointerIndex != -1) {
            final int location[] = {0, 0};
            view.getLocationOnScreen(location);
            float x = event.getX(pointerIndex) + location[0];
            float offset = x - mLastDownX + mLastDownXlat;
            mSpringChain.getControlSpring().setCurrentValue(offset);
            mVelocityTracker.addMovement(event);
          }
          break;
        }
      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        final int pointerIndex = event.findPointerIndex(mActivePointerId);
        if (pointerIndex != -1) {
          mVelocityTracker.addMovement(event);
          mVelocityTracker.computeCurrentVelocity(1000);
          mSpringChain
              .getControlSpring()
              .setVelocity(mVelocityTracker.getXVelocity())
              .setEndValue(0);
        }
        break;
    }
    return true;
  }
  /**
   * When over-scroll has already started (to the left in this case) and suddenly the user changes
   * their mind and scrolls a bit in the other direction: <br>
   * We expect the <b>touch to still be intercepted</b> in that case, and the <b>overscroll to
   * remain in effect</b>.
   */
  @Test
  public void onTouchMoveAction_dragRightWhenLeftOverscolled_continueOverscrollingRight()
      throws Exception {

    // Arrange

    // In left & right tests we use equal ratios to avoid the effect's under-scroll handling
    final float touchDragRatioFwd = 3f;
    final float touchDragRatioBck = 3f;

    // Bring UUT to a left-overscroll state
    when(mViewAdapter.isInAbsoluteStart()).thenReturn(false);
    when(mViewAdapter.isInAbsoluteEnd()).thenReturn(true);

    HorizontalOverScrollBounceEffectDecorator uut = getUUT(touchDragRatioFwd, touchDragRatioBck);
    MotionEvent eventMoveLeft = createLongLeftMoveEvent();
    uut.onTouch(mView, eventMoveLeft);
    reset(mView);

    float startTransX =
        (eventMoveLeft.getX() - eventMoveLeft.getHistoricalX(0)) / touchDragRatioFwd;
    when(mView.getTranslationX()).thenReturn(startTransX);

    // Create the right-drag event
    MotionEvent eventMoveRight = createShortRightMoveEvent();

    // Act

    boolean ret = uut.onTouch(mView, eventMoveRight);

    // Assert

    float expectedTransX =
        startTransX
            + (eventMoveRight.getX() - eventMoveRight.getHistoricalX(0)) / touchDragRatioBck;
    verify(mView).setTranslationX(expectedTransX);
    verify(mView, never()).setTranslationY(anyFloat());
    assertTrue(ret);
  }
Пример #17
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   if (!getCursor().moveToPosition(position)) {
     // May happen if the last alarm was deleted and the cursor refreshed while the
     // list is updated.
     Log.v("couldn't move cursor to position " + position);
     return null;
   }
   View v;
   if (convertView == null) {
     v = newView(mContext, getCursor(), parent);
   } else {
     // Do a translation check to test for animation. Change this to something more
     // reliable and robust in the future.
     if (convertView.getTranslationX() != 0 || convertView.getTranslationY() != 0) {
       // view was animated, reset
       v = newView(mContext, getCursor(), parent);
     } else {
       v = convertView;
     }
   }
   bindView(v, mContext, getCursor());
   return v;
 }
Пример #18
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (mTopCard == null) {
      return false;
    }
    if (mGestureDetector.onTouchEvent(event)) {
      return true;
    }
    // Log.d("Touch Event", MotionEvent.actionToString(event.getActionMasked()) + " ");
    final int pointerIndex;
    final float x, y;
    final float dx, dy;
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mTopCard.getHitRect(childRect);

        pointerIndex = event.getActionIndex();
        x = event.getX(pointerIndex);
        y = event.getY(pointerIndex);

        if (!childRect.contains((int) x, (int) y)) {
          return false;
        }
        mLastTouchX = x;
        mLastTouchY = y;
        mActivePointerId = event.getPointerId(pointerIndex);

        float[] points = new float[] {x - mTopCard.getLeft(), y - mTopCard.getTop()};
        mTopCard.getMatrix().invert(mMatrix);
        mMatrix.mapPoints(points);
        mTopCard.setPivotX(points[0]);
        mTopCard.setPivotY(points[1]);

        break;
      case MotionEvent.ACTION_MOVE:
        pointerIndex = event.findPointerIndex(mActivePointerId);
        x = event.getX(pointerIndex);
        y = event.getY(pointerIndex);

        dx = x - mLastTouchX;
        dy = y - mLastTouchY;

        if (Math.abs(dx) > mTouchSlop || Math.abs(dy) > mTouchSlop) {
          mDragging = true;
        }

        if (!mDragging) {
          return true;
        }

        mTopCard.setTranslationX(mTopCard.getTranslationX() + dx);
        mTopCard.setTranslationY(mTopCard.getTranslationY() + dy);

        mTopCard.setRotation(40 * mTopCard.getTranslationX() / (getWidth() / 2.f));

        mLastTouchX = x;
        mLastTouchY = y;
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (!mDragging) {
          return true;
        }
        mDragging = false;
        mActivePointerId = INVALID_POINTER_ID;
        ValueAnimator animator =
            ObjectAnimator.ofPropertyValuesHolder(
                    mTopCard,
                    PropertyValuesHolder.ofFloat("translationX", 0),
                    PropertyValuesHolder.ofFloat("translationY", 0),
                    PropertyValuesHolder.ofFloat(
                        "rotation",
                        (float)
                            Math.toDegrees(
                                mRandom.nextGaussian() * DISORDERED_MAX_ROTATION_RADIANS)),
                    PropertyValuesHolder.ofFloat("pivotX", mTopCard.getWidth() / 2.f),
                    PropertyValuesHolder.ofFloat("pivotY", mTopCard.getHeight() / 2.f))
                .setDuration(250);
        animator.setInterpolator(new AccelerateInterpolator());
        animator.start();
        break;
      case MotionEvent.ACTION_POINTER_UP:
        pointerIndex = event.getActionIndex();
        final int pointerId = event.getPointerId(pointerIndex);

        if (pointerId == mActivePointerId) {
          final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
          mLastTouchX = event.getX(newPointerIndex);
          mLastTouchY = event.getY(newPointerIndex);

          mActivePointerId = event.getPointerId(newPointerIndex);
        }
        break;
    }

    return true;
  }
Пример #19
0
 public static float e(View paramView) {
   return paramView.getTranslationX();
 }
Пример #20
0
  protected boolean handlerTouch(View v, MotionEvent event) {
    // final ViewHolder holder = (ViewHolder) v.getTag();  //获取滑动时候相应的ViewHolder,以便获取button按钮
    if (viewHolder.tvDelete != null) {
      int bottomWidth = viewHolder.tvDelete.getWidth() + viewHolder.tvDelete.getWidth();
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          downX = (int) event.getRawX();
          break;
        case MotionEvent.ACTION_MOVE:
          int dx = (int) (event.getRawX() - downX);
          if (isOpen) {
            // 打开状态
            // 向右滑动
            if (dx > 0 && dx < bottomWidth) {
              v.setTranslationX(dx - bottomWidth);
              // 允许移动,阻止点击
              Log.i("BT-MusicDowningAdapter", "(dx > 0 && dx < bottomWidth");
              result = true;
            }
          } else {
            // 闭合状态
            // 向左移动
            if (dx < 0 && Math.abs(dx) < bottomWidth) {
              v.setTranslationX(dx);
              // 允许移动,阻止点击
              Log.i("BT-MusicDowningAdapter", "dx < 0 && Math.abs(dx) < bottomWidth");
              result = true;
            }
          }
          break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
          // 获取已经移动的
          float ddx = v.getTranslationX();
          // 判断打开还是关闭
          if (ddx <= 0 && ddx > -(bottomWidth / 2)) {
            Log.i("BT-MusicDowningAdapter", "ddx <= 0 && ddx > -(bottomWidth / 2)");
            // 关闭
            ObjectAnimator oa1 = ObjectAnimator.ofFloat(v, "translationX", ddx, 0).setDuration(100);
            oa1.start();
            oa1.addListener(
                new Animator.AnimatorListener() {
                  @Override
                  public void onAnimationStart(Animator animation) {}

                  @Override
                  public void onAnimationRepeat(Animator animation) {}

                  @Override
                  public void onAnimationEnd(Animator animation) {
                    isOpen = false;
                    result = false;
                  }

                  @Override
                  public void onAnimationCancel(Animator animation) {
                    isOpen = false;
                    result = false;
                  }
                });
          }
          if (ddx <= -(bottomWidth / 2) && ddx > -bottomWidth) {
            // 打开
            Log.i("BT-MusicDowningAdapter", "ddx <= -(bottomWidth / 2) && ddx > -bottomWidth");
            ObjectAnimator oa1 =
                ObjectAnimator.ofFloat(v, "translationX", ddx, -bottomWidth).setDuration(100);
            oa1.start();
            result = true;
            isOpen = true;
          }
          break;
      }
    } else {
      Log.i("BT-MusicDowningAdapter", "tvDelete=null");
    }
    return result;
  }
Пример #21
0
 public boolean onInterceptTouchEvent(MotionEvent ev) {
   final int action = ev.getAction();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       mLastY = ev.getY();
       mDragging = false;
       View view = mCallback.getChildAtPosition(ev);
       if (view instanceof SwipeableItemView) {
         mCurrView = (SwipeableItemView) view;
       } else {
         // If the touched item is not a swipeable one, clean the cache in
         // mCurrView to make sure nothing will be swiped for this action
         mCurrView = null;
       }
       mVelocityTracker.clear();
       if (mCurrView != null) {
         mCurrAnimView = mCurrView.getSwipeableView().getView();
         mCanCurrViewBeDimissed = mCallback.canChildBeDismissed(mCurrView);
         mVelocityTracker.addMovement(ev);
         mInitialTouchPosX = ev.getX();
         mInitialTouchPosY = ev.getY();
       }
       mCallback.cancelDismissCounter();
       break;
     case MotionEvent.ACTION_MOVE:
       if (mCurrView != null) {
         // Check the movement direction.
         if (mLastY >= 0 && !mDragging) {
           float currY = ev.getY();
           float currX = ev.getX();
           float deltaY = Math.abs(currY - mInitialTouchPosY);
           float deltaX = Math.abs(currX - mInitialTouchPosX);
           if (deltaY > mCurrView.getMinAllowScrollDistance() && deltaY > (FACTOR * deltaX)) {
             mLastY = ev.getY();
             mCallback.onScroll();
             return false;
           }
         }
         mVelocityTracker.addMovement(ev);
         float pos = ev.getX();
         float delta = pos - mInitialTouchPosX;
         if (Math.abs(delta) > mPagingTouchSlop) {
           mCallback.onBeginDrag(mCurrView.getSwipeableView().getView());
           mPrevView = mCallback.getLastSwipedItem();
           mDragging = true;
           mInitialTouchPosX = ev.getX() - mCurrAnimView.getTranslationX();
           mInitialTouchPosY = ev.getY();
         }
       }
       mLastY = ev.getY();
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
       mDragging = false;
       mCurrView = null;
       mCurrAnimView = null;
       mLastY = -1;
       break;
   }
   return mDragging;
 }
 public boolean a(MotionEvent paramMotionEvent)
 {
   boolean bool = false;
   switch (paramMotionEvent.getAction())
   {
   }
   for (;;)
   {
     bool = p;
     float f2;
     do
     {
       return bool;
       v = paramMotionEvent.getY();
       p = false;
       q = false;
       Object localObject = b.a(paramMotionEvent);
       if ((localObject instanceof crq)) {}
       for (localObject = (crq)localObject;; localObject = null)
       {
         r = ((crq)localObject);
         n.clear();
         if (r == null) {
           break;
         }
         if (c.containsKey(r)) {
           ((ObjectAnimator)c.get(r)).cancel();
         }
         s = r.a();
         t = b.a(r);
         n.addMovement(paramMotionEvent);
         o = paramMotionEvent.getX();
         w = paramMotionEvent.getY();
         break;
       }
       if (r == null) {
         break label384;
       }
       if ((v < 0.0F) || (p)) {
         break label307;
       }
       f2 = paramMotionEvent.getY();
       f1 = paramMotionEvent.getX();
       f2 = Math.abs(f2 - w);
       f1 = Math.abs(f1 - o);
       if ((!q) && ((f2 <= 2.0F) || (f2 <= f1 * 1.2F))) {
         break label307;
       }
       v = paramMotionEvent.getY();
     } while (f2 <= k);
     q = true;
     return false;
     label307:
     n.addMovement(paramMotionEvent);
     float f1 = paramMotionEvent.getX() - o;
     if (Math.abs(f1) > l)
     {
       b.a(r, (int)Math.signum(f1));
       p = true;
       o = (paramMotionEvent.getX() - s.getTranslationX());
       w = paramMotionEvent.getY();
     }
     label384:
     v = paramMotionEvent.getY();
     continue;
     p = false;
     r = null;
     s = null;
     v = -1.0F;
     q = false;
   }
 }
 public boolean b(MotionEvent paramMotionEvent)
 {
   if (!p) {
     return false;
   }
   n.addMovement(paramMotionEvent);
   float f1;
   float f3;
   float f2;
   switch (paramMotionEvent.getAction())
   {
   default: 
   case 2: 
   case 4: 
     do
     {
       return true;
     } while (r == null);
     f1 = paramMotionEvent.getX() - o;
     if (Math.abs(f1) < j) {
       return true;
     }
     if (!b.a(r))
     {
       f3 = b(s);
       f2 = 0.05F * f3;
       if (Math.abs(f1) >= f3) {
         if (f1 > 0.0F) {
           f1 = f2;
         }
       }
     }
     break;
   }
   for (;;)
   {
     label135:
     b.b(r, (int)Math.signum(f1));
     paramMotionEvent = s;
     if (m == 0) {
       paramMotionEvent.setTranslationX(f1);
     }
     for (;;)
     {
       a(r.a());
       break;
       f1 = -f2;
       break label135;
       f1 = f2 * (float)Math.sin(f1 / f3 * 1.5707963267948966D);
       break label135;
       paramMotionEvent.setTranslationY(f1);
     }
     if (r == null) {
       break;
     }
     f1 = h;
     f2 = u;
     n.computeCurrentVelocity(1000, f1 * f2);
     f3 = e;
     float f4 = u;
     paramMotionEvent = n;
     label277:
     label294:
     label333:
     int i2;
     label367:
     int i3;
     if (m == 0)
     {
       f1 = paramMotionEvent.getXVelocity();
       paramMotionEvent = n;
       if (m != 0) {
         break label651;
       }
       f2 = paramMotionEvent.getYVelocity();
       float f5 = Math.abs(s.getTranslationX());
       float f6 = b(s);
       if (f5 <= 0.4D * f6) {
         break label659;
       }
       i1 = 1;
       if ((Math.abs(f1) <= f3 * f4) || (Math.abs(f1) <= Math.abs(f2))) {
         break label677;
       }
       if (f1 <= 0.0F) {
         break label665;
       }
       i2 = 1;
       if (s.getTranslationX() <= 0.0F) {
         break label671;
       }
       i3 = 1;
       label382:
       if ((i2 != i3) || (f5 <= f6 * 0.05D)) {
         break label677;
       }
       i2 = 1;
       label406:
       if ((!b.a(r)) || ((i2 == 0) && (i1 == 0))) {
         break label683;
       }
       i1 = 1;
       label435:
       if (i1 == 0) {
         break label712;
       }
       paramMotionEvent = r;
       if (i2 == 0) {
         break label689;
       }
       label450:
       localView = r.a();
       if ((f1 >= 0.0F) && ((f1 != 0.0F) || (localView.getTranslationX() >= 0.0F)) && ((f1 != 0.0F) || (localView.getTranslationX() != 0.0F) || (m != 1))) {
         break label694;
       }
       f2 = -b(localView);
       label515:
       i1 = g;
       if (f1 == 0.0F) {
         break label704;
       }
     }
     label651:
     label659:
     label665:
     label671:
     label677:
     label683:
     label689:
     label694:
     label704:
     for (int i1 = Math.min(i1, (int)(Math.abs(f2 - localView.getTranslationX()) * 1000.0F / Math.abs(f1)));; i1 = f)
     {
       if ((localView != null) && (localView.isHardwareAccelerated()))
       {
         localView.setLayerType(2, null);
         localView.buildLayer();
       }
       localObjectAnimator = a(localView, f2);
       localObjectAnimator.setInterpolator(d);
       localObjectAnimator.setDuration(i1);
       localObjectAnimator.addListener(new crl(this, localView, paramMotionEvent));
       localObjectAnimator.addUpdateListener(new crm(this, localView));
       localObjectAnimator.start();
       break;
       f1 = paramMotionEvent.getYVelocity();
       break label277;
       f2 = paramMotionEvent.getXVelocity();
       break label294;
       i1 = 0;
       break label333;
       i2 = 0;
       break label367;
       i3 = 0;
       break label382;
       i2 = 0;
       break label406;
       i1 = 0;
       break label435;
       f1 = 0.0F;
       break label450;
       f2 = b(localView);
       break label515;
     }
     label712:
     paramMotionEvent = r;
     View localView = paramMotionEvent.a();
     ObjectAnimator localObjectAnimator = a(localView, 0.0F);
     localObjectAnimator.setDuration(i);
     localObjectAnimator.addUpdateListener(new crn(this, localView));
     localObjectAnimator.addListener(new cro(this, paramMotionEvent, localObjectAnimator, localView));
     localObjectAnimator.start();
     break;
   }
 }
 @Override
 public void onAnimationCancel(Animator animation) {
   mTransitionPosition = Math.round(mStartX + mMovingView.getTranslationX());
   mViewInHierarchy.setTag(R.id.transitionPosition, mTransitionPosition);
 }
Пример #25
0
  public boolean onTouchEvent(MotionEvent ev) {
    if (!mDragging) {
      return false;
    }
    mVelocityTracker.addMovement(ev);
    final int action = ev.getAction();
    switch (action) {
      case MotionEvent.ACTION_OUTSIDE:
      case MotionEvent.ACTION_MOVE:
        if (mCurrView != null) {
          float deltaX = ev.getX() - mInitialTouchPosX;
          // If the swipe started in the dead region, ignore it.
          if (mInitialTouchPosX <= (DEAD_REGION_FOR_SWIPE * mDensityScale)) {
            return true;
          }
          // If the user has gone vertical and not gone horizontalish AT
          // LEAST minBeforeLock, switch to scroll. Otherwise, cancel
          // the swipe.
          float minDistance = MIN_SWIPE;
          if (Math.abs(deltaX) < minDistance) {
            // Don't start the drag until at least X distance has
            // occurred.
            return true;
          }
          // don't let items that can't be dismissed be dragged more
          // than maxScrollDistance
          if (CONSTRAIN_SWIPE && !mCallback.canChildBeDismissed(mCurrView)) {
            float size = getSize(mCurrAnimView);
            float maxScrollDistance = 0.15f * size;
            if (Math.abs(deltaX) >= size) {
              deltaX = deltaX > 0 ? maxScrollDistance : -maxScrollDistance;
            } else {
              deltaX = maxScrollDistance * (float) Math.sin((deltaX / size) * (Math.PI / 2));
            }
          }
          setTranslation(mCurrAnimView, deltaX);
          if (FADE_OUT_DURING_SWIPE && mCanCurrViewBeDimissed) {
            mCurrAnimView.setAlpha(getAlphaForOffset(mCurrAnimView));
            if (mPrevView != null) {
              // Base how much the text of the prev item is faded
              // on how far the current item has moved.
              mPrevView.setTextAlpha(getTextAlphaForOffset(mCurrAnimView));
            }
          }
          invalidateGlobalRegion(mCurrView.getSwipeableView().getView());
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (mCurrView != null) {
          float maxVelocity = MAX_DISMISS_VELOCITY * mDensityScale;
          mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, maxVelocity);
          float escapeVelocity = SWIPE_ESCAPE_VELOCITY * mDensityScale;
          float velocity = getVelocity(mVelocityTracker);
          float perpendicularVelocity = getPerpendicularVelocity(mVelocityTracker);

          // Decide whether to dismiss the current view
          // Tweak constants below as required to prevent erroneous
          // swipe/dismiss
          float translation = Math.abs(mCurrAnimView.getTranslationX());
          float currAnimViewSize = getSize(mCurrAnimView);
          // Long swipe = translation of .4 * width
          boolean childSwipedFarEnough =
              DISMISS_IF_SWIPED_FAR_ENOUGH && translation > 0.4 * currAnimViewSize;
          // Fast swipe = > escapeVelocity and translation of .1 *
          // width
          boolean childSwipedFastEnough =
              (Math.abs(velocity) > escapeVelocity)
                  && (Math.abs(velocity) > Math.abs(perpendicularVelocity))
                  && (velocity > 0) == (mCurrAnimView.getTranslationX() > 0)
                  && translation > 0.05 * currAnimViewSize;
          if (LOG_SWIPE_DISMISS_VELOCITY) {
            LogUtils.v(
                TAG,
                "Swipe/Dismiss: "
                    + velocity
                    + "/"
                    + escapeVelocity
                    + "/"
                    + perpendicularVelocity
                    + ", x: "
                    + translation
                    + "/"
                    + currAnimViewSize);
          }

          boolean dismissChild =
              mCallback.canChildBeDismissed(mCurrView)
                  && (childSwipedFastEnough || childSwipedFarEnough);

          if (dismissChild) {
            dismissChild(mCurrView, childSwipedFastEnough ? velocity : 0f);
          } else {
            snapChild(mCurrView);
          }
        }
        break;
    }
    return true;
  }
 private void snapshotView(JsonWriter paramJsonWriter, View paramView) throws IOException {
   int i = paramView.getId();
   Object localObject1;
   if (-1 == i) {
     localObject1 = null;
     paramJsonWriter.beginObject();
     paramJsonWriter.name("hashCode").value(paramView.hashCode());
     paramJsonWriter.name("id").value(i);
     paramJsonWriter.name("mp_id_name").value((String) localObject1);
     localObject1 = paramView.getContentDescription();
     if (localObject1 != null) {
       break label418;
     }
     paramJsonWriter.name("contentDescription").nullValue();
     label81:
     localObject1 = paramView.getTag();
     if (localObject1 != null) {
       break label438;
     }
     paramJsonWriter.name("tag").nullValue();
   }
   Object localObject2;
   int j;
   for (; ; ) {
     paramJsonWriter.name("top").value(paramView.getTop());
     paramJsonWriter.name("left").value(paramView.getLeft());
     paramJsonWriter.name("width").value(paramView.getWidth());
     paramJsonWriter.name("height").value(paramView.getHeight());
     paramJsonWriter.name("scrollX").value(paramView.getScrollX());
     paramJsonWriter.name("scrollY").value(paramView.getScrollY());
     paramJsonWriter.name("visibility").value(paramView.getVisibility());
     float f1 = 0.0F;
     float f2 = 0.0F;
     if (Build.VERSION.SDK_INT >= 11) {
       f1 = paramView.getTranslationX();
       f2 = paramView.getTranslationY();
     }
     paramJsonWriter.name("translationX").value(f1);
     paramJsonWriter.name("translationY").value(f2);
     paramJsonWriter.name("classes");
     paramJsonWriter.beginArray();
     localObject1 = paramView.getClass();
     do {
       paramJsonWriter.value((String) this.mClassnameCache.get(localObject1));
       localObject2 = ((Class) localObject1).getSuperclass();
       if (localObject2 == Object.class) {
         break;
       }
       localObject1 = localObject2;
     } while (localObject2 != null);
     paramJsonWriter.endArray();
     addProperties(paramJsonWriter, paramView);
     localObject1 = paramView.getLayoutParams();
     if (!(localObject1 instanceof RelativeLayout.LayoutParams)) {
       break label469;
     }
     localObject1 = ((RelativeLayout.LayoutParams) localObject1).getRules();
     paramJsonWriter.name("layoutRules");
     paramJsonWriter.beginArray();
     j = localObject1.length;
     i = 0;
     while (i < j) {
       paramJsonWriter.value(localObject1[i]);
       i += 1;
     }
     localObject1 = this.mResourceIds.nameForId(i);
     break;
     label418:
     paramJsonWriter.name("contentDescription").value(((CharSequence) localObject1).toString());
     break label81;
     label438:
     if ((localObject1 instanceof CharSequence)) {
       paramJsonWriter.name("tag").value(localObject1.toString());
     }
   }
   paramJsonWriter.endArray();
   label469:
   paramJsonWriter.name("subviews");
   paramJsonWriter.beginArray();
   if ((paramView instanceof ViewGroup)) {
     localObject1 = (ViewGroup) paramView;
     j = ((ViewGroup) localObject1).getChildCount();
     i = 0;
     while (i < j) {
       localObject2 = ((ViewGroup) localObject1).getChildAt(i);
       if (localObject2 != null) {
         paramJsonWriter.value(localObject2.hashCode());
       }
       i += 1;
     }
   }
   paramJsonWriter.endArray();
   paramJsonWriter.endObject();
   if ((paramView instanceof ViewGroup)) {
     paramView = (ViewGroup) paramView;
     j = paramView.getChildCount();
     i = 0;
     while (i < j) {
       localObject1 = paramView.getChildAt(i);
       if (localObject1 != null) {
         snapshotView(paramJsonWriter, (View) localObject1);
       }
       i += 1;
     }
   }
 }
 @Override
 public void onAnimationPause(Animator animator) {
   mPausedX = mMovingView.getTranslationX();
   mMovingView.setTranslationX(mTerminalX);
 }
Пример #28
0
        @Override
        public boolean onTouch(final View v, MotionEvent event) {
          int index = event.getActionIndex();
          int pointerId = event.getPointerId(index);

          if (mSwipeSlop < 0) {
            mSwipeSlop = ViewConfiguration.get(getActivity()).getScaledTouchSlop();
          }

          v.onTouchEvent(event);

          switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
              if (mItemPressed) {
                // Multi-item swipes not handled
                return false;
              }
              mItemPressed = true;
              mDownX = event.getX();
              if (mVelocityTracker == null) {
                // Retrieve a new VelocityTracker object to watch the velocity of a motion.
                mVelocityTracker = VelocityTracker.obtain();
              } else {
                // Reset the velocity tracker back to its initial state.
                mVelocityTracker.clear();
              }
              mVelocityTracker.addMovement(event);
              break;
            case MotionEvent.ACTION_CANCEL:
              v.setAlpha(1);
              v.setTranslationX(0);
              mItemPressed = false;
              mVelocityTracker.recycle();
              mVelocityTracker = null;
              break;
            case MotionEvent.ACTION_MOVE:
              {
                mVelocityTracker.addMovement(event);
                float x = event.getX() + v.getTranslationX();
                float deltaX = x - mDownX;
                float deltaXAbs = Math.abs(deltaX);
                if (!mSwiping) {
                  if (deltaXAbs > mSwipeSlop) {
                    mSwiping = true;
                    getListView().requestDisallowInterceptTouchEvent(true);
                    mBackgroundContainer.showBackground(v.getTop(), v.getHeight());
                  }
                }
                if (mSwiping) {
                  v.setTranslationX((x - mDownX));
                  v.setAlpha(1 - deltaXAbs / v.getWidth());
                }
              }
              break;
            case MotionEvent.ACTION_UP:
              {
                // User let go - figure out whether to animate the view out, or back into place
                if (mSwiping) {
                  float x = event.getX() + v.getTranslationX();
                  float deltaX = x - mDownX;
                  float deltaXAbs = Math.abs(deltaX);
                  float fractionCovered;
                  float endX;
                  float endAlpha;
                  final boolean remove;
                  mVelocityTracker.computeCurrentVelocity(1000);
                  float velocityX =
                      Math.abs(VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId));
                  if (velocityX > 700 || deltaXAbs > v.getWidth() / 4) {
                    fractionCovered = deltaXAbs / v.getWidth();
                    endX = deltaX < 0 ? -v.getWidth() : v.getWidth();
                    endAlpha = 0;
                    remove = true;
                  } else {
                    // Not far enough - animate it back
                    fractionCovered = 1 - (deltaXAbs / v.getWidth());
                    endX = 0;
                    endAlpha = 1;
                    remove = false;
                  }
                  mVelocityTracker.clear();
                  int SWIPE_DURATION = 600;
                  long duration = (int) ((1 - fractionCovered) * SWIPE_DURATION);
                  getListView().setEnabled(false);
                  v.animate()
                      .setDuration(Math.abs(duration))
                      .alpha(endAlpha)
                      .translationX(endX)
                      .setListener(
                          new AnimatorActionListener(
                              new Runnable() {
                                @Override
                                public void run() {
                                  // Restore animated values
                                  v.setAlpha(1);
                                  v.setTranslationX(0);
                                  if (remove) {
                                    animateRemoval(getListView(), v);
                                  } else {
                                    mBackgroundContainer.hideBackground();
                                    getListView().setEnabled(true);
                                  }
                                }
                              },
                              AnimatorActionListener.ActionType.END));
                }
              }
              mItemPressed = false;
              break;
            default:
              return false;
          }
          return true;
        }
Пример #29
0
 public static float getTranslationX(View view) {
   return view.getTranslationX();
 }
Пример #30
0
 @SuppressLint("NewApi")
 private float getTranslation(View v) {
   return mSwipeDirection == X ? v.getTranslationX() : v.getTranslationY();
 }