├── example
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.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
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── java
│ │ └── com
│ │ │ └── dyhdyh
│ │ │ └── support
│ │ │ └── glide
│ │ │ └── example
│ │ │ ├── SimpleGlideModule.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── glide-plus
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── dyhdyh
│ │ └── support
│ │ └── glide
│ │ ├── transformations
│ │ ├── CircleTransformation.java
│ │ ├── BitmapCircleTransformation.java
│ │ └── ImageWrapperTransformation.java
│ │ ├── resource
│ │ ├── gifbitmap
│ │ │ ├── ImageWrapperFileToStreamDecoder.java
│ │ │ ├── ImageWrapperResource.java
│ │ │ ├── ImageWrapper.java
│ │ │ ├── ImageWrapperDrawableTranscoder.java
│ │ │ ├── ImageWrapperStreamResourceDecoder.java
│ │ │ └── ImageWrapperResourceDecoder.java
│ │ └── decoder
│ │ │ └── StreamByteArrayResourceDecoder.java
│ │ ├── animator
│ │ ├── DrawableCrossFadeAnimator.java
│ │ └── DrawableScaleBounceAnimator.java
│ │ ├── gif
│ │ ├── transform
│ │ │ ├── GifDrawableCircleTransform.java
│ │ │ └── OverrideSizeTransform.java
│ │ └── resource
│ │ │ ├── GifResourceDecoder.java
│ │ │ └── GifDrawableResource.java
│ │ └── GlidePlus.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshot
├── screenshot.gif
├── example-compared.jpg
├── example-download.png
├── example-compared-small.jpg
└── example-compared-small.png
├── gradle.properties
├── .gitignore
├── LICENSE
├── config.gradle
├── README.md
├── gradlew.bat
└── gradlew
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/glide-plus/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':glide-plus'
2 |
--------------------------------------------------------------------------------
/screenshot/screenshot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/screenshot/screenshot.gif
--------------------------------------------------------------------------------
/screenshot/example-compared.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/screenshot/example-compared.jpg
--------------------------------------------------------------------------------
/screenshot/example-download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/screenshot/example-download.png
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | glide-support
3 |
4 |
--------------------------------------------------------------------------------
/screenshot/example-compared-small.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/screenshot/example-compared-small.jpg
--------------------------------------------------------------------------------
/screenshot/example-compared-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/screenshot/example-compared-small.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiandanin/GlidePlus/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 150dp
4 | 32dp
5 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/glide-plus/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/transformations/CircleTransformation.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.transformations;
2 |
3 | import android.content.Context;
4 |
5 | import com.dyhdyh.support.glide.gif.transform.GifDrawableCircleTransform;
6 |
7 | /**
8 | * gif圆形 bitmap圆形
9 | * author dengyuhan
10 | * created 2017/7/13 14:49
11 | */
12 | public class CircleTransformation extends ImageWrapperTransformation {
13 |
14 | public CircleTransformation(Context context) {
15 | super(new GifDrawableCircleTransform(), new BitmapCircleTransformation(context));
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/example/src/main/java/com/dyhdyh/support/glide/example/SimpleGlideModule.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.example;
2 |
3 | import android.content.Context;
4 |
5 | import com.bumptech.glide.Glide;
6 | import com.bumptech.glide.GlideBuilder;
7 | import com.bumptech.glide.load.DecodeFormat;
8 | import com.bumptech.glide.module.GlideModule;
9 |
10 | /**
11 | * author dengyuhan
12 | * created 2017/7/14 14:58
13 | */
14 | public class SimpleGlideModule implements GlideModule {
15 | @Override
16 | public void applyOptions(Context context, GlideBuilder builder) {
17 | builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
18 | }
19 |
20 | @Override
21 | public void registerComponents(Context context, Glide glide) {
22 | // nothing to do here
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/gifbitmap/ImageWrapperFileToStreamDecoder.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.gifbitmap;
2 |
3 | import android.content.Context;
4 |
5 | import com.bumptech.glide.load.ResourceDecoder;
6 | import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
7 |
8 | import java.io.InputStream;
9 |
10 | /**
11 | * author dengyuhan
12 | * created 2017/7/13 15:21
13 | */
14 | public class ImageWrapperFileToStreamDecoder extends FileToStreamDecoder {
15 | public ImageWrapperFileToStreamDecoder(Context context) {
16 | this(new ImageWrapperStreamResourceDecoder(context));
17 | }
18 |
19 | public ImageWrapperFileToStreamDecoder(ResourceDecoder streamDecoder) {
20 | super(streamDecoder);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/animator/DrawableCrossFadeAnimator.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.animator;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.view.View;
5 |
6 | import com.bumptech.glide.request.animation.ViewPropertyAnimation;
7 |
8 | /**
9 | * 淡入淡出动画
10 | * author dengyuhan
11 | * created 2017/3/30 17:31
12 | */
13 | public class DrawableCrossFadeAnimator implements ViewPropertyAnimation.Animator {
14 |
15 | private final int duration;
16 | private static final int DEFAULT_DURATION_MS = 300;
17 |
18 |
19 | public DrawableCrossFadeAnimator() {
20 | this(DEFAULT_DURATION_MS);
21 | }
22 |
23 | public DrawableCrossFadeAnimator(int duration) {
24 | this.duration = duration;
25 | }
26 |
27 | @Override
28 | public void animate(View view) {
29 | ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).setDuration(duration).start();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/example/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/dengyuhan/Library/dev/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 |
--------------------------------------------------------------------------------
/glide-plus/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/dengyuhan/Library/dev/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 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/gif/transform/GifDrawableCircleTransform.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.gif.transform;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapShader;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 |
8 | /**
9 | * 用于pl.droidsonroids.gif.Gifdrawable的圆形Transform
10 | * author dengyuhan
11 | * created 2017/7/12 16:10
12 | */
13 | public class GifDrawableCircleTransform extends OverrideSizeTransform {
14 |
15 | @Override
16 | public void onDraw(Canvas canvas, Paint paint, Bitmap buffer, int outWidth, int outHeight) {
17 | int width = buffer.getWidth();
18 | int height = buffer.getHeight();
19 |
20 | int size = Math.min(width, height);
21 |
22 | BitmapShader shader = new BitmapShader(buffer, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
23 | paint.setShader(shader);
24 | paint.setAntiAlias(true);
25 |
26 | float r = size / 2f;
27 |
28 | canvas.drawCircle(width / 2f, height / 2f, r, paint);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 dengyuhan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | android =
3 | [
4 | versionCode : 4,
5 | versionName : "1.0.3",
6 |
7 | compileSdkVersion: 25,
8 | buildToolsVersion: "25.0.2",
9 | minSdkVersion : 14,
10 | targetSdkVersion : 25,
11 | supportVersion : "25.3.0",
12 | ]
13 |
14 | jcenter =
15 | [
16 | //项目名称
17 | name : "GlidePlus",
18 | groupId : "com.dyhdyh.support",
19 | //项目地址
20 | siteUrl : "https://github.com/dengyuhan/GlidePlus",
21 | //项目git地址
22 | gitUrl : "https://github.com/dengyuhan/GlidePlus.git",
23 | //项目描述
24 | description: "Glide增强版,强化对GIF的支持",
25 | //开发者的一些基本信息
26 | authorId : "dengyuhan",
27 | authorName : "dengyuhan",
28 | authorEmail: "22309946@qq.com",
29 | ]
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.android.compileSdkVersion
5 | buildToolsVersion rootProject.ext.android.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.dyhdyh.support.glide.example"
9 | minSdkVersion rootProject.ext.android.minSdkVersion
10 | targetSdkVersion rootProject.ext.android.targetSdkVersion
11 | versionCode rootProject.ext.android.targetSdkVersion
12 | versionName rootProject.ext.android.versionName
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:25.3.1'
25 | compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
26 | compile 'com.github.chrisbanes:PhotoView:2.0.0'
27 | compile project(':glide-plus')
28 | compile 'com.android.support:recyclerview-v7:25.3.1'
29 | }
30 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/gif/resource/GifResourceDecoder.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.gif.resource;
2 |
3 | import com.bumptech.glide.load.ResourceDecoder;
4 | import com.bumptech.glide.load.engine.Resource;
5 | import com.dyhdyh.support.glide.resource.decoder.StreamByteArrayResourceDecoder;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 |
10 | import pl.droidsonroids.gif.GifDrawable;
11 |
12 | /**
13 | * author dengyuhan
14 | * created 2017/7/13 12:07
15 | */
16 | public class GifResourceDecoder implements ResourceDecoder {
17 |
18 | private StreamByteArrayResourceDecoder mByteDecoder = new StreamByteArrayResourceDecoder();
19 |
20 | @Override
21 | public Resource decode(InputStream source, int width, int height) throws IOException {
22 | byte[] bytes = mByteDecoder.decode(source, width, height).get();
23 | GifDrawable gifDrawable = new GifDrawable(bytes);
24 | gifDrawable.setLoopCount(0);
25 | return new GifDrawableResource(gifDrawable, bytes);
26 | }
27 |
28 | @Override
29 | public String getId() {
30 | return getClass().getName();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/gif/transform/OverrideSizeTransform.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.gif.transform;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Rect;
7 |
8 | import pl.droidsonroids.gif.transforms.Transform;
9 |
10 | /**
11 | * author dengyuhan
12 | * created 2017/7/13 14:24
13 | */
14 | public abstract class OverrideSizeTransform implements Transform {
15 | public static final int ORIGINAL_WIDTH = 0;
16 | public static final int ORIGINAL_HEIGHT = 0;
17 |
18 | private int mOutWidth = ORIGINAL_WIDTH;
19 | private int mOutHeight = ORIGINAL_HEIGHT;
20 |
21 | @Override
22 | public void onBoundsChange(Rect bounds) {
23 |
24 | }
25 |
26 | @Override
27 | public void onDraw(Canvas canvas, Paint paint, Bitmap buffer) {
28 | this.onDraw(canvas, paint, buffer, mOutWidth, mOutHeight);
29 | }
30 |
31 | public OverrideSizeTransform setDrawSize(int outWidth, int outHeight) {
32 | this.mOutWidth = outWidth;
33 | this.mOutHeight = outHeight;
34 | return this;
35 | }
36 |
37 | public abstract void onDraw(Canvas canvas, Paint paint, Bitmap buffer, int outWidth, int outHeight);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/gifbitmap/ImageWrapperResource.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.gifbitmap;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.bumptech.glide.load.engine.Resource;
6 |
7 | import pl.droidsonroids.gif.GifDrawable;
8 |
9 | /**
10 | * A resource that wraps an {@link ImageWrapper}.
11 | */
12 | public class ImageWrapperResource implements Resource {
13 | private final ImageWrapper data;
14 |
15 | public ImageWrapperResource(ImageWrapper data) {
16 | if (data == null) {
17 | throw new NullPointerException("Data must not be null");
18 | }
19 | this.data = data;
20 | }
21 |
22 | @Override
23 | public ImageWrapper get() {
24 | return data;
25 | }
26 |
27 | @Override
28 | public int getSize() {
29 | return data.getSize();
30 | }
31 |
32 | @Override
33 | public void recycle() {
34 | Resource bitmapResource = data.getBitmapResource();
35 | if (bitmapResource != null) {
36 | bitmapResource.recycle();
37 | }
38 | Resource gifDataResource = data.getGifResource();
39 | if (gifDataResource != null) {
40 | gifDataResource.recycle();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/animator/DrawableScaleBounceAnimator.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.animator;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.PropertyValuesHolder;
5 | import android.view.View;
6 | import android.view.animation.BounceInterpolator;
7 |
8 | import com.bumptech.glide.request.animation.ViewPropertyAnimation;
9 |
10 | /**
11 | * 缩放弹性动画
12 | * author dengyuhan
13 | * created 2017/3/30 17:31
14 | */
15 | public class DrawableScaleBounceAnimator implements ViewPropertyAnimation.Animator {
16 |
17 | private final int duration;
18 | private static final int DEFAULT_DURATION_MS = 800;
19 |
20 |
21 | public DrawableScaleBounceAnimator() {
22 | this(DEFAULT_DURATION_MS);
23 | }
24 |
25 | public DrawableScaleBounceAnimator(int duration) {
26 | this.duration = duration;
27 | }
28 |
29 | @Override
30 | public void animate(View view) {
31 | ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view,
32 | PropertyValuesHolder.ofFloat("scaleX", 0f, 1f),
33 | PropertyValuesHolder.ofFloat("scaleY", 0f, 1f))
34 | .setDuration(duration);
35 | animator.setInterpolator(new BounceInterpolator());
36 | animator.start();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
14 |
21 |
22 |
28 |
29 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/gifbitmap/ImageWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.gifbitmap;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.bumptech.glide.load.engine.Resource;
6 |
7 | import pl.droidsonroids.gif.GifDrawable;
8 |
9 | /**
10 | * author dengyuhan
11 | * created 2017/7/12 15:25
12 | */
13 | public class ImageWrapper {
14 | private final Resource gifResource;
15 | private final Resource bitmapResource;
16 |
17 | public ImageWrapper(Resource bitmapResource, Resource gifResource) {
18 | if (bitmapResource != null && gifResource != null) {
19 | throw new IllegalArgumentException("Can only contain either a bitmap resource or a gif resource, not both");
20 | } else if (bitmapResource == null && gifResource == null) {
21 | throw new IllegalArgumentException("Must contain either a bitmap resource or a gif resource");
22 | } else {
23 | this.bitmapResource = bitmapResource;
24 | this.gifResource = gifResource;
25 | }
26 | }
27 |
28 | public int getSize() {
29 | return this.bitmapResource != null ? this.bitmapResource.getSize() : this.gifResource.getSize();
30 | }
31 |
32 | public Resource getBitmapResource() {
33 | return this.bitmapResource;
34 | }
35 |
36 | public Resource getGifResource() {
37 | return this.gifResource;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/gif/resource/GifDrawableResource.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.gif.resource;
2 |
3 | import com.bumptech.glide.load.engine.Resource;
4 |
5 | import pl.droidsonroids.gif.GifDrawable;
6 | import pl.droidsonroids.gif.transforms.Transform;
7 |
8 | /**
9 | * author dengyuhan
10 | * created 2017/7/13 14:58
11 | */
12 | public class GifDrawableResource implements Resource {
13 | private GifDrawable drawable;
14 | private byte[] data;
15 | private Transform gifTransform;
16 |
17 | public GifDrawableResource(GifDrawable gifDrawable, byte[] data) {
18 | this.drawable = gifDrawable;
19 | this.data = data;
20 | }
21 |
22 | @Override
23 | public GifDrawable get() {
24 | try {
25 | GifDrawable newDrawable = new GifDrawable(data);
26 | newDrawable.setLoopCount(drawable.getLoopCount());
27 | newDrawable.setTransform(gifTransform);
28 | return newDrawable;
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | return drawable;
32 | }
33 | }
34 |
35 | public void setGifTransform(Transform gifTransform) {
36 | this.gifTransform = gifTransform;
37 | }
38 |
39 | @Override
40 | public int getSize() {
41 | return (int) drawable.getInputSourceByteCount();
42 | }
43 |
44 | @Override
45 | public void recycle() {
46 | drawable.stop();
47 | drawable.recycle();
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/decoder/StreamByteArrayResourceDecoder.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.decoder;
2 |
3 | import android.util.Log;
4 |
5 | import com.bumptech.glide.load.ResourceDecoder;
6 | import com.bumptech.glide.load.engine.Resource;
7 | import com.bumptech.glide.load.resource.bytes.BytesResource;
8 |
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 |
13 | /**
14 | * author dengyuhan
15 | * created 2017/7/13 15:02
16 | */
17 | public class StreamByteArrayResourceDecoder implements ResourceDecoder {
18 | private final String TAG = "StreamByteDecoder";
19 |
20 | @Override
21 | public Resource decode(InputStream source, int width, int height) throws IOException {
22 | return new BytesResource(inputStreamToBytes(source));
23 | }
24 |
25 | private byte[] inputStreamToBytes(InputStream is) {
26 | final int bufferSize = 16384;
27 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(bufferSize);
28 | try {
29 | int nRead;
30 | byte[] data = new byte[bufferSize];
31 | while ((nRead = is.read(data)) != -1) {
32 | buffer.write(data, 0, nRead);
33 | }
34 | buffer.flush();
35 | } catch (IOException e) {
36 | Log.w(TAG, "Error reading data from stream", e);
37 | }
38 | //TODO the returned byte[] may be partial if an IOException was thrown from read
39 | return buffer.toByteArray();
40 | }
41 |
42 | @Override
43 | public String getId() {
44 | return getClass().getName();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 本项目已过时,Glide4.0后对GIF已经有很好的支持
2 |
3 |
4 |
5 | 基于[glide](https://github.com/bumptech/glide)与
6 | [android-gif-drawable](https://github.com/koral--/android-gif-drawable)对Glide处理Gif进行加强
7 |
8 | ## __示例apk__
9 | 
10 |
11 | ## __快速开始__
12 | #### Gradle
13 | ```
14 | compile 'com.dyhdyh.support:glide-plus:1.0.1'
15 | compile 'com.github.bumptech.glide:glide:3.7.0'
16 | ```
17 |
18 | #### 示例
19 | ```
20 | GlidePlus.with(this)
21 | .gifPlus()//开启gif增强
22 | .circle()//圆形
23 | //.crossFade()//淡入淡出(默认开启)
24 | //.transform(new ImageWrapperCircleTransformation())
25 | //.animate(new DrawableScaleBounceAnimator())
26 | .glide()
27 | .load(url)
28 | .placeholder(R.mipmap.placeholder)
29 | .error(R.mipmap.error)
30 | .into(iv);
31 | ```
32 |
33 | ## __效果__
34 | 
35 |
36 | ## __对比图__
37 | 
38 |
39 | ## __在RecyclerView中使用的注意事项__
40 | 1.重写Adapter中`onViewDetachedFromWindow`与`onViewAttachedToWindow`,在Item出屏的时候暂停播放gif,进屏的时候再播放gif,这样可以节省一些性能。
41 |
42 | ```
43 | @Override
44 | public void onViewDetachedFromWindow(ViewHolder holder) {
45 | Drawable drawable = holder.iv.getDrawable();
46 | if (drawable instanceof pl.droidsonroids.gif.GifDrawable){
47 | ((pl.droidsonroids.gif.GifDrawable) drawable).pause();
48 | }
49 | }
50 |
51 | @Override
52 | public void onViewAttachedToWindow(ViewHolder holder) {
53 | Drawable drawable = holder.iv.getDrawable();
54 | if (drawable instanceof pl.droidsonroids.gif.GifDrawable){
55 | ((pl.droidsonroids.gif.GifDrawable) drawable).start();
56 | }
57 | }
58 | ```
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/gifbitmap/ImageWrapperDrawableTranscoder.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.gifbitmap;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.drawable.Drawable;
6 |
7 | import com.bumptech.glide.load.engine.Resource;
8 | import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
9 | import com.bumptech.glide.load.resource.transcode.GlideBitmapDrawableTranscoder;
10 | import com.bumptech.glide.load.resource.transcode.ResourceTranscoder;
11 |
12 | /**
13 | * An com.bumptech.glide.load.resource.transcode.ResourceTranscoder that can transcode either an
14 | * {@link Bitmap} or an pl.droidsonroids.gif.GifDrawable into an
15 | * {@link android.graphics.drawable.Drawable}.
16 | */
17 | public class ImageWrapperDrawableTranscoder implements ResourceTranscoder {
18 | private final ResourceTranscoder bitmapDrawableResourceTranscoder;
19 |
20 | public ImageWrapperDrawableTranscoder(Context context) {
21 | this(new GlideBitmapDrawableTranscoder(context));
22 | }
23 |
24 | public ImageWrapperDrawableTranscoder(
25 | ResourceTranscoder bitmapDrawableResourceTranscoder) {
26 | this.bitmapDrawableResourceTranscoder = bitmapDrawableResourceTranscoder;
27 | }
28 |
29 | @SuppressWarnings("unchecked")
30 | @Override
31 | public Resource transcode(Resource toTranscode) {
32 | ImageWrapper gifBitmap = toTranscode.get();
33 | Resource bitmapResource = gifBitmap.getBitmapResource();
34 |
35 | final Resource extends Drawable> result;
36 | if (bitmapResource != null) {
37 | result = bitmapDrawableResourceTranscoder.transcode(bitmapResource);
38 | } else {
39 | result = gifBitmap.getGifResource();
40 | }
41 | // This is unchecked but always safe, anything that extends a Drawable can be safely cast to a Drawable.
42 | return (Resource) result;
43 | }
44 |
45 | @Override
46 | public String getId() {
47 | return getClass().getName();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/gifbitmap/ImageWrapperStreamResourceDecoder.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.gifbitmap;
2 |
3 | import android.content.Context;
4 |
5 | import com.bumptech.glide.Glide;
6 | import com.bumptech.glide.load.ResourceDecoder;
7 | import com.bumptech.glide.load.engine.Resource;
8 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
9 | import com.bumptech.glide.load.model.ImageVideoWrapper;
10 | import com.bumptech.glide.load.resource.bitmap.FileDescriptorBitmapDecoder;
11 | import com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder;
12 | import com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder;
13 | import com.dyhdyh.support.glide.gif.resource.GifResourceDecoder;
14 |
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 |
18 | /**
19 | * A com.bumptech.glide.load.ResourceDecoder that can decode an
20 | * {@link ImageWrapper} from {@link InputStream} data.
21 | */
22 | public class ImageWrapperStreamResourceDecoder implements ResourceDecoder {
23 | private final ResourceDecoder gifBitmapDecoder;
24 |
25 | public ImageWrapperStreamResourceDecoder(Context context) {
26 | StreamBitmapDecoder streamBitmapDecoder = new StreamBitmapDecoder(context);
27 | FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(context);
28 | ImageVideoBitmapDecoder imageVideoBitmapDecoder = new ImageVideoBitmapDecoder(streamBitmapDecoder, fileDescriptorBitmapDecoder);
29 | GifResourceDecoder gifResourceDecoder = new GifResourceDecoder();
30 | BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
31 | this.gifBitmapDecoder = new ImageWrapperResourceDecoder(imageVideoBitmapDecoder, gifResourceDecoder, bitmapPool);
32 | }
33 |
34 | public ImageWrapperStreamResourceDecoder(
35 | ResourceDecoder gifBitmapDecoder) {
36 | this.gifBitmapDecoder = gifBitmapDecoder;
37 | }
38 |
39 | @Override
40 | public Resource decode(InputStream source, int width, int height) throws IOException {
41 | return gifBitmapDecoder.decode(new ImageVideoWrapper(source, null), width, height);
42 | }
43 |
44 | @Override
45 | public String getId() {
46 | return gifBitmapDecoder.getId();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/transformations/BitmapCircleTransformation.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.transformations;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapShader;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.bumptech.glide.load.Transformation;
12 | import com.bumptech.glide.load.engine.Resource;
13 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
14 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
15 |
16 | /**
17 | * bitmap圆形
18 | * author dengyuhan
19 | * created 2017/7/13 14:51
20 | */
21 | public class BitmapCircleTransformation implements Transformation {
22 |
23 | private BitmapPool mBitmapPool;
24 |
25 | public BitmapCircleTransformation(Context context) {
26 | this(Glide.get(context).getBitmapPool());
27 | }
28 |
29 | public BitmapCircleTransformation(BitmapPool pool) {
30 | this.mBitmapPool = pool;
31 | }
32 |
33 | @Override
34 | public Resource transform(Resource resource, int outWidth, int outHeight) {
35 | Bitmap source = resource.get();
36 | int size = Math.min(source.getWidth(), source.getHeight());
37 |
38 | int width = (source.getWidth() - size) / 2;
39 | int height = (source.getHeight() - size) / 2;
40 |
41 | Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
42 | if (bitmap == null) {
43 | bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
44 | }
45 |
46 | Canvas canvas = new Canvas(bitmap);
47 | Paint paint = new Paint();
48 | BitmapShader shader =
49 | new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
50 | if (width != 0 || height != 0) {
51 | Matrix matrix = new Matrix();
52 | matrix.setTranslate(-width, -height);
53 | shader.setLocalMatrix(matrix);
54 | }
55 | paint.setShader(shader);
56 | paint.setAntiAlias(true);
57 |
58 | float r = size / 2f;
59 | canvas.drawCircle(r, r, r, paint);
60 |
61 | return BitmapResource.obtain(bitmap, mBitmapPool);
62 | }
63 |
64 | @Override
65 | public String getId() {
66 | return getClass().getName();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/transformations/ImageWrapperTransformation.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.transformations;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.bumptech.glide.load.Transformation;
6 | import com.bumptech.glide.load.engine.Resource;
7 | import com.dyhdyh.support.glide.gif.resource.GifDrawableResource;
8 | import com.dyhdyh.support.glide.gif.transform.OverrideSizeTransform;
9 | import com.dyhdyh.support.glide.resource.gifbitmap.ImageWrapper;
10 | import com.dyhdyh.support.glide.resource.gifbitmap.ImageWrapperResource;
11 |
12 | import pl.droidsonroids.gif.GifDrawable;
13 | import pl.droidsonroids.gif.transforms.Transform;
14 |
15 | /**
16 | * 包装gif bitmap支持glide的Transformation
17 | * author dengyuhan
18 | * created 2017/7/13 14:38
19 | */
20 | public abstract class ImageWrapperTransformation implements Transformation {
21 | private Transform mGifTransform;
22 | private Transformation mBitmapTransformation;
23 |
24 | public ImageWrapperTransformation(Transform gifTransform, Transformation bitmapTransformation) {
25 | this.mGifTransform = gifTransform;
26 | this.mBitmapTransformation = bitmapTransformation;
27 | }
28 |
29 | @Override
30 | public Resource transform(Resource resource, int outWidth, int outHeight) {
31 | ImageWrapper gifBitmapWrapper = resource.get();
32 | Resource bitmapResource = gifBitmapWrapper.getBitmapResource();
33 | if (bitmapResource != null) {
34 | Resource transform = mBitmapTransformation.transform(bitmapResource, outWidth, outHeight);
35 | return new ImageWrapperResource(new ImageWrapper(transform, gifBitmapWrapper.getGifResource()));
36 | }
37 |
38 | Resource gifResource = gifBitmapWrapper.getGifResource();
39 | if (gifResource != null) {
40 | if (mGifTransform instanceof OverrideSizeTransform) {
41 | ((OverrideSizeTransform) mGifTransform).setDrawSize(outWidth, outHeight);
42 | }
43 | if (gifResource instanceof GifDrawableResource){
44 | ((GifDrawableResource) gifResource).setGifTransform(mGifTransform);
45 | }else{
46 | gifResource.get().setTransform(mGifTransform);
47 | }
48 | }
49 | return resource;
50 | }
51 |
52 | @Override
53 | public String getId() {
54 | return getClass().getName();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
14 |
15 |
21 |
22 |
28 |
29 |
35 |
36 |
42 |
43 |
44 |
48 |
49 |
54 |
55 |
56 |
57 |
61 |
62 |
65 |
66 |
67 |
68 |
69 |
73 |
74 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/GlidePlus.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 |
6 | import com.bumptech.glide.GenericRequestBuilder;
7 | import com.bumptech.glide.Glide;
8 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
9 | import com.bumptech.glide.load.model.StreamEncoder;
10 | import com.bumptech.glide.load.model.stream.StreamStringLoader;
11 | import com.bumptech.glide.request.animation.ViewPropertyAnimation;
12 | import com.dyhdyh.support.glide.animator.DrawableCrossFadeAnimator;
13 | import com.dyhdyh.support.glide.resource.gifbitmap.ImageWrapper;
14 | import com.dyhdyh.support.glide.resource.gifbitmap.ImageWrapperDrawableTranscoder;
15 | import com.dyhdyh.support.glide.resource.gifbitmap.ImageWrapperFileToStreamDecoder;
16 | import com.dyhdyh.support.glide.resource.gifbitmap.ImageWrapperStreamResourceDecoder;
17 | import com.dyhdyh.support.glide.transformations.CircleTransformation;
18 | import com.dyhdyh.support.glide.transformations.ImageWrapperTransformation;
19 |
20 | import java.io.InputStream;
21 |
22 | /**
23 | * author dengyuhan
24 | * created 2017/7/13 16:17
25 | */
26 | public class GlidePlus {
27 |
28 | private GenericRequestBuilder mRequestBuilder;
29 | private Context mContext;
30 |
31 | public GlidePlus(Context context) {
32 | this.mContext = context;
33 | }
34 |
35 | public static GlidePlus with(Context context) {
36 | return new GlidePlus(context);
37 | }
38 |
39 | /**
40 | * Gif增强
41 | *
42 | * @return
43 | */
44 | public GlidePlus gifPlus() {
45 | mRequestBuilder = Glide.with(mContext)
46 | .using(new StreamStringLoader(mContext), InputStream.class)
47 | .from(String.class)
48 | .as(ImageWrapper.class)
49 | .transcode(new ImageWrapperDrawableTranscoder(mContext), Drawable.class)
50 | .decoder(new ImageWrapperStreamResourceDecoder(mContext))
51 | .cacheDecoder(new ImageWrapperFileToStreamDecoder(mContext))
52 | .sourceEncoder(new StreamEncoder())
53 | .animate(new DrawableCrossFadeAnimator())
54 | .diskCacheStrategy(DiskCacheStrategy.SOURCE);
55 | return this;
56 | }
57 |
58 |
59 | /**
60 | * 淡出淡出动画
61 | *
62 | * @return
63 | */
64 | public GlidePlus crossFade() {
65 | mRequestBuilder.animate(new DrawableCrossFadeAnimator());
66 | return this;
67 | }
68 |
69 | /**
70 | * 圆形
71 | *
72 | * @return
73 | */
74 | public GlidePlus circle() {
75 | mRequestBuilder.transform(new CircleTransformation(mContext));
76 | return this;
77 | }
78 |
79 |
80 | public GlidePlus transform(ImageWrapperTransformation transformation) {
81 | mRequestBuilder.transform(transformation);
82 | return this;
83 | }
84 |
85 |
86 | public GlidePlus animate(ViewPropertyAnimation.Animator animator) {
87 | mRequestBuilder.animate(animator);
88 | return this;
89 | }
90 |
91 |
92 | public GenericRequestBuilder glide() {
93 | return mRequestBuilder;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/example/src/main/java/com/dyhdyh/support/glide/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.example;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 |
9 | import com.bumptech.glide.Glide;
10 | import com.dyhdyh.support.glide.GlidePlus;
11 | import com.dyhdyh.support.glide.transformations.BitmapCircleTransformation;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 | ImageView iv_glide;
15 | ImageView iv_gif;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | iv_glide = (ImageView) findViewById(R.id.iv_glide);
22 | iv_gif = (ImageView) findViewById(R.id.iv_gif);
23 | }
24 |
25 |
26 | public void clickBitmap(View v) {
27 | //String url = "http://img2.imgtn.bdimg.com/it/u=848366370,4290604224&fm=26&gp=0.jpg";
28 | //String url="http://img3.duitang.com/uploads/item/201407/18/20140718155834_NMS23.jpeg";
29 | String url = "http://dl.bizhi.sogou.com/images/2012/03/07/70401.jpg";
30 | loadGlide(url);
31 | }
32 |
33 | public void clickGif(View v) {
34 | //500*309
35 | String url = "http://imgs.ebrun.com/resources/2016_08/2016_08_12/201608128571470994130828.gif";
36 | //600*250
37 | //String url="http://img208.poco.cn/mypoco/myphoto/20110620/23/53838356201106202249241923418303298_000.gif";
38 |
39 | //400*400
40 | //String url = "http://www.cheerinus.com/upload_files/qb_news_/95/68143_20160528050505_fttee.gif";
41 | //600*600
42 | //String url="http://payload345.cargocollective.com/1/0/19261/9211166/random_ani_buns_600x600.gif";
43 |
44 | //400*800
45 | //String url="http://www.cheerinus.com/upload_files/qb_news_/95/68143_20160528050505_fttee.gif";
46 |
47 | //背景透明
48 | //String url="http://i4.piimg.com/1949/448259b71240aa90.gif";
49 | loadGlide(url);
50 | }
51 |
52 |
53 | public void clickLongGif(View v) {
54 | String url = "http://www.poluoluo.com/qq/UploadFiles_7828/201410/20141022210900574.gif";
55 | loadGlide(url);
56 | }
57 |
58 | public void clickBigGif(View v) {
59 | String url = "http://i2.kiimg.com/1949/7e171c3a397062e0.gif";
60 | loadGlide(url);
61 | }
62 |
63 |
64 | private void loadGlide(String url) {
65 | int radius = getResources().getDimensionPixelSize(R.dimen.rounded_corners);
66 | Glide.with(this)
67 | .load(url)
68 | .bitmapTransform(new BitmapCircleTransformation(this))//圆形
69 | .crossFade()//淡入淡出
70 | .placeholder(R.mipmap.ic_launcher)
71 | .error(R.mipmap.ic_launcher_round)
72 | .into(iv_glide);
73 |
74 | GlidePlus.with(this)
75 | .gifPlus()//开启gif增强
76 | .circle()//圆形
77 | //.crossFade()//淡入淡出(默认开启)
78 | //.animate(new DrawableScaleBounceAnimator())
79 | .glide()
80 | .load(url)
81 | .placeholder(R.mipmap.ic_launcher)
82 | .error(R.mipmap.ic_launcher_round)
83 | .into(iv_gif);
84 | }
85 |
86 |
87 | public void clickRecyclerView(View v) {
88 | startActivity(new Intent(this,GifRecyclerActivity.class));
89 | }
90 |
91 |
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/glide-plus/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | apply plugin: 'com.jfrog.bintray'
5 |
6 | version = rootProject.ext.android.versionName
7 | group = rootProject.ext.jcenter.groupId
8 |
9 | android {
10 | compileSdkVersion rootProject.ext.android.compileSdkVersion
11 | buildToolsVersion rootProject.ext.android.buildToolsVersion
12 |
13 | defaultConfig {
14 | minSdkVersion rootProject.ext.android.minSdkVersion
15 | targetSdkVersion rootProject.ext.android.targetSdkVersion
16 | versionCode rootProject.ext.android.targetSdkVersion
17 | versionName rootProject.ext.android.versionName
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile 'com.android.support:appcompat-v7:25.3.1'
30 | compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
31 | compile 'com.github.bumptech.glide:glide:3.7.0'
32 | }
33 |
34 |
35 | install {
36 | repositories.mavenInstaller {
37 | pom {
38 | project {
39 | packaging 'aar'
40 | name rootProject.ext.jcenter.description
41 | url rootProject.ext.jcenter.siteUrl
42 | licenses {
43 | license {
44 | name 'The Apache Software License, Version 2.0'
45 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
46 | }
47 | }
48 | developers {
49 | developer {
50 | id rootProject.ext.jcenter.authorId
51 | name rootProject.ext.jcenter.authorName
52 | email rootProject.ext.jcenter.authorEmail
53 | }
54 | }
55 | scm {
56 | connection rootProject.ext.jcenter.gitUrl
57 | developerConnection rootProject.ext.jcenter.gitUrl
58 | url rootProject.ext.jcenter.siteUrl
59 | }
60 | }
61 | }
62 | }
63 | }
64 |
65 | // 生成jar包的task
66 | task sourcesJar(type: Jar) {
67 | from android.sourceSets.main.java.srcDirs
68 | classifier = 'sources'
69 | }
70 |
71 | // 生成javaDoc的jar
72 | task javadoc(type: Javadoc) {
73 | source = android.sourceSets.main.java.srcDirs
74 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
75 | }
76 | task javadocJar(type: Jar, dependsOn: javadoc) {
77 | classifier = 'javadoc'
78 | from javadoc.destinationDir
79 | }
80 | artifacts {
81 | archives javadocJar
82 | archives sourcesJar
83 | }
84 |
85 | //设置编码格式,如果不设置可能会在gradlew install的时候出现GBK编码映射错误
86 | javadoc {
87 | options {
88 | encoding "UTF-8"
89 | charSet 'UTF-8'
90 | author true
91 | version true
92 | links "http://docs.oracle.com/javase/8/docs/api"
93 | }
94 | }
95 | Properties properties = new Properties()
96 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
97 | bintray {
98 | user = properties.getProperty("bintray.user")
99 | key = properties.getProperty("bintray.apikey")
100 | configurations = ['archives']
101 | pkg {
102 | repo = "maven"
103 | name = rootProject.ext.jcenter.name
104 | websiteUrl = rootProject.ext.jcenter.siteUrl
105 | vcsUrl = rootProject.ext.jcenter.gitUrl
106 | licenses = ["Apache-2.0"]
107 | publish = true
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/glide-plus/src/main/java/com/dyhdyh/support/glide/resource/gifbitmap/ImageWrapperResourceDecoder.java:
--------------------------------------------------------------------------------
1 | package com.dyhdyh.support.glide.resource.gifbitmap;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.bumptech.glide.load.ResourceDecoder;
6 | import com.bumptech.glide.load.engine.Resource;
7 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
8 | import com.bumptech.glide.load.model.ImageVideoWrapper;
9 | import com.bumptech.glide.load.resource.bitmap.BitmapResource;
10 | import com.bumptech.glide.load.resource.bitmap.ImageHeaderParser;
11 | import com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream;
12 | import com.bumptech.glide.util.ByteArrayPool;
13 |
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 |
17 | import pl.droidsonroids.gif.GifDrawable;
18 |
19 | /**
20 | * An com.bumptech.glide.load.ResourceDecoder that can decode either an {@link Bitmap} or an pl.droidsonroids.gif.GifDrawable
21 | * from an {@link InputStream} or a {@link android.os.ParcelFileDescriptor ParcelFileDescriptor}.
22 | */
23 | public class ImageWrapperResourceDecoder implements ResourceDecoder {
24 | private static final ImageTypeParser DEFAULT_PARSER = new ImageTypeParser();
25 | private static final BufferedStreamFactory DEFAULT_STREAM_FACTORY = new BufferedStreamFactory();
26 | // 2048 is rather arbitrary, for most well formatted image types we only need 32 bytes.
27 | // Visible for testing.
28 | static final int MARK_LIMIT_BYTES = 2048;
29 |
30 | private final ResourceDecoder bitmapDecoder;
31 | private final ResourceDecoder gifDecoder;
32 | private final BitmapPool bitmapPool;
33 | private final ImageTypeParser parser;
34 | private final BufferedStreamFactory streamFactory;
35 | private String id;
36 |
37 | public ImageWrapperResourceDecoder(ResourceDecoder bitmapDecoder,
38 | ResourceDecoder gifDecoder, BitmapPool bitmapPool) {
39 | this(bitmapDecoder, gifDecoder, bitmapPool, DEFAULT_PARSER, DEFAULT_STREAM_FACTORY);
40 | }
41 |
42 | // Visible for testing.
43 | ImageWrapperResourceDecoder(ResourceDecoder bitmapDecoder,
44 | ResourceDecoder gifDecoder, BitmapPool bitmapPool, ImageTypeParser parser,
45 | BufferedStreamFactory streamFactory) {
46 | this.bitmapDecoder = bitmapDecoder;
47 | this.gifDecoder = gifDecoder;
48 | this.bitmapPool = bitmapPool;
49 | this.parser = parser;
50 | this.streamFactory = streamFactory;
51 | }
52 |
53 | @SuppressWarnings("resource")
54 | // @see ResourceDecoder.decode
55 | @Override
56 | public Resource decode(ImageVideoWrapper source, int width, int height) throws IOException {
57 | ByteArrayPool pool = ByteArrayPool.get();
58 | byte[] tempBytes = pool.getBytes();
59 |
60 | ImageWrapper wrapper = null;
61 | try {
62 | wrapper = decode(source, width, height, tempBytes);
63 | } finally {
64 | pool.releaseBytes(tempBytes);
65 | }
66 | return wrapper != null ? new ImageWrapperResource(wrapper) : null;
67 | }
68 |
69 | private ImageWrapper decode(ImageVideoWrapper source, int width, int height, byte[] bytes) throws IOException {
70 | final ImageWrapper result;
71 | if (source.getStream() != null) {
72 | result = decodeStream(source, width, height, bytes);
73 | } else {
74 | result = decodeBitmapWrapper(source, width, height);
75 | }
76 | return result;
77 | }
78 |
79 | private ImageWrapper decodeStream(ImageVideoWrapper source, int width, int height, byte[] bytes)
80 | throws IOException {
81 | InputStream bis = streamFactory.build(source.getStream(), bytes);
82 | bis.mark(MARK_LIMIT_BYTES);
83 | ImageHeaderParser.ImageType type = parser.parse(bis);
84 | bis.reset();
85 |
86 | ImageWrapper result = null;
87 | if (type == ImageHeaderParser.ImageType.GIF) {
88 | result = decodeGifWrapper(bis, width, height);
89 | }
90 | // Decoding the gif may fail even if the type matches.
91 | if (result == null) {
92 | // We can only reset the buffered InputStream, so to start from the beginning of the stream, we need to
93 | // pass in a new source containing the buffered stream rather than the original stream.
94 | ImageVideoWrapper forBitmapDecoder = new ImageVideoWrapper(bis, source.getFileDescriptor());
95 | result = decodeBitmapWrapper(forBitmapDecoder, width, height);
96 | }
97 | return result;
98 | }
99 |
100 | private ImageWrapper decodeGifWrapper(InputStream bis, int width, int height) throws IOException {
101 | ImageWrapper result = null;
102 | Resource gifResource = gifDecoder.decode(bis, width, height);
103 | if (gifResource != null) {
104 | GifDrawable drawable = gifResource.get();
105 | // We can more efficiently hold Bitmaps in memory, so for static GIFs, try to return Bitmaps
106 | // instead. Returning a Bitmap incurs the cost of allocating the GifDrawable as well as the normal
107 | // Bitmap allocation, but since we can encode the Bitmap out as a JPEG, future decodes will be
108 | // efficient.
109 | if (drawable.getNumberOfFrames() > 1) {
110 | result = new ImageWrapper(null /*bitmapResource*/, gifResource);
111 | } else {
112 | Resource bitmapResource = new BitmapResource(drawable.getCurrentFrame(), bitmapPool);
113 | result = new ImageWrapper(bitmapResource, null /*gifResource*/);
114 | }
115 | }
116 | return result;
117 | }
118 |
119 | private ImageWrapper decodeBitmapWrapper(ImageVideoWrapper toDecode, int width, int height) throws IOException {
120 | ImageWrapper result = null;
121 |
122 | Resource bitmapResource = bitmapDecoder.decode(toDecode, width, height);
123 | if (bitmapResource != null) {
124 | result = new ImageWrapper(bitmapResource, null);
125 | }
126 |
127 | return result;
128 | }
129 |
130 | @Override
131 | public String getId() {
132 | if (id == null) {
133 | id = gifDecoder.getId() + bitmapDecoder.getId();
134 | }
135 | return id;
136 | }
137 |
138 | // Visible for testing.
139 | static class BufferedStreamFactory {
140 | public InputStream build(InputStream is, byte[] buffer) {
141 | return new RecyclableBufferedInputStream(is, buffer);
142 | }
143 | }
144 |
145 | // Visible for testing.
146 | static class ImageTypeParser {
147 | public ImageHeaderParser.ImageType parse(InputStream is) throws IOException {
148 | return new ImageHeaderParser(is).getType();
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------