All Projects → MRezaNasirloo → Circularprogressbar

MRezaNasirloo / Circularprogressbar

A subclass of {android.view.View} class for creating a custom circular progressBar

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Circularprogressbar

Konsole
Home of the simple console library consisting of ProgressBar, Window, Form, Draw & MockConsole (C# console progress bar with support for single or multithreaded progress updates) Window is a 100%-ish console compatible window, supporting all normal console writing to a windowed section of the screen, supporting scrolling and clipping of console output.
Stars: ✭ 467 (+83.14%)
Mutual labels:  draw, progressbar
VHProgressBar
Vartical and Horizontal ProgressBar
Stars: ✭ 23 (-90.98%)
Mutual labels:  progressbar
angular-progress-bar
This component allow you to easy incorporate progress-bar to angular/ionic project, providing binding and color options
Stars: ✭ 26 (-89.8%)
Mutual labels:  progressbar
RotatableAutofitEditText
Extended EditText which allows to move, rotate and resize text at the same time
Stars: ✭ 51 (-80%)
Mutual labels:  customview
LineProgressbar
A light weight jquery progressbar plugin
Stars: ✭ 34 (-86.67%)
Mutual labels:  progressbar
awesome-canvas
Canvas资源库大全中文版。An awesome Canvas packages and resources.
Stars: ✭ 288 (+12.94%)
Mutual labels:  draw
DockProgressBar
Dock progress bar on Mac OS X
Stars: ✭ 18 (-92.94%)
Mutual labels:  progressbar
Youtube-Pagination-ProgressBar
Youtube app uses a nice ProgressBar for pagiantion.The ProgressBar goes down using transition and then dissapear when the process ends,so I created a Custom ProgresBar as youtube app has.
Stars: ✭ 25 (-90.2%)
Mutual labels:  progressbar
JQScrollNumberLabel
JQScrollNumberLabel:仿tumblr热度滚动数字条数, 一个显示数字的控件,当你改变其数字时,能够有滚动的动画,同时动画和位数可以限制,动态创建和实例化可选,字体样式自定义等。
Stars: ✭ 29 (-88.63%)
Mutual labels:  customview
Cirque
An iOS component that enables you to draw multi color circle strokes with gradient trasitions between colors
Stars: ✭ 23 (-90.98%)
Mutual labels:  draw
JQFlowView
卡片式无限自动轮播图 ,无限/自动轮播,可自定义非当前显示view缩放和透明的特效等;喜欢❤️就star一下吧!
Stars: ✭ 24 (-90.59%)
Mutual labels:  customview
suru
A tqdm-style progress bar in Nim
Stars: ✭ 40 (-84.31%)
Mutual labels:  progressbar
CustomEditText
Simple Custom EditText for Android like Instagram
Stars: ✭ 23 (-90.98%)
Mutual labels:  customview
canvas-constructor
An ES6 utility for canvas with built-in functions and chained methods.
Stars: ✭ 96 (-62.35%)
Mutual labels:  draw
svelte-progressbar
A multiseries, SVG progressbar component made with Svelte
Stars: ✭ 85 (-66.67%)
Mutual labels:  progressbar
colorquant
Go library for color quantization and dithering
Stars: ✭ 75 (-70.59%)
Mutual labels:  draw
Examples Gtkmm
Shows how to use Gtkmm controls by programming code (c++17).
Stars: ✭ 23 (-90.98%)
Mutual labels:  progressbar
MinTimetable
Customizable TimeTableView for Android
Stars: ✭ 26 (-89.8%)
Mutual labels:  customview
Socket.io
NodeJS《你画我猜》游戏
Stars: ✭ 255 (+0%)
Mutual labels:  draw
Examples Win32
Shows how to use Win32 controls by programming code (c++17).
Stars: ✭ 22 (-91.37%)
Mutual labels:  progressbar

CircularProgressBar

A subclass of {@link android.view.View} class for creating a custom circular progressBar

enter image description here

1. Create a file under values/attrs.xml This resources is used for setting values in XML layout file for our view

<resources>
    <declare-styleable name="CircleProgressBar">
        <attr name="min" format="integer" />
        <attr name="max" format="integer" />
        <attr name="progress" format="integer" />
        <attr name="progressbarColor" format="color" />
        <attr name="progressBarThickness" format="dimension" />
    </declare-styleable>

</resources>

2. Create a class and extends the View class CircularProgressBar.java

public class CircleProgressBar extends View {


/**
 * ProgressBar's line thickness
 */
private float strokeWidth = 4;
private float progress = 0;
private int min = 0;
private int max = 100;
/**
 * Start the progress at 12 o'clock
 */
private int startAngle = -90;
private int color = Color.DKGRAY;
private RectF rectF;
private Paint backgroundPaint;
private Paint foregroundPaint;

These are the fields we need in order to draw our view

It is neccessary to add a constructor, Also we need to read values from XML layout file

public CircleProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs);
}

In init() method we get and set our values from defined styleable and initialize our Paint objects.

private void init(Context context, AttributeSet attrs) {
    rectF = new RectF();
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.CircleProgressBar,
            0, 0);
    //Reading values from the XML layout
    try {
        strokeWidth = typedArray.getDimension(R.styleable.CircleProgressBar_progressBarThickness, strokeWidth);
        progress = typedArray.getFloat(R.styleable.CircleProgressBar_progress, progress);
        color = typedArray.getInt(R.styleable.CircleProgressBar_progressbarColor, color);
        min = typedArray.getInt(R.styleable.CircleProgressBar_min, min);
        max = typedArray.getInt(R.styleable.CircleProgressBar_max, max);
    } finally {
        typedArray.recycle();
    }

    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    backgroundPaint.setColor(adjustAlpha(color, 0.3f));
    backgroundPaint.setStyle(Paint.Style.STROKE);
    backgroundPaint.setStrokeWidth(strokeWidth);

    foregroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    foregroundPaint.setColor(color);
    foregroundPaint.setStyle(Paint.Style.STROKE);
    foregroundPaint.setStrokeWidth(strokeWidth);
}

We also use adjustAlpha method to make the background color ligher.

private int adjustAlpha(int color, float factor) {
	int alpha = Math.round(Color.alpha(color) * factor);
	int red = Color.red(color);
	int green = Color.green(color);
	int blue = Color.blue(color);
	return Color.argb(alpha, red, green, blue);
}

3. It is crucial to measure our view, In order to properly draw our custom view, we need to know what size it is. So we override the onMeasure()

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    final int min = Math.min(width, height);
    setMeasuredDimension(min, min);
    rectF.set(0 + strokeWidth / 2, 0 + strokeWidth / 2, min - strokeWidth / 2, min - strokeWidth / 2);
}

You should set the size of the view to the rectF object in order to instruct the canvas.draw() method where it should to draw the view. Also it is important to call the setMeasuredDimension() to notify the system how big the view is going to be.

4. The most important part of this class is the onDraw() method, we should override it to draw our view in its providing Canvas

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawOval(rectF, backgroundPaint);
    float angle = 360 * progress / max;
    canvas.drawArc(rectF, startAngle, angle, false, foregroundPaint);

}

5. Now add the view in your Layout file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    <com.mrn.customprogressbar.CircleProgressBar
        android:id="@+id/custom_progressBar"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_margin="10dp"
        app:progress="35"
        app:progressBarThickness="4dp"/>
    
</LinearLayout>

6. Lastly add coresponsive setters and getters, The neccessary one is the setProgress()

public void setProgress(float progress) {
    this.progress = progress;
    invalidate();// Notify the view to redraw it self (the onDraw method is called)
}

That's it.

ScreenShot

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].