Beispiel #1
0
 public void setPivotY(float pivotY) {
   if (NEEDS_PROXY) {
     wrap(this).setPivotY(pivotY);
   } else {
     super.setPivotY(pivotY);
   }
 }
 @Override
 protected void onTransform(View view, float position) {
   view.setPivotX(position < 0 ? 0 : view.getWidth());
   view.setPivotY(view.getHeight() / 2f);
   float scale = position < 0 ? 1f + position : 1f - position;
   view.setScaleX(scale);
   view.setScaleY(scale);
 }
 private void startAnim(View convertView) {
   convertView.setPivotX(0.0f);
   convertView.setPivotY(1.0f);
   PropertyValuesHolder x = PropertyValuesHolder.ofFloat("scaleX", 0.0f, 1.0f);
   PropertyValuesHolder y = PropertyValuesHolder.ofFloat("scaleY", 0.0f, 1.0f);
   ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(convertView, x, y);
   animator.setDuration(animTime);
   animator.start();
 }
  @Override
  protected void onTransform(View view, float position) {
    final float width = view.getWidth();
    final float rotation = ROT_MOD * position;

    view.setPivotX(width * 0.5f);
    view.setPivotY(0f);
    view.setTranslationX(0f);
    view.setRotation(rotation);
  }
 /**
  * reset the view to default status
  *
  * @param target the target
  */
 public void reset(View target) {
   target.setAlpha(1);
   target.setScaleX(1);
   target.setScaleY(1);
   target.setTranslationX(0);
   target.setTranslationY(0);
   target.setRotation(0);
   target.setRotationY(0);
   target.setRotationX(0);
   target.setPivotX(target.getMeasuredWidth() / 2.0f);
   target.setPivotY(target.getMeasuredHeight() / 2.0f);
 }
  @Override
  protected void onTransform(View view, float position) {
    final float height = view.getHeight();
    final float width = view.getWidth();
    final float scale = min(position < 0 ? 1f : Math.abs(1f - position), 0.5f);

    view.setScaleX(scale);
    view.setScaleY(scale);
    view.setPivotX(width * 0.5f);
    view.setPivotY(height * 0.5f);
    view.setTranslationX(position < 0 ? width * position : -width * position * 0.25f);
  }
 @Override
 protected void onTransform(View view, float position) {
   if (position <= 0f) {
     view.setTranslationX(0f);
     view.setScaleX(1f);
     view.setScaleY(1f);
   } else if (position <= 1f) {
     final float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
     view.setAlpha(1 - position);
     view.setPivotY(0.5f * view.getHeight());
     view.setTranslationX(view.getWidth() * -position);
     view.setScaleX(scaleFactor);
     view.setScaleY(scaleFactor);
   }
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    if (mTopCard == null) {
      return false;
    }
    if (mGestureDetector.onTouchEvent(event)) {
      return true;
    }
    final int pointerIndex;
    final float x, y;
    final float dx, dy;
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mTopCard.getHitRect(childRect);

        CardModel cardModel = (CardModel) getAdapter().getItem(getChildCount() - 1);

        if (cardModel.getOnClickListener() != null) {
          cardModel.getOnClickListener().OnClickListener();
        }
        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);
        break;
      case MotionEvent.ACTION_MOVE:
        pointerIndex = event.findPointerIndex(mActivePointerId);
        x = event.getX(pointerIndex);
        y = event.getY(pointerIndex);
        if (Math.abs(x - mLastTouchX) > mTouchSlop || Math.abs(y - mLastTouchY) > mTouchSlop) {
          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]);
          return true;
        }
    }

    return false;
  }
  public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();
    view.setPivotX((float) pageWidth / 2);
    view.setPivotY((float) (pageHeight + pageWidth * distanceToCentreFactor));

    if (position < -1) { // [-infinity,1)
      // off to the left by a lot
      view.setRotation(0);
      view.setAlpha(0);
      view.setTranslationX(0);
    } else if (position <= 1) { // [-1,1]
      view.setTranslationX((-position) * pageWidth);
      view.setRotation(position * (180 - degrees));

      // Fade the page relative to its distance from the center
      view.setAlpha(Math.max(minAlpha, 1 - Math.abs(position) / 3));
    } else { // (1, +infinity]
      // off to the right by a lot
      view.setRotation(0);
      view.setAlpha(0);
      view.setTranslationX(0);
    }
  }
 @Override
 public void transformPage(View page, float position) {
   page.setPivotX(position < 0f ? page.getWidth() : 0f);
   page.setPivotY(page.getHeight() * 0.5f);
   page.setRotationY(90f * position);
 }
  @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;
  }
 @Override
 protected void onTransform(View view, float position) {
   view.setPivotX(position < 0f ? view.getWidth() : 0f);
   view.setPivotY(view.getHeight() * 0.5f);
   view.setRotationY(90f * position);
 }
 public static void setPivotY(View view, float f) {
   view.setPivotY(f);
 }
Beispiel #14
0
 static void setPivotY(View view, float pivotY) {
   view.setPivotY(pivotY);
 }
Beispiel #15
0
 @Override
 public void initView(View item, int position, int scrollDirection) {
   item.setPivotX(0);
   item.setPivotY(item.getHeight() / 2);
   item.setRotationY(INITIAL_ROTATION_ANGLE);
 }
Beispiel #16
0
  private void dealScroll() {
    // 最小缩放值
    float progress = 1 - getScrollX() * 1.0f / (mScreenWidth - mMenuOffset);
    // 移动动画处理
    switch (mTransInt) {
      case 1:
        mMenuView.setTranslationX(getScrollX());
        break;
      case 2:
        break;
      case 3:
        mMenuView.setTranslationX(getScrollX() * progress);
        break;
    }
    // 状态栏跟随内容区域滑动
    if (isTranslate) {
      statusView.setTranslationX(progress * (mScreenWidth - mMenuOffset));
    }
    // 缩放动画处理
    if (mScaleInt == 2) {
      mMenuView.setScaleX(progress * (1 - mStartScale) + mStartScale);
      mMenuView.setScaleY(progress * (1 - mStartScale) + mStartScale);
    }
    // 透明动画处理
    if (mAlphaInt == 2) {
      mMenuView.setAlpha(mStartAlpha + (1 - mStartAlpha) * progress);
    }
    // 旋转动画处理
    switch (mRotateInt) {
      case 2: // 中心
        mMenuView.setPivotX(mMenuView.getWidth() / 2);
        mMenuView.setPivotY(mMenuView.getHeight() / 2);
        mMenuView.setRotation(progress * 360);

        break;
      case 3: // 3D左侧翻转
        mMenuView.setPivotX(0);
        mMenuView.setPivotY(mMenuView.getHeight() / 2);
        mMenuView.setRotationY(progress * -(90 - mStart3DAngle) + (90 - mStart3DAngle));
        break;
      case 4: // x翻转
        mMenuView.setPivotX(0);
        mMenuView.setPivotY(0);
        mMenuView.setRotation(progress * -90 + 90);
        break;
      case 5: // 左上角
        mMenuView.setPivotX(mMenuView.getWidth() / 2);
        mMenuView.setPivotY(mMenuView.getHeight() / 2);
        mMenuView.setRotationX(progress * -(45) + 45);
        break;
      case 6: // 左下角
        mMenuView.setPivotX(0);
        mMenuView.setPivotY(mMenuView.getHeight());
        mMenuView.setRotation(progress * +90 + -90);
        break;
    }
    // 渐变状态栏
    if (mListener != null) { // 进度监听
      mListener.onProgressChange(progress);
    }
    // 设置动态模糊
    if (mBackImageView != null) {
      mBackImageView.setAlpha(progress);
    }
  }
 public void zoom(Float scaleX, Float scaleY, PointF pivot) {
   transformableView.setPivotX(pivot.x);
   transformableView.setPivotY(pivot.y);
   transformableView.setScaleX(scaleX);
   transformableView.setScaleY(scaleY);
 }
 @Override
 public void setPivotY(View view, float pivotY) {
   view.setPivotY(pivotY);
 }