• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

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

development


Commit MetaInfo

修訂b1c2adad16ef074d3b80d5fe7f3ec821ed383343 (tree)
時間2009-03-28 07:22:09
作者Raphael Moll <>
CommiterThe Android Open Source Project

Log Message

AI 143156: am: CL 142851 ADT GLE fix #1731389: widgets dropped in <merge> lack their default layout_widht/height.

Issue: <merge> did not have layout attributes. When new widgets are
dropped in a layout, GLE only adds layout width/height if the parent
supports them.
Fix: Make <merge> have layout attributes from FrameLayout. The ideal
choice would have been ViewGroup, but since ViewGroup is abstract we
don't have any ViewDescriptor for it. FrameLayout should provide a
sensible replacement.
Note: this requires CL 142780 to compile.
Original author: raphael
Merged from: //branches/cupcake/...

Automated import of CL 143156

Change Summary

差異

--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/LayoutParamsParser.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/LayoutParamsParser.java
@@ -157,7 +157,7 @@ public class LayoutParamsParser {
157157 superClasses[2] = paramsClassName;
158158 }
159159 HashMap<String, ArrayList<IClassDescriptor>> found =
160- mClassLoader.findClassesDerivingFrom("android.", superClasses);
160+ mClassLoader.findClassesDerivingFrom("android.", superClasses); //$NON-NLS-1$
161161 mTopViewClass = mClassLoader.getClass(rootClassName);
162162 mTopGroupClass = mClassLoader.getClass(groupClassName);
163163 if (paramsClassName != null) {
@@ -179,8 +179,7 @@ public class LayoutParamsParser {
179179 addView(mTopViewClass);
180180
181181 // ViewGroup derives from View
182- mGroupMap.get(groupClassName).setSuperClass(
183- mViewMap.get(rootClassName));
182+ mGroupMap.get(groupClassName).setSuperClass(mViewMap.get(rootClassName));
184183
185184 progress.setWorkRemaining(mGroupList.size() + mViewList.size());
186185
@@ -346,7 +345,7 @@ public class LayoutParamsParser {
346345 private IClassDescriptor findLayoutParams(IClassDescriptor groupClass) {
347346 IClassDescriptor[] innerClasses = groupClass.getDeclaredClasses();
348347 for (IClassDescriptor innerClass : innerClasses) {
349- if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_LAYOUTPARAMS)) {
348+ if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) {
350349 return innerClass;
351350 }
352351 }
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/AndroidConstants.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/AndroidConstants.java
@@ -189,14 +189,16 @@ public class AndroidConstants {
189189 public final static String CLASS_CONTEXT = "android.content.Context"; //$NON-NLS-1$
190190 public final static String CLASS_VIEW = "android.view.View"; //$NON-NLS-1$
191191 public final static String CLASS_VIEWGROUP = "android.view.ViewGroup"; //$NON-NLS-1$
192- public final static String CLASS_LAYOUTPARAMS = "LayoutParams"; //$NON-NLS-1$
192+ public final static String CLASS_NAME_LAYOUTPARAMS = "LayoutParams"; //$NON-NLS-1$
193193 public final static String CLASS_VIEWGROUP_LAYOUTPARAMS =
194- CLASS_VIEWGROUP + "$" + CLASS_LAYOUTPARAMS; //$NON-NLS-1$
195- public final static String CLASS_FRAMELAYOUT = "FrameLayout"; //$NON-NLS-1$
194+ CLASS_VIEWGROUP + "$" + CLASS_NAME_LAYOUTPARAMS; //$NON-NLS-1$
195+ public final static String CLASS_NAME_FRAMELAYOUT = "FrameLayout"; //$NON-NLS-1$
196+ public final static String CLASS_FRAMELAYOUT =
197+ "android.widget." + CLASS_NAME_FRAMELAYOUT; //$NON-NLS-1$
196198 public final static String CLASS_PREFERENCE = "android.preference.Preference"; //$NON-NLS-1$
197- public final static String CLASS_PREFERENCE_SCREEN = "PreferenceScreen"; //$NON-NLS-1$
199+ public final static String CLASS_NAME_PREFERENCE_SCREEN = "PreferenceScreen"; //$NON-NLS-1$
198200 public final static String CLASS_PREFERENCES =
199- "android.preference." + CLASS_PREFERENCE_SCREEN; //$NON-NLS-1$
201+ "android.preference." + CLASS_NAME_PREFERENCE_SCREEN; //$NON-NLS-1$
200202 public final static String CLASS_PREFERENCEGROUP = "android.preference.PreferenceGroup"; //$NON-NLS-1$
201203 public final static String CLASS_PARCELABLE = "android.os.Parcelable"; //$NON-NLS-1$
202204
--- 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
@@ -121,7 +121,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
121121
122122 // The <merge> tag can only be a root tag, so it is added at the end.
123123 // It gets everything else as children but it is not made a child itself.
124- ElementDescriptor mergeTag = createMerge();
124+ ElementDescriptor mergeTag = createMerge(newLayouts);
125125 mergeTag.setChildren(newDescriptors); // mergeTag makes a copy of the list
126126 newDescriptors.add(mergeTag);
127127 newLayouts.add(mergeTag);
@@ -195,7 +195,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
195195 if (need_separator) {
196196 String title;
197197 if (layoutParams.getShortClassName().equals(
198- AndroidConstants.CLASS_LAYOUTPARAMS)) {
198+ AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) {
199199 title = String.format("Layout Attributes from %1$s",
200200 layoutParams.getViewLayoutClass().getShortClassName());
201201 } else {
@@ -229,10 +229,10 @@ public final class LayoutDescriptors implements IDescriptorProvider {
229229 /**
230230 * Creates a new <include> descriptor and adds it to the list of view descriptors.
231231 *
232- * @param newViews A list of view descriptors being populated. Also used to find the
233- * View description and extract its layout attributes.
232+ * @param knownViews A list of view descriptors being populated. Also used to find the
233+ * View descriptor and extract its layout attributes.
234234 */
235- private void insertInclude(ArrayList<ElementDescriptor> newViews) {
235+ private void insertInclude(ArrayList<ElementDescriptor> knownViews) {
236236 String xml_name = "include"; //$NON-NLS-1$
237237
238238 // Create the include custom attributes
@@ -260,7 +260,8 @@ public final class LayoutDescriptors implements IDescriptorProvider {
260260 null); //overrides
261261
262262 // Find View and inherit all its layout attributes
263- AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(newViews);
263+ AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(
264+ AndroidConstants.CLASS_VIEW, knownViews);
264265
265266 // Create the include descriptor
266267 ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
@@ -273,33 +274,21 @@ public final class LayoutDescriptors implements IDescriptorProvider {
273274 null, // children
274275 false /* mandatory */);
275276
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;
277+ knownViews.add(desc);
295278 }
296279
297280 /**
298281 * Creates and return a new <merge> descriptor.
282+ * @param knownLayouts A list of all known layout view descriptors, used to find the
283+ * FrameLayout descriptor and extract its layout attributes.
299284 */
300- private ElementDescriptor createMerge() {
285+ private ElementDescriptor createMerge(ArrayList<ElementDescriptor> knownLayouts) {
301286 String xml_name = "merge"; //$NON-NLS-1$
302287
288+ // Find View and inherit all its layout attributes
289+ AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(
290+ AndroidConstants.CLASS_FRAMELAYOUT, knownLayouts);
291+
303292 // Create the include descriptor
304293 ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
305294 xml_name, // ui_name
@@ -307,10 +296,29 @@ public final class LayoutDescriptors implements IDescriptorProvider {
307296 "A root tag useful for XML layouts inflated using a ViewStub.", // tooltip
308297 null, // sdk_url
309298 null, // attributes
310- null, // layout attributes
299+ viewLayoutAttribs, // layout attributes
311300 null, // children
312301 false /* mandatory */);
313302
314303 return desc;
315304 }
305+
306+ /**
307+ * Finds the descriptor and retrieves all its layout attributes.
308+ */
309+ private AttributeDescriptor[] findViewLayoutAttributes(
310+ String viewFqcn,
311+ ArrayList<ElementDescriptor> knownViews) {
312+
313+ for (ElementDescriptor desc : knownViews) {
314+ if (desc instanceof ViewElementDescriptor) {
315+ ViewElementDescriptor viewDesc = (ViewElementDescriptor) desc;
316+ if (viewFqcn.equals(viewDesc.getCanonicalClassName())) {
317+ return viewDesc.getLayoutAttributes();
318+ }
319+ }
320+ }
321+
322+ return null;
323+ }
316324 }
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/parts/DropFeedback.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/parts/DropFeedback.java
@@ -96,6 +96,8 @@ class DropFeedback {
9696 RelativeInfo info = null;
9797 UiElementEditPart sibling = null;
9898
99+ // TODO consider merge like a vertical layout
100+ // TODO consider TableLayout like a linear
99101 if (LayoutConstants.LINEAR_LAYOUT.equals(layoutXmlName)) {
100102 sibling = findLinearTarget(parentPart, where)[1];
101103
--- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/uimodel/UiViewElementNode.java
+++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/uimodel/UiViewElementNode.java
@@ -81,7 +81,7 @@ public class UiViewElementNode extends UiElementNode {
8181 if (layoutDescriptors != null) {
8282 for (ElementDescriptor desc : layoutDescriptors) {
8383 if (desc instanceof ViewElementDescriptor &&
84- desc.getXmlName().equals(AndroidConstants.CLASS_FRAMELAYOUT)) {
84+ desc.getXmlName().equals(AndroidConstants.CLASS_NAME_FRAMELAYOUT)) {
8585 layout_attrs = ((ViewElementDescriptor) desc).getLayoutAttributes();
8686 need_xmlns = true;
8787 break;