diff options
author | newt@chromium.org <newt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 19:31:38 +0000 |
---|---|---|
committer | newt@chromium.org <newt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 19:31:38 +0000 |
commit | d2b739de6e881f7d2091fe20784206f2e60e663b (patch) | |
tree | 71a26a76e4f0fedd4dd7164587b756b2fd10a3bd /base/android | |
parent | 1d01dab1d63f5c7c23f2683f5f3783c087313f1d (diff) | |
download | chromium_src-d2b739de6e881f7d2091fe20784206f2e60e663b.zip chromium_src-d2b739de6e881f7d2091fe20784206f2e60e663b.tar.gz chromium_src-d2b739de6e881f7d2091fe20784206f2e60e663b.tar.bz2 |
Fix mismatched bookmark favicons on Android 4.2.1.
Due to a platform bug in Android 4.2.1 (JB MR1),
TextView.setCompoundDrawablesRelative() is a no-op if the view has ever
been measured. As a workaround, we use setCompoundDrawables() directly.
This bug caused the favicons on the bookmarks to appear next to the
wrong bookmark (e.g. the Gmail favicon might appear next to the Twitter
bookmark). This is now fixed.
BUG=368196
Review URL: https://codereview.chromium.org/263473005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267298 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android')
-rw-r--r-- | base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java index a544184..054e7f3 100644 --- a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java +++ b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java @@ -8,7 +8,6 @@ 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; @@ -16,9 +15,6 @@ 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). */ @@ -177,28 +173,16 @@ 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); + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { + // On JB MR1, due to a platform bug, setCompoundDrawablesRelative() is a no-op if the + // view has ever been measured. As a workaround, use setCompoundDrawables() directly. + // See: http://crbug.com/368196 and http://crbug.com/361709 + boolean isRtl = isLayoutRtl(textView); + textView.setCompoundDrawables(isRtl ? end : start, top, isRtl ? start : end, bottom); + } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { + textView.setCompoundDrawablesRelative(start, top, end, bottom); } else { - textView.setCompoundDrawables(start, top, bottom, end); + textView.setCompoundDrawables(start, top, end, bottom); } } @@ -208,10 +192,15 @@ public class ApiCompatibilityUtils { */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, Drawable start, Drawable top, Drawable end, Drawable bottom) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, bottom, end); + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { + // Work around the platform bug described in setCompoundDrawablesRelative() above. + boolean isRtl = isLayoutRtl(textView); + textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top, + isRtl ? start : end, bottom); + } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { + textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); } else { - textView.setCompoundDrawablesWithIntrinsicBounds(start, top, bottom, end); + textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); } } @@ -221,10 +210,15 @@ public class ApiCompatibilityUtils { */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView, int start, int top, int end, int bottom) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, bottom, end); + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { + // Work around the platform bug described in setCompoundDrawablesRelative() above. + boolean isRtl = isLayoutRtl(textView); + textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top, + isRtl ? start : end, bottom); + } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { + textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom); } else { - textView.setCompoundDrawablesWithIntrinsicBounds(start, top, bottom, end); + textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); } } |