use of android.animation.Animator in project platform_frameworks_base by android.
the class Transition method runAnimator.
private void runAnimator(Animator animator, final ArrayMap<Animator, AnimationInfo> runningAnimators) {
if (animator != null) {
// TODO: could be a single listener instance for all of them since it uses the param
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mCurrentAnimators.add(animation);
}
@Override
public void onAnimationEnd(Animator animation) {
runningAnimators.remove(animation);
mCurrentAnimators.remove(animation);
}
});
animate(animator);
}
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class Transition method animate.
/**
* This is a utility method used by subclasses to handle standard parts of
* setting up and running an Animator: it sets the {@link #getDuration()
* duration} and the {@link #getStartDelay() startDelay}, starts the
* animation, and, when the animator ends, calls {@link #end()}.
*
* @param animator The Animator to be run during this transition.
*
* @hide
*/
protected void animate(Animator animator) {
// TODO: maybe pass auto-end as a boolean parameter?
if (animator == null) {
end();
} else {
if (getDuration() >= 0) {
animator.setDuration(getDuration());
}
if (getStartDelay() >= 0) {
animator.setStartDelay(getStartDelay() + animator.getStartDelay());
}
if (getInterpolator() != null) {
animator.setInterpolator(getInterpolator());
}
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
end();
animation.removeListener(this);
}
});
animator.start();
}
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class Visibility method onDisappear.
/**
* Subclasses should override this method or
* {@link #onDisappear(ViewGroup, View, TransitionValues, TransitionValues)}
* if they need to create an Animator when targets disappear.
* The method should only be called by the Visibility class; it is
* not intended to be called from external classes.
* <p>
* The default implementation of this method attempts to find a View to use to call
* {@link #onDisappear(ViewGroup, View, TransitionValues, TransitionValues)},
* based on the situation of the View in the View hierarchy. For example,
* if a View was simply removed from its parent, then the View will be added
* into a {@link android.view.ViewGroupOverlay} and passed as the <code>view</code>
* parameter in {@link #onDisappear(ViewGroup, View, TransitionValues, TransitionValues)}.
* If a visible View is changed to be {@link View#GONE} or {@link View#INVISIBLE},
* then it can be used as the <code>view</code> and the visibility will be changed
* to {@link View#VISIBLE} for the duration of the animation. However, if a View
* is in a hierarchy which is also altering its visibility, the situation can be
* more complicated. In general, if a view that is no longer in the hierarchy in
* the end scene still has a parent (so its parent hierarchy was removed, but it
* was not removed from its parent), then it will be left alone to avoid side-effects from
* improperly removing it from its parent. The only exception to this is if
* the previous {@link Scene} was {@link Scene#getSceneForLayout(ViewGroup, int,
* android.content.Context) created from a layout resource file}, then it is considered
* safe to un-parent the starting scene view in order to make it disappear.</p>
*
* @param sceneRoot The root of the transition hierarchy
* @param startValues The target values in the start scene
* @param startVisibility The target visibility in the start scene
* @param endValues The target values in the end scene
* @param endVisibility The target visibility in the end scene
* @return An Animator to be started at the appropriate time in the
* overall transition for this scene change. A null value means no animation
* should be run.
*/
public Animator onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility) {
if ((mMode & MODE_OUT) != MODE_OUT) {
return null;
}
View startView = (startValues != null) ? startValues.view : null;
View endView = (endValues != null) ? endValues.view : null;
View overlayView = null;
View viewToKeep = null;
if (endView == null || endView.getParent() == null) {
if (endView != null) {
// endView was removed from its parent - add it to the overlay
overlayView = endView;
} else if (startView != null) {
// it being removed from its current parent
if (startView.getParent() == null) {
// no parent - safe to use
overlayView = startView;
} else if (startView.getParent() instanceof View) {
View startParent = (View) startView.getParent();
TransitionValues startParentValues = getTransitionValues(startParent, true);
TransitionValues endParentValues = getMatchedTransitionValues(startParent, true);
VisibilityInfo parentVisibilityInfo = getVisibilityChangeInfo(startParentValues, endParentValues);
if (!parentVisibilityInfo.visibilityChange) {
overlayView = TransitionUtils.copyViewImage(sceneRoot, startView, startParent);
} else if (startParent.getParent() == null) {
int id = startParent.getId();
if (id != View.NO_ID && sceneRoot.findViewById(id) != null && mCanRemoveViews) {
// no parent, but its parent is unparented but the parent
// hierarchy has been replaced by a new hierarchy with the same id
// and it is safe to un-parent startView
overlayView = startView;
}
}
}
}
} else {
// visibility change
if (endVisibility == View.INVISIBLE) {
viewToKeep = endView;
} else {
// Becoming GONE
if (startView == endView) {
viewToKeep = endView;
} else {
overlayView = startView;
}
}
}
final int finalVisibility = endVisibility;
final ViewGroup finalSceneRoot = sceneRoot;
if (overlayView != null) {
// TODO: Need to do this for general case of adding to overlay
int[] screenLoc = (int[]) startValues.values.get(PROPNAME_SCREEN_LOCATION);
int screenX = screenLoc[0];
int screenY = screenLoc[1];
int[] loc = new int[2];
sceneRoot.getLocationOnScreen(loc);
overlayView.offsetLeftAndRight((screenX - loc[0]) - overlayView.getLeft());
overlayView.offsetTopAndBottom((screenY - loc[1]) - overlayView.getTop());
sceneRoot.getOverlay().add(overlayView);
Animator animator = onDisappear(sceneRoot, overlayView, startValues, endValues);
if (animator == null) {
sceneRoot.getOverlay().remove(overlayView);
} else {
final View finalOverlayView = overlayView;
addListener(new TransitionListenerAdapter() {
@Override
public void onTransitionEnd(Transition transition) {
finalSceneRoot.getOverlay().remove(finalOverlayView);
}
});
}
return animator;
}
if (viewToKeep != null) {
int originalVisibility = viewToKeep.getVisibility();
viewToKeep.setTransitionVisibility(View.VISIBLE);
Animator animator = onDisappear(sceneRoot, viewToKeep, startValues, endValues);
if (animator != null) {
DisappearListener disappearListener = new DisappearListener(viewToKeep, finalVisibility, mSuppressLayout);
animator.addListener(disappearListener);
animator.addPauseListener(disappearListener);
addListener(disappearListener);
} else {
viewToKeep.setTransitionVisibility(originalVisibility);
}
return animator;
}
return null;
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class FastScroller method groupAnimatorOfFloat.
/**
* Constructs an animator for the specified property on a group of views.
* See {@link ObjectAnimator#ofFloat(Object, String, float...)} for
* implementation details.
*
* @param property The property being animated.
* @param value The value to which that property should animate.
* @param views The target views to animate.
* @return An animator for all the specified views.
*/
private static Animator groupAnimatorOfFloat(Property<View, Float> property, float value, View... views) {
AnimatorSet animSet = new AnimatorSet();
AnimatorSet.Builder builder = null;
for (int i = views.length - 1; i >= 0; i--) {
final Animator anim = ObjectAnimator.ofFloat(views[i], property, value);
if (builder == null) {
builder = animSet.play(anim);
} else {
builder.with(anim);
}
}
return animSet;
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class FastScroller method transitionToHidden.
/**
* Shows nothing.
*/
private void transitionToHidden() {
if (mDecorAnimation != null) {
mDecorAnimation.cancel();
}
final Animator fadeOut = groupAnimatorOfFloat(View.ALPHA, 0f, mThumbImage, mTrackImage, mPreviewImage, mPrimaryText, mSecondaryText).setDuration(DURATION_FADE_OUT);
// Push the thumb and track outside the list bounds.
final float offset = mLayoutFromRight ? mThumbImage.getWidth() : -mThumbImage.getWidth();
final Animator slideOut = groupAnimatorOfFloat(View.TRANSLATION_X, offset, mThumbImage, mTrackImage).setDuration(DURATION_FADE_OUT);
mDecorAnimation = new AnimatorSet();
mDecorAnimation.playTogether(fadeOut, slideOut);
mDecorAnimation.start();
mShowingPreview = false;
}
Aggregations