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.content.Context; | 7 import android.content.Context; |
| 8 import android.support.graphics.drawable.VectorDrawableCompat; |
8 import android.util.AttributeSet; | 9 import android.util.AttributeSet; |
9 import android.view.View; | 10 import android.view.View; |
10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
11 import android.view.ViewStub; | 12 import android.view.ViewStub; |
12 import android.widget.ImageView; | 13 import android.widget.ImageView; |
13 import android.widget.LinearLayout; | 14 import android.widget.LinearLayout; |
14 import android.widget.TextView; | 15 import android.widget.TextView; |
15 | 16 |
16 import org.chromium.base.ApiCompatibilityUtils; | 17 import org.chromium.base.ApiCompatibilityUtils; |
17 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 super.onFinishInflate(); | 73 super.onFinishInflate(); |
73 } | 74 } |
74 | 75 |
75 /** Initializes the dialog contents using the given params. Should only be
called once. */ | 76 /** Initializes the dialog contents using the given params. Should only be
called once. */ |
76 void initialize(DialogParams params) { | 77 void initialize(DialogParams params) { |
77 assert mParams == null && params != null; | 78 assert mParams == null && params != null; |
78 assert params.headerStringResource != 0; | 79 assert params.headerStringResource != 0; |
79 assert params.primaryButtonStringResource != 0; | 80 assert params.primaryButtonStringResource != 0; |
80 mParams = params; | 81 mParams = params; |
81 | 82 |
82 if (mParams.drawableResource == 0) { | 83 if (mParams.drawableResource == 0 && mParams.vectorDrawableResource == 0
) { |
83 // Dialogs with no illustration make the header stay visible at all
times instead of | 84 // Dialogs with no illustration make the header stay visible at all
times instead of |
84 // scrolling off on small screens. | 85 // scrolling off on small screens. |
85 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration
View); | 86 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration
View); |
86 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView); | 87 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView); |
87 addView(mHeaderView, 0); | 88 addView(mHeaderView, 0); |
88 | 89 |
89 // The margins only apply here (after it moves to the root) because
the scroll layout it | 90 // The margins only apply here (after it moves to the root) because
the scroll layout it |
90 // is normally in has implicit padding. | 91 // is normally in has implicit padding. |
91 int marginSize = | 92 int marginSize = |
92 getContext().getResources().getDimensionPixelSize(R.dimen.di
alog_header_margin); | 93 getContext().getResources().getDimensionPixelSize(R.dimen.di
alog_header_margin); |
93 ApiCompatibilityUtils.setMarginStart( | 94 ApiCompatibilityUtils.setMarginStart( |
94 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi
ze); | 95 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi
ze); |
95 ApiCompatibilityUtils.setMarginEnd( | 96 ApiCompatibilityUtils.setMarginEnd( |
96 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi
ze); | 97 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi
ze); |
| 98 } else if (mParams.vectorDrawableResource != 0) { |
| 99 mIllustrationView.setImageDrawable(VectorDrawableCompat.create( |
| 100 getResources(), mParams.vectorDrawableResource, getContext()
.getTheme())); |
97 } else { | 101 } else { |
98 mIllustrationView.setImageResource(mParams.drawableResource); | 102 mIllustrationView.setImageResource(mParams.drawableResource); |
99 } | 103 } |
100 | 104 |
101 // Create the header. | 105 // Create the header. |
102 mHeaderView.setText(mParams.headerStringResource); | 106 mHeaderView.setText(mParams.headerStringResource); |
103 | 107 |
104 // Set up the subheader text. | 108 // Set up the subheader text. |
105 if (mParams.subheaderStringResource == 0) { | 109 if (mParams.subheaderStringResource == 0) { |
106 ((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView); | 110 ((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 148 |
145 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 149 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
146 } | 150 } |
147 | 151 |
148 /** Adds a View to the layout within the scrollable area. */ | 152 /** Adds a View to the layout within the scrollable area. */ |
149 void addControl(View control) { | 153 void addControl(View control) { |
150 mScrollableContent.addView( | 154 mScrollableContent.addView( |
151 control, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParam
s.WRAP_CONTENT)); | 155 control, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParam
s.WRAP_CONTENT)); |
152 } | 156 } |
153 } | 157 } |
OLD | NEW |