├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── jkyeo
│ │ └── splashviewsample
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── jkyeo
│ │ │ └── splashviewsample
│ │ │ └── SampleActivity.java
│ └── res
│ │ ├── drawable
│ │ └── default_img.png
│ │ ├── layout
│ │ └── activity_sample.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
│ └── com
│ └── jkyeo
│ └── splashviewsample
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── splashview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── jkyeo
│ └── splashview
│ └── ApplicationTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── jkyeo
│ │ └── splashview
│ │ └── SplashView.java
└── res
│ └── values
│ └── strings.xml
└── test
└── java
└── com
└── jkyeo
└── splashview
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/android,java,intellij
3 |
4 | ### Android ###
5 | # Built application files
6 | *.apk
7 | *.ap_
8 |
9 | # Files for the ART/Dalvik VM
10 | *.dex
11 |
12 | # Java class files
13 | *.class
14 |
15 | # Generated files
16 | bin/
17 | gen/
18 | out/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # Intellij
40 | *.iml
41 | .idea/workspace.xml
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | ### Android Patch ###
47 | gen-external-apklibs
48 |
49 |
50 | ### Intellij ###
51 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
52 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
53 |
54 | # User-specific stuff:
55 | .idea/workspace.xml
56 | .idea/tasks.xml
57 | .idea/dictionaries
58 | .idea/vcs.xml
59 | .idea/jsLibraryMappings.xml
60 |
61 | # Sensitive or high-churn files:
62 | .idea/dataSources.ids
63 | .idea/dataSources.xml
64 | .idea/dataSources.local.xml
65 | .idea/sqlDataSources.xml
66 | .idea/dynamic.xml
67 | .idea/uiDesigner.xml
68 |
69 | # Gradle:
70 | .idea/gradle.xml
71 | .idea/libraries
72 |
73 | # Mongo Explorer plugin:
74 | .idea/mongoSettings.xml
75 |
76 | ## File-based project format:
77 | *.iws
78 |
79 | ## Plugin-specific files:
80 |
81 | # IntelliJ
82 | /out/
83 |
84 | # mpeltonen/sbt-idea plugin
85 | .idea_modules/
86 |
87 | # JIRA plugin
88 | atlassian-ide-plugin.xml
89 |
90 | # Crashlytics plugin (for Android Studio and IntelliJ)
91 | com_crashlytics_export_strings.xml
92 | crashlytics.properties
93 | crashlytics-build.properties
94 | fabric.properties
95 |
96 | ### Intellij Patch ###
97 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
98 |
99 | # *.iml
100 | # modules.xml
101 | # .idea/misc.xml
102 | # *.ipr
103 |
104 |
105 | ### Java ###
106 | *.class
107 |
108 | # Mobile Tools for Java (J2ME)
109 | .mtj.tmp/
110 |
111 | # Package Files #
112 | *.jar
113 | *.war
114 | *.ear
115 |
116 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
117 | hs_err_pid*
118 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | SplashViewSample
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
19 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-SplashView
2 |
3 | 闪屏页或者广告页 (SplashView) 在众多 App 里是比较常见的。一般来说 SplashView 有以下职责:
4 |
5 | - 在合适的时机显示 SplashView - 可控性
6 | - 下载、缓存、更新图片
7 | - 回调响应图片点击事件
8 | - 倒计时 Dismiss View,主动跳过 Dissmiss View
9 | - 本地没有缓存时,显示默认图片或者不显示 SplashView
10 |
11 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #666666
4 | #555555
5 | #DDDEDF
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SplashViewSample
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jkyeo/splashviewsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jkyeo.splashviewsample;
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 | }
--------------------------------------------------------------------------------
/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:2.1.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
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.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.10-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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':splashview'
2 |
--------------------------------------------------------------------------------
/splashview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/splashview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.4.0'
25 | }
26 |
--------------------------------------------------------------------------------
/splashview/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/jkyeo/Documents/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 |
--------------------------------------------------------------------------------
/splashview/src/androidTest/java/com/jkyeo/splashview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jkyeo.splashview;
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 | }
--------------------------------------------------------------------------------
/splashview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/splashview/src/main/java/com/jkyeo/splashview/SplashView.java:
--------------------------------------------------------------------------------
1 | package com.jkyeo.splashview;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.TargetApi;
7 | import android.app.Activity;
8 | import android.content.Context;
9 | import android.content.SharedPreferences;
10 | import android.graphics.Bitmap;
11 | import android.graphics.BitmapFactory;
12 | import android.graphics.Color;
13 | import android.graphics.drawable.GradientDrawable;
14 | import android.graphics.drawable.shapes.Shape;
15 | import android.os.Build;
16 | import android.os.Handler;
17 | import android.support.annotation.NonNull;
18 | import android.support.annotation.Nullable;
19 | import android.support.v7.app.ActionBar;
20 | import android.support.v7.app.AppCompatActivity;
21 | import android.text.TextUtils;
22 | import android.util.AttributeSet;
23 | import android.util.TypedValue;
24 | import android.view.Gravity;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.view.WindowManager;
28 | import android.widget.FrameLayout;
29 | import android.widget.ImageView;
30 | import android.widget.RelativeLayout;
31 | import android.widget.TextView;
32 |
33 | import java.io.BufferedOutputStream;
34 | import java.io.File;
35 | import java.io.FileOutputStream;
36 | import java.io.IOException;
37 | import java.io.InputStream;
38 | import java.net.HttpURLConnection;
39 | import java.net.MalformedURLException;
40 | import java.net.URL;
41 |
42 | /**
43 | * Created by jkyeo on 16/7/7.
44 | */
45 | public class SplashView extends FrameLayout {
46 |
47 | ImageView splashImageView;
48 | TextView skipButton;
49 |
50 | private static final String IMG_URL = "splash_img_url";
51 | private static final String ACT_URL = "splash_act_url";
52 | private static String IMG_PATH = null;
53 | private static final String SP_NAME = "splash";
54 | private static final int skipButtonSizeInDip = 36;
55 | private static final int skipButtonMarginInDip = 16;
56 | private Integer duration = 6;
57 | private static final int delayTime = 1000; // 每隔1000 毫秒执行一次
58 |
59 | private String imgUrl = null;
60 | private String actUrl = null;
61 |
62 | private boolean isActionBarShowing = true;
63 |
64 | private Activity mActivity = null;
65 |
66 | private OnSplashViewActionListener mOnSplashViewActionListener = null;
67 |
68 | private Handler handler = new Handler();
69 | private Runnable timerRunnable = new Runnable() {
70 | @Override
71 | public void run() {
72 | if (0 == duration) {
73 | dismissSplashView(false);
74 | return;
75 | } else {
76 | setDuration(--duration);
77 | }
78 | handler.postDelayed(timerRunnable, delayTime);
79 | }
80 | };
81 |
82 | private void setImage(Bitmap image) {
83 | splashImageView.setImageBitmap(image);
84 | }
85 |
86 | public SplashView(Activity context) {
87 | super(context);
88 | mActivity = context;
89 | initComponents();
90 | }
91 |
92 | public SplashView(Activity context, AttributeSet attrs) {
93 | super(context, attrs);
94 | mActivity = context;
95 | initComponents();
96 | }
97 |
98 | public SplashView(Activity context, AttributeSet attrs, int defStyleAttr) {
99 | super(context, attrs, defStyleAttr);
100 | mActivity = context;
101 | initComponents();
102 | }
103 |
104 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
105 | public SplashView(Activity context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
106 | super(context, attrs, defStyleAttr, defStyleRes);
107 | mActivity = context;
108 | initComponents();
109 | }
110 |
111 | private GradientDrawable splashSkipButtonBg = new GradientDrawable();
112 |
113 | void initComponents() {
114 | splashSkipButtonBg.setShape(GradientDrawable.OVAL);
115 | splashSkipButtonBg.setColor(Color.parseColor("#66333333"));
116 |
117 | splashImageView = new ImageView(mActivity);
118 | splashImageView.setScaleType(ImageView.ScaleType.FIT_XY);
119 | splashImageView.setBackgroundColor(mActivity.getResources().getColor(android.R.color.white));
120 | LayoutParams imageViewLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
121 | this.addView(splashImageView, imageViewLayoutParams);
122 | splashImageView.setClickable(true);
123 |
124 | skipButton = new TextView(mActivity);
125 | int skipButtonSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, skipButtonSizeInDip, mActivity.getResources().getDisplayMetrics());
126 | LayoutParams skipButtonLayoutParams = new LayoutParams(skipButtonSize, skipButtonSize);
127 | skipButtonLayoutParams.gravity = Gravity.TOP|Gravity.RIGHT;
128 | int skipButtonMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, skipButtonMarginInDip, mActivity.getResources().getDisplayMetrics());
129 | skipButtonLayoutParams.setMargins(0, skipButtonMargin, skipButtonMargin, 0);
130 | skipButton.setGravity(Gravity.CENTER);
131 | skipButton.setTextColor(mActivity.getResources().getColor(android.R.color.white));
132 | skipButton.setBackgroundDrawable(splashSkipButtonBg);
133 | skipButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
134 | this.addView(skipButton, skipButtonLayoutParams);
135 |
136 | skipButton.setOnClickListener(new OnClickListener() {
137 | @Override
138 | public void onClick(View v) {
139 | dismissSplashView(true);
140 | }
141 | });
142 |
143 | setDuration(duration);
144 | handler.postDelayed(timerRunnable, delayTime);
145 | }
146 |
147 | private void setImgUrl(String imgUrl) {
148 | this.imgUrl = imgUrl;
149 | }
150 |
151 | private void setActUrl(String actUrl) {
152 | this.actUrl = actUrl;
153 | }
154 |
155 | private void setDuration(Integer duration) {
156 | this.duration = duration;
157 | skipButton.setText(String.format("跳过\n%d s", duration));
158 | }
159 |
160 | private void setOnSplashImageClickListener(@Nullable final OnSplashViewActionListener listener) {
161 | if (null == listener) return;
162 | mOnSplashViewActionListener = listener;
163 | splashImageView.setOnClickListener(new OnClickListener() {
164 | @Override
165 | public void onClick(View v) {
166 | listener.onSplashImageClick(actUrl);
167 | }
168 | });
169 | }
170 |
171 | /**
172 | * static method, show splashView on above of the activity
173 | * you should called after setContentView()
174 | * @param activity activity instance
175 | * @param durationTime time to countDown
176 | * @param defaultBitmapRes if there's no cached bitmap, show this default bitmap;
177 | * if null == defaultBitmapRes, then will not show the splashView
178 | * @param listener splash view listener contains onImageClick and onDismiss
179 | */
180 | public static void showSplashView(@NonNull Activity activity,
181 | @Nullable Integer durationTime,
182 | @Nullable Integer defaultBitmapRes,
183 | @Nullable OnSplashViewActionListener listener) {
184 |
185 | ViewGroup contentView = (ViewGroup) activity.getWindow().getDecorView().findViewById(android.R.id.content);
186 | if (null == contentView || 0 == contentView.getChildCount()) {
187 | throw new IllegalStateException("You should call showSplashView() after setContentView() in Activity instance");
188 | }
189 | IMG_PATH = activity.getFilesDir().getAbsolutePath().toString() + "/splash_img.jpg";
190 | SplashView splashView = new SplashView(activity);
191 | RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
192 | splashView.setOnSplashImageClickListener(listener);
193 | if (null != durationTime) splashView.setDuration(durationTime);
194 | Bitmap bitmapToShow = null;
195 |
196 | if (isExistsLocalSplashData(activity)) {
197 | bitmapToShow = BitmapFactory.decodeFile(IMG_PATH);
198 | SharedPreferences sp = activity.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
199 | splashView.setImgUrl(sp.getString(IMG_URL, null));
200 | splashView.setActUrl(sp.getString(ACT_URL, null));
201 | } else if (null != defaultBitmapRes) {
202 | bitmapToShow = BitmapFactory.decodeResource(activity.getResources(), defaultBitmapRes);
203 | }
204 |
205 | if (null == bitmapToShow) return;
206 | splashView.setImage(bitmapToShow);
207 | activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
208 | if (activity instanceof AppCompatActivity) {
209 | ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
210 | if (null != supportActionBar) {
211 | supportActionBar.setShowHideAnimationEnabled(false);
212 | splashView.isActionBarShowing = supportActionBar.isShowing();
213 | supportActionBar.hide();
214 | }
215 | } else if (activity instanceof Activity) {
216 | android.app.ActionBar actionBar = activity.getActionBar();
217 | if (null != actionBar) {
218 | splashView.isActionBarShowing = actionBar.isShowing();
219 | actionBar.hide();
220 | }
221 | }
222 | contentView.addView(splashView, param);
223 | }
224 |
225 | /**
226 | * simple way to show splash view, set all non-able param as non
227 | * @param activity
228 | */
229 | public static void simpleShowSplashView(@NonNull Activity activity) {
230 | showSplashView(activity, null, null, null);
231 | }
232 |
233 | private void dismissSplashView(boolean initiativeDismiss) {
234 | if (null != mOnSplashViewActionListener) mOnSplashViewActionListener.onSplashViewDismiss(initiativeDismiss);
235 |
236 |
237 | handler.removeCallbacks(timerRunnable);
238 | final ViewGroup parent = (ViewGroup) this.getParent();
239 | if (null != parent) {
240 | ObjectAnimator animator = ObjectAnimator.ofFloat(SplashView.this, "scale", 0.0f, 0.5f).setDuration(600);
241 | animator.start();
242 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
243 | @Override
244 | public void onAnimationUpdate(ValueAnimator animation) {
245 | float cVal = (Float) animation.getAnimatedValue();
246 | SplashView.this.setAlpha(1.0f - 2.0f * cVal);
247 | SplashView.this.setScaleX(1.0f + cVal);
248 | SplashView.this.setScaleY(1.0f + cVal);
249 | }
250 | });
251 | animator.addListener(new Animator.AnimatorListener() {
252 | @Override
253 | public void onAnimationStart(Animator animation) {
254 |
255 | }
256 |
257 | @Override
258 | public void onAnimationEnd(Animator animation) {
259 | parent.removeView(SplashView.this);
260 | showSystemUi();
261 | }
262 |
263 | @Override
264 | public void onAnimationCancel(Animator animation) {
265 | parent.removeView(SplashView.this);
266 | showSystemUi();
267 | }
268 |
269 | @Override
270 | public void onAnimationRepeat(Animator animation) {
271 |
272 | }
273 | });
274 | }
275 | }
276 |
277 | private void showSystemUi() {
278 | mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
279 | if (mActivity instanceof AppCompatActivity) {
280 | ActionBar supportActionBar = ((AppCompatActivity) mActivity).getSupportActionBar();
281 | if (null != supportActionBar) {
282 | if (isActionBarShowing) supportActionBar.show();
283 | }
284 | } else if (mActivity instanceof Activity) {
285 | android.app.ActionBar actionBar = mActivity.getActionBar();
286 | if (null != actionBar) {
287 | if (isActionBarShowing) actionBar.show();
288 | }
289 | }
290 | }
291 |
292 | private static boolean isExistsLocalSplashData(Activity activity) {
293 | SharedPreferences sp = activity.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
294 | String imgUrl = sp.getString(IMG_URL, null);
295 | return !TextUtils.isEmpty(imgUrl) && isFileExist(IMG_PATH);
296 | }
297 |
298 | /**
299 | * static method, update splash view data
300 | * @param imgUrl - url of image which you want to set as splash image
301 | * @param actionUrl - related action url, such as webView etc.
302 | */
303 | public static void updateSplashData(@NonNull Activity activity, @NonNull String imgUrl, @Nullable String actionUrl) {
304 | IMG_PATH = activity.getFilesDir().getAbsolutePath().toString() + "/splash_img.jpg";
305 |
306 | SharedPreferences.Editor editor = activity.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE).edit();
307 | editor.putString(IMG_URL, imgUrl);
308 | editor.putString(ACT_URL, actionUrl);
309 | editor.apply();
310 |
311 | getAndSaveNetWorkBitmap(imgUrl);
312 | }
313 |
314 | public interface OnSplashViewActionListener {
315 | void onSplashImageClick(String actionUrl);
316 | void onSplashViewDismiss(boolean initiativeDismiss);
317 | }
318 |
319 | private static void getAndSaveNetWorkBitmap(final String urlString) {
320 | Runnable getAndSaveImageRunnable = new Runnable() {
321 | @Override
322 | public void run() {
323 | URL imgUrl = null;
324 | Bitmap bitmap = null;
325 | try {
326 | imgUrl = new URL(urlString);
327 | HttpURLConnection urlConn = (HttpURLConnection) imgUrl.openConnection();
328 | urlConn.setDoInput(true);
329 | urlConn.connect();
330 | InputStream is = urlConn.getInputStream();
331 | bitmap = BitmapFactory.decodeStream(is);
332 | is.close();
333 | saveBitmapFile(bitmap, IMG_PATH);
334 | } catch (MalformedURLException e) {
335 | e.printStackTrace();
336 | } catch (IOException e) {
337 | e.printStackTrace();
338 | }
339 | }
340 | };
341 | new Thread(getAndSaveImageRunnable).start();
342 | }
343 |
344 | private static void saveBitmapFile(Bitmap bm, String filePath) throws IOException {
345 | File myCaptureFile = new File(filePath);
346 | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
347 | bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
348 | bos.flush();
349 | bos.close();
350 | }
351 |
352 | public static boolean isFileExist(String filePath) {
353 | if(TextUtils.isEmpty(filePath)) {
354 | return false;
355 | } else {
356 | File file = new File(filePath);
357 | return file.exists() && file.isFile();
358 | }
359 | }
360 | }
361 |
--------------------------------------------------------------------------------
/splashview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SplashView
3 |
4 |
--------------------------------------------------------------------------------
/splashview/src/test/java/com/jkyeo/splashview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jkyeo.splashview;
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 | }
--------------------------------------------------------------------------------