Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPeekPromoControl.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPeekPromoControl.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPeekPromoControl.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..39ca4f1e34f26b9c709457154113fcac8145da0e |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPeekPromoControl.java |
| @@ -0,0 +1,163 @@ |
| +// 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 android.view.ViewGroup; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation; |
| +import org.chromium.chrome.browser.util.MathUtils; |
| +import org.chromium.ui.resources.dynamics.DynamicResourceLoader; |
| + |
| +/** |
| + * Controls the Search Peek Promo. |
| + */ |
| +public class ContextualSearchPeekPromoControl extends ContextualSearchInflater |
| + implements ChromeAnimation.Animatable<ContextualSearchPeekPromoControl.AnimationType> { |
| + |
| + /** |
| + * Animation properties. |
| + */ |
| + protected enum AnimationType { |
| + APPEARANCE |
| + } |
| + |
| + private static final float RIPPLE_MINIMUM_WIDTH_DP = 56.f; |
| + |
| + private boolean mIsVisible; |
| + private float mHeightPx; |
| + private final float mPaddingPx; |
|
David Trainor- moved to gerrit
2015/10/02 20:49:20
can we group these finals together. and move the
pedro (no code reviews)
2015/10/02 22:15:57
Done.
|
| + private float mRippleWidthPx; |
| + private float mRippleOpacity; |
| + private float mTextOpacity; |
| + |
| + private final float mDefaultHeightPx; |
| + private final float mRippleMinimumWidthPx; |
| + private final float mRippleMaximumWidthPx; |
| + |
| + // TODO(pedrosimonetti): DO NOT SUBMIT. Add JavaDoc. |
| + |
| + /** |
| + * @param panel The panel delegate. |
| + * @param context The Android Context used to inflate the View. |
| + * @param container The container View used to inflate the View. |
| + * @param resourceLoader The resource loader that will handle the snapshot capturing. |
| + */ |
| + public ContextualSearchPeekPromoControl(ContextualSearchPanelDelegate panel, |
| + Context context, |
|
David Trainor- moved to gerrit
2015/10/02 20:49:20
fix indent.
pedro (no code reviews)
2015/10/02 22:15:57
Oops.
|
| + ViewGroup container, |
| + DynamicResourceLoader resourceLoader) { |
| + super(panel, R.layout.contextual_search_peek_promo, R.id.contextual_search_peek_promo, |
| + context, container, resourceLoader); |
| + |
| + final float dpToPx = context.getResources().getDisplayMetrics().density; |
| + |
| + mDefaultHeightPx = context.getResources().getDimensionPixelOffset( |
| + R.dimen.contextual_search_peek_promo_height); |
| + mPaddingPx = context.getResources().getDimensionPixelOffset( |
| + R.dimen.contextual_search_peek_promo_padding); |
| + |
| + mRippleMinimumWidthPx = RIPPLE_MINIMUM_WIDTH_DP * dpToPx; |
| + mRippleMaximumWidthPx = panel.getMaximumWidthPx(); |
| + } |
| + |
| + void show() { |
|
David Trainor- moved to gerrit
2015/10/02 20:49:20
moar javadocz
pedro (no code reviews)
2015/10/02 22:15:57
Done.
|
| + if (mIsVisible) return; |
| + |
| + mIsVisible = true; |
| + mHeightPx = Math.round(mDefaultHeightPx); |
| + |
| + invalidate(); |
| + } |
| + |
| + void hide() { |
| + if (!mIsVisible) return; |
| + |
| + mIsVisible = false; |
| + mHeightPx = 0.f; |
| + } |
| + |
| + // ============================================================================================ |
| + // Public API |
| + // ============================================================================================ |
| + |
| + public boolean isVisible() { |
| + return mIsVisible; |
| + } |
| + |
| + public float getHeightPx() { |
| + return mHeightPx; |
| + } |
| + |
| + public float getPaddingPx() { |
| + return mPaddingPx; |
| + } |
| + |
| + public float getRippleWidthPx() { |
| + return mRippleWidthPx; |
| + } |
| + |
| + public float getRippleOpacity() { |
| + return mRippleOpacity; |
| + } |
| + |
| + public float getTextOpacity() { |
| + return mTextOpacity; |
| + } |
| + |
| + // ============================================================================================ |
| + // Panel Animation |
| + // ============================================================================================ |
| + |
| + public void onUpdateFromCloseToPeek(float percentage) { |
| + if (!isVisible()) return; |
| + |
| + mHeightPx = Math.round(mDefaultHeightPx); |
| + } |
| + |
| + public void onUpdateFromPeekToExpand(float percentage) { |
| + if (!isVisible()) return; |
| + |
| + mHeightPx = Math.round(MathUtils.interpolate(mDefaultHeightPx, 0.f, percentage)); |
| + mTextOpacity = MathUtils.interpolate(1.f, 0.f, percentage); |
| + } |
| + |
| + public void onUpdateFromExpandToMaximize(float percentage) { |
| + if (!isVisible()) return; |
| + |
| + mHeightPx = 0.f; |
| + mTextOpacity = 0.f; |
| + } |
| + |
| + // ============================================================================================ |
| + // Peek Promo Appearance Animation |
| + // ============================================================================================ |
| + |
| + public void animateAppearance() { |
| + // TODO(pedrosimonetti): Find a generic way to tell when a specific animation finishes. |
| + mSearchPanelDelegate.addToAnimation(this, AnimationType.APPEARANCE, 0.f, 1.f, |
| + ContextualSearchPanelAnimation.BASE_ANIMATION_DURATION_MS, 0); |
| + } |
| + |
| + @Override |
| + public void setProperty(AnimationType prop, float val) { |
| + if (prop == AnimationType.APPEARANCE) { |
| + updateForAppearanceAnimation(val); |
| + } |
| + } |
| + |
| + private void updateForAppearanceAnimation(float percentage) { |
| + mRippleWidthPx = Math.round(MathUtils.interpolate( |
| + mRippleMinimumWidthPx, mRippleMaximumWidthPx, percentage)); |
| + |
| + mRippleOpacity = MathUtils.interpolate(0.f, 1.f, percentage); |
| + |
| + float textOpacityDelay = 0.5f; |
| + float textOpacityPercentage = |
| + Math.max(0, percentage - textOpacityDelay) / (1.f - textOpacityDelay); |
| + mTextOpacity = MathUtils.interpolate(0.f, 1.f, textOpacityPercentage); |
| + } |
| +} |