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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Finish the parent activity by callingActivity.finish()
.boolean
getBooleanFromArguments
(String key, boolean defaultValue) Retrieves a boolean from the fragment arguments associated with the supplied key.protected int
Returns 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.int
getIntFromArguments
(String key, int defaultValue) Retrieves an integer from the fragment arguments associated with the supplied key.protected int
Returns 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 CharSequence
Returns 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 CharSequence
getTitle()
Returns the title used by the parent activity.void
Try to invalidate options menu attached to the parent activity.boolean
Checks whether the parent activity is a app compat activity.boolean
Returns whether to enable the menu for this fragment.boolean
Returns whether to force menu icons for this fragment.protected boolean
Returns whether to use a menu provider for this fragment.boolean
Returns whether to register a shared preferences listener for this fragment.boolean
Returns whether the search view is expanded for the parent activity.boolean
Returns whether to register a listener to listen the search view expand and collapse callbacks for theDynamicActivity
.boolean
Checks whether the support action bar is applied to the parent activity.void
onAddActivityHeader
(View view) This method will be called after adding the activity header.protected void
onAddMenuProvider
(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.void
onApplyTransitions
(boolean exit) This method will be called on applying transitions.void
void
onCreateMenu
(Menu menu, MenuInflater menuInflater) void
void
onDynamicPause
(boolean forced) void
onDynamicResume
(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.void
onMenuClosed
(Menu menu) boolean
onMenuItemSelected
(MenuItem menuItem) void
onPause()
void
onPrepareMenu
(Menu menu) protected void
onRemoveProvider
(MenuProvider menuProvider) This method will be called to remove a menu provider from the parent activity.void
onResume()
void
onSaveInstanceState
(Bundle outState) void
This method will be called when the search view is collapsed.void
This method will be called when the search view is expanded.void
onSharedPreferenceChanged
(SharedPreferences sharedPreferences, String key) void
onStart()
protected void
onStartActivityException
(Exception exception) This method will be called when there is an exception on starting the activity from this fragment.void
onViewCreated
(View view, Bundle savedInstanceState) void
boolean
Returns whether to set the options menu for this fragment.void
setHostMenuItemVisible
(int id, boolean visible) Set the visibility of the app bar menu item for the host by supplying its id.void
setMenuVisibility
(boolean menuVisible) protected void
setResult
(int resultCode) Set result for the parent activity to notify the requester about the action.protected void
setResult
(int resultCode, boolean finish) Set result for the parent activity to notify the requester about the action.protected void
Set result for the parent activity to notify the requester about the action.protected void
Set result for the parent activity to notify the requester about the action.void
startActivity
(Intent intent) void
startActivity
(Intent intent, Bundle options) void
startActivityForResult
(Intent intent, int requestCode) void
startActivityForResult
(Intent intent, int requestCode, Bundle options) void
startMotionActivity
(Intent intent, Bundle options) CallActivity.startActivity(Intent, Bundle)
from the fragment's containing Activity.void
startMotionActivityForResult
(Intent intent, int requestCode, Bundle options) CallActivity.startActivityForResult(Intent, int, Bundle)
from the fragment's containing Activity.void
Methods 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:
onViewCreated
in classFragment
-
startActivity
- Overrides:
startActivity
in classFragment
-
startActivity
- Overrides:
startActivity
in classFragment
-
startActivityForResult
- Overrides:
startActivityForResult
in classFragment
-
startActivityForResult
- Overrides:
startActivityForResult
in 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:
postponeEnterTransition
in classFragment
-
startPostponedEnterTransition
public void startPostponedEnterTransition()- Overrides:
startPostponedEnterTransition
in classFragment
-
onApplyTransitions
public void onApplyTransitions(boolean exit) Description copied from interface:DynamicTransitionListener
This method will be called on applying transitions.It is recommended to do any shared element adjustments here like postponing the transition.
- Specified by:
onApplyTransitions
in interfaceDynamicTransitionListener
- Parameters:
exit
-true
if the activity is exiting.
-
getDynamicEnterTransition
Description copied from interface:DynamicTransitionListener
Returns the enter transition used by his listener.- Specified by:
getDynamicEnterTransition
in interfaceDynamicTransitionListener
- Returns:
- The enter transition used by his listener.
- See Also:
-
getDynamicReturnTransition
Description copied from interface:DynamicTransitionListener
Returns the return transition used by his listener.- Specified by:
getDynamicReturnTransition
in interfaceDynamicTransitionListener
- Returns:
- The return transition transition used by his listener.
- See Also:
-
getDynamicExitTransition
Description copied from interface:DynamicTransitionListener
Returns the exit transition used by his listener.- Specified by:
getDynamicExitTransition
in interfaceDynamicTransitionListener
- Returns:
- The exit transition used by his listener.
- See Also:
-
getDynamicReenterTransition
Description copied from interface:DynamicTransitionListener
Returns the reenter transition used by his listener.- Specified by:
getDynamicReenterTransition
in interfaceDynamicTransitionListener
- Returns:
- The reenter transition used by his listener.
- See Also:
-
onAdjustEnterReturnTransition
Description copied from interface:DynamicTransitionListener
This method will be called to optionally to adjust the enter and return transitions before applying.- Specified by:
onAdjustEnterReturnTransition
in interfaceDynamicTransitionListener
- Parameters:
transition
- The transition to be adjusted.enter
-true
if enter transition, otherwise return transition.- Returns:
- The adjusted enter or return transition before applying.
- See Also:
-
onAdjustExitReenterTransition
Description copied from interface:DynamicTransitionListener
This method will be called to optionally to adjust the exit and reenter transitions before applying.- Specified by:
onAdjustExitReenterTransition
in interfaceDynamicTransitionListener
- Parameters:
transition
- The transition to be adjusted.exit
-true
if exit transition, otherwise reenter transition.- Returns:
- The adjusted exit or reenter transition before applying.
- See Also:
-
getPostponeTransitionView
Description copied from interface:DynamicTransitionListener
This 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:
getPostponeTransitionView
in 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:DynamicTransitionListener
This 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:
onFindView
in 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:DynamicSearchListener
This method will be called when the search view is expanded.- Specified by:
onSearchViewExpanded
in interfaceDynamicSearchListener
-
onSearchViewCollapsed
public void onSearchViewCollapsed()Description copied from interface:DynamicSearchListener
This method will be called when the search view is collapsed.- Specified by:
onSearchViewCollapsed
in interfaceDynamicSearchListener
-
getTextWatcher
Description copied from interface:DynamicSearchListener
This method will be called to get the text watcher for the search view.- Specified by:
getTextWatcher
in interfaceDynamicSearchListener
- Returns:
- The text watcher for the search view.
-
startMotionActivity
CallActivity.startActivity(Intent, Bundle)
from the fragment's containing Activity.It will allow
Bundle
options 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
Bundle
options 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:
true
to register aDynamicSearchListener
to listen the search view expand and collapse callbacks for theDynamicActivity
.
-
isEnableMenu
public boolean isEnableMenu()Returns whether to enable the menu for this fragment.- Returns:
true
to 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:
true
if set the options menu for this fragment.- See Also:
-
isForceMenuIcons
public boolean isForceMenuIcons()Returns whether to force menu icons for this fragment.- Returns:
true
if force menu icons for this fragment.- See Also:
-
isHasMenuProvider
protected boolean isHasMenuProvider()Returns whether to use a menu provider for this fragment.- Returns:
true
if 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:
onPrepareMenu
in interfaceMenuProvider
-
onCreateMenu
- Specified by:
onCreateMenu
in interfaceMenuProvider
-
onMenuItemSelected
- Specified by:
onMenuItemSelected
in interfaceMenuProvider
-
onMenuClosed
- Specified by:
onMenuClosed
in interfaceMenuProvider
-
setMenuVisibility
public void setMenuVisibility(boolean menuVisible) - Overrides:
setMenuVisibility
in classFragment
-
onStart
public void onStart() -
onResume
public void onResume() -
onPause
public void onPause() -
onDestroy
public void onDestroy() -
onDynamicResume
Description copied from interface:DynamicLifecycle
This method will be called when the dynamic resume event occurs like resuming aFragment
when it is visible to the user inside aViewPager
.- Specified by:
onDynamicResume
in interfaceDynamicLifecycle
- Parameters:
forced
-true
if called explicitly.
-
onDynamicPause
Description copied from interface:DynamicLifecycle
This method will be called when the dynamic pause event occurs like pausing aFragment
when it goes off screen inside aViewPager
.- Specified by:
onDynamicPause
in interfaceDynamicLifecycle
- Parameters:
forced
-true
if called explicitly.
-
onSaveInstanceState
- Overrides:
onSaveInstanceState
in classFragment
-
getProductFlavor
- Specified by:
getProductFlavor
in 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:
true
if the parent activity is anAppCompatActivity
.
-
isSupportActionBar
public boolean isSupportActionBar()Checks whether the support action bar is applied to the parent activity.- Returns:
true
if 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
-true
to 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
-true
to 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
-true
to make the menu item visible.
-