belongs to Maven artifact androidx.car:car:1.0.0-alpha1

CarDrawerController

public class CarDrawerController
extends Object

java.lang.Object
   ↳ 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

CarDrawerController(Toolbar toolbar, DrawerLayout drawerLayout, ActionBarDrawerToggle drawerToggle)

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

Public methods

void addDrawerListener(DrawerLayout.DrawerListener listener)

Sets a listener to be notified of Drawer events.

void closeDrawer()

Close the drawer.

void onConfigurationChanged(Configuration newConfig)

Notify this controller that device configurations may have changed.

boolean onOptionsItemSelected(MenuItem item)

An analog to an Activity's onOptionsItemSelected().

void openDrawer()

Opens the drawer.

final void pushAdapter(CarDrawerAdapter adapter)

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

void removeDrawerListener(DrawerLayout.DrawerListener listener)

Removes a listener to be notified of Drawer events.

void scrollToPosition(int position)

Scroll to given position in the list.

void setRootAdapter(CarDrawerAdapter rootAdapter)

Sets the CarDrawerAdapter that will function as the root adapter.

void showLoadingProgressBar(boolean show)

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

void syncState()

Synchronizes the display of the drawer with its linked DrawerLayout.

Inherited methods

Public constructors

CarDrawerController

CarDrawerController (Toolbar toolbar, 
                DrawerLayout drawerLayout, 
                ActionBarDrawerToggle drawerToggle)

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 DrawerLayout: The top-level container for the window content that shows the interactive drawer.

drawerToggle ActionBarDrawerToggle: The ActionBarDrawerToggle that bridges the given toolbar and drawerLayout.

Public methods

addDrawerListener

void addDrawerListener (DrawerLayout.DrawerListener listener)

Sets a listener to be notified of Drawer events.

Parameters
listener DrawerLayout.DrawerListener

closeDrawer

void closeDrawer ()

Close the drawer.

onConfigurationChanged

void onConfigurationChanged (Configuration newConfig)

Notify this controller that device configurations may have changed.

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

Parameters
newConfig Configuration

onOptionsItemSelected

boolean onOptionsItemSelected (MenuItem item)

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.

Parameters
item MenuItem

Returns
boolean true if the item processing was handled by this class.

openDrawer

void openDrawer ()

Opens the drawer.

pushAdapter

void pushAdapter (CarDrawerAdapter adapter)

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.

removeDrawerListener

void removeDrawerListener (DrawerLayout.DrawerListener listener)

Removes a listener to be notified of Drawer events.

Parameters
listener DrawerLayout.DrawerListener

scrollToPosition

void scrollToPosition (int position)

Scroll to given position in the list.

Parameters
position int

setRootAdapter

void setRootAdapter (CarDrawerAdapter rootAdapter)

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.

showLoadingProgressBar

void showLoadingProgressBar (boolean show)

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.

Parameters
show boolean

syncState

void syncState ()

Synchronizes the display of the drawer with its linked DrawerLayout.

This should be called from the associated Activity's 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.