Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
44e0516e
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,发现更多精彩内容 >>
提交
44e0516e
编写于
5月 31, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generify BitmapRequest and GenericRequestBuilder
上级
ba414a3e
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
191 addition
and
202 deletion
+191
-202
library/robolectric/src/com/bumptech/glide/ListPreloaderTest.java
...robolectric/src/com/bumptech/glide/ListPreloaderTest.java
+7
-7
library/robolectric/src/com/bumptech/glide/request/GenericRequestTest.java
...ic/src/com/bumptech/glide/request/GenericRequestTest.java
+22
-23
library/src/com/bumptech/glide/BitmapRequestBuilder.java
library/src/com/bumptech/glide/BitmapRequestBuilder.java
+38
-28
library/src/com/bumptech/glide/GenericRequestBuilder.java
library/src/com/bumptech/glide/GenericRequestBuilder.java
+72
-92
library/src/com/bumptech/glide/Glide.java
library/src/com/bumptech/glide/Glide.java
+29
-29
library/src/com/bumptech/glide/ListPreloader.java
library/src/com/bumptech/glide/ListPreloader.java
+2
-2
library/src/com/bumptech/glide/request/bitmap/GenericRequest.java
...src/com/bumptech/glide/request/bitmap/GenericRequest.java
+17
-17
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
...rc/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
+2
-2
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
...rc/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
+2
-2
未找到文件。
library/robolectric/src/com/bumptech/glide/ListPreloaderTest.java
浏览文件 @
44e0516e
...
...
@@ -55,10 +55,10 @@ public class ListPreloaderTest {
}
@Override
protected
RequestBuilder
getRequestBuilder
(
Object
item
)
{
protected
Bitmap
RequestBuilder
getRequestBuilder
(
Object
item
)
{
assertEquals
(
objects
.
get
(
expectedPosition
),
item
);
expectedPosition
++;
return
mock
(
RequestBuilder
.
class
);
return
mock
(
Bitmap
RequestBuilder
.
class
);
}
};
...
...
@@ -110,10 +110,10 @@ public class ListPreloaderTest {
}
@Override
protected
RequestBuilder
getRequestBuilder
(
Object
item
)
{
protected
Bitmap
RequestBuilder
getRequestBuilder
(
Object
item
)
{
assertEquals
(
objects
.
get
(
expectedPosition
),
item
);
expectedPosition
--;
return
mock
(
RequestBuilder
.
class
);
return
mock
(
Bitmap
RequestBuilder
.
class
);
}
};
...
...
@@ -221,7 +221,7 @@ public class ListPreloaderTest {
}
@Override
protected
RequestBuilder
getRequestBuilder
(
Object
item
)
{
protected
Bitmap
RequestBuilder
getRequestBuilder
(
Object
item
)
{
loadedObjects
.
add
(
item
);
return
super
.
getRequestBuilder
(
item
);
}
...
...
@@ -254,8 +254,8 @@ public class ListPreloaderTest {
}
@Override
protected
RequestBuilder
getRequestBuilder
(
Object
item
)
{
return
mock
(
RequestBuilder
.
class
);
protected
Bitmap
RequestBuilder
getRequestBuilder
(
Object
item
)
{
return
mock
(
Bitmap
RequestBuilder
.
class
);
}
}
}
library/robolectric/src/com/bumptech/glide/request/
Bitmap
RequestTest.java
→
library/robolectric/src/com/bumptech/glide/request/
Generic
RequestTest.java
浏览文件 @
44e0516e
...
...
@@ -2,7 +2,6 @@ package com.bumptech.glide.request;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.Color
;
import
android.graphics.drawable.ColorDrawable
;
import
android.graphics.drawable.Drawable
;
...
...
@@ -16,7 +15,7 @@ import com.bumptech.glide.load.engine.Engine;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.resource.ResourceFetcher
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.bitmap.
Bitmap
Request
;
import
com.bumptech.glide.request.bitmap.
Generic
Request
;
import
com.bumptech.glide.request.target.Target
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -39,7 +38,7 @@ import static org.mockito.Mockito.verify;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
Bitmap
RequestTest
{
public
class
Generic
RequestTest
{
private
RequestHarness
harness
;
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -55,15 +54,15 @@ public class BitmapRequestTest {
Drawable
placeholderDrawable
=
null
;
int
errorResourceId
=
0
;
Drawable
errorDrawable
=
null
;
LoadProvider
<
Object
,
Object
,
Bitmap
>
loadProvider
=
mock
(
LoadProvider
.
class
);
LoadProvider
<
Object
,
Object
,
Object
>
loadProvider
=
mock
(
LoadProvider
.
class
);
public
RequestHarness
()
{
ModelLoader
<
Object
,
Object
>
modelLoader
=
mock
(
ModelLoader
.
class
);
when
(
loadProvider
.
getModelLoader
()).
thenReturn
(
modelLoader
);
}
public
BitmapRequest
<
Object
,
Object
>
getRequest
()
{
return
new
BitmapRequest
<
Object
,
Object
>(
loadProvider
,
model
,
context
,
priority
,
target
,
1
f
,
public
GenericRequest
<
Object
,
Object
,
Object
>
getRequest
()
{
return
new
GenericRequest
<
Object
,
Object
,
Object
>(
loadProvider
,
model
,
context
,
priority
,
target
,
1
f
,
placeholderDrawable
,
placeholderResourceId
,
errorDrawable
,
errorResourceId
,
null
,
0
,
null
,
requestCoordinator
,
engine
,
mock
(
Transformation
.
class
));
}
...
...
@@ -76,14 +75,14 @@ public class BitmapRequestTest {
@Test
public
void
testIsNotCompleteBeforeReceivingResource
()
{
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
assertFalse
(
request
.
isComplete
());
}
@Test
public
void
testIsCompleteAfterReceivingResource
()
{
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onResourceReady
(
harness
.
resource
);
...
...
@@ -96,14 +95,14 @@ public class BitmapRequestTest {
doAnswer
(
new
Answer
()
{
@Override
public
Object
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
Request
request
=
(
Request
)
invocation
.
getArguments
()[
0
];
com
.
bumptech
.
glide
.
request
.
Request
request
=
(
com
.
bumptech
.
glide
.
request
.
Request
)
invocation
.
getArguments
()[
0
];
assertFalse
(
request
.
isComplete
());
return
true
;
}
}).
when
(
requestCoordinator
).
canSetImage
(
any
(
Request
.
class
));
}).
when
(
requestCoordinator
).
canSetImage
(
any
(
com
.
bumptech
.
glide
.
request
.
Request
.
class
));
harness
.
requestCoordinator
=
requestCoordinator
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onResourceReady
(
harness
.
resource
);
...
...
@@ -112,14 +111,14 @@ public class BitmapRequestTest {
@Test
public
void
testIsNotFailedWithoutException
()
{
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
assertFalse
(
request
.
isFailed
());
}
@Test
public
void
testIsFailedAfterException
()
{
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onException
(
new
Exception
(
"test"
));
assertTrue
(
request
.
isFailed
());
...
...
@@ -129,7 +128,7 @@ public class BitmapRequestTest {
public
void
testEngineLoadPassedCorrectMetadata
()
{
Priority
expected
=
Priority
.
HIGH
;
harness
.
priority
=
expected
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onSizeReady
(
100
,
100
);
...
...
@@ -146,7 +145,7 @@ public class BitmapRequestTest {
any
(
ResourceFetcher
.
class
),
any
(
ResourceDecoder
.
class
),
any
(
Transformation
.
class
),
any
(
ResourceEncoder
.
class
),
any
(
Priority
.
class
),
any
(
ResourceCallback
.
class
))).
thenReturn
(
loadStatus
);
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onSizeReady
(
100
,
100
);
request
.
cancel
();
...
...
@@ -156,7 +155,7 @@ public class BitmapRequestTest {
@Test
public
void
testResourceIsRecycledOnClear
()
{
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onResourceReady
(
harness
.
resource
);
request
.
clear
();
...
...
@@ -175,7 +174,7 @@ public class BitmapRequestTest {
harness
.
context
=
context
;
harness
.
placeholderResourceId
=
expectedId
;
harness
.
target
=
target
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
run
();
assertEquals
(
expected
,
target
.
currentPlaceholder
);
...
...
@@ -189,7 +188,7 @@ public class BitmapRequestTest {
harness
.
placeholderDrawable
=
expected
;
harness
.
target
=
target
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
run
();
assertEquals
(
expected
,
target
.
currentPlaceholder
);
...
...
@@ -206,7 +205,7 @@ public class BitmapRequestTest {
harness
.
context
=
context
;
harness
.
errorResourceId
=
expectedId
;
harness
.
target
=
target
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onException
(
null
);
...
...
@@ -221,7 +220,7 @@ public class BitmapRequestTest {
harness
.
errorDrawable
=
expected
;
harness
.
target
=
target
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
onException
(
null
);
...
...
@@ -237,7 +236,7 @@ public class BitmapRequestTest {
harness
.
placeholderDrawable
=
placeholder
;
harness
.
target
=
target
;
harness
.
model
=
null
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
run
();
...
...
@@ -255,7 +254,7 @@ public class BitmapRequestTest {
harness
.
errorDrawable
=
errorPlaceholder
;
harness
.
target
=
target
;
harness
.
model
=
null
;
Bitmap
Request
request
=
harness
.
getRequest
();
Generic
Request
request
=
harness
.
getRequest
();
request
.
run
();
...
...
@@ -295,7 +294,7 @@ public class BitmapRequestTest {
}
@Override
public
void
setRequest
(
Request
request
)
{
public
void
setRequest
(
com
.
bumptech
.
glide
.
request
.
Request
request
)
{
}
@Override
...
...
library/src/com/bumptech/glide/RequestBuilder.java
→
library/src/com/bumptech/glide/
Bitmap
RequestBuilder.java
浏览文件 @
44e0516e
...
...
@@ -8,7 +8,9 @@ import android.view.animation.Animation;
import
com.bumptech.glide.load.DecodeFormat
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.data.bitmap.CenterCrop
;
import
com.bumptech.glide.load.data.bitmap.Downsampler
;
import
com.bumptech.glide.load.data.bitmap.FitCenter
;
import
com.bumptech.glide.load.data.bitmap.StreamBitmapDecoder
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.provider.LoadProvider
;
...
...
@@ -23,12 +25,14 @@ import java.io.InputStream;
* @param <ModelType> The type of model that will be loaded into the target.
*/
@SuppressWarnings
(
"unused"
)
//public api
public
class
RequestBuilder
<
ModelType
>
extends
GenericRequestBuilder
<
ModelType
,
InputStream
,
ParcelFileDescriptor
>
{
public
class
BitmapRequestBuilder
<
ModelType
>
extends
GenericRequestBuilder
<
ModelType
,
InputStream
,
ParcelFileDescriptor
,
Bitmap
>
{
private
final
BitmapPool
bitmapPool
;
private
Downsampler
downsampler
=
Downsampler
.
AT_LEAST
;
private
DecodeFormat
decodeFormat
=
DecodeFormat
.
PREFER_RGB_565
;
RequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
InputStream
,
Bitmap
>
streamLoadProvider
,
BitmapRequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
InputStream
,
Bitmap
>
streamLoadProvider
,
LoadProvider
<
ModelType
,
ParcelFileDescriptor
,
Bitmap
>
fileDescriptorLoadProvider
,
BitmapPool
bitmapPool
)
{
super
(
context
,
model
,
streamLoadProvider
,
fileDescriptorLoadProvider
);
this
.
bitmapPool
=
bitmapPool
;
...
...
@@ -41,7 +45,7 @@ public class RequestBuilder<ModelType> extends GenericRequestBuilder<ModelType,
*
* @return This RequestBuilder
*/
public
RequestBuilder
<
ModelType
>
approximate
()
{
public
Bitmap
RequestBuilder
<
ModelType
>
approximate
()
{
return
downsample
(
Downsampler
.
AT_LEAST
);
}
...
...
@@ -52,7 +56,7 @@ public class RequestBuilder<ModelType> extends GenericRequestBuilder<ModelType,
*
* @return This RequestBuilder
*/
public
RequestBuilder
<
ModelType
>
asIs
()
{
public
Bitmap
RequestBuilder
<
ModelType
>
asIs
()
{
return
downsample
(
Downsampler
.
NONE
);
}
...
...
@@ -65,37 +69,37 @@ public class RequestBuilder<ModelType> extends GenericRequestBuilder<ModelType,
* @param downsampler The downsampler
* @return This RequestBuilder
*/
private
RequestBuilder
<
ModelType
>
downsample
(
Downsampler
downsampler
)
{
private
Bitmap
RequestBuilder
<
ModelType
>
downsample
(
Downsampler
downsampler
)
{
this
.
downsampler
=
downsampler
;
super
.
imageDecoder
(
new
StreamBitmapDecoder
(
downsampler
,
bitmapPool
,
decodeFormat
));
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
thumbnail
(
float
sizeMultiplier
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
thumbnail
(
float
sizeMultiplier
)
{
super
.
thumbnail
(
sizeMultiplier
);
return
this
;
}
public
RequestBuilder
<
ModelType
>
thumbnail
(
RequestBuilder
<
ModelType
>
thumbnailRequest
)
{
public
BitmapRequestBuilder
<
ModelType
>
thumbnail
(
Bitmap
RequestBuilder
<
ModelType
>
thumbnailRequest
)
{
super
.
thumbnail
(
thumbnailRequest
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
sizeMultiplier
(
float
sizeMultiplier
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
sizeMultiplier
(
float
sizeMultiplier
)
{
super
.
sizeMultiplier
(
sizeMultiplier
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
imageDecoder
(
ResourceDecoder
<
InputStream
,
Bitmap
>
decoder
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
imageDecoder
(
ResourceDecoder
<
InputStream
,
Bitmap
>
decoder
)
{
super
.
imageDecoder
(
decoder
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
videoDecoder
(
ResourceDecoder
<
ParcelFileDescriptor
,
Bitmap
>
decoder
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
videoDecoder
(
ResourceDecoder
<
ParcelFileDescriptor
,
Bitmap
>
decoder
)
{
super
.
videoDecoder
(
decoder
);
return
this
;
}
...
...
@@ -115,74 +119,80 @@ public class RequestBuilder<ModelType> extends GenericRequestBuilder<ModelType,
* @param format The format to use.
* @return This request builder.
*/
public
RequestBuilder
<
ModelType
>
format
(
DecodeFormat
format
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
format
(
DecodeFormat
format
)
{
this
.
decodeFormat
=
format
;
super
.
imageDecoder
(
new
StreamBitmapDecoder
(
downsampler
,
bitmapPool
,
format
));
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
priority
(
Priority
priority
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
priority
(
Priority
priority
)
{
super
.
priority
(
priority
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
centerCrop
()
{
super
.
centerCrop
();
return
this
;
/**
* Transform images using {@link CenterCrop}.
*
* @return This RequestBuilder
*/
public
BitmapRequestBuilder
<
ModelType
>
centerCrop
()
{
return
transform
(
new
CenterCrop
(
Glide
.
get
(
context
).
getBitmapPool
()));
}
@Override
public
RequestBuilder
<
ModelType
>
fitCenter
()
{
super
.
fitCenter
();
return
this
;
/**
* Transform images using {@link FitCenter}.
*
* @return This RequestBuilder
*/
public
BitmapRequestBuilder
<
ModelType
>
fitCenter
()
{
return
transform
(
new
FitCenter
(
Glide
.
get
(
context
).
getBitmapPool
()));
}
@Override
public
RequestBuilder
<
ModelType
>
transform
(
Transformation
<
Bitmap
>
transformation
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
transform
(
Transformation
<
Bitmap
>
transformation
)
{
super
.
transform
(
transformation
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
animate
(
int
animationId
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
animate
(
int
animationId
)
{
super
.
animate
(
animationId
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
animate
(
Animation
animation
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
animate
(
Animation
animation
)
{
super
.
animate
(
animation
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
placeholder
(
int
resourceId
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
placeholder
(
int
resourceId
)
{
super
.
placeholder
(
resourceId
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
placeholder
(
Drawable
drawable
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
placeholder
(
Drawable
drawable
)
{
super
.
placeholder
(
drawable
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
error
(
int
resourceId
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
error
(
int
resourceId
)
{
super
.
error
(
resourceId
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
error
(
Drawable
drawable
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
error
(
Drawable
drawable
)
{
super
.
error
(
drawable
);
return
this
;
}
@Override
public
RequestBuilder
<
ModelType
>
listener
(
RequestListener
<
ModelType
>
requestListener
)
{
public
Bitmap
RequestBuilder
<
ModelType
>
listener
(
RequestListener
<
ModelType
>
requestListener
)
{
super
.
listener
(
requestListener
);
return
this
;
}
...
...
library/src/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
44e0516e
此差异已折叠。
点击以展开。
library/src/com/bumptech/glide/Glide.java
浏览文件 @
44e0516e
...
...
@@ -44,7 +44,7 @@ import java.net.URL;
import
java.util.UUID
;
/**
* A singleton to present a simple static interface for building requests with {@link RequestBuilder} and maintaining
* A singleton to present a simple static interface for building requests with {@link
Bitmap
RequestBuilder} and maintaining
* an {@link Engine}, {@link BitmapPool}, {@link DiskCache} and {@link MemoryCache}.
*
* <p>
...
...
@@ -398,7 +398,7 @@ public class Glide {
}
/**
* A {@link RequestBuilder} builder that returns a request for a model that represents an image.
* A {@link
Bitmap
RequestBuilder} builder that returns a request for a model that represents an image.
*/
public
static
class
ModelRequest
{
private
final
Context
context
;
...
...
@@ -457,10 +457,10 @@ public class Glide {
*
* @param string The string representing the image. Must be either a path, or a uri handled by
* {@link StreamUriLoader}
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the model
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the model
* into.
*/
public
RequestBuilder
<
String
>
load
(
String
string
)
{
public
Bitmap
RequestBuilder
<
String
>
load
(
String
string
)
{
return
loadGeneric
(
string
);
}
...
...
@@ -471,10 +471,10 @@ public class Glide {
* @see #using(StreamModelLoader)
*
* @param uri The uri representing the image. Must be a uri handled by {@link StreamUriLoader}
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the model
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the model
* into.
*/
public
RequestBuilder
<
Uri
>
load
(
Uri
uri
)
{
public
Bitmap
RequestBuilder
<
Uri
>
load
(
Uri
uri
)
{
return
loadGeneric
(
uri
);
}
...
...
@@ -486,10 +486,10 @@ public class Glide {
* @see #using(StreamModelLoader)
*
* @param file The File containing the image
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the model
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the model
* into.
*/
public
RequestBuilder
<
File
>
load
(
File
file
)
{
public
Bitmap
RequestBuilder
<
File
>
load
(
File
file
)
{
return
loadGeneric
(
file
);
}
...
...
@@ -501,10 +501,10 @@ public class Glide {
* @see #using(StreamModelLoader)
*
* @param resourceId the id of the resource containing the image
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the model
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the model
* into.
*/
public
RequestBuilder
<
Integer
>
load
(
Integer
resourceId
)
{
public
Bitmap
RequestBuilder
<
Integer
>
load
(
Integer
resourceId
)
{
return
loadGeneric
(
resourceId
);
}
...
...
@@ -514,11 +514,11 @@ public class Glide {
*
* @param model The model to load.
* @param <T> The type of the model to load.
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the image
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the image
* into.
*/
@SuppressWarnings
(
"unused"
)
public
<
T
>
RequestBuilder
<
T
>
loadFromImage
(
T
model
)
{
public
<
T
>
Bitmap
RequestBuilder
<
T
>
loadFromImage
(
T
model
)
{
return
loadGeneric
(
model
);
}
...
...
@@ -530,10 +530,10 @@ public class Glide {
* @see #using(StreamModelLoader)
*
* @param url The URL representing the image.
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the model
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the model
* into.
*/
public
RequestBuilder
<
URL
>
loadFromImage
(
URL
url
)
{
public
Bitmap
RequestBuilder
<
URL
>
loadFromImage
(
URL
url
)
{
return
loadGeneric
(
url
);
}
...
...
@@ -545,10 +545,10 @@ public class Glide {
* @param model The data to load.
* @param id A unique id that identifies the image represented by the model suitable for use as a cache key
* (url, filepath etc). If there is no suitable id, use {@link #loadFromImage(byte[])} instaed.
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the image
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the image
* into.
*/
public
RequestBuilder
<
byte
[]>
loadFromImage
(
byte
[]
model
,
final
String
id
)
{
public
Bitmap
RequestBuilder
<
byte
[]>
loadFromImage
(
byte
[]
model
,
final
String
id
)
{
StreamByteArrayLoader
loader
=
new
StreamByteArrayLoader
()
{
@Override
public
String
getId
(
byte
[]
model
)
{
...
...
@@ -559,7 +559,7 @@ public class Glide {
LoadProvider
<
byte
[],
InputStream
,
Bitmap
>
loadProvider
=
new
FixedLoadProvider
<
byte
[],
InputStream
,
Bitmap
>(
loader
,
streamDataProvider
);
return
new
RequestBuilder
<
byte
[]>(
context
,
model
,
loadProvider
,
null
,
bitmapPool
);
return
new
Bitmap
RequestBuilder
<
byte
[]>(
context
,
model
,
loadProvider
,
null
,
bitmapPool
);
}
/**
...
...
@@ -567,10 +567,10 @@ public class Glide {
* simple id that represents the given data.
*
* @param model the data to load.
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the image
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the image
* into.
*/
public
RequestBuilder
<
byte
[]>
loadFromImage
(
byte
[]
model
)
{
public
Bitmap
RequestBuilder
<
byte
[]>
loadFromImage
(
byte
[]
model
)
{
return
loadFromImage
(
model
,
UUID
.
randomUUID
()
.
toString
());
}
...
...
@@ -581,11 +581,11 @@ public class Glide {
*
* @param model The model to load.
* @param <T> The type of the model to load.
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the image
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the image
* into.
*/
@SuppressWarnings
(
"unused"
)
public
<
T
>
RequestBuilder
<
T
>
loadFromVideo
(
T
model
)
{
public
<
T
>
Bitmap
RequestBuilder
<
T
>
loadFromVideo
(
T
model
)
{
return
loadGeneric
(
model
);
}
...
...
@@ -596,14 +596,14 @@ public class Glide {
*
* @param model The model the load.
* @param <T> The type of the model to load.
* @return A {@link RequestBuilder} to set options for the load and ultimately the target to load the image
* @return A {@link
Bitmap
RequestBuilder} to set options for the load and ultimately the target to load the image
* into.
*/
public
<
T
>
RequestBuilder
<
T
>
load
(
T
model
)
{
public
<
T
>
Bitmap
RequestBuilder
<
T
>
load
(
T
model
)
{
return
loadGeneric
(
model
);
}
private
<
T
>
RequestBuilder
<
T
>
loadGeneric
(
T
model
)
{
private
<
T
>
Bitmap
RequestBuilder
<
T
>
loadGeneric
(
T
model
)
{
LoadProvider
<
T
,
InputStream
,
Bitmap
>
streamLoadProvider
=
null
;
ModelLoader
<
T
,
InputStream
>
streamModelLoader
=
buildStreamModelLoader
(
model
,
context
);
if
(
streamModelLoader
!=
null
)
{
...
...
@@ -618,7 +618,7 @@ public class Glide {
new
FixedLoadProvider
<
T
,
ParcelFileDescriptor
,
Bitmap
>(
fileDescriptorModelLoader
,
fileDescriptorDataProvider
);
}
return
new
RequestBuilder
<
T
>(
context
,
model
,
streamLoadProvider
,
fileDescriptorLoadProvider
,
bitmapPool
);
return
new
Bitmap
RequestBuilder
<
T
>(
context
,
model
,
streamLoadProvider
,
fileDescriptorLoadProvider
,
bitmapPool
);
}
}
...
...
@@ -642,8 +642,8 @@ public class Glide {
this
.
bitmapPool
=
bitmapPool
;
}
public
RequestBuilder
<
T
>
loadFromVideo
(
T
model
)
{
return
new
RequestBuilder
<
T
>(
context
,
model
,
null
,
public
Bitmap
RequestBuilder
<
T
>
loadFromVideo
(
T
model
)
{
return
new
Bitmap
RequestBuilder
<
T
>(
context
,
model
,
null
,
new
FixedLoadProvider
<
T
,
ParcelFileDescriptor
,
Bitmap
>(
loader
,
dataLoadProvider
),
bitmapPool
);
}
}
...
...
@@ -668,8 +668,8 @@ public class Glide {
this
.
bitmapPool
=
bitmapPool
;
}
public
RequestBuilder
<
T
>
load
(
T
model
)
{
return
new
RequestBuilder
<
T
>(
context
,
model
,
public
Bitmap
RequestBuilder
<
T
>
load
(
T
model
)
{
return
new
Bitmap
RequestBuilder
<
T
>(
context
,
model
,
new
FixedLoadProvider
<
T
,
InputStream
,
Bitmap
>(
loader
,
dataLoadProvider
),
null
,
bitmapPool
);
}
}
...
...
library/src/com/bumptech/glide/ListPreloader.java
浏览文件 @
44e0516e
...
...
@@ -82,9 +82,9 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
* target and context will be provided by the preloader.
*
* @param item The model to load.
* @return A non null {@link RequestBuilder}.
* @return A non null {@link
Bitmap
RequestBuilder}.
*/
protected
abstract
RequestBuilder
getRequestBuilder
(
T
item
);
protected
abstract
Bitmap
RequestBuilder
getRequestBuilder
(
T
item
);
private
void
preload
(
int
start
,
boolean
increasing
)
{
if
(
isIncreasing
!=
increasing
)
{
...
...
library/src/com/bumptech/glide/request/bitmap/
Bitmap
Request.java
→
library/src/com/bumptech/glide/request/bitmap/
Generic
Request.java
浏览文件 @
44e0516e
package
com.bumptech.glide.request.bitmap
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.util.Log
;
import
android.view.animation.Animation
;
...
...
@@ -23,24 +22,25 @@ import com.bumptech.glide.request.target.Target;
import
java.io.InputStream
;
/**
* A {@link
Request} that loads an {@link Bitmap
} into a given {@link Target}.
* A {@link
com.bumptech.glide.request.Request} that loads a {@link Resource
} into a given {@link Target}.
*
* @param <A> The type of the model that the {@link Bitmap} will be loaded from.
* @param <T> The type of the resource that the {@link Bitmap} will be loaded from.
* @param <A> The type of the model that the resource will be loaded from.
* @param <T> The type of the data that the resource will be loaded from.
* @param <Z> The type of the resource that will be loaded.
*/
public
class
BitmapRequest
<
A
,
T
>
implements
Request
,
Target
.
SizeReadyCallback
,
ResourceCallback
<
Bitmap
>
{
private
static
final
String
TAG
=
"
Bitmap
Request"
;
public
class
GenericRequest
<
A
,
T
,
Z
>
implements
Request
,
Target
.
SizeReadyCallback
,
ResourceCallback
<
Z
>
{
private
static
final
String
TAG
=
"Request"
;
private
final
int
placeholderResourceId
;
private
final
int
errorResourceId
;
private
final
Context
context
;
private
final
Transformation
<
Bitmap
>
transformation
;
private
final
LoadProvider
<
A
,
T
,
Bitmap
>
loadProvider
;
private
final
Transformation
<
Z
>
transformation
;
private
final
LoadProvider
<
A
,
T
,
Z
>
loadProvider
;
private
final
int
animationId
;
private
final
RequestCoordinator
requestCoordinator
;
private
final
A
model
;
private
Priority
priority
;
private
final
Target
<
Bitmap
>
target
;
private
final
Target
<
Z
>
target
;
private
final
RequestListener
<
A
>
requestListener
;
private
final
float
sizeMultiplier
;
private
final
Engine
engine
;
...
...
@@ -50,14 +50,14 @@ public class BitmapRequest<A, T> implements Request, Target.SizeReadyCallback, R
private
boolean
isCancelled
;
private
boolean
isError
;
private
boolean
loadedFromMemoryCache
;
private
Resource
<
Bitmap
>
resource
;
private
Resource
<
Z
>
resource
;
private
Engine
.
LoadStatus
loadStatus
;
public
BitmapRequest
(
LoadProvider
<
A
,
T
,
Bitmap
>
loadProvider
,
A
model
,
Context
context
,
Priority
priority
,
Target
<
Bitmap
>
target
,
float
sizeMultiplier
,
Drawable
placeholderDrawable
,
int
placeholderResourceId
,
public
GenericRequest
(
LoadProvider
<
A
,
T
,
Z
>
loadProvider
,
A
model
,
Context
context
,
Priority
priority
,
Target
<
Z
>
target
,
float
sizeMultiplier
,
Drawable
placeholderDrawable
,
int
placeholderResourceId
,
Drawable
errorDrawable
,
int
errorResourceId
,
RequestListener
<
A
>
requestListener
,
int
animationId
,
Animation
animation
,
RequestCoordinator
requestCoordinator
,
Engine
engine
,
Transformation
<
Bitmap
>
transformation
)
{
Transformation
<
Z
>
transformation
)
{
this
.
loadProvider
=
loadProvider
;
this
.
model
=
model
;
this
.
context
=
context
;
...
...
@@ -148,9 +148,9 @@ public class BitmapRequest<A, T> implements Request, Target.SizeReadyCallback, R
width
=
Math
.
round
(
sizeMultiplier
*
width
);
height
=
Math
.
round
(
sizeMultiplier
*
height
);
ResourceDecoder
<
InputStream
,
Bitmap
>
cacheDecoder
=
loadProvider
.
getCacheDecoder
();
ResourceDecoder
<
T
,
Bitmap
>
decoder
=
loadProvider
.
getSourceDecoder
();
ResourceEncoder
<
Bitmap
>
encoder
=
loadProvider
.
getEncoder
();
ResourceDecoder
<
InputStream
,
Z
>
cacheDecoder
=
loadProvider
.
getCacheDecoder
();
ResourceDecoder
<
T
,
Z
>
decoder
=
loadProvider
.
getSourceDecoder
();
ResourceEncoder
<
Z
>
encoder
=
loadProvider
.
getEncoder
();
ModelLoader
<
A
,
T
>
modelLoader
=
loadProvider
.
getModelLoader
();
final
String
id
=
modelLoader
.
getId
(
model
);
...
...
@@ -175,7 +175,7 @@ public class BitmapRequest<A, T> implements Request, Target.SizeReadyCallback, R
}
@Override
public
void
onResourceReady
(
Resource
<
Bitmap
>
resource
)
{
public
void
onResourceReady
(
Resource
<
Z
>
resource
)
{
if
(!
canSetImage
())
{
resource
.
release
();
return
;
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
浏览文件 @
44e0516e
...
...
@@ -11,7 +11,7 @@ import android.widget.ImageView;
import
com.actionbarsherlock.app.SherlockFragment
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.RequestBuilder
;
import
com.bumptech.glide.
Bitmap
RequestBuilder
;
import
com.bumptech.glide.samples.flickr.api.Photo
;
import
java.util.ArrayList
;
...
...
@@ -79,7 +79,7 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer {
}
@Override
protected
RequestBuilder
<
Photo
>
getRequestBuilder
(
Photo
item
)
{
protected
Bitmap
RequestBuilder
<
Photo
>
getRequestBuilder
(
Photo
item
)
{
return
Glide
.
with
(
context
)
.
loadFromImage
(
item
)
.
centerCrop
();
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
浏览文件 @
44e0516e
...
...
@@ -10,9 +10,9 @@ import android.widget.ImageView;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
com.actionbarsherlock.app.SherlockFragment
;
import
com.bumptech.glide.BitmapRequestBuilder
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.RequestBuilder
;
import
com.bumptech.glide.samples.flickr.api.Photo
;
import
java.util.ArrayList
;
...
...
@@ -89,7 +89,7 @@ public class FlickrPhotoList extends SherlockFragment implements PhotoViewer {
}
@Override
protected
RequestBuilder
getRequestBuilder
(
Photo
item
)
{
protected
Bitmap
RequestBuilder
getRequestBuilder
(
Photo
item
)
{
return
Glide
.
with
(
context
)
.
loadFromImage
(
item
)
.
thumbnail
(
0.1f
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录