Class DynamicFragment
java.lang.Object
androidx.fragment.app.Fragment
com.pranavpandey.android.dynamic.support.fragment.DynamicFragment
- All Implemented Interfaces:
ComponentCallbacks,SharedPreferences.OnSharedPreferenceChangeListener,View.OnCreateContextMenuListener,ActivityResultCaller,MenuProvider,HasDefaultViewModelProviderFactory,LifecycleOwner,ViewModelStoreOwner,androidx.savedstate.SavedStateRegistryOwner,DynamicLifecycle,DynamicSearchListener,DynamicTransitionListener,DynamicProductFlavor
- Direct Known Subclasses:
DynamicPermissionsFragment,DynamicSplashFragment,DynamicTutorialFragment,DynamicViewPager2Fragment,DynamicViewPagerFragment,ThemeFragment
public class DynamicFragment
extends Fragment
implements DynamicProductFlavor, DynamicLifecycle, DynamicTransitionListener, DynamicSearchListener, MenuProvider, SharedPreferences.OnSharedPreferenceChangeListener
Base fragment class to provide basic functionality and to work with the
DynamicActivity.
Extend this fragment to add more functionality according to the requirements.
-
Nested Class Summary
Nested classes/interfaces inherited from class androidx.fragment.app.Fragment
Fragment.InstantiationException, Fragment.SavedState -
Field Summary
Fields inherited from class androidx.fragment.app.Fragment
mPreviousWho -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidFinish the parent activity by callingActivity.finish().booleangetBooleanFromArguments(String key, boolean defaultValue) Retrieves a boolean from the fragment arguments associated with the supplied key.protected intReturns the menu item id to make it checked.Get the parent activity for this fragment.Returns the enter transition used by his listener.Returns the exit transition used by his listener.Returns the reenter transition used by his listener.Returns the return transition used by his listener.Returns the menu used by the host.intgetIntFromArguments(String key, int defaultValue) Retrieves an integer from the fragment arguments associated with the supplied key.protected intReturns the bottom navigation view id to make its menu item checked.<T extends Parcelable>
TRetrieves a parcelable from the fragment arguments associated with the supplied key.This method will be called to postpone the transition until the returned view is laid.Get the current saved instance state for this fragment.Retrieves a string from the fragment arguments associated with the supplied key.getStringFromArguments(String key, String defaultValue) Retrieves a string from the fragment arguments associated with the supplied key.protected CharSequenceReturns the subtitle used by the parent activity.Get the parent activity for this fragment.This method will be called to get the text watcher for the search view.protected CharSequencegetTitle()Returns the title used by the parent activity.voidTry to invalidate options menu attached to the parent activity.booleanChecks whether the parent activity is a app compat activity.booleanReturns whether to enable the menu for this fragment.booleanReturns whether to force menu icons for this fragment.protected booleanReturns whether to use a menu provider for this fragment.booleanReturns whether to register a shared preferences listener for this fragment.booleanReturns whether the search view is expanded for the parent activity.booleanReturns whether to register a listener to listen the search view expand and collapse callbacks for theDynamicActivity.booleanChecks whether the support action bar is applied to the parent activity.voidonAddActivityHeader(View view) This method will be called after adding the activity header.protected voidonAddMenuProvider(MenuProvider menuProvider) This method will be called to add a menu provider for the parent activity.onAdjustEnterReturnTransition(Object transition, boolean enter) This method will be called to optionally to adjust the enter and return transitions before applying.onAdjustExitReenterTransition(Object transition, boolean exit) This method will be called to optionally to adjust the exit and reenter transitions before applying.voidonApplyTransitions(boolean exit) This method will be called on applying transitions.voidvoidonCreateMenu(Menu menu, MenuInflater menuInflater) voidvoidonDynamicPause(boolean forced) voidonDynamicResume(boolean forced) onFindView(int resultCode, int position, String transition, int viewId) This method will be called to find the view according to the transition name or resource id.voidonMenuClosed(Menu menu) booleanonMenuItemSelected(MenuItem menuItem) voidonPause()voidonPrepareMenu(Menu menu) protected voidonRemoveProvider(MenuProvider menuProvider) This method will be called to remove a menu provider from the parent activity.voidonResume()voidonSaveInstanceState(Bundle outState) voidThis method will be called when the search view is collapsed.voidThis method will be called when the search view is expanded.voidonSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) voidonStart()protected voidonStartActivityException(Exception exception) This method will be called when there is an exception on starting the activity from this fragment.voidonViewCreated(View view, Bundle savedInstanceState) voidbooleanReturns whether to set the options menu for this fragment.voidsetHostMenuItemVisible(int id, boolean visible) Set the visibility of the app bar menu item for the host by supplying its id.voidsetMenuVisibility(boolean menuVisible) protected voidsetResult(int resultCode) Set result for the parent activity to notify the requester about the action.protected voidsetResult(int resultCode, boolean finish) Set result for the parent activity to notify the requester about the action.protected voidSet result for the parent activity to notify the requester about the action.protected voidSet result for the parent activity to notify the requester about the action.voidstartActivity(Intent intent) voidstartActivity(Intent intent, Bundle options) voidstartActivityForResult(Intent intent, int requestCode) voidstartActivityForResult(Intent intent, int requestCode, Bundle options) voidstartMotionActivity(Intent intent, Bundle options) CallActivity.startActivity(Intent, Bundle)from the fragment's containing Activity.voidstartMotionActivityForResult(Intent intent, int requestCode, Bundle options) CallActivity.startActivityForResult(Intent, int, Bundle)from the fragment's containing Activity.voidMethods inherited from class androidx.fragment.app.Fragment
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelCreationExtras, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroyOptionsMenu, onDestroyView, onDetach, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onStop, onViewStateRestored, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startIntentSenderForResult, toString, unregisterForContextMenu
-
Constructor Details
-
DynamicFragment
public DynamicFragment()
-
-
Method Details
-
onCreate
-
onViewCreated
- Overrides:
onViewCreatedin classFragment
-
startActivity
- Overrides:
startActivityin classFragment
-
startActivity
- Overrides:
startActivityin classFragment
-
startActivityForResult
- Overrides:
startActivityForResultin classFragment
-
startActivityForResult
- Overrides:
startActivityForResultin classFragment
-
onStartActivityException
This method will be called when there is an exception on starting the activity from this fragment.- Parameters:
exception- The exception occurred.- See Also:
-
postponeEnterTransition
public void postponeEnterTransition()- Overrides:
postponeEnterTransitionin classFragment
-
startPostponedEnterTransition
public void startPostponedEnterTransition()- Overrides:
startPostponedEnterTransitionin classFragment
-
onApplyTransitions
public void onApplyTransitions(boolean exit) Description copied from interface:DynamicTransitionListenerThis method will be called on applying transitions.It is recommended to do any shared element adjustments here like postponing the transition.
- Specified by:
onApplyTransitionsin interfaceDynamicTransitionListener- Parameters:
exit-trueif the activity is exiting.
-
getDynamicEnterTransition
Description copied from interface:DynamicTransitionListenerReturns the enter transition used by his listener.- Specified by:
getDynamicEnterTransitionin interfaceDynamicTransitionListener- Returns:
- The enter transition used by his listener.
- See Also:
-
getDynamicReturnTransition
Description copied from interface:DynamicTransitionListenerReturns the return transition used by his listener.- Specified by:
getDynamicReturnTransitionin interfaceDynamicTransitionListener- Returns:
- The return transition transition used by his listener.
- See Also:
-
getDynamicExitTransition
Description copied from interface:DynamicTransitionListenerReturns the exit transition used by his listener.- Specified by:
getDynamicExitTransitionin interfaceDynamicTransitionListener- Returns:
- The exit transition used by his listener.
- See Also:
-
getDynamicReenterTransition
Description copied from interface:DynamicTransitionListenerReturns the reenter transition used by his listener.- Specified by:
getDynamicReenterTransitionin interfaceDynamicTransitionListener- Returns:
- The reenter transition used by his listener.
- See Also:
-
onAdjustEnterReturnTransition
Description copied from interface:DynamicTransitionListenerThis method will be called to optionally to adjust the enter and return transitions before applying.- Specified by:
onAdjustEnterReturnTransitionin interfaceDynamicTransitionListener- Parameters:
transition- The transition to be adjusted.enter-trueif enter transition, otherwise return transition.- Returns:
- The adjusted enter or return transition before applying.
- See Also:
-
onAdjustExitReenterTransition
Description copied from interface:DynamicTransitionListenerThis method will be called to optionally to adjust the exit and reenter transitions before applying.- Specified by:
onAdjustExitReenterTransitionin interfaceDynamicTransitionListener- Parameters:
transition- The transition to be adjusted.exit-trueif exit transition, otherwise reenter transition.- Returns:
- The adjusted exit or reenter transition before applying.
- See Also:
-
getPostponeTransitionView
Description copied from interface:DynamicTransitionListenerThis method will be called to postpone the transition until the returned view is laid.It will be called only on API 21 and above.
- Specified by:
getPostponeTransitionViewin interfaceDynamicTransitionListener- Returns:
- The view to postpone the transition.
-
onFindView
@Nullable public View onFindView(int resultCode, int position, @NonNull String transition, @IdRes int viewId) Description copied from interface:DynamicTransitionListenerThis method will be called to find the view according to the transition name or resource id.It will be called only on API 21 and above.
- Specified by:
onFindViewin interfaceDynamicTransitionListener- Parameters:
resultCode- The transition result code.position- The position of the shared element.transition- The transition name of the view.viewId- The id resource to find the view by id.- Returns:
- The view according to the view id.
-
onSearchViewExpanded
public void onSearchViewExpanded()Description copied from interface:DynamicSearchListenerThis method will be called when the search view is expanded.- Specified by:
onSearchViewExpandedin interfaceDynamicSearchListener
-
onSearchViewCollapsed
public void onSearchViewCollapsed()Description copied from interface:DynamicSearchListenerThis method will be called when the search view is collapsed.- Specified by:
onSearchViewCollapsedin interfaceDynamicSearchListener
-
getTextWatcher
Description copied from interface:DynamicSearchListenerThis method will be called to get the text watcher for the search view.- Specified by:
getTextWatcherin interfaceDynamicSearchListener- Returns:
- The text watcher for the search view.
-
startMotionActivity
CallActivity.startActivity(Intent, Bundle)from the fragment's containing Activity.It will allow
Bundleoptions ifDynamicMotion.isMotion()is enabled.- Parameters:
intent- The intent to be used.options- The intent to be set.
-
startMotionActivityForResult
CallActivity.startActivityForResult(Intent, int, Bundle)from the fragment's containing Activity.It will allow
Bundleoptions ifDynamicMotion.isMotion()is enabled.- Parameters:
intent- The intent to be used.requestCode- The request code to be set.options- The intent to be set.
-
onAddActivityHeader
This method will be called after adding the activity header.- Parameters:
view- The view added to the header.
-
isSearchViewListenerListener
public boolean isSearchViewListenerListener()Returns whether to register a listener to listen the search view expand and collapse callbacks for theDynamicActivity.- Returns:
trueto register aDynamicSearchListenerto listen the search view expand and collapse callbacks for theDynamicActivity.
-
isEnableMenu
public boolean isEnableMenu()Returns whether to enable the menu for this fragment.- Returns:
trueto enable the menu for this fragment.
-
isSearchViewExpanded
public boolean isSearchViewExpanded()Returns whether the search view is expanded for the parent activity.- Returns:
- The search view is expanded for the parent activity.
-
setHasOptionsMenu
public boolean setHasOptionsMenu()Returns whether to set the options menu for this fragment.- Returns:
trueif set the options menu for this fragment.- See Also:
-
isForceMenuIcons
public boolean isForceMenuIcons()Returns whether to force menu icons for this fragment.- Returns:
trueif force menu icons for this fragment.- See Also:
-
isHasMenuProvider
protected boolean isHasMenuProvider()Returns whether to use a menu provider for this fragment.- Returns:
trueif a menu provider is required for this fragment.- See Also:
-
onAddMenuProvider
This method will be called to add a menu provider for the parent activity.- Parameters:
menuProvider- The menu provider to be added.
-
onRemoveProvider
This method will be called to remove a menu provider from the parent activity.- Parameters:
menuProvider- The menu provider to be removed.
-
invalidateHostMenu
public void invalidateHostMenu()Try to invalidate options menu attached to the parent activity.- See Also:
-
onPrepareMenu
- Specified by:
onPrepareMenuin interfaceMenuProvider
-
onCreateMenu
- Specified by:
onCreateMenuin interfaceMenuProvider
-
onMenuItemSelected
- Specified by:
onMenuItemSelectedin interfaceMenuProvider
-
onMenuClosed
- Specified by:
onMenuClosedin interfaceMenuProvider
-
setMenuVisibility
public void setMenuVisibility(boolean menuVisible) - Overrides:
setMenuVisibilityin classFragment
-
onStart
public void onStart() -
onResume
public void onResume() -
onPause
public void onPause() -
onDestroy
public void onDestroy() -
onDynamicResume
Description copied from interface:DynamicLifecycleThis method will be called when the dynamic resume event occurs like resuming aFragmentwhen it is visible to the user inside aViewPager.- Specified by:
onDynamicResumein interfaceDynamicLifecycle- Parameters:
forced-trueif called explicitly.
-
onDynamicPause
Description copied from interface:DynamicLifecycleThis method will be called when the dynamic pause event occurs like pausing aFragmentwhen it goes off screen inside aViewPager.- Specified by:
onDynamicPausein interfaceDynamicLifecycle- Parameters:
forced-trueif called explicitly.
-
onSaveInstanceState
- Overrides:
onSaveInstanceStatein classFragment
-
getProductFlavor
- Specified by:
getProductFlavorin interfaceDynamicProductFlavor
-
getSavedInstanceState
Get the current saved instance state for this fragment.- Returns:
- The current saved instance state for this fragment.
-
getTitle
Returns the title used by the parent activity.- Returns:
- The title used by the parent activity.
-
getSubtitle
Returns the subtitle used by the parent activity.- Returns:
- The subtitle used by the parent activity.
-
getCheckedMenuItemId
Returns the menu item id to make it checked.- Returns:
- The menu item id to make it checked.
-
isAppCompatActivity
public boolean isAppCompatActivity()Checks whether the parent activity is a app compat activity.- Returns:
trueif the parent activity is anAppCompatActivity.
-
isSupportActionBar
public boolean isSupportActionBar()Checks whether the support action bar is applied to the parent activity.- Returns:
trueif the support action bar is notnull.
-
getParcelableFromArguments
Retrieves a parcelable from the fragment arguments associated with the supplied key.- Type Parameters:
T- The type of the parcelable.- Parameters:
key- The key to be retrieved.- Returns:
- The parcelable from the fragment arguments.
- See Also:
-
getStringFromArguments
Retrieves a string from the fragment arguments associated with the supplied key.- Parameters:
key- The key to be retrieved.defaultValue- The default value.- Returns:
- The string from the fragment arguments.
- See Also:
-
getStringFromArguments
Retrieves a string from the fragment arguments associated with the supplied key.- Parameters:
key- The key to be retrieved.- Returns:
- The string from the fragment arguments.
- See Also:
-
getIntFromArguments
Retrieves an integer from the fragment arguments associated with the supplied key.- Parameters:
key- The key to be retrieved.defaultValue- The default value.- Returns:
- The integer from the fragment arguments.
- See Also:
-
getBooleanFromArguments
Retrieves a boolean from the fragment arguments associated with the supplied key.- Parameters:
key- The key to be retrieved.defaultValue- The default value.- Returns:
- The boolean from the fragment arguments.
- See Also:
-
setResult
Set result for the parent activity to notify the requester about the action.- Parameters:
resultCode- The result code for the activity.intent- The result intent to provide any data as an extra.finish-trueto finish the activity.
-
setResult
Set result for the parent activity to notify the requester about the action.- Parameters:
resultCode- The result code for the activity.intent- The result intent to provide any data as an extra.
-
setResult
protected void setResult(int resultCode, boolean finish) Set result for the parent activity to notify the requester about the action.- Parameters:
resultCode- The result code for the activity.finish-trueto finish the activity.
-
setResult
protected void setResult(int resultCode) Set result for the parent activity to notify the requester about the action.- Parameters:
resultCode- The result code for the activity.
-
finishActivity
protected void finishActivity()Finish the parent activity by callingActivity.finish(). -
getSystemActivity
Get the parent activity for this fragment.- Returns:
- The parent activity as the instance of
DynamicSystemActivity.
-
getDynamicActivity
Get the parent activity for this fragment.- Returns:
- The parent activity as the instance of
DynamicActivity.
-
getHostMenu
Returns the menu used by the host.- Returns:
- The menu used by the host.
-
setHostMenuItemVisible
Set the visibility of the app bar menu item for the host by supplying its id.- Parameters:
id- The id to find the menu item.visible-trueto make the menu item visible.
-