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

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

Merge "Make ActionBar menus handle configuration changes gracefully."

parents 015912e7 773b1b97
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -57,17 +57,33 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
        mItemMargin = mItemPadding / 2;
        a.recycle();

        // Measure for initial configuration
        mMaxItems = measureMaxActionButtons();

        // TODO There has to be a better way to indicate that we don't have a hard menu key.
        final int screen = getResources().getConfiguration().screenLayout;
        mReserveOverflow = (screen & Configuration.SCREENLAYOUT_SIZE_MASK) ==
                Configuration.SCREENLAYOUT_SIZE_XLARGE;
    }

    public void onConfigurationChanged(Configuration newConfig) {
        final int screen = newConfig.screenLayout;
        mReserveOverflow = (screen & Configuration.SCREENLAYOUT_SIZE_MASK) ==
                Configuration.SCREENLAYOUT_SIZE_XLARGE;
        mMaxItems = measureMaxActionButtons();
        if (mMenu != null) {
            mMenu.setMaxActionItems(mMaxItems);
            updateChildren(false);
        }
    }

    private int measureMaxActionButtons() {
        final Resources res = getResources();
        final int size = res.getDimensionPixelSize(com.android.internal.R.dimen.action_icon_size);
        final int spaceAvailable = res.getDisplayMetrics().widthPixels / 2;
        final int itemSpace = size + mItemPadding;
        
        mMaxItems = spaceAvailable / (itemSpace > 0 ? itemSpace : 1);

        // TODO There has to be a better way to indicate that we don't have a hard menu key.
        final int screen = res.getConfiguration().screenLayout;
        mReserveOverflow = (screen & Configuration.SCREENLAYOUT_SIZE_MASK) ==
                Configuration.SCREENLAYOUT_SIZE_XLARGE;
        return spaceAvailable / (itemSpace > 0 ? itemSpace : 1);
    }

    public boolean isOverflowReserved() {