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
This commit is contained in:
committed by
The Android Open Source Project
parent
0105db6763
commit
b1c2adad16
@@ -157,7 +157,7 @@ public class LayoutParamsParser {
|
|||||||
superClasses[2] = paramsClassName;
|
superClasses[2] = paramsClassName;
|
||||||
}
|
}
|
||||||
HashMap<String, ArrayList<IClassDescriptor>> found =
|
HashMap<String, ArrayList<IClassDescriptor>> found =
|
||||||
mClassLoader.findClassesDerivingFrom("android.", superClasses);
|
mClassLoader.findClassesDerivingFrom("android.", superClasses); //$NON-NLS-1$
|
||||||
mTopViewClass = mClassLoader.getClass(rootClassName);
|
mTopViewClass = mClassLoader.getClass(rootClassName);
|
||||||
mTopGroupClass = mClassLoader.getClass(groupClassName);
|
mTopGroupClass = mClassLoader.getClass(groupClassName);
|
||||||
if (paramsClassName != null) {
|
if (paramsClassName != null) {
|
||||||
@@ -179,8 +179,7 @@ public class LayoutParamsParser {
|
|||||||
addView(mTopViewClass);
|
addView(mTopViewClass);
|
||||||
|
|
||||||
// ViewGroup derives from View
|
// ViewGroup derives from View
|
||||||
mGroupMap.get(groupClassName).setSuperClass(
|
mGroupMap.get(groupClassName).setSuperClass(mViewMap.get(rootClassName));
|
||||||
mViewMap.get(rootClassName));
|
|
||||||
|
|
||||||
progress.setWorkRemaining(mGroupList.size() + mViewList.size());
|
progress.setWorkRemaining(mGroupList.size() + mViewList.size());
|
||||||
|
|
||||||
@@ -346,7 +345,7 @@ public class LayoutParamsParser {
|
|||||||
private IClassDescriptor findLayoutParams(IClassDescriptor groupClass) {
|
private IClassDescriptor findLayoutParams(IClassDescriptor groupClass) {
|
||||||
IClassDescriptor[] innerClasses = groupClass.getDeclaredClasses();
|
IClassDescriptor[] innerClasses = groupClass.getDeclaredClasses();
|
||||||
for (IClassDescriptor innerClass : innerClasses) {
|
for (IClassDescriptor innerClass : innerClasses) {
|
||||||
if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_LAYOUTPARAMS)) {
|
if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) {
|
||||||
return innerClass;
|
return innerClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,14 +189,16 @@ public class AndroidConstants {
|
|||||||
public final static String CLASS_CONTEXT = "android.content.Context"; //$NON-NLS-1$
|
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_VIEW = "android.view.View"; //$NON-NLS-1$
|
||||||
public final static String CLASS_VIEWGROUP = "android.view.ViewGroup"; //$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 =
|
public final static String CLASS_VIEWGROUP_LAYOUTPARAMS =
|
||||||
CLASS_VIEWGROUP + "$" + CLASS_LAYOUTPARAMS; //$NON-NLS-1$
|
CLASS_VIEWGROUP + "$" + CLASS_NAME_LAYOUTPARAMS; //$NON-NLS-1$
|
||||||
public final static String CLASS_FRAMELAYOUT = "FrameLayout"; //$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 = "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 =
|
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_PREFERENCEGROUP = "android.preference.PreferenceGroup"; //$NON-NLS-1$
|
||||||
public final static String CLASS_PARCELABLE = "android.os.Parcelable"; //$NON-NLS-1$
|
public final static String CLASS_PARCELABLE = "android.os.Parcelable"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
// 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.
|
// 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
|
mergeTag.setChildren(newDescriptors); // mergeTag makes a copy of the list
|
||||||
newDescriptors.add(mergeTag);
|
newDescriptors.add(mergeTag);
|
||||||
newLayouts.add(mergeTag);
|
newLayouts.add(mergeTag);
|
||||||
@@ -195,7 +195,7 @@ public final class LayoutDescriptors implements IDescriptorProvider {
|
|||||||
if (need_separator) {
|
if (need_separator) {
|
||||||
String title;
|
String title;
|
||||||
if (layoutParams.getShortClassName().equals(
|
if (layoutParams.getShortClassName().equals(
|
||||||
AndroidConstants.CLASS_LAYOUTPARAMS)) {
|
AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) {
|
||||||
title = String.format("Layout Attributes from %1$s",
|
title = String.format("Layout Attributes from %1$s",
|
||||||
layoutParams.getViewLayoutClass().getShortClassName());
|
layoutParams.getViewLayoutClass().getShortClassName());
|
||||||
} else {
|
} 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.
|
* 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
|
* @param knownViews A list of view descriptors being populated. Also used to find the
|
||||||
* View description and extract its layout attributes.
|
* 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$
|
String xml_name = "include"; //$NON-NLS-1$
|
||||||
|
|
||||||
// Create the include custom attributes
|
// Create the include custom attributes
|
||||||
@@ -260,7 +260,8 @@ public final class LayoutDescriptors implements IDescriptorProvider {
|
|||||||
null); //overrides
|
null); //overrides
|
||||||
|
|
||||||
// Find View and inherit all its layout attributes
|
// Find View and inherit all its layout attributes
|
||||||
AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(newViews);
|
AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(
|
||||||
|
AndroidConstants.CLASS_VIEW, knownViews);
|
||||||
|
|
||||||
// Create the include descriptor
|
// Create the include descriptor
|
||||||
ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
|
ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
|
||||||
@@ -273,33 +274,21 @@ public final class LayoutDescriptors implements IDescriptorProvider {
|
|||||||
null, // children
|
null, // children
|
||||||
false /* mandatory */);
|
false /* mandatory */);
|
||||||
|
|
||||||
newViews.add(desc);
|
knownViews.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and return a new <merge> descriptor.
|
* 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$
|
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
|
// Create the include descriptor
|
||||||
ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
|
ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name
|
||||||
xml_name, // ui_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
|
"A root tag useful for XML layouts inflated using a ViewStub.", // tooltip
|
||||||
null, // sdk_url
|
null, // sdk_url
|
||||||
null, // attributes
|
null, // attributes
|
||||||
null, // layout attributes
|
viewLayoutAttribs, // layout attributes
|
||||||
null, // children
|
null, // children
|
||||||
false /* mandatory */);
|
false /* mandatory */);
|
||||||
|
|
||||||
return desc;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ class DropFeedback {
|
|||||||
RelativeInfo info = null;
|
RelativeInfo info = null;
|
||||||
UiElementEditPart sibling = null;
|
UiElementEditPart sibling = null;
|
||||||
|
|
||||||
|
// TODO consider merge like a vertical layout
|
||||||
|
// TODO consider TableLayout like a linear
|
||||||
if (LayoutConstants.LINEAR_LAYOUT.equals(layoutXmlName)) {
|
if (LayoutConstants.LINEAR_LAYOUT.equals(layoutXmlName)) {
|
||||||
sibling = findLinearTarget(parentPart, where)[1];
|
sibling = findLinearTarget(parentPart, where)[1];
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class UiViewElementNode extends UiElementNode {
|
|||||||
if (layoutDescriptors != null) {
|
if (layoutDescriptors != null) {
|
||||||
for (ElementDescriptor desc : layoutDescriptors) {
|
for (ElementDescriptor desc : layoutDescriptors) {
|
||||||
if (desc instanceof ViewElementDescriptor &&
|
if (desc instanceof ViewElementDescriptor &&
|
||||||
desc.getXmlName().equals(AndroidConstants.CLASS_FRAMELAYOUT)) {
|
desc.getXmlName().equals(AndroidConstants.CLASS_NAME_FRAMELAYOUT)) {
|
||||||
layout_attrs = ((ViewElementDescriptor) desc).getLayoutAttributes();
|
layout_attrs = ((ViewElementDescriptor) desc).getLayoutAttributes();
|
||||||
need_xmlns = true;
|
need_xmlns = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user