Skip to content

Commit

Permalink
* add new listener to define a custom onOptionsItemSelected listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Nov 16, 2015
1 parent eac813b commit 6b1e6e0
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ public static void update(final Activity activity, final MenuItem menu, Drawable
* @param badgeCount
*/
public static void update(final Activity activity, final MenuItem menu, Drawable icon, BadgeStyle style, String badgeCount) {
update(activity, menu, icon, style, badgeCount, null);
}

/**
* update the given menu item with icon, badgeCount and style
*
* @param activity use to bind onOptionsItemSelected / and to display the toast
* @param menu
* @param icon
* @param style
* @param badgeCount
* @param listener
*/
public static void update(final Activity activity, final MenuItem menu, Drawable icon, BadgeStyle style, String badgeCount, final ActionItemBadgeListener listener) {
if (menu == null) return;

FrameLayout badge;
Expand All @@ -176,7 +190,13 @@ public static void update(final Activity activity, final MenuItem menu, Drawable
badge.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.onOptionsItemSelected(menu);
boolean consumed = false;
if (listener != null) {
consumed = listener.onOptionsItemSelected(menu);
}
if (!consumed) {
activity.onOptionsItemSelected(menu);
}
}
});

Expand Down Expand Up @@ -221,4 +241,9 @@ public boolean onLongClick(View v) {
public static void hide(MenuItem menu) {
menu.setVisible(false);
}


public interface ActionItemBadgeListener {
boolean onOptionsItemSelected(MenuItem menu);
}
}

0 comments on commit 6b1e6e0

Please sign in to comment.