├── .gitignore ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ethanhua │ │ └── skeleton │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── ethanhua │ │ │ └── skeleton │ │ │ ├── RecyclerViewSkeletonScreen.java │ │ │ ├── ShimmerViewHolder.java │ │ │ ├── Skeleton.java │ │ │ ├── SkeletonAdapter.java │ │ │ ├── SkeletonScreen.java │ │ │ ├── ViewReplacer.java │ │ │ └── ViewSkeletonScreen.java │ └── res │ │ ├── layout │ │ ├── layout_default_item_skeleton.xml │ │ └── layout_shimmer.xml │ │ └── values │ │ ├── strings.xml │ │ └── values.xml │ └── test │ └── java │ └── com │ └── ethanhua │ └── skeleton │ └── ExampleUnitTest.java ├── sample ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ethanhua │ │ └── skeleton │ │ └── sample │ │ ├── MainActivity.java │ │ ├── RecyclerViewActivity.java │ │ ├── StatusViewActivity.java │ │ ├── ViewActivity.java │ │ └── adapter │ │ ├── NewsAdapter.java │ │ ├── PersonAdapter.java │ │ ├── SimpleRcvViewHolder.java │ │ └── TopicAdapter.java │ └── res │ ├── drawable-xxhdpi │ ├── girl.jpg │ ├── google.jpg │ ├── ic_arrow_right.png │ ├── ic_tool_breakfast.png │ ├── ic_tool_circumference.png │ ├── ic_tool_dinner.png │ └── ic_tool_extra_meal.png │ ├── drawable │ ├── bg_grid_item.xml │ ├── img1.jpg │ └── img2.png │ ├── layout-v21 │ └── layout_progress.xml │ ├── layout │ ├── activity_main.xml │ ├── activity_recyclerview.xml │ ├── activity_status_view.xml │ ├── activity_view.xml │ ├── activity_view_skeleton.xml │ ├── item_news.xml │ ├── item_person.xml │ ├── item_skeleton_news.xml │ ├── item_skeleton_person.xml │ ├── item_title_more.xml │ ├── item_topic.xml │ ├── layout_empty_view.xml │ ├── layout_error.xml │ ├── layout_img_skeleton.xml │ └── layout_progress.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── screenshots ├── 01.gif ├── 02.gif ├── 03.gif ├── 04.gif └── qrcode.png └── settings.gradle /.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 | .idea 11 | /sample/build 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Skeleton 2 | [![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) 3 | The library provides an easy way to show skeleton loading view like Facebook and Alipay. 4 | It now uses a memory optimised version of shimmer animation so it is even faster and you can animate bigger layouts as well. 5 | 6 | # Preview 7 | 8 | 9 | ![img](screenshots/01.gif) 10 | ![img](screenshots/02.gif) 11 | ![img](screenshots/03.gif) 12 | ![img](screenshots/04.gif) 13 | 14 | # Demo Apk 15 | 16 | you can scan the qrcode for download demo apk 17 | 18 | ![](screenshots/qrcode.png) 19 | 20 | # Feature 21 | 22 | - Light 23 | - Noninvasive, you don't need to make changes to existing code. 24 | - Wide applicability,it is available for all views 25 | - Memory optimised 26 | 27 | # Getting started 28 | 29 | In your build.gradle: 30 | ``` 31 | dependencies { 32 | implementation 'com.ethanhua:skeleton:1.1.2' 33 | implementation 'io.supercharge:shimmerlayout:2.1.0' 34 | } 35 | ``` 36 | 37 | 38 | 39 | # Usage 40 | For RecyclerView: 41 | ```java 42 | skeletonScreen = Skeleton.bind(recyclerView) 43 | .adapter(adapter) 44 | .load(R.layout.item_skeleton_news) 45 | .show(); 46 | ``` 47 | 48 | 49 | 50 |  For View: 51 | ```java 52 | skeletonScreen = Skeleton.bind(rootView) 53 | .load(R.layout.layout_img_skeleton) 54 | .show(); 55 | ``` 56 | 57 | 58 | 59 | More Config: 60 | ```java 61 | .shimmer(true) // whether show shimmer animation. default is true 62 | .count(10) // the recycler view item count. default is 10 63 | .color(color) // the shimmer color. default is #a2878787 64 | .angle(20) // the shimmer angle. default is 20; 65 | .duration(1000) // the shimmer animation duration. default is 1000; 66 | .frozen(false) // whether frozen recyclerView during skeleton showing default is true; 67 | ``` 68 | 69 | when data return you can call the method to hide skeleton loading view 70 | ```java 71 | skeletonScreen.hide() 72 | ``` 73 | 74 | 75 | # Thanks 76 | 77 | https://github.com/team-supercharge/ShimmerLayout 78 | 79 | -------------------------------------------------------------------------------- /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 | maven {url 'https://maven.google.com'} 6 | maven { url "https://jitpack.io" }//必须添加这行 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.4' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | // classpath 'com.novoda:bintray-release:0.5.0' 15 | classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2' 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | jcenter() 22 | maven {url 'https://maven.google.com'} 23 | maven { url "https://jitpack.io" }//必须添加这行 24 | } 25 | tasks.withType(Javadoc) { 26 | options{ 27 | encoding "UTF-8" 28 | charSet 'UTF-8' 29 | links "http://docs.oracle.com/javase/7/docs/api" 30 | } 31 | } 32 | } 33 | 34 | task clean(type: Delete) { 35 | delete rootProject.buildDir 36 | } 37 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 17 19:46:25 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.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | //apply plugin: 'com.novoda.bintray-release' 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | minSdkVersion 15 7 | targetSdkVersion 26 8 | versionCode 10 9 | versionName "1.1.2" 10 | } 11 | buildTypes { 12 | release { 13 | minifyEnabled false 14 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 15 | } 16 | } 17 | } 18 | 19 | dependencies { 20 | implementation fileTree(include: ['*.jar'], dir: 'libs') 21 | implementation 'io.supercharge:shimmerlayout:2.1.0' 22 | implementation 'com.android.support:recyclerview-v7:26.1.0' 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | } 25 | 26 | //publish { 27 | // userOrg = 'ethanhua' 28 | // groupId = 'com.ethanhua' 29 | // artifactId = 'skeleton' 30 | // publishVersion = '1.1.2' 31 | // bintrayUser = 'ethanhua' 32 | // bintrayKey = '' 33 | // desc = 'a library provider a easy way to show skeleton loading view' 34 | // website = 'https://github.com/ethanhua/Skeleton' 35 | //} -------------------------------------------------------------------------------- /library/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/ethanhua/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/ethanhua/skeleton/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | /** 4 | * Instrumentation test, which will execute on an Android device. 5 | * 6 | * @see Testing documentation 7 | */ 8 | 9 | public class ExampleInstrumentedTest { 10 | 11 | public void useAppContext() throws Exception { 12 | // Context of the app under test. 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/RecyclerViewSkeletonScreen.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | import android.support.annotation.ColorRes; 4 | import android.support.annotation.IntRange; 5 | import android.support.annotation.LayoutRes; 6 | import android.support.v4.content.ContextCompat; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | /** 10 | * Created by ethanhua on 2017/7/29. 11 | */ 12 | 13 | public class RecyclerViewSkeletonScreen implements SkeletonScreen { 14 | 15 | private final RecyclerView mRecyclerView; 16 | private final RecyclerView.Adapter mActualAdapter; 17 | private final SkeletonAdapter mSkeletonAdapter; 18 | private final boolean mRecyclerViewFrozen; 19 | 20 | private RecyclerViewSkeletonScreen(Builder builder) { 21 | mRecyclerView = builder.mRecyclerView; 22 | mActualAdapter = builder.mActualAdapter; 23 | mSkeletonAdapter = new SkeletonAdapter(); 24 | mSkeletonAdapter.setItemCount(builder.mItemCount); 25 | mSkeletonAdapter.setLayoutReference(builder.mItemResID); 26 | mSkeletonAdapter.shimmer(builder.mShimmer); 27 | mSkeletonAdapter.setShimmerColor(builder.mShimmerColor); 28 | mSkeletonAdapter.setShimmerAngle(builder.mShimmerAngle); 29 | mSkeletonAdapter.setShimmerDuration(builder.mShimmerDuration); 30 | mRecyclerViewFrozen = builder.mFrozen; 31 | } 32 | 33 | @Override 34 | public void show() { 35 | mRecyclerView.setAdapter(mSkeletonAdapter); 36 | if (!mRecyclerView.isComputingLayout() && mRecyclerViewFrozen) { 37 | mRecyclerView.setLayoutFrozen(true); 38 | } 39 | } 40 | 41 | @Override 42 | public void hide() { 43 | mRecyclerView.setAdapter(mActualAdapter); 44 | } 45 | 46 | public static class Builder { 47 | private RecyclerView.Adapter mActualAdapter; 48 | private final RecyclerView mRecyclerView; 49 | private boolean mShimmer = true; 50 | private int mItemCount = 10; 51 | private int mItemResID = R.layout.layout_default_item_skeleton; 52 | private int mShimmerColor; 53 | private int mShimmerDuration = 1000; 54 | private int mShimmerAngle = 20; 55 | private boolean mFrozen = true; 56 | 57 | public Builder(RecyclerView recyclerView) { 58 | this.mRecyclerView = recyclerView; 59 | this.mShimmerColor = ContextCompat.getColor(recyclerView.getContext(), R.color.shimmer_color); 60 | } 61 | 62 | /** 63 | * @param adapter the target recyclerView actual adapter 64 | */ 65 | public Builder adapter(RecyclerView.Adapter adapter) { 66 | this.mActualAdapter = adapter; 67 | return this; 68 | } 69 | 70 | /** 71 | * @param itemCount the child item count in recyclerView 72 | */ 73 | public Builder count(int itemCount) { 74 | this.mItemCount = itemCount; 75 | return this; 76 | } 77 | 78 | /** 79 | * @param shimmer whether show shimmer animation 80 | */ 81 | public Builder shimmer(boolean shimmer) { 82 | this.mShimmer = shimmer; 83 | return this; 84 | } 85 | 86 | /** 87 | * the duration of the animation , the time it will take for the highlight to move from one end of the layout 88 | * to the other. 89 | * 90 | * @param shimmerDuration Duration of the shimmer animation, in milliseconds 91 | */ 92 | public Builder duration(int shimmerDuration) { 93 | this.mShimmerDuration = shimmerDuration; 94 | return this; 95 | } 96 | 97 | /** 98 | * @param shimmerColor the shimmer color 99 | */ 100 | public Builder color(@ColorRes int shimmerColor) { 101 | this.mShimmerColor = ContextCompat.getColor(mRecyclerView.getContext(), shimmerColor); 102 | return this; 103 | } 104 | 105 | /** 106 | * @param shimmerAngle the angle of the shimmer effect in clockwise direction in degrees. 107 | */ 108 | public Builder angle(@IntRange(from = 0, to = 30) int shimmerAngle) { 109 | this.mShimmerAngle = shimmerAngle; 110 | return this; 111 | } 112 | 113 | /** 114 | * @param skeletonLayoutResID the loading skeleton layoutResID 115 | */ 116 | public Builder load(@LayoutRes int skeletonLayoutResID) { 117 | this.mItemResID = skeletonLayoutResID; 118 | return this; 119 | } 120 | 121 | /** 122 | * @param frozen whether frozen recyclerView during skeleton showing 123 | * @return 124 | */ 125 | public Builder frozen(boolean frozen) { 126 | this.mFrozen = frozen; 127 | return this; 128 | } 129 | 130 | public RecyclerViewSkeletonScreen show() { 131 | RecyclerViewSkeletonScreen recyclerViewSkeleton = new RecyclerViewSkeletonScreen(this); 132 | recyclerViewSkeleton.show(); 133 | return recyclerViewSkeleton; 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/ShimmerViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | /** 9 | * Created by ethanhua on 2017/7/29. 10 | */ 11 | 12 | public class ShimmerViewHolder extends RecyclerView.ViewHolder { 13 | 14 | public ShimmerViewHolder(LayoutInflater inflater, ViewGroup parent, int innerViewResId) { 15 | super(inflater.inflate(R.layout.layout_shimmer, parent, false)); 16 | ViewGroup layout = (ViewGroup) itemView; 17 | View view = inflater.inflate(innerViewResId, layout, false); 18 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 19 | if (lp != null) { 20 | layout.setLayoutParams(lp); 21 | } 22 | layout.addView(view); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/Skeleton.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by ethanhua on 2017/7/29. 8 | */ 9 | 10 | public class Skeleton { 11 | 12 | public static RecyclerViewSkeletonScreen.Builder bind(RecyclerView recyclerView) { 13 | return new RecyclerViewSkeletonScreen.Builder(recyclerView); 14 | } 15 | 16 | public static ViewSkeletonScreen.Builder bind(View view) { 17 | return new ViewSkeletonScreen.Builder(view); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/SkeletonAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | import android.support.annotation.IntRange; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.ViewGroup; 7 | 8 | import io.supercharge.shimmerlayout.ShimmerLayout; 9 | 10 | /** 11 | * Created by ethanhua on 2017/7/29. 12 | */ 13 | 14 | public class SkeletonAdapter extends RecyclerView.Adapter { 15 | 16 | private int mItemCount; 17 | private int mLayoutReference; 18 | private int mColor; 19 | private boolean mShimmer; 20 | private int mShimmerDuration; 21 | private int mShimmerAngle; 22 | 23 | @Override 24 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 25 | LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 26 | if (mShimmer) { 27 | return new ShimmerViewHolder(inflater, parent, mLayoutReference); 28 | } 29 | return new RecyclerView.ViewHolder(inflater.inflate(mLayoutReference, parent, false)) { 30 | }; 31 | } 32 | 33 | @Override 34 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 35 | if (mShimmer) { 36 | ShimmerLayout layout = (ShimmerLayout) holder.itemView; 37 | layout.setShimmerAnimationDuration(mShimmerDuration); 38 | layout.setShimmerAngle(mShimmerAngle); 39 | layout.setShimmerColor(mColor); 40 | layout.startShimmerAnimation(); 41 | } 42 | } 43 | 44 | @Override 45 | public int getItemCount() { 46 | return mItemCount; 47 | } 48 | 49 | public void setLayoutReference(int layoutReference) { 50 | this.mLayoutReference = layoutReference; 51 | } 52 | 53 | public void setItemCount(int itemCount) { 54 | this.mItemCount = itemCount; 55 | } 56 | 57 | public void setShimmerColor(int color) { 58 | this.mColor = color; 59 | } 60 | 61 | public void shimmer(boolean shimmer) { 62 | this.mShimmer = shimmer; 63 | } 64 | 65 | public void setShimmerDuration(int shimmerDuration) { 66 | this.mShimmerDuration = shimmerDuration; 67 | } 68 | 69 | public void setShimmerAngle(@IntRange(from = 0, to = 30) int shimmerAngle) { 70 | this.mShimmerAngle = shimmerAngle; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/SkeletonScreen.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | /** 4 | * Created by ethanhua on 2017/7/29. 5 | */ 6 | 7 | public interface SkeletonScreen { 8 | 9 | void show(); 10 | 11 | void hide(); 12 | } 13 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/ViewReplacer.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | import android.util.Log; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | /** 9 | * Created by ethanhua on 2017/8/2. 10 | */ 11 | 12 | public class ViewReplacer { 13 | private static final String TAG = ViewReplacer.class.getName(); 14 | private final View mSourceView; 15 | private View mTargetView; 16 | private int mTargetViewResID = -1; 17 | private View mCurrentView; 18 | private ViewGroup mSourceParentView; 19 | private final ViewGroup.LayoutParams mSourceViewLayoutParams; 20 | private int mSourceViewIndexInParent = 0; 21 | private final int mSourceViewId; 22 | 23 | public ViewReplacer(View sourceView) { 24 | mSourceView = sourceView; 25 | mSourceViewLayoutParams = mSourceView.getLayoutParams(); 26 | mCurrentView = mSourceView; 27 | mSourceViewId = mSourceView.getId(); 28 | } 29 | 30 | 31 | public void replace(int targetViewResID) { 32 | if (mTargetViewResID == targetViewResID) { 33 | return; 34 | } 35 | if (init()) { 36 | mTargetViewResID = targetViewResID; 37 | replace(LayoutInflater.from(mSourceView.getContext()).inflate(mTargetViewResID, mSourceParentView, false)); 38 | } 39 | } 40 | 41 | public void replace(View targetView) { 42 | if (mCurrentView == targetView) { 43 | return; 44 | } 45 | if (targetView.getParent() != null) { 46 | ((ViewGroup) targetView.getParent()).removeView(targetView); 47 | } 48 | if (init()) { 49 | mTargetView = targetView; 50 | mSourceParentView.removeView(mCurrentView); 51 | mTargetView.setId(mSourceViewId); 52 | mSourceParentView.addView(mTargetView, mSourceViewIndexInParent, mSourceViewLayoutParams); 53 | mCurrentView = mTargetView; 54 | } 55 | } 56 | 57 | public void restore() { 58 | if (mSourceParentView != null) { 59 | mSourceParentView.removeView(mCurrentView); 60 | mSourceParentView.addView(mSourceView, mSourceViewIndexInParent, mSourceViewLayoutParams); 61 | mCurrentView = mSourceView; 62 | mTargetView = null; 63 | mTargetViewResID = -1; 64 | } 65 | } 66 | 67 | 68 | public View getSourceView() { 69 | return mSourceView; 70 | } 71 | 72 | public View getTargetView() { 73 | return mTargetView; 74 | } 75 | 76 | public View getCurrentView() { 77 | return mCurrentView; 78 | } 79 | 80 | private boolean init() { 81 | if (mSourceParentView == null) { 82 | mSourceParentView = (ViewGroup) mSourceView.getParent(); 83 | if (mSourceParentView == null) { 84 | Log.e(TAG, "the source view have not attach to any view"); 85 | return false; 86 | } 87 | int count = mSourceParentView.getChildCount(); 88 | for (int index = 0; index < count; index++) { 89 | if (mSourceView == mSourceParentView.getChildAt(index)) { 90 | mSourceViewIndexInParent = index; 91 | break; 92 | } 93 | } 94 | } 95 | return true; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /library/src/main/java/com/ethanhua/skeleton/ViewSkeletonScreen.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | import android.support.annotation.ColorRes; 4 | import android.support.annotation.IntRange; 5 | import android.support.annotation.LayoutRes; 6 | import android.support.v4.content.ContextCompat; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.ViewParent; 12 | 13 | import io.supercharge.shimmerlayout.ShimmerLayout; 14 | 15 | /** 16 | * Created by ethanhua on 2017/7/29. 17 | */ 18 | 19 | public class ViewSkeletonScreen implements SkeletonScreen { 20 | private static final String TAG = ViewSkeletonScreen.class.getName(); 21 | private final ViewReplacer mViewReplacer; 22 | private final View mActualView; 23 | private final int mSkeletonResID; 24 | private final int mShimmerColor; 25 | private final boolean mShimmer; 26 | private final int mShimmerDuration; 27 | private final int mShimmerAngle; 28 | 29 | private ViewSkeletonScreen(Builder builder) { 30 | mActualView = builder.mView; 31 | mSkeletonResID = builder.mSkeletonLayoutResID; 32 | mShimmer = builder.mShimmer; 33 | mShimmerDuration = builder.mShimmerDuration; 34 | mShimmerAngle = builder.mShimmerAngle; 35 | mShimmerColor = builder.mShimmerColor; 36 | mViewReplacer = new ViewReplacer(builder.mView); 37 | } 38 | 39 | private ShimmerLayout generateShimmerContainerLayout(ViewGroup parentView) { 40 | final ShimmerLayout shimmerLayout = (ShimmerLayout) LayoutInflater.from(mActualView.getContext()).inflate(R.layout.layout_shimmer, parentView, false); 41 | shimmerLayout.setShimmerColor(mShimmerColor); 42 | shimmerLayout.setShimmerAngle(mShimmerAngle); 43 | shimmerLayout.setShimmerAnimationDuration(mShimmerDuration); 44 | View innerView = LayoutInflater.from(mActualView.getContext()).inflate(mSkeletonResID, shimmerLayout, false); 45 | ViewGroup.LayoutParams lp = innerView.getLayoutParams(); 46 | if (lp != null) { 47 | shimmerLayout.setLayoutParams(lp); 48 | } 49 | shimmerLayout.addView(innerView); 50 | shimmerLayout.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { 51 | @Override 52 | public void onViewAttachedToWindow(View v) { 53 | shimmerLayout.startShimmerAnimation(); 54 | } 55 | 56 | @Override 57 | public void onViewDetachedFromWindow(View v) { 58 | shimmerLayout.stopShimmerAnimation(); 59 | } 60 | }); 61 | shimmerLayout.startShimmerAnimation(); 62 | return shimmerLayout; 63 | } 64 | 65 | private View generateSkeletonLoadingView() { 66 | ViewParent viewParent = mActualView.getParent(); 67 | if (viewParent == null) { 68 | Log.e(TAG, "the source view have not attach to any view"); 69 | return null; 70 | } 71 | ViewGroup parentView = (ViewGroup) viewParent; 72 | if (mShimmer) { 73 | return generateShimmerContainerLayout(parentView); 74 | } 75 | return LayoutInflater.from(mActualView.getContext()).inflate(mSkeletonResID, parentView, false); 76 | } 77 | 78 | @Override 79 | public void show() { 80 | View skeletonLoadingView = generateSkeletonLoadingView(); 81 | if (skeletonLoadingView != null) { 82 | mViewReplacer.replace(skeletonLoadingView); 83 | } 84 | } 85 | 86 | @Override 87 | public void hide() { 88 | if (mViewReplacer.getTargetView() instanceof ShimmerLayout) { 89 | ((ShimmerLayout) mViewReplacer.getTargetView()).stopShimmerAnimation(); 90 | } 91 | mViewReplacer.restore(); 92 | } 93 | 94 | public static class Builder { 95 | private final View mView; 96 | private int mSkeletonLayoutResID; 97 | private boolean mShimmer = true; 98 | private int mShimmerColor; 99 | private int mShimmerDuration = 1000; 100 | private int mShimmerAngle = 20; 101 | 102 | public Builder(View view) { 103 | this.mView = view; 104 | this.mShimmerColor = ContextCompat.getColor(mView.getContext(), R.color.shimmer_color); 105 | } 106 | 107 | /** 108 | * @param skeletonLayoutResID the loading skeleton layoutResID 109 | */ 110 | public Builder load(@LayoutRes int skeletonLayoutResID) { 111 | this.mSkeletonLayoutResID = skeletonLayoutResID; 112 | return this; 113 | } 114 | 115 | /** 116 | * @param shimmerColor the shimmer color 117 | */ 118 | public Builder color(@ColorRes int shimmerColor) { 119 | this.mShimmerColor = ContextCompat.getColor(mView.getContext(), shimmerColor); 120 | return this; 121 | } 122 | 123 | /** 124 | * @param shimmer whether show shimmer animation 125 | */ 126 | public ViewSkeletonScreen.Builder shimmer(boolean shimmer) { 127 | this.mShimmer = shimmer; 128 | return this; 129 | } 130 | 131 | /** 132 | * the duration of the animation , the time it will take for the highlight to move from one end of the layout 133 | * to the other. 134 | * 135 | * @param shimmerDuration Duration of the shimmer animation, in milliseconds 136 | */ 137 | public ViewSkeletonScreen.Builder duration(int shimmerDuration) { 138 | this.mShimmerDuration = shimmerDuration; 139 | return this; 140 | } 141 | 142 | /** 143 | * @param shimmerAngle the angle of the shimmer effect in clockwise direction in degrees. 144 | */ 145 | public ViewSkeletonScreen.Builder angle(@IntRange(from = 0, to = 30) int shimmerAngle) { 146 | this.mShimmerAngle = shimmerAngle; 147 | return this; 148 | } 149 | 150 | public ViewSkeletonScreen show() { 151 | ViewSkeletonScreen skeletonScreen = new ViewSkeletonScreen(this); 152 | skeletonScreen.show(); 153 | return skeletonScreen; 154 | } 155 | 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /library/src/main/res/layout/layout_default_item_skeleton.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 23 | 24 | 34 | 35 | 39 | 40 | 45 | 46 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /library/src/main/res/layout/layout_shimmer.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | skeleton 3 | 4 | -------------------------------------------------------------------------------- /library/src/main/res/values/values.xml: -------------------------------------------------------------------------------- 1 | 2 | #16000000 3 | #24000000 4 | 5 | -------------------------------------------------------------------------------- /library/src/test/java/com/ethanhua/skeleton/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton; 2 | 3 | 4 | 5 | import static junit.framework.Assert.assertEquals; 6 | 7 | 8 | /** 9 | * Example local unit test, which will execute on the development machine (host). 10 | * 11 | * @see Testing documentation 12 | */ 13 | public class ExampleUnitTest { 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.ethanhua.skeleton.sample" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 6 10 | versionName "1.0.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 24 | exclude group: 'com.android.support', module: 'support-annotations' 25 | }) 26 | //implementation project(':library') 27 | implementation 'com.ethanhua:skeleton:1.1.2' 28 | implementation 'io.supercharge:shimmerlayout:2.1.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 30 | implementation 'com.android.support:recyclerview-v7:26.1.0' 31 | implementation 'com.android.support:appcompat-v7:26.1.0' 32 | testImplementation 'junit:junit:4.12' 33 | } 34 | -------------------------------------------------------------------------------- /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/ethanhua/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | //https://github.com/willowtreeapps/spruce-android 带动画 9 | //https://github.com/ethanhua/Skeleton 10 | //http://www.sohu.com/a/278677153_739982 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | findViewById(R.id.btn_list).setOnClickListener(new View.OnClickListener() { 18 | @Override 19 | public void onClick(View view) { 20 | RecyclerViewActivity.start(MainActivity.this, RecyclerViewActivity.TYPE_LINEAR); 21 | } 22 | }); 23 | findViewById(R.id.btn_grid).setOnClickListener(new View.OnClickListener() { 24 | @Override 25 | public void onClick(View view) { 26 | RecyclerViewActivity.start(MainActivity.this, RecyclerViewActivity.TYPE_GRID); 27 | } 28 | }); 29 | findViewById(R.id.btn_view).setOnClickListener(new View.OnClickListener() { 30 | @Override 31 | public void onClick(View view) { 32 | ViewActivity.start(MainActivity.this, ViewActivity.TYPE_VIEW); 33 | } 34 | }); 35 | findViewById(R.id.btn_Imgloading).setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View view) { 38 | ViewActivity.start(MainActivity.this, ViewActivity.TYPE_IMG_LOADING); 39 | } 40 | }); 41 | 42 | findViewById(R.id.btn_status).setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | startActivity(new Intent(MainActivity.this, StatusViewActivity.class)); 46 | } 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/RecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | 12 | import com.ethanhua.skeleton.Skeleton; 13 | import com.ethanhua.skeleton.SkeletonScreen; 14 | import com.ethanhua.skeleton.sample.adapter.NewsAdapter; 15 | import com.ethanhua.skeleton.sample.adapter.PersonAdapter; 16 | 17 | /** 18 | * Created by ethanhua on 2017/7/27. 19 | */ 20 | 21 | public class RecyclerViewActivity extends AppCompatActivity { 22 | 23 | 24 | private static final String PARAMS_TYPE = "params_type"; 25 | public static final String TYPE_LINEAR = "type_linear"; 26 | public static final String TYPE_GRID = "type_grid"; 27 | private String mType; 28 | 29 | public static void start(Context context, String type) { 30 | Intent intent = new Intent(context, RecyclerViewActivity.class); 31 | intent.putExtra(PARAMS_TYPE, type); 32 | context.startActivity(intent); 33 | } 34 | 35 | @Override 36 | protected void onCreate(@Nullable Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_recyclerview); 39 | mType = getIntent().getStringExtra(PARAMS_TYPE); 40 | init(); 41 | } 42 | 43 | 44 | private void init() { 45 | RecyclerView recyclerView = findViewById(R.id.recyclerView); 46 | if (TYPE_LINEAR.equals(mType)) { 47 | recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 48 | NewsAdapter adapter = new NewsAdapter(); 49 | final SkeletonScreen skeletonScreen = Skeleton.bind(recyclerView) 50 | .adapter(adapter) 51 | .shimmer(true) 52 | .angle(20) 53 | .frozen(false) 54 | .duration(1200) 55 | .count(100) 56 | .load(R.layout.item_skeleton_news) 57 | .show(); //default count is 10 58 | recyclerView.postDelayed(new Runnable() { 59 | @Override 60 | public void run() { 61 | skeletonScreen.hide(); 62 | } 63 | }, 3000); 64 | return; 65 | } 66 | if (TYPE_GRID.equals(mType)) { 67 | recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); 68 | PersonAdapter adapter = new PersonAdapter(); 69 | final SkeletonScreen skeletonScreen = Skeleton.bind(recyclerView) 70 | .adapter(adapter) 71 | .load(R.layout.item_skeleton_person) 72 | .shimmer(false) 73 | .show(); 74 | recyclerView.postDelayed(new Runnable() { 75 | @Override 76 | public void run() { 77 | skeletonScreen.hide(); 78 | } 79 | }, 3000); 80 | } 81 | } 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/StatusViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample; 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 com.ethanhua.skeleton.ViewReplacer; 9 | 10 | public class StatusViewActivity extends AppCompatActivity { 11 | private ViewReplacer mViewReplacer; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_status_view); 17 | mViewReplacer = new ViewReplacer(findViewById(R.id.tv_content)); 18 | findViewById(R.id.btn_loading).setOnClickListener(new View.OnClickListener() { 19 | @Override 20 | public void onClick(View v) { 21 | mViewReplacer.replace(R.layout.layout_progress); 22 | } 23 | }); 24 | 25 | findViewById(R.id.btn_error).setOnClickListener(new View.OnClickListener() { 26 | @Override 27 | public void onClick(View v) { 28 | mViewReplacer.replace(R.layout.layout_error); 29 | } 30 | }); 31 | 32 | findViewById(R.id.btn_empty).setOnClickListener(new View.OnClickListener() { 33 | @Override 34 | public void onClick(View v) { 35 | mViewReplacer.replace(R.layout.layout_empty_view); 36 | } 37 | }); 38 | 39 | findViewById(R.id.btn_content).setOnClickListener(new View.OnClickListener() { 40 | @Override 41 | public void onClick(View v) { 42 | mViewReplacer.restore(); 43 | } 44 | }); 45 | 46 | } 47 | 48 | public void gotoSet(View view) { 49 | Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); 50 | startActivity(intent); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/ViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.os.Message; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.View; 11 | 12 | import com.ethanhua.skeleton.Skeleton; 13 | import com.ethanhua.skeleton.SkeletonScreen; 14 | import com.ethanhua.skeleton.sample.adapter.TopicAdapter; 15 | 16 | import java.lang.ref.WeakReference; 17 | 18 | public class ViewActivity extends AppCompatActivity { 19 | 20 | 21 | private static final String PARAMS_TYPE = "params_type"; 22 | public static final String TYPE_IMG_LOADING = "type_img"; 23 | public static final String TYPE_VIEW = "type_view"; 24 | private SkeletonScreen skeletonScreen; 25 | 26 | public static void start(Context context, String type) { 27 | Intent intent = new Intent(context, ViewActivity.class); 28 | intent.putExtra(PARAMS_TYPE, type); 29 | context.startActivity(intent); 30 | } 31 | 32 | public static class MyHandler extends android.os.Handler { 33 | private final WeakReference activityWeakReference; 34 | 35 | MyHandler(ViewActivity activity) { 36 | this.activityWeakReference = new WeakReference<>(activity); 37 | } 38 | 39 | @Override 40 | public void handleMessage(Message msg) { 41 | super.handleMessage(msg); 42 | if (activityWeakReference.get() != null) { 43 | activityWeakReference.get().skeletonScreen.hide(); 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | protected void onCreate(Bundle savedInstanceState) { 50 | super.onCreate(savedInstanceState); 51 | setContentView(R.layout.activity_view); 52 | String mType = getIntent().getStringExtra(PARAMS_TYPE); 53 | View rootView = findViewById(R.id.rootView); 54 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 55 | TopicAdapter adapter = new TopicAdapter(); 56 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); 57 | recyclerView.setLayoutManager(linearLayoutManager); 58 | recyclerView.setAdapter(adapter); 59 | if (TYPE_VIEW.equals(mType)) { 60 | skeletonScreen = Skeleton.bind(rootView) 61 | .load(R.layout.activity_view_skeleton) 62 | .duration(1000) 63 | .color(R.color.shimmer_color) 64 | .angle(0) 65 | .show(); 66 | } 67 | if (TYPE_IMG_LOADING.equals(mType)) { 68 | skeletonScreen = Skeleton.bind(rootView) 69 | .load(R.layout.layout_img_skeleton) 70 | .duration(1000) 71 | .color(R.color.shimmer_color_for_image) 72 | .show(); 73 | } 74 | MyHandler myHandler = new MyHandler(this); 75 | myHandler.sendEmptyMessageDelayed(1, 3000); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/adapter/NewsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.ViewGroup; 6 | 7 | import com.ethanhua.skeleton.sample.R; 8 | 9 | /** 10 | * Created by ethanhua on 2017/7/27. 11 | */ 12 | 13 | public class NewsAdapter extends RecyclerView.Adapter { 14 | 15 | 16 | @Override 17 | public SimpleRcvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 18 | return new SimpleRcvViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_news, parent, false)); 19 | } 20 | 21 | @Override 22 | public void onBindViewHolder(SimpleRcvViewHolder holder, int position) { 23 | 24 | } 25 | 26 | @Override 27 | public int getItemCount() { 28 | return 100; 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/adapter/PersonAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.ViewGroup; 6 | 7 | import com.ethanhua.skeleton.sample.R; 8 | 9 | /** 10 | * Created by ethanhua on 2017/7/29. 11 | */ 12 | 13 | public class PersonAdapter extends RecyclerView.Adapter { 14 | 15 | @Override 16 | public SimpleRcvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 17 | return new SimpleRcvViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_person, parent, false)); 18 | } 19 | 20 | @Override 21 | public void onBindViewHolder(SimpleRcvViewHolder holder, int position) { 22 | 23 | } 24 | 25 | @Override 26 | public int getItemCount() { 27 | return 10; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/adapter/SimpleRcvViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.util.SparseArray; 5 | import android.view.View; 6 | 7 | 8 | public class SimpleRcvViewHolder extends RecyclerView.ViewHolder { 9 | private final SparseArray views = new SparseArray<>(); 10 | 11 | public SimpleRcvViewHolder(View itemView) { 12 | super(itemView); 13 | } 14 | 15 | @SuppressWarnings("unchecked") 16 | public V getView(int resId) { 17 | View v = views.get(resId); 18 | if (null == v) { 19 | v = itemView.findViewById(resId); 20 | views.put(resId, v); 21 | } 22 | return (V) v; 23 | } 24 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/ethanhua/skeleton/sample/adapter/TopicAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ethanhua.skeleton.sample.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.ViewGroup; 6 | 7 | import com.ethanhua.skeleton.sample.R; 8 | 9 | /** 10 | * Created by ethanhua on 2017/7/29. 11 | */ 12 | 13 | public class TopicAdapter extends RecyclerView.Adapter { 14 | private static final int TYPE_HEADER = 1; 15 | private static final int TYPE_CONTENT = 2; 16 | 17 | @Override 18 | public SimpleRcvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 19 | if (viewType == TYPE_HEADER) { 20 | return new SimpleRcvViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_title_more, parent, false)); 21 | } 22 | return new SimpleRcvViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_topic, parent, false)); 23 | } 24 | 25 | @Override 26 | public void onBindViewHolder(SimpleRcvViewHolder holder, int position) { 27 | 28 | } 29 | 30 | @Override 31 | public int getItemCount() { 32 | return 7; 33 | } 34 | 35 | @Override 36 | public int getItemViewType(int position) { 37 | if (position == 0) { 38 | return TYPE_HEADER; 39 | } 40 | return TYPE_CONTENT; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/girl.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/girl.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/google.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/google.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/ic_arrow_right.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_tool_breakfast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/ic_tool_breakfast.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_tool_circumference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/ic_tool_circumference.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_tool_dinner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/ic_tool_dinner.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_tool_extra_meal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable-xxhdpi/ic_tool_extra_meal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/bg_grid_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable/img1.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weileng11/Skeleton-master/23ebfc9e34fad710415fa954fec20dade0e656d5/sample/src/main/res/drawable/img2.png -------------------------------------------------------------------------------- /sample/src/main/res/layout-v21/layout_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |