├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── update_bg.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── update_progress_layout.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── zhh
│ │ │ └── appupdateprogress
│ │ │ ├── view
│ │ │ ├── AppUpdateProgressDialog.java
│ │ │ └── NumberProgressBar.java
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zhh
│ │ └── appupdateprogress
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AppUpdateProgress
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seastoneard/AppUpdateProgress/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seastoneard/AppUpdateProgress/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/update_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seastoneard/AppUpdateProgress/HEAD/app/src/main/res/mipmap-xxhdpi/update_bg.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seastoneard/AppUpdateProgress/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #00AAEE
7 | #66000000
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 | defaultConfig {
7 | applicationId "com.zhh.appupdateprogress"
8 | minSdkVersion 16
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:23.+'
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zhh/appupdateprogress/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zhh.appupdateprogress;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zhh.appupdateprogress", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/update_progress_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
17 |
18 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
21 |
22 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhh/appupdateprogress/view/AppUpdateProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.zhh.appupdateprogress.view;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 |
6 | import com.zhh.appupdateprogress.R;
7 |
8 |
9 | /**
10 | * Created by zhh on 2017/4/10.
11 | */
12 |
13 | public class AppUpdateProgressDialog extends Dialog {
14 |
15 | private NumberProgressBar numberProgressBar;
16 |
17 | public AppUpdateProgressDialog(Context context) {
18 | super(context, R.style.Custom_Progress);
19 | initLayout();
20 | }
21 |
22 | public AppUpdateProgressDialog(Context context, int theme) {
23 | super(context, R.style.Custom_Progress);
24 | initLayout();
25 | }
26 |
27 | private void initLayout() {
28 | this.setContentView(R.layout.update_progress_layout);
29 | getWindow().setBackgroundDrawableResource(android.R.color.transparent);
30 | numberProgressBar = (NumberProgressBar) findViewById(R.id.number_progress);
31 | this.setCanceledOnTouchOutside(false);//点击dialog背景部分不消失
32 | // this.setCancelable(false);//dialog出现时,点击back键不消失
33 | }
34 |
35 | public void setProgress(int mProgress) {
36 | numberProgressBar.setProgress(mProgress);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhh/appupdateprogress/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhh.appupdateprogress;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.KeyEvent;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | import com.zhh.appupdateprogress.view.AppUpdateProgressDialog;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | private AppUpdateProgressDialog dialog=null;
17 | private int mProgress = 0;//下载进度
18 | private int mMaxProgress;//百分比
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | mMaxProgress = 100;
25 | findViewById(R.id.btn_update).setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View v) {
28 | mProgress=0;
29 | showDialog();
30 | }
31 | });
32 | }
33 |
34 | private void showDialog() {
35 | dialog = new AppUpdateProgressDialog(this);
36 | //正在下载时,不可关闭dialog
37 | dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
38 | @Override
39 | public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
40 | if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
41 | Toast.makeText(MainActivity.this, "正在下载请稍后", Toast.LENGTH_SHORT).show();
42 | return true;
43 | } else {
44 | return false;
45 | }
46 | }
47 | });
48 | dialog.show();
49 | new Thread(new Runnable() {
50 | @Override
51 | public void run() {
52 | while (mProgress < mMaxProgress) {
53 | try {
54 | mProgress++;
55 | Message msg =myHandler.obtainMessage();
56 | msg.what = 100;
57 | msg.obj = mProgress;
58 | myHandler.sendMessage(msg);
59 | Thread.sleep(200);
60 | } catch (InterruptedException e) {
61 | e.printStackTrace();
62 | }
63 | }
64 | }
65 | }).start();
66 | }
67 |
68 |
69 | Handler myHandler = new Handler() {
70 | public void handleMessage(Message msg) {
71 | switch (msg.what) {
72 | case 100:
73 | int progress = (int) msg.obj;
74 | dialog.setProgress(progress);
75 | if (100 == progress) {
76 | dialog.dismiss();
77 | Toast.makeText(MainActivity.this,"下载完成,跳转到安装界面",Toast.LENGTH_SHORT).show();
78 | }
79 | break;
80 | }
81 | }
82 | };
83 | }
84 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhh/appupdateprogress/view/NumberProgressBar.java:
--------------------------------------------------------------------------------
1 |
2 | package com.zhh.appupdateprogress.view;
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.graphics.RectF;
10 | import android.graphics.Typeface;
11 | import android.util.AttributeSet;
12 | import android.util.TypedValue;
13 | import android.view.View;
14 |
15 | import com.zhh.appupdateprogress.R;
16 |
17 |
18 | public class NumberProgressBar extends View {
19 |
20 |
21 | /**
22 | * 右侧未完成进度条的颜色
23 | */
24 | private int paintStartColor = 0xffe5e5e5;
25 |
26 | /**
27 | * Contxt
28 | */
29 | private Context context;
30 |
31 | /**
32 | * 主线程传过来进程 0 - 100
33 | */
34 | private int progress;
35 |
36 | /**
37 | * 得到自定义视图的宽度
38 | */
39 | private int viewWidth;
40 |
41 |
42 | private RectF pieOval;
43 |
44 | private RectF pieOvalIn;
45 |
46 | /**
47 | * 得到自定义视图的Y轴中心点
48 | */
49 | private int viewCenterY;
50 |
51 | /**
52 | * 已完成的画笔
53 | */
54 | private Paint paintInit = new Paint();
55 |
56 |
57 | /**
58 | * 未完成进度条画笔的属性
59 | */
60 | private Paint paintStart = new Paint();
61 |
62 | /**
63 | * 大圆的画笔
64 | */
65 | private Paint paintEndBig = new Paint();
66 |
67 | /**
68 | * 小圆的画笔
69 | */
70 | private Paint paintSmall = new Paint();
71 |
72 |
73 | /**
74 | * 画中间的百分比文字的画笔
75 | */
76 | private Paint paintText = new Paint();
77 |
78 | /**
79 | * 要画的文字的宽度
80 | */
81 | private int textWidth;
82 |
83 | /**
84 | * 画文字时底部的坐标
85 | */
86 | private float textBottomY;
87 |
88 | private int smallR;//小圆的半径
89 | private int bigR;//大圆半径
90 | private float radius;
91 | private int jR;//气泡矩形
92 |
93 | /**
94 | * 文字总共移动的长度(即从0%到100%文字左侧移动的长度)
95 | */
96 | // private int totalMovedLength;
97 | public NumberProgressBar(Context context, AttributeSet attrs) {
98 | super(context, attrs);
99 | this.context = context;
100 | // 构造器中初始化数据
101 | smallR = dip2px(context, 4);//小圆半径
102 | bigR = dip2px(context, 8);//大圆半径
103 | radius = dip2px(context, 10) / 2;//进度条高度
104 | jR = dip2px(context, 6);//矩形
105 |
106 | initData();
107 | }
108 |
109 | /**
110 | * 初始化数据
111 | */
112 | private void initData() {
113 |
114 | // 未完成进度条画笔的属性
115 | paintStart.setColor(paintStartColor);
116 | paintStart.setStrokeWidth(dip2px(context, 1));
117 | paintStart.setDither(true);
118 | paintStart.setAntiAlias(true);
119 | paintStart.setStyle(Paint.Style.FILL);
120 |
121 | // 已完成进度条画笔的属性
122 | paintInit.setColor(context.getResources().getColor(R.color.blue));
123 | paintInit.setStrokeWidth(dip2px(context, 1));
124 | paintInit.setAntiAlias(true);
125 | paintInit.setDither(true);
126 | paintInit.setStyle(Paint.Style.FILL);
127 |
128 |
129 | // 小圆画笔
130 | paintSmall.setColor(Color.WHITE);
131 | paintSmall.setAntiAlias(true);
132 | paintSmall.setStyle(Paint.Style.FILL);
133 |
134 | // 大圆画笔
135 | paintEndBig.setColor(context.getResources().getColor(R.color.blue));
136 | paintEndBig.setAntiAlias(true);
137 | paintEndBig.setStyle(Paint.Style.FILL);
138 |
139 |
140 | // 百分比文字画笔的属性
141 | int paintTextSizePx = sp2px(context, 11); //设置百分比文字的尺寸
142 | paintText.setColor(context.getResources().getColor(R.color.blue));
143 | paintText.setTextSize(paintTextSizePx);
144 | paintText.setAntiAlias(true);
145 | paintText.setTypeface(Typeface.DEFAULT_BOLD);
146 |
147 | }
148 |
149 | @Override
150 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
152 | }
153 |
154 |
155 | @Override
156 | protected void onDraw(Canvas canvas) {
157 | super.onDraw(canvas);
158 |
159 | //得到float型进度
160 | float progressFloat = progress / 100.0f;
161 | int viewHeight = getMeasuredHeight();//得到控件的高度
162 |
163 | viewWidth = getMeasuredWidth() - 4 * jR;
164 |
165 | viewCenterY = viewHeight - bigR;
166 |
167 | float currentMovedLen = viewWidth * progressFloat + 2 * jR;
168 |
169 | String str = progress + "%";
170 |
171 | Rect bounds = new Rect();
172 | paintText.getTextBounds(str, 0, str.length(), bounds);
173 | textWidth = bounds.width();
174 | textBottomY = bounds.height();
175 | /**
176 | * 1:绘画的文本
177 | * 2.距离x的位移
178 | * 3.距离Y的位移
179 | * 4.画笔对象
180 | */
181 | canvas.drawText(str, currentMovedLen - textWidth / 2,
182 | viewCenterY - smallR / 2 - bigR / 2 - 2 * jR + textBottomY / 2,
183 | paintText);//文字
184 |
185 |
186 | //圆角矩形初始的
187 | canvas.drawRoundRect(new RectF(2 * jR, viewCenterY - radius, currentMovedLen,
188 | viewCenterY + radius),
189 | radius, radius, paintInit);
190 |
191 | //圆角矩形--进行中
192 | canvas.drawRoundRect(new RectF(currentMovedLen, viewCenterY - radius, viewWidth + 2 * jR,
193 | viewCenterY + radius), radius, radius, paintStart);
194 |
195 | pieOval = new RectF(currentMovedLen - bigR, viewCenterY - bigR, currentMovedLen + bigR, viewCenterY + bigR);
196 |
197 | pieOvalIn = new RectF(currentMovedLen - smallR, viewCenterY - smallR, currentMovedLen + smallR, viewCenterY + smallR);
198 |
199 | //大圆
200 | canvas.drawArc(pieOval, 0, 360, true, paintEndBig);
201 |
202 | //小圆
203 | canvas.drawArc(pieOvalIn, 0, 360, true, paintSmall);
204 | }
205 |
206 | /**
207 | * @param progress 外部传进来的当前进度
208 | */
209 | public void setProgress(int progress) {
210 | this.progress = progress;
211 | invalidate();
212 | }
213 |
214 | public static int dip2px(Context ctx, float dp) {
215 | float density = ctx.getResources().getDisplayMetrics().density;
216 | int px = (int) (dp * density + 0.5f);
217 | return px;
218 | }
219 |
220 | public static int sp2px(Context context, float spValue) {
221 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, context.getResources().getDisplayMetrics());
222 | }
223 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AppUpdateProgress
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
前言:现在一般的Android软件都是需要不断更新的,当你打开某个app的时候,如果有新的版本,它会提示你有新版本需要更新。当有更新时,会弹出一个提示框,点击下载,则在通知来创建一个数字进度条进行下载,下载成功后才到安装界面。
10 |
11 |
12 |
效果:
13 |
14 |
15 | 
16 |
17 |
18 |
19 |
开发环境:AndroidStudio2.2.1+gradle-2.14.1
20 |
21 |
22 |
23 |
涉及知识:
24 |
1.Handler机制
25 |
2.自定义控件+Canvas绘画
26 |
3.自定义dialog
27 |
28 |
29 |
部分代码:
30 |
31 |
32 |
33 |
public class NumberProgressBar extends View {
34 |
35 |
36 | /**
37 | * 右侧未完成进度条的颜色
38 | */
39 | private int paintStartColor = 0xffe5e5e5;
40 |
41 | /**
42 | * Contxt
43 | */
44 | private Context context;
45 |
46 | /**
47 | * 主线程传过来进程 0 - 100
48 | */
49 | private int progress;
50 |
51 | /**
52 | * 得到自定义视图的宽度
53 | */
54 | private int viewWidth;
55 |
56 |
57 | private RectF pieOval;
58 |
59 | private RectF pieOvalIn;
60 |
61 | /**
62 | * 得到自定义视图的Y轴中心点
63 | */
64 | private int viewCenterY;
65 |
66 | /**
67 | * 已完成的画笔
68 | */
69 | private Paint paintInit = new Paint();
70 |
71 |
72 | /**
73 | * 未完成进度条画笔的属性
74 | */
75 | private Paint paintStart = new Paint();
76 |
77 | /**
78 | * 大圆的画笔
79 | */
80 | private Paint paintEndBig = new Paint();
81 |
82 | /**
83 | * 小圆的画笔
84 | */
85 | private Paint paintSmall = new Paint();
86 |
87 |
88 | /**
89 | * 画中间的百分比文字的画笔
90 | */
91 | private Paint paintText = new Paint();
92 |
93 | /**
94 | * 要画的文字的宽度
95 | */
96 | private int textWidth;
97 |
98 | /**
99 | * 画文字时底部的坐标
100 | */
101 | private float textBottomY;
102 |
103 | private int smallR;//小圆的半径
104 | private int bigR;//大圆半径
105 | private float radius;
106 | private int jR;//气泡矩形
107 |
108 | /**
109 | * 文字总共移动的长度(即从0%到100%文字左侧移动的长度)
110 | */
111 | // private int totalMovedLength;
112 | public NumberProgressBar(Context context, AttributeSet attrs) {
113 | super(context, attrs);
114 | this.context = context;
115 | // 构造器中初始化数据
116 | smallR = dip2px(context, 4);//小圆半径
117 | bigR = dip2px(context, 8);//大圆半径
118 | radius = dip2px(context, 10) / 2;//进度条高度
119 | jR = dip2px(context, 6);//矩形
120 |
121 | initData();
122 | }
123 |
124 | /**
125 | * 初始化数据
126 | */
127 | private void initData() {
128 |
129 | // 未完成进度条画笔的属性
130 | paintStart.setColor(paintStartColor);
131 | paintStart.setStrokeWidth(dip2px(context, 1));
132 | paintStart.setDither(true);
133 | paintStart.setAntiAlias(true);
134 | paintStart.setStyle(Paint.Style.FILL);
135 |
136 | // 已完成进度条画笔的属性
137 | paintInit.setColor(context.getResources().getColor(R.color.blue));
138 | paintInit.setStrokeWidth(dip2px(context, 1));
139 | paintInit.setAntiAlias(true);
140 | paintInit.setDither(true);
141 | paintInit.setStyle(Paint.Style.FILL);
142 |
143 |
144 | // 小圆画笔
145 | paintSmall.setColor(Color.WHITE);
146 | paintSmall.setAntiAlias(true);
147 | paintSmall.setStyle(Paint.Style.FILL);
148 |
149 | // 大圆画笔
150 | paintEndBig.setColor(context.getResources().getColor(R.color.blue));
151 | paintEndBig.setAntiAlias(true);
152 | paintEndBig.setStyle(Paint.Style.FILL);
153 |
154 |
155 | // 百分比文字画笔的属性
156 | int paintTextSizePx = sp2px(context, 11); //设置百分比文字的尺寸
157 | paintText.setColor(context.getResources().getColor(R.color.blue));
158 | paintText.setTextSize(paintTextSizePx);
159 | paintText.setAntiAlias(true);
160 | paintText.setTypeface(Typeface.DEFAULT_BOLD);
161 |
162 | }
163 |
164 | @Override
165 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
166 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
167 | }
168 |
169 |
170 | @Override
171 | protected void onDraw(Canvas canvas) {
172 | super.onDraw(canvas);
173 |
174 | //得到float型进度
175 | float progressFloat = progress / 100.0f;
176 | int viewHeight = getMeasuredHeight();//得到控件的高度
177 |
178 | viewWidth = getMeasuredWidth() - 4 * jR;
179 |
180 | viewCenterY = viewHeight - bigR;
181 |
182 | float currentMovedLen = viewWidth * progressFloat + 2 * jR;
183 |
184 | String str = progress + "%";
185 |
186 | Rect bounds = new Rect();
187 | paintText.getTextBounds(str, 0, str.length(), bounds);
188 | textWidth = bounds.width();
189 | textBottomY = bounds.height();
190 | /**
191 | * 1:绘画的文本
192 | * 2.距离x的位移
193 | * 3.距离Y的位移
194 | * 4.画笔对象
195 | */
196 | canvas.drawText(str, currentMovedLen - textWidth / 2,
197 | viewCenterY - smallR / 2 - bigR / 2 - 2 * jR + textBottomY / 2,
198 | paintText);//文字
199 |
200 |
201 | //圆角矩形初始的
202 | canvas.drawRoundRect(new RectF(2 * jR, viewCenterY - radius, currentMovedLen,
203 | viewCenterY + radius),
204 | radius, radius, paintInit);
205 |
206 | //圆角矩形--进行中
207 | canvas.drawRoundRect(new RectF(currentMovedLen, viewCenterY - radius, viewWidth + 2 * jR,
208 | viewCenterY + radius), radius, radius, paintStart);
209 |
210 | pieOval = new RectF(currentMovedLen - bigR, viewCenterY - bigR,
211 | currentMovedLen + bigR, viewCenterY + bigR);
212 |
213 | pieOvalIn = new RectF(currentMovedLen - smallR, viewCenterY - smallR,
214 | currentMovedLen + smallR, viewCenterY + smallR);
215 |
216 | //大圆
217 | canvas.drawArc(pieOval, 0, 360, true, paintEndBig);
218 |
219 | //小圆
220 | canvas.drawArc(pieOvalIn, 0, 360, true, paintSmall);
221 | }
222 |
223 | /**
224 | * @param progress 外部传进来的当前进度
225 | */
226 | public void setProgress(int progress) {
227 | this.progress = progress;
228 | invalidate();
229 | }
230 |
231 | public static int dip2px(Context ctx, float dp) {
232 | float density = ctx.getResources().getDisplayMetrics().density;
233 | int px = (int) (dp * density + 0.5f);
234 | return px;
235 | }
236 |
237 | public static int sp2px(Context context, float spValue) {
238 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
239 | spValue, context.getResources().getDisplayMetrics());
240 | }
241 | }
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
--------------------------------------------------------------------------------