├── FileDownloaderDemo2 ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values-w820dp │ │ │ ├── sizes.xml │ │ │ └── dimens.xml │ │ ├── values │ │ │ ├── integers.xml │ │ │ ├── dimens.xml │ │ │ ├── sizes.xml │ │ │ └── styles.xml │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-hdpi │ │ │ ├── advanced_use__btn_bottom_action_tab_1_normal.png │ │ │ ├── advanced_use__btn_bottom_action_tab_1_pressed.png │ │ │ ├── advanced_use__btn_bottom_action_tab_2_normal.png │ │ │ └── advanced_use__btn_bottom_action_tab_2_pressed.png │ │ ├── layout │ │ │ ├── main__activity_main.xml │ │ │ ├── custom_model__activity_custom_model.xml │ │ │ ├── advanced_use__fragment_course_preview.xml │ │ │ ├── advanced_use__activity_advanced_use.xml │ │ │ ├── advanced_use__bottom_action_tab.xml │ │ │ ├── advanced_use__item_course_preview.xml │ │ │ ├── advanced_use__fragment_course_download.xml │ │ │ ├── custom_model__item_download.xml │ │ │ └── advanced_use__item_course_download.xml │ │ ├── values-v11 │ │ │ └── styles.xml │ │ ├── values-v14 │ │ │ └── styles.xml │ │ └── drawable │ │ │ ├── advanced_use__selector_btn_bottom_action_tab_1.xml │ │ │ └── advanced_use__selector_btn_bottom_action_tab_2.xml │ │ ├── java │ │ └── org │ │ │ └── wlf │ │ │ └── filedownloader_demo2 │ │ │ ├── ToastUtil.java │ │ │ ├── advanced_use │ │ │ ├── course_download │ │ │ │ └── TimeUtil.java │ │ │ ├── data_access │ │ │ │ └── GetCourseDownloads.java │ │ │ ├── AdvancedUseActivity.java │ │ │ ├── db │ │ │ │ ├── CourseDbHelper.java │ │ │ │ └── BaseOrmLiteSQLiteHelper.java │ │ │ └── course_preview │ │ │ │ └── CoursePreviewFragment.java │ │ │ ├── MainActivity.java │ │ │ ├── FileDownloadApplication.java │ │ │ └── custom_model │ │ │ ├── CustomModelActivity.java │ │ │ └── CustomVideoInfo.java │ │ └── AndroidManifest.xml ├── libs │ ├── LibActionTabPager-release.aar │ └── circleprogressbarlib-0.6.1.aar ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .gitattributes ├── capture ├── simple_download.gif ├── manager_download.gif ├── manager_download_zh.gif └── simple_download_zh.gif ├── design ├── Download Process Map.png ├── Download Process Map.vsd ├── file-downloader uml.eap └── file-downloader classes map.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── download └── release │ ├── FileDownloader-0.3.2.jar │ └── FileDownloader-0.3.2-javadoc │ ├── resources │ ├── tab.gif │ ├── titlebar.gif │ ├── background.gif │ └── titlebar_end.gif │ ├── package-list │ ├── org │ └── wlf │ │ └── filedownloader │ │ ├── listener │ │ └── simple │ │ │ └── package-frame.html │ │ ├── file_move │ │ └── package-frame.html │ │ ├── file_delete │ │ └── package-frame.html │ │ ├── file_rename │ │ └── package-frame.html │ │ ├── db │ │ └── package-frame.html │ │ ├── file_download │ │ ├── db_recorder │ │ │ └── package-frame.html │ │ ├── package-frame.html │ │ ├── file_saver │ │ │ └── package-frame.html │ │ ├── base │ │ │ └── package-frame.html │ │ └── http_downloader │ │ │ └── package-frame.html │ │ ├── util │ │ └── package-frame.html │ │ ├── base │ │ └── package-frame.html │ │ └── package-frame.html │ ├── overview-frame.html │ └── index.html ├── FileDownloaderDemo ├── src │ └── main │ │ ├── res │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── main__ic_apk.png │ │ ├── values │ │ │ ├── dimens.xml │ │ │ ├── sizes.xml │ │ │ └── styles.xml │ │ ├── values-w820dp │ │ │ ├── dimens.xml │ │ │ └── sizes.xml │ │ ├── values-v11 │ │ │ └── styles.xml │ │ ├── values-v14 │ │ │ └── styles.xml │ │ ├── menu │ │ │ └── options.xml │ │ ├── layout │ │ │ ├── main__activity_main.xml │ │ │ └── main__item_download.xml │ │ └── values-zh │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── org │ │ └── wlf │ │ └── filedownloader_demo │ │ ├── util │ │ ├── TimeUtil.java │ │ └── ApkUtil.java │ │ └── FileDownloadApplication.java ├── build.gradle └── proguard-rules.pro ├── DESIGN.md ├── FileDownloader ├── project.properties ├── src │ └── main │ │ ├── java │ │ └── org │ │ │ └── wlf │ │ │ └── filedownloader │ │ │ ├── file_download │ │ │ ├── base │ │ │ │ ├── OnTaskRunFinishListener.java │ │ │ │ ├── RetryableDownloadTask.java │ │ │ │ ├── Pauseable.java │ │ │ │ ├── DownloadTask.java │ │ │ │ ├── DownloadRecorder.java │ │ │ │ ├── HttpFailReason.java │ │ │ │ └── OnStopFileDownloadTaskListener.java │ │ │ ├── http_downloader │ │ │ │ ├── Download.java │ │ │ │ ├── Range.java │ │ │ │ ├── ContentLengthInputStream.java │ │ │ │ └── ContentRangeInfo.java │ │ │ ├── db_recorder │ │ │ │ ├── Record.java │ │ │ │ ├── DownloadFileDbRecorder.java │ │ │ │ ├── DownloadFileDbHelper.java │ │ │ │ └── DownloadFileDao.java │ │ │ ├── file_saver │ │ │ │ ├── DownloadNoticeStrategy.java │ │ │ │ └── Save.java │ │ │ ├── CloseConnectionTask.java │ │ │ ├── DetectUrlFileInfo.java │ │ │ ├── DetectUrlFileCacher.java │ │ │ └── FileDownloadTaskParam.java │ │ │ ├── util │ │ │ ├── MathUtil.java │ │ │ ├── ArrayUtil.java │ │ │ ├── MapUtil.java │ │ │ ├── CollectionUtil.java │ │ │ ├── ContentValuesUtil.java │ │ │ ├── NetworkUtil.java │ │ │ └── DateUtil.java │ │ │ ├── base │ │ │ ├── Stoppable.java │ │ │ ├── Control.java │ │ │ ├── FailException.java │ │ │ ├── Status.java │ │ │ ├── UrlFailReason.java │ │ │ ├── BaseDownloadConfigBuilder.java │ │ │ └── BaseUrlFileInfo.java │ │ │ ├── file_delete │ │ │ └── DownloadFileDeleter.java │ │ │ ├── file_move │ │ │ └── DownloadFileMover.java │ │ │ ├── file_rename │ │ │ └── DownloadFileRenamer.java │ │ │ ├── db │ │ │ ├── DatabaseCallback.java │ │ │ ├── ContentDbDao.java │ │ │ ├── BaseContentDbDao.java │ │ │ └── BaseContentDbHelper.java │ │ │ ├── listener │ │ │ ├── OnRetryableFileDownloadStatusListener.java │ │ │ ├── OnDetectUrlFileListener.java │ │ │ └── simple │ │ │ │ └── OnSimpleFileDownloadStatusListener.java │ │ │ ├── DownloadStatusConfiguration.java │ │ │ └── DownloadFileChangeConfiguration.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── build.gradle └── bintrayUpload.gradle ├── .gitignore ├── gradle.properties ├── Q&A-zh.md ├── Q&A.md ├── gradlew.bat ├── maven_push.gradle └── USEINSERVICE-zh.md /FileDownloaderDemo2/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':FileDownloader', ':FileDownloaderDemo2' 2 | include ':FileDownloaderDemo' 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=Java 2 | *.css linguist-language=Java 3 | *.html linguist-language=Java -------------------------------------------------------------------------------- /capture/simple_download.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/capture/simple_download.gif -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values-w820dp/sizes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /capture/manager_download.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/capture/manager_download.gif -------------------------------------------------------------------------------- /capture/manager_download_zh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/capture/manager_download_zh.gif -------------------------------------------------------------------------------- /capture/simple_download_zh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/capture/simple_download_zh.gif -------------------------------------------------------------------------------- /design/Download Process Map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/design/Download Process Map.png -------------------------------------------------------------------------------- /design/Download Process Map.vsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/design/Download Process Map.vsd -------------------------------------------------------------------------------- /design/file-downloader uml.eap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/design/file-downloader uml.eap -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /design/file-downloader classes map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/design/file-downloader classes map.png -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/download/release/FileDownloader-0.3.2.jar -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 2 3 | 4 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/libs/LibActionTabPager-release.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/libs/LibActionTabPager-release.aar -------------------------------------------------------------------------------- /FileDownloaderDemo2/libs/circleprogressbarlib-0.6.1.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/libs/circleprogressbarlib-0.6.1.aar -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/mipmap-xhdpi/main__ic_apk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo/src/main/res/mipmap-xhdpi/main__ic_apk.png -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/resources/tab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/download/release/FileDownloader-0.3.2-javadoc/resources/tab.gif -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/resources/titlebar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/download/release/FileDownloader-0.3.2-javadoc/resources/titlebar.gif -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/resources/background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/download/release/FileDownloader-0.3.2-javadoc/resources/background.gif -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/resources/titlebar_end.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/download/release/FileDownloader-0.3.2-javadoc/resources/titlebar_end.gif -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 100dp 4 | 5 | 6 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 120dp 4 | 5 | 6 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_1_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_1_normal.png -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_1_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_1_pressed.png -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_2_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_2_normal.png -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_2_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gytai/file-downloader/master/FileDownloaderDemo2/src/main/res/mipmap-hdpi/advanced_use__btn_bottom_action_tab_2_pressed.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Nov 27 22:38:23 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /DESIGN.md: -------------------------------------------------------------------------------- 1 | # file-downloader Design 2 | 3 | **Download Process Map** 4 | ![image](https://github.com/wlfcolin/file-downloader/blob/master/design/Download Process Map.png) 5 | 6 | **Classes Map** 7 | ![image](https://github.com/wlfcolin/file-downloader/blob/master/design/file-downloader classes map.png) -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 100dp 4 | 5 | 8dp 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FileDownloader/project.properties: -------------------------------------------------------------------------------- 1 | #project 2 | project.name=file-downloader 3 | project.groupId=org.wlf 4 | project.artifactId=FileDownloader 5 | project.packaging=aar 6 | project.siteUrl=https://github.com/wlfcolin/file-downloader 7 | project.gitUrl=https://github.com/wlfcolin/file-downloader.git 8 | 9 | #javadoc 10 | javadoc.name=file-downloader -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/base/OnTaskRunFinishListener.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.base; 2 | 3 | /** 4 | * @author wlf(Andy) 5 | * @datetime 2016-03-27 21:00 GMT+8 6 | * @email 411086563@qq.com 7 | */ 8 | public interface OnTaskRunFinishListener { 9 | 10 | /** 11 | * onTaskRunFinish 12 | */ 13 | void onTaskRunFinish(); 14 | } 15 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/util/MathUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.util; 2 | 3 | /** 4 | * MathUtil 5 | * 6 | * @author wlf(Andy) 7 | * @datetime 2015-12-11 21:40 GMT+8 8 | * @email 411086563@qq.com 9 | */ 10 | public class MathUtil { 11 | 12 | public static double formatNumber(double number) { 13 | return (Math.round(number * 100.00)) / 100.00; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/layout/main__activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values/sizes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18sp 4 | 12sp 5 | 12sp 6 | 12sp 7 | 12sp 8 | 9 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values/sizes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18sp 4 | 12sp 5 | 12sp 6 | 12sp 7 | 12sp 8 | 9 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values-w820dp/sizes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24sp 4 | 18sp 5 | 18sp 6 | 18sp 7 | 18sp 8 | 9 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/layout/custom_model__activity_custom_model.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/http_downloader/Download.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.http_downloader; 2 | 3 | /** 4 | * download 5 | *
6 | * 下载接口 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public interface Download { 12 | 13 | /** 14 | * download 15 | * 16 | * @throws Exception any fail exception during download 17 | */ 18 | void download() throws Exception; 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | 8 | # Android generated 9 | bin/ 10 | gen/ 11 | 12 | # Ant 13 | build.xml 14 | local.properties 15 | 16 | # Maven 17 | target/ 18 | pom.xml.* 19 | release.properties 20 | 21 | # Eclipse 22 | .classpath 23 | .project 24 | .externalToolBuilders/ 25 | 26 | # IntelliJ 27 | *.iml 28 | *.ipr 29 | *.iws 30 | .idea/ 31 | out/ 32 | 33 | # Mac 34 | .DS_Store 35 | 36 | # Ignore gradle files 37 | .gradle/ 38 | build/ -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/base/Stoppable.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.base; 2 | 3 | /** 4 | * interface for those can stop classes 5 | *
6 | * 可停止接口 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public interface Stoppable { 12 | 13 | /** 14 | * stop 15 | */ 16 | void stop(); 17 | 18 | /** 19 | * whether is stopped 20 | * 21 | * @return true means stopped 22 | */ 23 | boolean isStopped(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/drawable/advanced_use__selector_btn_bottom_action_tab_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/drawable/advanced_use__selector_btn_bottom_action_tab_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/layout/advanced_use__fragment_course_preview.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/base/Control.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.base; 2 | 3 | /** 4 | * to control an operation 5 | * 6 | * @author wlf(Andy) 7 | * @datetime 2015-12-07 22:00 GMT+8 8 | * @email 411086563@qq.com 9 | */ 10 | public interface Control { 11 | 12 | /** 13 | * stop the operation 14 | */ 15 | void stop(); 16 | 17 | /** 18 | * whether is the operation stopped 19 | * 20 | * @return true means the operation has been stopped 21 | */ 22 | boolean isStopped(); 23 | } 24 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/base/RetryableDownloadTask.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.base; 2 | 3 | /** 4 | * RetryableDownloadTask interface 5 | * 6 | * @author wlf(Andy) 7 | * @datetime 2016-01-10 00:17 GMT+8 8 | * @email 411086563@qq.com 9 | * @since 0.3.0 10 | */ 11 | public interface RetryableDownloadTask extends DownloadTask { 12 | 13 | /** 14 | * set RetryDownloadTimes 15 | * 16 | * @param retryDownloadTimes 17 | */ 18 | void setRetryDownloadTimes(int retryDownloadTimes); 19 | } 20 | -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/package-list: -------------------------------------------------------------------------------- 1 | org.wlf.filedownloader 2 | org.wlf.filedownloader.base 3 | org.wlf.filedownloader.db 4 | org.wlf.filedownloader.file_delete 5 | org.wlf.filedownloader.file_download 6 | org.wlf.filedownloader.file_download.base 7 | org.wlf.filedownloader.file_download.db_recorder 8 | org.wlf.filedownloader.file_download.file_saver 9 | org.wlf.filedownloader.file_download.http_downloader 10 | org.wlf.filedownloader.file_move 11 | org.wlf.filedownloader.file_rename 12 | org.wlf.filedownloader.listener 13 | org.wlf.filedownloader.listener.simple 14 | org.wlf.filedownloader.util 15 | -------------------------------------------------------------------------------- /FileDownloader/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/util/ArrayUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.util; 2 | 3 | /** 4 | * Util for Array 5 | * 6 | * @author wlf(Andy) 7 | * @email 411086563@qq.com 8 | */ 9 | public class ArrayUtil { 10 | 11 | /** 12 | * Returns true if the array is null or 0-length. 13 | * 14 | * @param array the array to be examined 15 | * @return true if array is null or zero length 16 | */ 17 | public static boolean isEmpty(Object[] array) { 18 | if (array == null || array.length == 0) { 19 | return true; 20 | } else { 21 | return false; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_delete/DownloadFileDeleter.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_delete; 2 | 3 | import org.wlf.filedownloader.file_download.db_recorder.DownloadFileDbRecorder; 4 | 5 | /** 6 | * DownloadFileDeleter 7 | *
8 | * 删除下载文件 9 | * 10 | * @author wlf(Andy) 11 | * @email 411086563@qq.com 12 | * @since 0.3.0 13 | */ 14 | public interface DownloadFileDeleter extends DownloadFileDbRecorder { 15 | 16 | /** 17 | * delete download file 18 | * 19 | * @param url download url 20 | * @throws Exception any exception during delete 21 | */ 22 | void deleteDownloadFile(String url) throws Exception; 23 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=0.3.2 2 | VERSION_CODE=7 3 | POM_GROUP_ID=com.github.wlfcolin 4 | POM_DESCRIPTION=this is a powerful http-file download tool, it is to make downloading http file easily. 5 | POM_URL=https://github.com/wlfcolin/file-downloader 6 | POM_SCM_URL=https://github.com/wlfcolin/file-downloader 7 | POM_SCM_CONNECTION=scm:git@github.com:wlfcolin/file-downloader.git 8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:wlfcolin/file-downloader.git 9 | POM_LICENCE_NAME=The Apache License, Version 2.0 10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 11 | POM_LICENCE_DIST=repo 12 | POM_DEVELOPER_ID=wlfcolin 13 | POM_DEVELOPER_NAME=Andy Wu 14 | POM_INCEPTION_YEAR=2015 -------------------------------------------------------------------------------- /FileDownloaderDemo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 15 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "org.wlf.filedownloader_demo" 9 | minSdkVersion 8 10 | targetSdkVersion 15 11 | versionCode 7 12 | versionName "0.3.2" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile project(':FileDownloader') 25 | // compile 'org.wlf:FileDownloader:0.3.2' 26 | } 27 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_move/DownloadFileMover.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_move; 2 | 3 | import org.wlf.filedownloader.file_download.db_recorder.DownloadFileDbRecorder; 4 | 5 | /** 6 | * DownloadFileMover 7 | *
8 | * 移动下载文件 9 | * 10 | * @author wlf(Andy) 11 | * @email 411086563@qq.com 12 | * @since 0.3.0 13 | */ 14 | public interface DownloadFileMover extends DownloadFileDbRecorder { 15 | 16 | /** 17 | * move download file name 18 | * 19 | * @param url download url 20 | * @param newDirPath new file name 21 | * @throws Exception any exception during move 22 | */ 23 | void moveDownloadFile(String url, String newDirPath) throws Exception; 24 | } -------------------------------------------------------------------------------- /FileDownloader/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\_AndroidTools\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path 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 | -------------------------------------------------------------------------------- /FileDownloaderDemo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\_AndroidTools\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path 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 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/util/MapUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.util; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Util for {@link Map} 7 | * 8 | * @author wlf(Andy) 9 | * @datetime 2015-11-14 18:12 GMT+8 10 | * @email 411086563@qq.com 11 | */ 12 | public class MapUtil { 13 | 14 | /** 15 | * Returns true if the collection is null or 0-length. 16 | * 17 | * @param map the map to be examined 18 | * @return true if str is null or zero length 19 | */ 20 | public static boolean isEmpty(Map map) { 21 | if (map == null || map.isEmpty() || map.size() == 0) { 22 | return true; 23 | } else { 24 | return false; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /FileDownloader/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | android { 3 | compileSdkVersion 8 4 | buildToolsVersion "23.0.3" 5 | defaultConfig { 6 | minSdkVersion 8 7 | targetSdkVersion 8 8 | versionCode 7 9 | versionName "0.3.2" 10 | } 11 | buildTypes { 12 | release { 13 | minifyEnabled false 14 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 15 | } 16 | } 17 | 18 | // only use by uploading release version to bintray 19 | // apply from: "bintrayUpload.gradle" 20 | // only use by uploading release version to maven center 21 | // apply from: '../maven_push.gradle' 22 | 23 | } 24 | 25 | dependencies { 26 | } 27 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_rename/DownloadFileRenamer.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_rename; 2 | 3 | import org.wlf.filedownloader.file_download.db_recorder.DownloadFileDbRecorder; 4 | 5 | /** 6 | * DownloadFileRenamer 7 | *
8 | * 重命名下载文件 9 | * 10 | * @author wlf(Andy) 11 | * @email 411086563@qq.com 12 | * @since 0.3.0 13 | */ 14 | public interface DownloadFileRenamer extends DownloadFileDbRecorder { 15 | 16 | /** 17 | * rename download file name 18 | * 19 | * @param url download url 20 | * @param newFileName new file name 21 | * @throws Exception any exception during rename 22 | */ 23 | void renameDownloadFile(String url, String newFileName) throws Exception; 24 | } -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/db_recorder/Record.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.db_recorder; 2 | 3 | import org.wlf.filedownloader.base.Status; 4 | 5 | /** 6 | * record status 7 | *
8 | * 记录状态接口 9 | * 10 | * @author wlf(Andy) 11 | * @email 411086563@qq.com 12 | */ 13 | public interface Record { 14 | 15 | /** 16 | * record status 17 | * 18 | * @param url download url 19 | * @param status record status,ref{@link Status} 20 | * @param increaseSize increased size since last record 21 | * @throws Exception any fail exception during recording status 22 | */ 23 | void recordStatus(String url, int status, int increaseSize) throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wlf/android/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path 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 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/util/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.util; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * Util for {@link Collection} 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public class CollectionUtil { 12 | 13 | /** 14 | * Returns true if the collection is null or 0-length. 15 | * 16 | * @param collection the collection to be examined 17 | * @return true if str collection null or zero length 18 | */ 19 | public static boolean isEmpty(Collection collection) { 20 | if (collection == null || collection.isEmpty() || collection.size() == 0) { 21 | return true; 22 | } else { 23 | return false; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/util/ContentValuesUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.util; 2 | 3 | import android.content.ContentValues; 4 | 5 | /** 6 | * Util for {@link ContentValues} 7 | * 8 | * @author wlf(Andy) 9 | * @datetime 2015-11-14 17:53 GMT+8 10 | * @email 411086563@qq.com 11 | */ 12 | public class ContentValuesUtil { 13 | 14 | /** 15 | * Returns true if the values is null or 0-length. 16 | * 17 | * @param values the values to be examined 18 | * @return true if values is null or zero length 19 | */ 20 | public static boolean isEmpty(ContentValues values) { 21 | if (values == null || values.size() == 0) { 22 | return true; 23 | } else { 24 | return false; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/java/org/wlf/filedownloader_demo2/ToastUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader_demo2; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * show toast util 8 | * 9 | * @author wlf 10 | * @email 411086563@qq.com 11 | */ 12 | public class ToastUtil { 13 | 14 | private static Toast cacheToast = null; 15 | 16 | /** 17 | * show toast 18 | * 19 | * @param context 20 | * @param msg 21 | */ 22 | public static final void showToast(Context context, String msg) { 23 | if (cacheToast != null) { 24 | cacheToast.cancel(); 25 | } 26 | cacheToast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT); 27 | cacheToast.show(); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/file_saver/DownloadNoticeStrategy.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.file_saver; 2 | 3 | /** 4 | * the Strategy use for notify download progress 5 | *
6 | * 更新进度的策略 7 | * 8 | * @author wlf(Andy) 9 | * @datetime 2015-11-25 11:40 GMT+8 10 | * @email 411086563@qq.com 11 | */ 12 | public enum DownloadNoticeStrategy { 13 | 14 | NOTICE_AUTO(-1),// notice auto 15 | NOTICE_BY_SIZE(1024 * 1024),// notice by size, 1M(bytes for mValue) 16 | NOTICE_BY_TIME(1000 * 2);// notice by time interval, 2s(milliseconds for mValue) 17 | 18 | private long mValue; 19 | 20 | private DownloadNoticeStrategy(long value) { 21 | this.mValue = value; 22 | } 23 | 24 | public long getValue() { 25 | return mValue; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/db/DatabaseCallback.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.db; 2 | 3 | import android.database.sqlite.SQLiteDatabase; 4 | import android.database.sqlite.SQLiteOpenHelper; 5 | 6 | /** 7 | * database callback, see {@link SQLiteOpenHelper}.onXXXX 8 | * 9 | * @author wlf(Andy) 10 | * @email 411086563@qq.com 11 | */ 12 | public interface DatabaseCallback { 13 | 14 | /** 15 | * the database has been created 16 | * 17 | * @param db SQLiteDatabase 18 | */ 19 | void onCreate(SQLiteDatabase db); 20 | 21 | /** 22 | * the database has been upgraded 23 | * 24 | * @param db SQLiteDatabase 25 | * @param oldVersion oldVersion 26 | * @param newVersion newVersion 27 | */ 28 | void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); 29 | } 30 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/db_recorder/DownloadFileDbRecorder.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.db_recorder; 2 | 3 | import org.wlf.filedownloader.DownloadFileInfo; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * record status for download file 9 | *
10 | * 数据库记录器(记录下载文件状态) 11 | * 12 | * @author wlf(Andy) 13 | * @email 411086563@qq.com 14 | */ 15 | public interface DownloadFileDbRecorder extends Record { 16 | 17 | /** 18 | * get DownloadFile by url 19 | * 20 | * @param url the url 21 | * @return DownloadFile recorded 22 | */ 23 | DownloadFileInfo getDownloadFile(String url); 24 | 25 | /** 26 | * get all DownloadFiles 27 | * 28 | * @return all DownloadFile recorded 29 | */ 30 | List getDownloadFiles(); 31 | } 32 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/base/Pauseable.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.base; 2 | 3 | /** 4 | * Pauseable interface 5 | *
6 | * 可暂停的接口 7 | * 8 | * @author wlf(Andy) 9 | * @datetime 2016-01-10 00:44 GMT+8 10 | * @email 411086563@qq.com 11 | * @since 0.3.0 12 | */ 13 | public interface Pauseable { 14 | 15 | /** 16 | * whether is downloading 17 | * 18 | * @param url file url 19 | * @return true means the download task of the url is running 20 | */ 21 | boolean isDownloading(String url); 22 | 23 | /** 24 | * pause a download 25 | * 26 | * @param url file url 27 | * @param onStopFileDownloadTaskListener OnStopFileDownloadTaskListener impl 28 | */ 29 | void pause(String url, OnStopFileDownloadTaskListener onStopFileDownloadTaskListener); 30 | } 31 | -------------------------------------------------------------------------------- /Q&A-zh.md: -------------------------------------------------------------------------------- 1 | # file-downloader 常见问题 2 | 3 | ---------------------------------------------------------------------- 4 | Q: 如果针对同一的url连续调用FileDownloader.start(url)两次会导致这个url对对于的文件下载两次吗? 5 | 6 | A: 不会,FileDownloader是通过url来区分一个文件的,如果对同一的url调用下载方法两次,那么第二次将会忽略。 7 | 8 | ---------------------------------------------------------------------- 9 | Q: 如果本地文件被手动或者别的软件删除了(前提是不是调用FileDownloader.delete()方法删除的),那么下次下载会自动重新开始下载吗? 10 | 11 | A: 不会,FileDownloader回通过状态告诉你文件不存在了(DownloadFileInfo.getStatus() == DOWNLOAD_STATUS_FILE_NOT_EXIST)也会通过失败回调告诉你文件不存在了(OnFileDownloadStatusListener.onFileDownloadStatusFailed回调中的FileDownloadStatusFailReason.TYPE_SAVE_FILE_NOT_EXIST). 12 | 13 | ---------------------------------------------------------------------- 14 | Q: 如果服务器文件被替换了,但是下载URL还是一样,请问会自动重新下载这个URL地址一样的新文件吗? 15 | 16 | A: 不会,如果服务器支持eTag,FileDownloader会通过失败回调告诉你文件改变了(FileDownloadStatusFailReason.TYPE_DOWNLOAD_FILE_ERROR,0.3.1之后这种情况失败改为FileDownloadStatusFailReason.TYPE_URL_FILE_CHANGED)。 17 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/file_saver/Save.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.file_saver; 2 | 3 | import org.wlf.filedownloader.file_download.http_downloader.ContentLengthInputStream; 4 | 5 | /** 6 | * save data 7 | *
8 | * 保存接口 9 | * 10 | * @author wlf(Andy) 11 | * @email 411086563@qq.com 12 | */ 13 | public interface Save { 14 | 15 | /** 16 | * save data 17 | * 18 | * @param inputStream the inputStream data needed to save 19 | * @param startPosInTotal the start position of inputStream start to save in total data 20 | *

21 | * |(0,totalStart)----|(startPosInTotal,inputStream start)--- 22 | * |(inputStream.length,inputStream end)----|(fileTotalSize,totalEnd) 23 | * @throws Exception any fail exception during saving data 24 | */ 25 | void saveData(ContentLengthInputStream inputStream, long startPosInTotal) throws Exception; 26 | } 27 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/base/FailException.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.base; 2 | 3 | /** 4 | * fail exception, use for sync method call 5 | *
6 | * 失败异常,用于同步调用抛出的异常 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public abstract class FailException extends FailReason { 12 | 13 | public FailException(String type) { 14 | super(type); 15 | } 16 | 17 | public FailException(String detailMessage, String type) { 18 | super(detailMessage, type); 19 | } 20 | 21 | public FailException(String detailMessage, Throwable throwable, String type) { 22 | super(detailMessage, throwable, type); 23 | } 24 | 25 | public FailException(Throwable throwable, String type) { 26 | super(throwable, type); 27 | } 28 | 29 | public FailException(String detailMessage, Throwable throwable) { 30 | super(detailMessage, throwable); 31 | } 32 | 33 | public FailException(Throwable throwable) { 34 | super(throwable); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/base/DownloadTask.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.base; 2 | 3 | import org.wlf.filedownloader.base.Stoppable; 4 | 5 | /** 6 | * DownloadTask interface 7 | * 8 | * @author wlf(Andy) 9 | * @datetime 2016-01-10 00:12 GMT+8 10 | * @email 411086563@qq.com 11 | * @since 0.3.0 12 | */ 13 | public interface DownloadTask extends Runnable, Stoppable { 14 | 15 | /** 16 | * get download url of the task 17 | * 18 | * @return download url 19 | */ 20 | String getUrl(); 21 | 22 | /** 23 | * set StopFileDownloadTaskListener 24 | * 25 | * @param onStopFileDownloadTaskListener OnStopFileDownloadTaskListener 26 | */ 27 | void setOnStopFileDownloadTaskListener(OnStopFileDownloadTaskListener onStopFileDownloadTaskListener); 28 | 29 | /** 30 | * set TaskRunFinishListener 31 | * 32 | * @param onTaskRunFinishListener 33 | */ 34 | void setOnTaskRunFinishListener(OnTaskRunFinishListener onTaskRunFinishListener); 35 | } 36 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/db_recorder/DownloadFileDbHelper.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.db_recorder; 2 | 3 | import android.content.Context; 4 | 5 | import org.wlf.filedownloader.db.BaseContentDbHelper; 6 | import org.wlf.filedownloader.db.ContentDbDao; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * DownloadFile DbHelper 12 | *
13 | * 下载文件数据库操作类 14 | * 15 | * @author wlf(Andy) 16 | * @email 411086563@qq.com 17 | */ 18 | public class DownloadFileDbHelper extends BaseContentDbHelper { 19 | 20 | private static final String DB_NAME = "download_file.db"; 21 | private static final int DB_VERSION = 3; 22 | 23 | public DownloadFileDbHelper(Context context) { 24 | super(context, DB_NAME, null, DB_VERSION); 25 | } 26 | 27 | @Override 28 | protected void onConfigContentDbDaos(List contentDbDaos) { 29 | DownloadFileDao downloadFileDao = new DownloadFileDao(this); 30 | // config DownloadFileDao dao 31 | contentDbDaos.add(downloadFileDao); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/org/wlf/filedownloader/listener/simple/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.wlf.filedownloader.listener.simple (file-downloader) 8 | 9 | 10 | 11 | 12 |

org.wlf.filedownloader.listener.simple

13 |
14 |

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/layout/advanced_use__activity_advanced_use.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 15 | 16 | 17 | 21 | 22 | 23 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 15 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "org.wlf.filedownloader_demo2" 9 | minSdkVersion 15 10 | targetSdkVersion 15 11 | versionCode 7 12 | versionName "0.3.2" 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(':FileDownloader') 25 | // compile 'org.wlf:FileDownloader:0.3.2' 26 | 27 | // compile 'me.tedyin.circleprogressbarlib:circleprogressbarlib:0.6.1' 28 | compile(name: 'circleprogressbarlib-0.6.1', ext: 'aar') 29 | compile(name: 'LibActionTabPager-release', ext: 'aar') 30 | 31 | compile 'com.j256.ormlite:ormlite-android:4.48' 32 | compile 'com.android.support:recyclerview-v7:23.1.1' 33 | 34 | compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' 35 | } 36 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/menu/options.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 13 | 18 | 19 | 24 | 25 | 30 | 31 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/CloseConnectionTask.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.HttpURLConnection; 6 | 7 | /** 8 | * CloseConnection Task 9 | *
10 | * 连接关闭的任务 11 | * 12 | * @author wlf(Andy) 13 | * @email 411086563@qq.com 14 | */ 15 | public class CloseConnectionTask implements Runnable { 16 | 17 | private HttpURLConnection mURLConnection = null; 18 | private InputStream mInputStream = null; 19 | 20 | public CloseConnectionTask(HttpURLConnection urlConnection, InputStream inputStream) { 21 | mURLConnection = urlConnection; 22 | mInputStream = inputStream; 23 | } 24 | 25 | @Override 26 | public void run() { 27 | // close inputStream 28 | if (mInputStream != null) { 29 | try { 30 | mInputStream.close(); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | // close connection 37 | if (mURLConnection != null) { 38 | mURLConnection.disconnect(); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/org/wlf/filedownloader/file_move/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.wlf.filedownloader.file_move (file-downloader) 8 | 9 | 10 | 11 | 12 |

org.wlf.filedownloader.file_move

13 |
14 |

接口

15 | 18 |

19 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/org/wlf/filedownloader/file_delete/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.wlf.filedownloader.file_delete (file-downloader) 8 | 9 | 10 | 11 | 12 |

org.wlf.filedownloader.file_delete

13 |
14 |

接口

15 | 18 |

19 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/org/wlf/filedownloader/file_rename/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.wlf.filedownloader.file_rename (file-downloader) 8 | 9 | 10 | 11 | 12 |

org.wlf.filedownloader.file_rename

13 |
14 |

接口

15 | 18 |

19 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/base/DownloadRecorder.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.base; 2 | 3 | import org.wlf.filedownloader.DownloadFileInfo; 4 | import org.wlf.filedownloader.file_download.DetectUrlFileInfo; 5 | import org.wlf.filedownloader.file_download.db_recorder.DownloadFileDbRecorder; 6 | 7 | /** 8 | * DownloadRecorder 9 | *
10 | * 删除下载文件任务 11 | * 12 | * @author wlf(Andy) 13 | * @email 411086563@qq.com 14 | * @since 0.3.0 15 | */ 16 | public interface DownloadRecorder extends DownloadFileDbRecorder { 17 | 18 | /** 19 | * record download file 20 | * 21 | * @param url file url 22 | * @param deleteMode true means delete all resource 23 | * @throws Exception any exception during record 24 | */ 25 | void resetDownloadFile(String url, boolean deleteMode) throws Exception; 26 | 27 | /** 28 | * reset download size 29 | * 30 | * @param url download url 31 | * @param downloadSize the downloadSize reset to 32 | * @throws Exception any fail exception during recording status 33 | */ 34 | void resetDownloadSize(String url, long downloadSize) throws Exception; 35 | 36 | DownloadFileInfo createDownloadFileInfo(DetectUrlFileInfo detectUrlFileInfo); 37 | } -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/util/NetworkUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | /** 8 | * NetworkUtil 9 | * 10 | * @author wlf(Andy) 11 | * @email 411086563@qq.com 12 | */ 13 | public class NetworkUtil { 14 | 15 | /** 16 | * is network available 17 | * 18 | * @param context Context 19 | * @return true means network is available 20 | */ 21 | public static boolean isNetworkAvailable(Context context) { 22 | boolean isNetwork = false; 23 | ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 24 | if (connectivity == null) { 25 | return isNetwork; 26 | } else { 27 | NetworkInfo[] info = connectivity.getAllNetworkInfo(); 28 | if (info != null) { 29 | for (int i = 0; i < info.length; i++) { 30 | if (info[i].getState() == NetworkInfo.State.CONNECTED) { 31 | isNetwork = true; 32 | break; 33 | } 34 | } 35 | } 36 | return isNetwork; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/java/org/wlf/filedownloader_demo/util/TimeUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader_demo.util; 2 | 3 | /** 4 | * time util 5 | *
6 | * 时间工具类 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public class TimeUtil { 12 | 13 | /** 14 | * format seconds to HH:mm:ss String 15 | * 16 | * @param seconds seconds 17 | * @return String of formatted in HH:mm:ss 18 | */ 19 | public static String seconds2HH_mm_ss(long seconds) { 20 | 21 | long h = 0; 22 | long m = 0; 23 | long s = 0; 24 | long temp = seconds % 3600; 25 | 26 | if (seconds > 3600) { 27 | h = seconds / 3600; 28 | if (temp != 0) { 29 | if (temp > 60) { 30 | m = temp / 60; 31 | if (temp % 60 != 0) { 32 | s = temp % 60; 33 | } 34 | } else { 35 | s = temp; 36 | } 37 | } 38 | } else { 39 | m = seconds / 60; 40 | if (seconds % 60 != 0) { 41 | s = seconds % 60; 42 | } 43 | } 44 | 45 | String dh = h < 10 ? "0" + h : h + ""; 46 | String dm = m < 10 ? "0" + m : m + ""; 47 | String ds = s < 10 ? "0" + s : s + ""; 48 | 49 | return dh + ":" + dm + ":" + ds; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /download/release/FileDownloader-0.3.2-javadoc/org/wlf/filedownloader/db/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | org.wlf.filedownloader.db (file-downloader) 8 | 9 | 10 | 11 | 12 |

org.wlf.filedownloader.db

13 |
14 |

接口

15 | 19 |

20 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/java/org/wlf/filedownloader_demo2/advanced_use/course_download/TimeUtil.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader_demo2.advanced_use.course_download; 2 | 3 | /** 4 | * time util 5 | *
6 | * 时间工具类 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public class TimeUtil { 12 | 13 | /** 14 | * format seconds to HH:mm:ss String 15 | * 16 | * @param seconds seconds 17 | * @return String of formatted in HH:mm:ss 18 | */ 19 | public static String seconds2HH_mm_ss(long seconds) { 20 | 21 | long h = 0; 22 | long m = 0; 23 | long s = 0; 24 | long temp = seconds % 3600; 25 | 26 | if (seconds > 3600) { 27 | h = seconds / 3600; 28 | if (temp != 0) { 29 | if (temp > 60) { 30 | m = temp / 60; 31 | if (temp % 60 != 0) { 32 | s = temp % 60; 33 | } 34 | } else { 35 | s = temp; 36 | } 37 | } 38 | } else { 39 | m = seconds / 60; 40 | if (seconds % 60 != 0) { 41 | s = seconds % 60; 42 | } 43 | } 44 | 45 | String dh = h < 10 ? "0" + h : h + ""; 46 | String dm = m < 10 ? "0" + m : m + ""; 47 | String ds = s < 10 ? "0" + s : s + ""; 48 | 49 | return dh + ":" + dm + ":" + ds; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Q&A.md: -------------------------------------------------------------------------------- 1 | # file-downloader Frequently Asked Questions 2 | 3 | ---------------------------------------------------------------------- 4 | *Q:* if i call the FileDownloader.start(url) twice with the same url, whether FileDownloader will download the url file twice ? 5 | 6 | *A:* No, FileDownloader will never download the file that has been downloaded, in this cause, if FileDownloader is downloading the url file, the second call the same url will do nothing. 7 | 8 | ---------------------------------------------------------------------- 9 | *Q:* if FileDownloader can auto download a file that has been deleted without FileDownloader.delete() in local storage file system such as sdcard by calling FileDownloader.start(url) ? 10 | 11 | *A:* No, FileDownloader will tell you the status DOWNLOAD_STATUS_FILE_NOT_EXIST through DownloadFileInfo.getStatus() or FileDownloadStatusFailReason.TYPE_SAVE_FILE_NOT_EXIST in OnFileDownloadStatusListener.onFileDownloadStatusFailed callback. 12 | 13 | ---------------------------------------------------------------------- 14 | *Q:* if the server url file change a new file, but the url is not changed, whether the FileDownloader will reStart download the url file automatic 15 | 16 | *A:* No, if the server provided eTag, FileDownloader will tell you FileDownloadStatusFailReason.TYPE_DOWNLOAD_FILE_ERROR (since 0.3.1, in this case the type will be FileDownloadStatusFailReason.TYPE_URL_FILE_CHANGED) in OnFileDownloadStatusListener.onFileDownloadStatusFailed callback. 17 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/layout/advanced_use__bottom_action_tab.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 15 | 16 | 23 | 24 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /FileDownloader/src/main/java/org/wlf/filedownloader/file_download/http_downloader/Range.java: -------------------------------------------------------------------------------- 1 | package org.wlf.filedownloader.file_download.http_downloader; 2 | 3 | /** 4 | * data range 5 | *
6 | * 表示数据范围 7 | * 8 | * @author wlf(Andy) 9 | * @email 411086563@qq.com 10 | */ 11 | public class Range { 12 | 13 | public final long startPos;// public final field 14 | public final long endPos;// public final field 15 | 16 | public Range(long startPos, long endPos) { 17 | super(); 18 | this.startPos = startPos; 19 | this.endPos = endPos; 20 | } 21 | 22 | public long getLength() { 23 | return endPos - startPos; 24 | } 25 | 26 | /** 27 | * check data range whether legal 28 | * 29 | * @param range data range 30 | * @return true means legal 31 | */ 32 | public static boolean isLegal(Range range) { 33 | if (range != null && range.startPos >= 0 && range.endPos > 0 && range.endPos > range.startPos) { 34 | return true; 35 | } 36 | return false; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | if (o instanceof Range) { 42 | Range other = (Range) o; 43 | if (other.startPos == startPos && other.endPos == endPos) { 44 | return true; 45 | } 46 | } 47 | return false; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "[" + startPos + "," + endPos + "]"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 13 | 14 | 15 | 18 | 19 | 20 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /FileDownloaderDemo2/src/main/res/layout/advanced_use__item_course_preview.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 21 | 22 | 28 | 29 | 30 | 40 | 41 | -------------------------------------------------------------------------------- /FileDownloaderDemo/src/main/res/layout/main__activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | 18 | 19 |