Class 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

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.
See Also:
  • Field Details

    • ADS_DEFAULT_BUTTON_COLOR

      public static final int ADS_DEFAULT_BUTTON_COLOR
      Default 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

      @NonNull public static DynamicDialogFragment newInstance()
      Initialize the new instance of this fragment.
      Returns:
      An instance of DynamicDialogFragment.
    • onCreate

      public void onCreate(@Nullable Bundle savedInstanceState)
      Overrides:
      onCreate in class DialogFragment
    • onCreateDialog

      @NonNull public Dialog onCreateDialog(@Nullable Bundle savedInstanceState)
      Overrides:
      onCreateDialog in class AppCompatDialogFragment
    • getLayoutRes

      @LayoutRes public int getLayoutRes()
      Returns the layout resource for this dialog.
      Returns:
      The layout resource for this dialog.
    • onCustomiseBuilder

      @NonNull protected DynamicDialog.Builder onCustomiseBuilder(@NonNull DynamicDialog.Builder dialogBuilder, @Nullable Bundle savedInstanceState)
      Override this method to customise the dynamic dialog builder before creating the dialog.
      Parameters:
      dialogBuilder - The current builder to be customised.
      savedInstanceState - The saved state of the fragment to restore it later.
      Returns:
      The customised dynamic dialog builder.
    • onCustomiseDialog

      protected void onCustomiseDialog(@NonNull DynamicDialog alertDialog, @Nullable View view, @Nullable Bundle savedInstanceState)
      Override this method to customise the dynamic dialog before attaching it with this fragment.
      Parameters:
      alertDialog - The current dialog to be customised.
      view - The view used by the dialog.
      savedInstanceState - The saved state of the fragment to restore it later.
    • getProductFlavor

      public String getProductFlavor()
      Specified by:
      getProductFlavor in interface DynamicProductFlavor
    • isOnSharedPreferenceChangeListener

      public boolean isOnSharedPreferenceChangeListener()
      Returns whether to register a shared preferences listener for this fragment.
      Returns:
      true to register a SharedPreferences.OnSharedPreferenceChangeListener to receive preference change callback.
    • onResume

      public void onResume()
      Overrides:
      onResume in class Fragment
    • onPause

      public void onPause()
      Overrides:
      onPause in class Fragment
    • onDismiss

      public void onDismiss(@NonNull DialogInterface dialog)
      Specified by:
      onDismiss in interface DialogInterface.OnDismissListener
      Overrides:
      onDismiss in class DialogFragment
    • onCancel

      public void onCancel(@NonNull DialogInterface dialog)
      Specified by:
      onCancel in interface DialogInterface.OnCancelListener
      Overrides:
      onCancel in class DialogFragment
    • onDestroyView

      public void onDestroyView()
      Overrides:
      onDestroyView in class DialogFragment
    • getButtonColor

      @ColorInt public int getButtonColor()
      Get the button color set for the dialog.
      Returns:
      The button color set for the dialog.
    • setButtonColor

      @NonNull public DynamicDialogFragment setButtonColor(@ColorInt int buttonColor)
      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

      @Nullable public CharSequence getPositiveButtonText()
      Get the positive button text set for the dialog.
      Returns:
      The positive button text set for the dialog.
    • setPositiveButtonText

      @NonNull public DynamicDialogFragment setPositiveButtonText(@Nullable CharSequence text)
      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

      @Nullable public CharSequence getNegativeButtonText()
      Get the negative button text set for the dialog.
      Returns:
      The negative button text set for the dialog.
    • setNegativeButtonText

      @NonNull public DynamicDialogFragment setNegativeButtonText(@Nullable CharSequence text)
      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

      @Nullable public CharSequence getNeutralButtonText()
      Get the neutral button text set for the dialog.
      Returns:
      The neutral button text set for the dialog.
    • setNeutralButtonText

      @NonNull public DynamicDialogFragment setNeutralButtonText(@Nullable CharSequence text)
      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 class DialogFragment
      Returns:
      true to make the dialog cancelable.

      The default value is true.

    • setIsCancelable

      @NonNull public DynamicDialogFragment setIsCancelable(boolean cancelable)
      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

      @NonNull public DynamicDialogFragment setAutoDismiss(boolean autoDismiss)
      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

      @Nullable protected DynamicDialog.Builder getBuilder()
      The dynamic dialog builder set for this fragment.
      Returns:
      The dialog builder to customise this fragment according to the requirements.
    • setBuilder

      @NonNull public DynamicDialogFragment setBuilder(@NonNull DynamicDialog.Builder dynamicAlertDialogBuilder)
      Sets a dynamic dialog builder for this dialog fragment.
      Parameters:
      dynamicAlertDialogBuilder - The dynamic dialog builder to be set.
      Returns:
      The DynamicDialogFragment object to allow for chaining of calls to set methods.
    • getOnShowListener

      @Nullable protected DialogInterface.OnShowListener 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

      @Nullable protected DialogInterface.OnDismissListener 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

      @Nullable protected DialogInterface.OnCancelListener 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

      @Nullable protected DialogInterface.OnKeyListener 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

      public void showDialog(@NonNull FragmentActivity fragmentActivity, @Nullable String tag)
      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

      public void showDialog(@NonNull FragmentActivity fragmentActivity)
      Show this dialog fragment and attach it to the supplied activity.
      Parameters:
      fragmentActivity - The fragment activity to attach this dialog fragment.
    • getDynamicDialog

      @Nullable public DynamicDialog getDynamicDialog()
      Returns the dialog shown by this fragment.
      Returns:
      The DynamicDialog shown by this fragment.
    • getParcelableFromArguments

      @Nullable public <T extends Parcelable> T getParcelableFromArguments(@Nullable String key)
      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

      @Nullable public String getStringFromArguments(@Nullable String key)
      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

      public boolean getBooleanFromArguments(@Nullable String key, boolean defaultValue)
      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

      protected void setResult(int resultCode, @Nullable Intent intent, boolean finish)
      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

      protected void setResult(int resultCode, @Nullable Intent intent)
      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 calling Activity.finish().
      See Also:
    • onSharedPreferenceChanged

      public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Nullable String key)
      Specified by:
      onSharedPreferenceChanged in interface SharedPreferences.OnSharedPreferenceChangeListener