-
- Brief introduction
- Run Demo
- Install dependent packages
- Now compile a good dependency
- Gradle
- Maven
- Proguard
- Simple to use
- To set the scratch diagram and load failure diagram
- Load cover diagram
- Loading pictures from other paths
- Loading pictures to other controls
- Debugging information
- Turn on request response information
- Turn on workflow logging
Brief introduction
Now on Android loading picture frame has been rotten street, so we do not say here who is good or bad, of course, do not compare, because the results are one-sided, there is no good who bad only suitable for demand
The result was a Google Developer forum in Thailand, where Google introduced a picture-loading library called Glide, the author of Bumptech. The library is widely used in Google's open source projects, including the official app released at the 2014 Google I/O conference. Need to specifically note that this is not an official library, personal feeling and Picasso special like, of course, this is the first feeling, in fact, the internal is really not the same, this is the English address, of course, domestic translation of reference in this
Of course, the installation of my blog has always been the style, come up or run the next demo, so that since the check see to learn this library some effects, more understanding of the project structure of the great God, learn more about the project structure of the Great God is very helpful
Run Demo
First I came to glide on GitHub and could see so much inside
is not a large part of seeing so many documents that are blinded by this
Download the source code in the form of build, instead of downloading it via download zip, here's a simple summary of the next steps
clone https://github.com/bumptech/glide.git
We clone the code locally and then use the Android Studio import to select the outermost Build.gradle file, after successful import as
which
Library: Is the source of glide
Samples: It's all a demo.
Third_party: is a library of some dependent libraries
Now that we can run the demo, we run the gallery, which can be run directly in Android Studio, using the following command:
:samples:flickr:run:samples:giphy:run:samples:svg:run
As you can see here is the Run method of a project below the demo, let's see how the Great gods are implemented, and we have the following code in Gallery's Build.gradle file
task run(type‘installDebug‘) { ‘Installs the APK and runs the main activity: "gradlew :samples:???:run"‘ "${android.sdkDirectory}/platform-tools/adb"‘shell‘‘am‘‘start‘‘-n‘‘com.bumptech.glide.samples.gallery/.MainActivity‘}
So we can see how he's running the run way.
There is also a place worth learning, Unify the SDK version and the version of the dependent package into the Gradle.properties file, the advantage is that if you want to change the version only need to change the file inside the line, then we will see how he wrote it, here only looked at the gallery directory of Build.gradle files, other files All the same.
Apply plugin:' Com.android.application 'dependencies {Compile project (': library ') Compile (Project (': Integration:recyclerview ') {transitive =false} Compile"Com.android.support:support-v4:${support_v4_version}"Compile"Com.android.support:recyclerview-v7:${support_v7_version}"}android {compilesdkversion compile_sdk_version as intBuildtoolsversion build_tools_version Defaultconfig {ApplicationID' Com.bumptech.glide.samples.gallery 'Minsdkversion min_sdk_version as intTargetsdkversion target_sdk_version as intVersioncode1Versionname"1.0"} compileoptions {sourcecompatibility javaversion.version_1_7 targetcompatibility JavaVersion.VERSION_1_ 7}}task Run ( type: Exec, dependsOn: 'installdebug') {Description' installs the APK and runs the main activity: "Gradlew:samples:???: Run" 'CommandLine"${ANDROID.SDKDIRECTORY}/PLATFORM-TOOLS/ADB",' Shell ',' AM ',' Start ','-n ',' com.bumptech.glide.samples.gallery/. Mainactivity '}
You can see a variable like ${support_v4_version},compile_sdk_version, but his value is set in the Gradle.properties file.
COMPILE_SDK_VERSION=22BUILD_TOOLS_VERSION=22.0.1TARGET_SDK_VERSION=22MIN_SDK_VERSION=10
Individuals feel that some of the parameters used to manage a project in this way are good, such as: compiling the SDK version, depending on the version or some configuration parameters
Here you can see the built-in jar package on the website.
You can see this demo will show all the pictures on our phone.
Now the demo run is introduced here, as for the other, we can change the demo and then run to see the effect, now say the use of common methods
Install dependent packages
There is a lot of this way, people choose their own suitable way
Now compile a good dependency
Here you can download the official already compiled jar
Gradle
Because the Glide library has been uploaded to Jcenter, we can add dependencies directly to the Build.gradle file in the outermost of the project.
{ compile ‘com.github.bumptech.glide:glide:3.7.0‘ compile ‘com.android.support:support-v4:19.1.0‘}
Maven
<dependency> <groupId>Com.github.bumptech.glide</groupId> <artifactid>Glide</artifactid> <version>3.7.0</version></Dependency><dependency> <groupId>Com.google.android</groupId> <artifactid>Support-v4</artifactid> <version>R7</version></Dependency>
Proguard
This step is very important, so no matter how confused you are added, or the day you want to confuse, looking everywhere to ignore the package, this is a very painful thing, because you rely on the library certainly more than this one
publicclass * implements com.bumptech.glide.module.GlideModule-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { **[] $VALUES; public *;}
Simple to use
This step is very simple, do not have to explain too much, look directly at the code
Glide.with(this).load(imgUrl).centerCrop().into(iv1);
To set the scratch diagram and load failure diagram
Glide.with(context).load(datas.get(position)).placeholder(R.drawable.ic_launcher).error(R.drawable.error).centerCrop().crossFade().into(holder.iv);
Load cover diagram
In general, a cover chart can be a small picture or a low-pixel version.
Glide.with(this).load(url).thumbnail(Glide.with(this).load(thumbUrl)).centerCrop().into(iv2);
Loading pictures from other paths
Through the API we can see he's overloaded a lot of ways
There is also a custom load path
Loading pictures to other controls
This requirement is very common, for example, we need to load a background image for a linearlayout. which can be used to provide a custom target method
Glide.with(this).load(imgUrl).into(new SimpleTarget<GlideDrawable>() { @Override publicvoidonResourceReadysuper GlideDrawable> glideAnimation) { linearLayout.setBackgroundDrawable(resource); }});
Debugging information
These instructions can also be found on the official website
Turn on request response information
Executing in the terminal
shelllog.tag.GenericRequest DEBUG
After opening we can view the output of this information in Logcat
Turn on workflow logging
This means that you can see how the resources are found internally, for example, from memory, or from a disk or network.
shelllogshelllogshelllog.tag.DecodeJob VERBOSE
After opening, enter the following log information
Well, the basic use is here, the next one will be from the source of the point of view you familiar with glide, so it is also learning a master how to structure a project, and can also learn some glide advanced use, the above test code on my GitHub
Reference: http://www.open-open.com/lib/view/open1440397324450.html
On Google's recommended Android picture loading framework Glide