├── .gitignore ├── CHANGELOG.md ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.txt └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── romainpiel │ │ └── shimmer │ │ ├── Shimmer.java │ │ ├── ShimmerButton.java │ │ ├── ShimmerTextView.java │ │ ├── ShimmerViewBase.java │ │ └── ShimmerViewHelper.java │ └── res │ ├── drawable-nodpi │ ├── mask.xml │ └── spot_mask.png │ └── values │ └── attrs.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.txt └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── romainpiel │ │ └── shimmer │ │ └── sample │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ ├── values-v16 │ └── styles.xml │ ├── values-v17 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── settings.gradle ├── shimmer.gif └── shimmer.png /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Android Studio 23 | .idea/ 24 | .gradle 25 | /*/local.properties 26 | /*/out 27 | /*/*/build 28 | /*/*/production 29 | *.iml 30 | *.iws 31 | *.ipr 32 | *~ 33 | *.swp 34 | *.gpg -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## Version 1.4.0 *13/02/2015* 4 | 5 | - Cleaned up library manifest 6 | 7 | ## Version 1.3.0 *12/01/2015* 8 | 9 | - Updated build tools 10 | 11 | ## Version 1.2.0 *24/03/2014* 12 | 13 | - Added `ShimmerButton` 14 | - Minor fixes 15 | 16 | ## Version 1.1.0 *10/03/2014* 17 | 18 | - Converted static method `Shimmer.animate()` to a class object containing the properties of the animation 19 | - Optimized `ShimmerTextView` using a single `Shader` 20 | - Minor fixes 21 | 22 | ## Version 1.0.0 *06/03/2014* 23 | 24 | Initial release. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shimmer for Android 2 | 3 | This library is DEPRECATED, as I don't have time to mainatin it anymore. But feel free to go through the code and copy that into your project, it still does its job. 4 | 5 | Shimmer-android is an Android port of [Facebook Shimmer library for iOS](https://github.com/facebook/Shimmer). 6 | 7 | [![ScreenShot](shimmer.gif)](http://youtu.be/7EOsegp4J2o) 8 | 9 | [http://youtu.be/7EOsegp4J2o](http://youtu.be/7EOsegp4J2o) 10 | 11 | Examples of usage: 12 | - show a loading indicator 13 | - show a highlighted `TextView`. 14 | 15 | ## How to use 16 | 17 | Gradle dependency: 18 | ```groovy 19 | compile 'com.romainpiel.shimmer:library:1.4.0@aar' 20 | ``` 21 | 22 | Add a `ShimmerTextView` to your layout: 23 | ```xml 24 | 31 | ``` 32 | 33 | To start the animation: 34 | ```java 35 | shimmer = new Shimmer(); 36 | shimmer.start(myShimmerTextView); 37 | ``` 38 | 39 | You may want to keep track of the shimmer instance after the animation is started if you want to stop it. 40 | 41 | To stop it: 42 | ```java 43 | shimmer.cancel(); 44 | ``` 45 | 46 | ## Customization 47 | 48 | ### Customizing the view 49 | 50 | You can change the color of the reflection using the custom attribute `reflectionColor`: 51 | 52 | ```xml 53 | 61 | ``` 62 | 63 | ### Customizing the animation 64 | 65 | The animation can be tweaked like a usual `ObjectAnimator`: 66 | ```java 67 | // DON'T COPY THIS CODE TO YOUR PROJECT! It is just an example 68 | shimmer.setRepeatCount(0) 69 | .setDuration(500) 70 | .setStartDelay(300) 71 | .setDirection(Shimmer.ANIMATION_DIRECTION_RTL) 72 | .setAnimatorListener(new Animator.AnimatorListener(){}); 73 | ``` 74 | 75 | ### Custom Shimmer view 76 | 77 | Shimmer also includes a [`ShimmerButton`](https://github.com/RomainPiel/Shimmer-android/blob/master/library/src/main/java/com/romainpiel/shimmer/ShimmerButton.java). It works exactly the same way as a `ShimmerTextView`. 78 | Have a look at how it's implemented and you can apply the same effect on your custom view if you need it. 79 | 80 | ## Sample 81 | 82 | See the [sample](https://github.com/RomainPiel/Shimmer-android/tree/master/sample) for a common use of this library. 83 | 84 | ## License 85 | ``` 86 | Copyright 2014 Romain Piel 87 | 88 | Licensed under the Apache License, Version 2.0 (the "License"); 89 | you may not use this file except in compliance with the License. 90 | You may obtain a copy of the License at 91 | 92 | http://www.apache.org/licenses/LICENSE-2.0 93 | 94 | Unless required by applicable law or agreed to in writing, software 95 | distributed under the License is distributed on an "AS IS" BASIS, 96 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 97 | See the License for the specific language governing permissions and 98 | limitations under the License. 99 | ``` 100 | 101 | -------------------------------------------------------------------------------- /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 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.1.0' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.4.0 2 | VERSION_CODE=5 3 | GROUP=com.romainpiel.shimmer 4 | 5 | POM_DESCRIPTION=An Android TextView with a shimmering effect 6 | POM_URL=https://github.com/RomainPiel/Shimmer-android 7 | POM_SCM_URL=https://github.com/RomainPiel/Shimmer-android 8 | POM_SCM_CONNECTION=scm:git@github.com:RomainPiel/Shimmer-android.git 9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:RomainPiel/Shimmer-android.git 10 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 11 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 12 | POM_LICENCE_DIST=repo 13 | POM_DEVELOPER_ID=romainpiel 14 | POM_DEVELOPER_NAME=Romain Piel 15 | 16 | ANDROID_BUILD_TARGET_SDK_VERSION=21 17 | ANDROID_BUILD_TOOLS_VERSION=21.1.2 18 | ANDROID_BUILD_SDK_VERSION=21 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainpiel/Shimmer-android/75a2c3e33311e27e7c7c456a9fb89308b5e749f0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) 5 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) 10 | versionCode Integer.parseInt(project.VERSION_CODE) 11 | versionName project.VERSION_NAME 12 | } 13 | } 14 | 15 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' 16 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Shimmer-android 2 | POM_ARTIFACT_ID=library 3 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /library/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/romainpiel/Documents/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the ProGuard 5 | # include property in project.properties. 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 | #} -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /library/src/main/java/com/romainpiel/shimmer/Shimmer.java: -------------------------------------------------------------------------------- 1 | package com.romainpiel.shimmer; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.animation.ValueAnimator; 6 | import android.os.Build; 7 | import android.view.View; 8 | 9 | /** 10 | * Shimmer 11 | * User: romainpiel 12 | * Date: 06/03/2014 13 | * Time: 15:42 14 | */ 15 | public class Shimmer { 16 | 17 | public static final int ANIMATION_DIRECTION_LTR = 0; 18 | public static final int ANIMATION_DIRECTION_RTL = 1; 19 | 20 | private static final int DEFAULT_REPEAT_COUNT = ValueAnimator.INFINITE; 21 | private static final long DEFAULT_DURATION = 1000; 22 | private static final long DEFAULT_START_DELAY = 0; 23 | private static final int DEFAULT_DIRECTION = ANIMATION_DIRECTION_LTR; 24 | 25 | private int repeatCount; 26 | private long duration; 27 | private long startDelay; 28 | private int direction; 29 | private Animator.AnimatorListener animatorListener; 30 | 31 | private ObjectAnimator animator; 32 | 33 | public Shimmer() { 34 | repeatCount = DEFAULT_REPEAT_COUNT; 35 | duration = DEFAULT_DURATION; 36 | startDelay = DEFAULT_START_DELAY; 37 | direction = DEFAULT_DIRECTION; 38 | } 39 | 40 | public int getRepeatCount() { 41 | return repeatCount; 42 | } 43 | 44 | public Shimmer setRepeatCount(int repeatCount) { 45 | this.repeatCount = repeatCount; 46 | return this; 47 | } 48 | 49 | public long getDuration() { 50 | return duration; 51 | } 52 | 53 | public Shimmer setDuration(long duration) { 54 | this.duration = duration; 55 | return this; 56 | } 57 | 58 | public long getStartDelay() { 59 | return startDelay; 60 | } 61 | 62 | public Shimmer setStartDelay(long startDelay) { 63 | this.startDelay = startDelay; 64 | return this; 65 | } 66 | 67 | public int getDirection() { 68 | return direction; 69 | } 70 | 71 | public Shimmer setDirection(int direction) { 72 | 73 | if (direction != ANIMATION_DIRECTION_LTR && direction != ANIMATION_DIRECTION_RTL) { 74 | throw new IllegalArgumentException("The animation direction must be either ANIMATION_DIRECTION_LTR or ANIMATION_DIRECTION_RTL"); 75 | } 76 | 77 | this.direction = direction; 78 | return this; 79 | } 80 | 81 | public Animator.AnimatorListener getAnimatorListener() { 82 | return animatorListener; 83 | } 84 | 85 | public Shimmer setAnimatorListener(Animator.AnimatorListener animatorListener) { 86 | this.animatorListener = animatorListener; 87 | return this; 88 | } 89 | 90 | public void start(final V shimmerView) { 91 | 92 | if (isAnimating()) { 93 | return; 94 | } 95 | 96 | final Runnable animate = new Runnable() { 97 | @Override 98 | public void run() { 99 | 100 | shimmerView.setShimmering(true); 101 | 102 | float fromX = 0; 103 | float toX = shimmerView.getWidth(); 104 | if (direction == ANIMATION_DIRECTION_RTL) { 105 | fromX = shimmerView.getWidth(); 106 | toX = 0; 107 | } 108 | 109 | animator = ObjectAnimator.ofFloat(shimmerView, "gradientX", fromX, toX); 110 | animator.setRepeatCount(repeatCount); 111 | animator.setDuration(duration); 112 | animator.setStartDelay(startDelay); 113 | animator.addListener(new Animator.AnimatorListener() { 114 | @Override 115 | public void onAnimationStart(Animator animation) { 116 | } 117 | 118 | @Override 119 | public void onAnimationEnd(Animator animation) { 120 | shimmerView.setShimmering(false); 121 | 122 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 123 | shimmerView.postInvalidate(); 124 | } else { 125 | shimmerView.postInvalidateOnAnimation(); 126 | } 127 | 128 | animator = null; 129 | } 130 | 131 | @Override 132 | public void onAnimationCancel(Animator animation) { 133 | 134 | } 135 | 136 | @Override 137 | public void onAnimationRepeat(Animator animation) { 138 | 139 | } 140 | }); 141 | 142 | if (animatorListener != null) { 143 | animator.addListener(animatorListener); 144 | } 145 | 146 | animator.start(); 147 | } 148 | }; 149 | 150 | if (!shimmerView.isSetUp()) { 151 | shimmerView.setAnimationSetupCallback(new ShimmerViewHelper.AnimationSetupCallback() { 152 | @Override 153 | public void onSetupAnimation(final View target) { 154 | animate.run(); 155 | } 156 | }); 157 | } else { 158 | animate.run(); 159 | } 160 | } 161 | 162 | public void cancel() { 163 | if (animator != null) { 164 | animator.cancel(); 165 | } 166 | } 167 | 168 | public boolean isAnimating() { 169 | return animator != null && animator.isRunning(); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /library/src/main/java/com/romainpiel/shimmer/ShimmerButton.java: -------------------------------------------------------------------------------- 1 | package com.romainpiel.shimmer; 2 | 3 | import android.content.Context; 4 | import android.content.res.ColorStateList; 5 | import android.graphics.Canvas; 6 | import android.util.AttributeSet; 7 | import android.widget.Button; 8 | 9 | /** 10 | * Shimmer 11 | * User: romainpiel 12 | * Date: 06/03/2014 13 | * Time: 10:19 14 | * 15 | * Shimmering Button 16 | * Dumb class wrapping a ShimmerViewHelper 17 | */ 18 | public class ShimmerButton extends Button implements ShimmerViewBase { 19 | 20 | private ShimmerViewHelper shimmerViewHelper; 21 | 22 | public ShimmerButton(Context context) { 23 | super(context); 24 | shimmerViewHelper = new ShimmerViewHelper(this, getPaint(), null); 25 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 26 | } 27 | 28 | public ShimmerButton(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | shimmerViewHelper = new ShimmerViewHelper(this, getPaint(), attrs); 31 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 32 | } 33 | 34 | public ShimmerButton(Context context, AttributeSet attrs, int defStyle) { 35 | super(context, attrs, defStyle); 36 | shimmerViewHelper = new ShimmerViewHelper(this, getPaint(), attrs); 37 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 38 | } 39 | 40 | @Override 41 | public float getGradientX() { 42 | return shimmerViewHelper.getGradientX(); 43 | } 44 | 45 | @Override 46 | public void setGradientX(float gradientX) { 47 | shimmerViewHelper.setGradientX(gradientX); 48 | } 49 | 50 | @Override 51 | public boolean isShimmering() { 52 | return shimmerViewHelper.isShimmering(); 53 | } 54 | 55 | @Override 56 | public void setShimmering(boolean isShimmering) { 57 | shimmerViewHelper.setShimmering(isShimmering); 58 | } 59 | 60 | @Override 61 | public boolean isSetUp() { 62 | return shimmerViewHelper.isSetUp(); 63 | } 64 | 65 | @Override 66 | public void setAnimationSetupCallback(ShimmerViewHelper.AnimationSetupCallback callback) { 67 | shimmerViewHelper.setAnimationSetupCallback(callback); 68 | } 69 | 70 | @Override 71 | public int getPrimaryColor() { 72 | return shimmerViewHelper.getPrimaryColor(); 73 | } 74 | 75 | @Override 76 | public void setPrimaryColor(int primaryColor) { 77 | shimmerViewHelper.setPrimaryColor(primaryColor); 78 | } 79 | 80 | @Override 81 | public int getReflectionColor() { 82 | return shimmerViewHelper.getReflectionColor(); 83 | } 84 | 85 | @Override 86 | public void setReflectionColor(int reflectionColor) { 87 | shimmerViewHelper.setReflectionColor(reflectionColor); 88 | } 89 | 90 | @Override 91 | public void setTextColor(int color) { 92 | super.setTextColor(color); 93 | if (shimmerViewHelper != null) { 94 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 95 | } 96 | } 97 | 98 | @Override 99 | public void setTextColor(ColorStateList colors) { 100 | super.setTextColor(colors); 101 | if (shimmerViewHelper != null) { 102 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 103 | } 104 | } 105 | 106 | @Override 107 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 108 | super.onSizeChanged(w, h, oldw, oldh); 109 | if (shimmerViewHelper != null) { 110 | shimmerViewHelper.onSizeChanged(); 111 | } 112 | } 113 | 114 | @Override 115 | public void onDraw(Canvas canvas) { 116 | if (shimmerViewHelper != null) { 117 | shimmerViewHelper.onDraw(); 118 | } 119 | super.onDraw(canvas); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /library/src/main/java/com/romainpiel/shimmer/ShimmerTextView.java: -------------------------------------------------------------------------------- 1 | package com.romainpiel.shimmer; 2 | 3 | import android.content.Context; 4 | import android.content.res.ColorStateList; 5 | import android.graphics.Canvas; 6 | import android.util.AttributeSet; 7 | import android.widget.TextView; 8 | 9 | /** 10 | * Shimmer 11 | * User: romainpiel 12 | * Date: 06/03/2014 13 | * Time: 10:19 14 | * 15 | * Shimmering TextView 16 | * Dumb class wrapping a ShimmerViewHelper 17 | */ 18 | public class ShimmerTextView extends TextView implements ShimmerViewBase { 19 | 20 | private ShimmerViewHelper shimmerViewHelper; 21 | 22 | public ShimmerTextView(Context context) { 23 | super(context); 24 | shimmerViewHelper = new ShimmerViewHelper(this, getPaint(), null); 25 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 26 | } 27 | 28 | public ShimmerTextView(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | shimmerViewHelper = new ShimmerViewHelper(this, getPaint(), attrs); 31 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 32 | } 33 | 34 | public ShimmerTextView(Context context, AttributeSet attrs, int defStyle) { 35 | super(context, attrs, defStyle); 36 | shimmerViewHelper = new ShimmerViewHelper(this, getPaint(), attrs); 37 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 38 | } 39 | 40 | @Override 41 | public float getGradientX() { 42 | return shimmerViewHelper.getGradientX(); 43 | } 44 | 45 | @Override 46 | public void setGradientX(float gradientX) { 47 | shimmerViewHelper.setGradientX(gradientX); 48 | } 49 | 50 | @Override 51 | public boolean isShimmering() { 52 | return shimmerViewHelper.isShimmering(); 53 | } 54 | 55 | @Override 56 | public void setShimmering(boolean isShimmering) { 57 | shimmerViewHelper.setShimmering(isShimmering); 58 | } 59 | 60 | @Override 61 | public boolean isSetUp() { 62 | return shimmerViewHelper.isSetUp(); 63 | } 64 | 65 | @Override 66 | public void setAnimationSetupCallback(ShimmerViewHelper.AnimationSetupCallback callback) { 67 | shimmerViewHelper.setAnimationSetupCallback(callback); 68 | } 69 | 70 | @Override 71 | public int getPrimaryColor() { 72 | return shimmerViewHelper.getPrimaryColor(); 73 | } 74 | 75 | @Override 76 | public void setPrimaryColor(int primaryColor) { 77 | shimmerViewHelper.setPrimaryColor(primaryColor); 78 | } 79 | 80 | @Override 81 | public int getReflectionColor() { 82 | return shimmerViewHelper.getReflectionColor(); 83 | } 84 | 85 | @Override 86 | public void setReflectionColor(int reflectionColor) { 87 | shimmerViewHelper.setReflectionColor(reflectionColor); 88 | } 89 | 90 | @Override 91 | public void setTextColor(int color) { 92 | super.setTextColor(color); 93 | if (shimmerViewHelper != null) { 94 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 95 | } 96 | } 97 | 98 | @Override 99 | public void setTextColor(ColorStateList colors) { 100 | super.setTextColor(colors); 101 | if (shimmerViewHelper != null) { 102 | shimmerViewHelper.setPrimaryColor(getCurrentTextColor()); 103 | } 104 | } 105 | 106 | @Override 107 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 108 | super.onSizeChanged(w, h, oldw, oldh); 109 | if (shimmerViewHelper != null) { 110 | shimmerViewHelper.onSizeChanged(); 111 | } 112 | } 113 | 114 | @Override 115 | public void onDraw(Canvas canvas) { 116 | if (shimmerViewHelper != null) { 117 | shimmerViewHelper.onDraw(); 118 | } 119 | super.onDraw(canvas); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /library/src/main/java/com/romainpiel/shimmer/ShimmerViewBase.java: -------------------------------------------------------------------------------- 1 | package com.romainpiel.shimmer; 2 | 3 | /** 4 | * Shimmer 5 | * User: romainpiel 6 | * Date: 10/03/2014 7 | * Time: 17:33 8 | */ 9 | public interface ShimmerViewBase { 10 | 11 | public float getGradientX(); 12 | public void setGradientX(float gradientX); 13 | public boolean isShimmering(); 14 | public void setShimmering(boolean isShimmering); 15 | public boolean isSetUp(); 16 | public void setAnimationSetupCallback(ShimmerViewHelper.AnimationSetupCallback callback); 17 | public int getPrimaryColor(); 18 | public void setPrimaryColor(int primaryColor); 19 | public int getReflectionColor(); 20 | public void setReflectionColor(int reflectionColor); 21 | } 22 | -------------------------------------------------------------------------------- /library/src/main/java/com/romainpiel/shimmer/ShimmerViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.romainpiel.shimmer; 2 | 3 | import android.content.res.TypedArray; 4 | import android.graphics.LinearGradient; 5 | import android.graphics.Matrix; 6 | import android.graphics.Paint; 7 | import android.graphics.Shader; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | 11 | /** 12 | * Shimmer 13 | * User: romainpiel 14 | * Date: 10/03/2014 15 | * Time: 17:06 16 | */ 17 | public class ShimmerViewHelper { 18 | 19 | public interface AnimationSetupCallback { 20 | void onSetupAnimation(View target); 21 | } 22 | 23 | private static final int DEFAULT_REFLECTION_COLOR = 0xFFFFFFFF; 24 | 25 | private View view; 26 | private Paint paint; 27 | 28 | // center position of the gradient 29 | private float gradientX; 30 | 31 | // shader applied on the text view 32 | // only null until the first global layout 33 | private LinearGradient linearGradient; 34 | 35 | // shader's local matrix 36 | // never null 37 | private Matrix linearGradientMatrix; 38 | 39 | private int primaryColor; 40 | 41 | // shimmer reflection color 42 | private int reflectionColor; 43 | 44 | // true when animating 45 | private boolean isShimmering; 46 | 47 | // true after first global layout 48 | private boolean isSetUp; 49 | 50 | // callback called after first global layout 51 | private AnimationSetupCallback callback; 52 | 53 | public ShimmerViewHelper(View view, Paint paint, AttributeSet attributeSet) { 54 | this.view = view; 55 | this.paint = paint; 56 | init(attributeSet); 57 | } 58 | 59 | public float getGradientX() { 60 | return gradientX; 61 | } 62 | 63 | public void setGradientX(float gradientX) { 64 | this.gradientX = gradientX; 65 | view.invalidate(); 66 | } 67 | 68 | public boolean isShimmering() { 69 | return isShimmering; 70 | } 71 | 72 | public void setShimmering(boolean isShimmering) { 73 | this.isShimmering = isShimmering; 74 | } 75 | 76 | public boolean isSetUp() { 77 | return isSetUp; 78 | } 79 | 80 | public void setAnimationSetupCallback(AnimationSetupCallback callback) { 81 | this.callback = callback; 82 | } 83 | 84 | public int getPrimaryColor() { 85 | return primaryColor; 86 | } 87 | 88 | public void setPrimaryColor(int primaryColor) { 89 | this.primaryColor = primaryColor; 90 | if (isSetUp) { 91 | resetLinearGradient(); 92 | } 93 | } 94 | 95 | public int getReflectionColor() { 96 | return reflectionColor; 97 | } 98 | 99 | public void setReflectionColor(int reflectionColor) { 100 | this.reflectionColor = reflectionColor; 101 | if (isSetUp) { 102 | resetLinearGradient(); 103 | } 104 | } 105 | 106 | private void init(AttributeSet attributeSet) { 107 | 108 | reflectionColor = DEFAULT_REFLECTION_COLOR; 109 | 110 | if (attributeSet != null) { 111 | TypedArray a = view.getContext().obtainStyledAttributes(attributeSet, R.styleable.ShimmerView, 0, 0); 112 | if (a != null) { 113 | try { 114 | reflectionColor = a.getColor(R.styleable.ShimmerView_reflectionColor, DEFAULT_REFLECTION_COLOR); 115 | } catch (Exception e) { 116 | android.util.Log.e("ShimmerTextView", "Error while creating the view:", e); 117 | } finally { 118 | a.recycle(); 119 | } 120 | } 121 | } 122 | 123 | linearGradientMatrix = new Matrix(); 124 | } 125 | 126 | private void resetLinearGradient() { 127 | 128 | // our gradient is a simple linear gradient from textColor to reflectionColor. its axis is at the center 129 | // when it's outside of the view, the outer color (textColor) will be repeated (Shader.TileMode.CLAMP) 130 | // initially, the linear gradient is positioned on the left side of the view 131 | linearGradient = new LinearGradient(-view.getWidth(), 0, 0, 0, 132 | new int[]{ 133 | primaryColor, 134 | reflectionColor, 135 | primaryColor, 136 | }, 137 | new float[]{ 138 | 0, 139 | 0.5f, 140 | 1 141 | }, 142 | Shader.TileMode.CLAMP 143 | ); 144 | 145 | paint.setShader(linearGradient); 146 | } 147 | 148 | protected void onSizeChanged() { 149 | 150 | resetLinearGradient(); 151 | 152 | if (!isSetUp) { 153 | isSetUp = true; 154 | 155 | if (callback != null) { 156 | callback.onSetupAnimation(view); 157 | } 158 | } 159 | } 160 | 161 | /** 162 | * content of the wrapping view's onDraw(Canvas) 163 | * MUST BE CALLED BEFORE SUPER STATEMENT 164 | */ 165 | public void onDraw() { 166 | 167 | // only draw the shader gradient over the text while animating 168 | if (isShimmering) { 169 | 170 | // first onDraw() when shimmering 171 | if (paint.getShader() == null) { 172 | paint.setShader(linearGradient); 173 | } 174 | 175 | // translate the shader local matrix 176 | linearGradientMatrix.setTranslate(2 * gradientX, 0); 177 | 178 | // this is required in order to invalidate the shader's position 179 | linearGradient.setLocalMatrix(linearGradientMatrix); 180 | 181 | } else { 182 | // we're not animating, remove the shader from the paint 183 | paint.setShader(null); 184 | } 185 | 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /library/src/main/res/drawable-nodpi/mask.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /library/src/main/res/drawable-nodpi/spot_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainpiel/Shimmer-android/75a2c3e33311e27e7c7c456a9fb89308b5e749f0/library/src/main/res/drawable-nodpi/spot_mask.png -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) 5 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) 10 | versionCode Integer.parseInt(project.VERSION_CODE) 11 | versionName project.VERSION_NAME 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) 23 | compile project(':library') 24 | } 25 | -------------------------------------------------------------------------------- /sample/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/romainpiel/Documents/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the ProGuard 5 | # include property in project.properties. 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 | #} -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/romainpiel/shimmer/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.romainpiel.shimmer.sample; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.romainpiel.shimmer.Shimmer; 8 | import com.romainpiel.shimmer.ShimmerTextView; 9 | 10 | public class MainActivity extends Activity { 11 | 12 | ShimmerTextView tv; 13 | Shimmer shimmer; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | tv = (ShimmerTextView) findViewById(R.id.shimmer_tv); 21 | } 22 | 23 | public void toggleAnimation(View target) { 24 | if (shimmer != null && shimmer.isAnimating()) { 25 | shimmer.cancel(); 26 | } else { 27 | shimmer = new Shimmer(); 28 | shimmer.start(tv); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainpiel/Shimmer-android/75a2c3e33311e27e7c7c456a9fb89308b5e749f0/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainpiel/Shimmer-android/75a2c3e33311e27e7c7c456a9fb89308b5e749f0/sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainpiel/Shimmer-android/75a2c3e33311e27e7c7c456a9fb89308b5e749f0/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romainpiel/Shimmer-android/75a2c3e33311e27e7c7c456a9fb89308b5e749f0/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 15 | 16 |