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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelAnimation.java

Issue 1614513002: Refactor Contextual Search base classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more renaming Created 4 years, 11 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
Theresa 2016/01/21 00:39:02 Not sure if the copyright year gets updated when f
mdjones 2016/01/21 02:30:14 Done.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.compositor.bottombar.contextualsearch; 5 package org.chromium.chrome.browser.compositor.bottombar;
6 6
7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani matableAnimation.createAnimation; 7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani matableAnimation.createAnimation;
8 8
9 import android.content.Context; 9 import android.content.Context;
10 import android.view.animation.Interpolator; 10 import android.view.animation.Interpolator;
11 11
12 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; 12 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState;
13 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason; 13 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason;
14 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation; 14 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation;
15 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable ; 15 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable ;
16 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animation; 16 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animation;
17 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; 17 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
18 import org.chromium.chrome.browser.util.MathUtils; 18 import org.chromium.chrome.browser.util.MathUtils;
19 19
20 /** 20 /**
21 * Base abstract class for animating the Contextual Search Panel. 21 * Base abstract class for animating the Overlay Panel.
22 */ 22 */
23 public abstract class ContextualSearchPanelAnimation extends ContextualSearchPan elBase 23 public abstract class OverlayPanelAnimation extends OverlayPanelBase
24 implements Animatable<ContextualSearchPanelAnimation.Property> { 24 implements Animatable<OverlayPanelAnimation.Property> {
25 25
26 /** 26 /**
27 * Animation properties. 27 * Animation properties.
28 */ 28 */
29 protected enum Property { 29 protected enum Property {
30 PANEL_HEIGHT, 30 PANEL_HEIGHT,
31 PROMO_VISIBILITY, 31 PROMO_VISIBILITY,
32 BOTTOM_BAR_TEXT_VISIBILITY 32 BOTTOM_BAR_TEXT_VISIBILITY
33 } 33 }
34 34
35 /** 35 /**
36 * The base duration of animations in milliseconds. This value is based on 36 * The base duration of animations in milliseconds. This value is based on
37 * the Kennedy specification for slow animations. 37 * the Kennedy specification for slow animations.
38 */ 38 */
39 protected static final long BASE_ANIMATION_DURATION_MS = 218; 39 public static final long BASE_ANIMATION_DURATION_MS = 218;
40 40
41 /** 41 /**
42 * The maximum animation duration in milliseconds. 42 * The maximum animation duration in milliseconds.
43 */ 43 */
44 static final long MAXIMUM_ANIMATION_DURATION_MS = 350; 44 public static final long MAXIMUM_ANIMATION_DURATION_MS = 350;
45 45
46 /** 46 /**
47 * The minimum animation duration in milliseconds. 47 * The minimum animation duration in milliseconds.
48 */ 48 */
49 private static final long MINIMUM_ANIMATION_DURATION_MS = Math.round(7 * 100 0 / 60); 49 private static final long MINIMUM_ANIMATION_DURATION_MS = Math.round(7 * 100 0 / 60);
50 50
51 /** 51 /**
52 * Average animation velocity in dps per second. 52 * Average animation velocity in dps per second.
53 */ 53 */
54 private static final float INITIAL_ANIMATION_VELOCITY_DP_PER_SECOND = 1750f; 54 private static final float INITIAL_ANIMATION_VELOCITY_DP_PER_SECOND = 1750f;
(...skipping 29 matching lines...) Expand all
84 private boolean mIsAnimatingPanelClosing; 84 private boolean mIsAnimatingPanelClosing;
85 85
86 // ========================================================================= =================== 86 // ========================================================================= ===================
87 // Constructor 87 // Constructor
88 // ========================================================================= =================== 88 // ========================================================================= ===================
89 89
90 /** 90 /**
91 * @param context The current Android {@link Context}. 91 * @param context The current Android {@link Context}.
92 * @param updateHost The {@link LayoutUpdateHost} used to request updates in the Layout. 92 * @param updateHost The {@link LayoutUpdateHost} used to request updates in the Layout.
93 */ 93 */
94 public ContextualSearchPanelAnimation(Context context, LayoutUpdateHost upda teHost) { 94 public OverlayPanelAnimation(Context context, LayoutUpdateHost updateHost) {
95 super(context); 95 super(context);
96 mUpdateHost = updateHost; 96 mUpdateHost = updateHost;
97 } 97 }
98 98
99 // ========================================================================= =================== 99 // ========================================================================= ===================
100 // Animation API 100 // Animation API
101 // ========================================================================= =================== 101 // ========================================================================= ===================
102 102
103 /** 103 /**
104 * Notifies that the acceptance animation has finished. 104 * Notifies that the acceptance animation has finished.
105 */ 105 */
106 protected void onPromoAcceptanceAnimationFinished() { 106 protected void onPromoAcceptanceAnimationFinished() {
107 } 107 }
108 108
109 /** 109 /**
110 * Animates the Contextual Search Panel to its maximized state. 110 * Animates the Overlay Panel Panel to its maximized state.
Theresa 2016/01/21 00:39:02 Remove the extra "Panel" here and in other comment
mdjones 2016/01/21 02:30:14 Whoops. Done
111 * 111 *
112 * @param reason The reason for the change of panel state. 112 * @param reason The reason for the change of panel state.
113 */ 113 */
114 protected void maximizePanel(StateChangeReason reason) { 114 protected void maximizePanel(StateChangeReason reason) {
115 animatePanelToState(PanelState.MAXIMIZED, reason); 115 animatePanelToState(PanelState.MAXIMIZED, reason);
116 } 116 }
117 117
118 /** 118 /**
119 * Animates the Contextual Search Panel to its intermediary state. 119 * Animates the Overlay Panel Panel to its intermediary state.
120 * 120 *
121 * @param reason The reason for the change of panel state. 121 * @param reason The reason for the change of panel state.
122 */ 122 */
123 protected void expandPanel(StateChangeReason reason) { 123 protected void expandPanel(StateChangeReason reason) {
124 animatePanelToState(PanelState.EXPANDED, reason); 124 animatePanelToState(PanelState.EXPANDED, reason);
125 } 125 }
126 126
127 /** 127 /**
128 * Animates the Contextual Search Panel to its peeked state. 128 * Animates the Overlay Panel Panel to its peeked state.
129 * 129 *
130 * @param reason The reason for the change of panel state. 130 * @param reason The reason for the change of panel state.
131 */ 131 */
132 protected void peekPanel(StateChangeReason reason) { 132 protected void peekPanel(StateChangeReason reason) {
133 // Indicate to the Compositor that for now on the Panel should be 133 // Indicate to the Compositor that for now on the Panel should be
134 // rendered, until it's closed. 134 // rendered, until it's closed.
135 startShowing(); 135 startShowing();
136 136
137 // TODO(pedrosimonetti): Implement custom animation with the following v alues. 137 // TODO(pedrosimonetti): Implement custom animation with the following v alues.
138 // int SEARCH_BAR_ANIMATION_DURATION_MS = 218; 138 // int SEARCH_BAR_ANIMATION_DURATION_MS = 218;
(...skipping 19 matching lines...) Expand all
158 158
159 if (animate) { 159 if (animate) {
160 mIsAnimatingPanelClosing = true; 160 mIsAnimatingPanelClosing = true;
161 animatePanelToState(PanelState.CLOSED, reason); 161 animatePanelToState(PanelState.CLOSED, reason);
162 } else { 162 } else {
163 resizePanelToState(PanelState.CLOSED, reason); 163 resizePanelToState(PanelState.CLOSED, reason);
164 } 164 }
165 } 165 }
166 166
167 /** 167 /**
168 * Animates the Contextual Search Panel to a given |state| with a default du ration. 168 * Animates the Overlay Panel Panel to a given |state| with a default durati on.
169 * 169 *
170 * @param state The state to animate to. 170 * @param state The state to animate to.
171 * @param reason The reason for the change of panel state. 171 * @param reason The reason for the change of panel state.
172 */ 172 */
173 private void animatePanelToState(PanelState state, StateChangeReason reason) { 173 private void animatePanelToState(PanelState state, StateChangeReason reason) {
174 animatePanelToState(state, reason, BASE_ANIMATION_DURATION_MS); 174 animatePanelToState(state, reason, BASE_ANIMATION_DURATION_MS);
175 } 175 }
176 176
177 /** 177 /**
178 * Animates the Contextual Search Panel to a given |state| with a custom |du ration|. 178 * Animates the Overlay Panel Panel to a given |state| with a custom |durati on|.
179 * 179 *
180 * @param state The state to animate to. 180 * @param state The state to animate to.
181 * @param reason The reason for the change of panel state. 181 * @param reason The reason for the change of panel state.
182 * @param duration The animation duration in milliseconds. 182 * @param duration The animation duration in milliseconds.
183 */ 183 */
184 protected void animatePanelToState(PanelState state, StateChangeReason reaso n, long duration) { 184 protected void animatePanelToState(PanelState state, StateChangeReason reaso n, long duration) {
185 mAnimatingState = state; 185 mAnimatingState = state;
186 mAnimatingStateReason = reason; 186 mAnimatingStateReason = reason;
187 187
188 final float height = getPanelHeightFromState(state); 188 final float height = getPanelHeightFromState(state);
189 animatePanelTo(height, duration); 189 animatePanelTo(height, duration);
190 } 190 }
191 191
192 /** 192 /**
193 * Resizes the Contextual Search Panel to a given |state|. 193 * Resizes the Overlay Panel Panel to a given |state|.
194 * 194 *
195 * @param state The state to resize to. 195 * @param state The state to resize to.
196 * @param reason The reason for the change of panel state. 196 * @param reason The reason for the change of panel state.
197 */ 197 */
198 protected void resizePanelToState(PanelState state, StateChangeReason reason ) { 198 protected void resizePanelToState(PanelState state, StateChangeReason reason ) {
199 cancelHeightAnimation(); 199 cancelHeightAnimation();
200 200
201 final float height = getPanelHeightFromState(state); 201 final float height = getPanelHeightFromState(state);
202 setPanelHeight(height); 202 setPanelHeight(height);
203 setPanelState(state, reason); 203 setPanelState(state, reason);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 if (mUpdateHost != null) { 334 if (mUpdateHost != null) {
335 mUpdateHost.requestUpdate(); 335 mUpdateHost.requestUpdate();
336 } 336 }
337 } 337 }
338 338
339 // ========================================================================= =================== 339 // ========================================================================= ===================
340 // Animation Framework 340 // Animation Framework
341 // ========================================================================= =================== 341 // ========================================================================= ===================
342 342
343 /** 343 /**
344 * Animates the Contextual Search Panel to a given |height| with a custom |d uration|. 344 * Animates the Overlay Panel to a given |height| with a custom |duration|.
345 * 345 *
346 * @param height The height to animate to. 346 * @param height The height to animate to.
347 * @param duration The animation duration in milliseconds. 347 * @param duration The animation duration in milliseconds.
348 */ 348 */
349 private void animatePanelTo(float height, long duration) { 349 private void animatePanelTo(float height, long duration) {
350 animateProperty(Property.PANEL_HEIGHT, getHeight(), height, duration); 350 animateProperty(Property.PANEL_HEIGHT, getHeight(), height, duration);
351 } 351 }
352 352
353 /** 353 /**
354 * Animates the Contextual Search Panel. 354 * Animates the Overlay Panel.
355 * 355 *
356 * @param property The property which will be animated. 356 * @param property The property which will be animated.
357 * @param start The initial value. 357 * @param start The initial value.
358 * @param end The final value. 358 * @param end The final value.
359 * @param duration The animation duration in milliseconds. 359 * @param duration The animation duration in milliseconds.
360 */ 360 */
361 protected void animateProperty(Property property, float start, float end, lo ng duration) { 361 protected void animateProperty(Property property, float start, float end, lo ng duration) {
362 if (duration > 0) { 362 if (duration > 0) {
363 if (animationIsRunning()) { 363 if (animationIsRunning()) {
364 cancelAnimation(this, property); 364 cancelAnimation(this, property);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 439
440 mAnimatingState = PanelState.UNDEFINED; 440 mAnimatingState = PanelState.UNDEFINED;
441 mAnimatingStateReason = StateChangeReason.UNKNOWN; 441 mAnimatingStateReason = StateChangeReason.UNKNOWN;
442 } 442 }
443 443
444 /** 444 /**
445 * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn imation.Animatable} 445 * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn imation.Animatable}
446 * and adds it to the animation. 446 * and adds it to the animation.
447 * Automatically sets the start value at the beginning of the animation. 447 * Automatically sets the start value at the beginning of the animation.
448 */ 448 */
449 protected <T extends Enum<?>> void addToAnimation(Animatable<T> object, T pr op, float start, 449 public <T extends Enum<?>> void addToAnimation(Animatable<T> object, T prop, float start,
450 float end, long duration, long startTime) { 450 float end, long duration, long startTime) {
451 addToAnimation(object, prop, start, end, duration, startTime, false); 451 addToAnimation(object, prop, start, end, duration, startTime, false);
452 } 452 }
453 453
454 /** 454 /**
455 * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn imation.Animatable} 455 * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn imation.Animatable}
456 * and adds it to the animation. Uses a deceleration interpolator by default . 456 * and adds it to the animation. Uses a deceleration interpolator by default .
457 */ 457 */
458 protected <T extends Enum<?>> void addToAnimation(Animatable<T> object, T pr op, float start, 458 public <T extends Enum<?>> void addToAnimation(Animatable<T> object, T prop, float start,
459 float end, long duration, long startTime, boolean setStartValueAfter Delay) { 459 float end, long duration, long startTime, boolean setStartValueAfter Delay) {
460 addToAnimation(object, prop, start, end, duration, startTime, setStartVa lueAfterDelay, 460 addToAnimation(object, prop, start, end, duration, startTime, setStartVa lueAfterDelay,
461 ChromeAnimation.getDecelerateInterpolator()); 461 ChromeAnimation.getDecelerateInterpolator());
462 } 462 }
463 463
464 /** 464 /**
465 * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn imation.Animatable} 465 * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn imation.Animatable}
466 * and adds it to the animation. 466 * and adds it to the animation.
467 * 467 *
468 * @param <T> The Enum type of the Property being used 468 * @param <T> The Enum type of the Property being used
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 * Cancels any animation for the given object and property. 509 * Cancels any animation for the given object and property.
510 * @param object The object being animated. 510 * @param object The object being animated.
511 * @param prop The property to search for. 511 * @param prop The property to search for.
512 */ 512 */
513 protected <T extends Enum<?>> void cancelAnimation(Animatable<T> object, T p rop) { 513 protected <T extends Enum<?>> void cancelAnimation(Animatable<T> object, T p rop) {
514 if (mLayoutAnimations != null) { 514 if (mLayoutAnimations != null) {
515 mLayoutAnimations.cancel(object, prop); 515 mLayoutAnimations.cancel(object, prop);
516 } 516 }
517 } 517 }
518 } 518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698