Skip to content

Instantly share code, notes, and snippets.

@HIREN4131KINAL
Created June 6, 2017 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HIREN4131KINAL/332a005cd23f7c2a57de34eb931b116d to your computer and use it in GitHub Desktop.
Save HIREN4131KINAL/332a005cd23f7c2a57de34eb931b116d to your computer and use it in GitHub Desktop.
Proposal:Library to fetch, decode, and display bitmaps in your app.
Abstract
Loading bitmaps on the UI thread can degrade your app's performance, causing slow responsiveness or even ANR messages. It is therefore important to manage threading appropriately when working with bitmaps.If your app is loading multiple bitmaps into memory, you need to skillfully manage memory and disk caching. Otherwise, the responsiveness and fluidity of your app's UI may suffer.
Background
Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.
Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug in to Google's Volley project or Square's OkHttp library instead.
Glide's primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.
use Gradle:
repositories {
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
dependencies {
compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
compile 'com.android.support:support-v4:25.3.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
}
Or Maven:
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<version>4.0.0-RC0</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
<dependency>
<groupdId>com.github.bumptech.glide</groupId>
<artifactId>compiler</artifactId>
<version>4.0.0-RC0</version>
<optional>true</optional>
</dependency>
For info on using the bleeding edge, see the Snapshots wiki page.
ProGuard
Depending on your ProGuard (DexGuard) config and usage, you may need to include the following lines in your proguard.cfg (see Configuration wiki for more details):
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule
Simple use cases with Glide's generated API will look something like this:
// For a simple view:
@Override public void onCreate(Bundle savedInstanceState) {
...
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
GlideApp.with(this).load("http://goo.gl/gEgYUd").into(imageView);
}
// For a simple image list:
@Override public View getView(int position, View recycled, ViewGroup container) {
final ImageView myImageView;
if (recycled == null) {
myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, container, false);
} else {
myImageView = (ImageView) recycled;
}
String url = myUrls.get(position);
GlideApp
.with(myFragment)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.into(myImageView);
return myImageView;
}
Status
Version 3 on the 3.0 branch is a stable public release used in multiple open source projects at Google including in the Android Camera app and in the 2014 Google IO app. Version 4 is currently under development on the master branch.
Comments/bugs/questions/pull requests are always welcome! Please read CONTRIBUTING.md on how to report issues.
Compatibility
Android SDK: Glide requires a minimum API level of 10.
OkHttp 2.x: there are optional dependencies available called okhttp-integration, see Integration Libraries wiki page.
OkHttp 3.x: there are optional dependencies available called okhttp3-integration, see Integration Libraries wiki page.
Volley: there are optional dependencies available called volley-integration, see Integration Libraries wiki page.
Round Pictures: CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.
Huge Images (maps, comic strips): Glide can load huge images by downsampling them, but does not support zooming and panning ImageViews as they require special resource optimizations (such as tiling) to work without OutOfMemoryErrors.
Build
Building Glide with gradle is fairly straight forward:
git clone git@github.com:bumptech/glide.git # use https://github.com/bumptech/glide.git if "Permission Denied"
cd glide
git submodule init && git submodule update
./gradlew jar
Note: Make sure your Android SDK has the Android Support Repository installed, and that your $ANDROID_HOME environment variable is pointing at the SDK or add a local.properties file in the root project with a sdk.dir=... line.
Samples
Follow the steps in the Build section to setup the project and then:
./gradlew :samples:flickr:run
./gradlew :samples:giphy:run
./gradlew :samples:svg:run
You may also find precompiled APKs on the releases page.
Development
Follow the steps in the Build section to setup the project and then edit the files however you wish. Intellij IDEA 14 cleanly imports both Glide's source and tests and is the recommended way to work with Glide.
To open the project in IntelliJ IDEA:
Go to File menu or the Welcome Screen
Click on Open...
Navigate to Glide's root directory.
Select build.gradle
Changes
There are too many changes to list individually, but here's a few highlights:
New documentation that users can contribute to by submitting pull requests to Glide's gh-pages branch.
A new extensible generated API that allows you to easily customize Glide's fluent API by adding new types or custom option sets.
Substantially simplified types for individual requests that ensure that options are consistently available and easy to use even if you're loading different types of resources.
A variety of performance improvements, including a substantial reduction in garbage when downsampling images, a more intelligent default disk cache strategy, and improved performance when loading GIFs.
Improved handling of View sizes and layouts, especially in RecyclerView.
Status
Glide 4.0 is used internally by a variety of teams at Google and the library is considered stable internally. I expect that there will be more external users who may uncover issues that haven't come up internally. As a result I'm releasing this as an RC. If we don't uncover significant issues with stability or in the API, I expect a non-RC release shortly.
Release schedule.
Glide has had a rather haphazard approach to releases in the past, largely because I maintain Glide mostly in my free time. Going forward we're going to try to provide regular releases:
Releases will go out once a month, around the 15th (the exact date may vary a bit)
Releases will be skipped only if no changes have been since the previous release.
Releases may include breaking API changes without a major version change.
The third bullet point will help bridge the gap between how Glide is maintained inside and outside of Google and enable more regular releases.
Thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment