diff options
| -rw-r--r-- | core/java/android/preference/PreferenceFrameLayout.java | 113 | ||||
| -rw-r--r-- | core/res/res/layout/preference_list_content.xml | 2 | ||||
| -rw-r--r-- | core/res/res/layout/preference_list_fragment.xml | 6 | ||||
| -rwxr-xr-x | core/res/res/values/attrs.xml | 12 | ||||
| -rw-r--r-- | core/res/res/values/styles.xml | 12 |
5 files changed, 108 insertions, 37 deletions
diff --git a/core/java/android/preference/PreferenceFrameLayout.java b/core/java/android/preference/PreferenceFrameLayout.java index 481859e17c6f..f6d01d3364fd 100644 --- a/core/java/android/preference/PreferenceFrameLayout.java +++ b/core/java/android/preference/PreferenceFrameLayout.java @@ -20,16 +20,22 @@ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.View; +import android.view.ViewGroup.MarginLayoutParams; import android.widget.FrameLayout; +import android.widget.FrameLayout.LayoutParams; /** * @hide */ public class PreferenceFrameLayout extends FrameLayout { - private static final int DEFAULT_TOP_PADDING = 0; - private static final int DEFAULT_BOTTOM_PADDING = 0; - private final int mTopPadding; - private final int mBottomPadding; + private static final int DEFAULT_BORDER_TOP = 0; + private static final int DEFAULT_BORDER_BOTTOM = 0; + private static final int DEFAULT_BORDER_LEFT = 0; + private static final int DEFAULT_BORDER_RIGHT = 0; + private final int mBorderTop; + private final int mBorderBottom; + private final int mBorderLeft; + private final int mBorderRight; private boolean mPaddingApplied = false; public PreferenceFrameLayout(Context context) { @@ -46,45 +52,98 @@ public class PreferenceFrameLayout extends FrameLayout { com.android.internal.R.styleable.PreferenceFrameLayout, defStyle, 0); float density = context.getResources().getDisplayMetrics().density; - int defaultTopPadding = (int) (density * DEFAULT_TOP_PADDING + 0.5f); - int defaultBottomPadding = (int) (density * DEFAULT_BOTTOM_PADDING + 0.5f); - - mTopPadding = a.getDimensionPixelSize( - com.android.internal.R.styleable.PreferenceFrameLayout_topPadding, - defaultTopPadding); - mBottomPadding = a.getDimensionPixelSize( - com.android.internal.R.styleable.PreferenceFrameLayout_bottomPadding, - defaultBottomPadding); + int defaultBorderTop = (int) (density * DEFAULT_BORDER_TOP + 0.5f); + int defaultBottomPadding = (int) (density * DEFAULT_BORDER_BOTTOM + 0.5f); + int defaultLeftPadding = (int) (density * DEFAULT_BORDER_LEFT + 0.5f); + int defaultRightPadding = (int) (density * DEFAULT_BORDER_RIGHT + 0.5f); + mBorderTop = a.getDimensionPixelSize( + com.android.internal.R.styleable.PreferenceFrameLayout_borderTop, + defaultBorderTop); + mBorderBottom = a.getDimensionPixelSize( + com.android.internal.R.styleable.PreferenceFrameLayout_borderBottom, + defaultBottomPadding); + mBorderLeft = a.getDimensionPixelSize( + com.android.internal.R.styleable.PreferenceFrameLayout_borderLeft, + defaultLeftPadding); + mBorderRight = a.getDimensionPixelSize( + com.android.internal.R.styleable.PreferenceFrameLayout_borderRight, + defaultRightPadding); a.recycle(); } + /** + * {@inheritDoc} + */ + @Override + public LayoutParams generateLayoutParams(AttributeSet attrs) { + return new LayoutParams(getContext(), attrs); + } + @Override public void addView(View child) { - int topPadding = getPaddingTop(); - int bottomPadding = getPaddingBottom(); + int borderTop = getPaddingTop(); + int borderBottom = getPaddingBottom(); + int borderLeft = getPaddingLeft(); + int borderRight = getPaddingRight(); + + LayoutParams layoutParams = (PreferenceFrameLayout.LayoutParams) child.getLayoutParams(); // Check on the id of the child before adding it. - if (child != null && child.getId() != com.android.internal.R.id.default_preference_layout) { - // Add the padding to the view group after determining if the padding already exists. - if (!mPaddingApplied) { - topPadding += mTopPadding; - bottomPadding += mBottomPadding; - mPaddingApplied = true; - } - } else { + if (layoutParams != null && layoutParams.removeBorders) { if (mPaddingApplied) { - topPadding -= mTopPadding; - bottomPadding -= mBottomPadding; + borderTop -= mBorderTop; + borderBottom -= mBorderBottom; + borderLeft -= mBorderLeft; + borderRight -= mBorderRight; mPaddingApplied = false; } + } else { + // Add the padding to the view group after determining if the + // padding already exists. + if (!mPaddingApplied) { + borderTop += mBorderTop; + borderBottom += mBorderBottom; + borderLeft += mBorderLeft; + borderRight += mBorderRight; + mPaddingApplied = true; + } } + int previousTop = getPaddingTop(); int previousBottom = getPaddingBottom(); - if (previousTop != topPadding || previousBottom != bottomPadding) { - setPadding(getPaddingLeft(), topPadding, getPaddingRight(), bottomPadding); + int previousLeft = getPaddingLeft(); + int previousRight = getPaddingRight(); + if (previousTop != borderTop || previousBottom != borderBottom + || previousLeft != borderLeft || previousRight != borderRight) { + setPadding(borderLeft, borderTop, borderRight, borderBottom); } + super.addView(child); } + + public static class LayoutParams extends FrameLayout.LayoutParams { + public boolean removeBorders = false; + /** + * {@inheritDoc} + */ + public LayoutParams(Context c, AttributeSet attrs) { + super(c, attrs); + + TypedArray a = c.obtainStyledAttributes(attrs, + com.android.internal.R.styleable.PreferenceFrameLayout_Layout); + removeBorders = a.getBoolean( + com.android.internal.R.styleable.PreferenceFrameLayout_Layout_layout_removeBorders, + false); + a.recycle(); + } + + /** + * {@inheritDoc} + */ + public LayoutParams(int width, int height) { + super(width, height); + } + } }
\ No newline at end of file diff --git a/core/res/res/layout/preference_list_content.xml b/core/res/res/layout/preference_list_content.xml index 0f844180c2be..fd488bdf8838 100644 --- a/core/res/res/layout/preference_list_content.xml +++ b/core/res/res/layout/preference_list_content.xml @@ -64,8 +64,6 @@ android:layout_marginRight="@dimen/preference_screen_side_margin" android:layout_marginTop="16dp" android:layout_marginBottom="16dp" - android:paddingLeft="32dip" - android:paddingRight="32dip" android:background="?attr/preferencePanelBackground" android:visibility="gone" /> </LinearLayout> diff --git a/core/res/res/layout/preference_list_fragment.xml b/core/res/res/layout/preference_list_fragment.xml index dbe0df0c49e3..69fb73affaa1 100644 --- a/core/res/res/layout/preference_list_fragment.xml +++ b/core/res/res/layout/preference_list_fragment.xml @@ -18,11 +18,11 @@ --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/default_preference_layout" android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" - android:background="@android:color/transparent"> + android:background="@android:color/transparent" + android:layout_removeBorders="true"> <ListView android:id="@android:id/list" android:layout_width="match_parent" @@ -30,6 +30,8 @@ android:layout_weight="1" android:paddingTop="48dip" android:paddingBottom="48dip" + android:paddingLeft="32dip" + android:paddingRight="32dip" android:clipToPadding="false" android:drawSelectorOnTop="false" android:cacheColorHint="@android:color/transparent" diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 5daa94488e12..cc6dc2a85655 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2201,9 +2201,17 @@ </declare-styleable> <declare-styleable name="PreferenceFrameLayout"> <!-- Padding to use at the top of the prefs content. --> - <attr name="topPadding" format="dimension" /> + <attr name="borderTop" format="dimension" /> <!-- Padding to use at the bottom of the prefs content. --> - <attr name="bottomPadding" format="dimension" /> + <attr name="borderBottom" format="dimension" /> + <!-- Padding to use at the left of the prefs content. --> + <attr name="borderLeft" format="dimension" /> + <!-- Padding to use at the right of the prefs content. --> + <attr name="borderRight" format="dimension" /> + </declare-styleable> + <declare-styleable name="PreferenceFrameLayout_Layout"> + <!-- Padding to use at the top of the prefs content. --> + <attr name="layout_removeBorders" format="boolean" /> </declare-styleable> <declare-styleable name="MenuView"> <!-- Default appearance of menu item text. --> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index b3c3e0dcb37c..f5f392d21a73 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -50,8 +50,10 @@ </style> <style name="Widget.PreferenceFrameLayout"> - <item name="android:topPadding">0dip</item> - <item name="android:bottomPadding">0dip</item> + <item name="android:borderTop">0dip</item> + <item name="android:borderBottom">0dip</item> + <item name="android:borderLeft">0dip</item> + <item name="android:borderRight">0dip</item> </style> <!-- Base style for animations. This style specifies no animations. --> @@ -1962,7 +1964,9 @@ </style> <style name="Widget.Holo.PreferenceFrameLayout"> - <item name="android:topPadding">48dip</item> - <item name="android:bottomPadding">48dip</item> + <item name="android:borderTop">48dip</item> + <item name="android:borderBottom">48dip</item> + <item name="android:borderLeft">32dip</item> + <item name="android:borderRight">32dip</item> </style> </resources> |