• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 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 android.util;
18 
19 import org.xmlpull.v1.XmlPullParser;
20 
21 import android.util.AttributeSet;
22 
23 import com.android.internal.util.XmlUtils;
24 
25 /**
26  * Provides an implementation of AttributeSet on top of an XmlPullParser.
27  */
28 class XmlPullAttributes implements AttributeSet {
XmlPullAttributes(XmlPullParser parser)29     public XmlPullAttributes(XmlPullParser parser) {
30         mParser = parser;
31     }
32 
getAttributeCount()33     public int getAttributeCount() {
34         return mParser.getAttributeCount();
35     }
36 
getAttributeNamespace(int index)37     public String getAttributeNamespace (int index) {
38         return mParser.getAttributeNamespace(index);
39     }
40 
getAttributeName(int index)41     public String getAttributeName(int index) {
42         return mParser.getAttributeName(index);
43     }
44 
getAttributeValue(int index)45     public String getAttributeValue(int index) {
46         return mParser.getAttributeValue(index);
47     }
48 
getAttributeValue(String namespace, String name)49     public String getAttributeValue(String namespace, String name) {
50         return mParser.getAttributeValue(namespace, name);
51     }
52 
getPositionDescription()53     public String getPositionDescription() {
54         return mParser.getPositionDescription();
55     }
56 
getAttributeNameResource(int index)57     public int getAttributeNameResource(int index) {
58         return 0;
59     }
60 
getAttributeListValue(String namespace, String attribute, String[] options, int defaultValue)61     public int getAttributeListValue(String namespace, String attribute,
62             String[] options, int defaultValue) {
63         return XmlUtils.convertValueToList(
64             getAttributeValue(namespace, attribute), options, defaultValue);
65     }
66 
getAttributeBooleanValue(String namespace, String attribute, boolean defaultValue)67     public boolean getAttributeBooleanValue(String namespace, String attribute,
68             boolean defaultValue) {
69         return XmlUtils.convertValueToBoolean(
70             getAttributeValue(namespace, attribute), defaultValue);
71     }
72 
getAttributeResourceValue(String namespace, String attribute, int defaultValue)73     public int getAttributeResourceValue(String namespace, String attribute,
74             int defaultValue) {
75         return XmlUtils.convertValueToInt(
76             getAttributeValue(namespace, attribute), defaultValue);
77     }
78 
getAttributeIntValue(String namespace, String attribute, int defaultValue)79     public int getAttributeIntValue(String namespace, String attribute,
80             int defaultValue) {
81         return XmlUtils.convertValueToInt(
82             getAttributeValue(namespace, attribute), defaultValue);
83     }
84 
getAttributeUnsignedIntValue(String namespace, String attribute, int defaultValue)85     public int getAttributeUnsignedIntValue(String namespace, String attribute,
86             int defaultValue) {
87         return XmlUtils.convertValueToUnsignedInt(
88             getAttributeValue(namespace, attribute), defaultValue);
89     }
90 
getAttributeFloatValue(String namespace, String attribute, float defaultValue)91     public float getAttributeFloatValue(String namespace, String attribute,
92             float defaultValue) {
93         String s = getAttributeValue(namespace, attribute);
94         if (s != null) {
95             return Float.parseFloat(s);
96         }
97         return defaultValue;
98     }
99 
getAttributeListValue(int index, String[] options, int defaultValue)100     public int getAttributeListValue(int index,
101             String[] options, int defaultValue) {
102         return XmlUtils.convertValueToList(
103             getAttributeValue(index), options, defaultValue);
104     }
105 
getAttributeBooleanValue(int index, boolean defaultValue)106     public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
107         return XmlUtils.convertValueToBoolean(
108             getAttributeValue(index), defaultValue);
109     }
110 
getAttributeResourceValue(int index, int defaultValue)111     public int getAttributeResourceValue(int index, int defaultValue) {
112         return XmlUtils.convertValueToInt(
113             getAttributeValue(index), defaultValue);
114     }
115 
getAttributeIntValue(int index, int defaultValue)116     public int getAttributeIntValue(int index, int defaultValue) {
117         return XmlUtils.convertValueToInt(
118             getAttributeValue(index), defaultValue);
119     }
120 
getAttributeUnsignedIntValue(int index, int defaultValue)121     public int getAttributeUnsignedIntValue(int index, int defaultValue) {
122         return XmlUtils.convertValueToUnsignedInt(
123             getAttributeValue(index), defaultValue);
124     }
125 
getAttributeFloatValue(int index, float defaultValue)126     public float getAttributeFloatValue(int index, float defaultValue) {
127         String s = getAttributeValue(index);
128         if (s != null) {
129             return Float.parseFloat(s);
130         }
131         return defaultValue;
132     }
133 
getIdAttribute()134     public String getIdAttribute() {
135         return getAttributeValue(null, "id");
136     }
137 
getClassAttribute()138     public String getClassAttribute() {
139         return getAttributeValue(null, "class");
140     }
141 
getIdAttributeResourceValue(int defaultValue)142     public int getIdAttributeResourceValue(int defaultValue) {
143         return getAttributeResourceValue(null, "id", defaultValue);
144     }
145 
getStyleAttribute()146     public int getStyleAttribute() {
147         return getAttributeResourceValue(null, "style", 0);
148     }
149 
150     /*package*/ XmlPullParser mParser;
151 }
152