Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarWrapper.java

Issue 2846663002: Peek new infobars behind existing ones (Closed)
Patch Set: measure happens while adding view Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainerLayout.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainerLayout.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698