Index: base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java |
diff --git a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java |
index 1e8a143eb0a6e501cc9c188a28125f61103ad51f..a544184113e203f8036e6336c104daf085f874f8 100644 |
--- a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java |
+++ b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java |
@@ -8,6 +8,7 @@ import android.app.PendingIntent; |
import android.content.res.Configuration; |
import android.graphics.drawable.Drawable; |
import android.os.Build; |
+import android.util.Log; |
import android.view.View; |
import android.view.ViewGroup.MarginLayoutParams; |
import android.view.ViewTreeObserver; |
@@ -15,11 +16,16 @@ import android.widget.ImageView; |
import android.widget.RemoteViews; |
import android.widget.TextView; |
+import java.lang.reflect.InvocationTargetException; |
+import java.lang.reflect.Method; |
+ |
/** |
* Utility class to use new APIs that were added after ICS (API level 14). |
*/ |
public class ApiCompatibilityUtils { |
+ private static final String TAG = "ApiCompatibilityUtils"; |
+ |
private ApiCompatibilityUtils() { |
} |
@@ -172,6 +178,24 @@ public class ApiCompatibilityUtils { |
public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top, |
Drawable end, Drawable bottom) { |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
+ // On JB MR1, setCompoundDrawablesRelative() is a no-op if the view has ever been |
+ // measured: due to a bug, it doesn't call resetResolvedDrawables(). Unfortunately, |
+ // resetResolvedDrawables() is a hidden method so we can't call it directly. Instead, |
+ // we use reflection. |
+ if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { |
+ try { |
+ Method resetResolvedDrawables = TextView.class.getDeclaredMethod( |
+ "resetResolvedDrawables"); |
+ resetResolvedDrawables.setAccessible(true); |
+ resetResolvedDrawables.invoke(textView); |
+ } catch (NoSuchMethodException e) { |
+ Log.w(TAG, e); |
+ } catch (IllegalAccessException e) { |
+ Log.w(TAG, e); |
+ } catch (InvocationTargetException e) { |
+ throw new RuntimeException(e); |
+ } |
+ } |
textView.setCompoundDrawablesRelative(start, top, bottom, end); |
} else { |
textView.setCompoundDrawables(start, top, bottom, end); |