| 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..c6a05fbc5fb5cc2a0020a3063a868e4cd2d7a9d6
|
| --- /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;
|
| +
|
| + /**
|
| + * 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 ContextualSearchPanel mPanel;
|
| +
|
| +
|
| + /**
|
| + * @param panel The panel delegate.
|
| + * @param context The Android Context used to retrieve resources.
|
| + */
|
| + public ContextualSearchSearchProviderIconSpriteControl(
|
| + 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 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;
|
| + 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) {
|
| + mSpriteFrame = (int) (value * LAST_SPRITE_FRAME);
|
| + }
|
| + }
|
| +
|
| +}
|
|
|