Chromium Code Reviews| 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 f28b82e0f5b6dc0319c9a920b58d0a2f2a557dac..aa8551beb9e87fb71a2a5e9ec8b3988c4566dfdf 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 |
| @@ -10,6 +10,7 @@ import android.view.LayoutInflater; |
| import android.view.View; |
| import android.view.ViewGroup; |
| +import org.chromium.base.ApiCompatibilityUtils; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchOptOutPromo.ContextualSearchPromoHost; |
| @@ -18,7 +19,9 @@ import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context |
| import org.chromium.chrome.browser.contextualsearch.ContextualSearchFieldTrial; |
| import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| import org.chromium.chrome.browser.preferences.privacy.ContextualSearchPreferenceFragment; |
| +import org.chromium.chrome.browser.util.FeatureUtilities; |
| import org.chromium.chrome.browser.util.MathUtils; |
| +import org.chromium.ui.base.LocalizationUtils; |
| import org.chromium.ui.resources.dynamics.DynamicResourceLoader; |
| /** |
| @@ -124,6 +127,26 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl |
| private static final float ARROW_ICON_ROTATION_EXPANDED = -270.f; |
| /** |
| + * The opacity of the close icon when the Panel is peeking. |
| + */ |
| + private static final float CLOSE_ICON_OPACITY_PEEKED = 0.f; |
| + |
| + /** |
| + * The opacity of the close icon when the Panel is expanded. |
| + */ |
| + private static final float CLOSE_ICON_OPACITY_EXPANDED = 0.f; |
| + |
| + /** |
| + * The opacity of the close icon when the Panel is maximized. |
| + */ |
| + private static final float CLOSE_ICON_OPACITY_MAXIMIZED = 1.f; |
| + |
| + /** |
| + * The id of the close icon drawable. |
| + */ |
| + public static final int CLOSE_ICON_DRAWABLE_ID = R.drawable.btn_close; |
| + |
| + /** |
| * The height of the Progress Bar in dps. |
| */ |
| private static final float PROGRESS_BAR_HEIGHT_DP = 2.f; |
| @@ -435,6 +458,9 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl |
| private float mArrowIconOpacity; |
| private float mArrowIconRotation; |
| + private float mCloseIconOpacity; |
| + private float mCloseIconWidth; |
| + |
| /** |
| * @return The top margin of the Contextual Search Bar. |
| */ |
| @@ -533,6 +559,51 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl |
| return mArrowIconRotation; |
| } |
| + /** |
| + * @return Whether the close icon is visible. |
| + */ |
| + public boolean isCloseIconVisible() { |
| + // TODO(twellington): replace this call with call to new feature helper |
| + // (isCloseButtonAvailable). |
| + return FeatureUtilities.getCustomTabVisible(); |
| + } |
| + |
| + /** |
| + * @return The opacity of the close icon. |
| + */ |
| + public float getCloseIconOpacity() { |
| + return mCloseIconOpacity; |
| + } |
| + |
| + /** |
| + * @return The width/height of the close icon. |
| + */ |
| + public float getCloseIconDimension() { |
| + if (mCloseIconWidth == 0) { |
| + mCloseIconWidth = ApiCompatibilityUtils.getDrawable(mContext.getResources(), |
| + CLOSE_ICON_DRAWABLE_ID).getIntrinsicWidth() * mPxToDp; |
| + } |
| + return mCloseIconWidth; |
| + } |
| + |
| + /** |
| + * @return The Y coordinate of the close icon. |
| + */ |
| + public float getCloseIconY() { |
| + return (getSearchBarHeight() - getCloseIconDimension()) / 2; |
| + } |
| + |
| + /** |
| + * @return The X coordinate of the close icon. |
| + */ |
| + public float getCloseIconX() { |
| + if (LocalizationUtils.isLayoutRtl()) { |
| + return getSearchBarMarginSide(); |
| + } else { |
| + return getWidth() - getSearchBarMarginSide() - getCloseIconDimension(); |
| + } |
| + } |
| + |
| // -------------------------------------------------------------------------------------------- |
| // Base Page states |
| // -------------------------------------------------------------------------------------------- |
| @@ -912,6 +983,9 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl |
| mArrowIconOpacity = ARROW_ICON_OPACITY_PEEKED; |
| mArrowIconRotation = ARROW_ICON_ROTATION_PEEKED; |
| + // Close icon opacity. |
| + mCloseIconOpacity = CLOSE_ICON_OPACITY_PEEKED; |
| + |
| // Progress Bar. |
| mProgressBarOpacity = 0.f; |
| @@ -970,6 +1044,9 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl |
| ARROW_ICON_ROTATION_EXPANDED, |
| percentage)); |
| + // Close icon opacity. |
| + mCloseIconOpacity = CLOSE_ICON_OPACITY_EXPANDED; |
| + |
| // Progress Bar. |
| float peekedHeight = getPanelHeightFromState(PanelState.PEEKED); |
| float threshold = PROGRESS_BAR_VISIBILITY_THRESHOLD_DP / mPxToDp; |
| @@ -1032,13 +1109,29 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl |
| percentage); |
| mSearchIconOpacity = searchIconOpacity; |
| + // Determine arrow and close icon opacities. |
|
pedro (no code reviews)
2015/07/08 20:15:05
Nit: Add comment explaining what this is doing, an
Theresa
2015/07/08 21:04:59
Done. I had the explanation a little lower down, b
|
| + float arrowIconPercentage = percentage; |
| + float closeIconPercentage = percentage; |
| + if (isArrowIconVisible() && isCloseIconVisible()) { |
| + // If both icons are visible, the arrow icon needs to finish fading out before the |
| + // close icon starts fading in. |
| + arrowIconPercentage = percentage * 2; |
|
pedro (no code reviews)
2015/07/08 20:15:05
Two observations:
1) I think that dividing by 0.5
Theresa
2015/07/08 21:04:59
Done. For closeIconPercentage, the line is a littl
|
| + closeIconPercentage = (float) ((percentage - 0.5) * 2.0); |
|
pedro (no code reviews)
2015/07/08 20:15:05
Remember to use float type suffix:
0.5 --> .5f
Theresa
2015/07/08 21:04:59
Done.
|
| + } |
| + |
| // Arrow Icon. |
| mArrowIconOpacity = MathUtils.interpolate( |
| ARROW_ICON_OPACITY_EXPANDED, |
| ARROW_ICON_OPACITY_MAXIMIZED, |
| - percentage); |
| + arrowIconPercentage); |
| mArrowIconRotation = ARROW_ICON_ROTATION_EXPANDED; |
| + // Close icon opacity. |
| + mCloseIconOpacity = MathUtils.interpolate( |
| + CLOSE_ICON_OPACITY_EXPANDED, |
| + CLOSE_ICON_OPACITY_MAXIMIZED, |
| + closeIconPercentage); |
| + |
| // Progress Bar. |
| mProgressBarOpacity = 1.f; |
| mProgressBarY = searchBarHeight - PROGRESS_BAR_HEIGHT_DP + 1; |