diff options
| author | Philip Milne <pmilne@google.com> | 2012-04-04 23:41:34 -0700 |
|---|---|---|
| committer | Philip Milne <pmilne@google.com> | 2012-04-13 16:25:08 -0700 |
| commit | 1557fd7809078e421f751efc7d2539b3efdc54b2 (patch) | |
| tree | 90f58eac3acab19fa61719219814acc7d6683dcd /core/java/android/view/ViewGroup.java | |
| parent | c58a6d2da4790921743bdb4997ee59f8be1632e3 (diff) | |
| download | frameworks_base-1557fd7809078e421f751efc7d2539b3efdc54b2.zip frameworks_base-1557fd7809078e421f751efc7d2539b3efdc54b2.tar.gz frameworks_base-1557fd7809078e421f751efc7d2539b3efdc54b2.tar.bz2 | |
Fix for bug 6110465.
Add layout bound metadata to 9-patch files and make layouts take them into account.
This CL contains a proposed API for dealing with layout bounds.
This solution exposes:
1. Class: Insets - for storing layout Insets (and later possibly padding).
2. Methods: View:(get/set)LayoutInsets() - for storing layoutBounds.
3. Methods: ViewGroup:(get/set)LayoutMode() - for controlling layoutMode.
It also iuncudes the changes to GridLayout to support layout bounds.
Change-Id: I60c836b6530b61c5abf37f93ee9c44aad73573f1
Diffstat (limited to 'core/java/android/view/ViewGroup.java')
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 121b544..e5c5e45 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -169,6 +169,12 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager */ protected int mGroupFlags; + /* + * THe layout mode: either {@link #UNDEFINED_LAYOUT_MODE}, {@link #COMPONENT_BOUNDS} or + * {@link #LAYOUT_BOUNDS} + */ + private int mLayoutMode = UNDEFINED_LAYOUT_MODE; + /** * NOTE: If you change the flags below make sure to reflect the changes * the DisplayList class @@ -334,6 +340,24 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager */ public static final int PERSISTENT_ALL_CACHES = 0x3; + // Layout Modes + + private static final int UNDEFINED_LAYOUT_MODE = -1; + + /** + * This constant is a {@link #setLayoutMode(int) layoutMode}. + * Component bounds are the raw values of {@link #getLeft() left}, {@link #getTop() top}, + * {@link #getRight() right} and {@link #getBottom() bottom}. + */ + public static final int COMPONENT_BOUNDS = 0; + + /** + * This constant is a {@link #setLayoutMode(int) layoutMode}. + * Layout bounds are derived by offsetting the component bounds using + * {@link View#getLayoutInsets()}. + */ + public static final int LAYOUT_BOUNDS = 1; + /** * We clip to padding when FLAG_CLIP_TO_PADDING and FLAG_PADDING_NOT_NULL * are set at the same time. @@ -4368,6 +4392,52 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } /** + * Returns the basis of alignment during the layout of this view group: + * either {@link #COMPONENT_BOUNDS} or {@link #LAYOUT_BOUNDS}. + * + * @return whether or not this view group should use the component or layout bounds during + * layout operations + * + * @see #setLayoutMode(int) + */ + public int getLayoutMode() { + if (mLayoutMode == UNDEFINED_LAYOUT_MODE) { + ViewParent parent = getParent(); + if (parent instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup) parent; + return viewGroup.getLayoutMode(); + } else { + int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; + boolean preJellyBean = targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN; + return preJellyBean ? COMPONENT_BOUNDS : LAYOUT_BOUNDS; + } + + } + return mLayoutMode; + } + + /** + * Sets the basis of alignment during alignment of this view group. + * Valid values are either {@link #COMPONENT_BOUNDS} or {@link #LAYOUT_BOUNDS}. + * <p> + * The default is to query the property of the parent if this view group has a parent. + * If this ViewGroup is the root of the view hierarchy the default + * value is {@link #LAYOUT_BOUNDS} for target SDK's greater than JellyBean, + * {@link #LAYOUT_BOUNDS} otherwise. + * + * @return whether or not this view group should use the component or layout bounds during + * layout operations + * + * @see #getLayoutMode() + */ + public void setLayoutMode(int layoutMode) { + if (mLayoutMode != layoutMode) { + mLayoutMode = layoutMode; + requestLayout(); + } + } + + /** * Returns a new set of layout parameters based on the supplied attributes set. * * @param attrs the attributes to build the layout parameters from |
