| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
|
| index d08874dbf6936e08edc6cdfe4a8ecb26cbb26151..76f58a85a49efe3f64f7d403db88c2901c09b581 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
|
| @@ -5,6 +5,7 @@
|
| package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
|
|
|
| import android.content.Context;
|
| +import android.content.res.TypedArray;
|
| import android.os.Handler;
|
| import android.view.LayoutInflater;
|
| import android.view.View;
|
| @@ -23,6 +24,8 @@ import org.chromium.chrome.browser.util.MathUtils;
|
| import org.chromium.ui.base.LocalizationUtils;
|
| import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
|
|
|
| +import java.util.ArrayList;
|
| +
|
| /**
|
| * Base abstract class for the Contextual Search Panel.
|
| */
|
| @@ -760,6 +763,165 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
|
| }
|
|
|
| // --------------------------------------------------------------------------------------------
|
| + // Search provider icon states
|
| + // --------------------------------------------------------------------------------------------
|
| +
|
| + private static final int SEARCH_PROVIDER_ICON_LAST_SPRITE_FRAME = 18;
|
| +
|
| + private boolean mIsSearchProviderIconSpriteVisible;
|
| + private boolean mShouldAnimateSearchProviderIconSprite;
|
| + private int mSearchProviderIconSpriteFrame;
|
| + private int mSearchProviderIconSpritePreviousFrame;
|
| + private TypedArray mSearchProviderIconSpriteFrameRectsArray;
|
| +
|
| + /**
|
| + * @return Whether the search provider icon sprite is visible.
|
| + */
|
| + public boolean isSearchProviderIconSpriteVisible() {
|
| + return mIsSearchProviderIconSpriteVisible;
|
| + }
|
| +
|
| + /**
|
| + * @param isSearchProviderIconSpriteVisible Whether the search provider icon sprite should be
|
| + * visible.
|
| + */
|
| + public void setIsSearchProviderIconSpriteVisible(boolean isSearchProviderIconSpriteVisible) {
|
| + mIsSearchProviderIconSpriteVisible = isSearchProviderIconSpriteVisible;
|
| + }
|
| +
|
| + /**
|
| + * @return Whether the search provider icon sprite should be animated.
|
| + */
|
| + public boolean shouldAnimateSearchProviderIconSprite() {
|
| + return mShouldAnimateSearchProviderIconSprite;
|
| + }
|
| +
|
| + /**
|
| + * @param shouldAnimateSearchProviderIconSprite Whether the search provider icon sprite should
|
| + * be animated.
|
| + */
|
| + public void setShouldAnimateSearchProviderIconSprite(
|
| + boolean shouldAnimateSearchProviderIconSprite) {
|
| + mSearchProviderIconSpritePreviousFrame = 0;
|
| + if (shouldAnimateSearchProviderIconSprite) {
|
| + mIsSearchProviderIconSpriteVisible = false;
|
| + mSearchProviderIconSpriteFrame = 0;
|
| + } else {
|
| + mIsSearchProviderIconSpriteVisible = true;
|
| + mSearchProviderIconSpriteFrame = SEARCH_PROVIDER_ICON_LAST_SPRITE_FRAME;
|
| + }
|
| + mShouldAnimateSearchProviderIconSprite = shouldAnimateSearchProviderIconSprite;
|
| + }
|
| +
|
| + /**
|
| + * @return The size of the search provider icon sprite in px.
|
| + */
|
| + public float getSearchProviderIconSpriteSize() {
|
| + return mContext.getResources().getDimension(R.dimen.contextual_search_sprite_size);
|
| + }
|
| +
|
| + /**
|
| + * Each search provider icon sprite frame is represented by a set of rectangles. Most frames
|
| + * consist of small rectangles representing the change from the previous frame.
|
| + * Each rectangle is represented using six consecutive values that specify the values to be used
|
| + * when creating the destination and source rectangles that get painted:
|
| + * 0: destination x 1: destination y 2: source x 3: source y 4: width 5: height
|
| + *
|
| + * @return The rectangles that need to be painted for the current sprite frame.
|
| + */
|
| + public int[] getSearchProviderIconSpriteFrameRects() {
|
| + int[] results = null;
|
| +
|
| + if (mSearchProviderIconSpriteFrame != mSearchProviderIconSpritePreviousFrame
|
| + || !getSearchProviderIconSpritePaintPreviousFrames()) {
|
| +
|
| + // Initialize mSearchProviderIconSpriteFrameRectsArray if necessary.
|
| + if (mSearchProviderIconSpriteFrameRectsArray == null) {
|
| + mSearchProviderIconSpriteFrameRectsArray = mContext.getResources().obtainTypedArray(
|
| + R.array.contextual_search_sprite_frame_rects);
|
| + }
|
| +
|
| + // Get the rectangles for the current frame.
|
| + int[] currentFrameRects = null;
|
| + int currentFrameRectsId = mSearchProviderIconSpriteFrameRectsArray.getResourceId(
|
| + mSearchProviderIconSpriteFrame, 0);
|
| + if (currentFrameRectsId != 0) {
|
| + currentFrameRects = mContext.getResources().getIntArray(currentFrameRectsId);
|
| + }
|
| +
|
| + // If we skipped some frames in the animation, we need to paint the rectangles
|
| + // for those frames if getSearchProviderIconSpritePaintPreviousFrames() is true.
|
| + if (mSearchProviderIconSpriteFrame != mSearchProviderIconSpritePreviousFrame + 1
|
| + && getSearchProviderIconSpritePaintPreviousFrames()) {
|
| + ArrayList<int[]> allFrameRects = new ArrayList<int[]>();
|
| + int totalNumberOfRects = 0;
|
| +
|
| + // For each frame that was skipped, get the frame's rectangles from
|
| + // mSearchProviderIconSpriteFrameRectsArray and append them to the list of
|
| + // allFrameRects.
|
| + for (int frame = mSearchProviderIconSpritePreviousFrame + 1;
|
| + frame < mSearchProviderIconSpriteFrame; frame++) {
|
| + int frameRectsId =
|
| + mSearchProviderIconSpriteFrameRectsArray.getResourceId(frame, 0);
|
| + if (frameRectsId != 0) {
|
| + int[] frameRects = mContext.getResources().getIntArray(frameRectsId);
|
| + allFrameRects.add(frameRects);
|
| + totalNumberOfRects += frameRects.length;
|
| + }
|
| + }
|
| +
|
| + // Append the rectangles for the current frame.
|
| + if (currentFrameRects != null) {
|
| + allFrameRects.add(currentFrameRects);
|
| + totalNumberOfRects += currentFrameRects.length;
|
| + }
|
| +
|
| + // Merge the rectangles for each frame into one int[].
|
| + results = new int[totalNumberOfRects];
|
| + int index = 0;
|
| + for (int[] frameRects : allFrameRects) {
|
| + System.arraycopy(frameRects, 0, results, index, frameRects.length);
|
| + index = frameRects.length;
|
| + }
|
| + } else {
|
| + results = currentFrameRects;
|
| + }
|
| + }
|
| +
|
| + mSearchProviderIconSpritePreviousFrame = mSearchProviderIconSpriteFrame;
|
| + return (results != null) ? results : new int[] {};
|
| + }
|
| +
|
| + /**
|
| + * Sets the sprite frame to display based on the completion percentage.
|
| + *
|
| + * @param percentage The completion percentage.
|
| + */
|
| + public void setSearchProviderIconAnimationCompletion(float percentage) {
|
| + mSearchProviderIconSpriteFrame =
|
| + (int) (percentage * SEARCH_PROVIDER_ICON_LAST_SPRITE_FRAME);
|
| + }
|
| +
|
| + /**
|
| + * The sprite frames in the search provider icon sprite are created by painting a
|
| + * set of rectangles on top of the previous frames, with the exception of the first and last
|
| + * frame.
|
| + *
|
| + * @return Whether the previous sprite frames should be painted.
|
| + */
|
| + public boolean getSearchProviderIconSpritePaintPreviousFrames() {
|
| + return mSearchProviderIconSpriteFrame != 0
|
| + && mSearchProviderIconSpriteFrame != SEARCH_PROVIDER_ICON_LAST_SPRITE_FRAME;
|
| + }
|
| +
|
| + /**
|
| + * @return The number of frames in the search provider icon sprite.
|
| + */
|
| + public int getSearchProviderIconSpriteFrameCount() {
|
| + return SEARCH_PROVIDER_ICON_LAST_SPRITE_FRAME + 1;
|
| + }
|
| +
|
| + // --------------------------------------------------------------------------------------------
|
| // Promo states
|
| // --------------------------------------------------------------------------------------------
|
|
|
|
|