GithubHelp home page GithubHelp logo

circularprogressview's Introduction

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

circularprogressview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

circularprogressview's Issues

It loads forever

Hi
Well first of all your work is amazing!!

I added this code to my webView based app.But it loads forever.

When my website completes loading it still running.

Can you guide me what to do for that

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?

Webview

not showing in webview please fix this.

Stoping the animation

Hie Guys

Im grateful for your piece of work, but however i have an issue. The thing is, everything works fine, when im doing an async task the progressview should animate ( and it does,using the method startAnimation() ) but my challenge comes to when i want to stop the animation...i would suggest for a stopAnimation() method...thanks again

Stop CircularProgressView animation?

Hello, thank you for the great lib. I was wandering how to stop the animation of the circularprogressview. The only way i found is just setting its visibility to GONE. Is there a way to stop the animation? Or if i miss something can you point me the right way? I'm quite new to android. So my worries are if it just hide the animation and doesn't stop it, won't it eat the resources of the device? Thank you.

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.

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: #15 #16

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

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)

Memory leak

When implementing the basic CircularProgressView I noticed a memory leak from the Android Monitor.

CPV stops when View is reused

Commit 8ea4a9d resolves the memory leak but introduces a minor issue. When using the CPV in a ListView or RecyclerView where Views are recycled/reused the CPV hangs when it gets visible the second time. The solution is to override onAttachedToWindow() and call startAnimation() there.

I think you could even move the block

if(autostartAnimation)
    startAnimation();

from init(AttributeSet attrs, int defStyle) to onAttachedToWindow().

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

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

use version 2.20 , have a error about the same id

java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class com.yingyonghui.market.widget.CircularProgressView$WheelSavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/0x0. Make sure other views do not use the same id.
at android.view.View.onRestoreInstanceState(View.java:13978)
at android.view.View.dispatchRestoreInstanceState(View.java:13954)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3025)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3031)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3031)
at android.view.View.restoreHierarchyState(View.java:13932)
at android.support.v4.app.Fragment.restoreViewState(Fragment.java:466)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:981)
at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManagerImpl.java:1314)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:730)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1501)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManagerImpl.java:490)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate$52bc874c(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:551)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:513)
at android.support.v4.view.ViewPager.setCurrentItem$2563266(ViewPager.java:505)
at me.xiaopan.psts.PagerSlidingTabStrip$TabViewClickListener.onClick(PagerSlidingTabStrip.java:575)
at android.view.View.performClick(View.java:4848)
at android.view.View$PerformClick.run(View.java:20300)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5809)
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:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)

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'

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.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.