Ejemplo n.º 1
0
 private void animateRotate(View left, View right, float positionOffset, boolean up) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       mRot = (up ? 1 : -1) * (ROT_MAX * positionOffset);
       mTrans =
           (up ? -1 : 1)
               * (float)
                   (getMeasuredHeight() - getMeasuredHeight() * Math.cos(mRot * Math.PI / 180.0f));
       ViewHelper.setPivotX(left, left.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(left, up ? 0 : left.getMeasuredHeight());
       ViewHelper.setTranslationY(left, mTrans);
       ViewHelper.setRotation(left, mRot);
     }
     if (right != null) {
       manageLayer(right, true);
       mRot = (up ? 1 : -1) * (-ROT_MAX + ROT_MAX * positionOffset);
       mTrans =
           (up ? -1 : 1)
               * (float)
                   (getMeasuredHeight() - getMeasuredHeight() * Math.cos(mRot * Math.PI / 180.0f));
       ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(right, up ? 0 : right.getMeasuredHeight());
       ViewHelper.setTranslationY(right, mTrans);
       ViewHelper.setRotation(right, mRot);
     }
   }
 }
Ejemplo n.º 2
0
 private void animateZoom(View left, View right, float positionOffset, boolean in) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       mScale =
           in
               ? ZOOM_MAX + (1 - ZOOM_MAX) * (1 - positionOffset)
               : 1 + ZOOM_MAX - ZOOM_MAX * (1 - positionOffset);
       ViewHelper.setPivotX(left, left.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(left, left.getMeasuredHeight() * 0.5f);
       ViewHelper.setScaleX(left, mScale);
       ViewHelper.setScaleY(left, mScale);
     }
     if (right != null) {
       manageLayer(right, true);
       mScale =
           in
               ? ZOOM_MAX + (1 - ZOOM_MAX) * positionOffset
               : 1 + ZOOM_MAX - ZOOM_MAX * positionOffset;
       ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f);
       ViewHelper.setScaleX(right, mScale);
       ViewHelper.setScaleY(right, mScale);
     }
   }
 }
Ejemplo n.º 3
0
 private void animateFlipVertical(
     View left, View right, float positionOffset, int positionOffsetPixels) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       mRot = 180.0f * positionOffset;
       if (mRot > 90.0f) {
         left.setVisibility(View.INVISIBLE);
       } else {
         if (left.getVisibility() == View.INVISIBLE) left.setVisibility(View.VISIBLE);
         mTrans = positionOffsetPixels;
         ViewHelper.setPivotX(left, left.getMeasuredWidth() * 0.5f);
         ViewHelper.setPivotY(left, left.getMeasuredHeight() * 0.5f);
         ViewHelper.setTranslationX(left, mTrans);
         ViewHelper.setRotationX(left, mRot);
       }
     }
     if (right != null) {
       manageLayer(right, true);
       mRot = -180.0f * (1 - positionOffset);
       if (mRot < -90.0f) {
         right.setVisibility(View.INVISIBLE);
       } else {
         if (right.getVisibility() == View.INVISIBLE) right.setVisibility(View.VISIBLE);
         mTrans = -getWidth() - getPageMargin() + positionOffsetPixels;
         ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f);
         ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f);
         ViewHelper.setTranslationX(right, mTrans);
         ViewHelper.setRotationX(right, mRot);
       }
     }
   }
 }
Ejemplo n.º 4
0
 @Override
 protected void onTransform(View view, float position) {
   // Rotate the fragment on the left or right edge
   ViewHelper.setPivotX(view, position > 0 ? 0 : view.getWidth());
   ViewHelper.setPivotY(view, 0);
   ViewHelper.setRotation(view, -90f * position);
 }
Ejemplo n.º 5
0
  /** 滚动发生时调用 */
  @Override
  protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
    /**
     * 距离qq差别 :1.qq内容区域实现了一个缩放的效果 2.菜单的偏移量一直在变化 3.菜单也存在缩放和透明度的变化 实现1.需要将 0.7 ~ 1.0 (0.7 + 0.3 *
     * scale) 实现2.修改菜单的其实隐藏跨度 实现3.菜单透明度变化0.6 ~ 1.0 ( 0.6 + 0.4 *(1-scale))+缩放:0.7~1.0(1.0 -
     * scale*0.3)
     */
    // l是当前SrocllX值
    float scale = l * 1.0f / mMenuWidth;
    Log.i("SlidingMenu:onScrollChanged", "" + scale);
    // 调用属性动画 设置TranslationX 修改菜单的其实隐藏跨度,其实隐藏60%
    ViewHelper.setTranslationX(mMenu, mMenuWidth * scale * 0.6f);

    // 实现内容区域缩小
    float contextScale = 0.7f + 0.3f * scale;
    // 设置缩放的中心点 设置内容区域缩放值
    ViewHelper.setPivotX(mContent, 0);
    ViewHelper.setPivotY(mContent, mContent.getHeight() / 2);
    ViewHelper.setScaleX(mContent, contextScale);
    ViewHelper.setScaleY(mContent, contextScale);

    // 实现菜单区域缩放
    float menuScale = 1.0f - scale * 0.3f;
    // 实现菜单透明度变化
    float menuAlpha = 0.6f + 0.4f * (1 - scale);
    // 调用属性动画实现
    ViewHelper.setScaleX(mMenu, menuScale);
    ViewHelper.setScaleY(mMenu, menuScale);
    ViewHelper.setAlpha(mMenu, menuAlpha);
  }
Ejemplo n.º 6
0
 @Override
 public void initView(View item, int position, int scrollDirection) {
   ViewHelper.setPivotX(item, item.getWidth() / 2);
   ViewHelper.setPivotY(item, item.getHeight() / 2);
   ViewHelper.setRotationX(item, -INITIAL_ROTATION_ANGLE * scrollDirection);
   ViewHelper.setTranslationY(item, item.getHeight() * 2 * scrollDirection);
 }
Ejemplo n.º 7
0
 private void animateAccordion(View left, View right, float positionOffset) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       ViewHelper.setPivotX(left, left.getMeasuredWidth());
       ViewHelper.setPivotY(left, 0);
       ViewHelper.setScaleX(left, 1 - positionOffset);
     }
     if (right != null) {
       manageLayer(right, true);
       ViewHelper.setPivotX(right, 0);
       ViewHelper.setPivotY(right, 0);
       ViewHelper.setScaleX(right, positionOffset);
     }
   }
 }
Ejemplo n.º 8
0
  /**
   * Scale title view and move it in Flexible space
   *
   * @param scrollY
   */
  private void updateFlexibleSpaceText(final int scrollY) {
    if (!mIsToolbarShown) return;

    int adjustedScrollY = scrollY;
    if (scrollY < 0) {
      adjustedScrollY = 0;
    } else if (scrollY > mParallaxImageHeight) {
      adjustedScrollY = mParallaxImageHeight;
    }

    float maxScale = 1.6f;
    float scale =
        maxScale
            * ((float) (mParallaxImageHeight - mToolbarHeight) - adjustedScrollY)
            / (mParallaxImageHeight - mToolbarHeight);
    if (scale < 0) {
      scale = 0;
    }

    ViewHelper.setPivotX(mTitle, 0);
    ViewHelper.setPivotY(mTitle, 0);
    ViewHelper.setScaleX(mTitle, 1 + scale);
    ViewHelper.setScaleY(mTitle, 1 + scale);

    int maxTitleTranslation = (int) (mParallaxImageHeight * 0.4f);
    int titleTranslation = (int) (maxTitleTranslation * ((float) scale / maxScale));
    ViewHelper.setTranslationY(mTitle, titleTranslation);
  }
Ejemplo n.º 9
0
 protected void animateScroll(int position, float positionOffset) {
   if (mState != State.IDLE) {
     mRot = (float) (1 - Math.cos(2 * Math.PI * positionOffset)) / 2 * 30.0f;
     ViewHelper.setRotationY(this, mState == State.GOING_RIGHT ? mRot : -mRot);
     ViewHelper.setPivotX(this, getMeasuredWidth() * 0.5f);
     ViewHelper.setPivotY(this, getMeasuredHeight() * 0.5f);
   }
 }
Ejemplo n.º 10
0
 private void animateCube(View left, View right, float positionOffset, boolean in) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       mRot = (in ? 90.0f : -90.0f) * positionOffset;
       ViewHelper.setPivotX(left, left.getMeasuredWidth());
       ViewHelper.setPivotY(left, left.getMeasuredHeight() * 0.5f);
       ViewHelper.setRotationY(left, mRot);
     }
     if (right != null) {
       manageLayer(right, true);
       mRot = -(in ? 90.0f : -90.0f) * (1 - positionOffset);
       ViewHelper.setPivotX(right, 0);
       ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f);
       ViewHelper.setRotationY(right, mRot);
     }
   }
 }
 @Override
 protected void onTransform(View view, float position) {
   final float scale = position < 0 ? position + 1f : Math.abs(1f - position);
   ViewHelper.setScaleX(view, scale);
   ViewHelper.setScaleY(view, scale);
   ViewHelper.setPivotX(view, view.getWidth() * 0.5f);
   ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
   ViewHelper.setAlpha(view, position < -1f || position > 1f ? 0f : 1f - (scale - 1f));
 }
Ejemplo n.º 12
0
 @Override
 public void initView(View item, int position, int scrollDirection) {
   ViewHelper.setPivotX(item, item.getWidth() / 2);
   ViewHelper.setPivotY(item, item.getHeight() / 2);
   ViewHelper.setScaleX(item, INITIAL_SCALE_FACTOR);
   ViewHelper.setScaleY(item, INITIAL_SCALE_FACTOR);
   ViewHelper.setTranslationY(item, item.getHeight() / 2 * scrollDirection);
   ViewHelper.setAlpha(item, JazzyHelper.OPAQUE / 2);
 }
Ejemplo n.º 13
0
  @Override
  protected void onTransform(View view, float position) {
    final float width = view.getWidth();
    final float rotation = ROT_MOD * position;

    ViewHelper.setPivotX(view, width * 0.5f);
    ViewHelper.setPivotY(view, 0f);
    ViewHelper.setTranslationX(view, 0f);
    ViewHelper.setRotation(view, rotation);
  }
Ejemplo n.º 14
0
  private void setScaleDirection(int direction) {

    int screenWidth = getScreenWidth();
    float pivotX;
    float pivotY = getScreenHeight() * 0.5f;

    if (direction == DIRECTION_LEFT) {
      scrollViewMenu = scrollViewLeftMenu;
      pivotX = screenWidth * 1.5f;
    } else {
      scrollViewMenu = scrollViewRightMenu;
      pivotX = screenWidth * -0.5f;
    }

    ViewHelper.setPivotX(viewActivity, pivotX);
    ViewHelper.setPivotY(viewActivity, pivotY);
    ViewHelper.setPivotX(imageViewShadow, pivotX);
    ViewHelper.setPivotY(imageViewShadow, pivotY);
    scaleDirection = direction;
  }
Ejemplo n.º 15
0
  @Override
  public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Translate overlay and image
    float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
    int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
    ViewHelper.setTranslationY(
        mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
    ViewHelper.setTranslationY(
        mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

    // Scale title text
    float scale =
        1
            + ScrollUtils.getFloat(
                (flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);

    // Translate title text
    int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
    int titleTranslationY = maxTitleTranslationY - scrollY;
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);

    // Translate FAB
    int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
    float fabTranslationY =
        ScrollUtils.getFloat(
            -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2,
            mActionBarSize - mFab.getHeight() / 2,
            maxFabTranslationY);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin,
      // which causes FAB's OnClickListener not working.
      FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams();
      lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth();
      lp.topMargin = (int) fabTranslationY;
      mFab.requestLayout();
    } else {
      ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
      ViewHelper.setTranslationY(mFab, fabTranslationY);
    }

    // Show/hide FAB
    if (fabTranslationY < mFlexibleSpaceShowFabOffset) {
      hideFab();
    } else {
      showFab();
    }
  }
  @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);

    ViewHelper.setScaleX(view, scale);
    ViewHelper.setScaleY(view, scale);
    ViewHelper.setPivotX(view, width * 0.5f);
    ViewHelper.setPivotY(view, height * 0.5f);
    ViewHelper.setTranslationX(view, position > 0 ? width * position : -width * position * 0.25f);
  }
 /**
  * reset the view to default status
  *
  * @param target
  */
 public void reset(View target) {
   ViewHelper.setAlpha(target, 1);
   ViewHelper.setScaleX(target, 1);
   ViewHelper.setScaleY(target, 1);
   ViewHelper.setTranslationX(target, 0);
   ViewHelper.setTranslationY(target, 0);
   ViewHelper.setRotation(target, 0);
   ViewHelper.setRotationY(target, 0);
   ViewHelper.setRotationX(target, 0);
   ViewHelper.setPivotX(target, target.getMeasuredWidth() / 2.0f);
   ViewHelper.setPivotY(target, target.getMeasuredHeight() / 2.0f);
 }
 @Override
 protected void onTransform(View view, float position) {
   final float scale = 1f + Math.abs(position);
   ViewHelper.setScaleX(view, scale);
   ViewHelper.setScaleY(view, scale);
   ViewHelper.setPivotX(view, view.getWidth() * 0.5f);
   ViewHelper.setPivotY(view, view.getWidth() * 0.5f);
   ViewHelper.setAlpha(view, position < -1f || position > 1f ? 0f : 1f - (scale - 1f));
   if (position < -0.9) {
     // -0.9 to prevent a small bug
     ViewHelper.setTranslationX(view, view.getWidth() * position);
   }
 }
  private void translateTab(int scrollY, boolean animated) {
    int flexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    View imageView = findViewById(R.id.image);
    View overlayView = findViewById(R.id.overlay);
    TextView titleView = (TextView) findViewById(R.id.title);

    // Translate overlay and image
    float flexibleRange = flexibleSpaceImageHeight - getActionBarSize();
    int minOverlayTransitionY = tabHeight - overlayView.getHeight();
    ViewHelper.setTranslationY(
        overlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0));
    ViewHelper.setTranslationY(
        imageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    ViewHelper.setAlpha(overlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1));

    // Scale title text
    float scale =
        1
            + ScrollUtils.getFloat(
                (flexibleRange - scrollY - tabHeight) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    setPivotXToTitle(titleView);
    ViewHelper.setPivotY(titleView, 0);
    ViewHelper.setScaleX(titleView, scale);
    ViewHelper.setScaleY(titleView, scale);

    // Translate title text
    int maxTitleTranslationY = flexibleSpaceImageHeight - tabHeight - getActionBarSize();
    int titleTranslationY = maxTitleTranslationY - scrollY;
    ViewHelper.setTranslationY(titleView, titleTranslationY);

    // If tabs are moving, cancel it to start a new animation.
    ViewPropertyAnimator.animate(mSlidingTabLayout).cancel();
    // Tabs will move between the top of the screen to the bottom of the image.
    float translationY =
        ScrollUtils.getFloat(
            -scrollY + mFlexibleSpaceHeight - mTabHeight, 0, mFlexibleSpaceHeight - mTabHeight);
    if (animated) {
      // Animation will be invoked only when the current tab is changed.
      ViewPropertyAnimator.animate(mSlidingTabLayout)
          .translationY(translationY)
          .setDuration(200)
          .start();
    } else {
      // When Fragments' scroll, translate tabs immediately (without animation).
      ViewHelper.setTranslationY(mSlidingTabLayout, translationY);
    }
  }
Ejemplo n.º 20
0
 protected void animateTablet(View left, View right, float positionOffset) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       mRot = 30.0f * positionOffset;
       mTrans = getOffsetXForRotation(mRot, left.getMeasuredWidth(), left.getMeasuredHeight());
       ViewHelper.setPivotX(left, left.getMeasuredWidth() / 2);
       ViewHelper.setPivotY(left, left.getMeasuredHeight() / 2);
       ViewHelper.setTranslationX(left, mTrans);
       ViewHelper.setRotationY(left, mRot);
       logState(left, "Left");
     }
     if (right != null) {
       manageLayer(right, true);
       mRot = -30.0f * (1 - positionOffset);
       mTrans = getOffsetXForRotation(mRot, right.getMeasuredWidth(), right.getMeasuredHeight());
       ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f);
       ViewHelper.setTranslationX(right, mTrans);
       ViewHelper.setRotationY(right, mRot);
       logState(right, "Right");
     }
   }
 }
 public AnimationBuilder pivotY(float pivotY) {
   for (View view : views) {
     ViewHelper.setPivotY(view, pivotY);
   }
   return this;
 }
Ejemplo n.º 22
0
 public void setPivotY(float y) {
   ViewHelper.setPivotY(this, y);
 }
Ejemplo n.º 23
0
 public void initView(View paramView, int paramInt1, int paramInt2) {
   ViewHelper.setPivotX(paramView, paramView.getWidth() / 2);
   ViewHelper.setPivotY(paramView, paramView.getHeight() / 2);
   ViewHelper.setScaleX(paramView, 0.01F);
   ViewHelper.setScaleY(paramView, 0.01F);
 }