Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
896af010
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,发现更多精彩内容 >>
提交
896af010
编写于
3月 19, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle videos and images in one request.
上级
fcd787c9
变更
10
展开全部
显示空白变更内容
内联
并排
Showing
10 changed file
with
347 addition
and
360 deletion
+347
-360
library/src/com/bumptech/glide/Glide.java
library/src/com/bumptech/glide/Glide.java
+261
-318
library/src/com/bumptech/glide/loader/bitmap/BaseBitmapLoadFactory.java
...m/bumptech/glide/loader/bitmap/BaseBitmapLoadFactory.java
+34
-12
library/src/com/bumptech/glide/loader/bitmap/model/GenericLoaderFactory.java
...ptech/glide/loader/bitmap/model/GenericLoaderFactory.java
+1
-4
library/src/com/bumptech/glide/loader/bitmap/model/UriLoader.java
...src/com/bumptech/glide/loader/bitmap/model/UriLoader.java
+1
-5
library/src/com/bumptech/glide/resize/BaseBitmapLoadTask.java
...ary/src/com/bumptech/glide/resize/BaseBitmapLoadTask.java
+46
-15
library/tests/src/com/bumptech/glide/GlideTest.java
library/tests/src/com/bumptech/glide/GlideTest.java
+0
-1
library/tests/src/com/bumptech/glide/ListPreloaderTest.java
library/tests/src/com/bumptech/glide/ListPreloaderTest.java
+0
-1
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrModelLoader.java
.../com/bumptech/glide/samples/flickr/FlickrModelLoader.java
+1
-1
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
...rc/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
+1
-1
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrSearchActivity.java
...m/bumptech/glide/samples/flickr/FlickrSearchActivity.java
+2
-2
未找到文件。
library/src/com/bumptech/glide/Glide.java
浏览文件 @
896af010
此差异已折叠。
点击以展开。
library/src/com/bumptech/glide/loader/bitmap/BaseBitmapLoadFactory.java
浏览文件 @
896af010
...
...
@@ -11,32 +11,54 @@ import com.bumptech.glide.resize.load.Transformation;
/**
* A base {@link BitmapLoadFactory} that composes {@link ModelLoader} and {@link BitmapDecoder} sub-components
* to create an {@link BitmapLoadTask}.
* to create an {@link BitmapLoadTask}
capable of loading a model that represents either an image or a video
.
*
* @param <T> The type of the model.
* @param <Y> The type of the resource that the
{@link ModelLoader} provides and th
e {@link BitmapDecoder} can
* @param <Y> The type of the resource that the
image {@link ModelLoader} provides and the imag
e {@link BitmapDecoder} can
* decode.`
* @param <Z> The type of resource that the video {@link ModelLoader} provides and the video {@link BitmapDecoder} can
* decode.
*/
public
class
BaseBitmapLoadFactory
<
T
,
Y
>
implements
BitmapLoadFactory
<
T
>
{
private
final
ModelLoader
<
T
,
Y
>
modelLoader
;
private
final
BitmapDecoder
<
Y
>
decoder
;
public
class
BaseBitmapLoadFactory
<
T
,
Y
,
Z
>
implements
BitmapLoadFactory
<
T
>
{
private
final
ModelLoader
<
T
,
Y
>
imageModelLoader
;
private
final
BitmapDecoder
<
Y
>
imageDecoder
;
private
final
ModelLoader
<
T
,
Z
>
videoModelLoader
;
private
final
BitmapDecoder
<
Z
>
videoDecoder
;
private
final
TransformationLoader
<
T
>
transformationLoader
;
public
BaseBitmapLoadFactory
(
ModelLoader
<
T
,
Y
>
modelLoader
,
BitmapDecoder
<
Y
>
decoder
)
{
this
(
modelLoader
,
decoder
,
new
None
<
T
>());
@SuppressWarnings
(
"unused"
)
public
BaseBitmapLoadFactory
(
ModelLoader
<
T
,
Y
>
imageModelLoader
,
BitmapDecoder
<
Y
>
imageDecoder
)
{
this
(
imageModelLoader
,
imageDecoder
,
null
,
null
,
new
None
<
T
>());
}
public
BaseBitmapLoadFactory
(
ModelLoader
<
T
,
Y
>
modelLoader
,
BitmapDecoder
<
Y
>
decoder
,
@SuppressWarnings
(
"unused"
)
public
BaseBitmapLoadFactory
(
ModelLoader
<
T
,
Y
>
imageModelLoader
,
BitmapDecoder
<
Y
>
imageDecoder
,
TransformationLoader
<
T
>
transformationLoader
)
{
this
.
modelLoader
=
modelLoader
;
this
.
decoder
=
decoder
;
this
(
imageModelLoader
,
imageDecoder
,
null
,
null
,
transformationLoader
);
}
public
BaseBitmapLoadFactory
(
ModelLoader
<
T
,
Y
>
imageModelLoader
,
BitmapDecoder
<
Y
>
imageDecoder
,
ModelLoader
<
T
,
Z
>
videoModelLoader
,
BitmapDecoder
<
Z
>
videoDecoder
,
TransformationLoader
<
T
>
transformationLoader
)
{
this
.
imageModelLoader
=
imageModelLoader
;
this
.
imageDecoder
=
imageDecoder
;
this
.
videoModelLoader
=
videoModelLoader
;
this
.
videoDecoder
=
videoDecoder
;
this
.
transformationLoader
=
transformationLoader
;
}
@Override
public
BitmapLoadTask
getLoadTask
(
T
model
,
int
width
,
int
height
)
{
ResourceFetcher
<
Y
>
resourceFetcher
=
modelLoader
.
getResourceFetcher
(
model
,
width
,
height
);
ResourceFetcher
<
Y
>
imageFetcher
=
null
;
if
(
imageModelLoader
!=
null
)
{
imageFetcher
=
imageModelLoader
.
getResourceFetcher
(
model
,
width
,
height
);
}
ResourceFetcher
<
Z
>
videoFetcher
=
null
;
if
(
videoModelLoader
!=
null
)
{
videoFetcher
=
videoModelLoader
.
getResourceFetcher
(
model
,
width
,
height
);
}
Transformation
transformation
=
transformationLoader
.
getTransformation
(
model
);
return
new
BaseBitmapLoadTask
<
Y
>(
resourceFetcher
,
decoder
,
transformation
,
width
,
height
);
return
new
BaseBitmapLoadTask
<
Y
,
Z
>(
imageFetcher
,
imageDecoder
,
videoFetcher
,
videoDecoder
,
transformation
,
width
,
height
);
}
}
library/src/com/bumptech/glide/loader/bitmap/model/GenericLoaderFactory.java
浏览文件 @
896af010
...
...
@@ -39,10 +39,7 @@ public class GenericLoaderFactory {
public
<
T
,
Y
>
ModelLoader
<
T
,
Y
>
buildModelLoader
(
Class
<
T
>
modelClass
,
Class
<
Y
>
resourceClass
,
Context
context
)
{
final
ModelLoaderFactory
<
T
,
Y
>
factory
=
getFactory
(
modelClass
,
resourceClass
);
if
(
factory
==
null
)
{
throw
new
IllegalArgumentException
(
"No ModelLoaderFactory registered for class="
+
modelClass
);
}
return
factory
.
build
(
context
,
this
);
return
factory
!=
null
?
factory
.
build
(
context
,
this
)
:
null
;
}
@SuppressWarnings
(
"unchecked"
)
...
...
library/src/com/bumptech/glide/loader/bitmap/model/UriLoader.java
浏览文件 @
896af010
...
...
@@ -24,7 +24,7 @@ public abstract class UriLoader<T> implements ModelLoader<Uri, T>{
ResourceFetcher
<
T
>
result
=
null
;
if
(
isLocalUri
(
scheme
))
{
result
=
getLocalUriFetcher
(
context
,
model
);
}
else
if
(
"http"
.
equals
(
scheme
)
||
"https"
.
equals
(
scheme
))
{
}
else
if
(
urlLoader
!=
null
&&
(
"http"
.
equals
(
scheme
)
||
"https"
.
equals
(
scheme
)
))
{
try
{
result
=
urlLoader
.
getResourceFetcher
(
new
URL
(
model
.
toString
()),
width
,
height
);
}
catch
(
MalformedURLException
e
)
{
...
...
@@ -32,10 +32,6 @@ public abstract class UriLoader<T> implements ModelLoader<Uri, T>{
}
}
if
(
result
==
null
)
{
throw
new
IllegalArgumentException
(
"No stream loader for uri="
+
model
);
}
return
result
;
}
...
...
library/src/com/bumptech/glide/resize/BaseBitmapLoadTask.java
浏览文件 @
896af010
...
...
@@ -8,40 +8,47 @@ import com.bumptech.glide.resize.load.Transformation;
/**
* A base {@link BitmapLoadTask} that composes {@link ResourceFetcher} and {@link BitmapDecoder} to decode a
* bitmap.
* bitmap
from either an image or a video
.
*
* @param <T> The type of the resource returned by the {@link ResourceFetcher} and used by the
* {@link BitmapDecoder} to BitmapResourceLoader the bitmap.
* @param <T> The type of the resource returned by the image {@link ResourceFetcher} and used by the
* image {@link BitmapDecoder} to decode the bitmap.
* @param <Y> The type of the resource returned by the video {@link ResourceFetcher} and used by the
* video {@link BitmapDecoder} to decode the bitmap.
*/
public
class
BaseBitmapLoadTask
<
T
>
implements
BitmapLoadTask
{
public
class
BaseBitmapLoadTask
<
T
,
Y
>
implements
BitmapLoadTask
{
private
final
String
id
;
private
final
int
width
;
private
final
int
height
;
private
final
ResourceFetcher
<
Y
>
videoLoader
;
private
final
BitmapDecoder
<
Y
>
videoDecoder
;
private
final
Transformation
transformation
;
private
ResourceFetcher
<
T
>
l
oader
;
private
BitmapDecoder
<
T
>
d
ecoder
;
private
ResourceFetcher
<
T
>
imageL
oader
;
private
BitmapDecoder
<
T
>
imageD
ecoder
;
public
BaseBitmapLoadTask
(
ResourceFetcher
<
T
>
loader
,
BitmapDecoder
<
T
>
decoder
,
Transformation
transformation
,
public
BaseBitmapLoadTask
(
ResourceFetcher
<
T
>
imageLoader
,
BitmapDecoder
<
T
>
imageDecoder
,
ResourceFetcher
<
Y
>
videoLoader
,
BitmapDecoder
<
Y
>
videoDecoder
,
Transformation
transformation
,
int
width
,
int
height
)
{
this
.
loader
=
loader
;
this
.
decoder
=
decoder
;
this
.
imageLoader
=
imageLoader
;
this
.
imageDecoder
=
imageDecoder
;
this
.
videoLoader
=
videoLoader
;
this
.
videoDecoder
=
videoDecoder
;
this
.
transformation
=
transformation
;
this
.
width
=
width
;
this
.
height
=
height
;
this
.
id
=
loader
.
getId
()
+
d
ecoder
.
getId
()
+
transformation
.
getId
()
+
width
+
height
;
this
.
id
=
imageLoader
.
getId
()
+
imageD
ecoder
.
getId
()
+
transformation
.
getId
()
+
width
+
height
;
}
public
void
cancel
()
{
l
oader
.
cancel
();
imageL
oader
.
cancel
();
}
@Override
public
Bitmap
load
(
BitmapPool
bitmapPool
)
throws
Exception
{
T
resource
=
loader
.
loadResource
(
);
if
(
resource
==
null
)
{
throw
new
IllegalStateException
(
"Cannot decode null resource"
)
;
Bitmap
original
=
loadOriginal
(
bitmapPool
);
if
(
original
==
null
)
{
return
null
;
}
Bitmap
original
=
decoder
.
decode
(
resource
,
bitmapPool
,
width
,
height
);
Bitmap
transformed
=
transformation
.
transform
(
original
,
bitmapPool
,
width
,
height
);
if
(
original
!=
transformed
)
{
bitmapPool
.
put
(
original
);
...
...
@@ -49,6 +56,30 @@ public class BaseBitmapLoadTask<T> implements BitmapLoadTask {
return
transformed
;
}
private
Bitmap
loadOriginal
(
BitmapPool
bitmapPool
)
throws
Exception
{
Bitmap
result
=
loadOriginal
(
imageLoader
,
imageDecoder
,
bitmapPool
);
if
(
result
==
null
)
{
result
=
loadOriginal
(
videoLoader
,
videoDecoder
,
bitmapPool
);
}
return
result
;
}
private
<
X
>
Bitmap
loadOriginal
(
ResourceFetcher
<
X
>
fetcher
,
BitmapDecoder
<
X
>
decoder
,
BitmapPool
bitmapPool
)
throws
Exception
{
if
(
fetcher
==
null
||
decoder
==
null
)
{
return
null
;
}
X
resource
=
fetcher
.
loadResource
();
if
(
resource
==
null
)
{
return
null
;
}
return
decoder
.
decode
(
resource
,
bitmapPool
,
width
,
height
);
}
public
String
getId
()
{
return
id
;
}
...
...
library/tests/src/com/bumptech/glide/GlideTest.java
浏览文件 @
896af010
...
...
@@ -5,7 +5,6 @@ import android.net.Uri;
import
android.test.ActivityTestCase
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
com.bumptech.glide.loader.bitmap.model.ModelLoader
;
import
com.bumptech.glide.loader.bitmap.model.stream.StreamModelLoader
;
import
com.bumptech.glide.loader.bitmap.resource.ResourceFetcher
;
import
com.bumptech.glide.presenter.ImagePresenter
;
...
...
library/tests/src/com/bumptech/glide/ListPreloaderTest.java
浏览文件 @
896af010
...
...
@@ -3,7 +3,6 @@ package com.bumptech.glide;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.test.AndroidTestCase
;
import
com.bumptech.glide.loader.bitmap.model.ModelLoader
;
import
com.bumptech.glide.loader.bitmap.model.stream.StreamModelLoader
;
import
com.bumptech.glide.loader.bitmap.resource.ResourceFetcher
;
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrModelLoader.java
浏览文件 @
896af010
package
com.bumptech.glide.samples.flickr
;
import
android.content.Context
;
import
com.bumptech.glide.loader.bitmap.model.BaseUrlLoader
;
import
com.bumptech.glide.loader.bitmap.model.Cache
;
import
com.bumptech.glide.loader.bitmap.model.stream.BaseUrlLoader
;
import
com.bumptech.glide.samples.flickr.api.Api
;
import
com.bumptech.glide.samples.flickr.api.Photo
;
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
浏览文件 @
896af010
...
...
@@ -139,7 +139,7 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer {
//reason why ImagePresenter is used here and not in FlickrPhotoList.
final
Animation
fadeIn
=
AnimationUtils
.
loadAnimation
(
context
,
R
.
anim
.
fade_in
);
imagePresenter
=
new
ImagePresenter
.
Builder
<
Photo
>()
.
setBitmapLoadFactory
(
new
BaseBitmapLoadFactory
<
Photo
,
InputStream
>(
.
setBitmapLoadFactory
(
new
BaseBitmapLoadFactory
<
Photo
,
InputStream
,
Void
>(
new
FlickrModelLoader
(
context
,
urlCache
),
Downsampler
.
AT_LEAST
,
new
CenterCrop
<
Photo
>()))
.
setImageView
(
imageView
)
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrSearchActivity.java
浏览文件 @
896af010
...
...
@@ -31,6 +31,7 @@ import com.bumptech.glide.volley.VolleyUrlLoader;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -112,8 +113,7 @@ public class FlickrSearchActivity extends SherlockFragmentActivity {
}
requestQueue
=
Volley
.
newRequestQueue
(
this
);
glide
.
register
(
URL
.
class
,
new
VolleyUrlLoader
.
Factory
(
requestQueue
));
glide
.
register
(
URL
.
class
,
InputStream
.
class
,
new
VolleyUrlLoader
.
Factory
(
requestQueue
));
searching
=
findViewById
(
R
.
id
.
searching
);
searchLoading
=
findViewById
(
R
.
id
.
search_loading
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录