public class ActivityOptions extends Object
Context.startActivity(Intent, Bundle)
and related methods.Modifier and Type | Class and Description |
---|---|
static interface |
ActivityOptions.OnAnimationFinishedListener
Callback for use with
makeThumbnailAspectScaleDownAnimation(android.view.View, android.graphics.Bitmap, int, int, int, int, android.os.Handler, android.app.ActivityOptions.OnAnimationStartedListener)
to find out when the given animation has drawn its last frame. |
static interface |
ActivityOptions.OnAnimationStartedListener
Callback for use with
makeThumbnailScaleUpAnimation(android.view.View, android.graphics.Bitmap, int, int)
to find out when the given animation has started running. |
Modifier and Type | Field and Description |
---|---|
static int |
ANIM_CLIP_REVEAL |
static int |
ANIM_CUSTOM |
static int |
ANIM_CUSTOM_IN_PLACE |
static int |
ANIM_DEFAULT |
static int |
ANIM_LAUNCH_TASK_BEHIND |
static int |
ANIM_NONE |
static int |
ANIM_SCALE_UP |
static int |
ANIM_SCENE_TRANSITION |
static int |
ANIM_THUMBNAIL_ASPECT_SCALE_DOWN |
static int |
ANIM_THUMBNAIL_ASPECT_SCALE_UP |
static int |
ANIM_THUMBNAIL_SCALE_DOWN |
static int |
ANIM_THUMBNAIL_SCALE_UP |
static String |
EXTRA_USAGE_TIME_REPORT
A long in the extras delivered by
requestUsageTimeReport(android.app.PendingIntent) that contains
the total time (in ms) the user spent in the app flow. |
static String |
EXTRA_USAGE_TIME_REPORT_PACKAGES
A Bundle in the extras delivered by
requestUsageTimeReport(android.app.PendingIntent) that contains
detailed information about the time spent in each package associated with the app;
each key is a package name, whose value is a long containing the time (in ms). |
static String |
KEY_ANIM_ENTER_RES_ID
Custom enter animation resource ID.
|
static String |
KEY_ANIM_EXIT_RES_ID
Custom exit animation resource ID.
|
static String |
KEY_ANIM_HEIGHT
Initial height of the animation.
|
static String |
KEY_ANIM_IN_PLACE_RES_ID
Custom in-place animation resource ID.
|
static String |
KEY_ANIM_START_LISTENER
Callback for when animation is started.
|
static String |
KEY_ANIM_START_X
Start X position of thumbnail animation.
|
static String |
KEY_ANIM_START_Y
Start Y position of thumbnail animation.
|
static String |
KEY_ANIM_THUMBNAIL
Bitmap for thumbnail animation.
|
static String |
KEY_ANIM_TYPE
Type of animation that arguments specify.
|
static String |
KEY_ANIM_WIDTH
Initial width of the animation.
|
static String |
KEY_LAUNCH_BOUNDS
The bounds (window size) that the activity should be launched in.
|
static String |
KEY_PACKAGE_NAME
The package name that created the options.
|
Constructor and Description |
---|
ActivityOptions(Bundle opts) |
Modifier and Type | Method and Description |
---|---|
void |
abort() |
static void |
abort(ActivityOptions options) |
ActivityOptions |
forTargetActivity()
Return the filtered options only meant to be seen by the target activity itself
|
static ActivityOptions |
fromBundle(Bundle bOptions) |
IRemoteCallback |
getAnimationFinishedListener() |
int |
getAnimationType() |
AppTransitionAnimationSpec[] |
getAnimSpecs() |
int |
getCustomEnterResId() |
int |
getCustomExitResId() |
int |
getCustomInPlaceResId() |
int |
getDockCreateMode() |
int |
getExitCoordinatorKey() |
int |
getHeight() |
Rect |
getLaunchBounds()
Returns the bounds that should be used to launch the activity.
|
int |
getLaunchStackId() |
boolean |
getLaunchTaskBehind() |
int |
getLaunchTaskId() |
IRemoteCallback |
getOnAnimationStartListener() |
String |
getPackageName() |
int |
getResultCode() |
Intent |
getResultData() |
ResultReceiver |
getResultReceiver() |
int |
getRotationAnimationHint()
Returns the rotation animation set by
setRotationAnimationHint or -1
if unspecified. |
ArrayList<String> |
getSharedElementNames() |
int |
getStartX() |
int |
getStartY() |
boolean |
getTaskOverlay() |
Bitmap |
getThumbnail() |
PendingIntent |
getUsageTimeReport() |
int |
getWidth() |
boolean |
isReturning() |
static ActivityOptions |
makeBasic()
Create a basic ActivityOptions that has no special animation associated with it.
|
static ActivityOptions |
makeClipRevealAnimation(View source,
int startX,
int startY,
int width,
int height)
Create an ActivityOptions specifying an animation where the new
activity is revealed from a small originating area of the screen to
its final full representation.
|
static ActivityOptions |
makeCustomAnimation(Context context,
int enterResId,
int exitResId)
Create an ActivityOptions specifying a custom animation to run when
the activity is displayed.
|
static ActivityOptions |
makeCustomAnimation(Context context,
int enterResId,
int exitResId,
Handler handler,
ActivityOptions.OnAnimationStartedListener listener)
Create an ActivityOptions specifying a custom animation to run when
the activity is displayed.
|
static ActivityOptions |
makeCustomInPlaceAnimation(Context context,
int animId)
Creates an ActivityOptions specifying a custom animation to run in place on an existing
activity.
|
static ActivityOptions |
makeScaleUpAnimation(View source,
int startX,
int startY,
int width,
int height)
Create an ActivityOptions specifying an animation where the new
activity is scaled from a small originating area of the screen to
its final full representation.
|
static ActivityOptions |
makeSceneTransitionAnimation(Activity activity,
Pair<View,String>... sharedElements)
Create an ActivityOptions to transition between Activities using cross-Activity scene
animations.
|
static ActivityOptions |
makeSceneTransitionAnimation(Activity activity,
View sharedElement,
String sharedElementName)
Create an ActivityOptions to transition between Activities using cross-Activity scene
animations.
|
static ActivityOptions |
makeTaskLaunchBehind()
If set along with Intent.FLAG_ACTIVITY_NEW_DOCUMENT then the task being launched will not be
presented to the user but will instead be only available through the recents task list.
|
static ActivityOptions |
makeThumbnailAspectScaleDownAnimation(View source,
AppTransitionAnimationSpec[] specs,
Handler handler,
ActivityOptions.OnAnimationStartedListener onAnimationStartedListener,
ActivityOptions.OnAnimationFinishedListener onAnimationFinishedListener) |
static ActivityOptions |
makeThumbnailAspectScaleDownAnimation(View source,
Bitmap thumbnail,
int startX,
int startY,
int targetWidth,
int targetHeight,
Handler handler,
ActivityOptions.OnAnimationStartedListener listener)
Create an ActivityOptions specifying an animation where the new activity
window and a thumbnail is aspect-scaled to a new location.
|
static ActivityOptions |
makeThumbnailAspectScaleUpAnimation(View source,
Bitmap thumbnail,
int startX,
int startY,
int targetWidth,
int targetHeight,
Handler handler,
ActivityOptions.OnAnimationStartedListener listener)
Create an ActivityOptions specifying an animation where the new activity
window and a thumbnail is aspect-scaled to a new location.
|
static ActivityOptions |
makeThumbnailScaleDownAnimation(View source,
Bitmap thumbnail,
int startX,
int startY,
ActivityOptions.OnAnimationStartedListener listener)
Create an ActivityOptions specifying an animation where an activity window
is scaled from a given position to a thumbnail at a specified location.
|
static ActivityOptions |
makeThumbnailScaleUpAnimation(View source,
Bitmap thumbnail,
int startX,
int startY)
Create an ActivityOptions specifying an animation where a thumbnail
is scaled from a given position to the new activity window that is
being started.
|
static ActivityOptions |
makeThumbnailScaleUpAnimation(View source,
Bitmap thumbnail,
int startX,
int startY,
ActivityOptions.OnAnimationStartedListener listener)
Create an ActivityOptions specifying an animation where a thumbnail
is scaled from a given position to the new activity window that is
being started.
|
void |
requestUsageTimeReport(PendingIntent receiver)
Ask the the system track that time the user spends in the app being launched, and
report it back once done.
|
void |
setDockCreateMode(int dockCreateMode) |
ActivityOptions |
setLaunchBounds(Rect screenSpacePixelRect)
Sets the bounds (window size) that the activity should be launched in.
|
void |
setLaunchStackId(int launchStackId) |
void |
setLaunchTaskId(int taskId)
Sets the task the activity will be launched in.
|
void |
setRotationAnimationHint(int hint)
Set a rotation animation to be used if launching the activity
triggers an orientation change, or -1 to clear.
|
void |
setTaskOverlay(boolean taskOverlay)
Set's whether the activity launched with this option should be a task overlay.
|
static ActivityOptions |
startSharedElementAnimation(Window window,
Pair<View,String>... sharedElements)
Call this immediately prior to startActivity to begin a shared element transition
from a non-Activity.
|
static void |
stopSharedElementAnimation(Window window)
This method should be called when the
startSharedElementAnimation(Window, Pair[])
animation must be stopped and the Views reset. |
Bundle |
toBundle()
Returns the created options as a Bundle, which can be passed to
Context.startActivity(Intent, Bundle) and related methods. |
String |
toString()
Returns a string representation of the object.
|
void |
update(ActivityOptions otherOptions)
Update the current values in this ActivityOptions from those supplied
in otherOptions.
|
public static final String EXTRA_USAGE_TIME_REPORT
requestUsageTimeReport(android.app.PendingIntent)
that contains
the total time (in ms) the user spent in the app flow.public static final String EXTRA_USAGE_TIME_REPORT_PACKAGES
requestUsageTimeReport(android.app.PendingIntent)
that contains
detailed information about the time spent in each package associated with the app;
each key is a package name, whose value is a long containing the time (in ms).public static final String KEY_PACKAGE_NAME
public static final String KEY_LAUNCH_BOUNDS
PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT
or
PackageManager.FEATURE_PICTURE_IN_PICTURE
enabled.public static final String KEY_ANIM_TYPE
public static final String KEY_ANIM_ENTER_RES_ID
public static final String KEY_ANIM_EXIT_RES_ID
public static final String KEY_ANIM_IN_PLACE_RES_ID
public static final String KEY_ANIM_THUMBNAIL
public static final String KEY_ANIM_START_X
public static final String KEY_ANIM_START_Y
public static final String KEY_ANIM_WIDTH
public static final String KEY_ANIM_HEIGHT
public static final String KEY_ANIM_START_LISTENER
public static final int ANIM_NONE
public static final int ANIM_CUSTOM
public static final int ANIM_SCALE_UP
public static final int ANIM_THUMBNAIL_SCALE_UP
public static final int ANIM_THUMBNAIL_SCALE_DOWN
public static final int ANIM_SCENE_TRANSITION
public static final int ANIM_DEFAULT
public static final int ANIM_LAUNCH_TASK_BEHIND
public static final int ANIM_THUMBNAIL_ASPECT_SCALE_UP
public static final int ANIM_THUMBNAIL_ASPECT_SCALE_DOWN
public static final int ANIM_CUSTOM_IN_PLACE
public static final int ANIM_CLIP_REVEAL
public ActivityOptions(Bundle opts)
public static ActivityOptions makeCustomAnimation(Context context, int enterResId, int exitResId)
context
- Who is defining this. This is the application that the
animation resources will be loaded from.enterResId
- A resource ID of the animation resource to use for
the incoming activity. Use 0 for no animation.exitResId
- A resource ID of the animation resource to use for
the outgoing activity. Use 0 for no animation.public static ActivityOptions makeCustomAnimation(Context context, int enterResId, int exitResId, Handler handler, ActivityOptions.OnAnimationStartedListener listener)
context
- Who is defining this. This is the application that the
animation resources will be loaded from.enterResId
- A resource ID of the animation resource to use for
the incoming activity. Use 0 for no animation.exitResId
- A resource ID of the animation resource to use for
the outgoing activity. Use 0 for no animation.handler
- If listener is non-null this must be a valid
Handler on which to dispatch the callback; otherwise it should be null.listener
- Optional OnAnimationStartedListener to find out when the
requested animation has started running. If for some reason the animation
is not executed, the callback will happen immediately.public static ActivityOptions makeCustomInPlaceAnimation(Context context, int animId)
context
- Who is defining this. This is the application that the
animation resources will be loaded from.animId
- A resource ID of the animation resource to use for
the incoming activity.public static ActivityOptions makeScaleUpAnimation(View source, int startX, int startY, int width, int height)
If the Intent this is being used with has not set its
Intent.setSourceBounds
,
those bounds will be filled in for you based on the initial
bounds passed in here.
source
- The View that the new activity is animating from. This
defines the coordinate space for startX and startY.startX
- The x starting location of the new activity, relative to source.startY
- The y starting location of the activity, relative to source.width
- The initial width of the new activity.height
- The initial height of the new activity.public static ActivityOptions makeClipRevealAnimation(View source, int startX, int startY, int width, int height)
source
- The View that the new activity is animating from. This
defines the coordinate space for startX and startY.startX
- The x starting location of the new activity, relative to source.startY
- The y starting location of the activity, relative to source.width
- The initial width of the new activity.height
- The initial height of the new activity.public static ActivityOptions makeThumbnailScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY)
If the Intent this is being used with has not set its
Intent.setSourceBounds
,
those bounds will be filled in for you based on the initial
thumbnail location and size provided here.
source
- The View that this thumbnail is animating from. This
defines the coordinate space for startX and startY.thumbnail
- The bitmap that will be shown as the initial thumbnail
of the animation.startX
- The x starting location of the bitmap, relative to source.startY
- The y starting location of the bitmap, relative to source.public static ActivityOptions makeThumbnailScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY, ActivityOptions.OnAnimationStartedListener listener)
source
- The View that this thumbnail is animating from. This
defines the coordinate space for startX and startY.thumbnail
- The bitmap that will be shown as the initial thumbnail
of the animation.startX
- The x starting location of the bitmap, relative to source.startY
- The y starting location of the bitmap, relative to source.listener
- Optional OnAnimationStartedListener to find out when the
requested animation has started running. If for some reason the animation
is not executed, the callback will happen immediately.public static ActivityOptions makeThumbnailScaleDownAnimation(View source, Bitmap thumbnail, int startX, int startY, ActivityOptions.OnAnimationStartedListener listener)
source
- The View that this thumbnail is animating to. This
defines the coordinate space for startX and startY.thumbnail
- The bitmap that will be shown as the final thumbnail
of the animation.startX
- The x end location of the bitmap, relative to source.startY
- The y end location of the bitmap, relative to source.listener
- Optional OnAnimationStartedListener to find out when the
requested animation has started running. If for some reason the animation
is not executed, the callback will happen immediately.public static ActivityOptions makeThumbnailAspectScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight, Handler handler, ActivityOptions.OnAnimationStartedListener listener)
source
- The View that this thumbnail is animating from. This
defines the coordinate space for startX and startY.thumbnail
- The bitmap that will be shown as the initial thumbnail
of the animation.startX
- The x starting location of the bitmap, relative to source.startY
- The y starting location of the bitmap, relative to source.handler
- If listener is non-null this must be a valid
Handler on which to dispatch the callback; otherwise it should be null.listener
- Optional OnAnimationStartedListener to find out when the
requested animation has started running. If for some reason the animation
is not executed, the callback will happen immediately.public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source, Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight, Handler handler, ActivityOptions.OnAnimationStartedListener listener)
source
- The View that this thumbnail is animating to. This
defines the coordinate space for startX and startY.thumbnail
- The bitmap that will be shown as the final thumbnail
of the animation.startX
- The x end location of the bitmap, relative to source.startY
- The y end location of the bitmap, relative to source.handler
- If listener is non-null this must be a valid
Handler on which to dispatch the callback; otherwise it should be null.listener
- Optional OnAnimationStartedListener to find out when the
requested animation has started running. If for some reason the animation
is not executed, the callback will happen immediately.public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source, AppTransitionAnimationSpec[] specs, Handler handler, ActivityOptions.OnAnimationStartedListener onAnimationStartedListener, ActivityOptions.OnAnimationFinishedListener onAnimationFinishedListener)
public static ActivityOptions makeSceneTransitionAnimation(Activity activity, View sharedElement, String sharedElementName)
sharedElement
will be used as the epicenter for the
exit Transition. The position of the shared element in the launched Activity will be the
epicenter of its entering Transition.
This requires Window.FEATURE_ACTIVITY_TRANSITIONS
to be
enabled on the calling Activity to cause an exit transition. The same must be in
the called Activity to get an entering transition.
activity
- The Activity whose window contains the shared elements.sharedElement
- The View to transition to the started Activity.sharedElementName
- The shared element name as used in the target Activity. This
must not be null.Transition.setEpicenterCallback(
android.transition.Transition.EpicenterCallback)
@SafeVarargs public static ActivityOptions makeSceneTransitionAnimation(Activity activity, Pair<View,String>... sharedElements)
This requires Window.FEATURE_ACTIVITY_TRANSITIONS
to be
enabled on the calling Activity to cause an exit transition. The same must be in
the called Activity to get an entering transition.
activity
- The Activity whose window contains the shared elements.sharedElements
- The names of the shared elements to transfer to the called
Activity and their associated Views. The Views must each have
a unique shared element name.Transition.setEpicenterCallback(
android.transition.Transition.EpicenterCallback)
@SafeVarargs public static ActivityOptions startSharedElementAnimation(Window window, Pair<View,String>... sharedElements)
When all transitions have completed and the shared element has been transfered, the window's decor View will have its visibility set to View.GONE.
public static void stopSharedElementAnimation(Window window)
startSharedElementAnimation(Window, Pair[])
animation must be stopped and the Views reset. This can happen if there was an error
from startActivity or a springboard activity and the animation should stop and reset.public static ActivityOptions makeTaskLaunchBehind()
This behavior is not supported for activities with launchMode
values of
singleInstance
or singleTask
.
public static ActivityOptions makeBasic()
public boolean getLaunchTaskBehind()
public ActivityOptions setLaunchBounds(Rect screenSpacePixelRect)
NOTE: This value is ignored on devices that don't have
PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT
or
PackageManager.FEATURE_PICTURE_IN_PICTURE
enabled.
screenSpacePixelRect
- Launch bounds to use for the activity or null for fullscreen.public String getPackageName()
public Rect getLaunchBounds()
setLaunchBounds(Rect)
public int getAnimationType()
public int getCustomEnterResId()
public int getCustomExitResId()
public int getCustomInPlaceResId()
public Bitmap getThumbnail()
public int getStartX()
public int getStartY()
public int getWidth()
public int getHeight()
public IRemoteCallback getOnAnimationStartListener()
public IRemoteCallback getAnimationFinishedListener()
public int getExitCoordinatorKey()
public void abort()
public boolean isReturning()
public ResultReceiver getResultReceiver()
public int getResultCode()
public Intent getResultData()
public PendingIntent getUsageTimeReport()
public AppTransitionAnimationSpec[] getAnimSpecs()
public static ActivityOptions fromBundle(Bundle bOptions)
public static void abort(ActivityOptions options)
public int getLaunchStackId()
public void setLaunchStackId(int launchStackId)
public void setLaunchTaskId(int taskId)
public int getLaunchTaskId()
public void setTaskOverlay(boolean taskOverlay)
public boolean getTaskOverlay()
public int getDockCreateMode()
public void setDockCreateMode(int dockCreateMode)
public void update(ActivityOptions otherOptions)
public Bundle toBundle()
Context.startActivity(Intent, Bundle)
and related methods.
Note that the returned Bundle is still owned by the ActivityOptions
object; you must not modify it, but can supply it to the startActivity
methods that take an options Bundle.public void requestUsageTimeReport(PendingIntent receiver)
EXTRA_USAGE_TIME_REPORT
and EXTRA_USAGE_TIME_REPORT_PACKAGES
filled in.
The time interval tracked is from launching this activity until the user leaves that activity's flow. They are considered to stay in the flow as long as new activities are being launched or returned to from the original flow, even if this crosses package or task boundaries. For example, if the originator starts an activity to view an image, and while there the user selects to share, which launches their email app in a new task, and they complete the share, the time during that entire operation will be included until they finally hit back from the original image viewer activity.
The user is considered to complete a flow once they switch to another activity that is not part of the tracked flow. This may happen, for example, by using the notification shade, launcher, or recents to launch or switch to another app. Simply going in to these navigation elements does not break the flow (although the launcher and recents stops time tracking of the session); it is the act of going somewhere else that completes the tracking.
receiver
- A broadcast receiver that willl receive the report.public ActivityOptions forTargetActivity()
public int getRotationAnimationHint()
setRotationAnimationHint
or -1
if unspecified.public void setRotationAnimationHint(int hint)
WindowManager.LayoutParams
for rotation
animation values.public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())