development
Revision | 71194de29071f45e3f9a45ad32bcf377aeab2c5a (tree) |
---|---|
Time | 2009-03-25 14:20:57 |
Author | Raphael Moll <> |
Commiter | The Android Open Source Project |
Automated import from //branches/donutburger/...@142274,142274
@@ -70,6 +70,18 @@ public class DeclareStyleableInfo { | ||
70 | 70 | mFormats = formats; |
71 | 71 | } |
72 | 72 | |
73 | + /** | |
74 | + * @param name The XML Name of the attribute | |
75 | + * @param formats The formats of the attribute. Cannot be null. | |
76 | + * Should have at least one format. | |
77 | + * @param javadoc Short javadoc (i.e. the first sentence). | |
78 | + */ | |
79 | + public AttributeInfo(String name, Format[] formats, String javadoc) { | |
80 | + mName = name; | |
81 | + mFormats = formats; | |
82 | + mJavaDoc = javadoc; | |
83 | + } | |
84 | + | |
73 | 85 | public AttributeInfo(AttributeInfo info) { |
74 | 86 | mName = info.mName; |
75 | 87 | mFormats = info.mFormats; |
@@ -24,6 +24,7 @@ import com.android.sdklib.SdkConstants; | ||
24 | 24 | import org.eclipse.jface.resource.ImageDescriptor; |
25 | 25 | import org.eclipse.swt.graphics.Image; |
26 | 26 | |
27 | +import java.util.Collection; | |
27 | 28 | import java.util.HashSet; |
28 | 29 | import java.util.Set; |
29 | 30 |
@@ -221,6 +222,18 @@ public class ElementDescriptor { | ||
221 | 222 | mChildren = newChildren; |
222 | 223 | } |
223 | 224 | |
225 | + /** Sets the list of allowed children. | |
226 | + * <p/> | |
227 | + * This is just a convenience method that converts a Collection into an array and | |
228 | + * calls {@link #setChildren(ElementDescriptor[])}. | |
229 | + * <p/> | |
230 | + * This means a <em>copy</em> of the collection is made. The collection is not | |
231 | + * stored by the recipient and can thus be altered by the caller. | |
232 | + */ | |
233 | + public void setChildren(Collection<ElementDescriptor> newChildren) { | |
234 | + setChildren(newChildren.toArray(new ElementDescriptor[newChildren.size()])); | |
235 | + } | |
236 | + | |
224 | 237 | /** |
225 | 238 | * Returns an optional tooltip. Will be null if not present. |
226 | 239 | * <p/> |
@@ -43,7 +43,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
43 | 43 | public static final String ID_ATTR = "id"; //$NON-NLS-1$ |
44 | 44 | |
45 | 45 | /** The document descriptor. Contains all layouts and views linked together. */ |
46 | - private DocumentDescriptor mDescriptor = | |
46 | + private DocumentDescriptor mRootDescriptor = | |
47 | 47 | new DocumentDescriptor("layout_doc", null); //$NON-NLS-1$ |
48 | 48 | |
49 | 49 | /** The list of all known ViewLayout descriptors. */ |
@@ -60,7 +60,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
60 | 60 | |
61 | 61 | /** @return the document descriptor. Contains all layouts and views linked together. */ |
62 | 62 | public DocumentDescriptor getDescriptor() { |
63 | - return mDescriptor; | |
63 | + return mRootDescriptor; | |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** @return The read-only list of all known ViewLayout descriptors. */ |
@@ -74,7 +74,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
74 | 74 | } |
75 | 75 | |
76 | 76 | public ElementDescriptor[] getRootElementDescriptors() { |
77 | - return mDescriptor.getChildren(); | |
77 | + return mRootDescriptor.getChildren(); | |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -98,6 +98,10 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | + // Create <include> as a synthetic regular view. | |
102 | + // Note: ViewStub is already described by attrs.xml | |
103 | + insertInclude(newViews); | |
104 | + | |
101 | 105 | ArrayList<ElementDescriptor> newLayouts = new ArrayList<ElementDescriptor>(); |
102 | 106 | if (layouts != null) { |
103 | 107 | for (ViewClassInfo info : layouts) { |
@@ -109,17 +113,22 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
109 | 113 | ArrayList<ElementDescriptor> newDescriptors = new ArrayList<ElementDescriptor>(); |
110 | 114 | newDescriptors.addAll(newLayouts); |
111 | 115 | newDescriptors.addAll(newViews); |
112 | - ElementDescriptor[] newArray = newDescriptors.toArray( | |
113 | - new ElementDescriptor[newDescriptors.size()]); | |
114 | 116 | |
115 | 117 | // Link all layouts to everything else here.. recursively |
116 | 118 | for (ElementDescriptor layoutDesc : newLayouts) { |
117 | - layoutDesc.setChildren(newArray); | |
119 | + layoutDesc.setChildren(newDescriptors); | |
118 | 120 | } |
119 | 121 | |
122 | + // The <merge> tag can only be a root tag, so it is added at the end. | |
123 | + // It gets everything else as children but it is not made a child itself. | |
124 | + ElementDescriptor mergeTag = createMerge(); | |
125 | + mergeTag.setChildren(newDescriptors); // mergeTag makes a copy of the list | |
126 | + newDescriptors.add(mergeTag); | |
127 | + newLayouts.add(mergeTag); | |
128 | + | |
120 | 129 | mViewDescriptors = newViews; |
121 | 130 | mLayoutDescriptors = newLayouts; |
122 | - mDescriptor.setChildren(newArray); | |
131 | + mRootDescriptor.setChildren(newDescriptors); | |
123 | 132 | |
124 | 133 | mROLayoutDescriptors = Collections.unmodifiableList(mLayoutDescriptors); |
125 | 134 | mROViewDescriptors = Collections.unmodifiableList(mViewDescriptors); |
@@ -217,4 +226,91 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
217 | 226 | false /* mandatory */); |
218 | 227 | } |
219 | 228 | |
229 | + /** | |
230 | + * Creates a new <include> descriptor and adds it to the list of view descriptors. | |
231 | + * | |
232 | + * @param newViews A list of view descriptors being populated. Also used to find the | |
233 | + * View description and extract its layout attributes. | |
234 | + */ | |
235 | + private void insertInclude(ArrayList<ElementDescriptor> newViews) { | |
236 | + String xml_name = "include"; //$NON-NLS-1$ | |
237 | + | |
238 | + // Create the include custom attributes | |
239 | + ArrayList<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>(); | |
240 | + | |
241 | + // Note that the "layout" attribute does NOT have the Android namespace | |
242 | + DescriptorsUtils.appendAttribute(attributes, | |
243 | + null, //elementXmlName | |
244 | + null, //nsUri | |
245 | + new AttributeInfo( | |
246 | + "layout", //$NON-NLS-1$ | |
247 | + new AttributeInfo.Format[] { AttributeInfo.Format.REFERENCE } | |
248 | + ), | |
249 | + true, //required | |
250 | + null); //overrides | |
251 | + | |
252 | + DescriptorsUtils.appendAttribute(attributes, | |
253 | + null, //elementXmlName | |
254 | + SdkConstants.NS_RESOURCES, //nsUri | |
255 | + new AttributeInfo( | |
256 | + "id", //$NON-NLS-1$ | |
257 | + new AttributeInfo.Format[] { AttributeInfo.Format.REFERENCE } | |
258 | + ), | |
259 | + true, //required | |
260 | + null); //overrides | |
261 | + | |
262 | + // Find View and inherit all its layout attributes | |
263 | + AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(newViews); | |
264 | + | |
265 | + // Create the include descriptor | |
266 | + ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name | |
267 | + xml_name, // ui_name | |
268 | + null, // canonical class name, we don't have one | |
269 | + "Lets you statically include XML layouts inside other XML layouts.", // tooltip | |
270 | + null, // sdk_url | |
271 | + attributes.toArray(new AttributeDescriptor[attributes.size()]), | |
272 | + viewLayoutAttribs, // layout attributes | |
273 | + null, // children | |
274 | + false /* mandatory */); | |
275 | + | |
276 | + newViews.add(desc); | |
277 | + } | |
278 | + | |
279 | + /** | |
280 | + * Finds the View descriptor and retrieves all its layout attributes. | |
281 | + */ | |
282 | + private AttributeDescriptor[] findViewLayoutAttributes( | |
283 | + ArrayList<ElementDescriptor> newViews) { | |
284 | + | |
285 | + for (ElementDescriptor desc : newViews) { | |
286 | + if (desc instanceof ViewElementDescriptor) { | |
287 | + ViewElementDescriptor viewDesc = (ViewElementDescriptor) desc; | |
288 | + if (AndroidConstants.CLASS_VIEW.equals(viewDesc.getCanonicalClassName())) { | |
289 | + return viewDesc.getLayoutAttributes(); | |
290 | + } | |
291 | + } | |
292 | + } | |
293 | + | |
294 | + return null; | |
295 | + } | |
296 | + | |
297 | + /** | |
298 | + * Creates and return a new <merge> descriptor. | |
299 | + */ | |
300 | + private ElementDescriptor createMerge() { | |
301 | + String xml_name = "merge"; //$NON-NLS-1$ | |
302 | + | |
303 | + // Create the include descriptor | |
304 | + ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name | |
305 | + xml_name, // ui_name | |
306 | + null, // canonical class name, we don't have one | |
307 | + "A root tag useful for XML layouts inflated using a ViewStub.", // tooltip | |
308 | + null, // sdk_url | |
309 | + null, // attributes | |
310 | + null, // layout attributes | |
311 | + null, // children | |
312 | + false /* mandatory */); | |
313 | + | |
314 | + return desc; | |
315 | + } | |
220 | 316 | } |