Code Monkey home page Code Monkey logo

android-downloader's Introduction

#android-downloader

##Introduction android lib - downloader a multi-thread downloader for android

##Preview preview.png

##System requirements Android 2.2+

##Download Download the latest jar or grab via Maven:

<dependency>
  <groupId>com.github.snowdream.android.app</groupId>
  <artifactId>downloader</artifactId>
  <version>1.0</version>
</dependency>

or Gradle:

    compile 'com.github.snowdream.android.app:downloader:1.0'

##Usage 1.basic

DownloadManager downloadManager = new DownloadManager(this);

DownloadTask task = new DownloadTask(this);
task.setUrl("https://github.com/snowdream/android-autoupdate/raw/master/docs/test/android-autoupdater-v0.0.2-release.apk");

downloadManager.add(task, listener); //Add the task
downloadManager.start(task, listener); //Start the task
downloadManager.stop(task, listener); //Stop the task if you exit your APP.

private DownloadListener listener = new DownloadListener<Integer, DownloadTask>() {
    /**
     * The download task has been added to the sqlite.
     * <p/>
     * operation of UI allowed.
     *
     * @param downloadTask the download task which has been added to the sqlite.
     */
    @Override
    public void onAdd(DownloadTask downloadTask) {
        super.onAdd(downloadTask);
        Log.i("onAdd()");
        list.add(downloadTask);
        Log.i(""+downloadTask);
        adapter.notifyDataSetChanged();
    }

    /**
     * The download task has been delete from the sqlite
     * <p/>
     * operation of UI allowed.
     *
     * @param downloadTask the download task which has been deleted to the sqlite.
     */
    @Override
    public void onDelete(DownloadTask downloadTask) {
        super.onDelete(downloadTask);
        Log.i("onDelete()");
    }

    /**
     * The download task is stop
     * <p/>
     * operation of UI allowed.
     *
     * @param downloadTask the download task which has been stopped.
     */
    @Override
    public void onStop(DownloadTask downloadTask) {
        super.onStop(downloadTask);
        Log.i("onStop()");
    }

    /**
     * Runs on the UI thread before doInBackground(Params...).
     */
    @Override
    public void onStart() {
        super.onStart();
        Log.i("onStart()");
    }

    /**
     * Runs on the UI thread after publishProgress(Progress...) is invoked. The
     * specified values are the values passed to publishProgress(Progress...).
     *
     * @param values The values indicating progress.
     */
    @Override
    public void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        ((DownloadTaskAdapter) getListAdapter()).notifyDataSetChanged();
        Log.i("onProgressUpdate");
    }

    /**
     * Runs on the UI thread after doInBackground(Params...). The specified
     * result is the value returned by doInBackground(Params...). This method
     * won't be invoked if the task was cancelled.
     *
     * @param downloadTask The result of the operation computed by
     *                     doInBackground(Params...).
     */
    @Override
    public void onSuccess(DownloadTask downloadTask) {
        super.onSuccess(downloadTask);
        Log.i("onSuccess()");
    }

    /**
     * Applications should preferably override onCancelled(Object). This method
     * is invoked by the default implementation of onCancelled(Object). Runs on
     * the UI thread after cancel(boolean) is invoked and
     * doInBackground(Object[]) has finished.
     */
    @Override
    public void onCancelled() {
        super.onCancelled();
        Log.i("onCancelled()");
    }

    @Override
    public void onError(Throwable thr) {
        super.onError(thr);
        Log.i("onError()");
    }

    /**
     * Runs on the UI thread after doInBackground(Params...) when the task is
     * finished or cancelled.
     */
    @Override
    public void onFinish() {
        super.onFinish();
        Log.i("onFinish()");
    }
};

2.advance
You can set more properties of the DownloadTask.

DownloadTask task = new DownloadTask(this);
task.setUrl("https://github.com/snowdream/android-autoupdate/raw/master/docs/test/android-autoupdater-v0.0.2-release.apk");
task.setName("taskname");
task.setSize(10240);
task.setPath("/mnt/sdcard/snowdream/android/downloader/android-autoupdater-v0.0.2-release.apk");
task.setId(1);
...

##License

Copyright (C) 2013 Snowdream Mobile <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-downloader's People

Contributors

snowdream avatar

Stargazers

 avatar

Watchers

 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.