am 9bda7101: Fix the MergeRootFrameLayout rule by checking the presence of padding.
Merge commit '9bda7101b8c7007e65f0a744d93e4e446086f3ec' into eclair-mr2 * commit '9bda7101b8c7007e65f0a744d93e4e446086f3ec': Fix the MergeRootFrameLayout rule by checking the presence of padding.
This commit is contained in:
@@ -35,6 +35,11 @@ import org.w3c.dom.Element;
|
|||||||
* to {@link com.android.layoutopt.uix.LayoutAnalysis} and {@link org.w3c.dom.Node}.
|
* to {@link com.android.layoutopt.uix.LayoutAnalysis} and {@link org.w3c.dom.Node}.
|
||||||
*/
|
*/
|
||||||
public class LayoutAnalysisCategory {
|
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_WIDTH = "android:layout_width";
|
||||||
private static final String ANDROID_LAYOUT_HEIGHT = "android:layout_height";
|
private static final String ANDROID_LAYOUT_HEIGHT = "android:layout_height";
|
||||||
private static final String VALUE_FILL_PARENT = "fill_parent";
|
private static final String VALUE_FILL_PARENT = "fill_parent";
|
||||||
@@ -99,6 +104,18 @@ public class LayoutAnalysisCategory {
|
|||||||
return data == null ? -1 : (Integer) data;
|
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.
|
* Returns whether this node's width is fill_parent.
|
||||||
|
|||||||
@@ -8,9 +8,11 @@
|
|||||||
// - The node is a FrameLayout
|
// - The node is a FrameLayout
|
||||||
// - The node is fill_parent in both orientation *or* it has no layout_gravity
|
// - 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 a background nor a foreground
|
||||||
|
// - The node does not have padding
|
||||||
|
|
||||||
if (node.isRoot() && node.is("FrameLayout") && !node.'@android:background' &&
|
if (node.isRoot() && node.is("FrameLayout") && !node.'@android:background' &&
|
||||||
!node.'@android:foreground' && ((node.isWidthFillParent() &&
|
!node.'@android:foreground' && ((node.isWidthFillParent() &&
|
||||||
node.isHeightFillParent()) || !node.'@android:layout_gravity')) {
|
node.isHeightFillParent()) || !node.'@android:layout_gravity') &&
|
||||||
|
!node.hasPadding()) {
|
||||||
analysis << "The root-level <FrameLayout/> can be replaced with <merge/>"
|
analysis << "The root-level <FrameLayout/> can be replaced with <merge/>"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user