Index: remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java |
diff --git a/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java b/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java |
index 522480132426e9bb32515d11728eadf4e8478c7e..63dd5812ec2b959acfb4752fc221fa603b91b922 100644 |
--- a/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java |
+++ b/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java |
@@ -5,6 +5,7 @@ |
package org.chromium.chromoting; |
import android.content.Context; |
+import android.content.res.Resources; |
import android.graphics.PorterDuff; |
import android.graphics.drawable.Drawable; |
import android.util.TypedValue; |
@@ -24,26 +25,14 @@ public abstract class ChromotingUtil { |
* @param menu Menu with icons to be tinted. |
*/ |
public static void tintMenuIcons(Context context, Menu menu) { |
- TypedValue typedValue = new TypedValue(); |
- if (!context.getTheme().resolveAttribute(R.attr.colorControlNormal, typedValue, true)) { |
- Log.e(TAG, "Failed to resolve colorControlNormal attribute."); |
- return; |
- } |
- |
int color; |
- if (typedValue.resourceId != 0) { |
- // Attribute is a resource. |
- color = ApiCompatibilityUtils.getColor(context.getResources(), typedValue.resourceId); |
- } else if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT |
- && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { |
- // Attribute is a raw color value. |
- color = typedValue.data; |
- } else { |
+ try { |
+ color = getColorAttribute(context, R.attr.colorControlNormal); |
+ } catch (Resources.NotFoundException e) { |
// The resource compiler should prevent this from happening. |
Sergey Ulanov
2015/11/23 22:01:13
If this is unexpected then why do we need to handl
Lambros
2015/11/23 23:48:56
No need, it shouldn't happen if the code+resources
|
- Log.e(TAG, "Invalid colorControlNormal attribute: %s", typedValue); |
+ Log.e(TAG, "colorControlNormal attribute lookup failed.", e); |
return; |
} |
- |
int items = menu.size(); |
for (int i = 0; i < items; i++) { |
Drawable icon = menu.getItem(i).getIcon(); |
@@ -52,4 +41,29 @@ public abstract class ChromotingUtil { |
} |
} |
} |
+ |
+ /** |
+ * Returns a color from a theme attribute. |
+ * @param context Context with resources to look up. |
+ * @param attribute Attribute such as R.attr.colorControlNormal. |
+ * @return Color value. |
+ * @throws Resources.NotFoundException |
+ */ |
+ public static int getColorAttribute(Context context, int attribute) { |
+ TypedValue typedValue = new TypedValue(); |
+ if (!context.getTheme().resolveAttribute(attribute, typedValue, true)) { |
+ throw new Resources.NotFoundException("Attribute not found."); |
+ } |
+ |
+ if (typedValue.resourceId != 0) { |
+ // Attribute is a resource. |
+ return ApiCompatibilityUtils.getColor(context.getResources(), typedValue.resourceId); |
+ } else if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT |
+ && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { |
+ // Attribute is a raw color value. |
+ return typedValue.data; |
+ } else { |
+ throw new Resources.NotFoundException("Attribute not a color."); |
+ } |
+ } |
} |