1 /* 2 * Copyright (C) 2008 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.layoutlib.api.IResourceValue; 20 import com.android.layoutlib.api.IStyleResourceValue; 21 import com.android.resources.ResourceType; 22 23 import java.util.HashMap; 24 25 /** 26 * Represents an android style resources with a name and a list of children {@link ResourceValue}. 27 */ 28 @SuppressWarnings("deprecation") 29 public final class StyleResourceValue extends ResourceValue implements IStyleResourceValue { 30 31 private String mParentStyle = null; 32 private HashMap<String, ResourceValue> mItems = new HashMap<String, ResourceValue>(); 33 34 public StyleResourceValue(ResourceType type, String name, boolean isFramework) { 35 super(type, name, isFramework); 36 } 37 38 public StyleResourceValue(ResourceType type, String name, String parentStyle, 39 boolean isFramework) { 40 super(type, name, isFramework); 41 mParentStyle = parentStyle; 42 } 43 44 /** 45 * Returns the parent style name or <code>null</code> if unknown. 46 */ 47 public String getParentStyle() { 48 return mParentStyle; 49 } 50 51 /** 52 * Finds a value in the list by name 53 * @param name the name of the resource 54 */ 55 public ResourceValue findValue(String name) { 56 return mItems.get(name); 57 } 58 59 public void addValue(ResourceValue value) { 60 mItems.put(value.getName(), value); 61 } 62 63 @Override 64 public void replaceWith(ResourceValue value) { 65 assert value instanceof StyleResourceValue; 66 super.replaceWith(value); 67 68 if (value instanceof StyleResourceValue) { 69 mItems.clear(); 70 mItems.putAll(((StyleResourceValue)value).mItems); 71 } 72 } 73 74 /** 75 * Legacy method. 76 * @deprecated use {@link #getValue()} 77 */ 78 @Deprecated 79 public IResourceValue findItem(String name) { 80 return mItems.get(name); 81 } 82 } 83