public void backTopAndCenterWithAnimation() { mStepLayout.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= 11) { float centerHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height); ObjectAnimator centerAnimator = ObjectAnimator.ofFloat(mCenterLayoutParent, "y", -centerHeight, 0f); centerAnimator.setDuration(ANIMATION_TIME); centerAnimator.start(); float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height); ObjectAnimator topAnimator = ObjectAnimator.ofFloat(mFirstTopView, "y", -topHeight, 0f); topAnimator.setDuration(ANIMATION_TIME); topAnimator.start(); } else { mFirstTopView.setVisibility(View.VISIBLE); float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height); float bottomHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_bottom_height); mCenterLayoutParent.setPadding( mCenterLayoutParent.getPaddingLeft(), Math.round(topHeight), mCenterLayoutParent.getPaddingRight(), Math.round(bottomHeight)); } }
private void startTrans() { ObjectAnimator animator = ObjectAnimator.ofFloat(this, "translationX", 0, width / 3); animator.setDuration(200); animator.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator2 = ObjectAnimator.ofFloat(this, "translationX", width / 3, -width / 4); animator2.setDuration(200); animator2.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator3 = ObjectAnimator.ofFloat(this, "translationX", -width / 4, width / 5); animator3.setDuration(200); animator3.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator4 = ObjectAnimator.ofFloat(this, "translationX", width / 5, -width / 6); animator4.setDuration(200); animator4.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator5 = ObjectAnimator.ofFloat(this, "translationX", -width / 6, 0); animator5.setDuration(200); animator5.setInterpolator(new DecelerateInterpolator()); AnimatorSet set = new AnimatorSet(); List<Animator> items = new ArrayList<Animator>(); items.add(animator); items.add(animator2); items.add(animator3); items.add(animator4); items.add(animator5); set.playSequentially(items); set.start(); }
/** * ��ת���� * * @param one * @param two */ private void flipit(View one, View two) { final View visible; final View invisible; if (one.getVisibility() == View.GONE) { visible = two; invisible = one; } else { invisible = two; visible = one; } ObjectAnimator visToInvis = ObjectAnimator.ofFloat(visible, "rotationY", 0f, 90f); visToInvis.setDuration(500); visToInvis.setInterpolator(accelerator); final ObjectAnimator invisToVis = ObjectAnimator.ofFloat(invisible, "rotationY", -90f, 0f); invisToVis.setDuration(500); invisToVis.setInterpolator(decelerator); visToInvis.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator anim) { visible.setVisibility(View.GONE); invisToVis.start(); invisible.setVisibility(View.VISIBLE); } }); visToInvis.start(); }
private void stopAnimator() { ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(this, "scaleX", 1, 0); ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, "scaleY", 1, 0); scaleXAnimator.setDuration(300); scaleXAnimator.setInterpolator(new LinearInterpolator()); scaleYAnimator.setDuration(300); scaleYAnimator.setInterpolator(new LinearInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(scaleXAnimator, scaleYAnimator); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { isStart = false; } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
/** Return to initial state */ public void finish(int finishMode) { if (!mAttached) { return; } mTextHint.setVisibility(View.GONE); if (finishMode == FINISH_SLIDE_OUT) { PropertyValuesHolder slideX = PropertyValuesHolder.ofFloat( "translationX", new float[] {0.0f, mScreenshotView.getWidth()}); mSlideoutAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, slideX); mSlideoutAnimator.setInterpolator(new AccelerateInterpolator()); mSlideoutAnimator.setDuration(SLIDE_OUT_DURATION_MS); mSlideoutAnimator.addListener(this); mSlideoutAnimator.start(); } else { float currentScale = mScreenshotView.getScaleX(); float currentAlpha = mScreenshotView.getAlpha(); PropertyValuesHolder scaleUpX = PropertyValuesHolder.ofFloat("scaleX", new float[] {currentScale, 1.0f}); PropertyValuesHolder scaleUpY = PropertyValuesHolder.ofFloat("scaleY", new float[] {currentScale, 1.0f}); PropertyValuesHolder scaleUpAlpha = PropertyValuesHolder.ofFloat("alpha", new float[] {currentAlpha, 1.0f}); mScaleUpAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY, scaleUpAlpha); mScaleUpAnimator.setInterpolator(new DecelerateInterpolator()); mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS); mScaleUpAnimator.addListener(this); mScaleUpAnimator.start(); } }
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) return false; switch (event.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (!knobState) { innerContentAnimator = ObjectAnimator.ofFloat(AnSwitch.this, innerContentProperty, innerContentRate, 1.0F); innerContentAnimator.setDuration(300L); innerContentAnimator.setInterpolator(new DecelerateInterpolator()); innerContentAnimator.start(); } knobExpandAnimator = ObjectAnimator.ofFloat(AnSwitch.this, knobExpandProperty, knobExpandRate, 0.0F); knobExpandAnimator.setDuration(300L); knobExpandAnimator.setInterpolator(new DecelerateInterpolator()); knobExpandAnimator.start(); mIsChecked = knobState; if (AnSwitch.this.onSwitchStateChangeListener != null && mIsChecked != preIsOn) { AnSwitch.this.onSwitchStateChangeListener.onSwitchStateChange(mIsChecked); } break; } return gestureDetector.onTouchEvent(event); }
// 初始化歌曲列表 private void initLocalMusicList() { // fileInfos = MediaUtil.getFileInfos(getApplicationContext()); //获取歌曲对象集合 setListAdpter(MediaUtil.getMusicMaps(fileInfos)); // 显示歌曲列表 music_siger_tv.setText(fileInfos.get(listPosition).getArtist()); music_name_tv.setText(fileInfos.get(listPosition).getTitle()); music_play_bt.setPressed(play_bt_press); music_play_bt.setChecked(play_bt_check); anim = ObjectAnimator.ofFloat(music_album_iv, "rotation", 0, 360); lin = new LinearInterpolator(); anim.setDuration(6000); anim.setRepeatCount(-1); anim.setRepeatMode(ObjectAnimator.RESTART); anim.setInterpolator(lin); // 匀速 PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f); PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 0, 1f); PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 0, 1f); animSongName = ObjectAnimator.ofPropertyValuesHolder(music_name_tv, pvhX, pvhY, pvhZ); // 渐现 animSongName.setDuration(1000); animSongName.setRepeatCount(0); animSongName.setRepeatMode(ObjectAnimator.RESTART); animSongSinger = ObjectAnimator.ofPropertyValuesHolder(music_siger_tv, pvhX, pvhY, pvhZ); // 渐现 animSongSinger.setDuration(1000); animSongSinger.setRepeatCount(0); animSongSinger.setRepeatMode(ObjectAnimator.RESTART); }
private void setupAnimations() { mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, 360f); mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR); mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION); mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, mSweepProperty, 360f - MIN_SWEEP_ANGLE * 2); mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR); mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION); mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) {} @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) { toggleAppearingMode(); } }); }
private void flip(final View v1, final View v2, final boolean scale, boolean reverse) { final int duration = 300; final int degree = reverse ? 90 : -90; final int degree2 = -degree; final ObjectAnimator a, b; if (!scale) { a = ObjectAnimator.ofFloat(v1, "rotationY", 0, degree); b = ObjectAnimator.ofFloat(v2, "rotationY", degree2, 0); } else { final float scaleX = 0.5f; final float scaleY = 0.5f; a = ObjectAnimator.ofPropertyValuesHolder( v1, PropertyValuesHolder.ofFloat("rotationY", 0, degree), PropertyValuesHolder.ofFloat("scaleX", 1, scaleX), PropertyValuesHolder.ofFloat("scaleY", 1, scaleY)); b = ObjectAnimator.ofPropertyValuesHolder( v2, PropertyValuesHolder.ofFloat("rotationY", degree2, 0), PropertyValuesHolder.ofFloat("scaleX", scaleX, 1), PropertyValuesHolder.ofFloat("scaleY", scaleY, 1)); } a.setInterpolator(new LinearInterpolator()); b.setInterpolator(new LinearInterpolator()); a.setDuration(duration); b.setDuration(duration); a.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { v1.setVisibility(View.GONE); v2.setVisibility(View.VISIBLE); if (scale) { // 恢复scale v1.setScaleX(1); v1.setScaleY(1); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); v1.setVisibility(View.VISIBLE); v2.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.play(a).before(b); set.start(); }
public ShSwitchView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShSwitchView); tintColor = ta.getColor(R.styleable.ShSwitchView_tintColor, 0xFF9CE949); tempTintColor = tintColor; int defaultOuterStrokeWidth = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 1.5F, context.getResources().getDisplayMetrics()); int defaultShadowSpace = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 5, context.getResources().getDisplayMetrics()); outerStrokeWidth = ta.getDimensionPixelOffset( R.styleable.ShSwitchView_outerStrokeWidth, defaultOuterStrokeWidth); shadowSpace = ta.getDimensionPixelOffset(R.styleable.ShSwitchView_shadowSpace, defaultShadowSpace); ta.recycle(); knobBound = new RectF(); innerContentBound = new RectF(); ovalForPath = new RectF(); tempForRoundRect = new RectF(); paint = new Paint(Paint.ANTI_ALIAS_FLAG); roundRectPath = new Path(); gestureDetector = new GestureDetector(context, gestureListener); gestureDetector.setIsLongpressEnabled(false); if (Build.VERSION.SDK_INT >= 11) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } innerContentAnimator = ObjectAnimator.ofFloat(ShSwitchView.this, innerContentProperty, innerContentRate, 1.0F); innerContentAnimator.setDuration(commonDuration); innerContentAnimator.setInterpolator(new DecelerateInterpolator()); knobExpandAnimator = ObjectAnimator.ofFloat(ShSwitchView.this, knobExpandProperty, knobExpandRate, 1.0F); knobExpandAnimator.setDuration(commonDuration); knobExpandAnimator.setInterpolator(new DecelerateInterpolator()); knobMoveAnimator = ObjectAnimator.ofFloat(ShSwitchView.this, knobMoveProperty, knobMoveRate, 1.0F); knobMoveAnimator.setDuration(commonDuration); knobMoveAnimator.setInterpolator(new DecelerateInterpolator()); shadowDrawable = context.getResources().getDrawable(R.drawable.shadow); }
public void moveTopAndCenterToUpWithAnimation() { if (Build.VERSION.SDK_INT >= 11) { float centerMoveHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height); mStepLayout.setVisibility(View.INVISIBLE); ObjectAnimator centerAnimator = ObjectAnimator.ofFloat(mCenterLayoutParent, "y", 0f, -centerMoveHeight); centerAnimator.setDuration(ANIMATION_TIME); centerAnimator.start(); float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height); ObjectAnimator topAnimator = ObjectAnimator.ofFloat(mFirstTopView, "y", 0f, -topHeight); topAnimator.setDuration(ANIMATION_TIME); topAnimator.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) {} @Override public void onAnimationEnd(Animator animator) { mActivity.runOnUiThread( new Runnable() { @Override public void run() { if (null != mMenuListener) { mMenuListener.onShowSecondAnimationEnd(); } } }); } @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); topAnimator.start(); } else { mStepLayout.setVisibility(View.INVISIBLE); mFirstTopView.setVisibility(View.GONE); int centerMoveHeight = Math.round( mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height)); mCenterLayoutParent.setPadding( mCenterLayoutParent.getPaddingLeft(), mCenterLayoutParent.getPaddingTop() - centerMoveHeight, mCenterLayoutParent.getPaddingRight(), centerMoveHeight + mCenterLayoutParent.getPaddingBottom()); if (null != mMenuListener) { mMenuListener.onShowSecondAnimationEnd(); } } }
private void startAnimator() { ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(this, "scaleX", 0.0f, 1); ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, "scaleY", 0.0f, 1); scaleXAnimator.setDuration(300); scaleXAnimator.setInterpolator(new LinearInterpolator()); scaleYAnimator.setDuration(300); scaleYAnimator.setInterpolator(new LinearInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(scaleXAnimator, scaleYAnimator); animatorSet.start(); }
public static void animateShowing( final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) { final CheckBox checkBox = holder.checkBox; if (checkBox.getVisibility() == View.VISIBLE) { return; } checkBox.setVisibility(View.VISIBLE); checkBox.setAlpha(0.0f); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); checkBox.measure(widthSpec, heightSpec); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams(); final long transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; if (!isAnimate) { checkBox.setAlpha(1.0f); holder.contentLayout.setTranslationX(transValue); return; } final ObjectAnimator transBodyAnimator = new ObjectAnimator(); final PropertyValuesHolder trans = PropertyValuesHolder.ofFloat("TranslationX", 0.0f, transValue); transBodyAnimator.setTarget(holder.contentLayout); transBodyAnimator.setValues(trans); transBodyAnimator.setDuration(DURATION); ObjectAnimator checkBoxAnim = new ObjectAnimator(); final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 0.0f, 1.0f); final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 0.0f, 1.0f); final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 0.0f, 1.0f); checkBoxAnim.setValues(scaleX, scaleY, alpha); checkBoxAnim.setTarget(holder.checkBox); checkBoxAnim.setDuration(DURATION); checkBoxAnim.setInterpolator(new DecelerateInterpolator()); checkBoxAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { checkBox.setTag("animating"); } @Override public void onAnimationEnd(Animator animation) { // adapter.setCheckBoxAnimator(false); checkBox.setTag("animated"); } }); if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) { // 若正在播放动画,则不继续播放动画 transBodyAnimator.start(); checkBoxAnim.start(); } }
public static void animateHiding( final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) { final CheckBox checkBox = holder.checkBox; final View tansBody = holder.contentLayout; if (checkBox.getVisibility() == View.GONE) { return; } ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams(); final float transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; if (!isAnimate) { checkBox.setVisibility(View.GONE); holder.contentLayout.setTranslationX(0.0f); return; } final ObjectAnimator transBodyAnimator = new ObjectAnimator(); final PropertyValuesHolder trans = PropertyValuesHolder.ofFloat("TranslationX", transValue, 0.0f); transBodyAnimator.setTarget(tansBody); transBodyAnimator.setValues(trans); transBodyAnimator.setDuration(DURATION); ObjectAnimator checkBoxAnim = new ObjectAnimator(); final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 1.0f, 0.0f); final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 1.0f, 0.0f); final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 1.0f, 0.0f); checkBoxAnim.setValues(scaleX, scaleY, alpha); checkBoxAnim.setTarget(checkBox); checkBoxAnim.setDuration(DURATION); checkBoxAnim.setInterpolator(new AccelerateInterpolator()); checkBoxAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { checkBox.setTag("animating"); } @Override public void onAnimationEnd(Animator animation) { // adapter.setCheckBoxAnimator(false); checkBox.setScaleX(1.0f); checkBox.setScaleY(1.0f); checkBox.setAlpha(1.0f); checkBox.setVisibility(View.GONE); checkBox.setTag("animated"); } }); if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) { transBodyAnimator.start(); checkBoxAnim.start(); } }
private void animBottom(View v) { ObjectAnimator animator_x = ObjectAnimator.ofFloat(v, View.ALPHA, 0f, 1f); animator_x.setDuration(ANIMATION_DURATION_BASE * 2); int y = v.getTop(); if (mStart) y += vh.ll_parent.getPaddingTop(); ObjectAnimator animator_y = ObjectAnimator.ofFloat(v, "y", +1400, y); animator_y.setDuration(ANIMATION_DURATION_BASE); AnimatorSet set = new AnimatorSet(); set.setInterpolator(new LinearInterpolator()); set.playTogether(animator_x, animator_y); set.start(); }
@Override public void onClick(View v) { if (mViewPager.getCurrentItem() == 0) { ObjectAnimator anim = ObjectAnimator.ofFloat(v, "rotation", 360.0f, 315.0f); anim.setDuration(200); anim.start(); mViewPager.setCurrentItem(1); } else { ObjectAnimator anim = ObjectAnimator.ofFloat(v, "rotation", 315.0f, 360.0f); anim.setDuration(200); anim.start(); mViewPager.setCurrentItem(0); } }
private void scaleToNormal(View item) { if (animatorSet == null) { return; } if (animatorSet.isRunning()) { animatorSet.cancel(); } ObjectAnimator oa = ObjectAnimator.ofFloat(item, "ScaleX", 1f); oa.setDuration(durationSmall); oa.start(); ObjectAnimator oa2 = ObjectAnimator.ofFloat(item, "ScaleY", 1f); oa2.setDuration(durationSmall); oa2.start(); }
public void animateClosed() { if (!(getParent() instanceof DragLayer)) return; ObjectAnimator oa; if (mMode == PARTIAL_GROW) { PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); } else { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", mIconRect.width()); PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", mIconRect.height()); PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", mIconRect.left); PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", mIconRect.top); oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y); oa.addUpdateListener( new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { requestLayout(); } }); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); ObjectAnimator alphaOa = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha); alphaOa.setDuration(mExpandDuration); alphaOa.setInterpolator(new DecelerateInterpolator(2.0f)); alphaOa.start(); } oa.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { onCloseComplete(); mState = STATE_SMALL; } @Override public void onAnimationStart(Animator animation) { sendCustomAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getContext().getString(R.string.folder_closed)); mState = STATE_ANIMATING; } }); oa.setDuration(mExpandDuration); oa.start(); }
/** 上抛 */ public void upThrow() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shapeLoadingView, "translationY", mDistance, 0); ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 0.2f, 1); ObjectAnimator objectAnimator1 = null; switch (shapeLoadingView.getShape()) { case SHAPE_RECT: objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, -120); break; case SHAPE_CIRCLE: objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, 180); break; case SHAPE_TRIANGLE: objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, 180); break; } objectAnimator.setDuration(ANIMATION_DURATION); objectAnimator1.setDuration(ANIMATION_DURATION); objectAnimator.setInterpolator(new DecelerateInterpolator()); objectAnimator1.setInterpolator(new DecelerateInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(ANIMATION_DURATION); animatorSet.playTogether(objectAnimator, objectAnimator1, scaleIndication); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { freeFall(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
private void fadeIn(View v) { v.setAlpha(0f); ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(v, "alpha", 1f); alphaAnimator.setDuration( v.getContext().getResources().getInteger(android.R.integer.config_mediumAnimTime)); alphaAnimator.start(); }
/** Add animations to fade a view from the specified start alpha value to end value. */ public static void addFadeAnimators( List<Animator> animators, final View view, float startAlpha, final float endAlpha, int animationDelay) { if (startAlpha == endAlpha) { return; } view.setLayerType(View.LAYER_TYPE_HARDWARE, null); view.setAlpha(startAlpha); final ObjectAnimator fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, view.getAlpha(), endAlpha); fadeAnimator.setInterpolator(sDecelerateQuintInterpolator); fadeAnimator.setDuration(sAnimationDuration); fadeAnimator.setStartDelay(animationDelay); fadeAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setAlpha(endAlpha); view.setLayerType(View.LAYER_TYPE_NONE, null); } }); animators.add(fadeAnimator); }
/** 下落 */ public void freeFall() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shapeLoadingView, "translationY", 0, mDistance); ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 1, 0.2f); objectAnimator.setDuration(ANIMATION_DURATION); objectAnimator.setInterpolator(new AccelerateInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(ANIMATION_DURATION); animatorSet.playTogether(objectAnimator, scaleIndication); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { shapeLoadingView.changeShape(); upThrow(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
public void rotateLogo() { btnScan.setText(ctx.getString(R.string.stop_scan)); if (logoAnimator != null) logoAnimator.cancel(); logoAnimator = ObjectAnimator.ofFloat(imgLogo, "rotation", 0, 360); logoAnimator.setDuration(200); logoAnimator.setInterpolator(new AccelerateInterpolator()); logoAnimator.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { if (!pleaseStop) { rotateLogo(); } else { pleaseStop = false; resetLogo(); Log.w(LOG, "#### not repeating the logo anim anymore"); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); // logoAnimator.start(); // flashAccuracy(); }
private ObjectAnimator buildClosingAnimation() { ObjectAnimator rotationAnimator = initAnimator( ObjectAnimator.ofFloat( mGuillotineView, ROTATION, GUILLOTINE_OPENED_ANGLE, GUILLOTINE_CLOSED_ANGLE)); rotationAnimator.setDuration((long) (mDuration * GuillotineInterpolator.ROTATION_TIME)); rotationAnimator.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { isClosing = true; mGuillotineView.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { isClosing = false; mGuillotineView.setVisibility(View.GONE); startActionBarAnimation(); if (mListener != null) { mListener.onGuillotineClosed(); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); return rotationAnimator; }
private ObjectAnimator buildOpeningAnimation() { ObjectAnimator rotationAnimator = initAnimator( ObjectAnimator.ofFloat( mGuillotineView, ROTATION, GUILLOTINE_CLOSED_ANGLE, GUILLOTINE_OPENED_ANGLE)); rotationAnimator.setInterpolator(mInterpolator); rotationAnimator.setDuration(mDuration); rotationAnimator.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { mGuillotineView.setVisibility(View.VISIBLE); isOpening = true; } @Override public void onAnimationEnd(Animator animation) { isOpening = false; if (mListener != null) { mListener.onGuillotineOpened(); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); return rotationAnimator; }
// 开始动画 private void startAnim() { // 遍历第一个不是主菜单的ImageView列表 for (int i = 1; i < res.length; i++) { // 获取展开角度 float angle = (90 * 1.0f / (res.length - 2)) * (i - 1); // 获取X位移 PropertyValuesHolder holder1 = PropertyValuesHolder.ofFloat( "translationX", 0, (float) (Math.sin((angle * 1.57 / 90)) * 200)); // 获取Y位移 PropertyValuesHolder holder2 = PropertyValuesHolder.ofFloat( "translationY", 0, (float) (Math.cos((angle * 1.57 / 90)) * 200)); // 设置ImageView的属性动画 ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageViewList.get(i), holder1, holder2); // ObjectAnimator animator = // ObjectAnimator.ofFloat(imageViewList.get(i), "translationY", 0, i * // 60); // 动画时间 animator.setDuration(1000); // 动画延迟时间 animator.setFrameDelay(500 * i); // 设置加速器 animator.setInterpolator(new BounceInterpolator()); // 启动动画 animator.start(); isNotExpand = false; } }
private void animateButton(View loginButton) { loginButton.setScaleX(0f); loginButton.setScaleY(0f); loginButton.setAlpha(0f); ObjectAnimator animator1 = ObjectAnimator.ofFloat(loginButton, "alpha", 1f); animator1.setDuration(1000); ObjectAnimator animator2 = ObjectAnimator.ofFloat(loginButton, "scaleX", 1f); animator2.setDuration(1000); ObjectAnimator animator3 = ObjectAnimator.ofFloat(loginButton, "scaleY", 1f); animator3.setDuration(1000); AnimatorSet set = new AnimatorSet(); set.play(animator1).with(animator2).with(animator3); set.start(); }
@Override public void setWeekParams(HashMap<String, Integer> params, String tz) { super.setWeekParams(params, tz); if (params.containsKey(VIEW_PARAMS_ORIENTATION)) { mOrientation = params.get(VIEW_PARAMS_ORIENTATION); } updateToday(tz); mNumCells = mNumDays + 1; if (params.containsKey(VIEW_PARAMS_ANIMATE_TODAY) && mHasToday) { synchronized (mAnimatorListener) { if (mTodayAnimator != null) { mTodayAnimator.removeAllListeners(); mTodayAnimator.cancel(); } mTodayAnimator = ObjectAnimator.ofInt(this, "animateTodayAlpha", Math.max(mAnimateTodayAlpha, 80), 255); mTodayAnimator.setDuration(150); mAnimatorListener.setAnimator(mTodayAnimator); mAnimatorListener.setFadingIn(true); mTodayAnimator.addListener(mAnimatorListener); mAnimateToday = true; mTodayAnimator.start(); } } }
public void animateClosed() { if (!(getParent() instanceof DragLayer)) return; PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); oa.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { onCloseComplete(); setLayerType(LAYER_TYPE_NONE, null); mState = STATE_SMALL; } @Override public void onAnimationStart(Animator animation) { sendCustomAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getContext().getString(R.string.folder_closed)); mState = STATE_ANIMATING; } }); oa.setDuration(mExpandDuration); setLayerType(LAYER_TYPE_HARDWARE, null); oa.start(); }
public static Animator createIndeterminateRotation(Object paramObject) { paramObject = ObjectAnimator.ofFloat(paramObject, "rotation", new float[] {0.0F, 720.0F}); ((ObjectAnimator) paramObject).setDuration(6665L); ((ObjectAnimator) paramObject).setInterpolator(Interpolators.LINEAR.INSTANCE); ((ObjectAnimator) paramObject).setRepeatCount(-1); return (Animator) paramObject; }