Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto Vandalko-dev
  • Loading branch information
JakeWharton committed Apr 14, 2013
2 parents afda867 + 7d04106 commit a7aafb4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public void dispatchInvalidateOptionsMenu() {
if (BuildConfig.DEBUG) Log.d(TAG, "[dispatchInvalidateOptionsMenu]");

mActivity.getWindow().invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL);

if (mMenu != null) mMenu.invalidate();
}

@Override
Expand Down Expand Up @@ -301,6 +303,7 @@ public void setCustomView(View view) {
@Override
public void invalidate() {
mActionMode.invalidate();
if (mMenu != null) mMenu.invalidate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ public int addIntentOptions(int groupId, int itemId, int order, ComponentName ca

@Override
public void removeItem(int id) {
mNativeMap.remove(mNativeMenu.findItem(id));
mNativeMenu.removeItem(id);
}

@Override
public void removeGroup(int groupId) {
for (int i = 0; i < mNativeMenu.size(); i++) {
final android.view.MenuItem item = mNativeMenu.getItem(i);
if (item.getGroupId() == groupId) { mNativeMap.remove(item); }
}
mNativeMenu.removeGroup(groupId);
}

Expand All @@ -108,6 +113,20 @@ public void clear() {
mNativeMenu.clear();
}

public void invalidate() {
if (mNativeMap.isEmpty()) return;

final WeakHashMap<android.view.MenuItem, MenuItem> menuMapCopy = new WeakHashMap<android.view.MenuItem, MenuItem>(mNativeMap.size());

for (int i = 0; i < mNativeMenu.size(); i++) {
final android.view.MenuItem item = mNativeMenu.getItem(i);
menuMapCopy.put(item, mNativeMap.get(item));
}

mNativeMap.clear();
mNativeMap.putAll(menuMapCopy);
}

@Override
public void setGroupCheckable(int group, boolean checkable, boolean exclusive) {
mNativeMenu.setGroupCheckable(group, checkable, exclusive);
Expand Down

0 comments on commit a7aafb4

Please sign in to comment.