Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.widget; | 5 package org.chromium.chrome.browser.widget; |
| 6 | 6 |
| 7 import android.animation.Animator; | 7 import android.animation.Animator; |
| 8 import android.animation.ObjectAnimator; | 8 import android.animation.ObjectAnimator; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
| 11 import android.view.View; | 11 import android.view.View; |
| 12 import android.view.ViewGroup.LayoutParams; | |
| 12 | 13 |
| 13 import org.chromium.base.ObserverList; | 14 import org.chromium.base.ObserverList; |
| 14 import org.chromium.chrome.browser.util.MathUtils; | 15 import org.chromium.chrome.browser.util.MathUtils; |
| 15 import org.chromium.ui.interpolators.BakedBezierInterpolator; | 16 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * This view is used to obscure content and bring focus to a foreground view (i. e. the Chrome Home | 19 * This view is used to obscure content and bring focus to a foreground view (i. e. the Chrome Home |
| 19 * bottom sheet or the omnibox suggestions). | 20 * bottom sheet or the omnibox suggestions). |
| 20 * | 21 * |
| 21 * If the view is disabled, then its alpha will be set to 0f and it will not rec eive touch events. | 22 * If the view is disabled, then its alpha will be set to 0f and it will not rec eive touch events. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 @Override | 92 @Override |
| 92 public void setAlpha(float alpha) { | 93 public void setAlpha(float alpha) { |
| 93 super.setAlpha(alpha); | 94 super.setAlpha(alpha); |
| 94 | 95 |
| 95 int newVisibility = alpha <= 0f ? View.GONE : View.VISIBLE; | 96 int newVisibility = alpha <= 0f ? View.GONE : View.VISIBLE; |
| 96 setVisibility(newVisibility); | 97 setVisibility(newVisibility); |
| 97 } | 98 } |
| 98 | 99 |
| 99 @Override | 100 @Override |
| 100 public void setVisibility(int visibility) { | 101 public void setVisibility(int visibility) { |
| 101 if (getAlpha() <= 0f && visibility == View.VISIBLE) return; | 102 if (getAlpha() <= 0f && visibility == View.VISIBLE) { |
| 103 changeHeight(0); | |
|
Ted C
2017/07/18 16:41:18
changing the layout height in this case seems wron
mdjones
2017/07/19 18:40:50
For this view, alpha is tied to visibility (see se
| |
| 104 return; | |
| 105 } | |
| 106 changeHeight(visibility == View.VISIBLE ? LayoutParams.MATCH_PARENT : 0) ; | |
| 102 super.setVisibility(visibility); | 107 super.setVisibility(visibility); |
| 103 } | 108 } |
| 104 | 109 |
| 105 @Override | 110 @Override |
| 106 protected void dispatchVisibilityChanged(View view, int visibility) { | 111 protected void dispatchVisibilityChanged(View view, int visibility) { |
| 107 if (getAlpha() <= 0f && visibility == View.VISIBLE) return; | 112 if (getAlpha() <= 0f && visibility == View.VISIBLE) return; |
| 108 super.dispatchVisibilityChanged(view, visibility); | 113 super.dispatchVisibilityChanged(view, visibility); |
| 109 } | 114 } |
| 110 | 115 |
| 111 @Override | 116 @Override |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (mOverlayAnimator == fadeAnimation && mOverlayAnimator.isRunning()) { | 163 if (mOverlayAnimator == fadeAnimation && mOverlayAnimator.isRunning()) { |
| 159 return; | 164 return; |
| 160 } else if (mOverlayAnimator != null) { | 165 } else if (mOverlayAnimator != null) { |
| 161 mOverlayAnimator.cancel(); | 166 mOverlayAnimator.cancel(); |
| 162 } | 167 } |
| 163 mOverlayAnimator = fadeAnimation; | 168 mOverlayAnimator = fadeAnimation; |
| 164 mOverlayAnimator.start(); | 169 mOverlayAnimator.start(); |
| 165 } | 170 } |
| 166 | 171 |
| 167 /** | 172 /** |
| 173 * Change height of this view. | |
| 174 * @param height The height that it should be. | |
| 175 */ | |
| 176 private void changeHeight(int height) { | |
| 177 LayoutParams params = getLayoutParams(); | |
| 178 if (params != null && params.height != height) { | |
| 179 params.height = height; | |
| 180 setLayoutParams(params); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 /** | |
| 168 * Adds an observer to this fading view. | 185 * Adds an observer to this fading view. |
| 169 * @param observer The observer to be added. | 186 * @param observer The observer to be added. |
| 170 */ | 187 */ |
| 171 public void addObserver(FadingViewObserver observer) { | 188 public void addObserver(FadingViewObserver observer) { |
| 172 mObservers.addObserver(observer); | 189 mObservers.addObserver(observer); |
| 173 } | 190 } |
| 174 | 191 |
| 175 @Override | 192 @Override |
| 176 public void onClick(View view) { | 193 public void onClick(View view) { |
| 177 for (FadingViewObserver o : mObservers) o.onFadingViewClick(); | 194 for (FadingViewObserver o : mObservers) o.onFadingViewClick(); |
| 178 } | 195 } |
| 179 } | 196 } |
| OLD | NEW |