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

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

XML attributes

CarTheme_drawerBackButtonId  
CarTheme_drawerListId  
CarTheme_drawerProgressId  
CarTheme_drawerTitleId  

Public constructors

CarDrawerController(Toolbar toolbar, DrawerLayout drawerLayout, ActionBarDrawerToggle drawerToggle)

This constructor is deprecated. Use CarDrawerController(DrawerLayout, ActionBarDrawerToggle) instead. The Toolbar is no longer needed and will be ignored.

CarDrawerController(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

XML attributes

CarTheme_drawerBackButtonId

Related methods:

CarTheme_drawerListId

Related methods:

CarTheme_drawerProgressId

Related methods:

CarTheme_drawerTitleId

Related methods:

Public constructors

CarDrawerController

public CarDrawerController (Toolbar toolbar, 
                DrawerLayout drawerLayout, 
                ActionBarDrawerToggle drawerToggle)

This constructor is deprecated.
Use CarDrawerController(DrawerLayout, ActionBarDrawerToggle) instead. The Toolbar is no longer needed and will be ignored.

Parameters
toolbar Toolbar

drawerLayout DrawerLayout

drawerToggle ActionBarDrawerToggle

CarDrawerController

public CarDrawerController (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 its child views have the IDs expected in that layout. The ids expected can be configured in the theme by R.attr.drawerBackButtonId, R.attr.drawerListId, R.attr.drawerTitleId and R.attr.drawerProgressId.

Related XML Attributes:

Parameters
drawerLayout DrawerLayout: The top-level container for the window content that shows the interactive drawer.

drawerToggle ActionBarDrawerToggle: The ActionBarDrawerToggle that will open the drawer.

Public methods

addDrawerListener

public void addDrawerListener (DrawerLayout.DrawerListener listener)

Sets a listener to be notified of Drawer events.

Parameters
listener DrawerLayout.DrawerListener

closeDrawer

public void closeDrawer ()

Close the drawer.

onConfigurationChanged

public 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

public 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

public void openDrawer ()

Opens the drawer.

pushAdapter

public final 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

public void removeDrawerListener (DrawerLayout.DrawerListener listener)

Removes a listener to be notified of Drawer events.

Parameters
listener DrawerLayout.DrawerListener

scrollToPosition

public void scrollToPosition (int position)

Scroll to given position in the list.

Parameters
position int

setRootAdapter

public 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

public 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

public 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 the 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.