Coder Social home page Coder Social logo

Comments (3)

AwesomelyAmazing avatar AwesomelyAmazing commented on June 11, 2024

As a quick fix I made following changes in view in my project:

    private Handler spinHandler = new SpinHandler(this);

    private static class SpinHandler extends Handler {

        private final WeakReference<ProgressWheelView> viewRef;

        public SpinHandler(final ProgressWheelView view) {
            viewRef = new WeakReference<ProgressWheelView>(view);
        }

        /**
         * This is the code that will increment the progress variable
         * and so spin the wheel
         */
        @Override
        public void handleMessage(final Message msg) {
            final ProgressWheelView progressView = viewRef.get();
            if (progressView != null) {
                progressView.invalidate();
                if (progressView.isSpinning) {
                    progressView.progress += progressView.spinSpeed;
                    if (progressView.progress > 360) {
                        progressView.progress = 0;
                    }
                    progressView.spinHandler.sendEmptyMessageDelayed(0, progressView.delayMillis);
                }
            }
        }
    }

and:

@Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        setupBounds();
        setupPaints();
        invalidate();
        if (isSpinning) {
            spinHandler.sendEmptyMessage(0);
        }
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        spinHandler.removeMessages(0);
    }

With static handler nothing will stop gc from collecting view, and when it gets collected handler will just stop sending messages to itself.
When we get detached, but not yet gced we should stop messages so they won't lag the ui thread (since there could be a gridview with progresses and if each will send messages every now and then ui will lag)

from progresswheel.

Todd-Davies avatar Todd-Davies commented on June 11, 2024

Aleksandrs, that looks great. I can't see any problems with the code.

You should submit a pull request for review.

Thanks.

from progresswheel.

belen-mapplas avatar belen-mapplas commented on June 11, 2024

Hi guys,

I have problems in a Samsung Galasy S3 device. I start spinning the progressWheel without problems, and even stopping it, if the screen of the phone turns off, the mobile phone doesn't come back from that state.

I have also tried on a HTC One X and works like a charm.

Some ideas?

from progresswheel.

Related Issues (20)

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.