MenuHostHelper
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(onInvalidateMenuCallback: Runnable)Construct a new MenuHostHelper. |
Public functions |
|
|---|---|
Unit |
addMenuProvider(provider: MenuProvider)Adds the given |
Unit |
addMenuProvider(provider: MenuProvider, owner: LifecycleOwner)Adds the given |
Unit |
addMenuProvider(Adds the given |
Unit |
onCreateMenu(menu: Menu, menuInflater: MenuInflater)Inflates the entire |
Unit |
onMenuClosed(menu: Menu)Called when the given |
Boolean |
onMenuItemSelected(item: MenuItem)Called whenever one of the menu items from any of the current |
Unit |
onPrepareMenu(menu: Menu)Called right before the given |
Unit |
removeMenuProvider(provider: MenuProvider)Removes the given |
Public constructors
MenuHostHelper
MenuHostHelper(onInvalidateMenuCallback: Runnable)
Construct a new MenuHostHelper.
| Parameters | |
|---|---|
onInvalidateMenuCallback: Runnable |
callback to invalidate the menu whenever there may be a change to it |
Public functions
addMenuProvider
fun addMenuProvider(provider: MenuProvider): Unit
Adds the given MenuProvider to the helper.
| Parameters | |
|---|---|
provider: MenuProvider |
the MenuProvider to be added |
addMenuProvider
fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner): Unit
Adds the given MenuProvider to the helper. This MenuProvider will be removed once the given LifecycleOwner receives an Lifecycle.Event.ON_DESTROY event.
| Parameters | |
|---|---|
provider: MenuProvider |
the MenuProvider to be added |
owner: LifecycleOwner |
the Lifecycle owner whose state will determine the removal of the provider |
addMenuProvider
fun addMenuProvider(
provider: MenuProvider,
owner: LifecycleOwner,
state: Lifecycle.State
): Unit
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 | |
|---|---|
provider: MenuProvider |
the MenuProvider to be added |
owner: LifecycleOwner |
the Lifecycle owner whose state will determine the removal of the provider |
state: Lifecycle.State |
the Lifecycle.State to check for automated addition/removal |
onCreateMenu
fun onCreateMenu(menu: Menu, menuInflater: MenuInflater): Unit
Inflates the entire Menu, which will include all MenuItems provided by all current MenuProviders.
| Parameters | |
|---|---|
menu: Menu |
the menu to inflate all the menu items into |
menuInflater: MenuInflater |
the inflater to be used to inflate the menu |
onMenuClosed
fun onMenuClosed(menu: Menu): Unit
Called when the given Menu, which was provided by one of the current MenuProviders, is closed.
| Parameters | |
|---|---|
menu: Menu |
the menu that has been closed |
onMenuItemSelected
fun onMenuItemSelected(item: MenuItem): Boolean
Called whenever one of the menu items from any of the current MenuProviders is selected.
| Parameters | |
|---|---|
item: MenuItem |
the menu item that was selected |
| Returns | |
|---|---|
Boolean |
|
onPrepareMenu
fun onPrepareMenu(menu: Menu): Unit
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.
| Parameters | |
|---|---|
menu: Menu |
the menu that is to be prepared |
| See also | |
|---|---|
onCreateMenu |
removeMenuProvider
fun removeMenuProvider(provider: MenuProvider): Unit
Removes the given MenuProvider from the helper.
| Parameters | |
|---|---|
provider: MenuProvider |
the MenuProvider to be removed |