Class DynamicDrawerActivity

All Implemented Interfaces:
ComponentCallbacks, ComponentCallbacks2, SharedPreferences.OnSharedPreferenceChangeListener, KeyEvent.Callback, LayoutInflater.Factory, LayoutInflater.Factory2, View.OnCreateContextMenuListener, Window.Callback, ContextAware, FullyDrawnReporterOwner, OnBackPressedDispatcherOwner, ActivityResultCaller, ActivityResultRegistryOwner, ActionBarDrawerToggle.DelegateProvider, AppCompatCallback, ActivityCompat.OnRequestPermissionsResultCallback, ActivityCompat.RequestPermissionsRequestCodeValidator, OnMultiWindowModeChangedProvider, OnNewIntentProvider, OnPictureInPictureModeChangedProvider, TaskStackBuilder.SupportParentable, OnConfigurationChangedProvider, OnTrimMemoryProvider, KeyEventDispatcher.Component, MenuHost, HasDefaultViewModelProviderFactory, LifecycleOwner, ViewModelStoreOwner, androidx.savedstate.SavedStateRegistryOwner, NavigationView.OnNavigationItemSelectedListener, DynamicLocale, DynamicListener, DynamicSearchListener, DynamicSnackbar, DynamicTransitionListener, DynamicProductFlavor

public abstract class DynamicDrawerActivity extends DynamicActivity implements NavigationView.OnNavigationItemSelectedListener
A DynamicActivity to handle everything related to the DrawerLayout and NavigationMenu.

It also has many other useful functions to customise according to the requirements.

  • Field Details

    • mDrawerOnBackPressedCallback

      protected final OnBackPressedCallback mDrawerOnBackPressedCallback
      On back pressed callback to close the drawers.
    • mDrawerRunnable

      protected final Runnable mDrawerRunnable
      Runnable to close the drawer.
  • Constructor Details

    • DynamicDrawerActivity

      public DynamicDrawerActivity()
  • Method Details

    • getLayoutRes

      @LayoutRes protected int getLayoutRes()
      Description copied from class: DynamicActivity
      Returns the layout resource for this activity.
      Overrides:
      getLayoutRes in class DynamicActivity
      Returns:
      The layout resource for this activity.
    • onCreate

      protected void onCreate(@Nullable Bundle savedInstanceState)
      Overrides:
      onCreate in class DynamicActivity
    • onConfigureOnBackPressedDispatcher

      protected void onConfigureOnBackPressedDispatcher()
      Description copied from class: DynamicSystemActivity
      This method will be called to configure on back pressed callback to support API 33 and above.
      Overrides:
      onConfigureOnBackPressedDispatcher in class DynamicActivity
    • onResume

      public void onResume()
      Overrides:
      onResume in class DynamicSystemActivity
    • onBackPressed

      public void onBackPressed()
      Overrides:
      onBackPressed in class DynamicActivity
    • isDrawerActivity

      protected boolean isDrawerActivity()
      Description copied from class: DynamicActivity
      Checks whether the navigation drawer is added.
      Overrides:
      isDrawerActivity in class DynamicActivity
      Returns:
      true if this activity is a drawer activity.
    • setStatusBarColor

      public void setStatusBarColor(@ColorInt int color)
      Description copied from class: DynamicSystemActivity
      Set the status bar color.

      It will be applied only on the API 21 and above.

      Overrides:
      setStatusBarColor in class DynamicActivity
      Parameters:
      color - The color to be applied.
    • getEdgeToEdgeView

      @Nullable public View getEdgeToEdgeView()
      Description copied from class: DynamicSystemActivity
      Returns the view to apply edge-to-edge window insets.
      Overrides:
      getEdgeToEdgeView in class DynamicActivity
      Returns:
      The view to apply edge-to-edge window insets.
      See Also:
    • setActionBarDrawerToggle

      protected boolean setActionBarDrawerToggle()
      Sets the action bar drawer toggle icon according to the returned value.
      Returns:
      true to show the drawer toggle icon.
    • isPersistentDrawer

      public boolean isPersistentDrawer()
      Makes the drawer persistent according to the returned value.
      Returns:
      true to make the drawer persistent by locking it in the open mode.
      See Also:
    • onNavigationItemSelected

      public boolean onNavigationItemSelected(@NonNull MenuItem item)
      Specified by:
      onNavigationItemSelected in interface NavigationView.OnNavigationItemSelectedListener
    • getDrawer

      @NonNull public DrawerLayout getDrawer()
      Get the drawer layout used by this activity.
      Returns:
      The drawer layout used by this activity.
    • isDrawerOpen

      public boolean isDrawerOpen()
      Checks whether the drawer is in the open state.
      Returns:
      true if the drawer is in the open mode.
    • closeDrawer

      public void closeDrawer(int gravity)
      Close the drawer if it is not in the locked state.
      Parameters:
      gravity - The gravity of the drawer to close it.
      See Also:
    • closeDrawers

      public void closeDrawers()
      Close all the opened drawers if they are not in the locked state.
      See Also:
    • isDrawerLocked

      public boolean isDrawerLocked()
      Checks whether the drawer is in the locked mode.
      Returns:
      true if the drawer is in the locked mode.
    • getDrawerToggle

      public ActionBarDrawerToggle getDrawerToggle()
      Returns the action bar drawer toggle used by this activity.
      Returns:
      The action bar drawer toggle used by this activity.
    • showDrawerToggle

      public void showDrawerToggle(boolean showDrawerIndicator)
      Set the drawer toggle icon to open or close the navigation drawer.
      Parameters:
      showDrawerIndicator - true to show the drawer toggle icon.
    • animateDrawerToggle

      public void animateDrawerToggle(float startOffset, float endOffset)
      Animate the drawer toggle icon from one offset to another.
      Parameters:
      startOffset - The start offset.
      endOffset - The end offset.
    • getNavigationView

      @NonNull public NavigationView getNavigationView()
      Get the navigation view used by this activity.
      Returns:
      The navigation view used by this activity.
    • setNavigationViewMenu

      public void setNavigationViewMenu(@MenuRes int menuRes)
      Set menu for the navigation view.
      Parameters:
      menuRes - The menu resource id for the navigation view.
    • setNavHeaderIcon

      public void setNavHeaderIcon(@Nullable Drawable drawable)
      Set header icon for the navigation view.
      Parameters:
      drawable - The drawable for the header image view.
    • setNavHeaderIcon

      public void setNavHeaderIcon(@DrawableRes int drawableRes)
      Set header icon for the navigation view.
      Parameters:
      drawableRes - The drawable resource for the header image view.
    • setNavHeaderTitle

      public void setNavHeaderTitle(@Nullable String string)
      Set header title for the navigation view.
      Parameters:
      string - The string for the title.
    • setNavHeaderTitle

      public void setNavHeaderTitle(@StringRes int stringRes)
      Set header title for the navigation view.
      Parameters:
      stringRes - The string resource for the title.
    • setNavHeaderSubtitle

      public void setNavHeaderSubtitle(@Nullable String string)
      Set header subtitle for the navigation view.
      Parameters:
      string - The string for the subtitle.
    • setNavHeaderSubtitle

      public void setNavHeaderSubtitle(@StringRes int stringRes)
      Set header subtitle for the navigation view.
      Parameters:
      stringRes - The string resource for the subtitle.
    • onSearchViewExpanded

      public void onSearchViewExpanded()
      Description copied from interface: DynamicSearchListener
      This method will be called when the search view is expanded.
      Specified by:
      onSearchViewExpanded in interface DynamicSearchListener
      Overrides:
      onSearchViewExpanded in class DynamicActivity
    • onSearchViewCollapsed

      public void onSearchViewCollapsed()
      Description copied from interface: DynamicSearchListener
      This method will be called when the search view is collapsed.
      Specified by:
      onSearchViewCollapsed in interface DynamicSearchListener
      Overrides:
      onSearchViewCollapsed in class DynamicActivity