public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();

    if (position < -1) { // [-Infinity,-1)
      // This page is way off-screen to the left.
      ViewHelper.setAlpha(view, 0);

    } else if (position <= 0) { // [-1,0]
      // Use the default slide transition when moving to the left page
      ViewHelper.setAlpha(view, 1);
      ViewHelper.setTranslationX(view, 0);
      ViewHelper.setScaleX(view, 1);
      ViewHelper.setScaleY(view, 1);

    } else if (position <= 1) { // (0,1]
      // Fade the page out.
      ViewHelper.setAlpha(view, 1 - position);

      // Counteract the default slide transition
      ViewHelper.setTranslationX(view, pageWidth * -position);

      // Scale the page down (between MIN_SCALE and 1)
      float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
      ViewHelper.setScaleX(view, scaleFactor);
      ViewHelper.setScaleY(view, scaleFactor);

    } else { // (1,+Infinity]
      // This page is way off-screen to the right.
      ViewHelper.setAlpha(view, 0);
    }
  }
 private void setRotation(View view, float position, float percentage) {
   if (position > 0) {
     ViewHelper.setRotationY(view, -180 * (percentage + 1));
   } else {
     ViewHelper.setRotationY(view, 180 * (percentage + 1));
   }
 }
  @Override
  protected void updateViews(int scrollY, boolean animated) {
    super.updateViews(scrollY, animated);

    // Translate list background
    ViewHelper.setTranslationY(mListBackgroundView, ViewHelper.getTranslationY(mHeader));
  }
  /**
   * 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);
  }
Esempio n. 5
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);
 }
Esempio n. 6
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);
 }
Esempio n. 7
0
  public void show(final View view, Bundle bundle) {
    view.setEnabled(false);
    this.view = view;
    String text = bundle.getString("text");
    tv.setText(text);
    String content = bundle.getString("content");
    contentTv.setText("服务内容:" + content);
    String time = bundle.getString("time");
    timeTv.setText("时间:" + time);
    String location = bundle.getString("location");
    locationTv.setText("地点:" + location);
    ViewHelper.setRotationY(view, 0);
    ViewHelper.setRotationY(root, -90);
    root.setVisibility(View.VISIBLE);

    ViewPropertyAnimator.animate(view)
        .rotationY(90)
        .setDuration(300)
        .setListener(null)
        .setInterpolator(new AccelerateInterpolator());

    ViewPropertyAnimator.animate(root)
        .rotationY(0)
        .setDuration(200)
        .setStartDelay(300)
        .setListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                ViewHelper.setRotationY(view, 0);
              }
            });
  }
Esempio n. 8
0
  private void hideCard(int which) {
    if (isAnimating) return;
    List<Animator> animators = new ArrayList<>(mChildCount);
    final View displayingCard = getChildAt(which);
    int t = (int) (getMeasuredHeight() - (mChildCount - which) * mTitleBarHeightNoDisplay);
    ValueAnimator displayAnimator =
        ValueAnimator.ofFloat(ViewHelper.getY(displayingCard), t).setDuration(mDuration);
    displayAnimator.setTarget(displayingCard);
    final int finalT = t;
    displayAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float value = (float) valueAnimator.getAnimatedValue();
            ViewHelper.setY(displayingCard, value);
            if (mDarkFrameLayout != null && isFade && value < finalT) {
              mDarkFrameLayout.fade((int) ((1 - value / finalT) * DarkFrameLayout.MAX_ALPHA));
            }
          }
        });
    animators.add(displayAnimator);
    for (int i = 0; i < mChildCount; i++) {
      if (i == 0 && isExistBackground) continue;
      if (i != which) {
        t = (int) (getMeasuredHeight() - (mChildCount - i) * mTitleBarHeightNoDisplay);
        animators.add(
            ObjectAnimator.ofFloat(getChildAt(i), "y", ViewHelper.getY(getChildAt(i)), t));
      }
    }
    AnimatorSet set = new AnimatorSet();
    set.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animator) {
            isAnimating = true;
          }

          @Override
          public void onAnimationEnd(Animator animator) {
            isAnimating = false;
            isDisplaying = false;
          }

          @Override
          public void onAnimationCancel(Animator animator) {
            isAnimating = false;
            isDisplaying = false;
          }

          @Override
          public void onAnimationRepeat(Animator animator) {}
        });
    set.setInterpolator(mCloseAnimatorInterpolator);
    set.playTogether(animators);
    set.start();
    mDisplayingCard = -1;
    if (mOnDisplayOrHideListener != null)
      mOnDisplayOrHideListener.onHide(isExistBackground ? (which - 1) : which);
  }
Esempio n. 9
0
 void setDegree(float degree) {
   mValue = degree;
   View clipView = mTarget.get();
   float x = mArcMetric.getAxisPoint().x + mArcMetric.mRadius * Utils.cos(degree);
   float y = mArcMetric.getAxisPoint().y - mArcMetric.mRadius * Utils.sin(degree);
   ViewHelper.setX(clipView, x - clipView.getWidth() / 2);
   ViewHelper.setY(clipView, y - clipView.getHeight() / 2);
 }
Esempio n. 10
0
 protected void animateFade(View left, View right, float positionOffset) {
   if (left != null) {
     ViewHelper.setAlpha(left, 1 - positionOffset);
   }
   if (right != null) {
     ViewHelper.setAlpha(right, positionOffset);
   }
 }
Esempio n. 11
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);
   }
 }
 @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));
 }
    public void reset() {
      scrollDistance = 0;
      logoViewContainer = 0;
      viewContainerOffset = 0;
      toolbarOffset = 0;

      ViewHelper.setTranslationY(parentFragment.logoContainer, 0);
      ViewHelper.setTranslationY(parentFragment.viewContainer, 0);
      ViewHelper.setTranslationY(parentFragment.toolbar, 0);
    }
Esempio n. 14
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);
  }
Esempio 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();
    }
  }
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 private void setPivotXToTitle(View view) {
   final TextView mTitleView = (TextView) view.findViewById(R.id.title);
   Configuration config = getResources().getConfiguration();
   if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT
       && config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
     ViewHelper.setPivotX(mTitleView, view.findViewById(android.R.id.content).getWidth());
   } else {
     ViewHelper.setPivotX(mTitleView, 0);
   }
 }
Esempio n. 17
0
 protected void animateStack(View left, View right, float effectOffset, int positionOffsetPixels) {
   if (right != null) {
     mScale = (1 - SCALE_MAX) * effectOffset + SCALE_MAX;
     mTrans = -getWidth() - getPageMargin() + positionOffsetPixels;
     ViewHelper.setScaleX(right, mScale);
     ViewHelper.setScaleY(right, mScale);
     ViewHelper.setTranslationX(right, mTrans);
   }
   if (left != null) {
     left.bringToFront();
   }
 }
 /**
  * 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 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);
  }
Esempio n. 20
0
 /** Override method to configure the dragged view and secondView layout properly. */
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
   if (isInEditMode()) super.onLayout(changed, left, top, right, bottom);
   else if (isDragViewAtTop()) {
     dragView.layout(left, top, right, transformer.getOriginalHeight());
     secondView.layout(left, transformer.getOriginalHeight(), right, bottom);
     ViewHelper.setY(dragView, top);
     ViewHelper.setY(secondView, transformer.getOriginalHeight());
   } else {
     secondView.layout(left, transformer.getOriginalHeight(), right, bottom);
   }
 }
Esempio n. 21
0
 /**
  * 根据滑动的距离的比例,进行平移动画
  *
  * @param percent
  */
 private void animateView(float percent) {
   float f1 = 1 - percent * 0.5f;
   // 沿着水平X轴平移
   ViewHelper.setTranslationX(
       vg_left, -vg_left.getWidth() / 2.5f + vg_left.getWidth() / 2.5f * percent);
   if (isShowShadow) {
     // 阴影效果视图大小进行缩放
     ViewHelper.setScaleX(iv_shadow, f1 * 1.2f * (1 - percent * 0.10f));
     ViewHelper.setScaleY(iv_shadow, f1 * 1.85f * (1 - percent * 0.10f));
   }
   getBackground()
       .setColorFilter(evaluate(percent, Color.BLACK, Color.TRANSPARENT), Mode.SRC_OVER);
 }
Esempio n. 22
0
  /** 显示模糊背景 */
  protected void showShowdown() {

    ViewHelper.setTranslationY(mRootView, 0);
    mEffect.effect(mParentVG, mBg);
    ViewGroup.LayoutParams lp =
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mParentVG.addView(mBg, lp);
    ViewHelper.setAlpha(mBg, 0);
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mBg, "alpha", 0, 1);
    objectAnimator.setDuration(400);
    objectAnimator.start();
  }
Esempio n. 23
0
 protected void animateStack(
     View left, View right, float positionOffset, int positionOffsetPixels) {
   if (mState != State.IDLE) {
     if (right != null) {
       manageLayer(right, true);
       mScale = (1 - SCALE_MAX) * positionOffset + SCALE_MAX;
       mTrans = -getWidth() - getPageMargin() + positionOffsetPixels;
       ViewHelper.setScaleX(right, mScale);
       ViewHelper.setScaleY(right, mScale);
       ViewHelper.setTranslationX(right, mTrans);
     }
   }
 }
Esempio n. 24
0
  private void animateTitles() {
    final View prevTextView = getChildAt(0);
    final View nextTextView = getChildAt(getChildCount() - 1);

    if (prevTextView == null || nextTextView == null) {
      return;
    }

    // Set up initial values for the views that will be animated.
    ViewHelper.setTranslationX(prevTextView, -INIT_OFFSET);
    ViewHelper.setAlpha(prevTextView, 0);
    ViewHelper.setTranslationX(nextTextView, INIT_OFFSET);
    ViewHelper.setAlpha(nextTextView, 0);

    // Alpha animations.
    final ValueAnimator alpha1 = ObjectAnimator.ofFloat(prevTextView, "alpha", 1);
    final ValueAnimator alpha2 = ObjectAnimator.ofFloat(nextTextView, "alpha", 1);

    final AnimatorSet alphaAnimatorSet = new AnimatorSet();
    alphaAnimatorSet.playTogether(alpha1, alpha2);
    alphaAnimatorSet.setDuration(ALPHA_MS);
    alphaAnimatorSet.setStartDelay(ANIMATION_DELAY_MS);

    // Bounce animation.
    final float bounceDistance = getWidth() / 100f; // Hack: TextFields still have 0 width here.

    final BounceAnimatorBuilder prevBounceAnimatorBuilder =
        new BounceAnimatorBuilder(prevTextView, "translationX");
    prevBounceAnimatorBuilder.queue(new Attributes(bounceDistance, BOUNCE1_MS));
    prevBounceAnimatorBuilder.queue(new Attributes(-bounceDistance / 4, BOUNCE2_MS));
    prevBounceAnimatorBuilder.queue(new Attributes(0, BOUNCE3_MS));

    final BounceAnimatorBuilder nextBounceAnimatorBuilder =
        new BounceAnimatorBuilder(nextTextView, "translationX");
    nextBounceAnimatorBuilder.queue(new Attributes(-bounceDistance, BOUNCE1_MS));
    nextBounceAnimatorBuilder.queue(new Attributes(bounceDistance / 4, BOUNCE2_MS));
    nextBounceAnimatorBuilder.queue(new Attributes(0, BOUNCE3_MS));

    final AnimatorSet bounceAnimatorSet = new AnimatorSet();
    bounceAnimatorSet.playTogether(
        prevBounceAnimatorBuilder.build(), nextBounceAnimatorBuilder.build());

    TransitionsTracker.track(nextBounceAnimatorBuilder);

    final AnimatorSet titlesAnimatorSet = new AnimatorSet();
    titlesAnimatorSet.playTogether(alphaAnimatorSet, bounceAnimatorSet);
    titlesAnimatorSet.setStartDelay(ANIMATION_DELAY_MS);

    // Start animations.
    titlesAnimatorSet.start();
  }
Esempio n. 25
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);
  }
Esempio n. 26
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);
       }
     }
   }
 }
Esempio n. 27
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);
     }
   }
 }
Esempio n. 28
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);
     }
   }
 }
Esempio n. 29
0
 private void handleActionUp(MotionEvent event) {
   if (whichCardOnTouch == -1 || !isTouchOnCard) return;
   long pressDuration = System.currentTimeMillis() - mPressStartTime;
   computeVelocity();
   if (!isDisplaying
       && ((event.getY() - firstDownY < 0
               && (Math.abs(event.getY() - firstDownY) > mMoveDistanceToTrigger))
           || (yVelocity < 0
               && Math.abs(yVelocity) > mMinVelocity
               && Math.abs(yVelocity) > Math.abs(xVelocity)))) {
     displayCard(whichCardOnTouch);
   } else if (!isDisplaying
       && pressDuration < MAX_CLICK_TIME
       && // means click
       distance(firstDownX, firstDownY, event.getX(), event.getY()) < MAX_CLICK_DISTANCE) {
     displayCard(whichCardOnTouch);
   } else if (!isDisplaying
       && isDragging
       && ((event.getY() - firstDownY > 0)
           || Math.abs(event.getY() - firstDownY) < mMoveDistanceToTrigger)) {
     hideCard(whichCardOnTouch);
   } else if (isDisplaying) {
     float currentY = ViewHelper.getY(getChildAt(mDisplayingCard));
     if (currentY < mMarginTop || currentY < (mMarginTop + mMoveDistanceToTrigger)) {
       ObjectAnimator.ofFloat(getChildAt(mDisplayingCard), "y", currentY, mMarginTop)
           .setDuration(mDuration)
           .start();
     } else if (currentY > (mMarginTop + mMoveDistanceToTrigger)) {
       hideCard(mDisplayingCard);
     }
   }
   isTouchOnCard = false;
   deltaY = 0;
   isDragging = false;
 }
 @Override
 public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
   int baseColor = color;
   float alpha = Math.min(1, (float) scrollY / mParallaxImageHeight);
   mToolbarView.setBackgroundColor(ScrollUtils.getColorWithAlpha(alpha, baseColor));
   ViewHelper.setTranslationY(banner, scrollY / 2);
 }