Code Monkey home page Code Monkey logo

downloadprogress's Introduction

DownloadProgress

An android view showing a download progressBar, total size, downloadedSize, percentage downloaded and a cancel button of the android DownloadManager with just few lines of code. Just like Google Play downloading...

Version

1.0.1

Usage

To use this library in your android project, just simply add the following repositories and dependency into your build.gradle

repositories {
    maven {
        url 'https://dl.bintray.com/ayz4sci/maven/'
    }
}

dependencies {
    compile 'com.ayz4sci.androidfactory:downloadprogress:1.0.2'
}

Then place com.ayz4sci.androidfactory.DownloadProgressView wherever you want the downloadprogressview to show, for example:

    <com.ayz4sci.androidfactory.DownloadProgressView
    android:id="@+id/downloadProgressView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="10dp"
    android:orientation="horizontal" />

You could get a DownloadProgressView instance through findViewById method.

DownloadProgressView downloadProgressView = (DownloadProgressView) rootView.findViewById(R.id.downloadProgressView);

To show the downloadprogressview, call show method and pass the downloadID that you got from DownloadManager when you started the download and also set DownloadStatusListener to know when download is successful, failed or cancelled eg.

DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("YOUR_DOWNLOAD_URL"));
request.setTitle("TITLE");
request.setDescription("DESCRIPTION");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(getApplicationContext(), null, "DOWNLOAD_FILE_NAME.mp4");
request.allowScanningByMediaScanner();
downloadID = downloadManager.enqueue(request);

downloadProgressView.show(downloadID, new DownloadProgressView.DownloadStatusListener() {
  @Override
  public void downloadFailed(int reason) {
     //Action to perform when download fails, reason as returned by DownloadManager.COLUMN_REASON
  }

  @Override
  public void downloadSuccessful() {
    //Action to perform on success
  }

  @Override
  public void downloadCancelled() {
    //Action to perform when user press the cancel button
  }
});

That's all. DownloadProgressView will handle the rest!

Change Logs

v1.0.1

Initial version

License

Apache 2.0

downloadprogress's People

Contributors

ayz4sci avatar

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.