From b318ff54fcd17e7aadd1b0251c34cba348898704 Mon Sep 17 00:00:00 2001 From: Deepanshu Gupta Date: Mon, 24 Aug 2015 13:50:18 -0700 Subject: [PATCH] Make DatePicker rendering not fail (style search fix). [DO NOT MERGE] Only cherry picked for the style not found fix. Change-Id: Ied2b71de5b32bcb640bf4ec445e8a39509f800e9 (cherry picked from commit d5b82845450beac2d3c7db9cd80e9fc34d43a297) --- .../layoutlib/bridge/android/BridgeContext.java | 58 ++++++++++++---------- 1 file changed, 32 insertions(+), 26 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 ac3a3ce3aa8f..6ef0b7900501 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 @@ -66,7 +66,9 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.os.Parcel; import android.os.PowerManager; +import android.os.RemoteException; import android.os.UserHandle; import android.util.AttributeSet; import android.util.DisplayMetrics; @@ -679,44 +681,48 @@ public final class BridgeContext extends Context { } } } else if (defStyleRes != 0) { - boolean isFrameworkRes = true; - Pair value = Bridge.resolveResourceId(defStyleRes); - if (value == null) { - value = mLayoutlibCallback.resolveResourceId(defStyleRes); - isFrameworkRes = false; - } + StyleResourceValue item = mDynamicIdToStyleMap.get(defStyleRes); + if (item != null) { + defStyleValues = item; + } else { + boolean isFrameworkRes = true; + Pair value = Bridge.resolveResourceId(defStyleRes); + if (value == null) { + value = mLayoutlibCallback.resolveResourceId(defStyleRes); + isFrameworkRes = false; + } - if (value != null) { - if ((value.getFirst() == ResourceType.STYLE)) { - // look for the style in all resources: - StyleResourceValue item = mRenderResources.getStyle(value.getSecond(), - isFrameworkRes); - if (item != null) { - if (defaultPropMap != null) { - defaultPropMap.put("style", item.getName()); + if (value != null) { + if ((value.getFirst() == ResourceType.STYLE)) { + // look for the style in all resources: + item = mRenderResources.getStyle(value.getSecond(), isFrameworkRes); + if (item != null) { + if (defaultPropMap != null) { + defaultPropMap.put("style", item.getName()); + } + + defStyleValues = item; + } else { + Bridge.getLog().error(null, + String.format( + "Style with id 0x%x (resolved to '%s') does not exist.", + defStyleRes, value.getSecond()), + null); } - - defStyleValues = item; } else { Bridge.getLog().error(null, String.format( - "Style with id 0x%x (resolved to '%s') does not exist.", - defStyleRes, value.getSecond()), + "Resource id 0x%x is not of type STYLE (instead %s)", + defStyleRes, value.getFirst().toString()), null); } } else { Bridge.getLog().error(null, String.format( - "Resource id 0x%x is not of type STYLE (instead %s)", - defStyleRes, value.getFirst().toString()), + "Failed to find style with id 0x%x in current theme", + defStyleRes), null); } - } else { - Bridge.getLog().error(null, - String.format( - "Failed to find style with id 0x%x in current theme", - defStyleRes), - null); } } -- 2.11.0