OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.util; | 5 package org.chromium.chrome.browser.util; |
6 | 6 |
7 import android.graphics.Color; | 7 import android.graphics.Color; |
8 | 8 |
| 9 import org.chromium.chrome.browser.ntp.NewTabPage; |
| 10 import org.chromium.chrome.browser.tab.Tab; |
| 11 |
9 /** | 12 /** |
10 * Helper functions for working with colors. | 13 * Helper functions for working with colors. |
11 */ | 14 */ |
12 public class ColorUtils { | 15 public class ColorUtils { |
13 private static final float CONTRAST_LIGHT_ITEM_THRESHOLD = 3f; | 16 private static final float CONTRAST_LIGHT_ITEM_THRESHOLD = 3f; |
14 private static final float LIGHTNESS_OPAQUE_BOX_THRESHOLD = 0.82f; | 17 private static final float LIGHTNESS_OPAQUE_BOX_THRESHOLD = 0.82f; |
15 private static final float LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA = 0.2f; | 18 private static final float LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA = 0.2f; |
16 private static final float LIGHT_PROGRESSBAR_BACKGROUND_ALPHA = 0.5f; | 19 private static final float LIGHT_PROGRESSBAR_BACKGROUND_ALPHA = 0.5f; |
17 | 20 |
18 /** Percentage to darken a color by when setting the status bar color. */ | 21 /** Percentage to darken a color by when setting the status bar color. */ |
(...skipping 28 matching lines...) Expand all Loading... |
47 | 50 |
48 /** | 51 /** |
49 * @return The base color for the textbox given a toolbar background color. | 52 * @return The base color for the textbox given a toolbar background color. |
50 */ | 53 */ |
51 public static int getTextBoxColorForToolbarBackground(int color) { | 54 public static int getTextBoxColorForToolbarBackground(int color) { |
52 if (shouldUseOpaqueTextboxBackground(color)) return Color.WHITE; | 55 if (shouldUseOpaqueTextboxBackground(color)) return Color.WHITE; |
53 return getColorWithOverlay(Color.WHITE, color, LOCATION_BAR_TRANSPARENT_
BACKGROUND_ALPHA); | 56 return getColorWithOverlay(Color.WHITE, color, LOCATION_BAR_TRANSPARENT_
BACKGROUND_ALPHA); |
54 } | 57 } |
55 | 58 |
56 /** | 59 /** |
| 60 * @return Alpha for the textbox given a Tab. |
| 61 */ |
| 62 public static float getTextBoxAlphaForToolbarBackground(Tab tab) { |
| 63 int color = tab.getThemeColor(); |
| 64 if (tab.getNativePage() instanceof NewTabPage) { |
| 65 if (((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP()) re
turn 0f; |
| 66 } |
| 67 return shouldUseOpaqueTextboxBackground(color) |
| 68 ? 1f : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; |
| 69 } |
| 70 |
| 71 /** |
57 * Gets the background color for light theme progress bar. | 72 * Gets the background color for light theme progress bar. |
58 * @param toolbarColor The color of the toolbar. | 73 * @param toolbarColor The color of the toolbar. |
59 * @return The color of the progress bar in light theme, given the toolbar c
olor. | 74 * @return The color of the progress bar in light theme, given the toolbar c
olor. |
60 */ | 75 */ |
61 public static int getLightProgressbarBackground(int toolbarColor) { | 76 public static int getLightProgressbarBackground(int toolbarColor) { |
62 return getColorWithOverlay(Color.WHITE, toolbarColor, LIGHT_PROGRESSBAR_
BACKGROUND_ALPHA); | 77 return getColorWithOverlay(Color.WHITE, toolbarColor, LIGHT_PROGRESSBAR_
BACKGROUND_ALPHA); |
63 } | 78 } |
64 | 79 |
65 private static int getColorWithOverlay(int baseColor, int overlayColor, floa
t overlayAlpha) { | 80 private static int getColorWithOverlay(int baseColor, int overlayColor, floa
t overlayAlpha) { |
66 return Color.rgb( | 81 return Color.rgb( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 121 |
107 /** | 122 /** |
108 * Returns an opaque version of the given color. | 123 * Returns an opaque version of the given color. |
109 * @param color Color for which an opaque version should be returned. | 124 * @param color Color for which an opaque version should be returned. |
110 * @return Opaque version of the given color. | 125 * @return Opaque version of the given color. |
111 */ | 126 */ |
112 public static int getOpaqueColor(int color) { | 127 public static int getOpaqueColor(int color) { |
113 return Color.rgb(Color.red(color), Color.green(color), Color.blue(color)
); | 128 return Color.rgb(Color.red(color), Color.green(color), Color.blue(color)
); |
114 } | 129 } |
115 } | 130 } |
OLD | NEW |