Search in sources :

Example 1 with Animatable

use of org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable in project AndroidChromium by JackyAndroid.

the class StackAnimation method createUpdateDiscardAnimatorSet.

/**
 * Responsible for generating the animations that moves the tabs back in from
 * discard attempt or commit the current discard (if any). It also re-even the tabs
 * if one of then is removed.
 *
 * @param tabs         The tabs that make up the stack. These are the
 *                     tabs that will be affected by the TabSwitcherAnimation.
 * @param spacing      The default spacing between tabs.
 * @param warpSize     The warp size of the transform from scroll space to screen space.
 * @param discardRange The maximum value the discard amount.
 * @return             The TabSwitcherAnimation instance that will tween the
 *                     tabs to create the appropriate animation.
 */
protected ChromeAnimation<?> createUpdateDiscardAnimatorSet(StackTab[] tabs, int spacing, float warpSize, float discardRange) {
    ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>();
    int dyingTabsCount = 0;
    float firstDyingTabOffset = 0;
    for (int i = 0; i < tabs.length; ++i) {
        StackTab tab = tabs[i];
        addTiltScrollAnimation(set, tab.getLayoutTab(), 0.0f, UNDISCARD_ANIMATION_DURATION, 0);
        if (tab.isDying()) {
            dyingTabsCount++;
            if (dyingTabsCount == 1) {
                firstDyingTabOffset = getScreenPositionInScrollDirection(tab);
            }
        }
    }
    Interpolator interpolator = BakedBezierInterpolator.FADE_OUT_CURVE;
    int newIndex = 0;
    for (int i = 0; i < tabs.length; ++i) {
        StackTab tab = tabs[i];
        long startTime = (long) Math.max(0, TAB_REORDER_START_SPAN / getScreenSizeInScrollDirection() * (getScreenPositionInScrollDirection(tab) - firstDyingTabOffset));
        if (tab.isDying()) {
            float discard = tab.getDiscardAmount();
            if (discard == 0.0f)
                discard = isDefaultDiscardDirectionPositive() ? 0.0f : -0.0f;
            float s = Math.copySign(1.0f, discard);
            long duration = (long) (DISCARD_ANIMATION_DURATION * (1.0f - Math.abs(discard / discardRange)));
            addAnimation(set, tab, DISCARD_AMOUNT, discard, discardRange * s, duration, startTime, false, interpolator);
        } else {
            if (tab.getDiscardAmount() != 0.f) {
                addAnimation(set, tab, DISCARD_AMOUNT, tab.getDiscardAmount(), 0.0f, UNDISCARD_ANIMATION_DURATION, 0);
            }
            float newScrollOffset = StackTab.screenToScroll(spacing * newIndex, warpSize);
            // put it in the right place.
            if (tab.getDiscardAmount() >= discardRange) {
                tab.setScrollOffset(newScrollOffset);
                tab.setScale(SCALE_AMOUNT);
            } else {
                float start = tab.getScrollOffset();
                if (start != newScrollOffset) {
                    addAnimation(set, tab, SCROLL_OFFSET, start, newScrollOffset, TAB_REORDER_DURATION, startTime);
                }
            }
            newIndex++;
        }
    }
    return set;
}
Also used : ChromeAnimation(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation) Animatable(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable) Interpolator(android.view.animation.Interpolator) BakedBezierInterpolator(org.chromium.ui.interpolators.BakedBezierInterpolator)

Example 2 with Animatable

use of org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable in project AndroidChromium by JackyAndroid.

the class StackAnimation method createFullRollAnimatorSet.

/**
 * Responsible for generating the animations that make all the tabs do a full roll.
 *
 * @param tabs The tabs that make up the stack. These are the tabs that will be affected by the
 *             animations.
 * @return     The TabSwitcherAnimation instance that will tween the tabs to create the
 *             appropriate animation.
 */
protected ChromeAnimation<?> createFullRollAnimatorSet(StackTab[] tabs) {
    ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>();
    for (int i = 0; i < tabs.length; ++i) {
        LayoutTab layoutTab = tabs[i].getLayoutTab();
        // Set the pivot
        layoutTab.setTiltX(layoutTab.getTiltX(), layoutTab.getScaledContentHeight() / 2.0f);
        layoutTab.setTiltY(layoutTab.getTiltY(), layoutTab.getScaledContentWidth() / 2.0f);
        // Create the angle animation
        addTiltScrollAnimation(set, layoutTab, -360.0f, FULL_ROLL_ANIMATION_DURATION, 0);
    }
    return set;
}
Also used : ChromeAnimation(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation) Animatable(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 3 with Animatable

use of org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable in project AndroidChromium by JackyAndroid.

the class StackAnimationLandscape method createTabFocusedAnimatorSet.

@Override
protected ChromeAnimation<?> createTabFocusedAnimatorSet(StackTab[] tabs, int focusIndex, int spacing, float warpSize) {
    ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>();
    for (int i = 0; i < tabs.length; ++i) {
        StackTab tab = tabs[i];
        LayoutTab layoutTab = tab.getLayoutTab();
        addTiltScrollAnimation(set, layoutTab, 0.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
        addAnimation(set, tab, DISCARD_AMOUNT, tab.getDiscardAmount(), 0.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
        if (i < focusIndex) {
            // For tabs left of the focused tab move them left to 0.
            addAnimation(set, tab, SCROLL_OFFSET, tab.getScrollOffset(), Math.max(0.0f, tab.getScrollOffset() - mWidth - spacing), TAB_FOCUSED_ANIMATION_DURATION, 0);
        } else if (i > focusIndex) {
            // We also need to animate the X Translation to move them right
            // off the screen.
            float coveringTabPosition = layoutTab.getX();
            float distanceToBorder = LocalizationUtils.isLayoutRtl() ? coveringTabPosition + layoutTab.getScaledContentWidth() : mWidth - coveringTabPosition;
            float clampedDistanceToBorder = MathUtils.clamp(distanceToBorder, 0, mWidth);
            float delay = TAB_FOCUSED_MAX_DELAY * clampedDistanceToBorder / mWidth;
            addAnimation(set, tab, X_IN_STACK_OFFSET, tab.getXInStackOffset(), tab.getXInStackOffset() + (LocalizationUtils.isLayoutRtl() ? -mWidth : mWidth), (TAB_FOCUSED_ANIMATION_DURATION - (long) delay), (long) delay);
        } else {
            // This is the focused tab.  We need to scale it back to
            // 1.0f, move it to the top of the screen, and animate the
            // X Translation so that it looks like it is zooming into the
            // full screen view.  We move the card to the top left and extend it out so
            // it becomes a full card.
            tab.setXOutOfStack(0);
            tab.setYOutOfStack(0.0f);
            layoutTab.setBorderScale(1.f);
            addAnimation(set, tab, SCROLL_OFFSET, tab.getScrollOffset(), StackTab.screenToScroll(0, warpSize), TAB_FOCUSED_ANIMATION_DURATION, 0);
            addAnimation(set, tab, SCALE, tab.getScale(), 1.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
            addAnimation(set, tab, X_IN_STACK_INFLUENCE, tab.getXInStackInfluence(), 0.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
            addAnimation(set, tab, Y_IN_STACK_INFLUENCE, tab.getYInStackInfluence(), 0.0f, TAB_FOCUSED_Y_STACK_DURATION, 0);
            addAnimation(set, tab.getLayoutTab(), MAX_CONTENT_HEIGHT, tab.getLayoutTab().getMaxContentHeight(), tab.getLayoutTab().getUnclampedOriginalContentHeight(), TAB_FOCUSED_ANIMATION_DURATION, 0);
            tab.setYOutOfStack(mHeight - mHeightMinusBrowserControls - mBorderTopHeight);
            if (layoutTab.shouldStall()) {
                addAnimation(set, layoutTab, SATURATION, 1.0f, 0.0f, TAB_FOCUSED_BORDER_ALPHA_DURATION, TAB_FOCUSED_BORDER_ALPHA_DELAY);
            }
            addAnimation(set, tab.getLayoutTab(), TOOLBAR_ALPHA, layoutTab.getToolbarAlpha(), 1.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_ALPHA_DELAY);
            addAnimation(set, tab.getLayoutTab(), TOOLBAR_Y_OFFSET, getToolbarOffsetToLineUpWithBorder(), 0.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_ALPHA_DELAY);
            addAnimation(set, tab.getLayoutTab(), SIDE_BORDER_SCALE, 1.f, 0.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_ALPHA_DELAY);
        }
    }
    return set;
}
Also used : ChromeAnimation(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation) Animatable(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Example 4 with Animatable

use of org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable in project AndroidChromium by JackyAndroid.

the class StackAnimationPortrait method createTabFocusedAnimatorSet.

@Override
protected ChromeAnimation<?> createTabFocusedAnimatorSet(StackTab[] tabs, int focusIndex, int spacing, float warpSize) {
    ChromeAnimation<Animatable<?>> set = new ChromeAnimation<Animatable<?>>();
    for (int i = 0; i < tabs.length; ++i) {
        StackTab tab = tabs[i];
        LayoutTab layoutTab = tab.getLayoutTab();
        addTiltScrollAnimation(set, layoutTab, 0.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
        addAnimation(set, tab, DISCARD_AMOUNT, tab.getDiscardAmount(), 0.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
        if (i < focusIndex) {
            // For tabs above the focused tab move them up to 0.
            addAnimation(set, tab, SCROLL_OFFSET, tab.getScrollOffset(), tab.getScrollOffset() - mHeight - spacing, TAB_FOCUSED_ANIMATION_DURATION, 0);
        } else if (i > focusIndex) {
            // We also need to animate the Y Translation to move them down
            // off the screen.
            float coveringTabPosition = layoutTab.getY();
            float distanceToBorder = MathUtils.clamp(mHeight - coveringTabPosition, 0, mHeight);
            float delay = TAB_FOCUSED_MAX_DELAY * distanceToBorder / mHeight;
            addAnimation(set, tab, Y_IN_STACK_OFFSET, tab.getYInStackOffset(), tab.getYInStackOffset() + mHeight, (TAB_FOCUSED_ANIMATION_DURATION - (long) delay), (long) delay);
        } else {
            // This is the focused tab.  We need to scale it back to
            // 1.0f, move it to the top of the screen, and animate the
            // YTranslation so that it looks like it is zooming into the
            // full screen view.
            tab.setXOutOfStack(0.0f);
            tab.setYOutOfStack(0.0f);
            layoutTab.setBorderScale(1.f);
            addAnimation(set, tab, SCROLL_OFFSET, tab.getScrollOffset(), Math.max(0.0f, tab.getScrollOffset() - mWidth - spacing), TAB_FOCUSED_ANIMATION_DURATION, 0);
            addAnimation(set, tab, SCALE, tab.getScale(), 1.0f, TAB_FOCUSED_ANIMATION_DURATION, 0);
            addAnimation(set, tab, Y_IN_STACK_INFLUENCE, tab.getYInStackInfluence(), 0.0f, TAB_FOCUSED_Y_STACK_DURATION, 0);
            addAnimation(set, tab.getLayoutTab(), MAX_CONTENT_HEIGHT, tab.getLayoutTab().getMaxContentHeight(), tab.getLayoutTab().getUnclampedOriginalContentHeight(), TAB_FOCUSED_ANIMATION_DURATION, 0);
            tab.setYOutOfStack(mHeight - mHeightMinusBrowserControls - mBorderTopHeight);
            if (layoutTab.shouldStall()) {
                addAnimation(set, layoutTab, SATURATION, 1.0f, 0.0f, TAB_FOCUSED_BORDER_ALPHA_DURATION, TAB_FOCUSED_BORDER_ALPHA_DELAY);
            }
            addAnimation(set, tab.getLayoutTab(), TOOLBAR_ALPHA, layoutTab.getToolbarAlpha(), 1.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_ALPHA_DELAY);
            addAnimation(set, tab.getLayoutTab(), TOOLBAR_Y_OFFSET, getToolbarOffsetToLineUpWithBorder(), 0.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_ALPHA_DELAY);
            addAnimation(set, tab.getLayoutTab(), SIDE_BORDER_SCALE, 1.f, 0.f, TAB_FOCUSED_TOOLBAR_ALPHA_DURATION, TAB_FOCUSED_TOOLBAR_ALPHA_DELAY);
        }
    }
    return set;
}
Also used : ChromeAnimation(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation) Animatable(org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable) LayoutTab(org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)

Aggregations

ChromeAnimation (org.chromium.chrome.browser.compositor.layouts.ChromeAnimation)4 Animatable (org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable)4 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)3 Interpolator (android.view.animation.Interpolator)1 BakedBezierInterpolator (org.chromium.ui.interpolators.BakedBezierInterpolator)1