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
FieldsFields inherited from class androidx.fragment.app.DialogFragment
STYLE_NO_FRAME, STYLE_NO_INPUT, STYLE_NO_TITLE, STYLE_NORMALFields 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 DynamicDialog.BuilderThe dynamic dialog builder set for this fragment.intGet the button color set for the dialog.Returns the dialog shown by this fragment.intReturns 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.OnCancelListenerGet the on cancel listener set for the dialog.protected DialogInterface.OnDismissListenerGet the on dismiss listener set for the dialog.protected DialogInterface.OnKeyListenerGet the on key listener set for the dialog.protected DialogInterface.OnShowListenerGet 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 booleanReturns whether the dialog is auto dismissible.booleanReturns whether this dialog is cancelable.booleanReturns whether to register a shared preferences listener for this fragment.static DynamicDialogFragmentInitialize the new instance of this fragment.voidonCancel(DialogInterface dialog) voidonCreateDialog(Bundle savedInstanceState) protected DynamicDialog.BuilderonCustomiseBuilder(DynamicDialog.Builder dialogBuilder, Bundle savedInstanceState) Override this method to customise the dynamic dialog builder before creating the dialog.protected voidonCustomiseDialog(DynamicDialog alertDialog, View view, Bundle savedInstanceState) Override this method to customise the dynamic dialog before attaching it with this fragment.voidvoidonDismiss(DialogInterface dialog) voidonPause()voidonResume()voidonSharedPreferenceChanged(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 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.voidshowDialog(FragmentActivity fragmentActivity) Show this dialog fragment and attach it to the supplied activity.voidshowDialog(FragmentActivity fragmentActivity, String tag) Show this dialog fragment and attach it to the supplied activity.Methods inherited from class androidx.appcompat.app.AppCompatDialogFragment
setupDialogMethods 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, showNowMethods 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:
onCreatein classDialogFragment
-
onCreateDialog
- Overrides:
onCreateDialogin classAppCompatDialogFragment
-
getLayoutRes
Returns the layout resource for this dialog.- Returns:
- The layout resource for this dialog.
-
getProductFlavor
- Specified by:
getProductFlavorin interfaceDynamicProductFlavor
-
onResume
public void onResume() -
onPause
public void onPause() -
onDismiss
- Specified by:
onDismissin interfaceDialogInterface.OnDismissListener- Overrides:
onDismissin classDialogFragment
-
onCancel
- Specified by:
onCancelin interfaceDialogInterface.OnCancelListener- Overrides:
onCancelin classDialogFragment
-
onDestroyView
public void onDestroyView()- Overrides:
onDestroyViewin 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
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject to allow for chaining of calls to set methods.
-
isCancelable
public boolean isCancelable()Returns whether this dialog is cancelable.- Overrides:
isCancelablein classDialogFragment- Returns:
trueto make the dialog cancelable.The default value is
true.
-
setIsCancelable
Control whether the dialog is cancelable.- Parameters:
cancelable-trueto make the dialog cancelable.- Returns:
- The
DynamicDialogFragmentobject to allow for chaining of calls to set methods.
-
isAutoDismiss
protected boolean isAutoDismiss()Returns whether the dialog is auto dismissible.- Returns:
trueto dismiss the dialog in pause state.The default value is
false.
-
setAutoDismiss
Control whether the dialog is auto dismissible.- Parameters:
autoDismiss-trueto dismiss the dialog in pause state.- Returns:
- The
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject 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
DynamicDialogFragmentobject 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
DynamicDialogshown 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-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().
-