Class SimpleDialog<This extends SimpleDialog<This>>

java.lang.Object
androidx.fragment.app.Fragment
androidx.fragment.app.DialogFragment
eltos.simpledialogfragment.SimpleDialog<This>
All Implemented Interfaces:
android.content.ComponentCallbacks, android.content.DialogInterface.OnCancelListener, android.content.DialogInterface.OnDismissListener, android.view.View.OnCreateContextMenuListener, androidx.activity.result.ActivityResultCaller, androidx.lifecycle.HasDefaultViewModelProviderFactory, androidx.lifecycle.LifecycleOwner, androidx.lifecycle.ViewModelStoreOwner, androidx.savedstate.SavedStateRegistryOwner
Direct Known Subclasses:
CustomViewDialog

public class SimpleDialog<This extends SimpleDialog<This>> extends androidx.fragment.app.DialogFragment
An easy to use and extendable dialog fragment that displays a text message. This is the base class of all dialogs in this library. Created by eltos on 03.08.2015.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     

    Nested classes/interfaces inherited from class androidx.fragment.app.Fragment

    androidx.fragment.app.Fragment.InstantiationException, androidx.fragment.app.Fragment.SavedState
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    static final String
     
    protected static final String
     
    protected static final String
     

    Fields inherited from class androidx.fragment.app.DialogFragment

    STYLE_NO_FRAME, STYLE_NO_INPUT, STYLE_NO_TITLE, STYLE_NORMAL
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    protected boolean
    callResultListener(int which, android.os.Bundle extras)
     
    cancelable(boolean cancelable)
    Specifies whether this dialog may be canceled by pressing the back button or touching outside of the dialog.
    extra(android.os.Bundle extras)
    Pass extras to the dialog to retain specific information across configuration changes.
    Set that this dialog is shown as fullscreen dialog.
    fullscreen(boolean fullscreen)
    Specifies whether this dialog is shown as fullscreen or basic dialog.
    protected final android.os.Bundle
    null-save method to get arguments
    protected final CharSequence
     
    android.content.Context
     
    android.os.Bundle
    Gets the extras bundle provided
    Gets the string representation of the message set
    Gets the string representation of the title set
    icon(int iconResourceId)
    Sets this dialogs icon
    boolean
    Return whether the dialog was set to be cancelable or not
    msg(int messageResourceId)
    Sets this dialogs message
    msg(CharSequence message)
    Sets this dialogs message
    msgHtml(int messageResourceId)
    Sets this dialogs message as html styled string
    msgHtml(String message)
    Sets this dialogs message as html styled string
    neg()
    Sets this dialogs negative button text to R.string.no
    neg(int negativeButtonResourceId)
    Sets this dialogs negative button text
    neg(CharSequence negativeButton)
    Sets this dialogs negative button text
    Sets this dialogs neutral button text to R.string.cancel
    neut(int neutralButtonResourceId)
    Sets this dialogs neutral button text
    neut(CharSequence neutralButton)
    Sets this dialogs neutral button text
    void
    onCancel(android.content.DialogInterface dialog)
     
    void
    onCreate(android.os.Bundle savedInstanceState)
     
    android.app.Dialog
    onCreateDialog(android.os.Bundle savedInstanceState)
     
    void
     
    pos(int positiveButtonResourceId)
    Sets this dialogs positive button text
    pos(CharSequence positiveButton)
    Sets this dialogs positive button text
    protected final This
    setArg(String key, boolean value)
     
    protected final This
    setArg(String key, int value)
     
    protected final This
    setArg(String key, long value)
     
    protected final This
    setArg(String key, CharSequence value)
     
    protected void
    setButtonClickListener(int whichButton, android.view.View.OnClickListener listener)
    Call this method to overwrite the click listener for a button Note: This method has no effect if the dialog is not yet shown
    protected void
    setButtonEnabled(int whichButton, boolean enabled)
    Call this method to enable or disable a button Note: This method has no effect if the dialog is not yet shown
    void
    show(androidx.fragment.app.Fragment fragment)
    Shows the dialog.
    void
    show(androidx.fragment.app.FragmentActivity activity)
    Shows the dialog.
    void
    show(androidx.fragment.app.FragmentActivity activity, String tag)
    Shows the dialog.
    void
    show(androidx.fragment.app.FragmentActivity activity, String tag, String replaceTag)
    Shows the dialog.
    void
    show(androidx.fragment.app.FragmentManager manager, String tag)
    Deprecated.
    void
    show(androidx.fragment.app.Fragment fragment, String tag)
    Shows the dialog.
    void
    show(androidx.fragment.app.Fragment fragment, String tag, String replaceTag)
    Shows the dialog.
    int
    show(androidx.fragment.app.FragmentTransaction transaction, String tag)
    Deprecated.
    void
    showKeyboard(android.view.View view)
    Helper for opening the soft keyboard on a specified view
    theme(int theme)
    Set a custom theme.
    title(int titleResourceId)
    Sets this dialogs title
    Sets this dialogs title

    Methods inherited from class androidx.fragment.app.DialogFragment

    dismiss, dismissAllowingStateLoss, getDialog, getShowsDialog, getTheme, onAttach, onDetach, onDismiss, onGetLayoutInflater, onSaveInstanceState, onStart, onStop, onViewStateRestored, requireDialog, setCancelable, setShowsDialog, setStyle, setupDialog, showNow

    Methods inherited from class androidx.fragment.app.Fragment

    dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, 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, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, 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

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface androidx.lifecycle.HasDefaultViewModelProviderFactory

    getDefaultViewModelCreationExtras
  • Field Details

  • Constructor Details

    • SimpleDialog

      public SimpleDialog()
  • Method Details

    • build

      public static SimpleDialog build()
    • callResultListener

      @CallSuper protected boolean callResultListener(int which, @Nullable android.os.Bundle extras)
    • setArg

      protected final This setArg(String key, boolean value)
    • setArg

      protected final This setArg(String key, CharSequence value)
    • setArg

      protected final This setArg(String key, int value)
    • setArg

      protected final This setArg(String key, long value)
    • getArgString

      @Nullable protected final CharSequence getArgString(String key)
    • getArgs

      @NonNull protected final android.os.Bundle getArgs()
      null-save method to get arguments
      Returns:
      dialog arguments bundle
    • title

      public This title(CharSequence title)
      Sets this dialogs title
      Parameters:
      title - the title as string
      Returns:
      this instance
    • title

      public This title(@StringRes int titleResourceId)
      Sets this dialogs title
      Parameters:
      titleResourceId - the title as android string resource
      Returns:
      this instance
    • getTitle

      @Nullable public CharSequence getTitle()
      Gets the string representation of the title set
      Returns:
      the dialog title
    • msg

      public This msg(CharSequence message)
      Sets this dialogs message
      Parameters:
      message - title as string
      Returns:
      this instance
    • msg

      public This msg(@StringRes int messageResourceId)
      Sets this dialogs message
      Parameters:
      messageResourceId - the message as android string resource
      Returns:
      this instance
    • msgHtml

      public This msgHtml(String message)
      Sets this dialogs message as html styled string
      Parameters:
      message - title as html-string
      Returns:
      this instance
    • msgHtml

      public This msgHtml(@StringRes int messageResourceId)
      Sets this dialogs message as html styled string
      Parameters:
      messageResourceId - the message as html-styled android string resource
      Returns:
      this instance
    • getMessage

      @Nullable public CharSequence getMessage()
      Gets the string representation of the message set
      Returns:
      the dialog message
    • pos

      public This pos(CharSequence positiveButton)
      Sets this dialogs positive button text
      Parameters:
      positiveButton - the text as string
      Returns:
      this instance
    • pos

      public This pos(@StringRes int positiveButtonResourceId)
      Sets this dialogs positive button text
      Parameters:
      positiveButtonResourceId - the text as android string resource
      Returns:
      this instance
    • neg

      public This neg(CharSequence negativeButton)
      Sets this dialogs negative button text
      Parameters:
      negativeButton - the text as string
      Returns:
      this instance
    • neg

      public This neg(@StringRes int negativeButtonResourceId)
      Sets this dialogs negative button text
      Parameters:
      negativeButtonResourceId - the text as android string resource
      Returns:
      this instance
    • neg

      public This neg()
      Sets this dialogs negative button text to R.string.no
      Returns:
      this instance
    • neut

      public This neut(CharSequence neutralButton)
      Sets this dialogs neutral button text
      Parameters:
      neutralButton - the text as string
      Returns:
      this instance
    • neut

      public This neut(@StringRes int neutralButtonResourceId)
      Sets this dialogs neutral button text
      Parameters:
      neutralButtonResourceId - the text as android string resource
      Returns:
      this instance
    • neut

      public This neut()
      Sets this dialogs neutral button text to R.string.cancel
      Returns:
      this instance
    • icon

      public This icon(@DrawableRes int iconResourceId)
      Sets this dialogs icon
      Parameters:
      iconResourceId - the icon as android drawable resource
      Returns:
      this instance
    • cancelable

      public This cancelable(boolean cancelable)
      Specifies whether this dialog may be canceled by pressing the back button or touching outside of the dialog. The dialog may still be "canceled" by a neutral button.
      Parameters:
      cancelable - whether this dialog may be canceled
      Returns:
      this instance
    • isCancelable

      public boolean isCancelable()
      Return whether the dialog was set to be cancelable or not
      Overrides:
      isCancelable in class androidx.fragment.app.DialogFragment
      Returns:
      whether the dialog is cancelable
    • fullscreen

      public This fullscreen(boolean fullscreen)
      Specifies whether this dialog is shown as fullscreen or basic dialog.
      Parameters:
      fullscreen - whether this dialog is fullscreen
      Returns:
      this instance
    • fullscreen

      public This fullscreen()
      Set that this dialog is shown as fullscreen dialog.
      Returns:
      this instance
    • extra

      public This extra(android.os.Bundle extras)
      Pass extras to the dialog to retain specific information across configuration changes. All extras supplied here will be contained in the extras bundle passed to SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Parameters:
      extras - a bundle of extras to store
      Returns:
      this instance
    • getExtras

      @NonNull public android.os.Bundle getExtras()
      Gets the extras bundle provided
      Returns:
      the extras bundle (which may be empty)
    • theme

      public This theme(@StyleRes int theme)
      Set a custom theme. Default is using the theme defined by the 'simpleDialogTheme'-attribute or the 'alertDialogTheme'-attribute.
      Parameters:
      theme - the android style resource id of the custom theme
      Returns:
      this instance
    • show

      public void show(androidx.fragment.app.Fragment fragment)
      Shows the dialog. The SimpleDialog.OnDialogResultListener won't be called.
      Parameters:
      fragment - the hosting fragment
    • show

      public void show(androidx.fragment.app.Fragment fragment, String tag)
      Shows the dialog. Results will be forwarded to the fragment supplied. The tag can be used to identify the dialog in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Parameters:
      fragment - the hosting fragment
      tag - the dialogs tag
    • show

      public void show(androidx.fragment.app.Fragment fragment, String tag, String replaceTag)
      Shows the dialog. Results will be forwarded to the fragment supplied. The tag can be used to identify the dialog in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle) An optional argument can be used to remove a previously shown dialog with the tag given prior to showing this one.
      Parameters:
      fragment - the hosting fragment
      tag - the dialogs tag
      replaceTag - removes the dialog with the given tag if specified
    • show

      public void show(androidx.fragment.app.FragmentActivity activity)
      Shows the dialog. The SimpleDialog.OnDialogResultListener won't be called.
      Parameters:
      activity - the hosting activity
    • show

      public void show(androidx.fragment.app.FragmentActivity activity, String tag)
      Shows the dialog. Results will be forwarded to the activity supplied. The tag can be used to identify the dialog in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
      Parameters:
      activity - the hosting activity
      tag - the dialogs tag
    • show

      public void show(androidx.fragment.app.FragmentActivity activity, String tag, String replaceTag)
      Shows the dialog. Results will be forwarded to the activity supplied. The tag can be used to identify the dialog in SimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle) An optional argument can be used to remove a previously shown dialog with the tag given prior to showing this one.
      Parameters:
      activity - the hosting activity
      tag - the dialogs tag
      replaceTag - removes the dialog with the given tag if specified
    • onCreate

      @CallSuper public void onCreate(android.os.Bundle savedInstanceState)
      Overrides:
      onCreate in class androidx.fragment.app.DialogFragment
    • getContext

      public android.content.Context getContext()
      Overrides:
      getContext in class androidx.fragment.app.Fragment
    • onCreateDialog

      @NonNull public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState)
      Overrides:
      onCreateDialog in class androidx.fragment.app.DialogFragment
    • setButtonEnabled

      protected void setButtonEnabled(int whichButton, boolean enabled)
      Call this method to enable or disable a button Note: This method has no effect if the dialog is not yet shown
      Parameters:
      enabled - whether to en- or disable the button
    • setButtonClickListener

      protected void setButtonClickListener(int whichButton, android.view.View.OnClickListener listener)
      Call this method to overwrite the click listener for a button Note: This method has no effect if the dialog is not yet shown
      Parameters:
      listener - the click listener
    • showKeyboard

      public void showKeyboard(android.view.View view)
      Helper for opening the soft keyboard on a specified view
      Parameters:
      view - the view to be focused and receive keyboard input
    • show

      @Deprecated public void show(androidx.fragment.app.FragmentManager manager, String tag)
      Deprecated.
      Deprecated, use show(FragmentActivity) or show(Fragment) instead
      Overrides:
      show in class androidx.fragment.app.DialogFragment
    • show

      @Deprecated public int show(androidx.fragment.app.FragmentTransaction transaction, String tag)
      Deprecated.
      Overrides:
      show in class androidx.fragment.app.DialogFragment
    • onCancel

      @CallSuper public void onCancel(android.content.DialogInterface dialog)
      Specified by:
      onCancel in interface android.content.DialogInterface.OnCancelListener
      Overrides:
      onCancel in class androidx.fragment.app.DialogFragment
    • onDestroyView

      @CallSuper public void onDestroyView()
      Overrides:
      onDestroyView in class androidx.fragment.app.DialogFragment