android.view.animation.LinearInterpolator Java Examples

The following examples show how to use android.view.animation.LinearInterpolator. 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 Project: scene   Author: bytedance   File: Case1Scene.java    License: Apache License 2.0 7 votes vote down vote up
@NonNull
@Override
protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
    final View toView = toInfo.mSceneView;
    final View fromView = fromInfo.mSceneView;

    ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 0.0f);
    fromAlphaAnimator.setInterpolator(new LinearInterpolator());
    fromAlphaAnimator.setDuration(150 * 20);
    fromAlphaAnimator.setStartDelay(50 * 20);

    ValueAnimator fromTranslateAnimator = ObjectAnimator.ofFloat(fromView, View.TRANSLATION_Y, 0, 0.08f * toView.getHeight());
    fromTranslateAnimator.setInterpolator(new AccelerateInterpolator(2));
    fromTranslateAnimator.setDuration(200 * 20);

    ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.7f, 1.0f);
    toAlphaAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    toAlphaAnimator.setDuration(20 * 20);
    return TransitionUtils.mergeAnimators(fromAlphaAnimator, fromTranslateAnimator, toAlphaAnimator);
}
 
Example #2
Source Project: mollyim-android   Author: mollyim   File: CameraXVideoCaptureHelper.java    License: GNU General Public License v3.0 6 votes vote down vote up
CameraXVideoCaptureHelper(@NonNull Fragment fragment,
                          @NonNull CameraButtonView captureButton,
                          @NonNull CameraXView camera,
                          @NonNull MemoryFileDescriptor memoryFileDescriptor,
                          int      maxVideoDurationSec,
                          @NonNull Callback callback)
{
  this.fragment               = fragment;
  this.camera                 = camera;
  this.memoryFileDescriptor   = memoryFileDescriptor;
  this.callback               = callback;
  this.updateProgressAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(maxVideoDurationSec * 1000);

  updateProgressAnimator.setInterpolator(new LinearInterpolator());
  updateProgressAnimator.addUpdateListener(anim -> captureButton.setProgress(anim.getAnimatedFraction()));
  updateProgressAnimator.addListener(new AnimationEndCallback() {
    @Override
    public void onAnimationEnd(Animator animation) {
      if (isRecording) onVideoCaptureComplete();
    }
  });
}
 
Example #3
Source Project: scene   Author: bytedance   File: Android8DefaultSceneAnimatorExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
    if (fromInfo.mIsTranslucent) {
        return mDialogSceneAnimatorExecutor.onPopAnimator(fromInfo, toInfo);
    }
    final View toView = toInfo.mSceneView;
    final View fromView = fromInfo.mSceneView;

    ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 0.0f);
    fromAlphaAnimator.setInterpolator(new LinearInterpolator());
    fromAlphaAnimator.setDuration(150);
    fromAlphaAnimator.setStartDelay(50);

    ValueAnimator fromTranslateAnimator = ObjectAnimator.ofFloat(fromView, View.TRANSLATION_Y, 0, 0.08f * toView.getHeight());
    fromTranslateAnimator.setInterpolator(new AccelerateInterpolator(2));
    fromTranslateAnimator.setDuration(200);

    ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.7f, 1.0f);
    toAlphaAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    toAlphaAnimator.setDuration(200);
    return TransitionUtils.mergeAnimators(fromAlphaAnimator, fromTranslateAnimator, toAlphaAnimator);
}
 
Example #4
Source Project: FlowHelper   Author: LillteZheng   File: BaseAction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 放大缩小效果
 */
public void autoScaleView() {
    if (mParentView != null && mIsAutoScale && mScaleFactor > 1) {
        View lastView = mParentView.getChildAt(mLastIndex);
        View curView = mParentView.getChildAt(mCurrentIndex);
        if (lastView != null && curView != null) {
            lastView.animate()
                    .scaleX(1)
                    .scaleY(1)
                    .setDuration(mAnimTime)
                    .setInterpolator(new LinearInterpolator())
                    .start();
            curView.animate()
                    .scaleX(mScaleFactor)
                    .scaleY(mScaleFactor)
                    .setDuration(mAnimTime)
                    .setInterpolator(new LinearInterpolator())
                    .start();
        }
    }
}
 
Example #5
Source Project: ShizuruNotes   Author: MalitsPlus   File: CalendarLayout.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 隐藏内容布局
 */
@SuppressLint("NewApi")
final void hideContentView() {
    if (mContentView == null)
        return;
    mContentView.animate()
            .translationY(getHeight() - mMonthView.getHeight())
            .setDuration(220)
            .setInterpolator(new LinearInterpolator())
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mContentView.setVisibility(INVISIBLE);
                    mContentView.clearAnimation();
                }
            });
}
 
Example #6
Source Project: WanAndroid   Author: rain9155   File: SVGBgView.java    License: Apache License 2.0 6 votes vote down vote up
private void init() {
    mPathDataList = new ArrayList<>();
    mSvgRealSize = new RectF();

    mSvgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mValueAnimator = ValueAnimator.ofFloat(0);
    mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurPathDataIndex = (float) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    mValueAnimator.setInterpolator(new LinearInterpolator());
    mValueAnimator.setDuration(ANIM_TIME);

    new ParserThread().start();
}
 
Example #7
Source Project: HokoBlur   Author: HokoFly   File: MultiBlurActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setImage(@DrawableRes final int id) {
    mImageView.setImageResource(id);
    mDispatcher.submit(() -> {
        mInBitmap = BitmapFactory.decodeResource(getResources(), id);

        runOnUiThread(() -> {
            endAnimators();
            mAnimator = ValueAnimator.ofInt(0, (int) (mRadius / 25f * 1000));
            mAnimator.setInterpolator(new LinearInterpolator());
            mAnimator.addUpdateListener(animation -> {
                mSeekBar.setProgress((Integer) animation.getAnimatedValue());
                updateImage((int) ((Integer) animation.getAnimatedValue() / 1000f * 25f));
            });

            mAnimator.setDuration(300);
            mAnimator.start();
        });
    });
}
 
Example #8
Source Project: a   Author: 804463258   File: SmoothCheckBox.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void startUnCheckedAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1.0f);
    animator.setDuration(mAnimDuration);
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(animation -> {
        mScaleVal = (float) animation.getAnimatedValue();
        mFloorColor = getGradientColor(mCheckedColor, mFloorUnCheckedColor, mScaleVal);
        postInvalidate();
    });
    animator.start();

    ValueAnimator floorAnimator = ValueAnimator.ofFloat(1.0f, 0.8f, 1.0f);
    floorAnimator.setDuration(mAnimDuration);
    floorAnimator.setInterpolator(new LinearInterpolator());
    floorAnimator.addUpdateListener(animation -> {
        mFloorScale = (float) animation.getAnimatedValue();
        postInvalidate();
    });
    floorAnimator.start();
}
 
Example #9
Source Project: timecat   Author: triline3   File: ArcLayout.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 收缩动画
 */
private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, long startOffset, long duration, Interpolator interpolator) {
    AnimationSet animationSet = new AnimationSet(false);
    animationSet.setFillAfter(true);
    //收缩过程中,child 逆时针自旋转360度
    final long preDuration = duration / 2;
    Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setStartOffset(startOffset);
    rotateAnimation.setDuration(preDuration);
    rotateAnimation.setInterpolator(new LinearInterpolator());
    rotateAnimation.setFillAfter(true);

    animationSet.addAnimation(rotateAnimation);
    //收缩过程中位移,并逆时针旋转360度
    Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
    translateAnimation.setStartOffset(startOffset + preDuration);
    translateAnimation.setDuration(duration - preDuration);
    translateAnimation.setInterpolator(interpolator);
    translateAnimation.setFillAfter(true);

    animationSet.addAnimation(translateAnimation);

    return animationSet;
}
 
Example #10
Source Project: SchoolQuest   Author: Mini-Weav   File: LessonB.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void setUpSliderAnimation() {
    GameActivity gameActivity = GameActivity.getInstance();

    ImageView slider = gameActivity.findViewById(R.id.lesson_b_craft_bar_slider);
    ImageView craftBar = gameActivity.findViewById(R.id.lesson_b_craft_bar);

    int craftBarWidth = craftBar.getDrawable().getIntrinsicWidth();

    ObjectAnimator sliderAnimation = ObjectAnimator.ofFloat(slider, "translationX",
            -(craftBarWidth / 2) + (craftBarWidth / 27),
            (craftBarWidth / 2) - (craftBarWidth / 27));

    int baseSliderTime = 250;
    sliderAnimation.setDuration(baseSliderTime + (attn * baseSliderTime));
    sliderAnimation.setRepeatCount(-1);
    sliderAnimation.setRepeatMode(ValueAnimator.REVERSE);
    sliderAnimation.setInterpolator(new LinearInterpolator());

    sliderAnimation.start();
}
 
Example #11
Source Project: YCAudioPlayer   Author: yangchong211   File: YCLrcCustomView.java    License: Apache License 2.0 6 votes vote down vote up
private void scrollTo(int line, long duration) {
    float offset = getOffset(line);
    endAnimation();

    mAnimator = ValueAnimator.ofFloat(mOffset, offset);
    mAnimator.setDuration(duration);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mOffset = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    mAnimator.start();
}
 
Example #12
Source Project: wallpaper   Author: kysonzhu   File: PullToRefreshView.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * init
 * 
 * @description
 * @param context
 *            hylin 2012-7-26上午10:08:33
 */
private void init() {
	// Load all of the animations we need in code rather than through XML
	mFlipAnimation = new RotateAnimation(0, -180,
			RotateAnimation.RELATIVE_TO_SELF, 0.5f,
			RotateAnimation.RELATIVE_TO_SELF, 0.5f);
	mFlipAnimation.setInterpolator(new LinearInterpolator());
	mFlipAnimation.setDuration(250);
	mFlipAnimation.setFillAfter(true);
	mReverseFlipAnimation = new RotateAnimation(-180, 0,
			RotateAnimation.RELATIVE_TO_SELF, 0.5f,
			RotateAnimation.RELATIVE_TO_SELF, 0.5f);
	mReverseFlipAnimation.setInterpolator(new LinearInterpolator());
	mReverseFlipAnimation.setDuration(250);
	mReverseFlipAnimation.setFillAfter(true);

	mInflater = LayoutInflater.from(getContext());
	// header view 在此添加,保证是第一个添加到linearlayout的最上端
	addHeaderView();
}
 
Example #13
Source Project: MyBookshelf   Author: gedoor   File: SmoothCheckBox.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void startCheckedAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0f);
    animator.setDuration(mAnimDuration / 3 * 2);
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(animation -> {
        mScaleVal = (float) animation.getAnimatedValue();
        mFloorColor = getGradientColor(mUnCheckedColor, mCheckedColor, 1 - mScaleVal);
        postInvalidate();
    });
    animator.start();

    ValueAnimator floorAnimator = ValueAnimator.ofFloat(1.0f, 0.8f, 1.0f);
    floorAnimator.setDuration(mAnimDuration);
    floorAnimator.setInterpolator(new LinearInterpolator());
    floorAnimator.addUpdateListener(animation -> {
        mFloorScale = (float) animation.getAnimatedValue();
        postInvalidate();
    });
    floorAnimator.start();

    drawTickDelayed();
}
 
Example #14
Source Project: SimpleVideoEdit   Author: zhanghuicuc   File: TrimmerActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void anim() {
    Log.d(TAG, "--anim--onProgressUpdate---->>>>>>>" + mPlayer.getCurrentPosition());
    if (positionIcon.getVisibility() == View.GONE) {
        positionIcon.setVisibility(View.VISIBLE);
    }
    final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) positionIcon.getLayoutParams();
    int start = (int) (UIUtil.dip2px(this, INIT_THUMBVIEW_GAP) + (mStartPositionMs/*mVideoView.getCurrentPosition()*/ - scrolledMs) * pxPerMs);
    int end = (int) (UIUtil.dip2px(this, INIT_THUMBVIEW_GAP) + (mEndPositionMs - scrolledMs) * pxPerMs);
    animator = ValueAnimator
            .ofInt(start, end)
            .setDuration((mEndPositionMs - scrolledMs) - (mStartPositionMs/*mVideoView.getCurrentPosition()*/ - scrolledMs));
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            params.leftMargin = (int) animation.getAnimatedValue();
            positionIcon.setLayoutParams(params);
        }
    });
    animator.start();
}
 
Example #15
Source Project: mollyim-android   Author: mollyim   File: MicrophoneRecorderView.java    License: GNU General Public License v3.0 5 votes vote down vote up
void hide() {
  lockDropTarget.animate()
                .setStartDelay(0)
                .setDuration(ANIMATION_DURATION)
                .setInterpolator(new LinearInterpolator())
                .scaleX(0).scaleY(0)
                .start();
}
 
Example #16
Source Project: MyBookshelf   Author: gedoor   File: PageAnimation.java    License: GNU General Public License v3.0 5 votes vote down vote up
PageAnimation(int w, int h, int marginWidth, int marginTop, int marginBottom, View view, OnPageChangeListener listener) {
    mScreenWidth = w;
    mScreenHeight = h;

    //屏幕的间距
    mMarginTop = marginTop;

    mViewWidth = mScreenWidth - marginWidth * 2;
    mViewHeight = mScreenHeight - mMarginTop - marginBottom;

    mView = view;
    mListener = listener;

    mScroller = new Scroller(mView.getContext(), new LinearInterpolator());
}
 
Example #17
Source Project: star-zone-android   Author: bootsrc   File: PullRefreshFooter.java    License: Apache License 2.0 5 votes vote down vote up
private void initView(Context context) {
    View.inflate(context, R.layout.view_ptr_footer, this);
    loadingView = (ImageView) findViewById(R.id.iv_loading);
    rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setDuration(600);
    rotateAnimation.setInterpolator(new LinearInterpolator());
    rotateAnimation.setRepeatCount(Animation.INFINITE);
    setVisibility(GONE);
}
 
Example #18
Source Project: guarda-android-wallets   Author: guardaco   File: TransactionHistoryFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void initRotation(ImageView ivLoader) {
    if (loaderAnimation == null) {
        loaderAnimation = ObjectAnimator.ofFloat(ivLoader, "rotation", 0.0f, 360f);
        loaderAnimation.setDuration(1500);
        loaderAnimation.setRepeatCount(ObjectAnimator.INFINITE);
        loaderAnimation.setInterpolator(new LinearInterpolator());
        loaderAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationCancel(animation);
                tvUpdateTransactions.setClickable(true);
            }
        });
    }
}
 
Example #19
Source Project: guarda-android-wallets   Author: guardaco   File: TransHistoryAdapter.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void startClockwiseRotation(ImageView ivLoader) {
    loaderAnimation = ObjectAnimator.ofFloat(ivLoader, "rotation", 0.0f, 360f);
    loaderAnimation.setDuration(1500);
    loaderAnimation.setRepeatCount(ObjectAnimator.INFINITE);
    loaderAnimation.setInterpolator(new LinearInterpolator());
    loaderAnimation.start();
}
 
Example #20
Source Project: FimiX8-RE   Author: wladimir-computin   File: X8AiAutoPhotoLoadingView.java    License: MIT License 5 votes vote down vote up
private void init() {
    this.state = 3;
    this.objectAnimator = ObjectAnimator.ofFloat(this.imgLoading, "rotation", new float[]{0.0f, 360.0f});
    this.objectAnimator.setDuration(1500);
    this.objectAnimator.setInterpolator(new LinearInterpolator());
    this.objectAnimator.setRepeatCount(-1);
    this.objectAnimator.setRepeatMode(1);
}
 
Example #21
Source Project: ThermometerView   Author: biansemao   File: ThermometerView.java    License: MIT License 5 votes vote down vote up
/**
 * 设置温度值并启动动画(插值器:LinearInterpolator)
 *
 * @param newValue 新温度值float(℃)
 */
public void setValueAndStartAnim(float newValue) {
    if (newValue < minScaleValue) {
        newValue = minScaleValue;
    }
    if (newValue > maxScaleValue) {
        newValue = maxScaleValue;
    }

    ObjectAnimator waveShiftAnim = ObjectAnimator.ofFloat(this, "curValue", curScaleValue, newValue);
    waveShiftAnim.setRepeatCount(0);
    waveShiftAnim.setDuration(500);
    waveShiftAnim.setInterpolator(new LinearInterpolator());
    waveShiftAnim.start();
}
 
Example #22
Source Project: Upchain-wallet   Author: xilibi2003   File: LoadingView.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void buildAnimator() {
    final ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(ANIMATOR_DURATION);
    valueAnimator.setRepeatCount(-1);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRotation = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    animator = valueAnimator;
    animatorSet = buildFlexibleAnimation();
    animatorSet.addListener(animatorListener);
}
 
Example #23
Source Project: android-fly-refreshlayout   Author: mxdldev   File: DaisyHeaderView.java    License: Apache License 2.0 5 votes vote down vote up
public void initView(Context context) {
  LayoutInflater.from(context).inflate(R.layout.layout_daisy, this);
  mTxtLoading = findViewById(R.id.txt_loading);
  mTxtLoading.setText("下拉刷新");
  mImgDaisy = findViewById(R.id.img_daisy);
  mRotation = ObjectAnimator.ofFloat(mImgDaisy, "rotation", 0, 360).setDuration(800);
  mRotation.setRepeatCount(ValueAnimator.INFINITE);
  mRotation.setInterpolator(new LinearInterpolator());

}
 
Example #24
Source Project: android-fly-refreshlayout   Author: mxdldev   File: DaisyFooterView.java    License: Apache License 2.0 5 votes vote down vote up
public void initView(Context context) {
  LayoutInflater.from(context).inflate(R.layout.layout_daisy, this);
  mTxtLoading = findViewById(R.id.txt_loading);
  mTxtLoading.setText("上拉加载更多...");
  mImgDaisy = findViewById(R.id.img_daisy);

  mRotation = ObjectAnimator.ofFloat(mImgDaisy, "rotation", 0, 360).setDuration(800);
  mRotation.setRepeatCount(ValueAnimator.INFINITE);
  mRotation.setInterpolator(new LinearInterpolator());

}
 
Example #25
Source Project: WidgetCase   Author: faith-hb   File: HalfCircleProView.java    License: Apache License 2.0 5 votes vote down vote up
private void initAnimation() {
    progressAnimator = ValueAnimator.ofFloat(0, mProgress);
    progressAnimator.setDuration(duration);
    progressAnimator.setStartDelay(startDelay);
    progressAnimator.setInterpolator(new LinearInterpolator());
    progressAnimator.addUpdateListener(valueAnimator -> {
        float value = (float) valueAnimator.getAnimatedValue();
        mProgress = value;
        invalidate();
    });
    progressAnimator.start();
}
 
Example #26
Source Project: WidgetCase   Author: faith-hb   File: ShadowProBar.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 进度移动动画  通过插值的方式改变移动的距离
     */
    private void initAnimation() {
        progressAnimator = ValueAnimator.ofFloat(0, mProgress);
        progressAnimator.setDuration(duration);
        progressAnimator.setStartDelay(startDelay);
        progressAnimator.setInterpolator(new LinearInterpolator());
        progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float value = (float) valueAnimator.getAnimatedValue();
                //进度数值只显示整数,我们自己的需求,可以忽略
                //把当前百分比进度转化成view宽度对应的比例
                currentProgress = getWidth() * value / 100;

                if (currentProgress < progressRound && currentProgress != 0) {
                    currentProgress = progressRound;
                }

                if (currentProgress > getWidth()) {
                    currentProgress = getWidth();
                }
                //进度回调方法
//                if (progressListener != null) {
//                    progressListener.currentProgressListener(value);
//                }
                invalidate();
            }
        });
        progressAnimator.start();
    }
 
Example #27
Source Project: WidgetCase   Author: faith-hb   File: HorProBar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 进度移动动画  通过插值的方式改变移动的距离
 */
private void initAnimation() {
    progressAnimator = ValueAnimator.ofFloat(0, mProgress);
    progressAnimator.setDuration(duration);
    progressAnimator.setStartDelay(startDelay);
    progressAnimator.setInterpolator(new LinearInterpolator());
    progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float value = (float) valueAnimator.getAnimatedValue();
            //进度数值只显示整数,我们自己的需求,可以忽略
            textString = formatNum(/*format2Int(*/value);
            tipWidth = (int) (textPaint.measureText(textString + "%") + dp2px(10));
            //把当前百分比进度转化成view宽度对应的比例
            currentProgress = (mProgressWidth) * value / 100;
            if (currentProgress < dp2px(2) && currentProgress != 0) {
                currentProgress = dp2px(2);
            }
            //进度回调方法
            if (progressListener != null) {
                progressListener.currentProgressListener(value);
            }
            //移动百分比提示框,只有当前进度到提示框中间位置之后开始移动,
            //当进度框移动到最右边的时候停止移动,但是进度条还可以继续移动
            //moveDis是tip框移动的距离
            if (currentProgress <= (mProgressWidth)) {
                moveDis = (mWidth - mProgressWidth - tipWidth) / 2 + currentProgress;
            } else  /*if (currentProgress > mWidth-tipWidth)*/ {
                moveDis = (mWidth + mProgressWidth - tipWidth) / 2;
            }
            if (moveDis == 0) {
                moveDis = (mWidth - mProgressWidth - tipWidth) / 2;
            }

            invalidate();
        }
    });
    progressAnimator.start();
}
 
Example #28
Source Project: DS4Android   Author: toly1994328   File: LinkedView.java    License: MIT License 5 votes vote down vote up
private void init() {
    //初始化主画笔
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.BLUE);
    mPaint.setStrokeWidth(5);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(50);
    //初始化主路径
    mPath = new Path();
    //初始化文字画笔
    mTxtPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTxtPaint.setColor(Color.WHITE);
    mTxtPaint.setTextAlign(Paint.Align.CENTER);
    mTxtPaint.setTextSize(40);
    //初始化路径画笔
    mPathPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPathPaint.setColor(0xff810DF3);
    mPathPaint.setStrokeWidth(4);
    mPathPaint.setStyle(Paint.Style.STROKE);
    mCooPicture = HelpDraw.getCoo(getContext(), mCoo, false);
    mGridPicture = HelpDraw.getGrid(getContext());
    //初始化圆球按钮画笔
    mCtrlPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCtrlPaint.setColor(Color.RED);
    mCtrlPaint.setTextAlign(Paint.Align.CENTER);
    mCtrlPaint.setTextSize(30);
    //初始化时间流ValueAnimator
    mAnimator = ValueAnimator.ofFloat(0, 1);
    mAnimator.setRepeatCount(-1);
    mAnimator.setDuration(2000);
    mAnimator.setRepeatMode(ValueAnimator.REVERSE);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.addUpdateListener(animation -> {
        updateBall();//更新小球位置
        invalidate();
    });
}
 
Example #29
Source Project: android_9.0.0_r45   Author: lulululbj   File: BurnInProtectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
public BurnInProtectionHelper(Context context, int minHorizontalOffset,
        int maxHorizontalOffset, int minVerticalOffset, int maxVerticalOffset,
        int maxOffsetRadius) {
    mMinHorizontalBurnInOffset = minHorizontalOffset;
    mMaxHorizontalBurnInOffset = maxHorizontalOffset;
    mMinVerticalBurnInOffset = minVerticalOffset;
    mMaxVerticalBurnInOffset = maxVerticalOffset;
    if (maxOffsetRadius != BURN_IN_MAX_RADIUS_DEFAULT) {
        mBurnInRadiusMaxSquared = maxOffsetRadius * maxOffsetRadius;
    } else {
        mBurnInRadiusMaxSquared = BURN_IN_MAX_RADIUS_DEFAULT;
    }

    mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    context.registerReceiver(mBurnInProtectionReceiver,
            new IntentFilter(ACTION_BURN_IN_PROTECTION));
    Intent intent = new Intent(ACTION_BURN_IN_PROTECTION);
    intent.setPackage(context.getPackageName());
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    mBurnInProtectionIntent = PendingIntent.getBroadcast(context, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    DisplayManager displayManager =
            (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    mDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    displayManager.registerDisplayListener(this, null /* handler */);

    mCenteringAnimator = ValueAnimator.ofFloat(1f, 0f);
    mCenteringAnimator.setDuration(CENTERING_ANIMATION_DURATION_MS);
    mCenteringAnimator.setInterpolator(new LinearInterpolator());
    mCenteringAnimator.addListener(this);
    mCenteringAnimator.addUpdateListener(this);
}
 
Example #30
Source Project: DS4Android   Author: toly1994328   File: SingleLinkedView.java    License: MIT License 5 votes vote down vote up
private void init() {
    //初始化主画笔
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.BLUE);
    mPaint.setStrokeWidth(5);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(50);
    //初始化主路径
    mPath = new Path();
    //初始化文字画笔
    mTxtPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTxtPaint.setColor(Color.WHITE);
    mTxtPaint.setTextAlign(Paint.Align.CENTER);
    mTxtPaint.setTextSize(40);
    //初始化路径画笔
    mPathPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPathPaint.setColor(0xff810DF3);
    mPathPaint.setStrokeWidth(4);
    mPathPaint.setStyle(Paint.Style.STROKE);
    mCooPicture = HelpDraw.getCoo(getContext(), mCoo, false);
    mGridPicture = HelpDraw.getGrid(getContext());
    //初始化圆球按钮画笔
    mCtrlPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCtrlPaint.setColor(Color.RED);
    mCtrlPaint.setTextAlign(Paint.Align.CENTER);
    mCtrlPaint.setTextSize(30);
    //初始化时间流ValueAnimator
    mAnimator = ValueAnimator.ofFloat(0, 1);
    mAnimator.setRepeatCount(-1);
    mAnimator.setDuration(2000);
    mAnimator.setRepeatMode(ValueAnimator.REVERSE);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.addUpdateListener(animation -> {
        updateBall();//更新小球位置
        invalidate();
    });
}