Shimmer
Shimmer effect for Android
About

Shimmer is a java library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as an unobtrusive loading indicator. It was originally developed for Facebook Home.

Shimmer for Android is implemented as a layout, which means that you can simply nest any view inside a ShimmerFrameLayout tag, and call to start the animation from your code. That's all that is required. The layout will use the values you specify either on the tag (using custom attributes) or programmatically in your code, and generate an animation on the fly. See the API reference for further details.

Here's an example of a composite view, consisting of an image and some text below it, that shows the effect in action:

Download

To include Shimmer in your project, grab the latest prebuilt Jar file. ↓ Download Jar v0.1.0

Alternatively you can include Shimmer for Android from Maven Central via Gradle or Maven.

// Gradle dependency on Shimmer for Android
dependencies {
  compile 'com.facebook.shimmer:shimmer:0.1.0@aar'
}

<!-- Maven dependency on Shimmer for Android -->
<dependency>
  <groupId>com.facebook.shimmer</groupId>
  <artifactId>shimmer</artifactId>
  <version>0.1.0</version>
</dependency>

Note that you cannot use the custom attributes on the tag if you use the Jar file. You can instead download the AAR file and reference that locally in your project.

Building

You can use the included Gradle wrapper to build the Shimmer library and sample application locally as well. Check out the code at github.com/facebook/shimmer-android.

cd $SHIMMER_CHECKOUT

# install the Shimmer sample app
./gradlew installExample

# build the Android distribution Jar
./gradlew shimmerDistJar
Usage

The following snippet shows how you can use ShimmerFrameLayout

<com.facebook.shimmer.ShimmerFrameLayout
     android:id="@+id/shimmer_view_container"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
>
     ...(your complex view here)...
</com.facebook.shimmer.ShimmerFrameLayout>

In your code, you can then start the animation:

ShimmerFrameLayout container = 
  (ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);
container.startShimmerAnimation();
Attributes

You can control the look and pace of the effect using a number of custom attributes on the ShimmerFrameLayout tag. Alternatively, you can set these values on the layout object itself. For a comprehensive list, check out the API reference

Auto Start
Whether to automatically start the animation when the view is shown, or not.
Base Alpha
Alpha used to render the base view i.e. the unhighlighted view over which the highlight is drawn.
Duration
Time it takes for the highlight to move from one end of the layout to the other.
Repeat Count
Number of times of the current animation will repeat.
Repeat Delay
Delay after which the current animation will repeat.
Repeat Mode
What the animation should do after reaching the end, either restart from the beginning or reverse back towards it.
Mask Shape
Shape of the highlight mask, either with a linear or a circular gradient.
Angle
Angle at which the highlight mask is animated, from left-to-right, top-to-bottom etc.
Dropoff
Controls the size of the fading edge of the highlight.
Intensity
Controls the brightness of the highlight at the center
Tilt
Angle at which the highlight is tilted, measured in degrees
Fixed Width, Height
Fixed sized highlight mask, if set, overrides the relative size value
Relative Width, Height
Size of the highlight mask, relative to the layout it is applied to.
Support

Join the discussion over at our Facebook Group to report bugs, request features or show off your project.

Who is using Shimmer for Android?

Open an issue on Github if you are using this component in production and would like to be added to this list.

Slingshot
Slingshot uses Shimmer for Android to indicate loading status.


Home
Facebook Home uses the Shimmer effect to indicate status while loading the news feed, notifications and wallpaper settings.

License

BSD License

For Shimmer software

Copyright (c) 2015, Facebook, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.