From 71aff836bc7f1c3833b5aee79e12268574e4af7e Mon Sep 17 00:00:00 2001 From: Raphael Moll <> Date: Wed, 25 Mar 2009 21:11:04 -0700 Subject: [PATCH] Automated import from //branches/cupcake/...@142851,142851 --- .../ide/eclipse/adt/sdk/LayoutParamsParser.java | 7 ++- .../ide/eclipse/common/AndroidConstants.java | 12 +++-- .../layout/descriptors/LayoutDescriptors.java | 62 ++++++++++++---------- .../eclipse/editors/layout/parts/DropFeedback.java | 2 + .../editors/layout/uimodel/UiViewElementNode.java | 2 +- 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/LayoutParamsParser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/LayoutParamsParser.java index dc600d7f7..19ef16cfa 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/LayoutParamsParser.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/sdk/LayoutParamsParser.java @@ -157,7 +157,7 @@ public class LayoutParamsParser { superClasses[2] = paramsClassName; } HashMap> 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; } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/AndroidConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/AndroidConstants.java index 1da753c7b..226357f7a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/AndroidConstants.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/AndroidConstants.java @@ -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$ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java index 2c0f984db..a59ad6f19 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/descriptors/LayoutDescriptors.java +++ b/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 { // The 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 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 newViews) { + private void insertInclude(ArrayList 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 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 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 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 knownViews) { + + for (ElementDescriptor desc : knownViews) { + if (desc instanceof ViewElementDescriptor) { + ViewElementDescriptor viewDesc = (ViewElementDescriptor) desc; + if (viewFqcn.equals(viewDesc.getCanonicalClassName())) { + return viewDesc.getLayoutAttributes(); + } + } + } + + return null; + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/parts/DropFeedback.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/parts/DropFeedback.java index 6e79d64d4..b7d69af06 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/parts/DropFeedback.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/parts/DropFeedback.java @@ -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]; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/uimodel/UiViewElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/uimodel/UiViewElementNode.java index 1bf5d5abf..738591a29 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/uimodel/UiViewElementNode.java +++ b/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 { 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; -- 2.11.0