CarDrawerController

open class CarDrawerController
kotlin.Any
   ↳ androidx.car.drawer.CarDrawerController

A controller that will handle the set up of the navigation drawer. It will hook up the necessary buttons for up navigation, as well as expose methods to allow for a drill down navigation.

Summary

Public constructors
<init>(toolbar: Toolbar!, drawerLayout: DrawerLayout!, drawerToggle: ActionBarDrawerToggle!)

Creates a CarDrawerController that will control the navigation of the drawer given by drawerLayout.

Public methods
Unit

Switches to use the given CarDrawerAdapter as the one to supply the list to display in the navigation drawer.

open Unit
addDrawerListener(listener: DrawerListener)

Sets a listener to be notified of Drawer events.

open Unit

Sets the CarDrawerAdapter that will function as the root adapter.

open Unit
removeDrawerListener(listener: DrawerListener)

Removes a listener to be notified of Drawer events.

open Unit
scrollToPosition(position: Int)

Scroll to given position in the list.

open Unit

Close the drawer.

open Unit

Opens the drawer.

open Unit

Notify this controller that device configurations may have changed.

open Boolean

An analog to an Activity's onOptionsItemSelected().

open Unit

Synchronizes the display of the drawer with its linked DrawerLayout.

open Unit

Sets whether the loading progress bar is displayed in the navigation drawer.

Public constructors

<init>

CarDrawerController(toolbar: Toolbar!, drawerLayout: DrawerLayout!, drawerToggle: ActionBarDrawerToggle!)

Creates a CarDrawerController that will control the navigation of the drawer given by drawerLayout.

The given drawerLayout should either have a child View that is inflated from R.layout.car_drawer or ensure that it three children that have the IDs found in that layout.

Parameters
toolbar Toolbar!: The Toolbar that will serve as the action bar for an Activity.
drawerLayout Toolbar!: The top-level container for the window content that shows the interactive drawer.
drawerToggle Toolbar!: The ActionBarDrawerToggle that bridges the given toolbar and drawerLayout.

Public methods

pushAdapter

fun pushAdapter(adapter: CarDrawerAdapter!): Unit

Switches to use the given CarDrawerAdapter as the one to supply the list to display in the navigation drawer. The title will also be updated from the adapter.

This switch is treated as a navigation to the next level in the drawer. Navigation away from this level will pop the given adapter off and surface contents of the previous adapter that was set via this method. If no such adapter exists, then the root adapter set by #setRootAdapter(CarDrawerAdapter) will be used instead.

Parameters
adapter CarDrawerAdapter!: Adapter for next level of content in the drawer.

addDrawerListener

open fun addDrawerListener(listener: DrawerListener): Unit

Sets a listener to be notified of Drawer events.

setRootAdapter

open fun setRootAdapter(rootAdapter: CarDrawerAdapter?): Unit

Sets the CarDrawerAdapter that will function as the root adapter. The contents of this root adapter are shown when the drawer is first opened. It is also the top-most level of navigation in the drawer.

Parameters
rootAdapter CarDrawerAdapter?: The adapter that will act as the root. If this value is null, then this method will do nothing.

removeDrawerListener

open fun removeDrawerListener(listener: DrawerListener): Unit

Removes a listener to be notified of Drawer events.

scrollToPosition

open fun scrollToPosition(position: Int): Unit

Scroll to given position in the list.

closeDrawer

open fun closeDrawer(): Unit

Close the drawer.

openDrawer

open fun openDrawer(): Unit

Opens the drawer.

onConfigurationChanged

open fun onConfigurationChanged(newConfig: Configuration!): Unit

Notify this controller that device configurations may have changed.

This method should be called from the associated Activity's onConfigurationChanged() method.

onOptionsItemSelected

open fun onOptionsItemSelected(item: MenuItem!): Boolean

An analog to an Activity's onOptionsItemSelected(). This method should be called when the Activity's method is called and will return true if the selection has been handled.

Return
Boolean: true if the item processing was handled by this class.

syncState

open fun syncState(): Unit

Synchronizes the display of the drawer with its linked DrawerLayout.

This should be called from the associated Activity's androidx.appcompat.app.AppCompatActivity#onPostCreate(Bundle) method to synchronize after teh DRawerLayout's instance state has been restored, and any other time when the state may have diverged in such a way that this controller's associated ActionBarDrawerToggle had not been notified.

showLoadingProgressBar

open fun showLoadingProgressBar(show: Boolean): Unit

Sets whether the loading progress bar is displayed in the navigation drawer. If true, the progress bar is displayed and the navigation list is hidden and vice versa.