diff options
author | Xavier Ducrohet <xav@android.com> | 2011-06-24 11:42:32 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-06-24 12:08:58 -0700 |
commit | b5194e4f103c866fc2c75dfdc881ae5f6cfb0011 (patch) | |
tree | 6024358c22d36a9750ca91b6fa128e7206d350c3 /layoutlib_api/src/com/android/ide/common | |
parent | 0309368dc30aa2261e419d193dad01d909af8fed (diff) | |
download | sdk-b5194e4f103c866fc2c75dfdc881ae5f6cfb0011.zip sdk-b5194e4f103c866fc2c75dfdc881ae5f6cfb0011.tar.gz sdk-b5194e4f103c866fc2c75dfdc881ae5f6cfb0011.tar.bz2 |
Fix value parser to handle attr values not in declare-styleable.
Also change the layoutlib sample code to properly get the list
of framework attr flag/enum values.
Change-Id: Ie0bf126a0fab574d94d0f86b7b2f8581cf4eaae3
Diffstat (limited to 'layoutlib_api/src/com/android/ide/common')
-rw-r--r-- | layoutlib_api/src/com/android/ide/common/rendering/api/AttrResourceValue.java | 56 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java | 33 |
2 files changed, 68 insertions, 21 deletions
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/AttrResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/AttrResourceValue.java new file mode 100644 index 0000000..530e3d5 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/AttrResourceValue.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.common.rendering.api; + +import com.android.resources.ResourceType; + +import java.util.HashMap; +import java.util.Map; + +/** + * A Resource value representing an attr resource. + * + * {@link #getValue()} will return null, instead use {@link #getAttributeValues()} to + * get the enum/flag value associated with an attribute defined in the declare-styleable. + * + */ +public class AttrResourceValue extends ResourceValue { + + private Map<String, Integer> mValueMap; + + + public AttrResourceValue(ResourceType type, String name, boolean isFramework) { + super(type, name, isFramework); + } + + /** + * Return the enum/flag integer values. + * + * @return the map of (name, integer) values. Can be null. + */ + public Map<String, Integer> getAttributeValues() { + return mValueMap; + } + + public void addValue(String name, Integer value) { + if (mValueMap == null) { + mValueMap = new HashMap<String, Integer>(); + } + + mValueMap.put(name, value); + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java index 0699766..45679b2 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java @@ -30,11 +30,10 @@ import java.util.Map; */ public class DeclareStyleableResourceValue extends ResourceValue { - private Map<String, Map<String, Integer>> mEnumMap; + private Map<String, AttrResourceValue> mAttrMap; public DeclareStyleableResourceValue(ResourceType type, String name, boolean isFramework) { super(type, name, isFramework); - } /** @@ -43,33 +42,25 @@ public class DeclareStyleableResourceValue extends ResourceValue { * @return the map of (name, integer) values. */ public Map<String, Integer> getAttributeValues(String name) { - if (mEnumMap != null) { - return mEnumMap.get(name); + if (mAttrMap != null) { + AttrResourceValue attr = mAttrMap.get(name); + if (attr != null) { + return attr.getAttributeValues(); + } } return null; } - public Map<String, Map<String, Integer>> getAllAttributes() { - return mEnumMap; + public Map<String, AttrResourceValue> getAllAttributes() { + return mAttrMap; } - public void addValue(String attribute, String name, Integer value) { - Map<String, Integer> map; - - if (mEnumMap == null) { - mEnumMap = new HashMap<String, Map<String,Integer>>(); - - map = new HashMap<String, Integer>(); - mEnumMap.put(attribute, map); - } else { - map = mEnumMap.get(attribute); - if (map == null) { - map = new HashMap<String, Integer>(); - mEnumMap.put(attribute, map); - } + public void addValue(AttrResourceValue attr) { + if (mAttrMap == null) { + mAttrMap = new HashMap<String, AttrResourceValue>(); } - map.put(name, value); + mAttrMap.put(attr.getName(), attr); } } |