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

Commit 04c710ad authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Fix bug #8200928 ExpandableListView should be RTL-aware" into jb-mr2-dev

parents d8b50ab6 f4efad05
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -28616,8 +28616,10 @@ package android.widget {
    method public void setChildDivider(android.graphics.drawable.Drawable);
    method public void setChildDivider(android.graphics.drawable.Drawable);
    method public void setChildIndicator(android.graphics.drawable.Drawable);
    method public void setChildIndicator(android.graphics.drawable.Drawable);
    method public void setChildIndicatorBounds(int, int);
    method public void setChildIndicatorBounds(int, int);
    method public void setChildIndicatorBoundsRelative(int, int);
    method public void setGroupIndicator(android.graphics.drawable.Drawable);
    method public void setGroupIndicator(android.graphics.drawable.Drawable);
    method public void setIndicatorBounds(int, int);
    method public void setIndicatorBounds(int, int);
    method public void setIndicatorBoundsRelative(int, int);
    method public void setOnChildClickListener(android.widget.ExpandableListView.OnChildClickListener);
    method public void setOnChildClickListener(android.widget.ExpandableListView.OnChildClickListener);
    method public void setOnGroupClickListener(android.widget.ExpandableListView.OnGroupClickListener);
    method public void setOnGroupClickListener(android.widget.ExpandableListView.OnGroupClickListener);
    method public void setOnGroupCollapseListener(android.widget.ExpandableListView.OnGroupCollapseListener);
    method public void setOnGroupCollapseListener(android.widget.ExpandableListView.OnGroupCollapseListener);
+173 −20
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@ import android.widget.ExpandableListConnector.PositionMetadata;


import java.util.ArrayList;
import java.util.ArrayList;


import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;

/**
/**
 * A view that shows items in a vertically scrolling two-level list. This
 * A view that shows items in a vertically scrolling two-level list. This
 * differs from the {@link ListView} by allowing two levels: groups which can
 * differs from the {@link ListView} by allowing two levels: groups which can
@@ -76,6 +78,10 @@ import java.util.ArrayList;
 * @attr ref android.R.styleable#ExpandableListView_childIndicatorLeft
 * @attr ref android.R.styleable#ExpandableListView_childIndicatorLeft
 * @attr ref android.R.styleable#ExpandableListView_childIndicatorRight
 * @attr ref android.R.styleable#ExpandableListView_childIndicatorRight
 * @attr ref android.R.styleable#ExpandableListView_childDivider
 * @attr ref android.R.styleable#ExpandableListView_childDivider
 * @attr ref android.R.styleable#ExpandableListView_indicatorStart
 * @attr ref android.R.styleable#ExpandableListView_indicatorEnd
 * @attr ref android.R.styleable#ExpandableListView_childIndicatorStart
 * @attr ref android.R.styleable#ExpandableListView_childIndicatorEnd
 */
 */
public class ExpandableListView extends ListView {
public class ExpandableListView extends ListView {


@@ -134,6 +140,12 @@ public class ExpandableListView extends ListView {
    /** Right bound for drawing the indicator. */
    /** Right bound for drawing the indicator. */
    private int mIndicatorRight;
    private int mIndicatorRight;


    /** Start bound for drawing the indicator. */
    private int mIndicatorStart;

    /** End bound for drawing the indicator. */
    private int mIndicatorEnd;

    /**
    /**
     * Left bound for drawing the indicator of a child. Value of
     * Left bound for drawing the indicator of a child. Value of
     * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorLeft.
     * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorLeft.
@@ -146,12 +158,29 @@ public class ExpandableListView extends ListView {
     */
     */
    private int mChildIndicatorRight;
    private int mChildIndicatorRight;


    /**
     * Start bound for drawing the indicator of a child. Value of
     * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorStart.
     */
    private int mChildIndicatorStart;

    /**
     * End bound for drawing the indicator of a child. Value of
     * {@link #CHILD_INDICATOR_INHERIT} means use mIndicatorEnd.
     */
    private int mChildIndicatorEnd;

    /**
    /**
     * Denotes when a child indicator should inherit this bound from the generic
     * Denotes when a child indicator should inherit this bound from the generic
     * indicator bounds
     * indicator bounds
     */
     */
    public static final int CHILD_INDICATOR_INHERIT = -1;
    public static final int CHILD_INDICATOR_INHERIT = -1;


    /**
     * Denotes an undefined value for an indicator
     */
    private static final int INDICATOR_UNDEFINED = -2;

    /** The indicator drawn next to a group. */
    /** The indicator drawn next to a group. */
    private Drawable mGroupIndicator;
    private Drawable mGroupIndicator;


@@ -202,29 +231,117 @@ public class ExpandableListView extends ListView {
        super(context, attrs, defStyle);
        super(context, attrs, defStyle);


        TypedArray a =
        TypedArray a =
            context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ExpandableListView, defStyle,
            context.obtainStyledAttributes(attrs,
                    0);
                    com.android.internal.R.styleable.ExpandableListView, defStyle, 0);


        mGroupIndicator = a
        mGroupIndicator = a.getDrawable(
                .getDrawable(com.android.internal.R.styleable.ExpandableListView_groupIndicator);
                com.android.internal.R.styleable.ExpandableListView_groupIndicator);
        mChildIndicator = a
        mChildIndicator = a.getDrawable(
                .getDrawable(com.android.internal.R.styleable.ExpandableListView_childIndicator);
                com.android.internal.R.styleable.ExpandableListView_childIndicator);
        mIndicatorLeft = a
        mIndicatorLeft = a.getDimensionPixelSize(
                .getDimensionPixelSize(com.android.internal.R.styleable.ExpandableListView_indicatorLeft, 0);
                com.android.internal.R.styleable.ExpandableListView_indicatorLeft, 0);
        mIndicatorRight = a
        mIndicatorRight = a.getDimensionPixelSize(
                .getDimensionPixelSize(com.android.internal.R.styleable.ExpandableListView_indicatorRight, 0);
                com.android.internal.R.styleable.ExpandableListView_indicatorRight, 0);
        if (mIndicatorRight == 0 && mGroupIndicator != null) {
        if (mIndicatorRight == 0 && mGroupIndicator != null) {
            mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth();
            mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth();
        }
        }
        mChildIndicatorLeft = a.getDimensionPixelSize(
        mChildIndicatorLeft = a.getDimensionPixelSize(
                com.android.internal.R.styleable.ExpandableListView_childIndicatorLeft, CHILD_INDICATOR_INHERIT);
                com.android.internal.R.styleable.ExpandableListView_childIndicatorLeft,
                CHILD_INDICATOR_INHERIT);
        mChildIndicatorRight = a.getDimensionPixelSize(
        mChildIndicatorRight = a.getDimensionPixelSize(
                com.android.internal.R.styleable.ExpandableListView_childIndicatorRight, CHILD_INDICATOR_INHERIT);
                com.android.internal.R.styleable.ExpandableListView_childIndicatorRight,
        mChildDivider = a.getDrawable(com.android.internal.R.styleable.ExpandableListView_childDivider);
                CHILD_INDICATOR_INHERIT);
        mChildDivider = a.getDrawable(
                com.android.internal.R.styleable.ExpandableListView_childDivider);

        if (!isRtlCompatibilityMode()) {
            mIndicatorStart = a.getDimensionPixelSize(
                    com.android.internal.R.styleable.ExpandableListView_indicatorStart,
                    INDICATOR_UNDEFINED);
            mIndicatorEnd = a.getDimensionPixelSize(
                    com.android.internal.R.styleable.ExpandableListView_indicatorEnd,
                    INDICATOR_UNDEFINED);

            mChildIndicatorStart = a.getDimensionPixelSize(
                    com.android.internal.R.styleable.ExpandableListView_childIndicatorStart,
                    CHILD_INDICATOR_INHERIT);
            mChildIndicatorEnd = a.getDimensionPixelSize(
                    com.android.internal.R.styleable.ExpandableListView_childIndicatorEnd,
                    CHILD_INDICATOR_INHERIT);
        }


        a.recycle();
        a.recycle();
    }
    }


    /**
     * Return true if we are in RTL compatibility mode (either before Jelly Bean MR1 or
     * RTL not supported)
     */
    private boolean isRtlCompatibilityMode() {
        final int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
        return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport();
    }

    /**
     * Return true if the application tag in the AndroidManifest has set "supportRtl" to true
     */
    private boolean hasRtlSupport() {
        return mContext.getApplicationInfo().hasRtlSupport();
    }

    public void onRtlPropertiesChanged(int layoutDirection) {
        resolveIndicator();
        resolveChildIndicator();
    }

    /**
     * Resolve start/end indicator. start/end indicator always takes precedence over left/right
     * indicator when defined.
     */
    private void resolveIndicator() {
        final boolean isLayoutRtl = isLayoutRtl();
        if (isLayoutRtl) {
            if (mIndicatorStart >= 0) {
                mIndicatorRight = mIndicatorStart;
            }
            if (mIndicatorEnd >= 0) {
                mIndicatorLeft = mIndicatorEnd;
            }
        } else {
            if (mIndicatorStart >= 0) {
                mIndicatorLeft = mIndicatorStart;
            }
            if (mIndicatorEnd >= 0) {
                mIndicatorRight = mIndicatorEnd;
            }
        }
        if (mIndicatorRight == 0 && mGroupIndicator != null) {
            mIndicatorRight = mIndicatorLeft + mGroupIndicator.getIntrinsicWidth();
        }
    }

    /**
     * Resolve start/end child indicator. start/end child indicator always takes precedence over
     * left/right child indicator when defined.
     */
    private void resolveChildIndicator() {
        final boolean isLayoutRtl = isLayoutRtl();
        if (isLayoutRtl) {
            if (mChildIndicatorStart >= CHILD_INDICATOR_INHERIT) {
                mChildIndicatorRight = mChildIndicatorStart;
            }
            if (mChildIndicatorEnd >= CHILD_INDICATOR_INHERIT) {
                mChildIndicatorLeft = mChildIndicatorEnd;
            }
        } else {
            if (mChildIndicatorStart >= CHILD_INDICATOR_INHERIT) {
                mChildIndicatorLeft = mChildIndicatorStart;
            }
            if (mChildIndicatorEnd >= CHILD_INDICATOR_INHERIT) {
                mChildIndicatorRight = mChildIndicatorEnd;
            }
        }
    }


    @Override
    @Override
    protected void dispatchDraw(Canvas canvas) {
    protected void dispatchDraw(Canvas canvas) {
@@ -1053,6 +1170,24 @@ public class ExpandableListView extends ListView {
    public void setChildIndicatorBounds(int left, int right) {
    public void setChildIndicatorBounds(int left, int right) {
        mChildIndicatorLeft = left;
        mChildIndicatorLeft = left;
        mChildIndicatorRight = right;
        mChildIndicatorRight = right;
        resolveChildIndicator();
    }

    /**
     * Sets the relative drawing bounds for the child indicator. For either, you can
     * specify {@link #CHILD_INDICATOR_INHERIT} to use inherit from the general
     * indicator's bounds.
     *
     * @see #setIndicatorBounds(int, int)
     * @param start The start position (relative to the start bounds of this View)
     *            to start drawing the indicator.
     * @param end The end position (relative to the end bounds of this
     *            View) to end the drawing of the indicator.
     */
    public void setChildIndicatorBoundsRelative(int start, int end) {
        mChildIndicatorStart = start;
        mChildIndicatorEnd = end;
        resolveChildIndicator();
    }
    }


    /**
    /**
@@ -1084,6 +1219,24 @@ public class ExpandableListView extends ListView {
    public void setIndicatorBounds(int left, int right) {
    public void setIndicatorBounds(int left, int right) {
        mIndicatorLeft = left;
        mIndicatorLeft = left;
        mIndicatorRight = right;
        mIndicatorRight = right;
        resolveIndicator();
    }

    /**
     * Sets the relative drawing bounds for the indicators (at minimum, the group indicator
     * is affected by this; the child indicator is affected by this if the
     * child indicator bounds are set to inherit).
     *
     * @see #setChildIndicatorBounds(int, int)
     * @param start The start position (relative to the start bounds of this View)
     *            to start drawing the indicator.
     * @param end The end position (relative to the end bounds of this
     *            View) to end the drawing of the indicator.
     */
    public void setIndicatorBoundsRelative(int start, int end) {
        mIndicatorStart = start;
        mIndicatorEnd = end;
        resolveIndicator();
    }
    }


    /**
    /**
+10 −0
Original line number Original line Diff line number Diff line
@@ -2709,6 +2709,16 @@
             below and above child items.) The height of this will be the same as
             below and above child items.) The height of this will be the same as
             the height of the normal list item divider. -->
             the height of the normal list item divider. -->
        <attr name="childDivider" format="reference|color" />
        <attr name="childDivider" format="reference|color" />
        <!-- The start bound for an item's indicator. To specify a start bound specific to children,
             use childIndicatorStart. -->
        <attr name="indicatorStart" format="dimension" />
        <!-- The end bound for an item's indicator. To specify a right bound specific to children,
             use childIndicatorEnd. -->
        <attr name="indicatorEnd" format="dimension" />
        <!-- The start bound for a child's indicator. -->
        <attr name="childIndicatorStart" format="dimension" />
        <!-- The end bound for a child's indicator. -->
        <attr name="childIndicatorEnd" format="dimension" />
    </declare-styleable>
    </declare-styleable>
    <declare-styleable name="Gallery">
    <declare-styleable name="Gallery">
        <attr name="gravity" />
        <attr name="gravity" />