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

Unified Diff: remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java

Issue 1461893002: Android Chromoting: Disable hamburger animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't handle NotFoundException Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..64e00081fb0d896964392fd243bcf1aa0f9da1b8 100644
--- a/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java
+++ b/remoting/android/java/src/org/chromium/chromoting/ChromotingUtil.java
@@ -5,13 +5,13 @@
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;
import android.view.Menu;
import org.chromium.base.ApiCompatibilityUtils;
-import org.chromium.base.Log;
/** Utility methods for chromoting code. */
public abstract class ChromotingUtil {
@@ -24,32 +24,38 @@ public abstract class ChromotingUtil {
* @param menu Menu with icons to be tinted.
*/
public static void tintMenuIcons(Context context, Menu menu) {
+ int color = getColorAttribute(context, R.attr.colorControlNormal);
+ int items = menu.size();
+ for (int i = 0; i < items; i++) {
+ Drawable icon = menu.getItem(i).getIcon();
+ if (icon != null) {
+ icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ }
+ }
+ }
+
+ /**
+ * 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(R.attr.colorControlNormal, typedValue, true)) {
- Log.e(TAG, "Failed to resolve colorControlNormal attribute.");
- return;
+ if (!context.getTheme().resolveAttribute(attribute, typedValue, true)) {
+ throw new Resources.NotFoundException("Attribute not found.");
}
- int color;
if (typedValue.resourceId != 0) {
// Attribute is a resource.
- color = ApiCompatibilityUtils.getColor(context.getResources(), typedValue.resourceId);
+ 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.
- color = typedValue.data;
+ return typedValue.data;
} else {
- // The resource compiler should prevent this from happening.
- Log.e(TAG, "Invalid colorControlNormal attribute: %s", typedValue);
- return;
- }
-
- int items = menu.size();
- for (int i = 0; i < items; i++) {
- Drawable icon = menu.getItem(i).getIcon();
- if (icon != null) {
- icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
- }
+ throw new Resources.NotFoundException("Attribute not a color.");
}
}
}
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/Chromoting.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698