• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

Revision71194de29071f45e3f9a45ad32bcf377aeab2c5a (tree)
Time2009-03-25 14:20:57
AuthorRaphael Moll <>
CommiterThe Android Open Source Project

Log Message

Automated import from //branches/donutburger/...@142274,142274

Change Summary

Incremental Difference

--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/resources/DeclareStyleableInfo.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/resources/DeclareStyleableInfo.java
@@ -70,6 +70,18 @@ public class DeclareStyleableInfo {
7070 mFormats = formats;
7171 }
7272
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+
7385 public AttributeInfo(AttributeInfo info) {
7486 mName = info.mName;
7587 mFormats = info.mFormats;
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/descriptors/ElementDescriptor.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/descriptors/ElementDescriptor.java
@@ -24,6 +24,7 @@ import com.android.sdklib.SdkConstants;
2424 import org.eclipse.jface.resource.ImageDescriptor;
2525 import org.eclipse.swt.graphics.Image;
2626
27+import java.util.Collection;
2728 import java.util.HashSet;
2829 import java.util.Set;
2930
@@ -221,6 +222,18 @@ public class ElementDescriptor {
221222 mChildren = newChildren;
222223 }
223224
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+
224237 /**
225238 * Returns an optional tooltip. Will be null if not present.
226239 * <p/>
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java
@@ -43,7 +43,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
4343 public static final String ID_ATTR = "id"; //$NON-NLS-1$
4444
4545 /** The document descriptor. Contains all layouts and views linked together. */
46- private DocumentDescriptor mDescriptor =
46+ private DocumentDescriptor mRootDescriptor =
4747 new DocumentDescriptor("layout_doc", null); //$NON-NLS-1$
4848
4949 /** The list of all known ViewLayout descriptors. */
@@ -60,7 +60,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
6060
6161 /** @return the document descriptor. Contains all layouts and views linked together. */
6262 public DocumentDescriptor getDescriptor() {
63- return mDescriptor;
63+ return mRootDescriptor;
6464 }
6565
6666 /** @return The read-only list of all known ViewLayout descriptors. */
@@ -74,7 +74,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
7474 }
7575
7676 public ElementDescriptor[] getRootElementDescriptors() {
77- return mDescriptor.getChildren();
77+ return mRootDescriptor.getChildren();
7878 }
7979
8080 /**
@@ -98,6 +98,10 @@ public final class LayoutDescriptors implements IDescriptorProvider {
9898 }
9999 }
100100
101+ // Create <include> as a synthetic regular view.
102+ // Note: ViewStub is already described by attrs.xml
103+ insertInclude(newViews);
104+
101105 ArrayList<ElementDescriptor> newLayouts = new ArrayList<ElementDescriptor>();
102106 if (layouts != null) {
103107 for (ViewClassInfo info : layouts) {
@@ -109,17 +113,22 @@ public final class LayoutDescriptors implements IDescriptorProvider {
109113 ArrayList<ElementDescriptor> newDescriptors = new ArrayList<ElementDescriptor>();
110114 newDescriptors.addAll(newLayouts);
111115 newDescriptors.addAll(newViews);
112- ElementDescriptor[] newArray = newDescriptors.toArray(
113- new ElementDescriptor[newDescriptors.size()]);
114116
115117 // Link all layouts to everything else here.. recursively
116118 for (ElementDescriptor layoutDesc : newLayouts) {
117- layoutDesc.setChildren(newArray);
119+ layoutDesc.setChildren(newDescriptors);
118120 }
119121
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+
120129 mViewDescriptors = newViews;
121130 mLayoutDescriptors = newLayouts;
122- mDescriptor.setChildren(newArray);
131+ mRootDescriptor.setChildren(newDescriptors);
123132
124133 mROLayoutDescriptors = Collections.unmodifiableList(mLayoutDescriptors);
125134 mROViewDescriptors = Collections.unmodifiableList(mViewDescriptors);
@@ -217,4 +226,91 @@ public final class LayoutDescriptors implements IDescriptorProvider {
217226 false /* mandatory */);
218227 }
219228
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+ }
220316 }