├── .gitattributes
├── .gitignore
├── MainActivity
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── bin
│ ├── AndroidManifest.xml
│ ├── MainActivity.apk
│ ├── R.txt
│ ├── classes.dex
│ ├── classes
│ │ └── com
│ │ │ └── xckevin
│ │ │ ├── androiddownloadcomponent
│ │ │ ├── R$drawable.class
│ │ │ ├── R$string.class
│ │ │ ├── R$style.class
│ │ │ └── R.class
│ │ │ └── download
│ │ │ ├── AppContext.class
│ │ │ ├── BuildConfig.class
│ │ │ ├── R$attr.class
│ │ │ ├── R$dimen.class
│ │ │ ├── R$drawable.class
│ │ │ ├── R$id.class
│ │ │ ├── R$layout.class
│ │ │ ├── R$menu.class
│ │ │ ├── R$raw.class
│ │ │ ├── R$string.class
│ │ │ ├── R$style.class
│ │ │ ├── R.class
│ │ │ ├── model
│ │ │ └── GameInfoModel.class
│ │ │ ├── ui
│ │ │ ├── IDCreate.class
│ │ │ ├── ListActivity$1.class
│ │ │ ├── ListActivity.class
│ │ │ ├── ListAdapter$1.class
│ │ │ ├── ListAdapter$2.class
│ │ │ ├── ListAdapter$ViewHolder.class
│ │ │ ├── ListAdapter.class
│ │ │ └── MainActivity.class
│ │ │ └── util
│ │ │ └── SourceProvicer.class
│ ├── dexedLibs
│ │ ├── afinal_0.5.1_bin-bcdf7a8cb36c2d22db2af93ccc728359.jar
│ │ ├── android-support-v4-2df5435911296a354a1b7c19d9ff9857.jar
│ │ └── lib_download-821b26c3c1e1d4f4ea62161b71c042e5.jar
│ ├── jarlist.cache
│ ├── res
│ │ └── crunch
│ │ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ └── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ └── resources.ap_
├── gen
│ └── com
│ │ └── xckevin
│ │ ├── androiddownloadcomponent
│ │ └── R.java
│ │ └── download
│ │ ├── BuildConfig.java
│ │ └── R.java
├── ic_launcher-web.png
├── libs
│ ├── afinal_0.5.1_bin.jar
│ └── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── activity_list.xml
│ │ ├── activity_main.xml
│ │ └── item_download.xml
│ ├── menu
│ │ └── main.xml
│ ├── raw
│ │ └── gamehelper.db
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── xckevin
│ └── download
│ ├── AppContext.java
│ ├── model
│ └── GameInfoModel.java
│ ├── ui
│ ├── IDCreate.java
│ ├── ListActivity.java
│ ├── ListAdapter.java
│ └── MainActivity.java
│ └── util
│ └── SourceProvicer.java
├── README.md
└── lib_download
├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── bin
├── AndroidManifest.xml
├── R.txt
├── classes
│ └── com
│ │ └── xckevin
│ │ ├── androiddownloadcomponent
│ │ ├── BuildConfig.class
│ │ ├── R$attr.class
│ │ ├── R$drawable.class
│ │ ├── R$string.class
│ │ ├── R$style.class
│ │ └── R.class
│ │ └── download
│ │ ├── DownloadConfig$Builder.class
│ │ ├── DownloadConfig.class
│ │ ├── DownloadListener.class
│ │ ├── DownloadManager$1.class
│ │ ├── DownloadManager$10.class
│ │ ├── DownloadManager$11.class
│ │ ├── DownloadManager$2.class
│ │ ├── DownloadManager$3.class
│ │ ├── DownloadManager$4.class
│ │ ├── DownloadManager$5.class
│ │ ├── DownloadManager$6.class
│ │ ├── DownloadManager$7.class
│ │ ├── DownloadManager$8.class
│ │ ├── DownloadManager$9.class
│ │ ├── DownloadManager.class
│ │ ├── DownloadObserver.class
│ │ ├── DownloadOperator.class
│ │ ├── DownloadProvider.class
│ │ ├── DownloadTask.class
│ │ ├── DownloadTaskIDCreator.class
│ │ ├── Env.class
│ │ ├── MD5DownloadTaskIDCreator.class
│ │ ├── SqlLiteDownloadProvider.class
│ │ └── util
│ │ ├── FileUtil.class
│ │ ├── MD5.class
│ │ └── StringUtil.class
├── lib_download.jar
└── res
│ └── crunch
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ └── drawable-xxhdpi
│ └── ic_launcher.png
├── gen
└── com
│ └── xckevin
│ └── androiddownloadcomponent
│ ├── BuildConfig.java
│ └── R.java
├── ic_launcher-web.png
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── xckevin
└── download
├── DownloadConfig.java
├── DownloadListener.java
├── DownloadManager.java
├── DownloadObserver.java
├── DownloadOperator.java
├── DownloadProvider.java
├── DownloadTask.java
├── DownloadTaskIDCreator.java
├── Env.java
├── MD5DownloadTaskIDCreator.java
├── SqlLiteDownloadProvider.java
└── util
├── FileUtil.java
├── MD5.java
└── StringUtil.java
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # =========================
18 | # Operating System Files
19 | # =========================
20 |
21 | # OSX
22 | # =========================
23 |
24 | .DS_Store
25 | .AppleDouble
26 | .LSOverride
27 |
28 | # Icon must ends with two \r.
29 | Icon
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
--------------------------------------------------------------------------------
/MainActivity/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MainActivity/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainActivity
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/MainActivity/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/MainActivity/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/MainActivity/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/MainActivity/bin/MainActivity.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/MainActivity.apk
--------------------------------------------------------------------------------
/MainActivity/bin/R.txt:
--------------------------------------------------------------------------------
1 | int dimen activity_horizontal_margin 0x7f070000
2 | int dimen activity_vertical_margin 0x7f070001
3 | int drawable ic_launcher 0x7f020000
4 | int id action_settings 0x7f09000e
5 | int id delete 0x7f090005
6 | int id download_add_Btn 0x7f090000
7 | int id download_list_LV 0x7f090001
8 | int id item_action_Layout 0x7f090007
9 | int id item_info_Layout 0x7f09000a
10 | int id item_name 0x7f09000b
11 | int id item_progress 0x7f09000c
12 | int id item_speed 0x7f09000d
13 | int id item_start 0x7f090008
14 | int id item_stop 0x7f090009
15 | int id pause 0x7f090004
16 | int id progressbar 0x7f090002
17 | int id start 0x7f090003
18 | int id state 0x7f090006
19 | int layout activity_list 0x7f030000
20 | int layout activity_main 0x7f030001
21 | int layout item_download 0x7f030002
22 | int menu main 0x7f080000
23 | int raw gamehelper 0x7f040000
24 | int string action_settings 0x7f050001
25 | int string app_name 0x7f050000
26 | int string hello_world 0x7f050002
27 | int style AppBaseTheme 0x7f060000
28 | int style AppTheme 0x7f060001
29 | int style btn_download_action 0x7f060002
30 |
--------------------------------------------------------------------------------
/MainActivity/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes.dex
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R$drawable.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R$string.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R$style.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/androiddownloadcomponent/R.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/AppContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/AppContext.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/BuildConfig.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$attr.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$dimen.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$drawable.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$id.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$layout.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$menu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$menu.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$raw.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$raw.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$string.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R$style.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/R.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/model/GameInfoModel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/model/GameInfoModel.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/IDCreate.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/IDCreate.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/ListActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/ListActivity$1.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/ListActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/ListActivity.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter$1.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter$2.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter$ViewHolder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter$ViewHolder.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/ListAdapter.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/ui/MainActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/ui/MainActivity.class
--------------------------------------------------------------------------------
/MainActivity/bin/classes/com/xckevin/download/util/SourceProvicer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/classes/com/xckevin/download/util/SourceProvicer.class
--------------------------------------------------------------------------------
/MainActivity/bin/dexedLibs/afinal_0.5.1_bin-bcdf7a8cb36c2d22db2af93ccc728359.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/dexedLibs/afinal_0.5.1_bin-bcdf7a8cb36c2d22db2af93ccc728359.jar
--------------------------------------------------------------------------------
/MainActivity/bin/dexedLibs/android-support-v4-2df5435911296a354a1b7c19d9ff9857.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/dexedLibs/android-support-v4-2df5435911296a354a1b7c19d9ff9857.jar
--------------------------------------------------------------------------------
/MainActivity/bin/dexedLibs/lib_download-821b26c3c1e1d4f4ea62161b71c042e5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/dexedLibs/lib_download-821b26c3c1e1d4f4ea62161b71c042e5.jar
--------------------------------------------------------------------------------
/MainActivity/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/MainActivity/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/bin/resources.ap_
--------------------------------------------------------------------------------
/MainActivity/gen/com/xckevin/androiddownloadcomponent/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 | package com.xckevin.androiddownloadcomponent;
8 |
9 | public final class R {
10 | public static final class drawable {
11 | public static final int ic_launcher = 0x7f020000;
12 | }
13 | public static final class string {
14 | public static final int app_name = 0x7f050000;
15 | }
16 | public static final class style {
17 | public static final int AppBaseTheme = 0x7f060000;
18 | public static final int AppTheme = 0x7f060001;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/MainActivity/gen/com/xckevin/download/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.xckevin.download;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/MainActivity/gen/com/xckevin/download/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.xckevin.download;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class dimen {
14 | /** Default screen margins, per the Android Design guidelines.
15 |
16 | Customize dimensions originally defined in res/values/dimens.xml (such as
17 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
18 |
19 | */
20 | public static final int activity_horizontal_margin=0x7f070000;
21 | public static final int activity_vertical_margin=0x7f070001;
22 | }
23 | public static final class drawable {
24 | public static final int ic_launcher=0x7f020000;
25 | }
26 | public static final class id {
27 | public static final int action_settings=0x7f09000e;
28 | public static final int delete=0x7f090005;
29 | public static final int download_add_Btn=0x7f090000;
30 | public static final int download_list_LV=0x7f090001;
31 | public static final int item_action_Layout=0x7f090007;
32 | public static final int item_info_Layout=0x7f09000a;
33 | public static final int item_name=0x7f09000b;
34 | public static final int item_progress=0x7f09000c;
35 | public static final int item_speed=0x7f09000d;
36 | public static final int item_start=0x7f090008;
37 | public static final int item_stop=0x7f090009;
38 | public static final int pause=0x7f090004;
39 | public static final int progressbar=0x7f090002;
40 | public static final int start=0x7f090003;
41 | public static final int state=0x7f090006;
42 | }
43 | public static final class layout {
44 | public static final int activity_list=0x7f030000;
45 | public static final int activity_main=0x7f030001;
46 | public static final int item_download=0x7f030002;
47 | }
48 | public static final class menu {
49 | public static final int main=0x7f080000;
50 | }
51 | public static final class raw {
52 | public static final int gamehelper=0x7f040000;
53 | }
54 | public static final class string {
55 | public static final int action_settings=0x7f050001;
56 | public static final int app_name=0x7f050000;
57 | public static final int hello_world=0x7f050002;
58 | }
59 | public static final class style {
60 | /**
61 | Base application theme, dependent on API level. This theme is replaced
62 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
63 |
64 |
65 | Theme customizations available in newer API levels can go in
66 | res/values-vXX/styles.xml, while customizations related to
67 | backward-compatibility can go here.
68 |
69 |
70 | Base application theme for API 11+. This theme completely replaces
71 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
72 |
73 | API 11 theme customizations can go here.
74 |
75 | Base application theme for API 14+. This theme completely replaces
76 | AppBaseTheme from BOTH res/values/styles.xml and
77 | res/values-v11/styles.xml on API 14+ devices.
78 |
79 | API 14 theme customizations can go here.
80 |
81 | Base application theme, dependent on API level. This theme is replaced
82 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
83 |
84 |
85 | Theme customizations available in newer API levels can go in
86 | res/values-vXX/styles.xml, while customizations related to
87 | backward-compatibility can go here.
88 |
89 |
90 | Base application theme for API 11+. This theme completely replaces
91 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
92 |
93 | API 11 theme customizations can go here.
94 |
95 | Base application theme for API 14+. This theme completely replaces
96 | AppBaseTheme from BOTH res/values/styles.xml and
97 | res/values-v11/styles.xml on API 14+ devices.
98 |
99 | API 14 theme customizations can go here.
100 | */
101 | public static final int AppBaseTheme=0x7f060000;
102 | /** Application theme.
103 | All customizations that are NOT specific to a particular API-level can go here.
104 | Application theme.
105 | All customizations that are NOT specific to a particular API-level can go here.
106 | */
107 | public static final int AppTheme=0x7f060001;
108 | public static final int btn_download_action=0x7f060002;
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/MainActivity/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/ic_launcher-web.png
--------------------------------------------------------------------------------
/MainActivity/libs/afinal_0.5.1_bin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/libs/afinal_0.5.1_bin.jar
--------------------------------------------------------------------------------
/MainActivity/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/MainActivity/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/MainActivity/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-20
15 | android.library.reference.1=../lib_download
16 |
--------------------------------------------------------------------------------
/MainActivity/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MainActivity/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/MainActivity/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
23 |
28 |
33 |
34 |
40 |
41 |
--------------------------------------------------------------------------------
/MainActivity/res/layout/item_download.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
27 |
28 |
29 |
30 |
31 |
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/MainActivity/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/MainActivity/res/raw/gamehelper.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/res/raw/gamehelper.db
--------------------------------------------------------------------------------
/MainActivity/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MainActivity/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MainActivity/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/MainActivity/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MainActivity/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MainActivity/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AndroidDownloadComponentSample
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MainActivity/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
25 |
26 |
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/AppContext.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.io.File;
4 |
5 | import com.xckevin.download.ui.IDCreate;
6 | import android.app.Application;
7 | import android.os.Environment;
8 |
9 | public class AppContext extends Application {
10 | public static DownloadManager downloadMgr;
11 | @Override
12 | public void onCreate() {
13 | super.onCreate();
14 | downloadMgr = DownloadManager.getInstance();
15 |
16 | // use default configuration
17 | //downloadMgr.init();
18 |
19 | // custom configuration
20 | DownloadConfig.Builder builder = new DownloadConfig.Builder(this);
21 | String downloadPath = null;
22 | if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
23 | downloadPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Houny_Chang"+File.separator+"Download";
24 | } else {
25 | downloadPath = Environment.getDataDirectory().getAbsolutePath() + File.separator + "data" + File.separator + getPackageName()+ File.separator + "Houny_Chang" + File.separator + "Download";
26 | }
27 | File downloadFile = new File(downloadPath);
28 | if(!downloadFile.isDirectory() && !downloadFile.mkdirs()) {
29 | throw new IllegalAccessError(" cannot create download folder");
30 | }
31 | builder.setDownloadSavePath(downloadPath);
32 | builder.setMaxDownloadThread(3);
33 | builder.setDownloadTaskIDCreator(new IDCreate());
34 |
35 | downloadMgr.init(builder.build());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/model/GameInfoModel.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.model;
2 |
3 | import android.graphics.drawable.Drawable;
4 |
5 | /**
6 | *
7 | * @author Houny Chang
8 | *
9 | */
10 | public class GameInfoModel {
11 | private String id;
12 | private String name;
13 | private Drawable ico;
14 | private String packageName;
15 | private String url;
16 |
17 | public String getUrl() {
18 | return url;
19 | }
20 |
21 | public void setUrl(String url) {
22 | this.url = url;
23 | }
24 |
25 | public String getId() {
26 | return id;
27 | }
28 |
29 | public void setId(String id) {
30 | this.id = id;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | public Drawable getIco() {
42 | return ico;
43 | }
44 |
45 | public void setIco(Drawable ico) {
46 | this.ico = ico;
47 | }
48 |
49 |
50 |
51 | public String getPackageName() {
52 | return packageName;
53 | }
54 |
55 | public void setPackageName(String packageName) {
56 | this.packageName = packageName;
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | return "GameInfoModel [name=" + name + ", packageName=" + packageName
62 | + "]";
63 | }
64 |
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/ui/IDCreate.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.ui;
2 |
3 | import com.xckevin.download.DownloadTask;
4 | import com.xckevin.download.DownloadTaskIDCreator;
5 |
6 | public class IDCreate implements DownloadTaskIDCreator {
7 |
8 | @Override
9 | public String createId(DownloadTask task) {
10 | // TODO Auto-generated method stub
11 | return task.getId();
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/ui/ListActivity.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/src/com/xckevin/download/ui/ListActivity.java
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/ui/ListAdapter.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/MainActivity/src/com/xckevin/download/ui/ListAdapter.java
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.ui;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.view.View.OnClickListener;
8 | import android.widget.ProgressBar;
9 | import android.widget.TextView;
10 |
11 | import com.xckevin.download.DownloadListener;
12 | import com.xckevin.download.DownloadManager;
13 | import com.xckevin.download.DownloadTask;
14 | import com.xckevin.download.R;
15 | import com.xckevin.download.util.SourceProvicer;
16 |
17 | public class MainActivity extends Activity implements OnClickListener,
18 | DownloadListener {
19 |
20 | private TextView state;
21 | private ProgressBar progressBar;
22 | private DownloadTask downloadTask;
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | init();
29 | }
30 |
31 | private void init() {
32 | state = (TextView) findViewById(R.id.state);
33 | progressBar = (ProgressBar) findViewById(R.id.progressbar);
34 | findViewById(R.id.start).setOnClickListener(this);
35 | findViewById(R.id.pause).setOnClickListener(this);
36 | findViewById(R.id.delete).setOnClickListener(this);
37 | }
38 |
39 | @Override
40 | public boolean onCreateOptionsMenu(Menu menu) {
41 | // Inflate the menu; this adds items to the action bar if it is present.
42 | getMenuInflater().inflate(R.menu.main, menu);
43 | return true;
44 | }
45 |
46 | @Override
47 | public void onDownloadStart(DownloadTask task) {
48 | state.setText(task.getName() + "==> start download"+" Status: "+task.getStatus());
49 | downloadTask = task;
50 |
51 | }
52 |
53 | @Override
54 | public void onDownloadUpdated(DownloadTask task, long finishedSize,
55 | long trafficSpeed) {
56 | // TODO Auto-generated method stub
57 | state.setText(task.getName() + "==> downloading..., speed: "
58 | + trafficSpeed+" Status: "+task.getStatus());
59 | long total = task.getDownloadTotalSize();
60 | if (total != 0) {
61 | progressBar
62 | .setProgress((int) (task.getDownloadFinishedSize() * 100 / total));
63 | }
64 | }
65 |
66 | @Override
67 | public void onDownloadPaused(DownloadTask task) {
68 | state.setText(task.getName() + "==> pause download"+" Status: "+task.getStatus());
69 | }
70 |
71 | @Override
72 | public void onDownloadResumed(DownloadTask task) {
73 | state.setText(task.getName() + "==> resume download"+" Status: "+task.getStatus());
74 |
75 | }
76 |
77 | @Override
78 | public void onDownloadSuccessed(DownloadTask task) {
79 | state.setText(task.getName() + "==> download successed"+" Status: "+task.getStatus());
80 |
81 | }
82 |
83 | @Override
84 | public void onDownloadCanceled(DownloadTask task) {
85 | state.setText(task.getName() + "==> download canceled"+" Status: "+task.getStatus());
86 | }
87 |
88 | @Override
89 | public void onDownloadFailed(DownloadTask task) {
90 | state.setText(task.getName() + "==> download failed"+" Status: "+task.getStatus());
91 | }
92 |
93 | @Override
94 | public void onDownloadRetry(DownloadTask task) {
95 | state.setText(task.getName() + "==> retry download "+" Status: "+task.getStatus());
96 | }
97 |
98 | @Override
99 | public void onClick(View v) {
100 |
101 | switch (v.getId()) {
102 | case R.id.start:
103 | // if(downloadTask!=null&&downloadTask.getStatus()==DownloadTask.STATUS_PAUSED){
104 | // DownloadManager.getInstance().resumeDownload(downloadTask);
105 | // }else{
106 | // DownloadManager.getInstance().addDownloadTask(
107 | // SourceProvicer.getSimpleTask(), this);
108 | // }
109 |
110 | break;
111 | case R.id.pause:
112 | // if(downloadTask!=null){
113 | // DownloadManager.getInstance().pauseDownload(
114 | // downloadTask);
115 | // }
116 |
117 | break;
118 | case R.id.delete:
119 | // if(downloadTask!=null){
120 | // DownloadManager.getInstance().cancelDownload(
121 | // downloadTask);
122 | // }
123 | break;
124 | default:
125 |
126 | break;
127 | }
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/MainActivity/src/com/xckevin/download/util/SourceProvicer.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.util;
2 |
3 | import com.xckevin.download.DownloadTask;
4 |
5 | public class SourceProvicer {
6 |
7 | public static final String APK_URL = "http://dldir1.qq.com/qqfile/qq/QQ6.1/11879/QQ6.1.exe";
8 |
9 | public static DownloadTask getSimpleTask() {
10 | DownloadTask task = new DownloadTask();
11 | task.setName("QQ");
12 | task.setUrl(APK_URL);
13 |
14 | return task;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Downloader
2 | ==========
3 |
4 | Android downloader Lib, you can use it downloading file from network. support pause, resume and cancel . NOTE. It ONLY support http or https.
5 |
6 | ###Thanks to
7 | [xckevin](https://github.com/xckevin)
8 |
9 | This Project and Lib are base on xckevin's [Android-Download-Component](https://github.com/xckevin/Android-Download-Component).
10 |
11 | 中文说明
12 | =======
13 |
14 | 这是一个Android的下载lib,可以用它来从网上下载东西,支持暂停、继续和取消。注意,这个lib只支持Http和Https。
15 |
16 | ###致谢
17 | [xckevin](https://github.com/xckevin)
18 |
19 | 这个项目是在[xckevin](https://github.com/xckevin)的[Android-Download-Component](https://github.com/xckevin/Android-Download-Component)的基础上修改而来的。
20 | 我只是改了该lib里的某些地方让它更方便用,并修改了一个Activity。
21 |
22 | 如果你想要实现豌豆荚那样的,一处点击添加任务,多处监听下载进度的效果的话,可以使用这个。
23 |
--------------------------------------------------------------------------------
/lib_download/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/lib_download/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | lib_download
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/lib_download/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/lib_download/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lib_download/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lib_download/bin/R.txt:
--------------------------------------------------------------------------------
1 | int drawable ic_launcher 0x7f020000
2 | int string app_name 0x7f030000
3 | int style AppBaseTheme 0x7f040000
4 | int style AppTheme 0x7f040001
5 |
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/BuildConfig.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$attr.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$drawable.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$string.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R$style.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/androiddownloadcomponent/R.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadConfig$Builder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadConfig$Builder.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadConfig.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadListener.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$1.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$10.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$10.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$11.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$11.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$2.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$3.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$4.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$5.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$6.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$6.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$7.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$7.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$8.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$8.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager$9.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager$9.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadManager.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadObserver.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadObserver.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadOperator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadOperator.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadProvider.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadProvider.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadTask.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadTask.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/DownloadTaskIDCreator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/DownloadTaskIDCreator.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/Env.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/Env.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/MD5DownloadTaskIDCreator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/MD5DownloadTaskIDCreator.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/SqlLiteDownloadProvider.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/SqlLiteDownloadProvider.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/util/FileUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/util/FileUtil.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/util/MD5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/util/MD5.class
--------------------------------------------------------------------------------
/lib_download/bin/classes/com/xckevin/download/util/StringUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/classes/com/xckevin/download/util/StringUtil.class
--------------------------------------------------------------------------------
/lib_download/bin/lib_download.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/lib_download.jar
--------------------------------------------------------------------------------
/lib_download/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/gen/com/xckevin/androiddownloadcomponent/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.xckevin.androiddownloadcomponent;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/lib_download/gen/com/xckevin/androiddownloadcomponent/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.xckevin.androiddownloadcomponent;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static int ic_launcher=0x7f020000;
15 | }
16 | public static final class string {
17 | public static int app_name=0x7f030000;
18 | }
19 | public static final class style {
20 | /**
21 | Base application theme, dependent on API level. This theme is replaced
22 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
23 |
24 |
25 | Theme customizations available in newer API levels can go in
26 | res/values-vXX/styles.xml, while customizations related to
27 | backward-compatibility can go here.
28 |
29 |
30 | Base application theme for API 11+. This theme completely replaces
31 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
32 |
33 | API 11 theme customizations can go here.
34 |
35 | Base application theme for API 14+. This theme completely replaces
36 | AppBaseTheme from BOTH res/values/styles.xml and
37 | res/values-v11/styles.xml on API 14+ devices.
38 |
39 | API 14 theme customizations can go here.
40 | */
41 | public static int AppBaseTheme=0x7f040000;
42 | /** Application theme.
43 | All customizations that are NOT specific to a particular API-level can go here.
44 | */
45 | public static int AppTheme=0x7f040001;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/lib_download/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/ic_launcher-web.png
--------------------------------------------------------------------------------
/lib_download/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/lib_download/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-20
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/lib_download/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Houny/Downloader/f2ca96fe93e0061bb44ec7aefd7e85e8005b6b02/lib_download/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_download/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lib_download/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lib_download/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | AndroidDownloadComponent
4 |
5 |
6 |
--------------------------------------------------------------------------------
/lib_download/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadConfig.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.io.File;
4 |
5 |
6 | import android.content.Context;
7 |
8 | public class DownloadConfig {
9 |
10 | private String downloadSavePath;
11 |
12 | private int maxDownloadThread;
13 |
14 | private int retryTime;
15 |
16 | private DownloadProvider provider;
17 |
18 | private DownloadTaskIDCreator creator;
19 |
20 | private DownloadConfig() {
21 | downloadSavePath = Env.ROOT_DIR + File.separator + "download";
22 | maxDownloadThread = 2;
23 | retryTime = 2;
24 | creator = new MD5DownloadTaskIDCreator();
25 | }
26 |
27 | public String getDownloadSavePath() {
28 | return downloadSavePath;
29 | }
30 |
31 | public int getMaxDownloadThread() {
32 | return maxDownloadThread;
33 | }
34 |
35 | public int getRetryTime() {
36 | return retryTime;
37 | }
38 |
39 | public DownloadProvider getProvider(DownloadManager manager) {
40 | if(provider == null) {
41 | provider = SqlLiteDownloadProvider.getInstance(manager);
42 | }
43 | return provider;
44 | }
45 |
46 | public DownloadTaskIDCreator getCreator() {
47 | return creator;
48 | }
49 |
50 | public static DownloadConfig getDefaultDownloadConfig(DownloadManager manager) {
51 | DownloadConfig config = new DownloadConfig();
52 | config.provider = SqlLiteDownloadProvider.getInstance(manager);
53 | return config;
54 | }
55 |
56 | public static class Builder {
57 |
58 | private DownloadConfig config;
59 |
60 | public Builder(Context context) {
61 | config = new DownloadConfig();
62 | }
63 |
64 | public DownloadConfig build() {
65 | return config;
66 | }
67 |
68 | public Builder setDownloadSavePath(String downloadSavePath) {
69 | config.downloadSavePath = downloadSavePath;
70 | return this;
71 | }
72 |
73 | public Builder setMaxDownloadThread(int maxDownloadThread) {
74 | config.maxDownloadThread = maxDownloadThread;
75 | return this;
76 | }
77 |
78 | public Builder setRetryTime(int retryTime) {
79 | config.retryTime = retryTime;
80 | return this;
81 | }
82 |
83 | public Builder setDownloadProvider(DownloadProvider provider) {
84 | config.provider = provider;
85 | return this;
86 | }
87 |
88 | public Builder setDownloadTaskIDCreator(DownloadTaskIDCreator creator) {
89 | config.creator = creator;
90 | return this;
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadListener.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | public interface DownloadListener {
4 |
5 | public void onDownloadStart(DownloadTask task);
6 |
7 | public void onDownloadUpdated(DownloadTask task, long finishedSize, long trafficSpeed);
8 |
9 | public void onDownloadPaused(DownloadTask task);
10 |
11 | public void onDownloadResumed(DownloadTask task);
12 |
13 | public void onDownloadSuccessed(DownloadTask task);
14 |
15 | public void onDownloadCanceled(DownloadTask task);
16 |
17 | public void onDownloadFailed(DownloadTask task);
18 |
19 | public void onDownloadRetry(DownloadTask task);
20 | }
21 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadManager.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.io.File;
4 | import java.util.HashMap;
5 | import java.util.Iterator;
6 | import java.util.LinkedList;
7 | import java.util.List;
8 | import java.util.concurrent.ExecutorService;
9 | import java.util.concurrent.Executors;
10 |
11 | import android.os.Handler;
12 | import android.text.TextUtils;
13 | import android.util.Log;
14 |
15 | public class DownloadManager {
16 |
17 | private static final String TAG = "DownloadManager";
18 |
19 | // static {
20 | // if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
21 | // DOWNLOAD_DIR = Env.ROOT_DIR + File.separator + "download";
22 | // } else {
23 | // DOWNLOAD_DIR = Environment.getDataDirectory() + File.separator + "com.huaqian" + File.separator + "databases";
24 | // }
25 | // }
26 |
27 | private static DownloadManager instance;
28 |
29 | private DownloadConfig config;
30 |
31 | private HashMap taskOperators = new HashMap();
32 |
33 | private HashMap taskListeners = new HashMap();
34 |
35 | private LinkedList taskObservers = new LinkedList();
36 |
37 | private DownloadProvider provider;
38 |
39 | private static Handler handler = new Handler();
40 |
41 | private ExecutorService pool;
42 |
43 | private DownloadManager() {
44 |
45 | }
46 |
47 | public static synchronized DownloadManager getInstance() {
48 | if(instance == null) {
49 | instance = new DownloadManager();
50 | }
51 |
52 | return instance;
53 | }
54 |
55 | public void init() {
56 | config = DownloadConfig.getDefaultDownloadConfig(this);
57 | provider = config.getProvider(this);
58 | pool = Executors.newFixedThreadPool(config.getMaxDownloadThread());
59 | }
60 |
61 | public void init(DownloadConfig config) {
62 | if(config == null) {
63 | init();
64 | return ;
65 | }
66 | this.config = config;
67 | provider = config.getProvider(this);
68 | pool = Executors.newFixedThreadPool(config.getMaxDownloadThread());
69 | }
70 |
71 | public DownloadConfig getConfig() {
72 | return config;
73 | }
74 |
75 | public void setConfig(DownloadConfig config) {
76 | this.config = config;
77 | }
78 |
79 | public void addDownloadTask(DownloadTask task) {
80 | addDownloadTask(task, null);
81 | }
82 |
83 | public void addDownloadTask(DownloadTask task, DownloadListener listener) {
84 | if(TextUtils.isEmpty(task.getUrl())) {
85 | throw new IllegalArgumentException("task's url cannot be empty");
86 | }
87 | if(taskOperators.containsKey(task)) {
88 | return ;
89 | }
90 | DownloadOperator operator = new DownloadOperator(this, task);
91 | taskOperators.put(task, operator);
92 | if(listener != null) {
93 | taskListeners.put(task, listener);
94 | }
95 |
96 | task.setStatus(DownloadTask.STATUS_PENDDING);
97 | DownloadTask historyTask = provider.findDownloadTaskById(task.getId());
98 | if(historyTask == null) {
99 | task.setId(config.getCreator().createId(task));
100 | provider.saveDownloadTask(task);
101 | } else {
102 | provider.updateDownloadTask(task);
103 | }
104 |
105 | // new Thread(operator).start();
106 |
107 | pool.submit(operator);
108 | }
109 |
110 | public DownloadListener getDownloadListenerForTask(DownloadTask task) {
111 | if(task == null) {
112 | return null;
113 | }
114 |
115 | return taskListeners.get(task);
116 | }
117 |
118 | public void updateDownloadTaskListener(DownloadTask task, DownloadListener listener) {
119 | Log.v(TAG, "try to updateDownloadTaskListener");
120 | if(task == null || !taskOperators.containsKey(task)) {
121 | return ;
122 | }
123 |
124 | Log.v(TAG, "updateDownloadTaskListener");
125 | taskListeners.put(task, listener);
126 | }
127 |
128 | public void removeDownloadTaskListener(DownloadTask task) {
129 | Log.v(TAG, "try to removeDownloadTaskListener");
130 | if(task == null || !taskListeners.containsKey(task)) {
131 | return ;
132 | }
133 |
134 | Log.v(TAG, "removeDownloadTaskListener");
135 | taskListeners.remove(task);
136 | }
137 |
138 | public void pauseDownload(DownloadTask task,DownloadListener listener) {
139 | Log.v(TAG, "pauseDownload: " + task.getName());
140 | DownloadOperator operator = taskOperators.get(task);
141 | if(operator != null) {
142 | operator.pauseDownload();
143 | }else{
144 | addDownloadTask(task, listener);
145 | pauseDownload(task, listener);
146 | }
147 | }
148 |
149 | public void resumeDownload(DownloadTask task,DownloadListener listener) {
150 | Log.v(TAG, "resumeDownload: "+ task.getName());
151 | DownloadOperator operator = taskOperators.get(task);
152 | if(operator != null) {
153 | operator.resumeDownload();
154 | }else{
155 | addDownloadTask(task, listener);
156 | }
157 | }
158 |
159 | public void cancelDownload(final DownloadTask task,final DownloadListener listener) {
160 | Log.v(TAG, "cancelDownload: "+ task.getName());
161 | DownloadOperator operator = taskOperators.get(task);
162 | if(operator != null) {
163 | operator.cancelDownload();
164 | handler.post(new Runnable() {
165 |
166 | @Override
167 | public void run() {
168 | try {
169 | File file = new File(task.getDownloadSavePath());
170 | if(file.isFile()){
171 | file.delete();
172 | }
173 | } catch (Exception e) {
174 | }
175 | }
176 | });
177 | } else {
178 | // addDownloadTask(task, listener);
179 | // cancelDownload(task, listener);
180 | task.setStatus(DownloadTask.STATUS_CANCELED);
181 | // provider.deleteDownloadTask(task);
182 |
183 | handler.post(new Runnable() {
184 |
185 | @Override
186 | public void run() {
187 | provider.deleteDownloadTask(task);
188 | if(listener != null) {
189 | listener.onDownloadCanceled(task);
190 | }
191 | try {
192 | File file = new File(task.getDownloadSavePath());
193 | if(file.isFile()){
194 | file.delete();
195 | }
196 | } catch (Exception e) {
197 | }
198 | }
199 | });
200 | }
201 | }
202 |
203 | public DownloadTask findDownloadTaskById(String id) {
204 | Iterator iterator = taskOperators.keySet().iterator();
205 | while(iterator.hasNext()) {
206 | DownloadTask task = iterator.next();
207 | if(task.getId().equals(id)) {
208 | Log.v(TAG, "findDownloadTaskByAdId from map");
209 | return task;
210 | }
211 | }
212 |
213 | Log.v(TAG, "findDownloadTaskByAdId from provider");
214 | return provider.findDownloadTaskById(id);
215 | }
216 |
217 | public List getAllDownloadTask() {
218 | return provider.getAllDownloadTask();
219 | }
220 |
221 | public void registerDownloadObserver(DownloadObserver observer) {
222 | if(observer == null) {
223 | return ;
224 | }
225 | taskObservers.add(observer);
226 | }
227 |
228 | public void unregisterDownloadObserver(DownloadObserver observer) {
229 | if(observer == null) {
230 | return ;
231 | }
232 | taskObservers.remove(observer);
233 | }
234 |
235 | public void close() {
236 | pool.shutdownNow();
237 | }
238 |
239 | public void notifyDownloadTaskStatusChanged(final DownloadTask task) {
240 | handler.post(new Runnable() {
241 |
242 | public void run() {
243 | for(DownloadObserver observer : taskObservers) {
244 | observer.onDownloadTaskStatusChanged(task);
245 | }
246 | }
247 | });
248 | }
249 |
250 | void updateDownloadTask(final DownloadTask task, final long finishedSize, final long trafficSpeed) {
251 | task.setStatus(DownloadTask.STATUS_RUNNING);
252 | final DownloadListener listener = taskListeners.get(task);
253 | handler.post(new Runnable() {
254 |
255 | @Override
256 | public void run() {
257 | provider.updateDownloadTask(task);
258 | if(listener != null) {
259 | listener.onDownloadUpdated(task, finishedSize, trafficSpeed);
260 | }
261 | }
262 |
263 | });
264 | }
265 |
266 | void onDownloadStarted(final DownloadTask task) {
267 | task.setStatus(DownloadTask.STATUS_RUNNING);
268 | final DownloadListener listener = taskListeners.get(task);
269 | handler.post(new Runnable() {
270 |
271 | @Override
272 | public void run() {
273 | provider.updateDownloadTask(task);
274 | if(listener != null) {
275 | listener.onDownloadStart(task);
276 | }
277 | }
278 | });
279 | }
280 |
281 |
282 | void onDownloadPaused(final DownloadTask task) {
283 | task.setStatus(DownloadTask.STATUS_PAUSED);
284 | final DownloadListener listener = taskListeners.get(task);
285 | handler.post(new Runnable() {
286 |
287 | @Override
288 | public void run() {
289 | provider.updateDownloadTask(task);
290 | if(listener != null) {
291 | listener.onDownloadPaused(task);
292 | }
293 | }
294 | });
295 | }
296 |
297 | void onDownloadResumed(final DownloadTask task) {
298 | task.setStatus(DownloadTask.STATUS_RUNNING);
299 | final DownloadListener listener = taskListeners.get(task);
300 | handler.post(new Runnable() {
301 |
302 | @Override
303 | public void run() {
304 | provider.updateDownloadTask(task);
305 | if(listener != null) {
306 | listener.onDownloadResumed(task);
307 | }
308 | }
309 | });
310 | }
311 |
312 | void onDownloadCanceled(final DownloadTask task) {
313 | task.setStatus(DownloadTask.STATUS_CANCELED);
314 | final DownloadListener listener = taskListeners.get(task);
315 | removeTask(task);
316 | handler.post(new Runnable() {
317 |
318 | @Override
319 | public void run() {
320 | provider.deleteDownloadTask(task);
321 | if(listener != null) {
322 | listener.onDownloadCanceled(task);
323 | }
324 |
325 | }
326 | });
327 | }
328 |
329 | void onDownloadSuccessed(final DownloadTask task) {
330 | task.setStatus(DownloadTask.STATUS_FINISHED);
331 | final DownloadListener listener = taskListeners.get(task);
332 | removeTask(task);
333 | handler.post(new Runnable() {
334 |
335 | @Override
336 | public void run() {
337 | provider.updateDownloadTask(task);
338 | if(listener != null) {
339 | listener.onDownloadSuccessed(task);
340 | }
341 | }
342 |
343 | });
344 | }
345 |
346 | void onDownloadFailed(final DownloadTask task) {
347 | task.setStatus(DownloadTask.STATUS_ERROR);
348 | final DownloadListener listener = taskListeners.get(task);
349 | removeTask(task);
350 | handler.post(new Runnable() {
351 |
352 | @Override
353 | public void run() {
354 | provider.updateDownloadTask(task);
355 | if(listener != null) {
356 | listener.onDownloadFailed(task);
357 | }
358 | }
359 | });
360 | }
361 |
362 | void onDownloadRetry(final DownloadTask task) {
363 | final DownloadListener listener = taskListeners.get(task);
364 | handler.post(new Runnable() {
365 |
366 | @Override
367 | public void run() {
368 | if(listener != null) {
369 | listener.onDownloadRetry(task);
370 | }
371 | }
372 | });
373 | }
374 |
375 | private void removeTask(DownloadTask task) {
376 | taskOperators.remove(task);
377 | taskListeners.remove(task);
378 | }
379 |
380 | }
381 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadObserver.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | public interface DownloadObserver {
4 |
5 | public void onDownloadTaskStatusChanged(DownloadTask task);
6 | }
7 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadOperator.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.RandomAccessFile;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 |
10 | import android.text.TextUtils;
11 |
12 | import com.xckevin.download.util.FileUtil;
13 |
14 | public class DownloadOperator implements Runnable {
15 |
16 | // 100 kb
17 | private static final long REFRESH_INTEVAL_SIZE = 100 * 1024;
18 |
19 | private DownloadManager manager;
20 |
21 | private DownloadTask task;
22 |
23 | // already try times
24 | private int tryTimes;
25 |
26 | private volatile boolean pauseFlag;
27 | private volatile boolean stopFlag;
28 |
29 | private String filePath;
30 |
31 | DownloadOperator(DownloadManager manager, DownloadTask task) {
32 | this.manager = manager;
33 | this.task = task;
34 | this.tryTimes = 0;
35 | }
36 |
37 | void pauseDownload() {
38 | if(pauseFlag) {
39 | return ;
40 | }
41 | pauseFlag = true;
42 | }
43 |
44 | void resumeDownload() {
45 | if(!pauseFlag) {
46 | return ;
47 | }
48 | pauseFlag = false;
49 | synchronized (this) {
50 | notify();
51 | }
52 | }
53 |
54 | void cancelDownload() {
55 | stopFlag = true;
56 | resumeDownload();
57 | }
58 |
59 | @Override
60 | public void run() {
61 | do {
62 | RandomAccessFile raf = null;
63 | HttpURLConnection conn = null;
64 | InputStream is = null;
65 | try {
66 | raf = buildDownloadFile();
67 | conn = initConnection();
68 |
69 | conn.connect();
70 |
71 | task.setDownloadSavePath(filePath);
72 | if(task.getDownloadTotalSize() == 0) {
73 | task.setDownloadTotalSize(conn.getContentLength());
74 | }
75 | if(TextUtils.isEmpty(task.getMimeType())) {
76 | task.setMimeType(conn.getContentType());
77 | }
78 | task.setStatus(DownloadTask.STATUS_RUNNING);
79 | manager.onDownloadStarted(task);
80 |
81 |
82 | is = conn.getInputStream();
83 |
84 | byte[] buffer = new byte[8192];
85 | int count = 0;
86 | long total = task.getDownloadFinishedSize();
87 | long prevTime = System.currentTimeMillis();
88 | long achieveSize = total;
89 | while(!stopFlag && (count = is.read(buffer)) != -1) {
90 | while(pauseFlag) {
91 | manager.onDownloadPaused(task);
92 | synchronized (this) {
93 | try {
94 | wait();
95 | } catch (InterruptedException e) {
96 | e.printStackTrace();
97 | manager.onDownloadResumed(task);
98 | }
99 | }
100 | }
101 |
102 | raf.write(buffer, 0, count);
103 | total += count;
104 |
105 | long tempSize = total - achieveSize;
106 | if(tempSize > REFRESH_INTEVAL_SIZE) {
107 | long tempTime = System.currentTimeMillis() - prevTime;
108 | long speed = tempSize * 1000 / tempTime;
109 | achieveSize = total;
110 | prevTime = System.currentTimeMillis();
111 | task.setDownloadFinishedSize(total);
112 | task.setDownloadSpeed(speed);
113 | manager.updateDownloadTask(task, total, speed);
114 | }
115 | }
116 | task.setDownloadFinishedSize(total);
117 |
118 | if(stopFlag) {
119 | manager.onDownloadCanceled(task);
120 | } else {
121 | manager.onDownloadSuccessed(task);
122 | }
123 | break;
124 | } catch (IOException e) {
125 | e.printStackTrace();
126 | if(tryTimes > manager.getConfig().getRetryTime()) {
127 | manager.onDownloadFailed(task);
128 | break;
129 | } else {
130 | tryTimes ++;
131 | continue;
132 | }
133 | }
134 | } while(true);
135 | }
136 |
137 | private RandomAccessFile buildDownloadFile() throws IOException {
138 | String fileName = FileUtil.getFileNameByUrl(task.getUrl());
139 | File file = new File(manager.getConfig().getDownloadSavePath(), fileName);
140 | if(!file.getParentFile().isDirectory() && !file.getParentFile().mkdirs()) {
141 | throw new IOException("cannot create download folder");
142 | }
143 | if(file.exists()) {
144 |
145 | }
146 | filePath = file.getAbsolutePath();
147 | RandomAccessFile raf = new RandomAccessFile(file, "rw");
148 | if(task.getDownloadFinishedSize() != 0) {
149 | raf.seek(task.getDownloadFinishedSize());
150 | }
151 |
152 | return raf;
153 | }
154 |
155 | private HttpURLConnection initConnection() throws IOException {
156 | HttpURLConnection conn = (HttpURLConnection) new URL(task.getUrl()).openConnection();
157 | conn.setConnectTimeout(30000);
158 | conn.setReadTimeout(30000);
159 | conn.setUseCaches(true);
160 | if(task.getDownloadFinishedSize() != 0) {
161 | conn.setRequestProperty("Range", "bytes=" + task.getDownloadFinishedSize() + "-");
162 | }
163 |
164 | return conn;
165 | }
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadProvider.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.util.List;
4 |
5 | public interface DownloadProvider {
6 |
7 | public void saveDownloadTask(DownloadTask task);
8 |
9 | public void updateDownloadTask(DownloadTask task);
10 |
11 | public void deleteDownloadTask(DownloadTask task);
12 |
13 | public DownloadTask findDownloadTaskById(String id);
14 |
15 | public DownloadTask findDownloadTask(String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy);
16 |
17 | public List getAllDownloadTask();
18 |
19 | public void notifyDownloadStatusChanged(DownloadTask task);
20 | }
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadTask.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | public class DownloadTask {
4 |
5 | public static final String ID = "_id";
6 | public static final String URL = "_url";
7 | public static final String MIMETYPE = "_mimetype";
8 | public static final String SAVEPATH = "_savepath";
9 | public static final String FINISHEDSIZE = "_finishedsize";
10 | public static final String TOTALSIZE = "_totalsize";
11 | public static final String NAME = "_name";
12 | public static final String STATUS = "_status";
13 |
14 | public static final int STATUS_PENDDING = 1 << 0;//1
15 |
16 | public static final int STATUS_RUNNING = 1 << 1;//2
17 |
18 | public static final int STATUS_PAUSED = 1 << 2;//4
19 |
20 | public static final int STATUS_CANCELED = 1 << 3;//8
21 |
22 | public static final int STATUS_FINISHED = 1 << 4;//16
23 |
24 | public static final int STATUS_ERROR = 1 << 5;//32
25 |
26 | private String id;
27 |
28 | private String name;
29 |
30 | private String url;
31 |
32 | private String mimeType;
33 |
34 | private String downloadSavePath;
35 |
36 | private long downloadFinishedSize;
37 |
38 | private long downloadTotalSize;
39 |
40 | // @Transparent no need to persist
41 | private long downloadSpeed;
42 |
43 | private int status;
44 |
45 | public DownloadTask() {
46 | downloadFinishedSize = 0;
47 | downloadTotalSize = 0;
48 | status = STATUS_PENDDING;
49 | }
50 |
51 | @Override
52 | public boolean equals(Object o) {
53 | if(o == null) {
54 | return false;
55 | }
56 | if(!(o instanceof DownloadTask)) {
57 | return false;
58 | }
59 | DownloadTask task = (DownloadTask) o;
60 | if(this.name == null || this.downloadSavePath == null) {
61 | return this.url.equals(task.url);
62 | }
63 | return this.name.equals(task.name) && this.url.equals(task.url) && this.downloadSavePath.equals(task.downloadSavePath);
64 | }
65 |
66 | @Override
67 | public int hashCode() {
68 | int code = name == null ? 0 : name.hashCode();
69 | code += url.hashCode();
70 | return code;
71 | }
72 |
73 | public String getId() {
74 | return id;
75 | }
76 |
77 | public void setId(String id) {
78 | this.id = id;
79 | }
80 |
81 | public String getName() {
82 | return name;
83 | }
84 |
85 | public void setName(String name) {
86 | this.name = name;
87 | }
88 |
89 | public String getUrl() {
90 | return url;
91 | }
92 |
93 | public void setUrl(String url) {
94 | this.url = url;
95 | }
96 |
97 | public String getMimeType() {
98 | return mimeType;
99 | }
100 |
101 | public void setMimeType(String mimeType) {
102 | this.mimeType = mimeType;
103 | }
104 |
105 | public String getDownloadSavePath() {
106 | return downloadSavePath;
107 | }
108 |
109 | public void setDownloadSavePath(String downloadSavePath) {
110 | this.downloadSavePath = downloadSavePath;
111 | }
112 |
113 | public long getDownloadFinishedSize() {
114 | return downloadFinishedSize;
115 | }
116 |
117 | public void setDownloadFinishedSize(long downloadFinishedSize) {
118 | this.downloadFinishedSize = downloadFinishedSize;
119 | }
120 |
121 | public long getDownloadTotalSize() {
122 | return downloadTotalSize;
123 | }
124 |
125 | public void setDownloadTotalSize(long downloadTotalSize) {
126 | this.downloadTotalSize = downloadTotalSize;
127 | }
128 |
129 | public long getDownloadSpeed() {
130 | return downloadSpeed;
131 | }
132 |
133 | public void setDownloadSpeed(long downloadSpeed) {
134 | this.downloadSpeed = downloadSpeed;
135 | }
136 |
137 | public int getStatus() {
138 | return status;
139 | }
140 |
141 | public void setStatus(int status) {
142 | this.status = status;
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/DownloadTaskIDCreator.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | public interface DownloadTaskIDCreator {
4 |
5 | public String createId(DownloadTask task);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/Env.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.io.File;
4 |
5 | import android.os.Environment;
6 |
7 | public class Env {
8 |
9 | public static String ROOT_DIR = Environment.getExternalStorageDirectory().getPath() + File.separator + "HounyChang";
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/MD5DownloadTaskIDCreator.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import com.xckevin.download.util.MD5;
4 |
5 | public class MD5DownloadTaskIDCreator implements DownloadTaskIDCreator {
6 |
7 | @Override
8 | public String createId(DownloadTask task) {
9 | return MD5.getMD5(task.getUrl());
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/SqlLiteDownloadProvider.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import android.content.ContentValues;
9 | import android.database.Cursor;
10 | import android.database.sqlite.SQLiteDatabase;
11 | import android.text.TextUtils;
12 |
13 |
14 | public class SqlLiteDownloadProvider implements DownloadProvider {
15 |
16 | private static SqlLiteDownloadProvider instance;
17 |
18 | private DownloadManager manager;
19 |
20 | private String DOWNLOAD_TABLE = "tb_download";
21 |
22 | private SQLiteDatabase db;
23 |
24 | private SqlLiteDownloadProvider(DownloadManager manager) {
25 | this.manager = manager;
26 | File dbFile = new File(manager.getConfig().getDownloadSavePath()+File.separator+"db", "download.db");
27 | if(dbFile.exists()) {
28 | db = SQLiteDatabase.openDatabase(dbFile.getPath(), null, SQLiteDatabase.OPEN_READWRITE);
29 | } else {
30 | if(!dbFile.getParentFile().isDirectory()) {
31 | dbFile.getParentFile().mkdirs();
32 | }
33 | try {
34 | dbFile.createNewFile();
35 | db = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | throw new IllegalAccessError("cannot create database file of path: " + dbFile.getAbsolutePath());
39 | }
40 | }
41 |
42 | createTables();
43 | }
44 |
45 | public static synchronized SqlLiteDownloadProvider getInstance(DownloadManager manager) {
46 | if(instance == null) {
47 | instance = new SqlLiteDownloadProvider(manager);
48 | }
49 |
50 | return instance;
51 | }
52 |
53 | private void createTables() {
54 | StringBuffer buffer = new StringBuffer();
55 | buffer.append("CREATE TABLE IF NOT EXISTS ").append(DOWNLOAD_TABLE);
56 | buffer.append("(");
57 | buffer.append("`").append(DownloadTask.ID).append("` VARCHAR PRIMARY KEY,");
58 | buffer.append("`").append(DownloadTask.URL).append("` VARCHAR,");
59 | buffer.append("`").append(DownloadTask.MIMETYPE).append("` VARCHAR,");
60 | buffer.append("`").append(DownloadTask.SAVEPATH).append("` VARCHAR,");
61 | buffer.append("`").append(DownloadTask.NAME).append("` VARCHAR,");
62 | buffer.append("`").append(DownloadTask.FINISHEDSIZE).append("` LONG,");
63 | buffer.append("`").append(DownloadTask.TOTALSIZE).append("` LONG,");
64 | buffer.append("`").append(DownloadTask.STATUS).append("` int");
65 | buffer.append(")");
66 | db.execSQL(buffer.toString());
67 | }
68 |
69 | public void saveDownloadTask(DownloadTask task) {
70 | ContentValues values = createDownloadTaskValues(task);
71 | db.insert(DOWNLOAD_TABLE, null, values);
72 |
73 | notifyDownloadStatusChanged(task);
74 | }
75 |
76 | public void updateDownloadTask(DownloadTask task) {
77 | ContentValues values = createDownloadTaskValues(task);
78 | db.update(DOWNLOAD_TABLE, values, DownloadTask.ID + "=?", new String[]{task.getId()});
79 |
80 | notifyDownloadStatusChanged(task);
81 | }
82 |
83 | public DownloadTask findDownloadTaskById(String id) {
84 | if(TextUtils.isEmpty(id)) {
85 | return null;
86 | }
87 | DownloadTask task = null;
88 | Cursor cursor = db.query(DOWNLOAD_TABLE, null, DownloadTask.ID + "=?", new String[]{id}, null, null, null);
89 | if(cursor.moveToNext()) {
90 | task = restoreDownloadTaskFromCursor(cursor);
91 | }
92 | cursor.close();
93 |
94 | return task;
95 | }
96 |
97 | public void deleteDownloadTask(DownloadTask task){
98 | db.delete(DOWNLOAD_TABLE, DownloadTask.ID + "=?", new String[]{task.getId()});
99 | notifyDownloadStatusChanged(task);
100 | }
101 |
102 | public DownloadTask findDownloadTask(String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) {
103 | DownloadTask task = null;
104 | Cursor cursor = db.query(DOWNLOAD_TABLE, columns, selection, selectionArgs, groupBy, having, orderBy);
105 | if(cursor.moveToNext()) {
106 | task = restoreDownloadTaskFromCursor(cursor);
107 | }
108 | cursor.close();
109 |
110 | return task;
111 | }
112 |
113 | public void notifyDownloadStatusChanged(DownloadTask task) {
114 | manager.notifyDownloadTaskStatusChanged(task);
115 | }
116 |
117 | public List getAllDownloadTask() {
118 | List list = new ArrayList();
119 | DownloadTask task = null;
120 | Cursor cursor = db.query(DOWNLOAD_TABLE, null, null, null, null, null, DownloadTask.STATUS);
121 | while(cursor.moveToNext()) {
122 | task = restoreDownloadTaskFromCursor(cursor);
123 | list.add(task);
124 | }
125 | cursor.close();
126 | return list;
127 | }
128 |
129 | private ContentValues createDownloadTaskValues(DownloadTask task) {
130 | ContentValues values = new ContentValues();
131 | values.put(DownloadTask.ID, task.getId());
132 | values.put(DownloadTask.URL, task.getUrl());
133 | values.put(DownloadTask.MIMETYPE, task.getMimeType());
134 | values.put(DownloadTask.SAVEPATH, task.getDownloadSavePath());
135 | values.put(DownloadTask.FINISHEDSIZE, task.getDownloadFinishedSize());
136 | values.put(DownloadTask.TOTALSIZE, task.getDownloadTotalSize());
137 | values.put(DownloadTask.NAME, task.getName());
138 | values.put(DownloadTask.STATUS, task.getStatus());
139 |
140 | return values;
141 | }
142 |
143 | private DownloadTask restoreDownloadTaskFromCursor(Cursor cursor) {
144 | DownloadTask task = new DownloadTask();
145 | task.setId(cursor.getString(cursor.getColumnIndex(DownloadTask.ID)));
146 | task.setName(cursor.getString(cursor.getColumnIndex(DownloadTask.NAME)));
147 | task.setUrl(cursor.getString(cursor.getColumnIndex(DownloadTask.URL)));
148 | task.setMimeType(cursor.getString(cursor.getColumnIndex(DownloadTask.MIMETYPE)));
149 | task.setDownloadSavePath(cursor.getString(cursor.getColumnIndex(DownloadTask.SAVEPATH)));
150 | task.setDownloadFinishedSize(cursor.getLong(cursor.getColumnIndex(DownloadTask.FINISHEDSIZE)));
151 | task.setDownloadTotalSize(cursor.getLong(cursor.getColumnIndex(DownloadTask.TOTALSIZE)));
152 | task.setStatus(cursor.getInt(cursor.getColumnIndex(DownloadTask.STATUS)));
153 | return task;
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/util/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.util;
2 |
3 | import java.io.File;
4 | import java.util.UUID;
5 |
6 | /**
7 | * file utilities
8 | *
9 | * @author Kevin
10 | */
11 | public class FileUtil {
12 |
13 | /**
14 | * get file name from url
15 | *
16 | * @param url
17 | * @return
18 | */
19 | public static String getFileNameByUrl(String url) {
20 | if (StringUtil.isEmpty(url)) {
21 | return null;
22 | }
23 | int index = url.lastIndexOf('?');
24 | int index2 = url.lastIndexOf("/");
25 | if (index > 0 && index2 >= index) {
26 | return UUID.randomUUID().toString();
27 | }
28 | return url.substring(index2 + 1, index < 0 ? url.length() : index);
29 | }
30 |
31 | /**
32 | * get file extend name
33 | *
34 | * @param fileName
35 | * @return
36 | */
37 | public static String getFileExtendName(String fileName) {
38 | if (StringUtil.isEmpty(fileName)) {
39 | return null;
40 | }
41 | int index = fileName.lastIndexOf('.');
42 | if (index < 0) {
43 | return "unknown";
44 | } else {
45 | return fileName.substring(index + 1);
46 | }
47 | }
48 |
49 | public static boolean isFileExists(String filePath) {
50 | if (StringUtil.isEmpty(filePath)) {
51 | return false;
52 | }
53 |
54 | return new File(filePath).exists();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/util/MD5.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.util;
2 |
3 | import java.util.Locale;
4 |
5 | /**
6 | * MD 加密
7 | *
8 | * @author Kevin
9 | */
10 | public class MD5 {
11 |
12 | public static String getMD5(String instr) {
13 | String s = null;
14 | char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
15 | 'a', 'b', 'c', 'd', 'e', 'f'};
16 | try {
17 | java.security.MessageDigest md = java.security.MessageDigest
18 | .getInstance("MD5");
19 | md.update(instr.getBytes());
20 | byte tmp[] = md.digest();
21 | char str[] = new char[16 * 2];
22 | int k = 0;
23 | for (int i = 0; i < 16; i++) {
24 | byte byte0 = tmp[i];
25 | str[k++] = hexDigits[byte0 >>> 4 & 0xf];
26 | str[k++] = hexDigits[byte0 & 0xf];
27 | }
28 | s = new String(str).toUpperCase(Locale.ENGLISH);
29 |
30 | } catch (Exception e) {
31 |
32 | }
33 | return s;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/lib_download/src/com/xckevin/download/util/StringUtil.java:
--------------------------------------------------------------------------------
1 | package com.xckevin.download.util;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | /**
6 | * common string utils
7 | * @author Kevin
8 | *
9 | */
10 | public class StringUtil {
11 |
12 | // email
13 | private final static Pattern emailer = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
14 |
15 | /**
16 | * if string is empty
17 | *
18 | * @param input
19 | * @return boolean
20 | */
21 | public static boolean isEmpty(String input) {
22 | if (input == null || "".equals(input))
23 | return true;
24 |
25 | for (int i = 0; i < input.length(); i++) {
26 | char c = input.charAt(i);
27 | if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
28 | return false;
29 | }
30 | }
31 | return true;
32 | }
33 |
34 | /**
35 | * if email is valid
36 | *
37 | * @param email
38 | * @return
39 | */
40 | public static boolean isEmail(String email) {
41 | if (email == null || email.trim().length() == 0)
42 | return false;
43 | return emailer.matcher(email).matches();
44 | }
45 |
46 | /**
47 | * 半角转换为全角
48 | *
49 | * @param input
50 | * @return
51 | */
52 | public static String toDBC(String input) {
53 | char[] c = input.toCharArray();
54 | for (int i = 0; i < c.length; i++) {
55 | if (c[i] == 12288) {
56 | c[i] = (char) 32;
57 | continue;
58 | }
59 | if (c[i] > 65280 && c[i] < 65375)
60 | c[i] = (char) (c[i] - 65248);
61 | }
62 | return new String(c);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------