├── .gitignore
├── LICENSE.txt
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── cn
│ │ └── hugeterry
│ │ └── updatedemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── cn
│ │ │ └── hugeterry
│ │ │ └── updatedemo
│ │ │ ├── MainActivity.java
│ │ │ └── ManualUpdateActivity.java
│ └── res
│ │ ├── drawable
│ │ └── ic_arrow_white_24dp.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── activity_manualupdate.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── cn
│ └── hugeterry
│ └── updatedemo
│ └── ExampleUnitTest.java
├── settings.gradle
├── showUI
├── 1.png
├── 2.png
└── 3.png
└── updatefun
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── cn
│ └── hugeterry
│ └── updatefun
│ └── ApplicationTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── cn
│ │ └── hugeterry
│ │ └── updatefun
│ │ ├── UpdateFunGO.java
│ │ ├── config
│ │ ├── DownloadKey.java
│ │ └── UpdateKey.java
│ │ ├── module
│ │ ├── Download.java
│ │ ├── HandleUpdateResult.java
│ │ └── Update.java
│ │ ├── utils
│ │ ├── GetAppInfo.java
│ │ ├── InstallApk.java
│ │ └── StorageUtils.java
│ │ └── view
│ │ ├── DownLoadDialog.java
│ │ └── UpdateDialog.java
└── res
│ ├── drawable
│ ├── bg_button_normal.xml
│ ├── bg_button_pressed.xml
│ ├── bg_progress.xml
│ ├── button_update.xml
│ ├── ic_close_white_24dp.xml
│ └── material_card.xml
│ ├── layout
│ ├── download_dialog.xml
│ ├── download_notification_layout.xml
│ └── update_dialog.xml
│ ├── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ └── file_paths.xml
└── test
└── java
└── cn
└── hugeterry
└── updatefun
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | .DS_Store
5 | /build
6 | # built application files
7 | *.apk
8 | *.ap_
9 |
10 | # files for the dex VM
11 | *.dex
12 |
13 | # Java class files
14 | *.class
15 | .DS_Store
16 |
17 | # generated files
18 | bin/
19 | gen/
20 | Wiki/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Eclipse project files
26 | .classpath
27 | .project
28 | .settings/
29 |
30 | # Proguard folder generated by Eclipse
31 | proguard/
32 |
33 | #Android Studio
34 | build/
35 |
36 | # Intellij project files
37 | *.iml
38 | *.ipr
39 | *.iws
40 | .idea/
41 |
42 | #gradle
43 | .gradle/
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2016 HugeTerry.
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UpdateFun更新库
2 |
3 | UpdateFun是一个[fir.im](http://fir.im/)的Android更新下载模块,在[fir.im](http://fir.im/)上上传自己的APP后接入该库即可实现检查更新下载
4 |
5 | [](https://github.com/hugeterry/UpdateDemo/blob/master/LICENSE.txt)
6 | [ ](https://bintray.com/hugeterry/update/UpdateFun/_latestVersion)
7 |
8 |
9 |
10 |
11 | ## 用法
12 |
13 | ### Step 1
14 |
15 | 在gradle文件中加入下面的依赖:
16 |
17 | ```groovy
18 | dependencies {
19 | compile 'cn.hugeterry.updatefun:updatefun:2.0.6'
20 | }
21 | ```
22 |
23 | 如果你使用Maven,那么加入下面的依赖:
24 |
25 | ```xml
26 |
27 | cn.hugeterry.updatefun
28 | updatefun
29 | 2.0.6
30 | pom
31 |
32 | ```
33 |
34 | ### Step 2
35 |
36 | 在主界面activity的onCreate()中加上以下语句进行初始化(请放在setContentView()方法的后面):
37 |
38 | ```java
39 | UpdateKey.API_TOKEN = "写上你fir.im账号的API_TOKEN";
40 | UpdateKey.APP_ID = "写上APP的应用ID";
41 | //下载方式:
42 | //UpdateKey.DialogOrNotification=UpdateKey.WITH_DIALOG;通过Dialog来进行下载
43 | //UpdateKey.DialogOrNotification=UpdateKey.WITH_NOTIFITION;通过通知栏来进行下载(默认)
44 | UpdateFunGO.init(this);
45 | ```
46 |
47 | ### Step 3
48 |
49 | 在主界面Activity中加上以下语句:
50 |
51 | ```java
52 | @Override
53 | protected void onResume() {
54 | super.onResume();
55 | UpdateFunGO.onResume(this);
56 | }
57 | @Override
58 | protected void onStop() {
59 | super.onStop();
60 | UpdateFunGO.onStop(this);
61 | }
62 | ```
63 |
64 | ### Step 4 (2.0.6以上版本必须加,兼容Android 7.0+,非Android 7.0的手机也要加)
65 |
66 | 在app文件夹下的build.gradle里添加:
67 |
68 | ```groovy
69 | android {
70 | defaultConfig {
71 | ...
72 | resValue "string", "updatefun_provider_file_authorities", ".fileprovider"
73 | }
74 | }
75 | ```
76 |
77 | ``为你的应用包名
78 |
79 | 大功告成,好好享用吧
80 |
81 | ## 其他功能
82 |
83 | ### 手动更新(需1.8.4以上版本)[案例代码](sample/src/main/java/cn/hugeterry/updatedemo/ManualUpdateActivity.java)
84 |
85 | 请确保在你的app已添加依赖(见用法Step 1),
86 | 并已经写上你fir.im账号的API_TOKEN以及APP的应用ID(见用法Step 2)
87 |
88 | 在需要手动更新时调用:
89 | ```java
90 | UpdateFunGO.manualStart(this);
91 | ```
92 | 并在手动更新的当前Activity添加上以下代码:
93 | ```java
94 | @Override
95 | protected void onResume() {
96 | super.onResume();
97 | UpdateFunGO.onResume(this);
98 | }
99 | @Override
100 | protected void onStop() {
101 | super.onStop();
102 | UpdateFunGO.onStop(this);
103 | }
104 | ```
105 | 即可实现手动更新
106 |
107 |
108 |
109 | ## Demo
110 | [http://fir.im/updatefun](http://fir.im/updatefun)
111 |
112 |
113 | ## LICENSE
114 |
115 |
116 | Copyright 2016 HugeTerry.
117 |
118 | Licensed under the Apache License, Version 2.0 (the "License");
119 | you may not use this file except in compliance with the License.
120 | You may obtain a copy of the License at
121 |
122 | http://www.apache.org/licenses/LICENSE-2.0
123 |
124 | Unless required by applicable law or agreed to in writing, software
125 | distributed under the License is distributed on an "AS IS" BASIS,
126 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127 | See the License for the specific language governing permissions and
128 | limitations under the License.
129 |
130 |
131 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:3.0.1'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
10 | classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 27 13:03:38 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion '26.0.2'
6 |
7 | defaultConfig {
8 | applicationId "cn.hugeterry.updatedemo"
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 9
12 | versionName "1.6"
13 |
14 |
15 | resValue "string", "updatefun_provider_file_authorities", "cn.hugeterry.updatedemo.fileprovider"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(include: ['*.jar'], dir: 'libs')
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:appcompat-v7:25.1.0'
30 | compile project(':updatefun')
31 | }
32 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/admin/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/cn/hugeterry/updatedemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatedemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sample/src/main/java/cn/hugeterry/updatedemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatedemo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import cn.hugeterry.updatefun.config.UpdateKey;
9 | import cn.hugeterry.updatefun.UpdateFunGO;
10 |
11 | /**
12 | * Created by hugeterry(http://hugeterry.cn)
13 | * Date: 16/7/14 09:35
14 | */
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | //TODO:填上在http://fir.im/注册账号后获得的API_TOKEN以及APP的应用ID
22 | UpdateKey.API_TOKEN = "";
23 | UpdateKey.APP_ID = "578a11e7748aac01b7000039";
24 | //如果你想通过Dialog来进行下载,可以如下设置
25 | //UpdateKey.DialogOrNotification=UpdateKey.WITH_DIALOG;
26 | UpdateFunGO.init(this);
27 | }
28 |
29 | public void toUpdateView(View view) {
30 | //跳转至手动更新Activity
31 | Intent intent = new Intent(this, ManualUpdateActivity.class);
32 | startActivity(intent);
33 | }
34 |
35 | @Override
36 | protected void onResume() {
37 | super.onResume();
38 | UpdateFunGO.onResume(this);
39 | }
40 |
41 | @Override
42 | protected void onStop() {
43 | super.onStop();
44 | UpdateFunGO.onStop(this);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sample/src/main/java/cn/hugeterry/updatedemo/ManualUpdateActivity.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatedemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.Toolbar;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 |
9 | import cn.hugeterry.updatefun.UpdateFunGO;
10 |
11 | /**
12 | * 手动更新界面示例
13 | * Created by hugeterry(http://hugeterry.cn)
14 | * Date: 16/8/28 21:52
15 | */
16 | public class ManualUpdateActivity extends AppCompatActivity {
17 |
18 | private Toolbar toolbar;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_manualupdate);
24 |
25 | initToolbar();
26 | }
27 |
28 | public void checkUpdate(View view) {
29 | //请确保在主Activity已填上在http://fir.im/注册账号后获得的API_TOKEN以及APP的应用ID
30 | //手动更新onClick(),启动更新检测
31 | UpdateFunGO.manualStart(this);
32 | }
33 |
34 | @Override
35 | protected void onResume() {
36 | super.onResume();
37 | UpdateFunGO.onResume(this);
38 | }
39 |
40 | @Override
41 | protected void onStop() {
42 | super.onStop();
43 | UpdateFunGO.onStop(this);
44 | }
45 |
46 | private void initToolbar() {
47 | toolbar = (Toolbar) findViewById(R.id.toolbar);
48 | setSupportActionBar(toolbar);
49 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
50 | getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_white_24dp);
51 | getSupportActionBar().setTitle("关于");
52 | }
53 |
54 | @Override
55 | public boolean onOptionsItemSelected(MenuItem item) {
56 | switch (item.getItemId()) {
57 | case android.R.id.home:
58 | finish();
59 | break;
60 | }
61 | return super.onOptionsItemSelected(item);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_arrow_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_manualupdate.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UpdateDemo
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/src/test/java/cn/hugeterry/updatedemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatedemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':updatefun'
2 |
--------------------------------------------------------------------------------
/showUI/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/showUI/1.png
--------------------------------------------------------------------------------
/showUI/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/showUI/2.png
--------------------------------------------------------------------------------
/showUI/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hugeterry/UpdateFun/ff8371ad93c2ddfdafc77226cfd33af708b815c5/showUI/3.png
--------------------------------------------------------------------------------
/updatefun/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/updatefun/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | version = "2.0.6"
6 |
7 | android {
8 | compileSdkVersion 25
9 | buildToolsVersion '26.0.2'
10 |
11 | defaultConfig {
12 | minSdkVersion 15
13 | targetSdkVersion 25
14 | versionCode 26
15 | versionName "2.0.6"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:appcompat-v7:25.1.0'
30 | }
31 |
32 | def siteUrl = 'https://github.com/hugeterry/UpdateDemo'
33 | def gitUrl = 'https://github.com/hugeterry/UpdateDemo.git'
34 | group = "cn.hugeterry.updatefun"
35 | install {
36 | repositories.mavenInstaller {
37 | pom {
38 | project {
39 | packaging 'aar'
40 | name ''
41 | url siteUrl
42 |
43 | licenses {
44 | license {
45 | name 'The Apache Software License, Version 2.0'
46 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
47 | }
48 | }
49 | developers {
50 | developer {
51 | id 'hugeterry'
52 | name 'HugeTerry'
53 | email 'xuxt-314@qq.com'
54 | }
55 | }
56 | scm {
57 | connection gitUrl
58 | developerConnection gitUrl
59 | url siteUrl
60 | }
61 | }
62 | }
63 | }
64 | }
65 | task sourcesJar(type: Jar) {
66 | from android.sourceSets.main.java.srcDirs
67 | classifier = 'sources'
68 | }
69 | task javadoc(type: Javadoc) {
70 | source = android.sourceSets.main.java.srcDirs
71 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
72 | }
73 | task javadocJar(type: Jar, dependsOn: javadoc) {
74 | classifier = 'javadoc'
75 | from javadoc.destinationDir
76 | }
77 | artifacts {
78 | archives javadocJar
79 | archives sourcesJar
80 | }
81 | Properties properties = new Properties()
82 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
83 | bintray {
84 | user = properties.getProperty("bintray.user")
85 | key = properties.getProperty("bintray.apikey")
86 | configurations = ['archives']
87 | pkg {
88 | repo = "update"
89 | name = "UpdateFun"
90 | websiteUrl = siteUrl
91 | vcsUrl = gitUrl
92 | licenses = ["Apache-2.0"]
93 | publish = true
94 | }
95 | }
--------------------------------------------------------------------------------
/updatefun/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/admin/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/updatefun/src/androidTest/java/cn/hugeterry/updatefun/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/updatefun/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
17 |
20 |
21 |
26 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/UpdateFunGO.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun;
2 |
3 | import android.app.Activity;
4 | import android.app.Notification;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.widget.Toast;
9 |
10 | import cn.hugeterry.updatefun.config.DownloadKey;
11 | import cn.hugeterry.updatefun.config.UpdateKey;
12 | import cn.hugeterry.updatefun.module.Download;
13 | import cn.hugeterry.updatefun.module.HandleUpdateResult;
14 | import cn.hugeterry.updatefun.view.DownLoadDialog;
15 | import cn.hugeterry.updatefun.utils.GetAppInfo;
16 |
17 | /**
18 | * Created by hugeterry(http://hugeterry.cn)
19 | */
20 | public class UpdateFunGO {
21 |
22 | private static Thread download;
23 | private static Thread thread_update;
24 |
25 | private static volatile UpdateFunGO sInst = null;
26 |
27 | public static void manualStart(Context context) {
28 | DownloadKey.ISManual = true;
29 | if (!DownloadKey.LoadManual) {
30 | DownloadKey.LoadManual = true;
31 | new UpdateFunGO(context);
32 | } else Toast.makeText(context, "正在更新中,请稍等", Toast.LENGTH_LONG).show();
33 | }
34 |
35 | public static UpdateFunGO init(Context context) {
36 | UpdateFunGO inst = sInst;
37 | if (inst == null) {
38 | synchronized (UpdateFunGO.class) {
39 | inst = sInst;
40 | if (inst == null) {
41 | inst = new UpdateFunGO(context);
42 | sInst = inst;
43 | }
44 | }
45 | }
46 | return inst;
47 | }
48 |
49 | private UpdateFunGO(Context context) {
50 | if (DownloadKey.TOShowDownloadView != 2) {
51 | thread_update = new Thread(new HandleUpdateResult(context));
52 | thread_update.start();
53 | }
54 | }
55 |
56 | public static void showDownloadView(Context context) {
57 | DownloadKey.saveFileName =
58 | GetAppInfo.getAppPackageName(context) + ".apk";
59 | if (UpdateKey.DialogOrNotification == 1) {
60 | Intent intent = new Intent();
61 | intent.setClass(context, DownLoadDialog.class);
62 | ((Activity) context).startActivityForResult(intent, 0);
63 | } else if (UpdateKey.DialogOrNotification == 2) {
64 | Notification.Builder builder = notificationInit(context);
65 | download = new Download(context, builder);
66 | download.start();
67 | }
68 | }
69 |
70 | private static Notification.Builder notificationInit(Context context) {
71 | Intent intent = new Intent(context, context.getClass());
72 | PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
73 |
74 | Notification.Builder builder = new Notification.Builder(context);
75 | builder.setSmallIcon(android.R.drawable.stat_sys_download)
76 | .setTicker("开始下载")
77 | .setContentTitle(GetAppInfo.getAppName(context))
78 | .setContentText("正在更新")
79 | .setContentIntent(pIntent)
80 | .setWhen(System.currentTimeMillis());
81 | return builder;
82 | }
83 |
84 | public static void onResume(Context context) {
85 | if (DownloadKey.TOShowDownloadView == 2) {
86 | showDownloadView(context);
87 | } else {
88 | if (sInst != null) sInst = null;
89 | }
90 | }
91 |
92 | public static void onStop(Context context) {
93 | if (DownloadKey.TOShowDownloadView == 2 && UpdateKey.DialogOrNotification == 2) {
94 | download.interrupt();
95 | }
96 | if (thread_update != null) {
97 | thread_update.interrupt();
98 | }
99 | if (DownloadKey.ISManual) {
100 | DownloadKey.ISManual = false;
101 | }
102 | if (DownloadKey.LoadManual) {
103 | DownloadKey.LoadManual = false;
104 | }
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/config/DownloadKey.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.config;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by hugeterry(http://hugeterry.cn)
7 | */
8 | public class DownloadKey {
9 | @Deprecated
10 | public static Context FROMACTIVITY = null;
11 | public static Boolean ISManual = false;
12 | public static Boolean LoadManual = false;
13 | public static int TOShowDownloadView = 0;
14 | // public static final String savePath = Environment.getExternalStorageDirectory() + "/UpdateFun/";
15 | public static String saveFileName = "newversion.apk";
16 | public static String apkUrl = "";
17 | public static String changeLog = "";
18 | public static String version;
19 | public static boolean interceptFlag = false;
20 | }
21 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/config/UpdateKey.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.config;
2 |
3 | /**
4 | * Created by hugeterry(http://hugeterry.cn)
5 | */
6 | public class UpdateKey {
7 | public static String API_TOKEN = "";
8 | public static String APP_ID = "";
9 |
10 | public final static int WITH_DIALOG = 1;
11 | public final static int WITH_NOTIFITION = 2;
12 |
13 | public static int DialogOrNotification = WITH_NOTIFITION;//default
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/module/Download.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.module;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.lang.ref.WeakReference;
9 | import java.net.HttpURLConnection;
10 | import java.net.MalformedURLException;
11 | import java.net.URL;
12 |
13 | import android.annotation.TargetApi;
14 | import android.app.Notification;
15 | import android.app.NotificationManager;
16 | import android.content.Context;
17 | import android.os.Build;
18 | import android.os.Handler;
19 | import android.os.Message;
20 | import android.util.Log;
21 | import android.widget.Toast;
22 |
23 | import cn.hugeterry.updatefun.config.DownloadKey;
24 | import cn.hugeterry.updatefun.config.UpdateKey;
25 | import cn.hugeterry.updatefun.utils.GetAppInfo;
26 | import cn.hugeterry.updatefun.utils.InstallApk;
27 | import cn.hugeterry.updatefun.utils.StorageUtils;
28 | import cn.hugeterry.updatefun.view.DownLoadDialog;
29 |
30 | /**
31 | * Created by hugeterry(http://hugeterry.cn)
32 | */
33 | public class Download extends Thread {
34 |
35 | private static final int DOWN_UPDATE = 1;
36 | private static final int DOWN_OVER = 2;
37 | private static int progress;
38 |
39 | private Down_handler handler;
40 |
41 | private static int length;
42 | private static int count;
43 |
44 | private Context context;
45 | private static File apkFile;
46 |
47 | public Download(Context context) {
48 | this.context = context;
49 | handler = new Down_handler(context);
50 | }
51 |
52 | public Download(Context context, Notification.Builder builder) {
53 | this.context = context;
54 | NotificationManager notificationManager =
55 | (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
56 | handler = new Down_handler(context, builder, notificationManager);
57 | }
58 |
59 | private static class Down_handler extends Handler {
60 | WeakReference mContextReference;
61 | Notification.Builder builder;
62 | NotificationManager notificationManager;
63 |
64 | Down_handler(Context context) {
65 | mContextReference = new WeakReference<>(context);
66 | }
67 |
68 | Down_handler(Context context, Notification.Builder builder, NotificationManager notificationManager) {
69 | mContextReference = new WeakReference<>(context);
70 | this.builder = builder;
71 | this.notificationManager = notificationManager;
72 | }
73 |
74 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
75 | @Override
76 | public void handleMessage(Message msg) {
77 | Context context = mContextReference.get();
78 | switch (msg.what) {
79 | case DOWN_UPDATE:
80 | if (UpdateKey.DialogOrNotification == 1) {
81 | ((DownLoadDialog) context).progressBar.setProgress(progress);
82 | ((DownLoadDialog) context).textView.setText(progress + "%");
83 | } else if (UpdateKey.DialogOrNotification == 2) {
84 | builder.setProgress(length, count, false)
85 | .setContentText("下载进度:" + progress + "%");
86 | notificationManager.notify(1115, builder.build());
87 | }
88 | break;
89 | case DOWN_OVER:
90 | if (UpdateKey.DialogOrNotification == 1) {
91 | ((DownLoadDialog) context).finish();
92 | } else if (UpdateKey.DialogOrNotification == 2) {
93 | builder.setTicker("下载完成");
94 | notificationManager.notify(1115, builder.build());
95 | notificationManager.cancel(1115);
96 | }
97 | length = 0;
98 | count = 0;
99 | DownloadKey.TOShowDownloadView = 1;
100 | if (DownloadKey.ISManual) {
101 | DownloadKey.LoadManual = false;
102 | }
103 | if (checkApk(context)) {
104 | Log.i("UpdateFun TAG", "APK路径:" + apkFile);
105 | InstallApk.startInstall(context, apkFile);
106 | }
107 | break;
108 | default:
109 | break;
110 | }
111 | }
112 |
113 | }
114 |
115 | public void run() {
116 | URL url = null;
117 | HttpURLConnection conn = null;
118 | InputStream is = null;
119 | try {
120 | url = new URL(DownloadKey.apkUrl);
121 | } catch (MalformedURLException e) {
122 | e.printStackTrace();
123 | }
124 | Log.i("UpdateFun TAG",
125 | String.format("ApkDownloadUrl:%s", DownloadKey.apkUrl));
126 | try {
127 | conn = (HttpURLConnection) url.openConnection();
128 | conn.connect();
129 | length = conn.getContentLength();
130 | is = conn.getInputStream();
131 | } catch (FileNotFoundException e0) {
132 | // e0.printStackTrace();
133 | try {
134 | conn.disconnect();
135 | conn = (HttpURLConnection) url.openConnection();
136 | conn.setInstanceFollowRedirects(false);
137 | conn.connect();
138 | String location = new String(conn.getHeaderField("Location").getBytes("ISO-8859-1"), "UTF-8").replace(" ", "");
139 | url = new URL(location);
140 | conn = (HttpURLConnection) url.openConnection();
141 | conn.connect();
142 | length = conn.getContentLength();
143 | is = conn.getInputStream();
144 | } catch (IOException e1) {
145 | e1.printStackTrace();
146 | }
147 | } catch (IOException e2) {
148 | e2.printStackTrace();
149 | }
150 |
151 |
152 | try {
153 | File file = StorageUtils.getCacheDirectory(context);
154 | if (!file.exists()) {
155 | file.mkdir();
156 | }
157 |
158 | apkFile = new File(file, DownloadKey.saveFileName);
159 | FileOutputStream fos = new FileOutputStream(apkFile);
160 | long tempFileLength = file.length();
161 | byte buf[] = new byte[1024];
162 | int times = 0; //这很重要
163 | int numread;
164 | do {
165 | numread = is.read(buf);
166 | count += numread;
167 | progress = (int) (((float) count / length) * 100);
168 | if ((times == 512) || (tempFileLength == length)) {
169 | handler.sendEmptyMessage(DOWN_UPDATE);
170 | times = 0;
171 | }
172 | times++;
173 | if (numread <= 0) {
174 | handler.sendEmptyMessage(DOWN_OVER);
175 | break;
176 | }
177 | fos.write(buf, 0, numread);
178 | } while (!DownloadKey.interceptFlag);// 点击取消就停止下载.
179 | fos.flush();
180 | fos.close();
181 | is.close();
182 | conn.disconnect();
183 |
184 | if (DownloadKey.interceptFlag) {
185 | Log.i("UpdateFun TAG", "interrupt");
186 | length = 0;
187 | count = 0;
188 | DownloadKey.interceptFlag = false;
189 | this.interrupt();
190 | }
191 | } catch (IOException e3) {
192 | e3.printStackTrace();
193 | }
194 | }
195 |
196 | private static boolean checkApk(Context context) {
197 | String apkName = GetAppInfo.getAPKPackageName(context, apkFile.toString());
198 | String appName = GetAppInfo.getAppPackageName(context);
199 | if (apkName.equals(appName)) {
200 | Log.i("UpdateFun TAG", "apk检验:包名相同,安装apk");
201 | return true;
202 | } else {
203 | Log.i("UpdateFun TAG",
204 | String.format("apk检验:包名不同。该app包名:%s,apk包名:%s", appName, apkName));
205 | Toast.makeText(context, "apk检验:包名不同,不进行安装,原因可能是运营商劫持", Toast.LENGTH_LONG).show();
206 | return false;
207 | }
208 | }
209 |
210 | }
211 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/module/HandleUpdateResult.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.module;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Handler;
7 | import android.os.Message;
8 | import android.util.Log;
9 | import android.widget.Toast;
10 |
11 | import java.lang.ref.WeakReference;
12 |
13 | import cn.hugeterry.updatefun.config.DownloadKey;
14 | import cn.hugeterry.updatefun.utils.GetAppInfo;
15 | import cn.hugeterry.updatefun.view.UpdateDialog;
16 |
17 | /**
18 | * Created by hugeterry(http://hugeterry.cn)
19 | */
20 | public class HandleUpdateResult implements Runnable {
21 |
22 | private String version = "";
23 | private Up_handler up_handler;
24 |
25 | public HandleUpdateResult(Context context) {
26 | up_handler = new Up_handler(context);
27 | this.version = GetAppInfo.getAppVersionName(context);
28 | }
29 |
30 | private static class Up_handler extends Handler {
31 | WeakReference mActivityReference;
32 |
33 | public Up_handler(Context context) {
34 | mActivityReference = new WeakReference<>(context);
35 | }
36 |
37 | @Override
38 | public void handleMessage(Message msg) {
39 | final Context context = mActivityReference.get();
40 | if (context != null) {
41 | switch (msg.arg1) {
42 | case 1:
43 | showNoticeDialog(context);
44 | break;
45 | case 2:
46 | if (DownloadKey.ISManual) {
47 | DownloadKey.LoadManual = false;
48 | Toast.makeText(context, "网络不畅通", Toast.LENGTH_LONG).show();
49 | }
50 | break;
51 | case 3:
52 | if (DownloadKey.ISManual) {
53 | DownloadKey.LoadManual = false;
54 | Toast.makeText(context, "版本已是最新", Toast.LENGTH_LONG).show();
55 | }
56 | break;
57 | default:
58 | break;
59 | }
60 | }
61 | }
62 | }
63 |
64 | @Override
65 | public void run() {
66 | Update update = new Update();
67 | update.start();
68 |
69 | Message msg = new Message();
70 | try {
71 | update.join();
72 | } catch (InterruptedException e) {
73 | e.printStackTrace();
74 | }
75 |
76 | if (DownloadKey.version == null) {
77 | Log.i("UpdateFun TAG", "获取的应用信息为空,不更新,请确认网络是否畅通或者应用ID及API_TOKEN是否正确");
78 | msg.arg1 = 2;
79 | up_handler.sendMessage(msg);
80 | } else if (!DownloadKey.version.equals(version)) {
81 | Log.i("UpdateFun TAG", "需更新版本");
82 | msg.arg1 = 1;
83 | up_handler.sendMessage(msg);
84 | } else {
85 | Log.i("UpdateFun TAG", "版本已是最新");
86 | msg.arg1 = 3;
87 | up_handler.sendMessage(msg);
88 | }
89 | }
90 |
91 | public static void showNoticeDialog(Context context) {
92 | Intent intent = new Intent();
93 | intent.setClass(context, UpdateDialog.class);
94 | ((Activity) context).startActivityForResult(intent, 100);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/module/Update.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.module;
2 |
3 | import android.util.Log;
4 |
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStreamReader;
11 | import java.net.HttpURLConnection;
12 | import java.net.MalformedURLException;
13 | import java.net.URL;
14 |
15 | import cn.hugeterry.updatefun.config.DownloadKey;
16 | import cn.hugeterry.updatefun.config.UpdateKey;
17 |
18 | /**
19 | * Created by hugeterry(http://hugeterry.cn)
20 | */
21 | public class Update extends Thread {
22 |
23 | private String result;
24 | private String url = "http://api.fir.im/apps/latest/" + UpdateKey.APP_ID
25 | + "?api_token=" + UpdateKey.API_TOKEN;
26 |
27 | public void run() {
28 | try {
29 | URL httpUrl = new URL(url);
30 |
31 | HttpURLConnection conn = (HttpURLConnection) httpUrl
32 | .openConnection();
33 | conn.setRequestMethod("GET");
34 | conn.setReadTimeout(3000);
35 |
36 | if (conn.getResponseCode() == 200) {
37 | BufferedReader reader = new BufferedReader(new InputStreamReader(
38 | conn.getInputStream()));
39 | StringBuffer sb = new StringBuffer();
40 | String str;
41 |
42 | while ((str = reader.readLine()) != null) {
43 | sb.append(str);
44 | }
45 | result = new String(sb.toString().getBytes(), "utf-8");
46 |
47 | interpretingData(result);
48 | }
49 | } catch (MalformedURLException e) {
50 | e.printStackTrace();
51 | } catch (IOException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 |
56 | private void interpretingData(String result) {
57 | try {
58 | JSONObject object = new JSONObject(result);
59 | DownloadKey.changeLog = object.getString("changelog");
60 | DownloadKey.version = object.getString("versionShort");
61 | DownloadKey.apkUrl = object.getString("installUrl");
62 | Log.i("UpdateFun TAG",
63 | String.format("ChangeLog:%s, Version:%s, ApkDownloadUrl:%s",
64 | DownloadKey.changeLog, DownloadKey.version, DownloadKey.apkUrl));
65 | } catch (JSONException e) {
66 | e.printStackTrace();
67 | }
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/utils/GetAppInfo.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.utils;
2 |
3 | import android.content.Context;
4 | import android.content.pm.ApplicationInfo;
5 | import android.content.pm.PackageInfo;
6 | import android.content.pm.PackageManager;
7 | import android.graphics.drawable.Drawable;
8 |
9 | /**
10 | * Created by hugeterry(http://hugeterry.cn)
11 | */
12 | public class GetAppInfo {
13 | public static String getAppName(Context context) {
14 | String appName = "";
15 | try {
16 | PackageInfo pi = context.getPackageManager()
17 | .getPackageInfo(context.getPackageName(), 0);
18 | appName = pi.applicationInfo.loadLabel(context.getPackageManager()).toString();
19 | if (appName == null || appName.length() <= 0) {
20 | return "";
21 | }
22 | } catch (PackageManager.NameNotFoundException e) {
23 | e.printStackTrace();
24 | }
25 | return appName;
26 | }
27 |
28 | public static String getAppVersionName(Context context) {
29 | String versionName = "";
30 | try {
31 | PackageInfo pi = context.getPackageManager()
32 | .getPackageInfo(context.getPackageName(), 0);
33 | versionName = pi.versionName;
34 | if (versionName == null || versionName.length() <= 0) {
35 | return "";
36 | }
37 | } catch (Exception e) {
38 | e.printStackTrace();
39 | }
40 | return versionName;
41 | }
42 |
43 | public static String getAppPackageName(Context context) {
44 | return context.getPackageName();
45 | }
46 |
47 | public static Drawable getAppIcon(Context context) {
48 | try {
49 | PackageManager pm = context.getPackageManager();
50 | ApplicationInfo info = pm.getApplicationInfo(context.getPackageName(), 0);
51 | return info.loadIcon(pm);
52 | } catch (PackageManager.NameNotFoundException e) {
53 | e.printStackTrace();
54 | }
55 | return null;
56 | }
57 |
58 | public static String getAPKPackageName(Context context, String apkPath) {
59 | PackageManager pm = context.getPackageManager();
60 | PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
61 | if (info != null) {
62 | ApplicationInfo appInfo = info.applicationInfo;
63 | return appInfo.packageName;
64 | }
65 | return null;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/utils/InstallApk.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.utils;
2 |
3 | import android.app.PendingIntent;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.Uri;
7 | import android.os.Build;
8 | import android.support.v4.content.FileProvider;
9 |
10 | import java.io.File;
11 |
12 | import cn.hugeterry.updatefun.R;
13 |
14 | /**
15 | * Created by hugeterry(http://hugeterry.cn)
16 | */
17 | public class InstallApk {
18 | public static void startInstall(Context context, File apkfile) {
19 | if (!apkfile.exists()) {
20 | return;
21 | }
22 | Intent intent = new Intent(Intent.ACTION_VIEW);
23 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
24 | intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
25 | Uri contentUri = FileProvider.getUriForFile(context, context.getString(R.string.updatefun_provider_file_authorities), apkfile);
26 | intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
27 | } else {
28 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
29 | intent.setDataAndType(Uri.parse("file://" + apkfile.toString()),
30 | "application/vnd.android.package-archive");
31 | }
32 | context.startActivity(intent);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/utils/StorageUtils.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.utils;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageManager;
5 | import android.os.Environment;
6 | import android.util.Log;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 |
11 | import static android.os.Environment.MEDIA_MOUNTED;
12 |
13 | public class StorageUtils {
14 |
15 | private static final String EXTERNAL_STORAGE_PERMISSION = "android.permission.WRITE_EXTERNAL_STORAGE";
16 |
17 | private StorageUtils() {
18 | }
19 |
20 | /**
21 | * Returns application cache directory. Cache directory will be created on SD card
22 | * ("/Android/data/[app_package_name]/cache") if card is mounted and app has appropriate permission. Else -
23 | * Android defines cache directory on device's file system.
24 | *
25 | * @param context Application context
26 | * @return Cache {@link File directory}
27 | */
28 | public static File getCacheDirectory(Context context) {
29 | File appCacheDir = null;
30 | if (MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
31 | appCacheDir = getExternalCacheDir(context);
32 | }
33 | if (appCacheDir == null) {
34 | appCacheDir = context.getCacheDir();
35 | }
36 | if (appCacheDir == null) {
37 | Log.w("UpdateFun TAG", "Can't define system cache directory! The app should be re-installed.");
38 | }
39 | return appCacheDir;
40 | }
41 |
42 |
43 | private static File getExternalCacheDir(Context context) {
44 | File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
45 | File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
46 | if (!appCacheDir.exists()) {
47 | if (!appCacheDir.mkdirs()) {
48 | Log.w("UpdateFun TAG", "Unable to create external cache directory");
49 | return null;
50 | }
51 | try {
52 | new File(appCacheDir, ".nomedia").createNewFile();
53 | } catch (IOException e) {
54 | Log.i("UpdateFun TAG", "Can't create \".nomedia\" file in application external cache directory");
55 | }
56 | }
57 | return appCacheDir;
58 | }
59 |
60 | private static boolean hasExternalStoragePermission(Context context) {
61 | int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
62 | return perm == PackageManager.PERMISSION_GRANTED;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/view/DownLoadDialog.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.view;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.view.View.OnClickListener;
7 | import android.widget.ImageView;
8 | import android.widget.ProgressBar;
9 | import android.widget.TextView;
10 |
11 | import cn.hugeterry.updatefun.config.DownloadKey;
12 | import cn.hugeterry.updatefun.R;
13 | import cn.hugeterry.updatefun.module.Download;
14 |
15 | /**
16 | * Created by hugeterry(http://hugeterry.cn)
17 | */
18 |
19 | public class DownLoadDialog extends Activity {
20 | private ImageView close;
21 | public ProgressBar progressBar;
22 | public TextView textView;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.download_dialog);
28 |
29 | close = (ImageView) findViewById(R.id.downloaddialog_close);
30 | progressBar = (ProgressBar) findViewById(R.id.downloaddialog_progress);
31 | textView = (TextView) findViewById(R.id.downloaddialog_count);
32 |
33 | if (DownloadKey.interceptFlag) DownloadKey.interceptFlag = false;
34 | new Download(this).start();
35 |
36 | close.setOnClickListener(new OnClickListener() {
37 |
38 | @Override
39 | public void onClick(View arg0) {
40 | DownloadKey.TOShowDownloadView = 1;
41 | DownloadKey.interceptFlag = true;
42 | if (DownloadKey.ISManual) {
43 | DownloadKey.LoadManual = false;
44 | }
45 | finish();
46 | }
47 | });
48 |
49 | }
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/updatefun/src/main/java/cn/hugeterry/updatefun/view/UpdateDialog.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun.view;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.view.View.OnClickListener;
7 | import android.widget.TextView;
8 |
9 | import cn.hugeterry.updatefun.config.DownloadKey;
10 | import cn.hugeterry.updatefun.R;
11 |
12 | /**
13 | * Created by hugeterry(http://hugeterry.cn)
14 | */
15 | public class UpdateDialog extends Activity {
16 |
17 | private TextView yes, no;
18 | private TextView tv_version, tv_changelog;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.update_dialog);
24 |
25 | yes = (TextView) findViewById(R.id.updatedialog_yes);
26 | no = (TextView) findViewById(R.id.updatedialog_no);
27 | tv_version = (TextView) findViewById(R.id.title);
28 | tv_changelog = (TextView) findViewById(R.id.updatedialog_text_changelog);
29 |
30 | tv_version.setText("发现新版本: V" + DownloadKey.version);
31 | tv_changelog.setText("更新日志:\n" + DownloadKey.changeLog);
32 |
33 | yes.setOnClickListener(new OnClickListener() {
34 |
35 | @Override
36 | public void onClick(View arg0) {
37 | DownloadKey.TOShowDownloadView = 2;
38 | finish();
39 | }
40 | });
41 |
42 | no.setOnClickListener(new OnClickListener() {
43 |
44 | @Override
45 | public void onClick(View arg0) {
46 | DownloadKey.TOShowDownloadView = 1;
47 | if (DownloadKey.ISManual) {
48 | DownloadKey.LoadManual = false;
49 | }
50 | finish();
51 | }
52 | });
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/drawable/bg_button_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/drawable/bg_button_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/drawable/bg_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/drawable/button_update.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/drawable/ic_close_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/drawable/material_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 |
9 |
10 |
11 |
12 | -
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/layout/download_dialog.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
14 |
15 |
21 |
22 |
28 |
29 |
37 |
38 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/layout/download_notification_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
21 |
22 |
26 |
27 |
33 |
34 |
39 |
40 |
47 |
48 |
58 |
59 |
60 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/layout/update_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
18 |
19 |
25 |
26 |
36 |
37 |
44 |
45 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
85 |
86 |
92 |
93 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #5474C9
4 | #556BA7
5 | #F3456C
6 |
7 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UpdateFun
3 | cn.hugeterry.updatefun.fileprovider
4 |
5 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
27 |
28 |
--------------------------------------------------------------------------------
/updatefun/src/main/res/xml/file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
12 |
--------------------------------------------------------------------------------
/updatefun/src/test/java/cn/hugeterry/updatefun/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.hugeterry.updatefun;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------