use of android.animation.AnimatorSet in project android-tooltips by rharter.
the class ToolTipLayout method addTooltip.
public void addTooltip(ToolTip tooltip, boolean animate) {
mToolTips.add(tooltip);
View v = tooltip.getView();
if (tooltip.isDismissOnTouch()) {
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
addView(v);
requestLayout();
if (animate) {
// We use a two pass preDrawListener so we can get the post animation
// position of the item and then animate it.
getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!mShouldRemoveObserver) {
mShouldRemoveObserver = true;
mFinalPositions.clear();
for (ToolTip t : mToolTips) {
float position = 0;
if (Gravity.isVertical(t.getGravity())) {
position = t.getView().getY();
} else {
position = t.getView().getX();
}
mFinalPositions.put(t, position);
}
return false;
}
mShouldRemoveObserver = false;
getViewTreeObserver().removeOnPreDrawListener(this);
List<Animator> animators = new ArrayList<>();
for (ToolTip t : mToolTips) {
t.getView().setAlpha(0);
animators.add(ObjectAnimator.ofFloat(t.getView(), View.ALPHA, 0, 1));
// TODO Restore this once I can fix the flicker
// final float finalPosition = mFinalPositions.get(t);
// if ((Gravity.VERTICAL_GRAVITY_MASK & t.getGravity()) == Gravity.TOP) {
// float start = finalPosition - t.getView().getHeight() / 2;
// t.getView().setY(start);
//
// animators.add(ObjectAnimator
// .ofFloat(t.getView(), View.TRANSLATION_Y,
// start,
// finalPosition));
// } else if ((Gravity.VERTICAL_GRAVITY_MASK & t.getGravity())
// == Gravity.BOTTOM) {
// float start = finalPosition + t.getView().getHeight() / 2;
// t.getView().setY(start);
//
// animators.add(ObjectAnimator
// .ofFloat(t.getView(), View.TRANSLATION_Y,
// start,
// finalPosition));
// } else if ((Gravity.HORIZONTAL_GRAVITY_MASK & t.getGravity())
// == Gravity.LEFT) {
// float start = finalPosition - t.getView().getWidth() / 2;
// t.getView().setX(start);
//
// animators.add(ObjectAnimator
// .ofFloat(t.getView(), View.TRANSLATION_X,
// start,
// finalPosition));
// } else if ((Gravity.HORIZONTAL_GRAVITY_MASK & t.getGravity())
// == Gravity.RIGHT) {
// float start = finalPosition + t.getView().getWidth() / 2;
// t.getView().setX(start);
//
// animators.add(ObjectAnimator
// .ofFloat(t.getView(), View.TRANSLATION_X,
// start,
// finalPosition));
// }
}
AnimatorSet s = new AnimatorSet();
s.playTogether(animators);
s.start();
return true;
}
});
}
}
use of android.animation.AnimatorSet in project android-tooltips by rharter.
the class ToolTipLayout method dismiss.
/**
* Dismisses all tooltips currently being displayed.
*
* @param animate True to animate the transition.
*/
public void dismiss(boolean animate) {
mToolTips.clear();
if (animate) {
final List<View> viewsToRemove = new ArrayList<>();
List<Animator> a = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
a.add(ObjectAnimator.ofFloat(getChildAt(i), View.ALPHA, 0));
viewsToRemove.add(getChildAt(i));
}
AnimatorSet s = new AnimatorSet();
s.playTogether(a);
s.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
for (View v : viewsToRemove) {
removeView(v);
}
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
s.start();
} else {
removeAllViews();
}
}
use of android.animation.AnimatorSet in project ToggleDrawable by renaudcerrato.
the class MainActivity method toggle.
private void toggle() {
isFaded = !isFaded;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
AnimatorSet set = new AnimatorSet();
ObjectAnimator backgroundAnim = ObjectAnimator.ofInt(mContainer.getBackground(), "alpha", isFaded ? 128 : 0);
ObjectAnimator drawableAnim = ObjectAnimator.ofInt(mSeekBar, "progress", isFaded ? mSeekBar.getMax() : 0);
set.setDuration(700);
set.setInterpolator(new DecelerateInterpolator(3f));
set.playTogether(backgroundAnim, drawableAnim);
set.start();
} else {
Animation set = new ToggleAnimationSet(isFaded);
set.setDuration(700);
set.setInterpolator(new DecelerateInterpolator(3f));
mContainer.startAnimation(set);
}
}
use of android.animation.AnimatorSet in project ActivityAnimationLib by dkmeteor.
the class SplitEffect method animate.
public void animate(final Activity destActivity, final int duration) {
final Interpolator interpolator = new DecelerateInterpolator();
destActivity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
new Handler().post(new Runnable() {
@Override
public void run() {
mSetAnim = new AnimatorSet();
mTopImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mBottomImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mSetAnim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
clean(destActivity);
}
@Override
public void onAnimationCancel(Animator animation) {
clean(destActivity);
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
Animator anim1 = ObjectAnimator.ofFloat(mTopImage, "translationY", mTopImage.getHeight() * -1);
Animator anim2 = ObjectAnimator.ofFloat(mBottomImage, "translationY", mBottomImage.getHeight());
if (interpolator != null) {
anim1.setInterpolator(interpolator);
anim2.setInterpolator(interpolator);
}
mSetAnim.setDuration(duration);
mSetAnim.playTogether(anim1, anim2);
mSetAnim.start();
}
});
}
use of android.animation.AnimatorSet in project kickmaterial by byoutline.
the class AnimatorUtils method getScaleAnimator.
public static AnimatorSet getScaleAnimator(View view, float startScale, float endScale) {
AnimatorSet set = new AnimatorSet();
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(view, View.SCALE_X, startScale, endScale);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(view, View.SCALE_Y, startScale, endScale);
set.playTogether(scaleXAnimator, scaleYAnimator);
return set;
}
Aggregations