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

Unified Diff: base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java

Issue 232083005: Add workaround for TextView.setCompoundDrawablesRelative() on JB MR1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698