Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b2fb60c authored by Mindy Pereira's avatar Mindy Pereira
Browse files

Preference changes to layouts.

Change-Id: I37366c3465aa1d8d2bd30fb6ae4b821f5f2d5e2d
Additional changes to make the left and right padding
behave the same way as the top and bottom padding.
That is, our default pref screens will automatically
apply the padding and clipToPadding tags. Custom preference
screens will appear as before.
Uses LayoutParams now instead of a specific id.
parent 0b44476a
Loading
Loading
Loading
Loading
+86 −27
Original line number Diff line number Diff line
@@ -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
+0 −2
Original line number Diff line number Diff line
@@ -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>
+4 −2
Original line number Diff line number Diff line
@@ -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"
+10 −2
Original line number Diff line number Diff line
@@ -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. -->
+8 −4
Original line number Diff line number Diff line
@@ -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>