Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchSearchProviderIconSpriteControl.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchSearchProviderIconSpriteControl.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchSearchProviderIconSpriteControl.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e2cd154570af7a5d88edd0b8e45168b0c273ad6e |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchSearchProviderIconSpriteControl.java |
| @@ -0,0 +1,139 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.compositor.bottombar.contextualsearch; |
| + |
| +import android.content.Context; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation; |
| + |
| +/** |
| + * Controls the search provider icon sprite. |
| + */ |
| +public class ContextualSearchSearchProviderIconSpriteControl implements |
| + ChromeAnimation.Animatable<ContextualSearchSearchProviderIconSpriteControl.AnimationType> { |
| + |
| + /** |
| + * The index of the last frame in the search provider icon sprite animation. |
| + */ |
| + private static final int LAST_SPRITE_FRAME = 18; |
|
David Trainor- moved to gerrit
2015/10/15 21:04:57
Can we pull this from the int arrays? Or can we u
Theresa
2015/10/24 00:06:44
We could pass the animation completion percent and
Theresa
2015/10/24 00:24:36
Per an offline discussion w/ Pedro, I'll change it
pedro (no code reviews)
2015/10/24 00:29:00
I agree with David here too. We shouldn't hardcode
Theresa
2015/10/27 19:48:02
Done.
|
| + |
| + /** |
| + * Animation properties. |
| + */ |
| + protected enum AnimationType { |
| + APPEARANCE |
| + } |
| + |
| + /** |
| + * Whether the search provider icon sprite is visible. |
| + */ |
| + private boolean mIsVisible; |
| + |
| + /** |
| + * Whether the appearance of the search provider icon sprite should be animated. |
| + */ |
| + private boolean mShouldAnimateAppearance; |
| + |
| + /** |
| + * The current search provider icon sprite frame to display. |
| + */ |
| + private int mSpriteFrame; |
| + |
| + /** |
| + * The size to use for display of the search provider icon sprite in px. |
| + */ |
| + private float mSize; |
| + |
| + /** |
| + * The panel delegate. |
| + */ |
| + private ContextualSearchPanelDelegate mPanelDelegate; |
| + |
| + |
| + /** |
| + * @param panel The panel delegate. |
| + * @param context The Android Context used to retrieve resources. |
| + */ |
| + public ContextualSearchSearchProviderIconSpriteControl( |
| + ContextualSearchPanelDelegate panel, Context context) { |
| + mSize = context.getResources().getDimension(R.dimen.contextual_search_sprite_size); |
| + mPanelDelegate = panel; |
| + } |
| + |
| + /** |
| + * @return Whether the search provider icon sprite is visible. |
| + */ |
| + public boolean isVisible() { |
| + return mIsVisible; |
| + } |
| + |
| + /** |
| + * @param isVisible Whether the search provider icon sprite should be visible. |
| + */ |
| + public void setIsVisible(boolean isVisible) { |
| + mIsVisible = isVisible; |
| + } |
| + |
| + /** |
| + * @return The current search provider icon sprite frame to display. |
| + */ |
| + public int getSpriteFrame() { |
| + return mSpriteFrame; |
| + } |
| + |
| + /** |
| + * @return The size to use for display of the search provider icon sprite in px. |
| + */ |
| + public float getSize() { |
| + return mSize; |
| + } |
| + |
| + /** |
| + * @return Whether the appearance of the search provider icon sprite should be animated. |
| + */ |
| + public boolean shouldAnimateAppearance() { |
| + return mShouldAnimateAppearance; |
| + } |
| + |
| + /** |
| + * @param shouldAnimateAppearance Whether the appearance of the search provider icon sprite |
| + * should be animated. |
| + */ |
| + public void setShouldAnimateAppearance(boolean shouldAnimateAppearance) { |
| + if (shouldAnimateAppearance) { |
| + // The search provider icon sprite should be hidden until the animation starts. |
| + mIsVisible = false; |
| + mSpriteFrame = 0; |
| + } else { |
| + mIsVisible = true; |
| + mSpriteFrame = LAST_SPRITE_FRAME; |
| + } |
| + mShouldAnimateAppearance = shouldAnimateAppearance; |
| + } |
| + |
| + // ============================================================================================ |
| + // Search Provider Icon Sprite Appearance Animation |
| + // ============================================================================================ |
| + |
| + /** |
| + * Animates the appearance of the search provider icon sprite. This should be called after the |
| + * panel open animation has finished. |
| + */ |
| + public void animateApperance() { |
| + // The search provider icon sprite should be visible once the animation starts. |
| + mIsVisible = true; |
| + mPanelDelegate.addToAnimation(this, AnimationType.APPEARANCE, 0.f, 1.f, |
| + ContextualSearchPanelAnimation.MAXIMUM_ANIMATION_DURATION_MS, 0); |
| + } |
| + |
| + @Override |
| + public void setProperty(AnimationType type, float value) { |
| + if (type == AnimationType.APPEARANCE) { |
| + mSpriteFrame = (int) (value * LAST_SPRITE_FRAME); |
| + } |
| + } |
| + |
| +} |