I - A type of the BaseIntent implementation to allow proper methods chaining.public abstract class BaseIntent<I extends BaseIntent> extends Object
build(Context)
This method is called whenever startWith(IntentStarter) is invoked and a specific intent
builder implementation should build here an intent which is for that type of intent builder specific
and configure it with data supplied through its setters API.
onStartWith(IntentStarter, Intent)
It is not required to override this method. Default implementation of this method only starts
the intent obtained via build(Context) method via IntentStarter.startIntent(Intent).
If a specific intent builder implementation requires for example starting intent as activity for
result, than it should be done within this method.
enterTransition(int)
and exitTransition(int). These transitions will be used whenever onStartWith(IntentStarter, Intent)
is called using the intent starter's IntentStarter.overridePendingTransition(int, int).| Constructor and Description |
|---|
BaseIntent() |
| Modifier and Type | Method and Description |
|---|---|
CharSequence |
activityNotFoundMessage()
Returns the message text for the toast that is shown in case, when there wasn't found any
activity for the started intent.
|
I |
activityNotFoundMessage(CharSequence message)
Sets a message for the toast that is shown in case, when there wasn't found any activity that
would handle the started intent.
|
Intent |
build(Context context)
Called to create an instance of
Intent from the current data of this intent builder. |
protected IllegalArgumentException |
cannotBuildIntentException(String message)
Creates an instance of
IllegalArgumentException indicating that one of required parameters
for this intent builder has not been specified, but build(Context) has been invoked. |
CharSequence |
dialogTitle()
Returns the title text for the chooser dialog.
|
I |
dialogTitle(CharSequence title)
Sets a title for the chooser dialog.
|
protected void |
ensureCanBuildOrThrow()
Called to ensure that this builder can build its Intent from its current data.
|
int |
enterTransition()
Returns the window enter transition used to override window's pending transition.
|
I |
enterTransition(int transition)
Sets a window transition used to override default pending window enter transition when starting
this intent.
|
int |
exitTransition()
Returns the window exit transition used to override window's pending transition.
|
I |
exitTransition(int transition)
Sets a window transition used to override default pending window exit transition when starting
this intent.
|
static boolean |
isActivityForIntentAvailable(Context context,
Intent intent)
Checks whether there is any activity that can handle the specified intent available
on the current Android device.
|
protected void |
notifyActivityNotFound(Context context)
Notifies situation that there wasn't found any activity to handle the started intent.
|
protected abstract Intent |
onBuild(Context context)
Invoked from
build(Context) after ensureCanBuildOrThrow() to build intent
specific for this intent builder from the current data. |
protected boolean |
onStartWith(IntentStarter starter,
Intent intent)
Invoked whenever
startWith(IntentStarter) is called and there is an activity available
that can handle the given intent that has been created via build(Context). |
boolean |
startWith(IntentStarter starter)
Starts na intent specific for this intent builder created via
build(Context) using
the given intent starter. |
I |
transitions(int enterTransition,
int exitTransition)
Sets both, enter + exit, window transitions used to override default pending window transition
when starting this intent.
|
public I dialogTitle(@Nullable CharSequence title)
Default value: Choose
title - The desired dialog title text. May be null to clear the current one.dialogTitle()@NonNull public CharSequence dialogTitle()
public I activityNotFoundMessage(@Nullable CharSequence message)
message - The desired message text. May be null to clear the current one.activityNotFoundMessage()@NonNull public CharSequence activityNotFoundMessage()
activityNotFoundMessage(CharSequence)public I enterTransition(@AnimRes int transition)
See Activity.overridePendingTransition(int, int) for more info.
transition - Resource id of the desired window transition (animation).enterTransition()@AnimRes public int enterTransition()
0 if there was no transition specified.enterTransition(int)public I exitTransition(@AnimRes int transition)
See Activity.overridePendingTransition(int, int) for more info.
transition - Resource id of the desired window transition (animation).exitTransition()@AnimRes public int exitTransition()
0 if there was no transition specified.exitTransition(int)public I transitions(@AnimRes int enterTransition, @AnimRes int exitTransition)
enterTransition - Resource id of the desired window enter transition (animation).
May be 0 to not play any enter animation.exitTransition - Resource id of the desired window exit transition (animation).
May be 0 to not play any enter animation.enterTransition(int),
exitTransition(int)public boolean startWith(@NonNull IntentStarter starter)
build(Context) using
the given intent starter.starter - The desired starter to be used to start the intent. See IntentStarters
for default available starters.True if the intent has been successfully started, false otherwise.@NonNull public Intent build(@NonNull Context context)
Intent from the current data of this intent builder.context - Context obtained from the IntentStarter.IllegalArgumentException - If this builder does not have all required data to build the
requested intent.protected void ensureCanBuildOrThrow()
If there are some required data missing/not specified, an exception indicating such state
should be thrown. The default exception may be created via cannotBuildIntentException(String).
@NonNull protected abstract Intent onBuild(@NonNull Context context)
build(Context) after ensureCanBuildOrThrow() to build intent
specific for this intent builder from the current data.context - Context obtained from the IntentStarter.@CheckResult public static boolean isActivityForIntentAvailable(@NonNull Context context, @NonNull Intent intent)
context - Context used to obtain package manager.intent - The intent for which to resolve activity.True if activity for the intent has been resolved/found, false otherwise
which means that there is no activity currently installed on the current Android device that
could handle that intent.protected final IllegalArgumentException cannotBuildIntentException(@NonNull String message)
IllegalArgumentException indicating that one of required parameters
for this intent builder has not been specified, but build(Context) has been invoked.message - Message to be included into exception.protected boolean onStartWith(@NonNull IntentStarter starter, @NonNull Intent intent)
startWith(IntentStarter) is called and there is an activity available
that can handle the given intent that has been created via build(Context).
This implementation always returns true.
starter - The starter with which to start the intent.intent - The intent instance created by this intent builder.True to indicate that the intent has been started, false otherwise.protected void notifyActivityNotFound(@NonNull Context context)
This implementation by default shows a toast with the message specified via activityNotFoundMessage(CharSequence),
if any.
context - The context obtained from the IntentStarter.activityNotFoundMessage(CharSequence)