MenuHostHelper
public class MenuHostHelper
Helper class for implementing MenuHost. This class should be used to implement the MenuHost functions. i.e.:
class ExampleComponent : MenuHost { private val menuHostHelper = MenuHostHelper{ invalidateMenu() } override fun invalidateMenu() { … } override fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner) { menuHostHelper.addMenuProvider(provider, owner) } // Override remaining MenuHost methods in similar fashion }
Summary
Public constructors |
|---|
MenuHostHelper(@NonNull Runnable onInvalidateMenuCallback)Construct a new MenuHostHelper. |
Public methods |
|
|---|---|
void |
addMenuProvider(@NonNull MenuProvider provider)Adds the given |
void |
addMenuProvider(Adds the given |
void |
addMenuProvider(Adds the given |
void |
onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater)Inflates the entire |
void |
onMenuClosed(@NonNull Menu menu)Called when the given |
boolean |
onMenuItemSelected(@NonNull MenuItem item)Called whenever one of the menu items from any of the current |
void |
onPrepareMenu(@NonNull Menu menu)Called right before the given |
void |
removeMenuProvider(@NonNull MenuProvider provider)Removes the given |
Public constructors
Public methods
addMenuProvider
public void addMenuProvider(@NonNull MenuProvider provider)
Adds the given MenuProvider to the helper.
| Parameters | |
|---|---|
@NonNull MenuProvider provider |
the MenuProvider to be added |
addMenuProvider
public void addMenuProvider(
@NonNull MenuProvider provider,
@NonNull LifecycleOwner owner
)
Adds the given MenuProvider to the helper. This MenuProvider will be removed once the given LifecycleOwner receives an Lifecycle.Event.ON_DESTROY event.
| Parameters | |
|---|---|
@NonNull MenuProvider provider |
the MenuProvider to be added |
@NonNull LifecycleOwner owner |
the Lifecycle owner whose state will determine the removal of the provider |
addMenuProvider
public void addMenuProvider(
@NonNull MenuProvider provider,
@NonNull LifecycleOwner owner,
@NonNull Lifecycle.State state
)
Adds the given MenuProvider to the helper once the given LifecycleOwner reaches the given Lifecycle.State. This MenuProvider will be removed once the given LifecycleOwner goes down from the given Lifecycle.State or receives an Lifecycle.Event.ON_DESTROY event.
| Parameters | |
|---|---|
@NonNull MenuProvider provider |
the MenuProvider to be added |
@NonNull LifecycleOwner owner |
the Lifecycle owner whose state will determine the removal of the provider |
@NonNull Lifecycle.State state |
the Lifecycle.State to check for automated addition/removal |
onCreateMenu
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater)
Inflates the entire Menu, which will include all MenuItems provided by all current MenuProviders.
| Parameters | |
|---|---|
@NonNull Menu menu |
the menu to inflate all the menu items into |
@NonNull MenuInflater menuInflater |
the inflater to be used to inflate the menu |
onMenuClosed
public void onMenuClosed(@NonNull Menu menu)
Called when the given Menu, which was provided by one of the current MenuProviders, is closed.
onMenuItemSelected
public boolean onMenuItemSelected(@NonNull MenuItem item)
Called whenever one of the menu items from any of the current MenuProviders is selected.
| Returns | |
|---|---|
boolean |
|
onPrepareMenu
public void onPrepareMenu(@NonNull Menu menu)
Called right before the given Menu, which was provided by one of the current MenuProviders, is to be shown. This happens when the menu has been dynamically modified.
| See also | |
|---|---|
onCreateMenu |
removeMenuProvider
public void removeMenuProvider(@NonNull MenuProvider provider)
Removes the given MenuProvider from the helper.
| Parameters | |
|---|---|
@NonNull MenuProvider provider |
the MenuProvider to be removed |