summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-05-27 12:35:56 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-08-25 12:06:48 -0700
commit4f5e6c631522649796413c63695ae45b8759eba8 (patch)
treea6e2569b9cb80158f9701fcd0e9d1a541499e398 /tools/layoutlib
parent3e875dbb38c812e3684193fdefa04433c84541db (diff)
downloadframeworks_base-4f5e6c631522649796413c63695ae45b8759eba8.zip
frameworks_base-4f5e6c631522649796413c63695ae45b8759eba8.tar.gz
frameworks_base-4f5e6c631522649796413c63695ae45b8759eba8.tar.bz2
Skip warnings for some unresolved references. [DO NOT MERGE]
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 (cherry picked from commit b3e872be9e634c8d1f34d07778ea753880bbf2d9)
Diffstat (limited to 'tools/layoutlib')
-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 e82ea48..62e0f0b 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;
@@ -142,6 +144,29 @@ public final class BridgeContext extends Context {
private SharedPreferences mSharedPreferences;
private ClassLoader mClassLoader;
+
+ /**
+ * 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}.
@@ -798,6 +823,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);