1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.common.rendering.api; 18 19 import com.android.resources.ResourceType; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 24 /** 25 * A Resource value representing a declare-styleable resource. 26 * 27 * {@link #getValue()} will return null, instead use {@link #getAttributeValues(String)} to 28 * get the enum/flag value associated with an attribute defined in the declare-styleable. 29 * 30 */ 31 public class DeclareStyleableResourceValue extends ResourceValue { 32 33 private Map<String, AttrResourceValue> mAttrMap; 34 DeclareStyleableResourceValue(ResourceType type, String name, boolean isFramework)35 public DeclareStyleableResourceValue(ResourceType type, String name, boolean isFramework) { 36 super(type, name, isFramework); 37 } 38 39 /** 40 * Return the enum/flag integer value for a given attribute. 41 * @param name the name of the attribute 42 * @return the map of (name, integer) values. 43 */ getAttributeValues(String name)44 public Map<String, Integer> getAttributeValues(String name) { 45 if (mAttrMap != null) { 46 AttrResourceValue attr = mAttrMap.get(name); 47 if (attr != null) { 48 return attr.getAttributeValues(); 49 } 50 } 51 52 return null; 53 } 54 getAllAttributes()55 public Map<String, AttrResourceValue> getAllAttributes() { 56 return mAttrMap; 57 } 58 addValue(AttrResourceValue attr)59 public void addValue(AttrResourceValue attr) { 60 if (mAttrMap == null) { 61 mAttrMap = new HashMap<String, AttrResourceValue>(); 62 } 63 64 mAttrMap.put(attr.getName(), attr); 65 } 66 } 67