summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-05-27 12:35:56 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-06-01 14:41:38 -0700
commitb3e872be9e634c8d1f34d07778ea753880bbf2d9 (patch)
tree9f6cbbe9b567142cf4c725e5bbe398c9eda7eef8 /tools
parent88fb14532421f049614c34120c706c26a9af6bbd (diff)
downloadframeworks_base-b3e872be9e634c8d1f34d07778ea753880bbf2d9.zip
frameworks_base-b3e872be9e634c8d1f34d07778ea753880bbf2d9.tar.gz
frameworks_base-b3e872be9e634c8d1f34d07778ea753880bbf2d9.tar.bz2
Skip warnings for some unresolved references.
Some applications rename the newer RTL attributes to the older attributes in order to target RTL locales, but not need to include two attributes everywhere it's needed. For example, iosched renames paddingStart to paddingLeft (among other attributes) for API 17 and above. This leads to hundreds of warnings about missing attributes. This change suppresses such warnings. Also, skip adding unresolved attributes to the typed array. This is more in line with the actual implementation on device, and prevents unexpected warnings/errors/crashes later. Change-Id: Iee616fa6295aa9731ede0cf9dcd6dd2bd1fe8f20
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index f03ec58..a2518fa 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -16,6 +16,7 @@
package com.android.layoutlib.bridge.android;
+import com.android.SdkConstants;
import com.android.ide.common.rendering.api.AssetRepository;
import com.android.ide.common.rendering.api.ILayoutPullParser;
import com.android.ide.common.rendering.api.LayoutLog;
@@ -62,6 +63,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
import android.net.Uri;
+import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -146,6 +148,29 @@ public final class BridgeContext extends Context {
private ClassLoader mClassLoader;
private IBinder mBinder;
+
+ /**
+ * Some applications that target both pre API 17 and post API 17, set the newer attrs to
+ * reference the older ones. For example, android:paddingStart will resolve to
+ * android:paddingLeft. This way the apps need to only define paddingLeft at any other place.
+ * This a map from value to attribute name. Warning for missing references shouldn't be logged
+ * if value and attr name pair is the same as an entry in this map.
+ */
+ private static Map<String, String> RTL_ATTRS = new HashMap<String, String>(10);
+
+ static {
+ RTL_ATTRS.put("?android:attr/paddingLeft", "paddingStart");
+ RTL_ATTRS.put("?android:attr/paddingRight", "paddingEnd");
+ RTL_ATTRS.put("?android:attr/layout_marginLeft", "layout_marginStart");
+ RTL_ATTRS.put("?android:attr/layout_marginRight", "layout_marginEnd");
+ RTL_ATTRS.put("?android:attr/layout_toLeft", "layout_toStartOf");
+ RTL_ATTRS.put("?android:attr/layout_toRight", "layout_toEndOf");
+ RTL_ATTRS.put("?android:attr/layout_alignParentLeft", "layout_alignParentStart");
+ RTL_ATTRS.put("?android:attr/layout_alignParentRight", "layout_alignParentEnd");
+ RTL_ATTRS.put("?android:attr/drawableLeft", "drawableStart");
+ RTL_ATTRS.put("?android:attr/drawableRight", "drawableEnd");
+ }
+
/**
* @param projectKey An Object identifying the project. This is used for the cache mechanism.
* @param metrics the {@link DisplayMetrics}.
@@ -830,6 +855,22 @@ public final class BridgeContext extends Context {
}
resValue = mRenderResources.resolveResValue(resValue);
+
+ // If the value is a reference to another theme attribute that doesn't
+ // exist, we should log a warning and omit it.
+ String val = resValue.getValue();
+ if (val != null && val.startsWith(SdkConstants.PREFIX_THEME_REF)) {
+ if (!attrName.equals(RTL_ATTRS.get(val)) ||
+ getApplicationInfo().targetSdkVersion <
+ VERSION_CODES.JELLY_BEAN_MR1) {
+ // Only log a warning if the referenced value isn't one of the RTL
+ // attributes, or the app targets old API.
+ Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR,
+ String.format("Failed to find '%s' in current theme.", val),
+ val);
+ }
+ resValue = null;
+ }
}
ta.bridgeSetValue(index, attrName, frameworkAttr, resValue);