package com.liuguangqiang.download;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.liuguangqiang.download.core.AsyncDownload;
import com.liuguangqiang.download.core.DownloadConfiguration;
import com.liuguangqiang.download.core.DownloadListener;
import com.liuguangqiang.download.core.DownloadParams;


public class MainActivity extends Activity {

    private String TAG = "AsyncDownload";

    private String filePath;

    private String testUrl = "http://dl.fishsaying.com/fishsaying_1.8.1.apk";

    private TextView tvProgress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvProgress = (TextView) this.findViewById(R.id.tv_progress);
        init();
        testDownload();
    }

    private void init() {
        AsyncDownload.getInstance().init(
                new DownloadConfiguration.Builder().setFixedThreadPool(3).build());

        filePath = FileUtils.getSdcardPath() + "/AsyncDownload";
        File file = new File(filePath);
        if (!file.exists()) file.mkdirs();
    }

    DownloadParams params;

    private void testDownload() {
        String pathFormat = filePath + "/t%s.apk";

        String savePath;
        for (int i = 0; i < 5; i++) {
            savePath = String.format(pathFormat, i + 1);
            params = new DownloadParams(testUrl, savePath);
            params.setTag("Tag" + (i + 1));
            AsyncDownload.getInstance().download(params, new DownloadListener() {

                @Override
                public void onStart() {
                    Log.i(TAG, getDownloadParams().getTag() + " download start");
                }

                @Override
                public void onSuccess() {
                    Log.i(TAG, getDownloadParams().getTag() + " download success");
                }

                @Override
                public void onProgressUpdate(int progress) {
                    Log.i(TAG, getDownloadParams().getTag() + " progress：" + progress);
                    tvProgress.setText("progress--->" + progress);
                }

                @Override
                public void onFailure(String msg) {
                    Log.i(TAG, getDownloadParams().getTag() + "下载失败 : " + msg);
                }
            });
        }
    }

}

@@ -1049,9 +1049,10 @@
 ool(
-3
+10
 ).bu
@@ -1386,9 +1386,11 @@
 i %3C 
-5
+100
 ; i+
@@ -1498,16 +1498,27 @@
 (testUrl
++%22?temp=%22+i
 , savePa
@@ -1779,26 +1779,19 @@
 g() + %22 
-download s
+onS
 tart%22);%0A
@@ -1945,18 +1945,11 @@
 + %22 
-download s
+onS
 ucce
@@ -2056,24 +2056,26 @@
 progress) %7B%0A
+//
             
@@ -2237,166 +2237,645 @@
     
-%7D%0A%0A                @Override%0A                public void onFailure(String msg) %7B%0A                    Log.i(TAG, getDownloadParams().getTag() + %22%E4%B8%8B%E8%BD%BD%E5%A4%B1%E8%B4%A5 : %22 + msg
+    if(progress%3E=5)%7B%0A                        AsyncDownload.getInstance().cancel(getDownloadParams().getUrl());%0A                    %7D%0A                %7D%0A%0A                @Override%0A                public void onFailure(String msg) %7B%0A                    Log.i(TAG, getDownloadParams().getTag() + %22 onFailure : %22 + msg);%0A                %7D%0A%0A                @Override%0A                public void onFinish() %7B%0A                    Log.i(TAG, getDownloadParams().getTag() + %22 onFinish%22);%0A                %7D%0A%0A                @Override%0A                public void onCancel() %7B%0A                    Log.i(TAG, getDownloadParams().getTag() + %22 onCancel%22
 );%0A 

Update Demo.