Java Code Examples for android.animation.ObjectAnimator#setRepeatMode()

The following examples show how to use android.animation.ObjectAnimator#setRepeatMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WaveDrawable.java    From WaveDrawable with Apache License 2.0 6 votes vote down vote up
private Animator generateAnimation() {

        //Wave animation
        ObjectAnimator waveAnimator = ObjectAnimator.ofFloat(this, "waveScale", 0f, 1f);
        waveAnimator.setDuration(animationTime);
        if (waveInterpolator != null) {
            waveAnimator.setInterpolator(waveInterpolator);
        }
        //The animation is repeated
        waveAnimator.setRepeatCount(Animation.INFINITE);
        waveAnimator.setRepeatMode(Animation.INFINITE);

        //alpha animation
        ObjectAnimator alphaAnimator = ObjectAnimator.ofInt(this, "alpha", 255, 0);
        alphaAnimator.setDuration(animationTime);
        if (alphaInterpolator != null) {
            alphaAnimator.setInterpolator(alphaInterpolator);
        }
        alphaAnimator.setRepeatCount(Animation.INFINITE);
        alphaAnimator.setRepeatMode(Animation.INFINITE);

        animatorSet.playTogether(waveAnimator, alphaAnimator);

        return animatorSet;
    }
 
Example 2
Source File: PropertyAnimationActivity.java    From Android-Animation-Set with Apache License 2.0 6 votes vote down vote up
/**
 * ObjectAnimator usage
 *
 * @param b
 * @return
 */
public ObjectAnimator getObjectAnimator(boolean b) {
    if (b) {
        ObjectAnimator bgColorAnimator = ObjectAnimator.ofArgb(mPuppet,
                "backgroundColor",
                0xff009688, 0xff795548);
        bgColorAnimator.setRepeatCount(1);
        bgColorAnimator.setDuration(3000);
        bgColorAnimator.setRepeatMode(ValueAnimator.REVERSE);
        bgColorAnimator.setStartDelay(0);
        return bgColorAnimator;
    } else {
        ObjectAnimator rotationXAnimator = ObjectAnimator.ofFloat(mPuppet,
                "rotationX",
                0f, 360f);
        rotationXAnimator.setRepeatCount(1);
        rotationXAnimator.setDuration(3000);
        rotationXAnimator.setRepeatMode(ValueAnimator.REVERSE);
        return rotationXAnimator;
    }
}
 
Example 3
Source File: ObjectPropertyAnimActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
public void startSkewAnimation(View v) {
    float scale = (float)mShowAnimIV.getHeight()/(float)mShowAnimIV.getDrawable().getIntrinsicHeight();
    Matrix from = new Matrix();
    from.setScale(scale, scale);
    from.postSkew(-0.5f, 0.0f);
    Matrix to = new Matrix(mShowAnimIV.getMatrix());
    to.setScale(scale, scale);
    to.postSkew(0.5f, 0.0f);

    mShowAnimIV.setScaleType(ImageView.ScaleType.MATRIX);
    Matrix start = new Matrix();
    start.setScale(scale, scale);
    mShowAnimIV.setImageMatrix(start);

    ObjectAnimator objectAnimator = ObjectAnimator.ofObject(mShowAnimIV, "imageMatrix", new MatrixEvaluator(), from, to);
    objectAnimator.setDuration(C.Int.ANIM_DURATION);
    objectAnimator.setRepeatCount(5);
    objectAnimator.setRepeatMode(ObjectAnimator.REVERSE);
    objectAnimator.start();
}
 
Example 4
Source File: RocketAvatarsAnimator.java    From welcome-coordinator with Apache License 2.0 5 votes vote down vote up
private Animator getFlameAnimator(View targetView) {
    AnimatorSet animator = new AnimatorSet();
    animator.setDuration(1000);
    animator.setInterpolator(new LinearInterpolator());
    ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(targetView, View.ALPHA, 0f, 1f, 0.5f, 1f, 0.8f, 1f);
    ObjectAnimator scaleAnimator = ObjectAnimator.ofFloat(targetView, View.SCALE_Y, 0.8f, 1f, 0.9f, 1f, 0.7f, 1f);
    alphaAnimator.setRepeatCount(ValueAnimator.INFINITE);
    alphaAnimator.setRepeatMode(ValueAnimator.REVERSE);
    scaleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    scaleAnimator.setRepeatMode(ValueAnimator.REVERSE);
    animator.playTogether(alphaAnimator, scaleAnimator);
    return animator;
}
 
Example 5
Source File: Card.java    From android-play-places with Apache License 2.0 5 votes vote down vote up
/**
 * Set the UI state. The parameter describes the state and must be either
 * {@link #CARD_STATE_NORMAL}, {@link #CARD_STATE_FOCUSED} or {@link #CARD_STATE_INACTIVE}.
 * Note: This method must be called from the UI Thread.
 * @param state
 * @return The card itself, allows for chaining of calls
 */
public Card setState(int state) {
    mCardState = state;
    if (null != mOverlayView) {
        if (null != mOngoingAnimator) {
            mOngoingAnimator.end();
            mOngoingAnimator = null;
        }
        switch (state) {
            case CARD_STATE_NORMAL: {
                mOverlayView.setVisibility(View.GONE);
                mOverlayView.setAlpha(1.f);
                break;
            }
            case CARD_STATE_FOCUSED: {
                mOverlayView.setVisibility(View.VISIBLE);
                mOverlayView.setBackgroundResource(R.drawable.card_overlay_focused);
                ObjectAnimator animator = ObjectAnimator.ofFloat(mOverlayView, "alpha", 0.f);
                animator.setRepeatMode(ObjectAnimator.REVERSE);
                animator.setRepeatCount(ObjectAnimator.INFINITE);
                animator.setDuration(1000);
                animator.start();
                mOngoingAnimator = animator;
                break;
            }
            case CARD_STATE_INACTIVE: {
                mOverlayView.setVisibility(View.VISIBLE);
                mOverlayView.setAlpha(1.f);
                mOverlayView.setBackgroundColor(Color.argb(0xaa, 0xcc, 0xcc, 0xcc));
                break;
            }
        }
    }
    return this;
}
 
Example 6
Source File: WaveHelper.java    From WaveView with Apache License 2.0 5 votes vote down vote up
private void initAnimation() {
    List<Animator> animators = new ArrayList<>();

    // horizontal animation.
    // wave waves infinitely.
    ObjectAnimator waveShiftAnim = ObjectAnimator.ofFloat(
            mWaveView, "waveShiftRatio", 0f, 1f);
    waveShiftAnim.setRepeatCount(ValueAnimator.INFINITE);
    waveShiftAnim.setDuration(1000);
    waveShiftAnim.setInterpolator(new LinearInterpolator());
    animators.add(waveShiftAnim);

    // vertical animation.
    // water level increases from 0 to center of WaveView
    ObjectAnimator waterLevelAnim = ObjectAnimator.ofFloat(
            mWaveView, "waterLevelRatio", 0f, 0.5f);
    waterLevelAnim.setDuration(10000);
    waterLevelAnim.setInterpolator(new DecelerateInterpolator());
    animators.add(waterLevelAnim);

    // amplitude animation.
    // wave grows big then grows small, repeatedly
    ObjectAnimator amplitudeAnim = ObjectAnimator.ofFloat(
            mWaveView, "amplitudeRatio", 0.0001f, 0.05f);
    amplitudeAnim.setRepeatCount(ValueAnimator.INFINITE);
    amplitudeAnim.setRepeatMode(ValueAnimator.REVERSE);
    amplitudeAnim.setDuration(5000);
    amplitudeAnim.setInterpolator(new LinearInterpolator());
    animators.add(amplitudeAnim);

    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playTogether(animators);
}
 
Example 7
Source File: ZhiActivity.java    From MiniPay with Apache License 2.0 5 votes vote down vote up
private void initData() {
    Config config = (Config) getIntent().getSerializableExtra(MiniPayUtils.EXTRA_KEY_PAY_CONFIG);
    this.wechatQaImage = config.getWechatQaImage();
    this.aliQaImage = config.getAliQaImage();
    this.wechatTip = config.getWechatTip();
    this.aliTip = config.getAliTip();
    this.aliZhiKey = config.getAliZhiKey();

    if (!checkLegal()) {
        throw new IllegalStateException("MiniPay Config illegal!!!");
    } else {
        if (TextUtils.isEmpty(wechatTip)) wechatTip = getString(R.string.wei_zhi_tip);
        if (TextUtils.isEmpty(aliTip)) aliTip = getString(R.string.ali_zhi_tip);

        mZhiBg.setBackgroundResource(R.drawable.common_bg);
        mTitleTv.setText(R.string.wei_zhi_title);
        mSummeryTv.setText(wechatTip);
        mQaImage.setImageResource(wechatQaImage);
    }

    ObjectAnimator animator = ObjectAnimator.ofFloat(mTip, "alpha", 0, 0.66f, 1.0f, 0);
    animator.setDuration(2888);
    animator.setRepeatCount(6);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.start();
}
 
Example 8
Source File: Card.java    From android-BatchStepSensor with Apache License 2.0 5 votes vote down vote up
/**
 * Set the UI state. The parameter describes the state and must be either
 * {@link #CARD_STATE_NORMAL}, {@link #CARD_STATE_FOCUSED} or {@link #CARD_STATE_INACTIVE}.
 * Note: This method must be called from the UI Thread.
 * @param state
 * @return The card itself, allows for chaining of calls
 */
public Card setState(int state) {
    mCardState = state;
    if (null != mOverlayView) {
        if (null != mOngoingAnimator) {
            mOngoingAnimator.end();
            mOngoingAnimator = null;
        }
        switch (state) {
            case CARD_STATE_NORMAL: {
                mOverlayView.setVisibility(View.GONE);
                mOverlayView.setAlpha(1.f);
                break;
            }
            case CARD_STATE_FOCUSED: {
                mOverlayView.setVisibility(View.VISIBLE);
                mOverlayView.setBackgroundResource(R.drawable.card_overlay_focused);
                ObjectAnimator animator = ObjectAnimator.ofFloat(mOverlayView, "alpha", 0.f);
                animator.setRepeatMode(ObjectAnimator.REVERSE);
                animator.setRepeatCount(ObjectAnimator.INFINITE);
                animator.setDuration(1000);
                animator.start();
                mOngoingAnimator = animator;
                break;
            }
            case CARD_STATE_INACTIVE: {
                mOverlayView.setVisibility(View.VISIBLE);
                mOverlayView.setAlpha(1.f);
                mOverlayView.setBackgroundColor(Color.argb(0xaa, 0xcc, 0xcc, 0xcc));
                break;
            }
        }
    }
    return this;
}
 
Example 9
Source File: SplashActivity.java    From LittleFreshWeather with Apache License 2.0 5 votes vote down vote up
private void startAnimation() {
    ObjectAnimator animator = ObjectAnimator.ofFloat(ivSplashIcon, "translationY", 0, -(ivSplashIcon.getHeight() >> 1));
    animator.setDuration(800);
    animator.setRepeatCount(ObjectAnimator.INFINITE);
    animator.setRepeatMode(ObjectAnimator.RESTART);
    animator.setInterpolator(new CycleInterpolator(0.5f));
    animator.start();
}
 
Example 10
Source File: FoldingLayoutActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the folding view inwards (to a completely folded state) from its
 * current state and then back out to its original state.
 */
public void animateFold() {
    float foldFactor = mFoldLayout.getFoldFactor();

    ObjectAnimator animator = ObjectAnimator.ofFloat(mFoldLayout,
            "foldFactor", foldFactor, 1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(1);
    animator.setDuration(FOLD_ANIMATION_DURATION);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.start();
}
 
Example 11
Source File: CityWeatherActivity.java    From LittleFreshWeather with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    ++mSpecialWeatherNumSnow;
    if (mSpecialWeatherNumSnow <= mSpecialWeatherNumLimitSnow) {
        int screenHeight = DensityUtil.getScreenHeight(CityWeatherActivity.this);
        int screenWidth = DensityUtil.getScreenWidth(CityWeatherActivity.this);
        int fX = mRandom.nextInt(screenWidth);

        ImageView imageView = new ImageView(CityWeatherActivity.this);
        imageView.setVisibility(View.VISIBLE);
        if ((mSpecialWeatherNumSnow & 0x1) == 0) {
            //imageView.setImageResource(mSnowIconLightId);
            mPresenter.getImageViewSrc(imageView, mSnowIconLightId);
        } else {
            //imageView.setImageResource(mSnowIconDarkId);
            mPresenter.getImageViewSrc(imageView, mSnowIconDarkId);
        }
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(fX, 0, 0, 0);
        rlBackgroundView.addView(imageView, layoutParams);

        ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "translationY", -100, screenHeight + 100);
        if ((mSpecialWeatherNumSnow & 0x1) == 0) {
            animator.setDuration(mSpecialWeatherSpeedLimitSnow);
        } else {
            animator.setDuration(mSpecialWeatherSpeedLimitSnow + RAIN_SPEED_OFFSET);
        }
        animator.setRepeatMode(ObjectAnimator.RESTART);
        animator.setRepeatCount(ObjectAnimator.INFINITE);
        animator.setInterpolator(new LinearInterpolator());
        animator.start();

        mHandler.postDelayed(snowProc, SNOW_GEN_INTERVAL);
    }
}
 
Example 12
Source File: RippleLayout.java    From TvLauncher with Apache License 2.0 5 votes vote down vote up
private void addAnimToRippleView(RippleView rippleView, int i) {

        // The X axis zoom animation
        final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "scaleX", 1.0f, mRippleScale);
        scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleXAnimator.setStartDelay(i * mAnimDelay);
        scaleXAnimator.setDuration(mAnimDuration);
        mAnimatorList.add(scaleXAnimator);

        // The Y axis zoom animation
        final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "scaleY", 1.0f, mRippleScale);
        scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleYAnimator.setStartDelay(i * mAnimDelay);
        scaleYAnimator.setDuration(mAnimDuration);
        mAnimatorList.add(scaleYAnimator);

        /**
         * The color of alpha animation
         */
        final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "alpha", 1.0f, 0f);
        alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
        alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        alphaAnimator.setDuration(mAnimDuration);
        alphaAnimator.setStartDelay(i * mAnimDelay);
        mAnimatorList.add(alphaAnimator);
    }
 
Example 13
Source File: RippleBackground.java    From RippleBackground with Apache License 2.0 4 votes vote down vote up
private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleBackground);
    int rippleColor = typedArray.getColor(R.styleable.RippleBackground_rb_color, ContextCompat.getColor(context, R.color.ripple_color));
    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));
    int rippleDuration = typedArray.getInt(R.styleable.RippleBackground_rb_duration, DEFAULT_DURATION);
    int rippleDelay = typedArray.getInt(R.styleable.RippleBackground_rb_delay, DEFAULT_DURATION);
    int rippleAmount = typedArray.getInt(R.styleable.RippleBackground_rb_rippleAmount, DEFAULT_RIPPLE_COUNT);
    float rippleScale = typedArray.getFloat(R.styleable.RippleBackground_rb_scale, DEFAULT_SCALE);
    int rippleType = typedArray.getInt(R.styleable.RippleBackground_rb_type, DEFAULT_FILL_TYPE);
    typedArray.recycle();

    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);

    LayoutParams params = new LayoutParams((int) (2 * (rippleRadius + rippleStrokeWidth)), (int) (2 * (rippleRadius + rippleStrokeWidth)));
    params.addRule(CENTER_IN_PARENT, TRUE);

    animatorSet = new AnimatorSet();
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    ArrayList<Animator> animators = new ArrayList<>();

    for (int i = 0; i < rippleAmount; i++) {
        RippleView rippleView = new RippleView(context);
        addView(rippleView, params);
        list.add(rippleView);

        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, View.SCALE_X, 1.0f, rippleScale);
        scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleXAnimator.setStartDelay(i * rippleDelay);
        scaleXAnimator.setDuration(rippleDuration);
        scaleXAnimator.setInterpolator(new AccelerateInterpolator());
        animators.add(scaleXAnimator);

        ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, View.SCALE_Y, 1.0f, rippleScale);
        scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleYAnimator.setStartDelay(i * rippleDelay);
        scaleYAnimator.setDuration(rippleDuration);
        scaleXAnimator.setInterpolator(new AccelerateInterpolator());
        animators.add(scaleYAnimator);

        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, View.ALPHA, 1.0f, 0f);
        alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
        alphaAnimator.setStartDelay(i * rippleDelay);
        alphaAnimator.setDuration(rippleDuration);
        scaleXAnimator.setInterpolator(new AccelerateInterpolator());
        animators.add(alphaAnimator);
    }

    animatorSet.playTogether(animators);
}
 
Example 14
Source File: RippleBackground.java    From android-ripple-background with MIT License 4 votes vote down vote up
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);
}
 
Example 15
Source File: RippleAnimationView.java    From AndroidSamples with Apache License 2.0 4 votes vote down vote up
private void init(final Context context, final AttributeSet attrs) {

        //判断View当前是否处于 IDE 布局编辑(预览)状态,只有在编辑状态下才会返回true,
        //在编写只有在运行时才能看到绘制效果的自定义View时,可以使用该方法查看布局预览。
        if (isInEditMode()) {
            return;
        }

        //加载自定义属性
        mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleAnimationView);
        mRippleType = mTypedArray.getInt(R.styleable.RippleAnimationView_ripple_anim_type, DEFAULT_FILL_TYPE);
        mRippleColor = mTypedArray.getColor(R.styleable.RippleAnimationView_ripple_anim_color, ContextCompat.getColor(context, R.color.rippleColor));
        mRippleAmount = mTypedArray.getInt(R.styleable.RippleAnimationView_ripple_anim_amount, DEFAULT_RIPPLE_COUNT);
        mRippleScale = mTypedArray.getFloat(R.styleable.RippleAnimationView_ripple_anim_scale, DEFAULT_SCALE);
        mRippleRadius = mTypedArray.getDimension(R.styleable.RippleAnimationView_ripple_anim_radius, getResources().getDimension(R.dimen.rippleRadius));
        mRippleDuration = mTypedArray.getInt(R.styleable.RippleAnimationView_ripple_anim_duration, DEFAULT_DURATION_TIME);
        mRippleStrokeWidth = mTypedArray.getDimension(R.styleable.RippleAnimationView_ripple_anim_strokeWidth, getResources().getDimension(R.dimen.rippleStrokeWidth));
        //注意回收TypedArray
        mTypedArray.recycle();

        int rippleDelay = mRippleDuration / mRippleAmount;

        mPaint = new Paint();
        //抗锯齿
        mPaint.setAntiAlias(true);
        if (mRippleType == DEFAULT_FILL_TYPE) {
            mRippleStrokeWidth = 0;
            mPaint.setStyle(Paint.Style.FILL);
        } else {
            mPaint.setStyle(Paint.Style.STROKE);
        }
        mPaint.setColor(mRippleColor);

        LayoutParams rippleParams = new LayoutParams((int) (2 * (mRippleRadius + mRippleStrokeWidth)), (int) (2 * (mRippleRadius + mRippleStrokeWidth)));
        rippleParams.addRule(CENTER_IN_PARENT, TRUE);

        //分析该动画后将其拆分为缩放、渐变
        ArrayList<Animator> animatorList = new ArrayList<>();
        for (int i = 0; i < mRippleAmount; i++) {

            RippleCircleView rippleView = new RippleCircleView(this, context);
            addView(rippleView, rippleParams);
            mRippleViewList.add(rippleView);
            //ScaleX缩放
            final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, mRippleScale);
            //无限重复
            scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
            scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
            scaleXAnimator.setStartDelay(i * rippleDelay);
            scaleXAnimator.setDuration(mRippleDuration);
            animatorList.add(scaleXAnimator);
            //ScaleY缩放
            final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, mRippleScale);
            //无限重复
            scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
            scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
            scaleYAnimator.setStartDelay(i * rippleDelay);
            scaleYAnimator.setDuration(mRippleDuration);
            animatorList.add(scaleYAnimator);
            //Alpha渐变
            final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
            //无限重复
            alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
            alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
            alphaAnimator.setStartDelay(i * rippleDelay);
            alphaAnimator.setDuration(mRippleDuration);
            animatorList.add(alphaAnimator);
        }

        mAnimatorSet = new AnimatorSet();
        mAnimatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
        mAnimatorSet.playTogether(animatorList);
    }
 
Example 16
Source File: PomodoroTransitionActivity.java    From WearPomodoro with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onLayoutInflated(WatchViewStub stub) {
    super.onLayoutInflated(stub);
    PomodoroAlarmReceiver.completeWakefulIntent(getIntent());
    pomodoroMaster.cancelNotification();
    vibrator.vibrate(1000);

    awesomeGif = (GifImageView) stub.findViewById(R.id.transition_awesome_gif);
    awesomeGif.setBytes(PomodoroUtils.readRawResourceBytes(getResources(), R.raw.pomodoro));
    awesomeGif.startAnimation();

    if (nextActivityType.isBreak()) {
        float dp = PomodoroUtils.dipToPixels(this, 1);
        ObjectAnimator anim = ObjectAnimator.ofFloat(awesomeGif, View.TRANSLATION_X, -8*dp, 8*dp);
        anim.setDuration(1200);
        anim.setRepeatMode(ObjectAnimator.REVERSE);
        anim.setRepeatCount(ObjectAnimator.INFINITE);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();
    }

    final TextView messageText = (TextView) stub.findViewById(R.id.transition_text);
    final int eatenPomodoros = pomodoroMaster.getEatenPomodoros();

    if (nextActivityType.isBreak()) {
        int templateId = nextActivityType == ActivityType.LONG_BREAK ?
                R.string.transition_text_before_long_break_message_template :
                R.string.transition_text_before_short_break_message_template;
        messageText.setText(String.format(
                getString(templateId),
                eatenPomodoros + 1));
        activateStepsCounter();
    } else if (nextActivityType.isPomodoro()) {
        messageText.setText(String.format(
                getString(R.string.transition_text_before_pomodoro_message_template),
                eatenPomodoros + 1));
        uiTimer.schedule(new UITimer.Task() {
            @Override
            public void run() {
                cancelTask();
                finish();
                pomodoroMaster.start(ActivityType.POMODORO);
            }
        }, 3000, "PomodoroTransitionActivity.DelayTimer");
    }
}
 
Example 17
Source File: NearbyAddContactActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nearby);

    setTitle("");

    ImageView iv = (ImageView) findViewById(R.id.nearbyIcon);
    mList = findViewById(R.id.nearbyList);
    mList.setLayoutManager(new LinearLayoutManager(this));
    mList.setItemAnimator(new DefaultItemAnimator());

    NearbyListRecyclerViewAdapter adapter = new NearbyListRecyclerViewAdapter(this,new ArrayList<Contact>(contactList.values()));
    mList.setAdapter(adapter);

    ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(
            iv,
            PropertyValuesHolder.ofFloat("scaleX", 1.2f),
            PropertyValuesHolder.ofFloat("scaleY", 1.2f));
    scaleDown.setDuration(310);
    scaleDown.setInterpolator(new FastOutSlowInInterpolator());

    scaleDown.setRepeatCount(ObjectAnimator.INFINITE);
    scaleDown.setRepeatMode(ObjectAnimator.REVERSE);

    scaleDown.start();

    mApp = (ImApp)getApplication();

    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Showing status
    if(checkPlayServices())
    {
        String nearbyMessage = getIntent().getStringExtra(EXTRA_TEXT);
        initNearby(nearbyMessage);
    }
    else
    {
        Toast.makeText(this, R.string.nearby_not_supported,Toast.LENGTH_LONG).show();
        finish();
    }
}
 
Example 18
Source File: RippleBackground.java    From SmartOrnament with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 19
Source File: OrreryActivity.java    From AnimationApiDemos with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.orrery_main);

	ImageView orrery = (ImageView) findViewById(R.id.orrery);
	OrreryDrawable myOrreryDrawable = OrreryDrawable.Create();
	orrery.setImageDrawable(myOrreryDrawable);

	// ================================================================
	// 分别控制两种属性的动画
	// PropertyValuesHolder earthPositionValues = PropertyValuesHolder
	// .ofFloat("EarthPosition", 0, (float) (2 * Math.PI));
	// PropertyValuesHolder moonPositionValues =
	// PropertyValuesHolder.ofFloat(
	// "MoonPosition", 0, (float) (2 * Math.PI * 13));
	// ObjectAnimator orreryAnimator =
	// ObjectAnimator.ofPropertyValuesHolder(
	// myOrreryDrawable, earthPositionValues, moonPositionValues);

	// ================================================================
	// 使用新的数据结构,同时控制地球和月球
	OrreryDrawable.SolarSystemData startSolarSystemData = new OrreryDrawable.SolarSystemData();
	startSolarSystemData.rotationEarth = 0;
	startSolarSystemData.rotationMoon = 0;
	OrreryDrawable.SolarSystemData endSolarSystemData = new OrreryDrawable.SolarSystemData();
	endSolarSystemData.rotationEarth = (float) (2 * Math.PI);
	endSolarSystemData.rotationMoon = (float) (2 * Math.PI * 13);
	// 使用自定义的Evaluator
	OrreryEvaluator orreryEvaluator = new OrreryEvaluator();
	// ObjectAnimator orreryAnimator = ObjectAnimator.ofObject(
	// myOrreryDrawable, "SolarSystemData", orreryEvaluator,
	// startSolarSystemData, endSolarSystemData);

	// ================================================================
	// 尝试一下Keyframe
	Keyframe startFrame = Keyframe.ofObject(0, startSolarSystemData);
	Keyframe endFrame = Keyframe.ofObject(1, endSolarSystemData);
	PropertyValuesHolder solarSystemFrames = PropertyValuesHolder
			.ofKeyframe("SolarSystemData", startFrame, endFrame);
	solarSystemFrames.setEvaluator(orreryEvaluator);

	ObjectAnimator orreryAnimator = ObjectAnimator.ofPropertyValuesHolder(
			myOrreryDrawable, solarSystemFrames);

	// Default value is 10
	Log.i("FrameDelay", "delay: " + ValueAnimator.getFrameDelay());
	ValueAnimator.setFrameDelay(50);

	orreryAnimator.setDuration(60000);
	orreryAnimator.setInterpolator(new LinearInterpolator());
	orreryAnimator.setRepeatCount(ValueAnimator.INFINITE);
	orreryAnimator.setRepeatMode(ValueAnimator.RESTART);

	orreryAnimator.start();

	// add the fragment:
	FragmentTransaction ft = getFragmentManager().beginTransaction();

	ft.setCustomAnimations(R.anim.fade_in, android.R.animator.fade_out);
	ft.add(R.id.frame, new OrreryInfo());
	ft.commit();
}
 
Example 20
Source File: RippleBackground.java    From ShowcaseView with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
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(android.R.color.holo_red_light));
    rippleStrokeWidth = typedArray.getDimension(R.styleable.RippleBackground_rb_strokeWidth, 4);
    rippleRadius = typedArray.getDimension(R.styleable.RippleBackground_rb_radius, 4);
    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);
}