Package eltos.simpledialogfragment
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/interfaces inherited from class androidx.fragment.app.Fragment
androidx.fragment.app.Fragment.InstantiationException, androidx.fragment.app.Fragment.SavedState
-
Field Summary
Modifier and TypeFieldDescriptionprotected 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
-
Method Summary
Modifier and TypeMethodDescriptionstatic SimpleDialog
build()
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
getArgs()
null-save method to get argumentsprotected final CharSequence
getArgString
(String key) android.content.Context
android.os.Bundle
Gets the extras bundle providedGets the string representation of the message setgetTitle()
Gets the string representation of the title seticon
(int iconResourceId) Sets this dialogs iconboolean
Return whether the dialog was set to be cancelable or notmsg
(int messageResourceId) Sets this dialogs messagemsg
(CharSequence message) Sets this dialogs messagemsgHtml
(int messageResourceId) Sets this dialogs message as html styled stringSets this dialogs message as html styled stringneg()
Sets this dialogs negative button text toR.string.no
neg
(int negativeButtonResourceId) Sets this dialogs negative button textneg
(CharSequence negativeButton) Sets this dialogs negative button textneut()
Sets this dialogs neutral button text toR.string.cancel
neut
(int neutralButtonResourceId) Sets this dialogs neutral button textneut
(CharSequence neutralButton) Sets this dialogs neutral button textvoid
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 textpos
(CharSequence positiveButton) Sets this dialogs positive button textprotected final This
protected final This
protected final This
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 shownprotected 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 shownvoid
show
(androidx.fragment.app.Fragment fragment) Shows the dialog.void
show
(androidx.fragment.app.FragmentActivity activity) Shows the dialog.void
Shows the dialog.void
Shows the dialog.void
Deprecated.void
Shows the dialog.void
Shows the dialog.int
Deprecated.void
showKeyboard
(android.view.View view) Helper for opening the soft keyboard on a specified viewtheme
(int theme) Set a custom theme.title
(int titleResourceId) Sets this dialogs titletitle
(CharSequence title) Sets this dialogs titleMethods 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
-
TAG
- See Also:
-
TITLE
- See Also:
-
MESSAGE
- See Also:
-
POSITIVE_BUTTON_TEXT
- See Also:
-
NEGATIVE_BUTTON_TEXT
- See Also:
-
NEUTRAL_BUTTON_TEXT
- See Also:
-
ICON_RESOURCE
- See Also:
-
CANCELABLE
- See Also:
-
FULLSCREEN
- See Also:
-
THEME
- See Also:
-
HTML
- See Also:
-
BUNDLE
- See Also:
-
-
Constructor Details
-
SimpleDialog
public SimpleDialog()
-
-
Method Details
-
build
-
callResultListener
@CallSuper protected boolean callResultListener(int which, @Nullable android.os.Bundle extras) -
setArg
-
setArg
-
setArg
-
setArg
-
getArgString
-
getArgs
@NonNull protected final android.os.Bundle getArgs()null-save method to get arguments- Returns:
- dialog arguments bundle
-
title
Sets this dialogs title- Parameters:
title
- the title as string- Returns:
- this instance
-
title
Sets this dialogs title- Parameters:
titleResourceId
- the title as android string resource- Returns:
- this instance
-
getTitle
Gets the string representation of the title set- Returns:
- the dialog title
-
msg
Sets this dialogs message- Parameters:
message
- title as string- Returns:
- this instance
-
msg
Sets this dialogs message- Parameters:
messageResourceId
- the message as android string resource- Returns:
- this instance
-
msgHtml
Sets this dialogs message as html styled string- Parameters:
message
- title as html-string- Returns:
- this instance
-
msgHtml
Sets this dialogs message as html styled string- Parameters:
messageResourceId
- the message as html-styled android string resource- Returns:
- this instance
-
getMessage
Gets the string representation of the message set- Returns:
- the dialog message
-
pos
Sets this dialogs positive button text- Parameters:
positiveButton
- the text as string- Returns:
- this instance
-
pos
Sets this dialogs positive button text- Parameters:
positiveButtonResourceId
- the text as android string resource- Returns:
- this instance
-
neg
Sets this dialogs negative button text- Parameters:
negativeButton
- the text as string- Returns:
- this instance
-
neg
Sets this dialogs negative button text- Parameters:
negativeButtonResourceId
- the text as android string resource- Returns:
- this instance
-
neg
Sets this dialogs negative button text toR.string.no
- Returns:
- this instance
-
neut
Sets this dialogs neutral button text- Parameters:
neutralButton
- the text as string- Returns:
- this instance
-
neut
Sets this dialogs neutral button text- Parameters:
neutralButtonResourceId
- the text as android string resource- Returns:
- this instance
-
neut
Sets this dialogs neutral button text toR.string.cancel
- Returns:
- this instance
-
icon
Sets this dialogs icon- Parameters:
iconResourceId
- the icon as android drawable resource- Returns:
- this instance
-
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 classandroidx.fragment.app.DialogFragment
- Returns:
- whether the dialog is cancelable
-
fullscreen
Specifies whether this dialog is shown as fullscreen or basic dialog.- Parameters:
fullscreen
- whether this dialog is fullscreen- Returns:
- this instance
-
fullscreen
Set that this dialog is shown as fullscreen dialog.- Returns:
- this instance
-
extra
Pass extras to the dialog to retain specific information across configuration changes. All extras supplied here will be contained in the extras bundle passed toSimpleDialog.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
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. TheSimpleDialog.OnDialogResultListener
won't be called.- Parameters:
fragment
- the hosting fragment
-
show
Shows the dialog. Results will be forwarded to the fragment supplied. The tag can be used to identify the dialog inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Parameters:
fragment
- the hosting fragmenttag
- the dialogs tag
-
show
Shows the dialog. Results will be forwarded to the fragment supplied. The tag can be used to identify the dialog inSimpleDialog.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 fragmenttag
- the dialogs tagreplaceTag
- removes the dialog with the given tag if specified
-
show
public void show(androidx.fragment.app.FragmentActivity activity) Shows the dialog. TheSimpleDialog.OnDialogResultListener
won't be called.- Parameters:
activity
- the hosting activity
-
show
Shows the dialog. Results will be forwarded to the activity supplied. The tag can be used to identify the dialog inSimpleDialog.OnDialogResultListener.onResult(java.lang.String, int, android.os.Bundle)
- Parameters:
activity
- the hosting activitytag
- the dialogs tag
-
show
Shows the dialog. Results will be forwarded to the activity supplied. The tag can be used to identify the dialog inSimpleDialog.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 activitytag
- the dialogs tagreplaceTag
- removes the dialog with the given tag if specified
-
onCreate
@CallSuper public void onCreate(android.os.Bundle savedInstanceState) - Overrides:
onCreate
in classandroidx.fragment.app.DialogFragment
-
getContext
public android.content.Context getContext()- Overrides:
getContext
in classandroidx.fragment.app.Fragment
-
onCreateDialog
@NonNull public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) - Overrides:
onCreateDialog
in classandroidx.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.Deprecated, useshow(FragmentActivity)
orshow(Fragment)
instead- Overrides:
show
in classandroidx.fragment.app.DialogFragment
-
show
Deprecated.Deprecated, useshow(FragmentActivity, String)
orshow(Fragment, String)
instead- Overrides:
show
in classandroidx.fragment.app.DialogFragment
-
onCancel
@CallSuper public void onCancel(android.content.DialogInterface dialog) - Specified by:
onCancel
in interfaceandroid.content.DialogInterface.OnCancelListener
- Overrides:
onCancel
in classandroidx.fragment.app.DialogFragment
-
onDestroyView
@CallSuper public void onDestroyView()- Overrides:
onDestroyView
in classandroidx.fragment.app.DialogFragment
-