diff options
author | Adam Powell <adamp@google.com> | 2011-07-27 11:55:29 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2011-07-27 15:37:58 -0700 |
commit | 89b09da7b3b1e69264d9ec710c66eb2f891b313e (patch) | |
tree | b5a0e4a7453fdb71720cb15148ec84bd007100d2 /core/java | |
parent | 804b3d76c39eca09cbbd8b7c3fa1718e7ad094cc (diff) | |
download | frameworks_base-89b09da7b3b1e69264d9ec710c66eb2f891b313e.zip frameworks_base-89b09da7b3b1e69264d9ec710c66eb2f891b313e.tar.gz frameworks_base-89b09da7b3b1e69264d9ec710c66eb2f891b313e.tar.bz2 |
Bug 5076788 - Optimize the building and invalidation of menus
Fix cases that weren't batching menu presenter changes correctly.
Have FragmentManager invalidate the options menu less often.
Change-Id: Ia66fcd09ada8b0a084ad6b08d4340a8fa0c8fc5d
Diffstat (limited to 'core/java')
4 files changed, 16 insertions, 13 deletions
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java index cb97c46..7006192 100644 --- a/core/java/android/app/Fragment.java +++ b/core/java/android/app/Fragment.java @@ -880,7 +880,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener public void setHasOptionsMenu(boolean hasMenu) { if (mHasMenu != hasMenu) { mHasMenu = hasMenu; - if (isAdded() && !isHidden()) { + if (isAdded() && !isHidden() && isResumed()) { mActivity.invalidateOptionsMenu(); } } diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 789d3a6..24550c5 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -978,7 +978,7 @@ final class FragmentManagerImpl extends FragmentManager { } } - if (mNeedMenuInvalidate && mActivity != null) { + if (mNeedMenuInvalidate && mActivity != null && mCurState == Fragment.RESUMED) { mActivity.invalidateOptionsMenu(); mNeedMenuInvalidate = false; } diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java index bf2965b..bff621c 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuView.java @@ -36,8 +36,8 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo private boolean mReserveOverflow; private ActionMenuPresenter mPresenter; - private boolean mUpdateContentsBeforeMeasure; private boolean mFormatItems; + private int mFormatItemsWidth; private int mMinCellSize; private int mMeasuredExtraWidth; @@ -71,19 +71,21 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo } @Override - public void requestLayout() { - // Layout can influence how many action items fit. - mUpdateContentsBeforeMeasure = true; - super.requestLayout(); - } - - @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // If we've been given an exact size to match, apply special formatting during layout. + final boolean wasFormatted = mFormatItems; mFormatItems = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; - if (mUpdateContentsBeforeMeasure && mMenu != null) { + + if (wasFormatted != mFormatItems) { + mFormatItemsWidth = 0; // Reset this when switching modes + } + + // Special formatting can change whether items can fit as action buttons. + // Kick the menu and update presenters when this changes. + final int widthSize = MeasureSpec.getMode(widthMeasureSpec); + if (mFormatItems && mMenu != null && widthSize != mFormatItemsWidth) { + mFormatItemsWidth = widthSize; mMenu.onItemsChanged(true); - mUpdateContentsBeforeMeasure = false; } if (mFormatItems) { diff --git a/core/java/com/android/internal/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java index 159b3da..19cbe25 100644 --- a/core/java/com/android/internal/view/menu/MenuBuilder.java +++ b/core/java/com/android/internal/view/menu/MenuBuilder.java @@ -27,6 +27,7 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; +import android.util.Log; import android.util.SparseArray; import android.view.ActionProvider; import android.view.ContextMenu.ContextMenuInfo; @@ -47,7 +48,7 @@ import java.util.concurrent.CopyOnWriteArrayList; * standard menu UI. */ public class MenuBuilder implements Menu { - private static final String LOGTAG = "MenuBuilder"; + private static final String TAG = "MenuBuilder"; private static final String PRESENTER_KEY = "android:menu:presenters"; private static final String ACTION_VIEW_STATES_KEY = "android:menu:actionviewstates"; |