use of android.animation.Animator in project platform_frameworks_base by android.
the class FastScroller method transitionPreviewLayout.
/**
* Transitions the preview text to a new section. Handles animation,
* measurement, and layout. If the new preview text is empty, returns false.
*
* @param sectionIndex The section index to which the preview should
* transition.
* @return False if the new preview text is empty.
*/
private boolean transitionPreviewLayout(int sectionIndex) {
final Object[] sections = mSections;
String text = null;
if (sections != null && sectionIndex >= 0 && sectionIndex < sections.length) {
final Object section = sections[sectionIndex];
if (section != null) {
text = section.toString();
}
}
final Rect bounds = mTempBounds;
final View preview = mPreviewImage;
final TextView showing;
final TextView target;
if (mShowingPrimary) {
showing = mPrimaryText;
target = mSecondaryText;
} else {
showing = mSecondaryText;
target = mPrimaryText;
}
// Set and layout target immediately.
target.setText(text);
measurePreview(target, bounds);
applyLayout(target, bounds);
if (mPreviewAnimation != null) {
mPreviewAnimation.cancel();
}
// Cross-fade preview text.
final Animator showTarget = animateAlpha(target, 1f).setDuration(DURATION_CROSS_FADE);
final Animator hideShowing = animateAlpha(showing, 0f).setDuration(DURATION_CROSS_FADE);
hideShowing.addListener(mSwitchPrimaryListener);
// Apply preview image padding and animate bounds, if necessary.
bounds.left -= preview.getPaddingLeft();
bounds.top -= preview.getPaddingTop();
bounds.right += preview.getPaddingRight();
bounds.bottom += preview.getPaddingBottom();
final Animator resizePreview = animateBounds(preview, bounds);
resizePreview.setDuration(DURATION_RESIZE);
mPreviewAnimation = new AnimatorSet();
final AnimatorSet.Builder builder = mPreviewAnimation.play(hideShowing).with(showTarget);
builder.with(resizePreview);
// The current preview size is unaffected by hidden or showing. It's
// used to set starting scales for things that need to be scaled down.
final int previewWidth = preview.getWidth() - preview.getPaddingLeft() - preview.getPaddingRight();
// If target is too large, shrink it immediately to fit and expand to
// target size. Otherwise, start at target size.
final int targetWidth = target.getWidth();
if (targetWidth > previewWidth) {
target.setScaleX((float) previewWidth / targetWidth);
final Animator scaleAnim = animateScaleX(target, 1f).setDuration(DURATION_RESIZE);
builder.with(scaleAnim);
} else {
target.setScaleX(1f);
}
// If showing is larger than target, shrink to target size.
final int showingWidth = showing.getWidth();
if (showingWidth > targetWidth) {
final float scale = (float) targetWidth / showingWidth;
final Animator scaleAnim = animateScaleX(showing, scale).setDuration(DURATION_RESIZE);
builder.with(scaleAnim);
}
mPreviewAnimation.start();
return !TextUtils.isEmpty(text);
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class FastScroller method transitionToVisible.
/**
* Shows the thumb and track.
*/
private void transitionToVisible() {
if (mDecorAnimation != null) {
mDecorAnimation.cancel();
}
final Animator fadeIn = groupAnimatorOfFloat(View.ALPHA, 1f, mThumbImage, mTrackImage).setDuration(DURATION_FADE_IN);
final Animator fadeOut = groupAnimatorOfFloat(View.ALPHA, 0f, mPreviewImage, mPrimaryText, mSecondaryText).setDuration(DURATION_FADE_OUT);
final Animator slideIn = groupAnimatorOfFloat(View.TRANSLATION_X, 0f, mThumbImage, mTrackImage).setDuration(DURATION_FADE_IN);
mDecorAnimation = new AnimatorSet();
mDecorAnimation.playTogether(fadeIn, fadeOut, slideIn);
mDecorAnimation.start();
mShowingPreview = false;
}
use of android.animation.Animator in project android-ripple-background by skyfishjy.
the class RippleBackground method init.
private void init(final Context context, final AttributeSet attrs) {
if (isInEditMode())
return;
if (null == attrs) {
throw new IllegalArgumentException("Attributes should be provided to this view,");
}
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleBackground);
rippleColor = typedArray.getColor(R.styleable.RippleBackground_rb_color, getResources().getColor(R.color.rippelColor));
rippleStrokeWidth = typedArray.getDimension(R.styleable.RippleBackground_rb_strokeWidth, getResources().getDimension(R.dimen.rippleStrokeWidth));
rippleRadius = typedArray.getDimension(R.styleable.RippleBackground_rb_radius, getResources().getDimension(R.dimen.rippleRadius));
rippleDurationTime = typedArray.getInt(R.styleable.RippleBackground_rb_duration, DEFAULT_DURATION_TIME);
rippleAmount = typedArray.getInt(R.styleable.RippleBackground_rb_rippleAmount, DEFAULT_RIPPLE_COUNT);
rippleScale = typedArray.getFloat(R.styleable.RippleBackground_rb_scale, DEFAULT_SCALE);
rippleType = typedArray.getInt(R.styleable.RippleBackground_rb_type, DEFAULT_FILL_TYPE);
typedArray.recycle();
rippleDelay = rippleDurationTime / rippleAmount;
paint = new Paint();
paint.setAntiAlias(true);
if (rippleType == DEFAULT_FILL_TYPE) {
rippleStrokeWidth = 0;
paint.setStyle(Paint.Style.FILL);
} else
paint.setStyle(Paint.Style.STROKE);
paint.setColor(rippleColor);
rippleParams = new LayoutParams((int) (2 * (rippleRadius + rippleStrokeWidth)), (int) (2 * (rippleRadius + rippleStrokeWidth)));
rippleParams.addRule(CENTER_IN_PARENT, TRUE);
animatorSet = new AnimatorSet();
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorList = new ArrayList<Animator>();
for (int i = 0; i < rippleAmount; i++) {
RippleView rippleView = new RippleView(getContext());
addView(rippleView, rippleParams);
rippleViewList.add(rippleView);
final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleXAnimator.setStartDelay(i * rippleDelay);
scaleXAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleXAnimator);
final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleYAnimator.setStartDelay(i * rippleDelay);
scaleYAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleYAnimator);
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
alphaAnimator.setStartDelay(i * rippleDelay);
alphaAnimator.setDuration(rippleDurationTime);
animatorList.add(alphaAnimator);
}
animatorSet.playTogether(animatorList);
}
use of android.animation.Animator in project android-ripple-background by skyfishjy.
the class MainActivity method foundDevice.
private void foundDevice() {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(400);
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
ArrayList<Animator> animatorList = new ArrayList<Animator>();
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(foundDevice, "ScaleX", 0f, 1.2f, 1f);
animatorList.add(scaleXAnimator);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(foundDevice, "ScaleY", 0f, 1.2f, 1f);
animatorList.add(scaleYAnimator);
animatorSet.playTogether(animatorList);
foundDevice.setVisibility(View.VISIBLE);
animatorSet.start();
}
use of android.animation.Animator in project platform_frameworks_base by android.
the class RenderSessionImpl method animate.
/**
* Animate an object
* <p>
* {@link #acquire(long)} must have been called before this.
*
* @throws IllegalStateException if the current context is different than the one owned by
* the scene, or if {@link #acquire(long)} was not called.
*
* @see RenderSession#animate(Object, String, boolean, IAnimationListener)
*/
public Result animate(Object targetObject, String animationName, boolean isFrameworkAnimation, IAnimationListener listener) {
checkLock();
BridgeContext context = getContext();
// find the animation file.
ResourceValue animationResource;
int animationId = 0;
if (isFrameworkAnimation) {
animationResource = context.getRenderResources().getFrameworkResource(ResourceType.ANIMATOR, animationName);
if (animationResource != null) {
animationId = Bridge.getResourceId(ResourceType.ANIMATOR, animationName);
}
} else {
animationResource = context.getRenderResources().getProjectResource(ResourceType.ANIMATOR, animationName);
if (animationResource != null) {
animationId = context.getLayoutlibCallback().getResourceId(ResourceType.ANIMATOR, animationName);
}
}
if (animationResource != null) {
try {
Animator anim = AnimatorInflater.loadAnimator(context, animationId);
if (anim != null) {
anim.setTarget(targetObject);
new PlayAnimationThread(anim, this, animationName, listener).start();
return SUCCESS.createResult();
}
} catch (Exception e) {
// get the real cause of the exception.
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
return ERROR_UNKNOWN.createResult(t.getMessage(), t);
}
}
return ERROR_ANIM_NOT_FOUND.createResult();
}
Aggregations