Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchIconSpriteControl.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchIconSpriteControl.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchIconSpriteControl.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..62ce574a84062d791775b2cb22c7b165b5dbefeb |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchIconSpriteControl.java |
| @@ -0,0 +1,135 @@ |
| +// 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 ContextualSearchIconSpriteControl implements |
| + ChromeAnimation.Animatable<ContextualSearchIconSpriteControl.AnimationType> { |
| + |
| + /** |
| + * 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 completion percentage for the animation; used to calculate which sprite frame to display. |
| + */ |
| + private float mCompletionPercentage; |
| + |
| + /** |
| + * The size to use for display of the search provider icon sprite in px. |
| + */ |
| + private float mSize; |
|
pedro (no code reviews)
2015/10/29 17:01:42
nit: For consistency, rename this to mSizePx. Curr
Theresa
2015/10/29 17:44:09
Done.
|
| + |
| + /** |
| + * The panel delegate. |
|
pedro (no code reviews)
2015/10/29 17:01:42
nit: Remove "delegate". We're now using the full p
Theresa
2015/10/29 17:44:09
Done.
|
| + */ |
| + private ContextualSearchPanel mPanel; |
| + |
| + |
| + /** |
| + * @param panel The panel delegate. |
| + * @param context The Android Context used to retrieve resources. |
| + */ |
| + public ContextualSearchIconSpriteControl( |
| + ContextualSearchPanel panel, Context context) { |
| + mSize = context.getResources().getDimension(R.dimen.contextual_search_sprite_size); |
| + mPanel = 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 completion percentage for the animation; used to calculate which sprite frame |
| + * to display. |
| + */ |
| + public float getCompletionPercentage() { |
| + return mCompletionPercentage; |
| + } |
| + |
| + /** |
| + * @return The size to use for display of the search provider icon sprite in px. |
| + */ |
| + public float getSize() { |
|
pedro (no code reviews)
2015/10/29 17:01:42
nit: Similarly, call this getSizePx()
Theresa
2015/10/29 17:44:09
Done.
|
| + 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; |
| + mCompletionPercentage = 0.f; |
| + } else { |
| + mIsVisible = true; |
| + mCompletionPercentage = 1.f; |
| + } |
| + 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; |
| + mPanel.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) { |
| + mCompletionPercentage = value; |
| + } |
| + } |
| + |
| +} |