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

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: wrapper has height restricted mode 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
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 mHeightForAnimation;
Ted C 2017/05/19 17:21:41 I would throw a Px suffix on this to make it super
mdjones 2017/05/19 17:30:14 Done.
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);
36 } 45 }
37 46
47 /**
48 * @param restrict Whether or not the height of this view should be restrict ed for animations.
49 */
50 public void setRestrictHeightForAnimation(boolean restrict) {
51 mRestrictHeightForAnimation = restrict;
52 }
53
54 /**
55 * @param height The restricted height in px that will be used if
56 * {@link #mRestrictHeightForAnimation} is set.
57 */
58 public void setHeightForAnimation(int height) {
59 mHeightForAnimation = height;
60 }
61
38 InfoBarContainerLayout.Item getItem() { 62 InfoBarContainerLayout.Item getItem() {
39 return mItem; 63 return mItem;
40 } 64 }
41 65
42 @Override 66 @Override
67 public void onMeasure(int widthSpec, int heightSpec) {
68 if (mRestrictHeightForAnimation) {
69 int height = Math.min(mHeightForAnimation, MeasureSpec.getSize(heigh tSpec));
70 heightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.getMode (heightSpec));
71 }
72
73 super.onMeasure(widthSpec, heightSpec);
74 }
75
76 @Override
43 public void onViewAdded(View child) { 77 public void onViewAdded(View child) {
44 child.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, Layout Params.WRAP_CONTENT, 78 child.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, Layout Params.WRAP_CONTENT,
45 Gravity.TOP)); 79 Gravity.TOP));
46 } 80 }
47 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698