development
Révision | b1c2adad16ef074d3b80d5fe7f3ec821ed383343 (tree) |
---|---|
l'heure | 2009-03-28 07:22:09 |
Auteur | Raphael Moll <> |
Commiter | The Android Open Source Project |
AI 143156: am: CL 142851 ADT GLE fix #1731389: widgets dropped in <merge> lack their default layout_widht/height.
Automated import of CL 143156
@@ -157,7 +157,7 @@ public class LayoutParamsParser { | ||
157 | 157 | superClasses[2] = paramsClassName; |
158 | 158 | } |
159 | 159 | HashMap<String, ArrayList<IClassDescriptor>> found = |
160 | - mClassLoader.findClassesDerivingFrom("android.", superClasses); | |
160 | + mClassLoader.findClassesDerivingFrom("android.", superClasses); //$NON-NLS-1$ | |
161 | 161 | mTopViewClass = mClassLoader.getClass(rootClassName); |
162 | 162 | mTopGroupClass = mClassLoader.getClass(groupClassName); |
163 | 163 | if (paramsClassName != null) { |
@@ -179,8 +179,7 @@ public class LayoutParamsParser { | ||
179 | 179 | addView(mTopViewClass); |
180 | 180 | |
181 | 181 | // ViewGroup derives from View |
182 | - mGroupMap.get(groupClassName).setSuperClass( | |
183 | - mViewMap.get(rootClassName)); | |
182 | + mGroupMap.get(groupClassName).setSuperClass(mViewMap.get(rootClassName)); | |
184 | 183 | |
185 | 184 | progress.setWorkRemaining(mGroupList.size() + mViewList.size()); |
186 | 185 |
@@ -346,7 +345,7 @@ public class LayoutParamsParser { | ||
346 | 345 | private IClassDescriptor findLayoutParams(IClassDescriptor groupClass) { |
347 | 346 | IClassDescriptor[] innerClasses = groupClass.getDeclaredClasses(); |
348 | 347 | for (IClassDescriptor innerClass : innerClasses) { |
349 | - if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_LAYOUTPARAMS)) { | |
348 | + if (innerClass.getSimpleName().equals(AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) { | |
350 | 349 | return innerClass; |
351 | 350 | } |
352 | 351 | } |
@@ -189,14 +189,16 @@ public class AndroidConstants { | ||
189 | 189 | public final static String CLASS_CONTEXT = "android.content.Context"; //$NON-NLS-1$ |
190 | 190 | public final static String CLASS_VIEW = "android.view.View"; //$NON-NLS-1$ |
191 | 191 | 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$ | |
193 | 193 | 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$ | |
196 | 198 | 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$ | |
198 | 200 | 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$ | |
200 | 202 | public final static String CLASS_PREFERENCEGROUP = "android.preference.PreferenceGroup"; //$NON-NLS-1$ |
201 | 203 | public final static String CLASS_PARCELABLE = "android.os.Parcelable"; //$NON-NLS-1$ |
202 | 204 |
@@ -121,7 +121,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
121 | 121 | |
122 | 122 | // The <merge> tag can only be a root tag, so it is added at the end. |
123 | 123 | // It gets everything else as children but it is not made a child itself. |
124 | - ElementDescriptor mergeTag = createMerge(); | |
124 | + ElementDescriptor mergeTag = createMerge(newLayouts); | |
125 | 125 | mergeTag.setChildren(newDescriptors); // mergeTag makes a copy of the list |
126 | 126 | newDescriptors.add(mergeTag); |
127 | 127 | newLayouts.add(mergeTag); |
@@ -195,7 +195,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
195 | 195 | if (need_separator) { |
196 | 196 | String title; |
197 | 197 | if (layoutParams.getShortClassName().equals( |
198 | - AndroidConstants.CLASS_LAYOUTPARAMS)) { | |
198 | + AndroidConstants.CLASS_NAME_LAYOUTPARAMS)) { | |
199 | 199 | title = String.format("Layout Attributes from %1$s", |
200 | 200 | layoutParams.getViewLayoutClass().getShortClassName()); |
201 | 201 | } else { |
@@ -229,10 +229,10 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
229 | 229 | /** |
230 | 230 | * Creates a new <include> descriptor and adds it to the list of view descriptors. |
231 | 231 | * |
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. | |
234 | 234 | */ |
235 | - private void insertInclude(ArrayList<ElementDescriptor> newViews) { | |
235 | + private void insertInclude(ArrayList<ElementDescriptor> knownViews) { | |
236 | 236 | String xml_name = "include"; //$NON-NLS-1$ |
237 | 237 | |
238 | 238 | // Create the include custom attributes |
@@ -260,7 +260,8 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
260 | 260 | null); //overrides |
261 | 261 | |
262 | 262 | // Find View and inherit all its layout attributes |
263 | - AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes(newViews); | |
263 | + AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes( | |
264 | + AndroidConstants.CLASS_VIEW, knownViews); | |
264 | 265 | |
265 | 266 | // Create the include descriptor |
266 | 267 | ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name |
@@ -273,33 +274,21 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
273 | 274 | null, // children |
274 | 275 | false /* mandatory */); |
275 | 276 | |
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); | |
295 | 278 | } |
296 | 279 | |
297 | 280 | /** |
298 | 281 | * 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. | |
299 | 284 | */ |
300 | - private ElementDescriptor createMerge() { | |
285 | + private ElementDescriptor createMerge(ArrayList<ElementDescriptor> knownLayouts) { | |
301 | 286 | String xml_name = "merge"; //$NON-NLS-1$ |
302 | 287 | |
288 | + // Find View and inherit all its layout attributes | |
289 | + AttributeDescriptor[] viewLayoutAttribs = findViewLayoutAttributes( | |
290 | + AndroidConstants.CLASS_FRAMELAYOUT, knownLayouts); | |
291 | + | |
303 | 292 | // Create the include descriptor |
304 | 293 | ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name |
305 | 294 | xml_name, // ui_name |
@@ -307,10 +296,29 @@ public final class LayoutDescriptors implements IDescriptorProvider { | ||
307 | 296 | "A root tag useful for XML layouts inflated using a ViewStub.", // tooltip |
308 | 297 | null, // sdk_url |
309 | 298 | null, // attributes |
310 | - null, // layout attributes | |
299 | + viewLayoutAttribs, // layout attributes | |
311 | 300 | null, // children |
312 | 301 | false /* mandatory */); |
313 | 302 | |
314 | 303 | return desc; |
315 | 304 | } |
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 | + } | |
316 | 324 | } |
@@ -96,6 +96,8 @@ class DropFeedback { | ||
96 | 96 | RelativeInfo info = null; |
97 | 97 | UiElementEditPart sibling = null; |
98 | 98 | |
99 | + // TODO consider merge like a vertical layout | |
100 | + // TODO consider TableLayout like a linear | |
99 | 101 | if (LayoutConstants.LINEAR_LAYOUT.equals(layoutXmlName)) { |
100 | 102 | sibling = findLinearTarget(parentPart, where)[1]; |
101 | 103 |
@@ -81,7 +81,7 @@ public class UiViewElementNode extends UiElementNode { | ||
81 | 81 | if (layoutDescriptors != null) { |
82 | 82 | for (ElementDescriptor desc : layoutDescriptors) { |
83 | 83 | if (desc instanceof ViewElementDescriptor && |
84 | - desc.getXmlName().equals(AndroidConstants.CLASS_FRAMELAYOUT)) { | |
84 | + desc.getXmlName().equals(AndroidConstants.CLASS_NAME_FRAMELAYOUT)) { | |
85 | 85 | layout_attrs = ((ViewElementDescriptor) desc).getLayoutAttributes(); |
86 | 86 | need_xmlns = true; |
87 | 87 | break; |