Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1021)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/compositor/layouts/phone/stack/StackViewAnimation.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.compositor.layouts.phone.stack;
6
7 import android.animation.AnimatorSet;
8 import android.animation.ObjectAnimator;
9 import android.view.View;
10 import android.view.ViewGroup;
11 import android.view.ViewGroup.LayoutParams;
12 import android.widget.FrameLayout;
13
14 import org.chromium.chrome.browser.Tab;
15 import org.chromium.chrome.browser.compositor.layouts.phone.stack.StackAnimation .OverviewAnimationType;
16 import org.chromium.chrome.browser.tabmodel.TabModel;
17 import org.chromium.ui.base.LocalizationUtils;
18 import org.chromium.ui.interpolators.BakedBezierInterpolator;
19
20 /**
21 * A factory that builds Android view animations for the tab stack.
22 */
23 public class StackViewAnimation {
24 private static final int TAB_OPENED_ANIMATION_DURATION = 300;
25 private static final float TAB_OPENED_PIVOT_INSET_DP = 24.f;
26
27 private final float mDpToPx;
28 private final float mWidthDp;
29
30 /**
31 * Constructor.
32 * NOTE: Pass in height and heightMinusTopControls if they're ever needed.
33 *
34 * @param dpToPx The density of the device.
35 * @param widthDp The width of the layout in dp.
36 */
37 public StackViewAnimation(float dpToPx, float widthDp) {
38 mDpToPx = dpToPx;
39 mWidthDp = widthDp;
40 }
41
42 /**
43 * The wrapper method responsible for delegating animation requests to the a ppropriate helper
44 * method.
45 * @param type The type of animation to be created. This is what dete rmines which helper
46 * method is called.
47 * @param tabs The tabs that make up the current stack.
48 * @param container The {@link ViewGroup} that {@link View}s can be added t o/removed from.
49 * @param model The {@link TabModel} that this animation will influence .
50 * @param focusIndex The index of the tab that is the focus of this animatio n.
51 * @return The resulting {@link AnimatorSet} that will animate the Android views.
52 */
53 public AnimatorSet createAnimatorSetForType(OverviewAnimationType type, Stac kTab[] tabs,
54 ViewGroup container, TabModel model, int focusIndex) {
55 AnimatorSet set = null;
56
57 if (model != null) {
58 switch (type) {
59 case NEW_TAB_OPENED:
60 set = createNewTabOpenedAnimatorSet(tabs, container, model, focusIndex);
61 break;
62 default:
63 break;
64 }
65 }
66
67 return set;
68 }
69
70 private AnimatorSet createNewTabOpenedAnimatorSet(
71 StackTab[] tabs, ViewGroup container, TabModel model, int focusIndex ) {
72 Tab tab = model.getTabAt(focusIndex);
73 if (tab == null || !tab.isNativePage()) return null;
74
75 View view = tab.getView();
76 if (view == null) return null;
77
78 // Set up the view hierarchy
79 if (view.getParent() != null) ((ViewGroup) view.getParent()).removeView( view);
80 ViewGroup bgView = new FrameLayout(view.getContext());
81 bgView.setBackgroundColor(tab.getBackgroundColor());
82 bgView.addView(view);
83 container.addView(
84 bgView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams .MATCH_PARENT));
85
86 // Update any compositor state that needs to change
87 if (tabs != null && focusIndex >= 0 && focusIndex < tabs.length) {
88 tabs[focusIndex].setAlpha(0.f);
89 }
90
91 // Build the view animations
92 ObjectAnimator xScale = ObjectAnimator.ofFloat(bgView, View.SCALE_X, 0.f , 1.f);
93 ObjectAnimator yScale = ObjectAnimator.ofFloat(bgView, View.SCALE_Y, 0.f , 1.f);
94 ObjectAnimator alpha = ObjectAnimator.ofFloat(bgView, View.ALPHA, 0.f, 1 .f);
95
96 AnimatorSet set = new AnimatorSet();
97 set.playTogether(xScale, yScale, alpha);
98
99 set.setDuration(TAB_OPENED_ANIMATION_DURATION);
100 set.setInterpolator(BakedBezierInterpolator.TRANSFORM_FOLLOW_THROUGH_CUR VE);
101
102 float insetPx = TAB_OPENED_PIVOT_INSET_DP * mDpToPx;
103
104 bgView.setPivotY(TAB_OPENED_PIVOT_INSET_DP);
105 bgView.setPivotX(LocalizationUtils.isLayoutRtl() ? mWidthDp * mDpToPx - insetPx : insetPx);
106 return set;
107 }
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698