Commit a51ec8d0 authored by newt@chromium.org's avatar newt@chromium.org

Add workaround for TextView.setCompoundDrawablesRelative() on JB MR1.

Due to a bug, TextView.setCompoundDrawablesRelative() is a no-op on JB
MR1 if the text view has ever been measured. This is fixed in JB MR2
onwards, but causes some ugly bugs in Chrome on JB MR1: e.g. the
favicons often don't appear on the bookmarks page.

BUG=361709
NOTRY=true

Review URL: https://codereview.chromium.org/232083005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263137 0039d316-1c4b-4281-b951-d872f2087c98
parent b5827602
...@@ -8,6 +8,7 @@ import android.app.PendingIntent; ...@@ -8,6 +8,7 @@ import android.app.PendingIntent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
...@@ -15,11 +16,16 @@ import android.widget.ImageView; ...@@ -15,11 +16,16 @@ import android.widget.ImageView;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.TextView; 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). * Utility class to use new APIs that were added after ICS (API level 14).
*/ */
public class ApiCompatibilityUtils { public class ApiCompatibilityUtils {
private static final String TAG = "ApiCompatibilityUtils";
private ApiCompatibilityUtils() { private ApiCompatibilityUtils() {
} }
...@@ -172,6 +178,24 @@ public class ApiCompatibilityUtils { ...@@ -172,6 +178,24 @@ public class ApiCompatibilityUtils {
public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top, public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top,
Drawable end, Drawable bottom) { Drawable end, Drawable bottom) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 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); textView.setCompoundDrawablesRelative(start, top, bottom, end);
} else { } else {
textView.setCompoundDrawables(start, top, bottom, end); textView.setCompoundDrawables(start, top, bottom, end);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment