Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(938)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java

Issue 944173002: Expose a method to invalidate menu item content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added null check for ListView Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuHandler.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
index c8976b36c98ee8d46bf5b6946e592d9b0ceefa2c..9b879403b31840af88dcfb636a33c22c222f17ed 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java
@@ -23,6 +23,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListPopupWindow;
+import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
@@ -79,6 +80,44 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
}
/**
+ * 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.
*
* @param context The context of the AppMenu (ensure the proper theme is set on this context).
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuHandler.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698