| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.infobar; | 5 package org.chromium.chrome.browser.infobar; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
| 9 import android.view.Gravity; | 9 import android.view.Gravity; |
| 10 import android.view.View; | 10 import android.view.View; |
| 11 import android.widget.FrameLayout; | 11 import android.widget.FrameLayout; |
| 12 | 12 |
| 13 import org.chromium.chrome.R; | 13 import org.chromium.chrome.R; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Layout that holds an infobar's contents and provides a background color and a
top shadow. | 16 * Layout that holds an infobar's contents and provides a background color and a
top shadow. |
| 17 */ | 17 */ |
| 18 class InfoBarWrapper extends FrameLayout { | 18 class InfoBarWrapper extends FrameLayout { |
| 19 | 19 |
| 20 private final InfoBarContainerLayout.Item mItem; | 20 private final InfoBarContainerLayout.Item mItem; |
| 21 | 21 |
| 22 /** Whether or not the height of the layout should be restricted for animati
ons. */ |
| 23 private boolean mRestrictHeightForAnimation; |
| 24 |
| 25 /** |
| 26 * The height in px that this view will be restricted to if |
| 27 * {@link #mRestrictHeightForAnimation} is set. |
| 28 */ |
| 29 private int mHeightForAnimationPx; |
| 30 |
| 22 /** | 31 /** |
| 23 * Constructor for inflating from Java. | 32 * Constructor for inflating from Java. |
| 24 */ | 33 */ |
| 25 InfoBarWrapper(Context context, InfoBarContainerLayout.Item item) { | 34 InfoBarWrapper(Context context, InfoBarContainerLayout.Item item) { |
| 26 super(context); | 35 super(context); |
| 27 mItem = item; | 36 mItem = item; |
| 28 Resources res = context.getResources(); | 37 Resources res = context.getResources(); |
| 29 int peekingHeight = res.getDimensionPixelSize(R.dimen.infobar_peeking_he
ight); | 38 int peekingHeight = res.getDimensionPixelSize(R.dimen.infobar_peeking_he
ight); |
| 30 int shadowHeight = res.getDimensionPixelSize(R.dimen.infobar_shadow_heig
ht); | 39 int shadowHeight = res.getDimensionPixelSize(R.dimen.infobar_shadow_heig
ht); |
| 31 setMinimumHeight(peekingHeight + shadowHeight); | 40 setMinimumHeight(peekingHeight + shadowHeight); |
| 32 | 41 |
| 33 // setBackgroundResource() changes the padding, so call setPadding() sec
ond. | 42 // setBackgroundResource() changes the padding, so call setPadding() sec
ond. |
| 34 setBackgroundResource(R.drawable.infobar_wrapper_bg); | 43 setBackgroundResource(R.drawable.infobar_wrapper_bg); |
| 35 setPadding(0, shadowHeight, 0, 0); | 44 setPadding(0, shadowHeight, 0, 0); |
| 45 setClipChildren(true); |
| 46 } |
| 47 |
| 48 /** |
| 49 * @param restrict Whether or not the height of this view should be restrict
ed for animations. |
| 50 */ |
| 51 public void setRestrictHeightForAnimation(boolean restrict) { |
| 52 mRestrictHeightForAnimation = restrict; |
| 53 } |
| 54 |
| 55 /** |
| 56 * @param heightPx The restricted height in px that will be used if |
| 57 * {@link #mRestrictHeightForAnimation} is set. |
| 58 */ |
| 59 public void setHeightForAnimation(int heightPx) { |
| 60 mHeightForAnimationPx = heightPx; |
| 36 } | 61 } |
| 37 | 62 |
| 38 InfoBarContainerLayout.Item getItem() { | 63 InfoBarContainerLayout.Item getItem() { |
| 39 return mItem; | 64 return mItem; |
| 40 } | 65 } |
| 41 | 66 |
| 42 @Override | 67 @Override |
| 68 public void onMeasure(int widthSpec, int heightSpec) { |
| 69 if (mRestrictHeightForAnimation) { |
| 70 int heightPx = Math.min(mHeightForAnimationPx, MeasureSpec.getSize(h
eightSpec)); |
| 71 heightSpec = MeasureSpec.makeMeasureSpec(heightPx, MeasureSpec.getMo
de(heightSpec)); |
| 72 } |
| 73 |
| 74 super.onMeasure(widthSpec, heightSpec); |
| 75 } |
| 76 |
| 77 @Override |
| 43 public void onViewAdded(View child) { | 78 public void onViewAdded(View child) { |
| 44 child.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, Layout
Params.WRAP_CONTENT, | 79 child.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, Layout
Params.WRAP_CONTENT, |
| 45 Gravity.TOP)); | 80 Gravity.TOP)); |
| 46 } | 81 } |
| 47 } | 82 } |
| OLD | NEW |