I have now solved this problem; I was over-thinking it. The solution lies not in an ActionMode
, but within the menu.
Instead of starting an entirely new ActionMode
for the color menu, change the icon menu if the highlighter is selected. Save a reference to the Menu
parameter in onCreateActionMode
and set a flag of some sort; I'm using a boolean.
private class CustomActionModeCallback implements ActionMode.Callback {
private boolean highlighterClicked = false;
private Menu mMenu;
// Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mMenu = menu;
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.first_menu, menu);
return true;
}
// Called each time the action mode is shown.
// Always called after onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// This method is called when the handlebars are moved.
MenuInflater inflater = mode.getMenuInflater();
if (highlighterClicked) {
menu.clear(); // Remove the four icons
inflater.inflate(R.menu.highlight_colors, menu); // Show the colors
return true; // This time we did stuff, so return true
}
return false; // Return false if nothing is done
}
// Called when the user selects a contextual menu item
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
highlighterClicked = false;
switch (item.getItemId()) {
case R.id.copy:
// Do stuff
break;
case R.id.bookmark:
// Do stuff
break;
case R.id.highlight:
highlighterClicked = true;
onPrepareActionMode(mode, mMenu);
return true;
case R.id.note:
// Do stuff
break;
default:
// Any of the colors were picked
return true;
}
mode.finish(); // Action picked, so close the CAB
return true;
}
// Called when the user exits the action mode
@Override
public void onDestroyActionMode(ActionMode mode) {
clearFocus();
}
}
The selection highlight and handles stay active and functional, and the color options work as intended.
It is safe to delete the second ActionModeCallback
class; it is worthless. Again, way over-thought. :P