Material style circular progress bar for Android

Overview

Material CircularProgressView

Indeterminate Determinate
Sample Indeterminate GIF Sample Determinate GIF

Description

This CircularProgressView is a (surprisingly) circular progress bar Android View that is designed to imitate the Material versions of ProgressBar. These versions can be seen on this page of the Material design spec under Circular indicators.

Usage

To use CircularProgressView you must add it as a dependency in your Gradle build:

dependencies {
    compile 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
}

Then add the view to your layout:

<com.github.rahatarmanahmed.cpv.CircularProgressView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/progress_view"
    android:layout_width="40dp"
    android:layout_height="40dp"
    app:cpv_animAutostart="true"
    app:cpv_indeterminate="true" />

That's all you need! If you don't want the CircularProgressView to automatically start animating, omit the app:cpv_animAutostart option and start it manually yourself:

CircularProgressView progressView = (CircularProgressView) findViewById(R.id.progress_view);
progressView.startAnimation();

XML attributes

Name Type Default Description
cpv_progress float 0 The current progress of the progress bar.
cpv_maxProgress float 100 The maximum progress of the progress bar; what's considered as 100% of the bar.
cpv_thickness dimension 4px The thickness of the progress bar.
cpv_color color Theme's accent color. If not available, Material Blue 500 (#2196F3) The color of the progress bar.
cpv_indeterminate boolean false Whether this progress bar is indeterminate or not. If indeterminate, the progress set on this view will not have any effect.
cpv_animDuration integer 4000 The duration of the indeterminate progress bar animation in milliseconds. It is the duration of all "steps" of the indeterminate animation. (Indeterminate only)
cpv_animSwoopDuration integer 5000 The duration of the initial swoop of the determinate animation. (Determinate only)
cpv_animSyncDuration integer 500 The duration of the determinate progress update animation. When you use setUpdate(int), this is how long it takes for the view to finish animating to that progress. (Determinate only)
cpv_animSteps integer 3 The number of "steps" in the indeterminate animation (how many times it does the loopy thing before returning to its original position). It is recommended to use an odd number, as even numbers of steps look the same after half the number of steps.
cpv_animAutostart boolean false Whether this progress bar should automatically start animating once it is initialized.
cpv_startAngle float 0 The starting angle for progress bar. (Determinate only)

Public Methods

Name Description
isIndeterminate() Returns true if the progress bar is indeterminate, false if determinate.
setIndeterminate(boolean) Set whether this progress bar is indeterminate or not. Will reset the animation if the value changes
getThickness() Gets the thickness of the progress bar.
setThickness(int) Sets thickness of the progress bar.
getColor() Gets the color of the progress bar.
setColor(int) Sets the color of the progress bar.
getMaxProgress() Gets the maximum progress of the progress bar.
setMaxProgress(float) Sets the maximum progress of the progress bar.
getProgress() Gets the current progress of the progress bar.
setProgress(float) Sets the current progress of the progress bar. (Will linearly animate the update.)
startAnimation() Starts the animation of the progress bar. (Alias of resetAnimation().)
resetAnimation() Resets the animation of the progress bar.
stopAnimation() Stops the animation of the progress bar.
addListener(CircularProgressViewListener) Registers a CircularProgressViewListener with this view.
removeListener(CircularProgressViewListener) Unregisters a CircularProgressViewListener with this view.

Listener Events.

A CircularProgressViewListener class is available for listening to some events (as well as a CircularProgressViewAdapter).

Event Description
onProgressUpdate(float) Called when setProgress is called. (Determinate only)
onProgressUpdateEnd(float) Called when this view finishes animating to the updated progress. (Determinate only)
onAnimationReset() Called when resetAnimation() is called.
onModeChange(boolean) Called when you switch between indeterminate and determinate modes.

Known Issues

CircularProgressView flickers when phone is in battery saving mode

This happens because battery saving mode automatically ends all Animators, but the ones in CPV run in an endless loop. The best way to work around this right now is to use the native ProgressBar for API >21, since that is when the battery saver mode was introduced. See this issue comment on how to accomplish this.

Changelog

v2.5.0

  • Added stopAnimation() method
  • Fixed view animating while not visible. Setting visibility to GONE or INVISIBLE will stop the animation. Setting to VISIBLE will restart it.

v2.4.0

  • Added cpv_startAngle attribute

v2.3.2

  • Fixed CPV stopping when View is recycled

v2.3.1

  • Fixed memory leak

v2.3.0

v2.2.1

  • Fixed ignoring the color #FFFFFF

v2.2.0

  • Now it uses the actual theme's accent color if possible by default.

v2.1.0

  • Fixed default thickness using 4px instead of 4dp

v2.0.1

  • Possible fix for drawArc NullPointerError
  • Slight performance improvements

v2.0.0

  • Removed unnecessary appcompat dependency from example
  • Fixed repaint issue by drawing smaller arcs

v1.0.0

  • Initial release
Comments
  • Causes robolectric unable to proceed

    Causes robolectric unable to proceed

    Hi, I was using this library and robolectric (3.0-rc3) for unit test. I found that circularProgressView.startAnimation() will prevent Robolectric from proceeding.

    public class MainActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            CircularProgressView progressView = (CircularProgressView) findViewById(R.id.progress_view);
            progressView.startAnimation();
        }
    }
    
    @RunWith(RobolectricGradleTestRunner.class)
    @Config(constants = BuildConfig.class, sdk = 21)
    public class MainActivityTest {
        @Test
        public void testMainActivity() {
            MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class);
            Assert.assertNotNull(mainActivity);
        }
    }
    

    The program will stuck in setupActivity() and the assertion will never be reached. And if I comment out progressView.startAnimation();, then everything works fine. I don't know if its a problem of this library or of Robolectric, but would you take a look at this?

    help wanted 
    opened by ChrisZou 19
  • Possible memory leak

    Possible memory leak

    Hi, I try to use it with image pager UIL library. https://github.com/nostra13/Android-Universal-Image-Loader/tree/master/sample There is an adapter with item that has an image and a progrees bar on top of it, after the image is loaded the progress bar is hidden. So there are many instances of a progress bar there...

    UIL crashes with an error about out of memory on their sample application after about 10-20 swipes. With a standard progress bar this doesn't happen

    opened by MichaelHefetz 17
  • Added 'startAngle' as XML parameter for determinate progress use

    Added 'startAngle' as XML parameter for determinate progress use

    This is useful when using the ProgressView in determinate mode where we want to show percent progress towards a goal (e.g. 80% complete) and we want to start the progress bar at a specific angle instead of the default 0.

    opened by saadfarooq 11
  • Update to use actual theme's accent color

    Update to use actual theme's accent color

    As default Lollipop's ProgressBar uses the theme's accent color if no xml attribute is specified, I've made changes to accord this.

    Now, you can specify the color to use in the xml layout, or if you don't do that, it will use the accent color specified in the app theme. If no accent color specified, it will use the parent's accent color.

    opened by pedroadame 11
  • NPE in CircularProgressView

    NPE in CircularProgressView

    Hi!

    Two random crashes showed up in Crashlytics. Not sure in what circumstances and how to reproduce it. Never encountered myself. Just for your information, maybe there is something obviuos.

    Devices: Sony ST26I (4.1.2) and LG-E460 (4.1.2)

    java.lang.NullPointerException
           at android.view.GLES20Canvas.drawArc(GLES20Canvas.java:726)
           at com.github.rahatarmanahmed.cpv.CircularProgressView.onDraw(CircularProgressView.java:119)
           at android.view.View.draw(View.java:13573)
           at android.view.View.getDisplayList(View.java:12524)
           at android.view.View.getDisplayList(View.java:12568)
           at android.view.View.draw(View.java:13297)
           at android.view.ViewGroup.drawChild(ViewGroup.java:3037)
    ...
    

    Thanks for awesome library.

    opened by luhmirin-s 8
  • Long animation leaves 4 colored places at 0, 90, 180 and 270 angles

    Long animation leaves 4 colored places at 0, 90, 180 and 270 angles

    Thank you for the great widget! One small issue: On android 4.4.2, While the circle is animated for more than 5 cycles it starts painting the 4 places. These are the points where the bound box touches the circle. If I set the Paint to be aliased then it doesn't happen. progress_issue

    opened by MichaelHefetz 8
  • Added optional background with adjustable color and thickness

    Added optional background with adjustable color and thickness

    I think displaying a background on (especially determinate) progress views is quite a common thing. So I've gone ahead and added the option to draw such a background circle. Color and thickness are adjustable as well.

    opened by mrmaffen 5
  • stopAnimation() does not remove visibility

    stopAnimation() does not remove visibility

    Before calling startAnimation() on a built indeterminate progress view, it doesn't show the view until after calling startAnimation(), which is convenient in cases you want to conceal the view first while no process is executed. Is it possible to remove view visibility on stopAnimation()? Where in a single instance of the progress view can handle repeated start and stop animation calls throughout an activity, showing and hiding the view respectively.

    opened by leonapse 4
  • Finishing Animation for Indertiminate progress

    Finishing Animation for Indertiminate progress

    Hey,

    Thankx for this library. I just have one request. Could you please add a method to finish the animation for indeterminate progress?

    Simply hiding the progress bar suddenly when the background task is complete looks janky and I would love for the animation to complete the full circle before dissapearing. Please add that if its not too much work..

    Thankx

    opened by kuwapa 4
  • Starting from version 2.1.0 the progress is not working

    Starting from version 2.1.0 the progress is not working

    I have a code build on version 2.0.1 and it works fine When updated gradle to 2.2.0 nothing is showed in the place of the progress

    my code: <com.github.rahatarmanahmed.cpv.CircularProgressView android:id="@+id/progressBar" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="24dp" android:layout_height="24dp" android:layout_centerVertical="true" android:layout_gravity="right" android:layout_marginRight="12dp" app:cpv_color="#ffffff" app:cpv_indeterminate="true" app:cpv_thickness="2dp"/>

    I have tried to remove all extra params so it is like in the sample

    <com.github.rahatarmanahmed.cpv.CircularProgressView android:id="@+id/progressBar" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="24dp" android:layout_height="24dp" app:cpv_indeterminate="true"/>

    Still nothing...

    No exceptions in the log...

    I also have the following dependencies: compile 'com.android.support:appcompat-v7:22.1.1' compile 'com.android.support:recyclerview-v7:22.1.1' compile 'com.android.support:cardview-v7:22.1.1' compile 'com.android.support:support-v4:22.1.1'

    opened by MichaelHefetz 4
  • How to mimic the default Lollipop's look?

    How to mimic the default Lollipop's look?

    as the title says. What are the configurations for this? Also, can I make it so that if newer versions of Android arrive, it will use their default style and not the one of the library?

    opened by AndroidDeveloperLB 4
  • Crash when resetAnimation

    Crash when resetAnimation

    I use progessview only on xml and not use on code, progressview show on dialogfragment

    Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'boolean android.animation.AnimatorSet.mTerminated' on a null object reference
           at android.animation.AnimatorSet$DependencyListener.startIfReady(AnimatorSet.java:778)
           at android.animation.AnimatorSet$DependencyListener.onAnimationStart(AnimatorSet.java:767)
           at android.animation.ValueAnimator.notifyStartListeners(ValueAnimator.java:981)
           at android.animation.ValueAnimator.start(ValueAnimator.java:1043)
           at android.animation.ValueAnimator.start(ValueAnimator.java:1050)
           at android.animation.AnimatorSet.start(AnimatorSet.java:585)
           at android.animation.AnimatorSet.start(AnimatorSet.java:585)
           at com.github.rahatarmanahmed.cpv.CircularProgressView.resetAnimation(CircularProgressView.java:399)
           at com.github.rahatarmanahmed.cpv.CircularProgressView$5.onAnimationEnd(CircularProgressView.java:396)
           at android.animation.AnimatorSet$AnimatorSetListener.onAnimationEnd(AnimatorSet.java:854)
           at android.animation.AnimatorSet$AnimatorSetListener.onAnimationEnd(AnimatorSet.java:854)
           at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1171)
           at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:722)
           at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:738)
           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:829)
           at android.view.Choreographer.doCallbacks(Choreographer.java:606)
           at android.view.Choreographer.doFrame(Choreographer.java:575)
           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:815)
           at android.os.Handler.handleCallback(Handler.java:739)
           at android.os.Handler.dispatchMessage(Handler.java:95)
           at android.os.Looper.loop(Looper.java:145)
           at android.app.ActivityThread.main(ActivityThread.java:6934)
           at java.lang.reflect.Method.invoke(Method.java)
           at java.lang.reflect.Method.invoke(Method.java:372)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
    
    opened by agaDeonix 0
  • Flickering with disabled animations

    Flickering with disabled animations

    Hi, the animation is not shown correctly, if you disable animations in developer settings.

    I run in this issue, when I tested my Application using Espresso and disabled all animations. Should be related to this: https://github.com/rahatarmanahmed/CircularProgressView/issues/15 https://github.com/rahatarmanahmed/CircularProgressView/issues/16

    help wanted 
    opened by vojtaaa9 3
Owner
Rahat Ahmed
Dollar Store Developer
Rahat Ahmed
A material style progress wheel compatible with 2.3

![](https://img.shields.io/badge/Methods and size-106 | 12 KB-e91e63.svg) Material-ish Progress A material style progress wheel compatible with 2.3 Tr

Nico Hormazábal 2.5k Jan 4, 2023
Animated Material circular button

Material Circular Button Circular button for Android in Google Material Style How to use Clone this proyect and import the module "materialCircularBut

Adrián Lomas 217 Nov 25, 2022
Material style morphing play-pause drawable for Android

Play There is no need to explain what this thing does, just take a look at the gif below. Including in your project Add to your root build.gradle: all

Alexey Derbyshev 58 Jul 11, 2022
Navigation Drawer Activity with material design style and simplified methods

MaterialNavigationDrawer Navigation Drawer Activity with material design style and simplified methods       It requires 10+ API and android support v7

Fabio Biola 1.6k Jan 5, 2023
Material Shadows for android : A library for supporting convex material shadows

MaterialShadows A library for seamlessly integrating Material shadows. The library takes existing material shadows to next level by adding the followi

Harjot Singh Oberai 2.2k Dec 19, 2022
:hourglass_flowing_sand: An android progress view developed after taking inspiration from Uber app.

A simple progress animation developed after taking inspiration from the Uber app. Demo Download Add this to your root build.gradle file allprojects {

Ishan Khanna 286 Dec 23, 2022
:hourglass_flowing_sand: An android progress view developed after taking inspiration from Uber app.

A simple progress animation developed after taking inspiration from the Uber app. Demo Download Add this to your root build.gradle file allprojects {

Ishan Khanna 286 Dec 23, 2022
📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.

Material Dialogs for Android ?? ?? Android Library to implement animated, ?? beautiful, ?? stylish Material Dialog in android apps easily. 1. Material

Shreyas Patil 875 Dec 28, 2022
MaterialPickers-in-android - A simple android project that shows how to create material pickers for date and time

MaterialPickers-in-android A simple android project that shows how to create mat

Segun Francis 2 Apr 28, 2022
A library to bring fully animated Material Design components to pre-Lolipop Android.

Material MaterialLibrary is an Open Source Android library that back-port Material Design components to pre-Lolipop Android. MaterialLibrary's origina

Rey Pham 6k Dec 21, 2022
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included ?? • Setup ??️ • Migration Guide ??

Mike Penz 11.6k Dec 27, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Dec 26, 2022
Implementation of Ripple effect from Material Design for Android API 9+

RippleEffect ExpandableLayout provides an easy way to create a view called header with an expandable view. Both view are external layout to allow a ma

Robin Chutaux 4.9k Dec 30, 2022
Material Design implementation for Android 4.0+. Shadows, ripples, vectors, fonts, animations, widgets, rounded corners and more.

Carbon Material Design implementation for Android 4.0 and newer. This is not the exact copy of the Lollipop's API and features. It's a custom implemen

null 3k Jan 9, 2023
Android drawer icon with material design animation

LDrawer Android drawer icon with material design animation Note Basically same as appcompat_v7 version 21, you can use appcompat_v7 compile 'com.andro

Hasan Keklik 1.4k Dec 25, 2022
[] Android Library that implements Snackbars from Google's Material Design documentation.

DEPRECATED This lib is deprecated in favor of Google's Design Support Library which includes a Snackbar and is no longer being developed. Thanks for a

null 1.5k Dec 16, 2022
A material horizontal calendar view for Android based on RecyclerView

Horizontal Calendar A material horizontal calendar view for Android based on RecyclerView. Installation The library is hosted on jcenter, add this to

Mulham Raee 1.2k Dec 15, 2022
Android Sample Project with Material Design and Toolbar.

AndroidMaterialDesignToolbar -- PROJECT IS NOT SUPPORTED Android Sample Project with Material Design and Toolbar. Project use Appcompat library for ma

kemal selim tekinarslan 713 Nov 11, 2022
Default colors and dimens per Material Design guidelines and Android Design guidelines inside one library.

Material Design Dimens Default colors and dimens per Material Design guidelines and Android Design guidelines inside one library. Dimens Pattern: R.di

Dmitry Malkovich 1.4k Jan 3, 2023