OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.graphics.Paint; | 9 import android.graphics.Paint; |
10 import android.support.v7.widget.SwitchCompat; | 10 import android.support.v7.widget.SwitchCompat; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 * Adds an icon with a descriptive message to the layout. | 267 * Adds an icon with a descriptive message to the layout. |
268 * | 268 * |
269 * ----------------------------------------------------- | 269 * ----------------------------------------------------- |
270 * | ICON | PRIMARY MESSAGE SECONDARY MESSAGE | | 270 * | ICON | PRIMARY MESSAGE SECONDARY MESSAGE | |
271 * ----------------------------------------------------- | 271 * ----------------------------------------------------- |
272 * If an icon is not provided, the ImageView that would normally show it is
hidden. | 272 * If an icon is not provided, the ImageView that would normally show it is
hidden. |
273 * | 273 * |
274 * @param iconResourceId ID of the drawable to use for the icon. | 274 * @param iconResourceId ID of the drawable to use for the icon. |
275 * @param primaryMessage Message to display for the toggle. | 275 * @param primaryMessage Message to display for the toggle. |
276 * @param secondaryMessage Additional descriptive text for the toggle. May
be null. | 276 * @param secondaryMessage Additional descriptive text for the toggle. May
be null. |
| 277 * @param iconColorId ID of the tint color for the icon, or 0 for defau
lt. |
277 */ | 278 */ |
278 public View addIcon( | 279 public View addIcon(int iconResourceId, CharSequence primaryMessage, |
279 int iconResourceId, CharSequence primaryMessage, CharSequence second
aryMessage) { | 280 CharSequence secondaryMessage, int iconColorId) { |
280 LinearLayout layout = (LinearLayout) LayoutInflater.from(getContext()).i
nflate( | 281 LinearLayout layout = (LinearLayout) LayoutInflater.from(getContext()).i
nflate( |
281 R.layout.infobar_control_icon_with_description, this, false); | 282 R.layout.infobar_control_icon_with_description, this, false); |
282 addView(layout, new ControlLayoutParams()); | 283 addView(layout, new ControlLayoutParams()); |
283 | 284 |
284 ImageView iconView = (ImageView) layout.findViewById(R.id.control_icon); | 285 ImageView iconView = (ImageView) layout.findViewById(R.id.control_icon); |
285 iconView.setImageResource(iconResourceId); | 286 iconView.setImageResource(iconResourceId); |
| 287 if (iconColorId != 0) { |
| 288 iconView.setColorFilter(ApiCompatibilityUtils.getColor(getResources(
), iconColorId)); |
| 289 } |
286 | 290 |
287 // The primary message text is always displayed. | 291 // The primary message text is always displayed. |
288 TextView primaryView = (TextView) layout.findViewById(R.id.control_messa
ge); | 292 TextView primaryView = (TextView) layout.findViewById(R.id.control_messa
ge); |
289 primaryView.setText(primaryMessage); | 293 primaryView.setText(primaryMessage); |
290 | 294 |
291 // The secondary message text is optional. | 295 // The secondary message text is optional. |
292 TextView secondaryView = | 296 TextView secondaryView = |
293 (TextView) layout.findViewById(R.id.control_secondary_message); | 297 (TextView) layout.findViewById(R.id.control_secondary_message); |
294 if (secondaryMessage == null) { | 298 if (secondaryMessage == null) { |
295 layout.removeView(secondaryView); | 299 layout.removeView(secondaryView); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 405 |
402 /** | 406 /** |
403 * @return The {@link ControlLayoutParams} for the given child. | 407 * @return The {@link ControlLayoutParams} for the given child. |
404 */ | 408 */ |
405 @VisibleForTesting | 409 @VisibleForTesting |
406 static ControlLayoutParams getControlLayoutParams(View child) { | 410 static ControlLayoutParams getControlLayoutParams(View child) { |
407 return (ControlLayoutParams) child.getLayoutParams(); | 411 return (ControlLayoutParams) child.getLayoutParams(); |
408 } | 412 } |
409 | 413 |
410 } | 414 } |
OLD | NEW |