Commit b82a480d authored by dtrainor's avatar dtrainor Committed by Commit bot

Expose a method to invalidate menu item content

- Expose a way to cause the ListAdapter to refresh the MenuItem content of it's MenuItem list.

BUG=459409

Review URL: https://codereview.chromium.org/944173002

Cr-Commit-Position: refs/heads/master@{#318122}
parent 9883ef1b
...@@ -23,6 +23,7 @@ import android.widget.AdapterView; ...@@ -23,6 +23,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ListPopupWindow; import android.widget.ListPopupWindow;
import android.widget.ListView;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener; import android.widget.PopupWindow.OnDismissListener;
...@@ -78,6 +79,44 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -78,6 +79,44 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_fade_distance); mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_fade_distance);
} }
/**
* Notifies the menu that the contents of the menu item specified by {@code menuRowId} have
* changed. This should be called if icons, titles, etc. are changing for a particular menu
* item while the menu is open.
* @param menuRowId The id of the menu item to change. This must be a row id and not a child
* id.
*/
public void menuItemContentChanged(int menuRowId) {
// Make sure we have all the valid state objects we need.
if (mAdapter == null || mMenu == null || mPopup == null || mPopup.getListView() == null) {
return;
}
// Calculate the item index.
int index = -1;
int menuSize = mMenu.size();
for (int i = 0; i < menuSize; i++) {
if (mMenu.getItem(i).getItemId() == menuRowId) {
index = i;
break;
}
}
if (index == -1) return;
// Check if the item is visible.
ListView list = mPopup.getListView();
int startIndex = list.getFirstVisiblePosition();
int endIndex = list.getLastVisiblePosition();
if (index < startIndex || index > endIndex) return;
// Grab the correct View.
View view = list.getChildAt(index - startIndex);
if (view == null) return;
// Cause the Adapter to re-populate the View.
list.getAdapter().getView(index, view, list);
}
/** /**
* Creates and shows the app menu anchored to the specified view. * Creates and shows the app menu anchored to the specified view.
* *
......
...@@ -50,6 +50,17 @@ public class AppMenuHandler { ...@@ -50,6 +50,17 @@ public class AppMenuHandler {
mMenuResourceId = menuResourceId; mMenuResourceId = menuResourceId;
} }
/**
* Notifies the menu that the contents of the menu item specified by {@code menuRowId} have
* changed. This should be called if icons, titles, etc. are changing for a particular menu
* item while the menu is open.
* @param menuRowId The id of the menu item to change. This must be a row id and not a child
* id.
*/
public void menuItemContentChanged(int menuRowId) {
if (mAppMenu != null) mAppMenu.menuItemContentChanged(menuRowId);
}
/** /**
* Show the app menu. * Show the app menu.
* @param anchorView Anchor view (usually a menu button) to be used for the popup. * @param anchorView Anchor view (usually a menu button) to be used for the popup.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment