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().setSingleThreadExecutor().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 < 1; 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,"download start");
                }

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

                @Override
                public void onProgressUpdate(int progress) {
                    tvProgress.setText("progress--->"+progress);
                }

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

}

@@ -463,17 +463,19 @@
 ring TAG
-=
+ = 
 %22AsyncDo
@@ -808,17 +808,19 @@
 Progress
-=
+ = 
 (TextVie
@@ -821,16 +821,17 @@
 extView)
+ 
 this.fin
@@ -929,16 +929,17 @@
 d init()
+ 
 %7B%0A      
@@ -1033,29 +1033,25 @@
 .set
-SingleThreadExecutor(
+FixedThreadPool(3
 ).bu
@@ -1209,24 +1209,25 @@
 rs();%0A    %7D%0A
+%0A
     Download
@@ -1241,16 +1241,17 @@
 params;%0A
+%0A
     priv
@@ -1381,17 +1381,17 @@
  0; i %3C 
-1
+5
 ; i++) %7B
@@ -1543,12 +1543,16 @@
 Tag%22
-+(i+
+ + (i + 
 1));
@@ -1723,33 +1723,66 @@
       Log.i(TAG,
-%22
+ getDownloadParams().getTag() + %22 
 download start%22)
@@ -1900,17 +1900,50 @@
 g.i(TAG,
-%22
+ getDownloadParams().getTag() + %22 
 download
@@ -2056,24 +2056,112 @@
 progress) %7B%0A
+                    Log.i(TAG, getDownloadParams().getTag() + %22 progress%EF%BC%9A%22 + progress);%0A
             
@@ -2201,17 +2201,19 @@
 ess---%3E%22
-+
+ + 
 progress
@@ -2342,16 +2342,48 @@
 g.i(TAG,
+ getDownloadParams().getTag() + 
 %22%E4%B8%8B%E8%BD%BD%E5%A4%B1%E8%B4%A5 : 
@@ -2385,16 +2385,17 @@
 %E5%A4%B1%E8%B4%A5 : %22 +
+ 
 msg);%0A  

Update demo.