Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any Example of actual file download from URL? #9

Open
tusharkshirsagar2021 opened this issue Jul 26, 2021 · 2 comments
Open

Any Example of actual file download from URL? #9

tusharkshirsagar2021 opened this issue Jul 26, 2021 · 2 comments

Comments

@tusharkshirsagar2021
Copy link

If anyone implemented this?

@tusharkshirsagar2021
Copy link
Author

tusharkshirsagar2021 commented Jul 26, 2021

public class DownloadFileTask implements Runnable {
    private Handler handler;
    private DownloadButtonProgress btnProgress;
    private int progress = 0;
    public DownloadFileTask(Handler handler, DownloadButtonProgress btnProgress)
    {
        this.handler = handler;
        this.btnProgress = btnProgress;
    }
    @Override
    public void run() {
        try {
            setBtnIndeterminate();
            Thread.sleep(2000);
            setBtnDeterminate();
            while (progress <= 100) {
                Thread.sleep(30);
                progress++;
                setBtnProgress();
            }
            setBtnFinish();
        } catch ( InterruptedException e) {
            e.printStackTrace();
        }
    }
    private void setBtnIndeterminate() {

        handler.post(new Runnable() {
            @Override
            public void run () {
                // make operation on the UI - for example
                // on a progress bar.
                btnProgress.setIndeterminate();
            }
        });
    }

    private void setBtnDeterminate() {

        handler.post(new Runnable() {
            @Override
            public void run () {
                // make operation on the UI - for example
                // on a progress bar.
                btnProgress.setDeterminate();
            }
        });

    }

    private void setBtnProgress() {


        handler.post(new Runnable() {
            @Override
            public void run () {
                // make operation on the UI - for example
                // on a progress bar.
                btnProgress.setCurrentProgress(progress);
            }
        });
    }

    private void setBtnFinish() {
        handler.post(new Runnable() {
            @Override
            public void run () {
                // make operation on the UI - for example
                // on a progress bar.
                btnProgress.setFinish();
            }
        });

    }
}

Java version of sample.kt if anyone looking for

@tusharkshirsagar2021
Copy link
Author

tusharkshirsagar2021 commented Jul 26, 2021

Call it like new Thread(new DownloadFileTask(handler, playpauseview).start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant