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 * @Deprecated This class is broken as it does not handle the namespace for each attribute. 31 * Thankfully, newer versions of layoutlib don't actually use it, so we just keep it as is for 32 * backward compatibility on older layoutlibs. 33 * 34 */ 35 @Deprecated 36 public class DeclareStyleableResourceValue extends ResourceValue { 37 38 private Map<String, AttrResourceValue> mAttrMap; 39 DeclareStyleableResourceValue(ResourceType type, String name, boolean isFramework)40 public DeclareStyleableResourceValue(ResourceType type, String name, boolean isFramework) { 41 super(type, name, isFramework); 42 } 43 44 /** 45 * Return the enum/flag integer value for a given attribute. 46 * @param name the name of the attribute 47 * @return the map of (name, integer) values. 48 */ getAttributeValues(String name)49 public Map<String, Integer> getAttributeValues(String name) { 50 if (mAttrMap != null) { 51 AttrResourceValue attr = mAttrMap.get(name); 52 if (attr != null) { 53 return attr.getAttributeValues(); 54 } 55 } 56 57 return null; 58 } 59 getAllAttributes()60 public Map<String, AttrResourceValue> getAllAttributes() { 61 return mAttrMap; 62 } 63 addValue(AttrResourceValue attr)64 public void addValue(AttrResourceValue attr) { 65 if (mAttrMap == null) { 66 mAttrMap = new HashMap<String, AttrResourceValue>(); 67 } 68 69 mAttrMap.put(attr.getName(), attr); 70 } 71 } 72