下面列出了android.graphics.PaintFlagsDrawFilter#com.nineoldandroids.animation.AnimatorSet 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void animateView(final ViewGroup parent, final View view) {
if (mAnimationStartMillis == -1) {
mAnimationStartMillis = System.currentTimeMillis();
}
ViewHelper.setAlpha(view, 0);
Animator[] childAnimators;
if (mDecoratedBaseAdapter instanceof AnimationAdapter) {
childAnimators = ((AnimationAdapter) mDecoratedBaseAdapter).getAnimators(parent, view);
} else {
childAnimators = new Animator[0];
}
Animator[] animators = getAnimators(parent, view);
Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
AnimatorSet set = new AnimatorSet();
set.playTogether(concatAnimators(childAnimators, animators, alphaAnimator));
set.setStartDelay(calculateAnimationDelay());
set.setDuration(getAnimationDurationMillis());
set.start();
mAnimators.put(view.hashCode(), set);
}
public void onExpandAnimator(AnimatorSet animatorSet) {
int count = this.contentView.getChildCount();
for(int i = 0; i < count; ++i) {
View rootView = this.contentView.getChildAt(i);
ImageView iconIv = (ImageView)ABViewUtil.obtainView(rootView, com.wangjie.rapidfloatingactionbutton.R.id.rfab__content_label_list_icon_iv);
if(null == iconIv) {
return;
}
ObjectAnimator animator = new ObjectAnimator();
animator.setTarget(iconIv);
animator.setFloatValues(new float[]{45.0F, 0.0F});
animator.setPropertyName("rotation");
animator.setInterpolator(this.mOvershootInterpolator);
//animator.setStartDelay((long)(count * i * 20));
animatorSet.playTogether(new Animator[]{animator});
}
}
public void onCollapseAnimator(AnimatorSet animatorSet) {
int count = this.contentView.getChildCount();
for(int i = 0; i < count; ++i) {
View rootView = this.contentView.getChildAt(i);
ImageView iconIv = (ImageView)ABViewUtil.obtainView(rootView, com.wangjie.rapidfloatingactionbutton.R.id.rfab__content_label_list_icon_iv);
if(null == iconIv) {
return;
}
ObjectAnimator animator = new ObjectAnimator();
animator.setTarget(iconIv);
animator.setFloatValues(new float[]{0.0F, 45.0F});
animator.setPropertyName("rotation");
animator.setInterpolator(this.mOvershootInterpolator);
//animator.setStartDelay((long)(count * i * 20));
animatorSet.playTogether(new Animator[]{animator});
}
}
protected void init() {
bgPaint = new Paint();
bgPaint.setAntiAlias(true);
bgPaint.setColor(backgroundColor);
focusPaint = new Paint();
focusPaint.setAntiAlias(true);
focusPaint.setColor(focusColor);
animatorSet = new AnimatorSet();
bgRectF = new RectF();
mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
this.setBackgroundResource(0);
}
/**
* show the reside menu;
*/
public void openMenu(int direction){
if (isInDisableDirection(direction))
throw new IllegalArgumentException("You have set this direction disable, " +
"but now you want to open menu in this direction.");
setScaleDirection(direction);
isOpened = true;
AnimatorSet scaleDown_activity = buildScaleDownAnimation(viewActivity, 0.5f, 0.5f);
AnimatorSet scaleDown_shadow = buildScaleDownAnimation(imageViewShadow,
0.5f + shadowAdjustScaleX, 0.5f + shadowAdjustScaleY);
AnimatorSet alpha_menu = buildMenuAnimation(scrollViewMenu, 1.0f);
scaleDown_shadow.addListener(animationListener);
scaleDown_activity.playTogether(scaleDown_shadow);
scaleDown_activity.playTogether(alpha_menu);
scaleDown_activity.start();
}
/**
* Animates given View.
*
* @param view the View that should be animated.
*/
private void animateView(final int position, @NonNull final View view, @NonNull final Animator[] animators) {
if (mAnimationStartMillis == -1) {
mAnimationStartMillis = SystemClock.uptimeMillis();
}
ViewHelper.setAlpha(view, 0);
AnimatorSet set = new AnimatorSet();
set.playTogether(animators);
set.setStartDelay(calculateAnimationDelay(position));
set.setDuration(mAnimationDurationMillis);
set.start();
mAnimators.put(view.hashCode(), set);
}
public Animator getPullDownAnimIn(View view) {
ObjectAnimator in = ObjectAnimator.ofFloat(view, "translationY", -view.getMeasuredHeight(), 0);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0.6f, 1);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0.6f, 1);
AnimatorSet set = new AnimatorSet();
set.setInterpolator(new DecelerateInterpolator());
in.setDuration(ANIMATION_DURATION);
scaleY.setDuration(ANIMATION_DURATION);
scaleX.setDuration(ANIMATION_DURATION);
set.setDuration(ANIMATION_DURATION);
set.playTogether(scaleY, scaleX, in);
return set;
}
private Animator getPullUpAnimIn(View view) {
ObjectAnimator in = ObjectAnimator.ofFloat(view, "translationY", view.getMeasuredHeight(), 0);
// ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "rotationX", 20, 0);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0.6f, 1);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0.6f, 1f);
AnimatorSet set = new AnimatorSet();
set.setInterpolator(new DecelerateInterpolator());
in.setDuration(ANIMATION_DURATION);
scaleY.setDuration(ANIMATION_DURATION);
scaleX.setDuration(ANIMATION_DURATION);
set.setDuration(ANIMATION_DURATION);
set.playTogether(scaleY, scaleX, in);
return set;
}
/**
* Performs the undo animation and restores the original state for given {@link android.view.View}.
*
* @param view the parent {@code View} which contains both primary and undo {@code View}s.
*/
public void undo(@NonNull final View view) {
int position = AdapterViewUtil.getPositionForView(getListViewWrapper(), view);
mUndoPositions.remove(position);
View primaryView = mCallback.getPrimaryView(view);
View undoView = mCallback.getUndoView(view);
primaryView.setVisibility(View.VISIBLE);
ObjectAnimator undoAlphaAnimator = ObjectAnimator.ofFloat(undoView, ALPHA, 1f, 0f);
ObjectAnimator primaryAlphaAnimator = ObjectAnimator.ofFloat(primaryView, ALPHA, 0f, 1f);
ObjectAnimator primaryXAnimator = ObjectAnimator.ofFloat(primaryView, TRANSLATION_X, primaryView.getWidth(), 0f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(undoAlphaAnimator, primaryAlphaAnimator, primaryXAnimator);
animatorSet.addListener(new UndoAnimatorListener(undoView));
animatorSet.start();
mCallback.onUndo(view, position);
}
@Override
public void setupAnimation(@NonNull MenuItem mMenuItem, @NonNull TransitionControllerManager manager,
@IntRange(from = 0) int itemIndex, @IntRange(from = 0) int menuCount) {
if(mDelayed!=null) {
final int size = mDelayed.size();
for (int i = 0; i < size; i++) {
mDelayed.get(i).evaluate(manager.getTarget(), this);
}
}
ObjectAnimator anim = new ObjectAnimator();
anim.setValues(getValuesHolders());
AnimatorSet set = new AnimatorSet();
set.play(anim);
set.setStartDelay((long) (itemIndex * mCascade * SCALE_FACTOR));
set.setDuration((long) (SCALE_FACTOR - itemIndex * mCascade * SCALE_FACTOR));
manager.addAnimatorSetAsTransition(set).setRange(mStart, mEnd);
}
/**
* Flings given {@link android.view.View} out of sight.
*
* @param view the parent {@link android.view.View}.
* @param position the position of the item in the {@link android.widget.ListAdapter} corresponding to the {@code View}.
* @param flingToRight {@code true} if the {@code View} should be flinged to the right, {@code false} if it should be flinged to the left.
*/
private void flingView(@NonNull final View view, final int position, final boolean flingToRight) {
if (mViewWidth < 2) {
mViewWidth = mListViewWrapper.getListView().getWidth();
}
View swipeView = getSwipeView(view);
ObjectAnimator xAnimator = ObjectAnimator.ofFloat(swipeView, TRANSLATION_X, flingToRight ? mViewWidth : -mViewWidth);
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(swipeView, ALPHA, 0);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(xAnimator, alphaAnimator);
animatorSet.setDuration(mAnimationTime);
animatorSet.addListener(new FlingAnimatorListener(view, position));
animatorSet.start();
}
private void slideInToTop(View editContainer, View movableView, View v)
{
Log.d(TAG, "container view height :" + String.valueOf(v.getHeight()));
ObjectAnimator anim = ObjectAnimator.ofFloat(v, "translationY", mMainContainer.getHeight());
anim.setDuration(0);
anim.start();
v.setVisibility(View.VISIBLE);
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(v, "translationY", editContainer.getTop()+movableView.getHeight()),
ObjectAnimator.ofFloat(v, "alpha", 0, 1)
);
set.setDuration(ANIMATION_DURATION);
set.setInterpolator(ANIMATION_INTERPOLATOR);
set.start();
}
private void animateView(int position, ViewGroup parent, View view) {
if (mAnimationStartMillis == -1) {
mAnimationStartMillis = System.currentTimeMillis();
}
ViewHelper.setAlpha(view, 0);
Animator[] childAnimators;
if (mDecoratedBaseAdapter instanceof AnimationAdapter) {
childAnimators = ((AnimationAdapter) mDecoratedBaseAdapter).getAnimators(parent, view);
} else {
childAnimators = new Animator[0];
}
Animator[] animators = getAnimators(parent, view);
Animator alphaAnimator = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
AnimatorSet set = new AnimatorSet();
set.playTogether(concatAnimators(childAnimators, animators, alphaAnimator));
set.setStartDelay(calculateAnimationDelay());
set.setDuration(getAnimationDurationMillis());
set.start();
mAnimators.put(view.hashCode(), set);
}
/**
* show the reside menu;
*/
public void openMenu(int direction) {
setScaleDirection(direction);
isOpened = true;
AnimatorSet scaleDown_activity = buildScaleDownAnimation(viewActivity,
mScaleValue, mScaleValue);
AnimatorSet scaleDown_shadow = buildScaleDownAnimation(imageViewShadow,
mScaleValue + shadowAdjustScaleX, mScaleValue
+ shadowAdjustScaleY);
// AnimatorSet scaleDown_activity =
// buildMoveRightAnimation(viewActivity,
// getScreenWidth()*(mScaleValue + shadowAdjustScaleX));
// AnimatorSet scaleDown_shadow =
// buildMoveRightAnimation(imageViewShadow,
// getScreenWidth()*(mScaleValue + shadowAdjustScaleX));
AnimatorSet alpha_menu = buildMenuAnimation(scrollViewMenu, 1.0f);
scaleDown_shadow.addListener(animationListener);
scaleDown_activity.playTogether(scaleDown_shadow);
scaleDown_activity.playTogether(alpha_menu);
scaleDown_activity.start();
}
/**
* a helper method to build scale down animation;
*
* @param target
* @param targetScaleX
* @param targetScaleY
* @return
*/
private AnimatorSet buildScaleDownAnimation(View target,float targetScaleX,float targetScaleY){
// set the pivotX and pivotY to scale;
int pivotX = (int) (getScreenWidth() * 1.5);
int pivotY = (int) (getScreenHeight() * 0.5);
ViewHelper.setPivotX(target, pivotX);
ViewHelper.setPivotY(target, pivotY);
AnimatorSet scaleDown = new AnimatorSet();
scaleDown.playTogether(
ObjectAnimator.ofFloat(target, "scaleX", targetScaleX),
ObjectAnimator.ofFloat(target, "scaleY", targetScaleY)
);
scaleDown.setInterpolator(AnimationUtils.loadInterpolator(activity,
android.R.anim.decelerate_interpolator));
scaleDown.setDuration(250);
return scaleDown;
}
private void animateView(final ViewGroup parent, final View view) {
if (mAnimationStartMillis == -1) {
mAnimationStartMillis = System.currentTimeMillis();
}
ViewHelper.setAlpha(view, 0);
Animator[] childAnimators;
if (mDecoratedBaseAdapter instanceof AnimationAdapter) {
childAnimators = ((AnimationAdapter) mDecoratedBaseAdapter).getAnimators(parent, view);
} else {
childAnimators = new Animator[0];
}
Animator[] animators = getAnimators(parent, view);
Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
AnimatorSet set = new AnimatorSet();
set.playTogether(concatAnimators(childAnimators, animators, alphaAnimator));
set.setStartDelay(calculateAnimationDelay());
set.setDuration(getAnimationDurationMillis());
set.start();
mAnimators.put(view.hashCode(), set);
}
private void startBlurImageDisappearAnimator(){
if(!enableBlurBackground || mBlurImage == null) return;
AnimatorSet set = new AnimatorSet();
if(enableBackgroundZoom)
set.playTogether(
ObjectAnimator.ofFloat(mBlurImage, "alpha", 1f, 0.8f),
ObjectAnimator.ofFloat(mBlurImage, "scaleX", mZoomRatio, 1f),
ObjectAnimator.ofFloat(mBlurImage, "scaleY", mZoomRatio, 1f)
);
else
set.playTogether(
ObjectAnimator.ofFloat(mBlurImage, "alpha", 1f, 0f)
);
set.addListener(mGlobalListener);
set.addListener(mGlobalDisappearAnimators);
set.setDuration(mBlurDuration);
set.start();
}
private void addAnimation(View view) {
float[] vaules = new float[] {0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.25f, 1.2f, 1.15f, 1.1f, 1.0f};
AnimatorSet set = new AnimatorSet();
set.playTogether(ObjectAnimator.ofFloat(view, "scaleX", vaules),
ObjectAnimator.ofFloat(view, "scaleY", vaules));
set.setDuration(150);
set.start();
}
/**
* 给CheckBox加点击动画,利用开源库nineoldandroids设置动画
*/
private void addAnimation(View view) {
float[] vaules = new float[]{0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.25f, 1.2f, 1.15f, 1.1f, 1.0f};
AnimatorSet set = new AnimatorSet();
set.playTogether(ObjectAnimator.ofFloat(view, "scaleX", vaules),
ObjectAnimator.ofFloat(view, "scaleY", vaules));
set.setDuration(150);
set.start();
}
private Animator createTranslationAnimations(View view, float startX, float endX, float startY, float endY)
{
ObjectAnimator animX = ObjectAnimator.ofFloat(view, "translationX", startX, endX);
ObjectAnimator animY = ObjectAnimator.ofFloat(view, "translationY", startY, endY);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
return animSetXY;
}
public static boolean canReverse(Animator a) {
if (a instanceof AnimatorSet) {
final ArrayList<Animator> animators = ((AnimatorSet)a).getChildAnimations();
for(Animator anim: animators) {
if(!canReverse(anim)) {
return false;
}
}
} else if (a instanceof ValueAnimator) {
return true;
}
return false;
}
private void reverse(Animator a) {
if (a instanceof AnimatorSet) {
final ArrayList<Animator> animators = ((AnimatorSet)a).getChildAnimations();
for(Animator anim: animators) {
reverse(anim);
}
} else if (a instanceof ValueAnimator) {
((ValueAnimator)a).reverse();
}
}
@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
final View view = super.getView(position, convertView, parent);
if (mInsertQueue.getActiveIndexes().contains(position)) {
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
view.measure(widthMeasureSpec, heightMeasureSpec);
int originalHeight = view.getMeasuredHeight();
ValueAnimator heightAnimator = ValueAnimator.ofInt(1, originalHeight);
heightAnimator.addUpdateListener(new HeightUpdater(view));
Animator[] customAnimators = getAdditionalAnimators(view, parent);
Animator[] animators = new Animator[customAnimators.length + 1];
animators[0] = heightAnimator;
System.arraycopy(customAnimators, 0, animators, 1, customAnimators.length);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animators);
ViewHelper.setAlpha(view, 0);
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
AnimatorSet allAnimatorsSet = new AnimatorSet();
allAnimatorsSet.playSequentially(animatorSet, alphaAnimator);
allAnimatorsSet.setDuration(mInsertionAnimationDurationMs);
allAnimatorsSet.addListener(new ExpandAnimationListener(position));
allAnimatorsSet.start();
}
return view;
}
@Override
public void onSelectChanged(View v,boolean selected) {
AnimatorSet scaleAnimator = new AnimatorSet();
float end = selected?1.2f:1f;
ObjectAnimator scaleX ;
ObjectAnimator scaleY;
scaleX = ObjectAnimator.ofFloat(v,"scaleX",end);
scaleY = ObjectAnimator.ofFloat(v,"scaleY",end);
scaleAnimator.playTogether(scaleX,scaleY);
scaleAnimator.setDuration(300);
scaleAnimator.start();
}
/**
* 过渡选中点
*
* @param imageViewStrat
* @param imageViewNext
*/
private void animPointTrans(ImageView imageViewStrat, ImageView imageViewNext) {
imageViewStrat.setImageBitmap(bmpNomal);
ObjectAnimator animFil1l = ObjectAnimator.ofFloat(imageViewStrat, "scaleX", 1.0f);
ObjectAnimator animFill2 = ObjectAnimator.ofFloat(imageViewStrat, "scaleY", 1.0f);
AnimatorSet mFillAnimatorSet = new AnimatorSet();
mFillAnimatorSet.play(animFil1l).with(animFill2);
mFillAnimatorSet.start();
imageViewNext.setImageBitmap(bmpSelect);
mPlayByInAnimatorSet.start();
}
private AnimatorSet getAnimPointIn(ImageView imageViewNext) {
ObjectAnimator animIn1 = ObjectAnimator.ofFloat(imageViewNext, "scaleX", 0.25f, 1.0f);
ObjectAnimator animIn2 = ObjectAnimator.ofFloat(imageViewNext, "scaleY", 0.25f, 1.0f);
mPlayByInAnimatorSet = new AnimatorSet();
mPlayByInAnimatorSet.play(animIn1).with(animIn2);
mPlayByInAnimatorSet.setDuration(100);
return mPlayByInAnimatorSet;
}
private AnimatorSet getAnimPointOut(ImageView imageViewStrat) {
ObjectAnimator anim1 = ObjectAnimator.ofFloat(imageViewStrat, "scaleX", 1.0f, 0.25f);
ObjectAnimator anim2 = ObjectAnimator.ofFloat(imageViewStrat, "scaleY", 1.0f, 0.25f);
mPlayByOutAnimatorSet = new AnimatorSet();
mPlayByOutAnimatorSet.play(anim1).with(anim2);
mPlayByOutAnimatorSet.setDuration(100);
return mPlayByInAnimatorSet;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.easing_activity_my);
mEasingList = (ListView) findViewById(R.id.easing_list);
mAdapter = new EasingAdapter(this);
mEasingList.setAdapter(mAdapter);
mTarget = findViewById(R.id.target);
mHistory = (DrawView) findViewById(R.id.history);
mEasingList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
mHistory.clear();
Skill s = (Skill) view.getTag();
AnimatorSet set = new AnimatorSet();
mTarget.setTranslationX(0);
mTarget.setTranslationY(0);
set.playTogether(
Glider.glide(s, 1200, ObjectAnimator.ofFloat(mTarget, "translationY", 0, dipToPixels(EasingActivity.this, -(160 - 3))), new BaseEasingMethod.EasingListener() {
@Override
public void on(float time, float value, float start, float end, float duration) {
mHistory.drawPoint(time, duration, value - dipToPixels(EasingActivity.this, 60));
}
})
);
set.setDuration(1200);
set.start();
}
});
}
public void withAnimation(final long duration) {
if (progressLayouts == null)
return;
post(new Runnable() {
@Override
public void run() {
ObjectAnimator[] animators = new ObjectAnimator[progressLayouts.size() * 2];
int i = 0;
for (LinearLayout layout : progressLayouts) {
int start;
if (isRightAlign())
start = layout.getWidth() / 2;
else
start = -layout.getWidth() / 2;
animators[i++] =
ObjectAnimator.ofFloat(
layout, "translationX",
start, 0);
animators[i++] = ObjectAnimator.ofFloat(layout, "scaleX", 0, 1f);
}
if (animators.length == 0)
return;
final AnimatorSet set = new AnimatorSet();
set.playTogether(animators);
set.setDuration(duration).start();
}
}
);
}
/**
* Show the menu;
*/
public void openMenu(int direction) {
setScaleDirection(direction);
isOpened = true;
AnimatorSet scaleDown_activity = buildScaleDownAnimation(viewActivity, mScaleValue, mScaleValue);
AnimatorSet scaleDown_shadow = buildScaleDownAnimation(imageViewShadow,
mScaleValue + shadowAdjustScaleX, mScaleValue + shadowAdjustScaleY);
AnimatorSet alpha_menu = buildMenuAnimation(scrollViewMenu, 1.0f);
scaleDown_shadow.addListener(animationListener);
scaleDown_activity.playTogether(scaleDown_shadow);
scaleDown_activity.playTogether(alpha_menu);
scaleDown_activity.start();
}