From 16385c975cab7e7283039e9226547b8c6d0144e1 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 7 Oct 2009 12:31:17 -0700 Subject: [PATCH] Fix the MergeRootFrameLayout rule by checking the presence of padding. Change-Id: I3a8b257025e74f6899233d9b99f7f86b5675e997 --- .../uix/groovy/LayoutAnalysisCategory.java | 21 +++++++++++++++++++-- .../src/resources/rules/MergeRootFrameLayout.rule | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java b/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java index e2d8c3536..a70086d80 100644 --- a/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java +++ b/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java @@ -35,6 +35,11 @@ import org.w3c.dom.Element; * to {@link com.android.layoutopt.uix.LayoutAnalysis} and {@link org.w3c.dom.Node}. */ public class LayoutAnalysisCategory { + private static final String ANDROID_PADDING = "android:padding"; + private static final String ANDROID_PADDING_LEFT = "android:paddingLeft"; + private static final String ANDROID_PADDING_TOP = "android:paddingTop"; + private static final String ANDROID_PADDING_RIGHT = "android:paddingRight"; + private static final String ANDROID_PADDING_BOTTOM = "android:paddingBottom"; private static final String ANDROID_LAYOUT_WIDTH = "android:layout_width"; private static final String ANDROID_LAYOUT_HEIGHT = "android:layout_height"; private static final String VALUE_FILL_PARENT = "fill_parent"; @@ -98,8 +103,20 @@ public class LayoutAnalysisCategory { node.getUserData(XmlDocumentBuilder.NODE_END_LINE); return data == null ? -1 : (Integer) data; } - - + + /** + * xmlNode.hasPadding() + * + * @return True if the node has one ore more padding attributes. + */ + public static boolean hasPadding(Element element) { + return element.getAttribute(ANDROID_PADDING).length() > 0 || + element.getAttribute(ANDROID_PADDING_LEFT).length() > 0 || + element.getAttribute(ANDROID_PADDING_TOP).length() > 0 || + element.getAttribute(ANDROID_PADDING_BOTTOM).length() > 0 || + element.getAttribute(ANDROID_PADDING_RIGHT).length() > 0; + } + /** * Returns whether this node's width is fill_parent. */ diff --git a/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule b/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule index 2221036ae..d3fc3d9c0 100644 --- a/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule +++ b/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule @@ -8,9 +8,11 @@ // - The node is a FrameLayout // - The node is fill_parent in both orientation *or* it has no layout_gravity // - The node does not have a background nor a foreground +// - The node does not have padding if (node.isRoot() && node.is("FrameLayout") && !node.'@android:background' && !node.'@android:foreground' && ((node.isWidthFillParent() && - node.isHeightFillParent()) || !node.'@android:layout_gravity')) { + node.isHeightFillParent()) || !node.'@android:layout_gravity') && + !node.hasPadding()) { analysis << "The root-level can be replaced with " } -- 2.11.0