AI 143303: am: CL 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/...
  Original author: android-build
  Merged from: //branches/donutburger/...

Automated import of CL 143303
This commit is contained in:
Raphael Moll
2009-03-27 17:53:01 -07:00
committed by The Android Open Source Project
parent 11d34ff88b
commit 9350fdf467
5 changed files with 48 additions and 37 deletions

View File

@@ -157,7 +157,7 @@ public class LayoutParamsParser {
superClasses[2] = paramsClassName;
}
HashMap<String, ArrayList<IClassDescriptor>> found =
mClassLoader.findClassesDerivingFrom("android.", superClasses);
mClassLoader.findClassesDerivingFrom("android.", superClasses); //$NON-NLS-1$
mTopViewClass = mClassLoader.getClass(rootClassName);
mTopGroupClass = mClassLoader.getClass(groupClassName);
if (paramsClassName != null) {
@@ -179,8 +179,7 @@ public class LayoutParamsParser {
addView(mTopViewClass);
// ViewGroup derives from View
mGroupMap.get(groupClassName).setSuperClass(
mViewMap.get(rootClassName));
mGroupMap.get(groupClassName).setSuperClass(mViewMap.get(rootClassName));
progress.setWorkRemaining(mGroupList.size() + mViewList.size());
@@ -346,7 +345,7 @@ public class LayoutParamsParser {
private IClassDescriptor findLayoutParams(IClassDescriptor groupClass) {
IClassDescriptor[] innerClasses = groupClass.getDeclaredClasses();
for (IClassDescriptor innerClass : innerClasses) {
if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_LAYOUTPARAMS)) {
if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) {
return innerClass;
}
}

View File

@@ -189,14 +189,16 @@ public class AndroidConstants {
public final static String CLASS_CONTEXT = "android.content.Context"; //$NON-NLS-1$
public final static String CLASS_VIEW = "android.view.View"; //$NON-NLS-1$
public final static String CLASS_VIEWGROUP = "android.view.ViewGroup"; //$NON-NLS-1$
public final static String CLASS_LAYOUTPARAMS = "LayoutParams"; //$NON-NLS-1$
public final static String CLASS_NAME_LAYOUTPARAMS = "LayoutParams"; //$NON-NLS-1$
public final static String CLASS_VIEWGROUP_LAYOUTPARAMS =
CLASS_VIEWGROUP + "$" + CLASS_LAYOUTPARAMS; //$NON-NLS-1$
public final static String CLASS_FRAMELAYOUT = "FrameLayout"; //$NON-NLS-1$
CLASS_VIEWGROUP + "$" + CLASS_NAME_LAYOUTPARAMS; //$NON-NLS-1$
public final static String CLASS_NAME_FRAMELAYOUT = "FrameLayout"; //$NON-NLS-1$
public final static String CLASS_FRAMELAYOUT =
"android.widget." + CLASS_NAME_FRAMELAYOUT; //$NON-NLS-1$
public final static String CLASS_PREFERENCE = "android.preference.Preference"; //$NON-NLS-1$
public final static String CLASS_PREFERENCE_SCREEN = "PreferenceScreen"; //$NON-NLS-1$
public final static String CLASS_NAME_PREFERENCE_SCREEN = "PreferenceScreen"; //$NON-NLS-1$
public final static String CLASS_PREFERENCES =
"android.preference." + CLASS_PREFERENCE_SCREEN; //$NON-NLS-1$
"android.preference." + CLASS_NAME_PREFERENCE_SCREEN; //$NON-NLS-1$
public final static String CLASS_PREFERENCEGROUP = "android.preference.PreferenceGroup"; //$NON-NLS-1$
public final static String CLASS_PARCELABLE = "android.os.Parcelable"; //$NON-NLS-1$

View File

@@ -121,7 +121,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
// The <merge> tag can only be a root tag, so it is added at the end.
// It gets everything else as children but it is not made a child itself.
ElementDescriptor mergeTag = createMerge();
ElementDescriptor mergeTag = createMerge(newLayouts);
mergeTag.setChildren(newDescriptors); // mergeTag makes a copy of the list
newDescriptors.add(mergeTag);
newLayouts.add(mergeTag);
@@ -195,7 +195,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
if (need_separator) {
String title;
if (layoutParams.getShortClassName().equals(
AndroidConstants.CLASS_LAYOUTPARAMS)) {
AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) {
title = String.format("Layout Attributes from %1$s",
layoutParams.getViewLayoutClass().getShortClassName());
} else {
@@ -229,10 +229,10 @@ public final class LayoutDescriptors implements IDescriptorProvider {
/**
* Creates a new <include> descriptor and adds it to the list of view descriptors.
*
* @param newViews A list of view descriptors being populated. Also used to find the
* View description and extract its layout attributes.
* @param knownViews A list of view descriptors being populated. Also used to find the
* View descriptor and extract its layout attributes.
*/
private void insertInclude(ArrayList<ElementDescriptor> newViews) {
private void insertInclude(ArrayList<ElementDescriptor> knownViews) {
String xml_name = "include"; //$NON-NLS-1$
// Create the include custom attributes
@@ -260,7 +260,8 @@ public final class LayoutDescriptors implements IDescriptorProvider {
null); //overrides
// Find View and inherit all its layout attributes
AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(newViews);
AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(
AndroidConstants.CLASS_VIEW, knownViews);
// Create the include descriptor
ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
@@ -273,33 +274,21 @@ public final class LayoutDescriptors implements IDescriptorProvider {
null, // children
false /* mandatory */);
newViews.add(desc);
}
/**
* Finds the View descriptor and retrieves all its layout attributes.
*/
private AttributeDescriptor[] findViewLayoutAttributes(
ArrayList<ElementDescriptor> newViews) {
for (ElementDescriptor desc : newViews) {
if (desc instanceof ViewElementDescriptor) {
ViewElementDescriptor viewDesc = (ViewElementDescriptor) desc;
if (AndroidConstants.CLASS_VIEW.equals(viewDesc.getCanonicalClassName())) {
return viewDesc.getLayoutAttributes();
}
}
}
return null;
knownViews.add(desc);
}
/**
* Creates and return a new <merge> descriptor.
* @param knownLayouts A list of all known layout view descriptors, used to find the
* FrameLayout descriptor and extract its layout attributes.
*/
private ElementDescriptor createMerge() {
private ElementDescriptor createMerge(ArrayList<ElementDescriptor> knownLayouts) {
String xml_name = "merge"; //$NON-NLS-1$
// Find View and inherit all its layout attributes
AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(
AndroidConstants.CLASS_FRAMELAYOUT, knownLayouts);
// Create the include descriptor
ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
xml_name, // ui_name
@@ -307,10 +296,29 @@ public final class LayoutDescriptors implements IDescriptorProvider {
"A root tag useful for XML layouts inflated using a ViewStub.", // tooltip
null, // sdk_url
null, // attributes
null, // layout attributes
viewLayoutAttribs, // layout attributes
null, // children
false /* mandatory */);
return desc;
}
/**
* Finds the descriptor and retrieves all its layout attributes.
*/
private AttributeDescriptor[] findViewLayoutAttributes(
String viewFqcn,
ArrayList<ElementDescriptor> knownViews) {
for (ElementDescriptor desc : knownViews) {
if (desc instanceof ViewElementDescriptor) {
ViewElementDescriptor viewDesc = (ViewElementDescriptor) desc;
if (viewFqcn.equals(viewDesc.getCanonicalClassName())) {
return viewDesc.getLayoutAttributes();
}
}
}
return null;
}
}

View File

@@ -96,6 +96,8 @@ class DropFeedback {
RelativeInfo info = null;
UiElementEditPart sibling = null;
// TODO consider merge like a vertical layout
// TODO consider TableLayout like a linear
if (LayoutConstants.LINEAR_LAYOUT.equals(layoutXmlName)) {
sibling = findLinearTarget(parentPart, where)[1];

View File

@@ -81,7 +81,7 @@ public class UiViewElementNode extends UiElementNode {
if (layoutDescriptors != null) {
for (ElementDescriptor desc : layoutDescriptors) {
if (desc instanceof ViewElementDescriptor &&
desc.getXmlName().equals(AndroidConstants.CLASS_FRAMELAYOUT)) {
desc.getXmlName().equals(AndroidConstants.CLASS_NAME_FRAMELAYOUT)) {
layout_attrs = ((ViewElementDescriptor) desc).getLayoutAttributes();
need_xmlns = true;
break;