Android Open Source - treedo Progress Bar






From Project

Back to project page treedo.

License

The source code is released under:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Everyone is permitted to copy and distribute verbatim or modified copies of this license document, ...

If you think the Android project treedo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mbonnin.treedo;
//from  w w  w  .  ja  v  a2s. c  om
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import android.view.animation.AccelerateInterpolator;

/**
 * Created by martin on 15/11/14.
 */
public class ProgressBar extends View implements ValueAnimator.AnimatorUpdateListener {
    private final Paint mPainter;
    float mOffset;
    ValueAnimator mValueAnimator;

    public ProgressBar(Context context) {
        super(context);

        setBackgroundColor(getResources().getColor(R.color.vibrant_100));
        mPainter = new Paint();
        mPainter.setStyle(Paint.Style.FILL);
        mPainter.setColor(getResources().getColor(R.color.vibrant_200));
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int d = (int)Utils.toPixels(4);
        int width = d;
        MeasureSpec measureSpec = new MeasureSpec();

        int mode = measureSpec.getMode(widthMeasureSpec);
        int w = measureSpec.getSize(widthMeasureSpec);
        if (mode == MeasureSpec.AT_MOST
                || mode == MeasureSpec.EXACTLY) {
            width = w;
        }

        setMeasuredDimension(width, d);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        restartAnimation();
    }

    private void restartAnimation() {
        mValueAnimator = new ValueAnimator().ofFloat(0.0f, 1.0f);
        mValueAnimator.addUpdateListener(this);
        mValueAnimator.setInterpolator(new AccelerateInterpolator());
        mValueAnimator.setRepeatCount(mValueAnimator.INFINITE);
        mValueAnimator.setDuration(1000).start();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = canvas.getWidth();
        int start;
        if (mOffset < 0.5) {
            start = (int)(width * 2 * mOffset * mOffset );
        } else {
            float x = mOffset - 0.5f;
            start = (int)(width * (0.5 + 2.0 * x - 2 * x * x));
        }
        int end = (int)(width * (2.0 * mOffset - mOffset * mOffset * mOffset * mOffset));

        canvas.drawRect(start, 0, end, canvas.getHeight(), mPainter);
    }

    @Override
    public void onAnimationUpdate(ValueAnimator animator) {
        mOffset = (Float)animator.getAnimatedValue();
        invalidate();
    }
}




Java Source Code List

com.mbonnin.treedo.ApplicationTest.java
com.mbonnin.treedo.BackupAdapter.java
com.mbonnin.treedo.BackupManager.java
com.mbonnin.treedo.Database.java
com.mbonnin.treedo.DialogBuilder.java
com.mbonnin.treedo.ItemAdapter.java
com.mbonnin.treedo.ItemDecorator.java
com.mbonnin.treedo.ItemEditText.java
com.mbonnin.treedo.ItemListView.java
com.mbonnin.treedo.ItemView2.java
com.mbonnin.treedo.ItemView.java
com.mbonnin.treedo.Item.java
com.mbonnin.treedo.MainActivity.java
com.mbonnin.treedo.ObservableScrollView.java
com.mbonnin.treedo.ProgressBar.java
com.mbonnin.treedo.SpacerView.java
com.mbonnin.treedo.TypeSpinnerAdapter.java
com.mbonnin.treedo.Utils.java