001: /* Copyright 2007 David N. Welton - DedaSys LLC - http://www.dedasys.com
002:
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014: */
015:
016: package org.hecl.android;
017:
018: import android.util.AttributeSet;
019: import android.util.Log;
020:
021: import java.util.Enumeration;
022: import java.util.Vector;
023:
024: import org.hecl.DoubleThing;
025: import org.hecl.HeclException;
026: import org.hecl.IntThing;
027: import org.hecl.Properties;
028: import org.hecl.Thing;
029:
030: public class AttributeProps extends Properties implements AttributeSet {
031: private Vector names;
032: private Vector values;
033:
034: public AttributeProps() {
035: super ();
036: }
037:
038: private void update() {
039: Vector values = new Vector();
040: Enumeration vals = props.elements();
041: while (vals.hasMoreElements()) {
042: values.add(vals.nextElement());
043: }
044:
045: Vector names = new Vector();
046: Enumeration nms = props.keys();
047: while (nms.hasMoreElements()) {
048: names.add(nms.nextElement());
049: }
050:
051: Log.v("names", "are " + names);
052: Log.v("values", "are " + values);
053: }
054:
055: public void setProps(Thing[] argv, int offset) throws HeclException {
056:
057: super .setProps(argv, offset);
058: update();
059: }
060:
061: public void setProp(String name, Thing val) {
062: super .setProp(name, val);
063: update();
064: }
065:
066: public void delProp(String name) {
067: super .delProp(name);
068: update();
069: }
070:
071: public boolean getAttributeBooleanValue(String namespace,
072: String attribute, boolean defaultValue) {
073:
074: Log.v("attributeprops", "1");
075:
076: Thing val = super .getProp(attribute);
077: try {
078: if (val != null) {
079: return IntThing.get(val) != 0;
080: }
081: } catch (HeclException he) {
082: /* Ignore it */
083: }
084: return defaultValue;
085: }
086:
087: public boolean getAttributeBooleanValue(int index,
088: boolean defaultValue) {
089:
090: Log.v("attributeprops", "1");
091:
092: Thing val = (Thing) values.elementAt(index);
093: try {
094: if (val != null) {
095: return IntThing.get(val) != 0;
096: }
097: } catch (HeclException he) {
098: /* Ignore it */
099: }
100: return defaultValue;
101: }
102:
103: public int getAttributeCount() {
104:
105: Log.v("attributeprops", "1");
106:
107: return values.size();
108: }
109:
110: public float getAttributeFloatValue(int index, float defaultValue) {
111: Log.v("attributeprops", "1");
112:
113: Thing val = (Thing) values.elementAt(index);
114: try {
115: if (val != null) {
116: return (float) DoubleThing.get(val);
117: }
118: } catch (HeclException he) {
119: /* Ignore it */
120: }
121: return defaultValue;
122: }
123:
124: public float getAttributeFloatValue(String namespace,
125: String attribute, float defaultValue) {
126:
127: Log.v("attributeprops", "1");
128:
129: Thing val = super .getProp(attribute);
130: try {
131: if (val != null) {
132: return (float) DoubleThing.get(val);
133: }
134: } catch (HeclException he) {
135: /* Ignore it */
136: }
137: return defaultValue;
138:
139: }
140:
141: public int getAttributeIntValue(int index, int defaultValue) {
142:
143: Log.v("attributeprops", "1");
144:
145: Thing val = (Thing) values.elementAt(index);
146: try {
147: if (val != null) {
148: return IntThing.get(val);
149: }
150: } catch (HeclException he) {
151: /* Ignore it */
152: }
153: return defaultValue;
154: }
155:
156: public int getAttributeIntValue(String namespace, String attribute,
157: int defaultValue) {
158:
159: Log.v("attributeprops", "1");
160:
161: Thing val = super .getProp(attribute);
162: try {
163: if (val != null) {
164: return IntThing.get(val);
165: }
166: } catch (HeclException he) {
167: /* Ignore it */
168: }
169: return defaultValue;
170: }
171:
172: public int getAttributeListValue(String namespace,
173: String attribute, String[] options, int defaultValue) {
174:
175: Log.v("attributeprops", "1");
176:
177: return 0;
178:
179: }
180:
181: public int getAttributeListValue(int index, String[] options,
182: int defaultValue) {
183: Log.v("attributeprops", "1");
184:
185: return 0;
186:
187: }
188:
189: public String getAttributeName(int index) {
190: Log.v("attributeprops", "1");
191:
192: return names.elementAt(index).toString();
193: }
194:
195: public int getAttributeNameResource(int index) {
196: Log.v("attributeprops", "1");
197:
198: return 0; /* There's no resource... */
199: }
200:
201: public int getAttributeResourceValue(String namespace,
202: String attribute, int defaultValue) {
203: Log.v("attributeprops", "1");
204:
205: return defaultValue;
206: }
207:
208: public int getAttributeResourceValue(int index, int defaultValue) {
209: Log.v("attributeprops", "1");
210:
211: return defaultValue;
212: }
213:
214: public int getAttributeUnsignedIntValue(String namespace,
215: String attribute, int defaultValue) {
216:
217: Log.v("attributeprops", "1");
218:
219: Thing val = super .getProp(attribute);
220: try {
221: if (val != null) {
222: return (int) IntThing.get(val);
223: }
224: } catch (HeclException he) {
225: /* Ignore it */
226: }
227: return defaultValue;
228: }
229:
230: public int getAttributeUnsignedIntValue(int index, int defaultValue) {
231: Log.v("attributeprops", "1");
232:
233: Thing val = (Thing) values.elementAt(index);
234: try {
235: if (val != null) {
236: return (int) IntThing.get(val);
237: }
238: } catch (HeclException he) {
239: /* Ignore it */
240: }
241: return defaultValue;
242: }
243:
244: public String getAttributeValue(String namespace, String name) {
245: Log.v("attributeprops", "1");
246:
247: Thing val = super .getProp(name);
248: return val.toString();
249: }
250:
251: public String getAttributeValue(int index) {
252: Log.v("attributeprops", "1");
253:
254: Thing val = (Thing) values.elementAt(index);
255: return val.toString();
256: }
257:
258: public String getClassAttribute() {
259: Log.v("attributeprops", "1");
260:
261: return null;
262: }
263:
264: public String getIdAttribute() {
265: Log.v("attributeprops", "1");
266:
267: return null;
268: }
269:
270: public int getIdAttributeResourceValue(int defaultValue) {
271: Log.v("attributeprops", "1");
272:
273: return defaultValue;
274: }
275:
276: public String getPositionDescription() {
277: Log.v("attributeprops", "1");
278:
279: return "";
280: }
281:
282: public int getStyleAttribute() {
283: Log.v("attributeprops", "1");
284:
285: return 0;
286: }
287: }
|