1/*
2 * Copyright (C) 2010 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
17package com.android.layoutlib.bridge.android;
18
19import com.android.layoutlib.bridge.BridgeConstants;
20
21import android.util.AttributeSet;
22
23import java.util.Map;
24
25/**
26 * An implementation of the {@link AttributeSet} interface on top of a map of attribute in the form
27 * of (name, value).
28 *
29 * This is meant to be called only from {@link BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)}
30 * in the case of LayoutParams and therefore isn't a full implementation.
31 */
32public class BridgeLayoutParamsMapAttributes implements AttributeSet {
33
34    private final Map<String, String> mAttributes;
35
36    public BridgeLayoutParamsMapAttributes(Map<String, String> attributes) {
37        mAttributes = attributes;
38    }
39
40    @Override
41    public String getAttributeValue(String namespace, String name) {
42        if (BridgeConstants.NS_RESOURCES.equals(namespace)) {
43            return mAttributes.get(name);
44        }
45
46        return null;
47    }
48
49    // ---- the following methods are not called from
50    // BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)
51    // Should they ever be called, we'll just implement them on a need basis.
52
53    @Override
54    public int getAttributeCount() {
55        throw new UnsupportedOperationException();
56    }
57
58    @Override
59    public String getAttributeName(int index) {
60        throw new UnsupportedOperationException();
61    }
62
63    @Override
64    public String getAttributeValue(int index) {
65        throw new UnsupportedOperationException();
66    }
67
68    @Override
69    public String getPositionDescription() {
70        throw new UnsupportedOperationException();
71    }
72
73    @Override
74    public int getAttributeNameResource(int index) {
75        throw new UnsupportedOperationException();
76    }
77
78    @Override
79    public int getAttributeListValue(String namespace, String attribute,
80            String[] options, int defaultValue) {
81        throw new UnsupportedOperationException();
82    }
83
84    @Override
85    public boolean getAttributeBooleanValue(String namespace, String attribute,
86            boolean defaultValue) {
87        throw new UnsupportedOperationException();
88    }
89
90    @Override
91    public int getAttributeResourceValue(String namespace, String attribute,
92            int defaultValue) {
93        throw new UnsupportedOperationException();
94    }
95
96    @Override
97    public int getAttributeIntValue(String namespace, String attribute,
98            int defaultValue) {
99        throw new UnsupportedOperationException();
100    }
101
102    @Override
103    public int getAttributeUnsignedIntValue(String namespace, String attribute,
104            int defaultValue) {
105        throw new UnsupportedOperationException();
106    }
107
108    @Override
109    public float getAttributeFloatValue(String namespace, String attribute,
110            float defaultValue) {
111        throw new UnsupportedOperationException();
112    }
113
114    @Override
115    public int getAttributeListValue(int index,
116            String[] options, int defaultValue) {
117        throw new UnsupportedOperationException();
118    }
119
120    @Override
121    public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
122        throw new UnsupportedOperationException();
123    }
124
125    @Override
126    public int getAttributeResourceValue(int index, int defaultValue) {
127        throw new UnsupportedOperationException();
128    }
129
130    @Override
131    public int getAttributeIntValue(int index, int defaultValue) {
132        throw new UnsupportedOperationException();
133    }
134
135    @Override
136    public int getAttributeUnsignedIntValue(int index, int defaultValue) {
137        throw new UnsupportedOperationException();
138    }
139
140    @Override
141    public float getAttributeFloatValue(int index, float defaultValue) {
142        throw new UnsupportedOperationException();
143    }
144
145    @Override
146    public String getIdAttribute() {
147        throw new UnsupportedOperationException();
148    }
149
150    @Override
151    public String getClassAttribute() {
152        throw new UnsupportedOperationException();
153    }
154
155    @Override
156    public int getIdAttributeResourceValue(int defaultValue) {
157        throw new UnsupportedOperationException();
158    }
159
160    @Override
161    public int getStyleAttribute() {
162        throw new UnsupportedOperationException();
163    }
164}
165