Class DynamicStateActivity

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, DynamicLocale, DynamicListener, DynamicTransitionListener, DynamicProductFlavor
Direct Known Subclasses:
DynamicActivity

public abstract class DynamicStateActivity extends DynamicSystemActivity
A DynamicSystemActivity to maintain state of the widgets and fragments.

It will be useful while handling orientation changes. It saves the current fragment state and reuses it while a configuration change takes place.

  • Field Details

    • STATE_DELAY

      public static final int STATE_DELAY
      Minimum delay to restore the activity state.
      See Also:
    • ADS_STATE_LOCALE

      public static final String ADS_STATE_LOCALE
      Locale key to maintain its state during configuration changes.
      See Also:
    • ADS_STATE_CONTENT_FRAGMENT_TAG

      public static final String ADS_STATE_CONTENT_FRAGMENT_TAG
      Content fragment TAG key which will be used to find it during the configuration changes.
      See Also:
    • ADS_STATE_APP_BAR_COLLAPSED

      public static final String ADS_STATE_APP_BAR_COLLAPSED
      Status bar key to maintain its state.
      See Also:
    • ADS_STATE_FAB_VISIBLE

      public static final String ADS_STATE_FAB_VISIBLE
      FAB key to maintain its state.
      See Also:
    • ADS_STATE_EXTENDED_FAB_VISIBLE

      public static final String ADS_STATE_EXTENDED_FAB_VISIBLE
      Extended FAB key to maintain its state.
      See Also:
    • ADS_STATE_EXTENDED_FAB_STATE

      public static final String ADS_STATE_EXTENDED_FAB_STATE
      Extended FAB state key to maintain its state.
      See Also:
    • ADS_STATE_SEARCH_VIEW_VISIBLE

      public static final String ADS_STATE_SEARCH_VIEW_VISIBLE
      Search key to maintain its state.
      See Also:
    • ADS_VISIBILITY_FAB_NO_CHANGE

      public static final int ADS_VISIBILITY_FAB_NO_CHANGE
      FAB visibility constant for no change.
      See Also:
    • ADS_VISIBILITY_EXTENDED_FAB_NO_CHANGE

      public static final int ADS_VISIBILITY_EXTENDED_FAB_NO_CHANGE
      Extended FAB visibility constant for no change.
      See Also:
    • ADS_STATE_EXTENDED_FAB_NO_CHANGE

      public static final boolean ADS_STATE_EXTENDED_FAB_NO_CHANGE
      Extended FAB state constant for extended.
      See Also:
    • mAppBarStateListener

      protected AppBarLayout.OnOffsetChangedListener mAppBarStateListener
      App bar off set change listener to identify whether it is in the collapsed state.
  • Constructor Details

    • DynamicStateActivity

      public DynamicStateActivity()
  • Method Details

    • onCreate

      protected void onCreate(@Nullable Bundle savedInstanceState)
      Overrides:
      onCreate in class DynamicSystemActivity
    • getFragmentContainerId

      @IdRes protected abstract int getFragmentContainerId()
      Retrieves the fragment container id.

      This method must be implemented in the extended activity to show fragments inside this container.

      Returns:
      The fragment container id so that the fragment can be injected into this view.
    • onSaveInstanceState

      public void onSaveInstanceState(@NonNull Bundle outState)
      Overrides:
      onSaveInstanceState in class DynamicSystemActivity
    • switchFragment

      public void switchFragment(@NonNull FragmentTransaction fragmentTransaction, @NonNull Fragment fragment, boolean addToBackStack, @Nullable String tag, boolean restoreByTag)
      Switch the content fragment used by this activity by using the supplied fragment transaction.
      Parameters:
      fragmentTransaction - The customised fragment transaction to support animations and more.
      fragment - The fragment to be used by this activity.
      addToBackStack - true to put previous fragment to back stack.
      tag - The fragment tag to maintain the back stack.
      restoreByTag - true to restore the fragment by tag.
    • switchFragment

      public void switchFragment(@NonNull Fragment fragment, boolean addToBackStack, @Nullable String tag, boolean restoreByTag)
      Switch the content fragment used by this activity.
      Parameters:
      fragment - The fragment to be used by this activity.
      addToBackStack - true to put previous fragment to back stack.
      tag - The fragment tag to maintain the back stack.
      restoreByTag - true to restore the fragment by tag.
    • switchFragment

      public void switchFragment(@NonNull Fragment fragment, boolean addToBackStack, boolean restoreByTag)
      Switch the content fragment used by this activity.
      Parameters:
      fragment - The fragment to be used by this activity.
      addToBackStack - true to put previous fragment to back stack.
      restoreByTag - true to restore the fragment by tag.
      See Also:
    • switchFragment

      public void switchFragment(@NonNull Fragment fragment, boolean addToBackStack)
      Switch the content fragment used by this activity.
      Parameters:
      fragment - The fragment to be used by this activity.
      addToBackStack - true to put previous fragment to back stack.
      See Also:
    • switchNewFragment

      public void switchNewFragment(@NonNull Fragment fragment, boolean addToBackStack)
      Switch the content fragment used by this activity.
      Parameters:
      fragment - The fragment to be used by this activity.
      addToBackStack - true to put previous fragment to back stack.
      See Also:
    • getContentFragment

      @Nullable public Fragment getContentFragment()
      Returns the current displayed fragment.
      Returns:
      The content fragment used by this activity.
    • setContentFragment

      public void setContentFragment(@Nullable Fragment fragment, @NonNull String tag)
      Set the current content fragment.
      Parameters:
      fragment - The fragment to be set.
      tag - The content fragment tag.
    • getFABVisibility

      public int getFABVisibility()
      Returns the current FAB visibility.
      Returns:
      The current FAB visibility.
    • setFABVisibility

      public void setFABVisibility(int visibility)
      Set the current FAB visibility.
      Parameters:
      visibility - The FAB visibility to be set.
    • getExtendedFABVisibility

      public int getExtendedFABVisibility()
      Returns the current extended FAB visibility.
      Returns:
      The current extended FAB visibility.
    • setExtendedFABVisibility

      public void setExtendedFABVisibility(int visibility)
      Set the current extended FAB visibility.
      Parameters:
      visibility - The extended FAB visibility to be set.
    • getExtendedFABState

      public boolean getExtendedFABState()
      Returns whether the extend FAB is in the extended state.
      Returns:
      true if the extend FAB is in the extended state.
    • setExtendedFABState

      public void setExtendedFABState(boolean extended)
      Set the current extended FAB state.
      Parameters:
      extended - true if the extend FAB is in the extended state.
    • setAppBarCollapsed

      public void setAppBarCollapsed(boolean collapsed)
      Sets whether the app bar is collapsed.
      Parameters:
      collapsed - true if the app bar is collapsed.
    • isAppBarCollapsed

      public boolean isAppBarCollapsed()
      Returns whether the app bar is in collapsed state.
      Returns:
      true if the app bar is in collapsed state.
    • onNavigationItemSelected

      public void onNavigationItemSelected(@IdRes int itemId, boolean restore)
      This method will be called on selecting the navigation item.
      Parameters:
      itemId - The item id to be selected.
      restore - true if restoring the state of item.