use of android.view.animation.AnimationSet in project UltimateAndroid by cymcsg.
the class RayMenu method createItemDisapperAnimation.
private static Animation createItemDisapperAnimation(final long duration, final boolean isClicked) {
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(new ScaleAnimation(1.0f, isClicked ? 2.0f : 0.0f, 1.0f, isClicked ? 2.0f : 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f));
animationSet.setDuration(duration);
animationSet.setInterpolator(new DecelerateInterpolator());
animationSet.setFillAfter(true);
return animationSet;
}
use of android.view.animation.AnimationSet in project android_frameworks_base by DirtyUnicorns.
the class AppTransition method createScaleUpAnimationLocked.
private Animation createScaleUpAnimationLocked(int transit, boolean enter, Rect containingFrame) {
Animation a;
getDefaultNextAppTransitionStartRect(mTmpRect);
final int appWidth = containingFrame.width();
final int appHeight = containingFrame.height();
if (enter) {
// Entering app zooms out from the center of the initial rect.
float scaleW = mTmpRect.width() / (float) appWidth;
float scaleH = mTmpRect.height() / (float) appHeight;
Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, computePivot(mTmpRect.left, scaleW), computePivot(mTmpRect.top, scaleH));
scale.setInterpolator(mDecelerateInterpolator);
Animation alpha = new AlphaAnimation(0, 1);
alpha.setInterpolator(mThumbnailFadeOutInterpolator);
AnimationSet set = new AnimationSet(false);
set.addAnimation(scale);
set.addAnimation(alpha);
set.setDetachWallpaper(true);
a = set;
} else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN || transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
// If we are on top of the wallpaper, we need an animation that
// correctly handles the wallpaper staying static behind all of
// the animated elements. To do this, will just have the existing
// element fade out.
a = new AlphaAnimation(1, 0);
a.setDetachWallpaper(true);
} else {
// For normal animations, the exiting element just holds in place.
a = new AlphaAnimation(1, 1);
}
// Pick the desired duration. If this is an inter-activity transition,
// it is the standard duration for that. Otherwise we use the longer
// task transition duration.
final long duration;
switch(transit) {
case TRANSIT_ACTIVITY_OPEN:
case TRANSIT_ACTIVITY_CLOSE:
duration = mConfigShortAnimTime;
break;
default:
duration = DEFAULT_APP_TRANSITION_DURATION;
break;
}
a.setDuration(duration);
a.setFillAfter(true);
a.setInterpolator(mDecelerateInterpolator);
a.initialize(appWidth, appHeight, appWidth, appHeight);
return a;
}
use of android.view.animation.AnimationSet in project android_frameworks_base by DirtyUnicorns.
the class AppTransition method createThumbnailEnterExitAnimationLocked.
/**
* This animation is created when we are doing a thumbnail transition, for the activity that is
* leaving, and the activity that is entering.
*/
Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame, int transit, int taskId) {
final int appWidth = containingFrame.width();
final int appHeight = containingFrame.height();
Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Animation a;
getDefaultNextAppTransitionStartRect(mTmpRect);
final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
switch(thumbTransitState) {
case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
{
// Entering app scales up with the thumbnail
float scaleW = thumbWidth / appWidth;
float scaleH = thumbHeight / appHeight;
a = new ScaleAnimation(scaleW, 1, scaleH, 1, computePivot(mTmpRect.left, scaleW), computePivot(mTmpRect.top, scaleH));
break;
}
case THUMBNAIL_TRANSITION_EXIT_SCALE_UP:
{
// Exiting app while the thumbnail is scaling up should fade or stay in place
if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
// Fade out while bringing up selected activity. This keeps the
// current activity from showing through a launching wallpaper
// activity.
a = new AlphaAnimation(1, 0);
} else {
// noop animation
a = new AlphaAnimation(1, 1);
}
break;
}
case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN:
{
// Entering the other app, it should just be visible while we scale the thumbnail
// down above it
a = new AlphaAnimation(1, 1);
break;
}
case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN:
{
// Exiting the current app, the app should scale down with the thumbnail
float scaleW = thumbWidth / appWidth;
float scaleH = thumbHeight / appHeight;
Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH, computePivot(mTmpRect.left, scaleW), computePivot(mTmpRect.top, scaleH));
Animation alpha = new AlphaAnimation(1, 0);
AnimationSet set = new AnimationSet(true);
set.addAnimation(scale);
set.addAnimation(alpha);
set.setZAdjustment(Animation.ZORDER_TOP);
a = set;
break;
}
default:
throw new RuntimeException("Invalid thumbnail transition state");
}
return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
}
use of android.view.animation.AnimationSet in project android_frameworks_base by DirtyUnicorns.
the class AppTransition method createRelaunchAnimation.
private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
final int left = mTmpFromClipRect.left;
final int top = mTmpFromClipRect.top;
mTmpFromClipRect.offset(-left, -top);
// TODO: Isn't that strange that we ignore exact position of the containingFrame?
mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
AnimationSet set = new AnimationSet(true);
float fromWidth = mTmpFromClipRect.width();
float toWidth = mTmpToClipRect.width();
float fromHeight = mTmpFromClipRect.height();
// While the window might span the whole display, the actual content will be cropped to the
// system decoration frame, for example when the window is docked. We need to take into
// account the visible height when constructing the animation.
float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
int translateAdjustment = 0;
if (fromWidth <= toWidth && fromHeight <= toHeight) {
// The final window is larger in both dimensions than current window (e.g. we are
// maximizing), so we can simply unclip the new window and there will be no disappearing
// frame.
set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
} else {
// The disappearing window has one larger dimension. We need to apply scaling, so the
// first frame of the entry animation matches the old window.
set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
// We might not be going exactly full screen, but instead be aligned under the status
// bar using cropping. We still need to account for the cropped part, which will also
// be scaled.
translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
}
// We animate the translation from the old position of the removed window, to the new
// position of the added window. The latter might not be full screen, for example docked for
// docked windows.
TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left, 0, top - containingFrame.top - translateAdjustment, 0);
set.addAnimation(translate);
set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
set.setZAdjustment(Animation.ZORDER_TOP);
return set;
}
use of android.view.animation.AnimationSet in project android_frameworks_base by DirtyUnicorns.
the class AppTransition method createAspectScaledThumbnailEnterExitAnimationLocked.
/**
* This alternate animation is created when we are doing a thumbnail transition, for the
* activity that is leaving, and the activity that is entering.
*/
Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState, int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets, @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Animation a;
final int appWidth = containingFrame.width();
final int appHeight = containingFrame.height();
getDefaultNextAppTransitionStartRect(mTmpRect);
final int thumbWidthI = mTmpRect.width();
final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
final int thumbHeightI = mTmpRect.height();
final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
final int thumbStartY = mTmpRect.top - containingFrame.top;
switch(thumbTransitState) {
case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN:
{
final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
if (freeform && scaleUp) {
a = createAspectScaledThumbnailEnterFreeformAnimationLocked(containingFrame, surfaceInsets, taskId);
} else if (freeform) {
a = createAspectScaledThumbnailExitFreeformAnimationLocked(containingFrame, surfaceInsets, taskId);
} else {
AnimationSet set = new AnimationSet(true);
// In portrait, we scale to fit the width
mTmpFromClipRect.set(containingFrame);
mTmpToClipRect.set(containingFrame);
// Containing frame is in screen space, but we need the clip rect in the
// app space.
mTmpFromClipRect.offsetTo(0, 0);
mTmpToClipRect.offsetTo(0, 0);
// Exclude insets region from the source clip.
mTmpFromClipRect.inset(contentInsets);
mNextAppTransitionInsets.set(contentInsets);
if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
// We scale the width and clip to the top/left square
float scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
if (!mGridLayoutRecentsEnabled) {
int unscaledThumbHeight = (int) (thumbHeight / scale);
mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
}
mNextAppTransitionInsets.set(contentInsets);
Animation scaleAnim = new ScaleAnimation(scaleUp ? scale : 1, scaleUp ? 1 : scale, scaleUp ? scale : 1, scaleUp ? 1 : scale, containingFrame.width() / 2f, containingFrame.height() / 2f + contentInsets.top);
final float targetX = (mTmpRect.left - containingFrame.left);
final float x = containingFrame.width() / 2f - containingFrame.width() / 2f * scale;
final float targetY = (mTmpRect.top - containingFrame.top);
final float y = containingFrame.height() / 2f - containingFrame.height() / 2f * scale;
final float startX = targetX - x;
final float startY = targetY - y;
Animation clipAnim = scaleUp ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect) : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
Animation translateAnim = scaleUp ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0) : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
set.addAnimation(clipAnim);
set.addAnimation(scaleAnim);
set.addAnimation(translateAnim);
} else {
// In landscape, we don't scale at all and only crop
mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
Animation clipAnim = scaleUp ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect) : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
Animation translateAnim = scaleUp ? createCurvedMotion(thumbStartX, 0, thumbStartY - contentInsets.top, 0) : createCurvedMotion(0, thumbStartX, 0, thumbStartY - contentInsets.top);
set.addAnimation(clipAnim);
set.addAnimation(translateAnim);
}
a = set;
a.setZAdjustment(Animation.ZORDER_TOP);
}
break;
}
case THUMBNAIL_TRANSITION_EXIT_SCALE_UP:
{
// Previous app window during the scale up
if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
// Fade out the source activity if we are animating to a wallpaper
// activity.
a = new AlphaAnimation(1, 0);
} else {
a = new AlphaAnimation(1, 1);
}
break;
}
case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN:
{
// Target app window during the scale down
if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
// Fade in the destination activity if we are animating from a wallpaper
// activity.
a = new AlphaAnimation(0, 1);
} else {
a = new AlphaAnimation(1, 1);
}
break;
}
default:
throw new RuntimeException("Invalid thumbnail transition state");
}
return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, getAspectScaleDuration(), getAspectScaleInterpolator());
}
Aggregations