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

Commit fdac5ea9 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Refine the behavior of split action bars."

parents 6b6091a1 1ab418a2
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -368,7 +368,7 @@ public class ActionBarImpl extends ActionBar {
            mode.invalidate();
            mode.invalidate();
            mContextView.initForMode(mode);
            mContextView.initForMode(mode);
            animateToMode(true);
            animateToMode(true);
            if (mSplitView != null) {
            if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
                // TODO animate this
                // TODO animate this
                mSplitView.setVisibility(View.VISIBLE);
                mSplitView.setVisibility(View.VISIBLE);
            }
            }
@@ -526,7 +526,7 @@ public class ActionBarImpl extends ActionBar {
                mContainerView.setTranslationY(-mContainerView.getHeight());
                mContainerView.setTranslationY(-mContainerView.getHeight());
                b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
                b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
            }
            }
            if (mSplitView != null) {
            if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) {
                mSplitView.setAlpha(0);
                mSplitView.setAlpha(0);
                b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1));
                b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1));
            }
            }
@@ -560,7 +560,7 @@ public class ActionBarImpl extends ActionBar {
                b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
                b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
                        -mContainerView.getHeight()));
                        -mContainerView.getHeight()));
            }
            }
            if (mSplitView != null) {
            if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
                mSplitView.setAlpha(1);
                mSplitView.setAlpha(1);
                b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0));
                b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0));
            }
            }
+24 −10
Original line number Original line Diff line number Diff line
@@ -39,10 +39,13 @@ public class ActionMenuPresenter extends BaseMenuPresenter {


    private View mOverflowButton;
    private View mOverflowButton;
    private boolean mReserveOverflow;
    private boolean mReserveOverflow;
    private boolean mReserveOverflowSet;
    private int mWidthLimit;
    private int mWidthLimit;
    private int mActionItemWidthLimit;
    private int mActionItemWidthLimit;
    private int mMaxItems;
    private int mMaxItems;
    private boolean mMaxItemsSet;
    private boolean mStrictWidthLimit;
    private boolean mStrictWidthLimit;
    private boolean mWidthLimitSet;


    // Group IDs that have been added as actions - used temporarily, allocated here for reuse.
    // Group IDs that have been added as actions - used temporarily, allocated here for reuse.
    private final SparseBooleanArray mActionButtonGroups = new SparseBooleanArray();
    private final SparseBooleanArray mActionButtonGroups = new SparseBooleanArray();
@@ -64,14 +67,21 @@ public class ActionMenuPresenter extends BaseMenuPresenter {
        super.initForMenu(context, menu);
        super.initForMenu(context, menu);


        final Resources res = context.getResources();
        final Resources res = context.getResources();
        final int screen = res.getConfiguration().screenLayout;

        if (!mReserveOverflowSet) {
            // TODO Use the no-buttons specifier instead here
            // TODO Use the no-buttons specifier instead here
        mReserveOverflow = (screen & Configuration.SCREENLAYOUT_SIZE_MASK) ==
            mReserveOverflow = res.getConfiguration()
                Configuration.SCREENLAYOUT_SIZE_XLARGE;
                    .isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
        }

        if (!mWidthLimitSet) {
            mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
            mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
        }


        // Measure for initial configuration
        // Measure for initial configuration
        if (!mMaxItemsSet) {
            mMaxItems = res.getInteger(com.android.internal.R.integer.max_action_buttons);
            mMaxItems = res.getInteger(com.android.internal.R.integer.max_action_buttons);
        }


        int width = mWidthLimit;
        int width = mWidthLimit;
        if (mReserveOverflow) {
        if (mReserveOverflow) {
@@ -92,15 +102,19 @@ public class ActionMenuPresenter extends BaseMenuPresenter {
    }
    }


    public void setWidthLimit(int width, boolean strict) {
    public void setWidthLimit(int width, boolean strict) {
        if (mReserveOverflow) {
        mWidthLimit = width;
            width -= mOverflowButton.getMeasuredWidth();
        }
        mActionItemWidthLimit = width;
        mStrictWidthLimit = strict;
        mStrictWidthLimit = strict;
        mWidthLimitSet = true;
    }

    public void setReserveOverflow(boolean reserveOverflow) {
        mReserveOverflow = reserveOverflow;
        mReserveOverflowSet = true;
    }
    }


    public void setItemLimit(int itemCount) {
    public void setItemLimit(int itemCount) {
        mMaxItems = itemCount;
        mMaxItems = itemCount;
        mMaxItemsSet = true;
    }
    }


    @Override
    @Override
+8 −5
Original line number Original line Diff line number Diff line
@@ -168,14 +168,14 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi


        final MenuBuilder menu = (MenuBuilder) mode.getMenu();
        final MenuBuilder menu = (MenuBuilder) mode.getMenu();
        mActionMenuPresenter = new ActionMenuPresenter();
        mActionMenuPresenter = new ActionMenuPresenter();
        menu.addMenuPresenter(mActionMenuPresenter);
        mActionMenuPresenter.setReserveOverflow(true);
        mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);


        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.MATCH_PARENT);
                LayoutParams.MATCH_PARENT);
        mMenuView.setLayoutParams(layoutParams);
        if (mSplitView == null) {
        if (mSplitView == null) {
            addView(mMenuView);
            menu.addMenuPresenter(mActionMenuPresenter);
            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
            addView(mMenuView, layoutParams);
        } else {
        } else {
            // Allow full screen width in split mode.
            // Allow full screen width in split mode.
            mActionMenuPresenter.setWidthLimit(
            mActionMenuPresenter.setWidthLimit(
@@ -184,7 +184,10 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
            // Span the whole width
            // Span the whole width
            layoutParams.width = LayoutParams.MATCH_PARENT;
            layoutParams.width = LayoutParams.MATCH_PARENT;
            mSplitView.addView(mMenuView);
            layoutParams.height = mContentHeight;
            menu.addMenuPresenter(mActionMenuPresenter);
            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
            mSplitView.addView(mMenuView, layoutParams);
        }
        }


        mAnimateInOnLayout = true;
        mAnimateInOnLayout = true;
+13 −7
Original line number Original line Diff line number Diff line
@@ -327,15 +327,15 @@ public class ActionBarView extends AbsActionBarView {
            mActionMenuPresenter.setCallback(cb);
            mActionMenuPresenter.setCallback(cb);
            mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
            mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
        }
        }
        builder.addMenuPresenter(mActionMenuPresenter);
        builder.addMenuPresenter(mExpandedMenuPresenter);


        final ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        ActionMenuView menuView;
        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.MATCH_PARENT);
                LayoutParams.MATCH_PARENT);
        menuView.setLayoutParams(layoutParams);
        if (!mSplitActionBar) {
        if (!mSplitActionBar) {
            addView(menuView);
            builder.addMenuPresenter(mActionMenuPresenter);
            builder.addMenuPresenter(mExpandedMenuPresenter);
            menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
            addView(menuView, layoutParams);
        } else {
        } else {
            // Allow full screen width in split mode.
            // Allow full screen width in split mode.
            mActionMenuPresenter.setWidthLimit(
            mActionMenuPresenter.setWidthLimit(
@@ -344,9 +344,15 @@ public class ActionBarView extends AbsActionBarView {
            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
            // Span the whole width
            // Span the whole width
            layoutParams.width = LayoutParams.MATCH_PARENT;
            layoutParams.width = LayoutParams.MATCH_PARENT;
            builder.addMenuPresenter(mActionMenuPresenter);
            builder.addMenuPresenter(mExpandedMenuPresenter);
            menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
            if (mSplitView != null) {
            if (mSplitView != null) {
                mSplitView.addView(menuView);
                mSplitView.addView(menuView, layoutParams);
            } // We'll add this later if we missed it this time.
            } else {
                // We'll add this later if we missed it this time.
                menuView.setLayoutParams(layoutParams);
            }
        }
        }
        mMenuView = menuView;
        mMenuView = menuView;
    }
    }