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);
     }
   }
 }
    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);
    }
  @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();
    }
  }
  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);
    }
  }
  /**
   * 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);
  }
  @Override
  protected void updateViews(int scrollY, boolean animated) {
    super.updateViews(scrollY, animated);

    // Translate list background
    ViewHelper.setTranslationY(mListBackgroundView, ViewHelper.getTranslationY(mHeader));
  }
 @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);
 }
Exemple #8
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);
 }
 @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);
 }
 @Override
 public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
   float alpha = 1 - (float) Math.max(0, mParallaxImageHeight - scrollY) / mParallaxImageHeight;
   setToolBarBackgroundAlpha(mToolbar, alpha, primaryColor);
   setStatusBarBackgroundAlpha(statusBar, alpha + 0.2f, ActionBarView.darkenColor(primaryColor));
   note.setAlpha(1 - alpha);
   date.setAlpha(1 - alpha);
   ViewHelper.setTranslationY(mImageView, scrollY / 2);
 }
 public static void reset(View view) {
   ViewHelper.setAlpha(view, 1);
   ViewHelper.setScaleX(view, 1);
   ViewHelper.setScaleY(view, 1);
   ViewHelper.setTranslationX(view, 0);
   ViewHelper.setTranslationY(view, 0);
   ViewHelper.setRotation(view, 0);
   ViewHelper.setRotationY(view, 0);
   ViewHelper.setRotationX(view, 0);
 }
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      super.onScrolled(recyclerView, dx, dy);

      scrollDistance += dy;
      logoViewContainer += dy;
      float logoViewTranslation = logoViewContainer / 2;
      int logoContainerHeight = parentFragment.logoContainer.getHeight();
      if (logoViewTranslation > logoContainerHeight) logoViewTranslation = logoContainerHeight;
      else if (logoViewTranslation < 0) logoViewTranslation = 0;
      ViewHelper.setTranslationY(parentFragment.logoContainer, -logoViewTranslation);

      viewContainerOffset += dy;
      int viewContainerHeight = parentFragment.viewContainer.getHeight();
      if (viewContainerOffset > viewContainerHeight) viewContainerOffset = viewContainerHeight;
      else if (viewContainerOffset < 0) viewContainerOffset = 0;
      ViewHelper.setTranslationY(parentFragment.viewContainer, -viewContainerOffset);

      int toolbarHeight = parentFragment.toolbar.getHeight();
      if (viewContainerOffset
              >= viewContainerHeight - toolbarHeight - parentFragment.mTabs.getHeight()
          || dy < 0) {
        toolbarOffset += dy;
        if (toolbarOffset > toolbarHeight) toolbarOffset = toolbarHeight;
        else if (toolbarOffset < 0) toolbarOffset = 0;
        ViewHelper.setTranslationY(parentFragment.toolbar, -toolbarOffset);
      }

      if (!isColored && scrollDistance >= viewContainerHeight - toolbarHeight && dy < 0) {
        parentFragment.toolbar.setBackgroundColor(
            context.getResources().getColor(R.color.color_primary));
        parentFragment.descriptionText.setVisibility(View.VISIBLE);
        parentFragment.viewContainerBackground.setBackgroundColor(
            context.getResources().getColor(R.color.color_primary));
        isColored = true;
      }

      if (isColored && scrollDistance == 0) {
        parentFragment.toolbar.setBackgroundColor(Color.TRANSPARENT);
        parentFragment.viewContainerBackground.startAnimation(parentFragment.animation);
        isColored = false;
      }
    }
 /**
  * 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);
 }
  /** 显示模糊背景 */
  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();
  }
  /** move the toolbarlayout (containing toolbar & tabs) following the current scroll */
  private void followScrollToolbarLayout(float yOffset) {
    if (mHeader.toolbar.getBottom() == 0) return;

    if (toolbarJoinsTabs()) {
      if (firstScrollValue == Float.MIN_VALUE) firstScrollValue = yOffset;

      float translationY = firstScrollValue - yOffset;

      if (translationY > 0) {
        translationY = 0;
      }

      if (ENABLE_LOG) Log.d(TAG, "translationY " + translationY);

      ViewHelper.setTranslationY(mHeader.toolbarLayout, translationY);
    } else {
      ViewHelper.setTranslationY(mHeader.toolbarLayout, 0);
      justToolbarAnimated = false;
    }

    followScrollToolbarIsVisible = (ViewHelper.getY(mHeader.toolbarLayout) >= 0);
  }
  @Override
  protected void updateFlexibleSpace(int scrollY, View view) {
    int flexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);

    View listBackgroundView = view.findViewById(R.id.list_background);

    // Translate list background
    ViewHelper.setTranslationY(
        listBackgroundView, Math.max(0, -scrollY + flexibleSpaceImageHeight));

    // Also pass this event to parent Activity
    FlexibleSpaceWithImageWithViewPagerTabActivity parentActivity =
        (FlexibleSpaceWithImageWithViewPagerTabActivity) getActivity();
    if (parentActivity != null) {
      parentActivity.onScrollChanged(scrollY, (ObservableListView) view.findViewById(R.id.scroll));
    }
  }
Exemple #17
0
 public LoadToast show() {
   if (!mInflated) {
     mShowCalled = true;
     return this;
   }
   mView.show();
   ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2);
   ViewHelper.setAlpha(mView, 0f);
   ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
   // mView.setVisibility(View.VISIBLE);
   ViewPropertyAnimator.animate(mView)
       .alpha(1f)
       .translationY(25 + mTranslationY)
       .setInterpolator(new DecelerateInterpolator())
       .setDuration(300)
       .setStartDelay(0)
       .start();
   return this;
 }
  private void toggle(final boolean visible, final boolean animate, boolean force) {
    if (mVisible != visible || force) {
      mVisible = visible;
      int height = getHeight();
      if (height == 0 && !force) {
        ViewTreeObserver vto = getViewTreeObserver();
        if (vto.isAlive()) {
          vto.addOnPreDrawListener(
              new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                  ViewTreeObserver currentVto = getViewTreeObserver();
                  if (currentVto.isAlive()) {
                    currentVto.removeOnPreDrawListener(this);
                  }
                  toggle(visible, animate, true);
                  return true;
                }
              });
          return;
        }
      }
      int translationY = visible ? 0 : height + getMarginBottom();
      if (animate) {
        ViewPropertyAnimator.animate(this)
            .setInterpolator(mInterpolator)
            .setDuration(TRANSLATE_DURATION_MILLIS)
            .translationY(translationY);
      } else {
        ViewHelper.setTranslationY(this, translationY);
      }

      // On pre-Honeycomb a translated view is still clickable, so we need to disable clicks
      // manually
      if (!hasHoneycombApi()) {
        setClickable(visible);
      }
    }
  }
  @Override
  public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Store actual scroll state:
    if (mScrollY > scrollY) {
      goingUp = true;
    } else if (mScrollY < scrollY) {
      goingUp = false;
    }

    // If we're close to edge, show toolbar faster
    if (mScrollY - scrollY > 50 && !mIsToolbarShown) {
      showFullToolbar(50); // speed up
    } else if (mScrollY - scrollY > 0 && scrollY <= mParallaxImageHeight && !mIsToolbarShown) {
      showFullToolbar(250);
    }

    // Show or hide full toolbar color, so it will become visible over scrollable content:
    if (scrollY >= mParallaxImageHeight - mToolbarHeight) {
      setBackgroundAlpha(mToolbarView, 1, mToolbarBackgroundColor);
    } else {
      setBackgroundAlpha(mToolbarView, 0, mToolbarBackgroundColor);
    }

    // Translate flexible image in Y axis
    ViewHelper.setTranslationY(flImage, scrollY / 2);

    // Calculate flexible space alpha based on scroll state
    float alpha =
        1
            - (float) Math.max(0, mParallaxImageHeight - (mToolbarHeight) - scrollY)
                / (mParallaxImageHeight - (mToolbarHeight * 1.5f));
    setBackgroundAlpha(llTintLayer, alpha, mToolbarBackgroundColor);

    // Store last scroll state
    mScrollY = scrollY;

    // Move the flexible text
    updateFlexibleSpaceText((scrollY));
  }
 public void setTranslationY(float y) {
   ViewHelper.setTranslationY(this, y);
 }
  /**
   * Called when a scroller(RecyclerView/ListView,ScrollView,WebView) scrolled by the user
   *
   * @param source the scroller
   * @param yOffset the scroller current yOffset
   */
  public boolean onMaterialScrolled(Object source, float yOffset) {

    if (initialDistance == -1 || initialDistance == 0) {
      initialDistance = mHeader.mPagerSlidingTabStrip.getTop() - mHeader.toolbar.getBottom();
    }

    // only if yOffset changed
    if (yOffset == lastYOffset) return false;

    float scrollTop = -yOffset;

    {
      // parallax scroll of the Background ImageView (the KenBurnsView)
      if (mHeader.headerBackground != null) {

        if (this.settings.parallaxHeaderFactor != 0)
          ViewHelper.setTranslationY(
              mHeader.headerBackground, scrollTop / this.settings.parallaxHeaderFactor);

        if (ViewHelper.getY(mHeader.headerBackground) >= 0)
          ViewHelper.setY(mHeader.headerBackground, 0);
      }
    }

    if (ENABLE_LOG) Log.d("yOffset", "" + yOffset);

    // dispatch the new offset to all registered scrollables
    dispatchScrollOffset(source, minMax(0, yOffset, scrollMaxDp));

    float percent = yOffset / scrollMax;

    if (ENABLE_LOG) Log.d("percent1", "" + percent);

    if (percent != 0) {
      // distance between pager & toolbar
      float newDistance =
          ViewHelper.getY(mHeader.mPagerSlidingTabStrip) - mHeader.toolbar.getBottom();

      percent = 1 - newDistance / initialDistance;

      if (ENABLE_LOG) Log.d("percent2", "" + percent);
    }

    if (Float.isNaN(percent)) // fix for orientation change
    return false;

    // fix quick scroll
    if (percent == 0 && headerAnimator != null) {
      cancelHeaderAnimator();
      ViewHelper.setTranslationY(mHeader.toolbarLayout, 0);
    }

    percent = minMax(0, percent, 1);
    {
      if (!settings.toolbarTransparent) {
        // change color of toolbar & viewpager indicator &  statusBaground
        setColorPercent(percent);
      } else {
        if (justToolbarAnimated) {
          if (toolbarJoinsTabs()) setColorPercent(1);
          else if (lastPercent != percent) {
            animateColorPercent(0, 200);
          }
        }
      }

      lastPercent = percent; // save the percent

      if (mHeader.mPagerSlidingTabStrip != null) { // move the viewpager indicator
        // float newY = ViewHelper.getY(mHeader.mPagerSlidingTabStrip) + scrollTop;

        if (ENABLE_LOG) Log.d(TAG, "" + scrollTop);

        // mHeader.mPagerSlidingTabStrip.setTranslationY(mHeader.getToolbar().getBottom()-mHeader.mPagerSlidingTabStrip.getY());
        if (scrollTop <= 0) {
          ViewHelper.setTranslationY(mHeader.mPagerSlidingTabStrip, scrollTop);
          ViewHelper.setTranslationY(mHeader.toolbarLayoutBackground, scrollTop);

          // when
          if (ViewHelper.getY(mHeader.mPagerSlidingTabStrip) < mHeader.getToolbar().getBottom()) {
            float ty = mHeader.getToolbar().getBottom() - mHeader.mPagerSlidingTabStrip.getTop();
            ViewHelper.setTranslationY(mHeader.mPagerSlidingTabStrip, ty);
            ViewHelper.setTranslationY(mHeader.toolbarLayoutBackground, ty);
          }
        }
      }

      if (mHeader.mLogo != null) { // move the header logo to toolbar

        if (this.settings.hideLogoWithFade) {
          ViewHelper.setAlpha(mHeader.mLogo, 1 - percent);
          ViewHelper.setTranslationY(
              mHeader.mLogo, (mHeader.finalTitleY - mHeader.originalTitleY) * percent);
        } else {
          ViewHelper.setTranslationY(
              mHeader.mLogo, (mHeader.finalTitleY - mHeader.originalTitleY) * percent);
          ViewHelper.setTranslationX(
              mHeader.mLogo, (mHeader.finalTitleX - mHeader.originalTitleX) * percent);

          float scale = (1 - percent) * (1 - mHeader.finalScale) + mHeader.finalScale;
          setScale(scale, mHeader.mLogo);
        }
      }

      if (this.settings.hideToolbarAndTitle && mHeader.toolbarLayout != null) {
        boolean scrollUp = lastYOffset < yOffset;

        if (scrollUp) {
          scrollUp(yOffset);
        } else {
          scrollDown(yOffset);
        }
      }
    }

    if (headerAnimator != null && percent < 1) {
      cancelHeaderAnimator();
    }

    lastYOffset = yOffset;

    return true;
  }