Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
6d166ad3
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6d166ad3
编写于
8月 21, 2017
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add javadocs for Registry.
Work toward #2193.
上级
32313e35
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
156 addition
and
14 deletion
+156
-14
library/src/main/java/com/bumptech/glide/Registry.java
library/src/main/java/com/bumptech/glide/Registry.java
+156
-14
未找到文件。
library/src/main/java/com/bumptech/glide/Registry.java
浏览文件 @
6d166ad3
...
...
@@ -3,6 +3,7 @@ package com.bumptech.glide;
import
android.support.v4.util.Pools.Pool
;
import
com.bumptech.glide.load.Encoder
;
import
com.bumptech.glide.load.ImageHeaderParser
;
import
com.bumptech.glide.load.Options
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.data.DataRewinder
;
...
...
@@ -27,7 +28,8 @@ import java.util.Collections;
import
java.util.List
;
/**
* Manages component registration.
* Manages component registration to extend or replace Glide's default loading, decoding, and
* encoding logic.
*/
public
class
Registry
{
private
final
ModelLoaderRegistry
modelLoaderRegistry
;
...
...
@@ -53,60 +55,154 @@ public class Registry {
this
.
imageHeaderParserRegistry
=
new
ImageHeaderParserRegistry
();
}
/**
* Registers the given {@link Encoder} for the given data class (InputStream, FileDescriptor etc).
*
* <p>The {@link Encoder} will be used both for the exact data class and any subtypes. For
* example, registering an {@link Encoder} for {@link java.io.InputStream} will result in the
* {@link Encoder} being used for
* {@link android.content.res.AssetFileDescriptor.AutoCloseInputStream},
* {@link java.io.FileInputStream} and any other subclass.
*
* <p>If multiple {@link Encoder}s are registered for the same type or super type, the
* {@link Encoder} that is registered first will be used. As a result, it's not currently possible
* to replace Glide's default {@link Encoder}s.
*/
public
<
Data
>
Registry
register
(
Class
<
Data
>
dataClass
,
Encoder
<
Data
>
encoder
)
{
encoderRegistry
.
add
(
dataClass
,
encoder
);
return
this
;
}
public
<
Data
,
TResource
>
Registry
append
(
Class
<
Data
>
dataClass
,
Class
<
TResource
>
resourceClass
,
/**
* Appends the given {@link ResourceDecoder} onto the list of available {@link ResourceDecoder}s
* allowing it to be used if all earlier and default {@link ResourceDecoder}s for the given types
* fail (or if none are present).
*
* <p>If you're attempting to replace an existing {@link ResourceDecoder} or would like to ensure
* that your {@link ResourceDecoder} gets the chance to run before an existing
* {@link ResourceDecoder}, use {@link #prepend(Class, Class, ResourceDecoder)}. This method is
* best for new types of resources and data or as a way to add an additional fallback decoder
* for an existing type of data.
*
* @see #prepend(Class, Class, ResourceDecoder)
*
* @param dataClass The data that will be decoded from
* ({@link java.io.InputStream}, {@link java.io.FileDescriptor} etc).
* @param resourceClass The resource that will be decoded to ({@link android.graphics.Bitmap},
* {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc).
* @param decoder The {@link ResourceDecoder} to register.
*/
public
<
Data
,
TResource
>
Registry
append
(
Class
<
Data
>
dataClass
,
Class
<
TResource
>
resourceClass
,
ResourceDecoder
<
Data
,
TResource
>
decoder
)
{
decoderRegistry
.
append
(
decoder
,
dataClass
,
resourceClass
);
return
this
;
}
public
<
Data
,
TResource
>
Registry
prepend
(
Class
<
Data
>
dataClass
,
Class
<
TResource
>
resourceClass
,
/**
* Prepends the given {@link ResourceDecoder} into the list of available {@link ResourceDecoder}s
* so that it is attempted before all later and default {@link ResourceDecoder}s for the given
* types.
*
* <p>This method allows you to replace the default {@link ResourceDecoder} because it ensures
* the registered {@link ResourceDecoder} will run first. You can use the
* {@link ResourceDecoder#handles(Object, Options)} to fall back to the default
* {@link ResourceDecoder}s if you only want to change the default functionality for certain
* types of data.
*
* @see #append(Class, Class, ResourceDecoder)
*
* @param dataClass The data that will be decoded from
* ({@link java.io.InputStream}, {@link java.io.FileDescriptor} etc).
* @param resourceClass The resource that will be decoded to ({@link android.graphics.Bitmap},
* {@link com.bumptech.glide.load.resource.gif.GifDrawable} etc).
* @param decoder The {@link ResourceDecoder} to register.
*/
public
<
Data
,
TResource
>
Registry
prepend
(
Class
<
Data
>
dataClass
,
Class
<
TResource
>
resourceClass
,
ResourceDecoder
<
Data
,
TResource
>
decoder
)
{
decoderRegistry
.
prepend
(
decoder
,
dataClass
,
resourceClass
);
return
this
;
}
/**
* Registers the given {@link ResourceEncoder} for the given resource class
* ({@link android.graphics.Bitmap}, {@link com.bumptech.glide.load.resource.gif.GifDrawable}
* etc).
*
* <p>The {@link ResourceEncoder} will be used both for the exact resource class and any subtypes.
* For example, registering an {@link ResourceEncoder} for
* {@link android.graphics.drawable.Drawable} (not recommended) will result in the
* {@link ResourceEncoder} being used for {@link android.graphics.drawable.BitmapDrawable} and
* {@link com.bumptech.glide.load.resource.gif.GifDrawable} and any other subclass.
*
* <p>If multiple {@link ResourceEncoder}s are registered for the same type or super type, the
* {@link ResourceEncoder} that is registered first will be used. As a result, it's not currently
* possible to replace Glide's default {@link ResourceEncoder}s.
*/
public
<
TResource
>
Registry
register
(
Class
<
TResource
>
resourceClass
,
ResourceEncoder
<
TResource
>
encoder
)
{
resourceEncoderRegistry
.
add
(
resourceClass
,
encoder
);
return
this
;
}
/**
* Registers a new {@link com.bumptech.glide.load.data.DataRewinder.Factory} to handle a
* non-default data type that can be rewind to allow for efficient reads of file headers.
*/
public
Registry
register
(
DataRewinder
.
Factory
factory
)
{
dataRewinderRegistry
.
register
(
factory
);
return
this
;
}
/**
* Registers the given {@link ResourceTranscoder} to convert from the given resource {@link Class}
* to the given transcode {@link Class}.
*
* @param resourceClass The class that will be transcoded from (e.g.
* {@link android.graphics.Bitmap}).
* @param transcodeClass The class that will be transcoded to (e.g.
* {@link android.graphics.drawable.BitmapDrawable}).
* @param transcoder The {@link ResourceTranscoder} to register.
*/
public
<
TResource
,
Transcode
>
Registry
register
(
Class
<
TResource
>
resourceClass
,
Class
<
Transcode
>
transcodeClass
,
ResourceTranscoder
<
TResource
,
Transcode
>
transcoder
)
{
transcoderRegistry
.
register
(
resourceClass
,
transcodeClass
,
transcoder
);
return
this
;
}
/**
* Registers a new {@link ImageHeaderParser} that can obtain some basic metadata from an image
* header (orientation, type etc).
*/
public
Registry
register
(
ImageHeaderParser
parser
)
{
imageHeaderParserRegistry
.
add
(
parser
);
return
this
;
}
/**
* Use the given factory to build a {@link com.bumptech.glide.load.model.ModelLoader} for models
* of the given class. Generally the best use of this method is to replace one of the default
* factories or add an implementation for other similar low level models. Any factory replaced by
* the given factory will have its {@link ModelLoaderFactory#teardown()}} method called.
* Appends a new {@link ModelLoaderFactory} onto the end of the existing set so that the
* constructed {@link ModelLoader} will be tried after all default and previously registered
* {@link ModelLoader}s for the given model and data classes.
*
* <p>If you're attempting to replace an existing {@link ModelLoader}, use
* {@link #prepend(Class, Class, ModelLoaderFactory)}. This method is best for new types of models
* and/or data or as a way to add an additional fallback loader for an existing type of
* model/data.
*
* <p> Note - If a factory already exists for the given class, it will be replaced. If that
* factory is not being used for any other model class, {@link ModelLoaderFactory#teardown()} will
* be called. </p>
* <p>If multiple {@link ModelLoaderFactory}s are registered for the same model and/or data
* classes, the {@link ModelLoader}s they produce will be attempted in the order the
* {@link ModelLoaderFactory}s were registered. Only if all {@link ModelLoader}s fail will the
* entire request fail.
*
*
<p> Note - The factory must not be an anonymous inner class of an Activity or another object
*
that cannot be retained statically. </p>
*
@see #prepend(Class, Class, ModelLoaderFactory)
*
@see #replace(Class, Class, ModelLoaderFactory)
*
* @param modelClass The model class.
* @param dataClass the data class.
* @param modelClass The model class (e.g. URL, file path).
* @param dataClass the data class (e.g. {@link java.io.InputStream},
* {@link java.io.FileDescriptor}).
*/
public
<
Model
,
Data
>
Registry
append
(
Class
<
Model
>
modelClass
,
Class
<
Data
>
dataClass
,
ModelLoaderFactory
<
Model
,
Data
>
factory
)
{
...
...
@@ -114,12 +210,58 @@ public class Registry {
return
this
;
}
/**
* Prepends a new {@link ModelLoaderFactory} onto the beginning of the existing set so that the
* constructed {@link ModelLoader} will be tried before all default and previously registered
* {@link ModelLoader}s for the given model and data classes.
*
* <p>If you're attempting to add additional functionality or add a backup that should run only
* after the default {@link ModelLoader}s run, use
* {@link #append(Class, Class, ModelLoaderFactory)}. This method is best for adding an additional
* case to Glide's existing functionality that should run first. This method will still run
* Glide's default {@link ModelLoader}s if the prepended {@link ModelLoader}s fail.
*
* <p>If multiple {@link ModelLoaderFactory}s are registered for the same model and/or data
* classes, the {@link ModelLoader}s they produce will be attempted in the order the
* {@link ModelLoaderFactory}s were registered. Only if all {@link ModelLoader}s fail will the
* entire request fail.
*
* @see #append(Class, Class, ModelLoaderFactory)
* @see #replace(Class, Class, ModelLoaderFactory)
*
* @param modelClass The model class (e.g. URL, file path).
* @param dataClass the data class (e.g. {@link java.io.InputStream},
* {@link java.io.FileDescriptor}).
*/
public
<
Model
,
Data
>
Registry
prepend
(
Class
<
Model
>
modelClass
,
Class
<
Data
>
dataClass
,
ModelLoaderFactory
<
Model
,
Data
>
factory
)
{
modelLoaderRegistry
.
prepend
(
modelClass
,
dataClass
,
factory
);
return
this
;
}
/**
* Removes all default and previously registered {@link ModelLoaderFactory}s for the given data
* and model class and replaces all of them with the single {@link ModelLoader} provided.
*
* <p>If you're attempting to add additional functionality or add a backup that should run only
* after the default {@link ModelLoader}s run, use
* {@link #append(Class, Class, ModelLoaderFactory)}. This method should be used only when you
* want to ensure that Glide's default {@link ModelLoader}s do not run.
*
* <p>One good use case for this method is when you want to replace Glide's default networking
* library with your OkHttp, Volley, or your own implementation. Using
* {@link #prepend(Class, Class, ModelLoaderFactory)} or
* {@link #append(Class, Class, ModelLoaderFactory)} may still allow Glide's default networking
* library to run in some cases. Using this method will ensure that only your networking library
* will run and that the request will fail otherwise.
*
* @see #prepend(Class, Class, ModelLoaderFactory)
* @see #append(Class, Class, ModelLoaderFactory)
*
* @param modelClass The model class (e.g. URL, file path).
* @param dataClass the data class (e.g. {@link java.io.InputStream},
* {@link java.io.FileDescriptor}).
*/
public
<
Model
,
Data
>
Registry
replace
(
Class
<
Model
>
modelClass
,
Class
<
Data
>
dataClass
,
ModelLoaderFactory
<
Model
,
Data
>
factory
)
{
modelLoaderRegistry
.
replace
(
modelClass
,
dataClass
,
factory
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录