|
25 | 25 | import com.android.ide.common.rendering.api.StyleResourceValue; |
26 | 26 | import com.android.layoutlib.bridge.Bridge; |
27 | 27 | import com.android.layoutlib.bridge.BridgeConstants; |
| 28 | +import com.android.layoutlib.bridge.impl.ParserFactory; |
28 | 29 | import com.android.layoutlib.bridge.impl.Stack; |
29 | 30 | import com.android.resources.ResourceType; |
30 | 31 | import com.android.util.Pair; |
31 | 32 |
|
32 | | -import org.kxml2.io.KXmlParser; |
33 | 33 | import org.xmlpull.v1.XmlPullParser; |
34 | 34 | import org.xmlpull.v1.XmlPullParserException; |
35 | 35 |
|
@@ -201,14 +201,20 @@ public Map<String, String> getDefaultPropMap(Object key) { |
201 | 201 | * @param parser the parser to add. |
202 | 202 | */ |
203 | 203 | public void pushParser(BridgeXmlBlockParser parser) { |
| 204 | + if (ParserFactory.LOG_PARSER) { |
| 205 | + System.out.println("PUSH " + parser.getParser().toString()); |
| 206 | + } |
204 | 207 | mParserStack.push(parser); |
205 | 208 | } |
206 | 209 |
|
207 | 210 | /** |
208 | 211 | * Removes the parser at the top of the stack |
209 | 212 | */ |
210 | 213 | public void popParser() { |
211 | | - mParserStack.pop(); |
| 214 | + BridgeXmlBlockParser parser = mParserStack.pop(); |
| 215 | + if (ParserFactory.LOG_PARSER) { |
| 216 | + System.out.println("POPD " + parser.getParser().toString()); |
| 217 | + } |
212 | 218 | } |
213 | 219 |
|
214 | 220 | /** |
@@ -341,9 +347,7 @@ public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup par |
341 | 347 | // we need to create a pull parser around the layout XML file, and then |
342 | 348 | // give that to our XmlBlockParser |
343 | 349 | try { |
344 | | - KXmlParser parser = new KXmlParser(); |
345 | | - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); |
346 | | - parser.setInput(new FileInputStream(xml), "UTF-8"); //$NON-NLS-1$); |
| 350 | + XmlPullParser parser = ParserFactory.create(xml); |
347 | 351 |
|
348 | 352 | // set the resource ref to have correct view cookies |
349 | 353 | mBridgeInflater.setResourceReference(resource); |
@@ -682,25 +686,25 @@ public Looper getMainLooper() { |
682 | 686 | */ |
683 | 687 | private BridgeTypedArray createStyleBasedTypedArray(StyleResourceValue style, int[] attrs) |
684 | 688 | throws Resources.NotFoundException { |
685 | | - AtomicBoolean frameworkAttributes = new AtomicBoolean(); |
686 | | - AtomicReference<String> attrName = new AtomicReference<String>(); |
687 | | - TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes, attrName); |
688 | 689 |
|
689 | 690 | BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length, |
690 | | - style.isFramework(), frameworkAttributes.get(), attrName.get()); |
691 | | - |
692 | | - // loop through all the values in the style map, and init the TypedArray with |
693 | | - // the style we got from the dynamic id |
694 | | - for (Entry<Integer, String> styleAttribute : styleNameMap.entrySet()) { |
695 | | - int index = styleAttribute.getKey().intValue(); |
| 691 | + false, true, null); |
696 | 692 |
|
697 | | - String name = styleAttribute.getValue(); |
| 693 | + // for each attribute, get its name so that we can search it in the style |
| 694 | + for (int i = 0 ; i < attrs.length ; i++) { |
| 695 | + Pair<ResourceType, String> resolvedResource = Bridge.resolveResourceId(attrs[i]); |
| 696 | + if (resolvedResource != null) { |
| 697 | + String attrName = resolvedResource.getSecond(); |
| 698 | + // look for the value in the given style |
| 699 | + ResourceValue resValue = mRenderResources.findItemInStyle(style, attrName); |
698 | 700 |
|
699 | | - // get the value from the style, or its parent styles. |
700 | | - ResourceValue resValue = mRenderResources.findItemInStyle(style, name); |
| 701 | + if (resValue != null) { |
| 702 | + // resolve it to make sure there are no references left. |
| 703 | + ta.bridgeSetValue(i, attrName, mRenderResources.resolveResValue(resValue)); |
701 | 704 |
|
702 | | - // resolve it to make sure there are no references left. |
703 | | - ta.bridgeSetValue(index, name, mRenderResources.resolveResValue(resValue)); |
| 705 | + resValue = mRenderResources.resolveResValue(resValue); |
| 706 | + } |
| 707 | + } |
704 | 708 | } |
705 | 709 |
|
706 | 710 | ta.sealArray(); |
|
0 commit comments