Class DynamicDialogFragment
java.lang.Object
androidx.fragment.app.Fragment
androidx.fragment.app.DialogFragment
androidx.appcompat.app.AppCompatDialogFragment
com.pranavpandey.android.dynamic.support.dialog.fragment.DynamicDialogFragment
- All Implemented Interfaces:
ComponentCallbacks
,DialogInterface.OnCancelListener
,DialogInterface.OnDismissListener
,SharedPreferences.OnSharedPreferenceChangeListener
,View.OnCreateContextMenuListener
,ActivityResultCaller
,HasDefaultViewModelProviderFactory
,LifecycleOwner
,ViewModelStoreOwner
,androidx.savedstate.SavedStateRegistryOwner
,DynamicProductFlavor
- Direct Known Subclasses:
DynamicColorDialog
,DynamicProgressDialog
,DynamicRenameDialog
,DynamicSliderDialog
,DynamicThemeDialog
public class DynamicDialogFragment
extends AppCompatDialogFragment
implements DynamicProductFlavor, SharedPreferences.OnSharedPreferenceChangeListener
Base dialog fragment to provide all the functionality of
DynamicDialog
inside a
fragment. It can be extended to customise it further by overriding the supported methods.-
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.DialogFragment
STYLE_NO_FRAME, STYLE_NO_INPUT, STYLE_NO_TITLE, STYLE_NORMAL
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 DynamicDialog.Builder
The dynamic dialog builder set for this fragment.int
Get the button color set for the dialog.Returns the dialog shown by this fragment.int
Returns the layout resource for this dialog.Get the negative button text set for the dialog.Get the neutral button text set for the dialog.protected DialogInterface.OnCancelListener
Get the on cancel listener set for the dialog.protected DialogInterface.OnDismissListener
Get the on dismiss listener set for the dialog.protected DialogInterface.OnKeyListener
Get the on key listener set for the dialog.protected DialogInterface.OnShowListener
Get the on show listener set for the dialog.<T extends Parcelable>
TRetrieves a parcelable from the fragment arguments associated with the supplied key.Get the positive button text set for the dialog.Retrieves a string from the fragment arguments associated with the supplied key.protected boolean
Returns whether the dialog is auto dismissible.boolean
Returns whether this dialog is cancelable.boolean
Returns whether to register a shared preferences listener for this fragment.static DynamicDialogFragment
Initialize the new instance of this fragment.void
onCancel
(DialogInterface dialog) void
onCreateDialog
(Bundle savedInstanceState) protected DynamicDialog.Builder
onCustomiseBuilder
(DynamicDialog.Builder dialogBuilder, Bundle savedInstanceState) Override this method to customise the dynamic dialog builder before creating the dialog.protected void
onCustomiseDialog
(DynamicDialog alertDialog, View view, Bundle savedInstanceState) Override this method to customise the dynamic dialog before attaching it with this fragment.void
void
onDismiss
(DialogInterface dialog) void
onPause()
void
onResume()
void
onSharedPreferenceChanged
(SharedPreferences sharedPreferences, String key) setAutoDismiss
(boolean autoDismiss) Control whether the dialog is auto dismissible.setBuilder
(DynamicDialog.Builder dynamicAlertDialogBuilder) Sets a dynamic dialog builder for this dialog fragment.setButtonColor
(int buttonColor) Set the button color for the dialog.setIsCancelable
(boolean cancelable) Control whether the dialog is cancelable.Set the negative button text set for the dialog.Set the neutral button text set for the dialog.setOnCancelListener
(DialogInterface.OnCancelListener onCancelListener) Set an on cancel listener for the dialog.setOnDismissListener
(DialogInterface.OnDismissListener onDismissListener) Set an on dismiss listener for the dialog.setOnKeyListener
(DialogInterface.OnKeyListener onKeyListener) Set an on key listener for the dialog.setOnShowListener
(DialogInterface.OnShowListener onShowListener) Set an show listener for the dialog.Set the positive button text set for the dialog.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
showDialog
(FragmentActivity fragmentActivity) Show this dialog fragment and attach it to the supplied activity.void
showDialog
(FragmentActivity fragmentActivity, String tag) Show this dialog fragment and attach it to the supplied activity.Methods inherited from class androidx.appcompat.app.AppCompatDialogFragment
setupDialog
Methods inherited from class androidx.fragment.app.DialogFragment
dismiss, dismissAllowingStateLoss, dismissNow, getDialog, getShowsDialog, getTheme, onActivityCreated, onAttach, onDetach, onGetLayoutInflater, onSaveInstanceState, onStart, onStop, onViewStateRestored, requireComponentDialog, requireDialog, setCancelable, setShowsDialog, setStyle, show, show, showNow
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, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onViewCreated, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
-
Field Details
-
ADS_DEFAULT_BUTTON_COLOR
public static final int ADS_DEFAULT_BUTTON_COLORDefault button color. it will be used internally if there is no button color is applied.- See Also:
-
-
Constructor Details
-
DynamicDialogFragment
public DynamicDialogFragment()
-
-
Method Details
-
newInstance
Initialize the new instance of this fragment.- Returns:
- An instance of
DynamicDialogFragment
.
-
onCreate
- Overrides:
onCreate
in classDialogFragment
-
onCreateDialog
- Overrides:
onCreateDialog
in classAppCompatDialogFragment
-
getLayoutRes
Returns the layout resource for this dialog.- Returns:
- The layout resource for this dialog.
-
getProductFlavor
- Specified by:
getProductFlavor
in interfaceDynamicProductFlavor
-
onResume
public void onResume() -
onPause
public void onPause() -
onDismiss
- Specified by:
onDismiss
in interfaceDialogInterface.OnDismissListener
- Overrides:
onDismiss
in classDialogFragment
-
onCancel
- Specified by:
onCancel
in interfaceDialogInterface.OnCancelListener
- Overrides:
onCancel
in classDialogFragment
-
onDestroyView
public void onDestroyView()- Overrides:
onDestroyView
in classDialogFragment
-
getButtonColor
Get the button color set for the dialog.- Returns:
- The button color set for the dialog.
-
setButtonColor
Set the button color for the dialog.- Parameters:
buttonColor
- The button color to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getPositiveButtonText
Get the positive button text set for the dialog.- Returns:
- The positive button text set for the dialog.
-
setPositiveButtonText
Set the positive button text set for the dialog.- Parameters:
text
- The positive button text to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getNegativeButtonText
Get the negative button text set for the dialog.- Returns:
- The negative button text set for the dialog.
-
setNegativeButtonText
Set the negative button text set for the dialog.- Parameters:
text
- The negative button text to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getNeutralButtonText
Get the neutral button text set for the dialog.- Returns:
- The neutral button text set for the dialog.
-
setNeutralButtonText
Set the neutral button text set for the dialog.- Parameters:
text
- The neutral button text to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
isCancelable
public boolean isCancelable()Returns whether this dialog is cancelable.- Overrides:
isCancelable
in classDialogFragment
- Returns:
true
to make the dialog cancelable.The default value is
true
.
-
setIsCancelable
Control whether the dialog is cancelable.- Parameters:
cancelable
-true
to make the dialog cancelable.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
isAutoDismiss
protected boolean isAutoDismiss()Returns whether the dialog is auto dismissible.- Returns:
true
to dismiss the dialog in pause state.The default value is
false
.
-
setAutoDismiss
Control whether the dialog is auto dismissible.- Parameters:
autoDismiss
-true
to dismiss the dialog in pause state.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getBuilder
The dynamic dialog builder set for this fragment.- Returns:
- The dialog builder to customise this fragment according to the requirements.
-
getOnShowListener
Get the on show listener set for the dialog.- Returns:
- The callback when this dialog fragment is displayed.
-
setOnShowListener
@NonNull public DynamicDialogFragment setOnShowListener(@Nullable DialogInterface.OnShowListener onShowListener) Set an show listener for the dialog.- Parameters:
onShowListener
- The on show listener to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getOnDismissListener
Get the on dismiss listener set for the dialog.- Returns:
- The callback when this dialog fragment has been dismissed.
-
setOnDismissListener
@NonNull public DynamicDialogFragment setOnDismissListener(@Nullable DialogInterface.OnDismissListener onDismissListener) Set an on dismiss listener for the dialog.- Parameters:
onDismissListener
- The on dismiss listener to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getOnCancelListener
Get the on cancel listener set for the dialog.- Returns:
- The callback when this dialog fragment has been cancelled.
-
setOnCancelListener
@NonNull public DynamicDialogFragment setOnCancelListener(@Nullable DialogInterface.OnCancelListener onCancelListener) Set an on cancel listener for the dialog.- Parameters:
onCancelListener
- The on cancel listener to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
getOnKeyListener
Get the on key listener set for the dialog.- Returns:
- The callback when a key is pressed in this dialog fragment.
-
setOnKeyListener
@NonNull public DynamicDialogFragment setOnKeyListener(@Nullable DialogInterface.OnKeyListener onKeyListener) Set an on key listener for the dialog.- Parameters:
onKeyListener
- The on key listener to be set.- Returns:
- The
DynamicDialogFragment
object to allow for chaining of calls to set methods.
-
showDialog
Show this dialog fragment and attach it to the supplied activity.- Parameters:
fragmentActivity
- The fragment activity to attach this dialog fragment.tag
- The tag for this fragment.
-
showDialog
Show this dialog fragment and attach it to the supplied activity.- Parameters:
fragmentActivity
- The fragment activity to attach this dialog fragment.
-
getDynamicDialog
Returns the dialog shown by this fragment.- Returns:
- The
DynamicDialog
shown by this fragment.
-
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.- Returns:
- The string 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()
.
-