├── .gitignore ├── Demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── aigestudio │ │ └── downloader │ │ └── demo │ │ ├── DLService.java │ │ ├── MainActivity.java │ │ └── NotificationUtil.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable-xxxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ └── values │ └── strings.xml ├── Downloader ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── cn │ └── aigestudio │ └── downloader │ ├── bizs │ ├── DLCons.java │ ├── DLDBHelper.java │ ├── DLDBManager.java │ ├── DLError.java │ ├── DLException.java │ ├── DLHeader.java │ ├── DLInfo.java │ ├── DLManager.java │ ├── DLTask.java │ ├── DLThread.java │ ├── DLThreadInfo.java │ ├── DLUtil.java │ ├── IDLThreadListener.java │ ├── ITaskDAO.java │ ├── IThreadDAO.java │ ├── TaskDAO.java │ └── ThreadDAO.java │ └── interfaces │ ├── AsyncDListener.java │ ├── DLTaskListener.java │ ├── IDListener.java │ └── SimpleDListener.java ├── MultiThreadDownloader.iml ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── preview1.gif ├── preview2.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | *.iml 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /Demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "cn.aigestudio.downloader.demo" 9 | minSdkVersion 4 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile project(':Downloader') 25 | compile 'com.android.support:support-v4:22.1.1' 26 | // compile 'cn.aigestudio.downloader:Downloader:1.4.1' 27 | } 28 | -------------------------------------------------------------------------------- /Demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this dlLocalFile are appended to flags specified 3 | # in H:\Programming\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include dirPath and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Demo/src/main/java/cn/aigestudio/downloader/demo/DLService.java: -------------------------------------------------------------------------------- 1 | package cn.aigestudio.downloader.demo; 2 | 3 | import android.app.NotificationManager; 4 | import android.app.Service; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.IBinder; 8 | import android.support.v4.app.NotificationCompat; 9 | 10 | import java.io.File; 11 | 12 | import cn.aigestudio.downloader.bizs.DLManager; 13 | import cn.aigestudio.downloader.interfaces.SimpleDListener; 14 | 15 | /** 16 | * 执行下载的Service 17 | * 18 | * @author AigeStudio 2015-05-18 19 | */ 20 | public class DLService extends Service { 21 | 22 | @Override 23 | public int onStartCommand(Intent intent, int flags, int startId) { 24 | String url = intent.getStringExtra("url"); 25 | String path = intent.getStringExtra("path"); 26 | final int id = intent.getIntExtra("id", -1); 27 | final NotificationManager nm = (NotificationManager) getSystemService(Context 28 | .NOTIFICATION_SERVICE); 29 | final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 30 | .setSmallIcon(R.drawable.ic_launcher); 31 | 32 | final int[] length = new int[1]; 33 | DLManager.getInstance(this).dlStart(url, path, null, null, new SimpleDListener() { 34 | @Override 35 | public void onStart(String fileName, String realUrl, int fileLength) { 36 | builder.setContentTitle(fileName); 37 | length[0] = fileLength; 38 | } 39 | 40 | @Override 41 | public void onProgress(int progress) { 42 | builder.setProgress(length[0], progress, false); 43 | nm.notify(id, builder.build()); 44 | } 45 | 46 | @Override 47 | public void onFinish(File file) { 48 | nm.cancel(id); 49 | } 50 | }); 51 | return super.onStartCommand(intent, flags, startId); 52 | } 53 | 54 | @Override 55 | public IBinder onBind(Intent intent) { 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Demo/src/main/java/cn/aigestudio/downloader/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.aigestudio.downloader.demo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.os.Environment; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.ProgressBar; 9 | 10 | import cn.aigestudio.downloader.bizs.DLManager; 11 | import cn.aigestudio.downloader.interfaces.SimpleDListener; 12 | 13 | public class MainActivity extends Activity { 14 | private static final String[] URLS = { 15 | "http://china35.newhua.com/down/FetionNew2015September.zip", 16 | "http://download.chinaunix.net/down.php?id=10608&ResourceID=5267&site=1", 17 | "http://down.tech.sina.com.cn/download/d_load.php?d_id=49535&down_id=1&ip=42.81.45.159", 18 | "http://dlsw.baidu.com/sw-search-sp/soft/7b/33461/freeime.1406862029.exe", 19 | "http://113.207.16.84/dd.myapp.com/16891/2E53C25B6BC55D3330AB85A1B7B57485.apk?mkey=5630b43973f537cf&f=cf87&fsname=com.htshuo.htsg_3.0.1_49.apk&asr=02f1&p=.apk" 20 | }; 21 | 22 | private static final int[] RES_ID_BTN_START = { 23 | R.id.main_dl_start_btn1, 24 | R.id.main_dl_start_btn2, 25 | R.id.main_dl_start_btn3, 26 | R.id.main_dl_start_btn4, 27 | R.id.main_dl_start_btn5, 28 | R.id.main_dl_start_btn6}; 29 | private static final int[] RES_ID_BTN_STOP = { 30 | R.id.main_dl_stop_btn1, 31 | R.id.main_dl_stop_btn2, 32 | R.id.main_dl_stop_btn3, 33 | R.id.main_dl_stop_btn4, 34 | R.id.main_dl_stop_btn5, 35 | R.id.main_dl_stop_btn6}; 36 | private static final int[] RES_ID_PB = { 37 | R.id.main_dl_pb1, 38 | R.id.main_dl_pb2, 39 | R.id.main_dl_pb3, 40 | R.id.main_dl_pb4, 41 | R.id.main_dl_pb5, 42 | R.id.main_dl_pb6}; 43 | private static final int[] RES_ID_NOTIFY = { 44 | R.id.main_notify_btn1, 45 | R.id.main_notify_btn2, 46 | R.id.main_notify_btn3, 47 | R.id.main_notify_btn4, 48 | R.id.main_notify_btn5, 49 | R.id.main_notify_btn6}; 50 | 51 | private String saveDir; 52 | 53 | private ProgressBar[] pbDLs; 54 | 55 | @Override 56 | protected void onCreate(Bundle savedInstanceState) { 57 | super.onCreate(savedInstanceState); 58 | setContentView(R.layout.activity_main); 59 | 60 | DLManager.getInstance(MainActivity.this).setMaxTask(2); 61 | Button[] btnStarts = new Button[RES_ID_BTN_START.length]; 62 | for (int i = 0; i < btnStarts.length; i++) { 63 | btnStarts[i] = (Button) findViewById(RES_ID_BTN_START[i]); 64 | final int finalI = i; 65 | btnStarts[i].setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | DLManager.getInstance(MainActivity.this).dlStart(URLS[finalI], saveDir, 69 | null, null, new SimpleDListener(){ 70 | @Override 71 | public void onStart(String fileName, String realUrl, int fileLength) { 72 | pbDLs[finalI].setMax(fileLength); 73 | } 74 | 75 | @Override 76 | public void onProgress(int progress) { 77 | pbDLs[finalI].setProgress(progress); 78 | } 79 | }); 80 | } 81 | }); 82 | } 83 | 84 | Button[] btnStops = new Button[RES_ID_BTN_STOP.length]; 85 | for (int i = 0; i < btnStops.length; i++) { 86 | btnStops[i] = (Button) findViewById(RES_ID_BTN_STOP[i]); 87 | final int finalI = i; 88 | btnStops[i].setOnClickListener(new View.OnClickListener() { 89 | @Override 90 | public void onClick(View v) { 91 | DLManager.getInstance(MainActivity.this).dlStop(URLS[finalI]); 92 | } 93 | }); 94 | } 95 | 96 | pbDLs = new ProgressBar[RES_ID_PB.length]; 97 | for (int i = 0; i < pbDLs.length; i++) { 98 | pbDLs[i] = (ProgressBar) findViewById(RES_ID_PB[i]); 99 | pbDLs[i].setMax(100); 100 | } 101 | 102 | Button[] btnNotifys = new Button[RES_ID_NOTIFY.length]; 103 | for (int i = 0; i < btnNotifys.length; i++) { 104 | btnNotifys[i] = (Button) findViewById(RES_ID_NOTIFY[i]); 105 | final int finalI = i; 106 | btnNotifys[i].setOnClickListener(new View.OnClickListener() { 107 | @Override 108 | public void onClick(View v) { 109 | NotificationUtil.notificationForDLAPK(MainActivity.this, URLS[finalI]); 110 | } 111 | }); 112 | } 113 | 114 | saveDir = Environment.getExternalStorageDirectory() + "/AigeStudio/"; 115 | } 116 | 117 | @Override 118 | protected void onDestroy() { 119 | for (String url : URLS) { 120 | DLManager.getInstance(this).dlStop(url); 121 | } 122 | super.onDestroy(); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Demo/src/main/java/cn/aigestudio/downloader/demo/NotificationUtil.java: -------------------------------------------------------------------------------- 1 | package cn.aigestudio.downloader.demo; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Environment; 6 | 7 | /** 8 | * 通知工具类 9 | * 10 | * @author AigeStudio 2015-05-18 11 | */ 12 | public final class NotificationUtil { 13 | public static void notificationForDLAPK(Context context, String url) { 14 | notificationForDLAPK(context, url, Environment.getExternalStorageDirectory() + "/AigeStudio/"); 15 | } 16 | 17 | public static void notificationForDLAPK(Context context, String url, String path) { 18 | Intent intent = new Intent(context, DLService.class); 19 | intent.putExtra("url", url); 20 | intent.putExtra("path", path); 21 | intent.putExtra("id", (int) (Math.random() * 1024)); 22 | context.startService(intent); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Demo/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devaige/MultiThreadDownloader/21bf649b47ffb6830a2d15a2b7438a41bf3bca70/Demo/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Demo/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devaige/MultiThreadDownloader/21bf649b47ffb6830a2d15a2b7438a41bf3bca70/Demo/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Demo/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devaige/MultiThreadDownloader/21bf649b47ffb6830a2d15a2b7438a41bf3bca70/Demo/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Demo/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devaige/MultiThreadDownloader/21bf649b47ffb6830a2d15a2b7438a41bf3bca70/Demo/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Demo/src/main/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devaige/MultiThreadDownloader/21bf649b47ffb6830a2d15a2b7438a41bf3bca70/Demo/src/main/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | 13 | 14 |