Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
0ba0245a
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,发现更多精彩内容 >>
提交
0ba0245a
编写于
4月 23, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add BitmapRequest as ImagePresenter replacement.
上级
1ab791a7
变更
13
展开全部
显示空白变更内容
内联
并排
Showing
13 changed file
with
626 addition
and
116 deletion
+626
-116
library/src/com/bumptech/glide/Glide.java
library/src/com/bumptech/glide/Glide.java
+190
-105
library/src/com/bumptech/glide/ListPreloader.java
library/src/com/bumptech/glide/ListPreloader.java
+6
-6
library/src/com/bumptech/glide/presenter/target/BaseTarget.java
...y/src/com/bumptech/glide/presenter/target/BaseTarget.java
+13
-0
library/src/com/bumptech/glide/presenter/target/Target.java
library/src/com/bumptech/glide/presenter/target/Target.java
+6
-0
library/src/com/bumptech/glide/presenter/target/ViewTarget.java
...y/src/com/bumptech/glide/presenter/target/ViewTarget.java
+12
-0
library/src/com/bumptech/glide/resize/BitmapRequest.java
library/src/com/bumptech/glide/resize/BitmapRequest.java
+180
-0
library/src/com/bumptech/glide/resize/BitmapRequestBuilder.java
...y/src/com/bumptech/glide/resize/BitmapRequestBuilder.java
+111
-0
library/src/com/bumptech/glide/resize/Request.java
library/src/com/bumptech/glide/resize/Request.java
+25
-0
library/src/com/bumptech/glide/resize/RequestCoordinator.java
...ary/src/com/bumptech/glide/resize/RequestCoordinator.java
+30
-0
library/src/com/bumptech/glide/resize/ThumbnailRequestCoordinator.java
...om/bumptech/glide/resize/ThumbnailRequestCoordinator.java
+49
-0
library/tests/src/com/bumptech/glide/ListPreloaderTest.java
library/tests/src/com/bumptech/glide/ListPreloaderTest.java
+2
-2
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/FlickrPhotoList.java
...rc/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
+1
-2
未找到文件。
library/src/com/bumptech/glide/Glide.java
浏览文件 @
0ba0245a
此差异已折叠。
点击以展开。
library/src/com/bumptech/glide/ListPreloader.java
浏览文件 @
0ba0245a
...
...
@@ -41,7 +41,7 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
*/
public
ListPreloader
(
int
maxPreload
)
{
this
.
maxPreload
=
maxPreload
;
preloadTargetQueue
=
new
PreloadTargetQueue
(
maxPreload
);
preloadTargetQueue
=
new
PreloadTargetQueue
(
maxPreload
+
1
);
}
@Override
...
...
@@ -83,9 +83,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 Glide.Request}.
* @return A non null {@link Glide.Request
Builder
}.
*/
protected
abstract
Glide
.
Request
getRequest
(
T
item
);
protected
abstract
Glide
.
Request
Builder
getRequest
(
T
item
);
private
void
preload
(
int
start
,
boolean
increasing
)
{
if
(
isIncreasing
!=
increasing
)
{
...
...
@@ -111,13 +111,13 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
if
(
from
<
to
)
{
// Increasing
final
int
numItems
=
items
.
size
();
for
(
int
i
=
0
;
i
<
numItems
;
i
++)
{
for
(
int
i
=
items
.
size
()
-
1
;
i
>=
0
;
i
--)
{
preloadItem
(
items
,
i
);
}
}
else
{
// Decreasing
for
(
int
i
=
items
.
size
()
-
1
;
i
>=
0
;
i
--)
{
final
int
numItems
=
items
.
size
();
for
(
int
i
=
0
;
i
<
numItems
;
i
++)
{
preloadItem
(
items
,
i
);
}
}
...
...
library/src/com/bumptech/glide/presenter/target/BaseTarget.java
浏览文件 @
0ba0245a
...
...
@@ -7,6 +7,8 @@ import android.view.animation.Animation;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.presenter.ImagePresenter
;
import
com.bumptech.glide.presenter.Presenter
;
import
com.bumptech.glide.resize.BitmapRequest
;
import
com.bumptech.glide.resize.Request
;
/**
* A base {@link Target} for loading {@link Bitmap}s that provides basic or empty implementations for most methods.
...
...
@@ -23,6 +25,7 @@ import com.bumptech.glide.presenter.Presenter;
public
abstract
class
BaseTarget
implements
Target
{
private
Presenter
presenter
;
private
Request
request
;
@Override
public
void
setPresenter
(
Presenter
presenter
)
{
...
...
@@ -34,6 +37,16 @@ public abstract class BaseTarget implements Target {
return
presenter
;
}
@Override
public
void
setRequest
(
Request
request
)
{
this
.
request
=
request
;
}
@Override
public
Request
getRequest
()
{
return
request
;
}
@Override
public
void
setPlaceholder
(
Drawable
placeholder
)
{
}
...
...
library/src/com/bumptech/glide/presenter/target/Target.java
浏览文件 @
0ba0245a
...
...
@@ -5,6 +5,8 @@ import android.graphics.drawable.Drawable;
import
android.view.animation.Animation
;
import
com.bumptech.glide.presenter.ImagePresenter
;
import
com.bumptech.glide.presenter.Presenter
;
import
com.bumptech.glide.resize.BitmapRequest
;
import
com.bumptech.glide.resize.Request
;
/**
* An interface that Glide can load an image into
...
...
@@ -50,4 +52,8 @@ public interface Target {
public
void
setPresenter
(
Presenter
presenter
);
public
Presenter
getPresenter
();
public
void
setRequest
(
Request
request
);
public
Request
getRequest
();
}
library/src/com/bumptech/glide/presenter/target/ViewTarget.java
浏览文件 @
0ba0245a
...
...
@@ -12,6 +12,8 @@ import android.view.animation.Animation;
import
android.widget.ListView
;
import
com.bumptech.glide.presenter.ImagePresenter
;
import
com.bumptech.glide.presenter.Presenter
;
import
com.bumptech.glide.resize.BitmapRequest
;
import
com.bumptech.glide.resize.Request
;
import
java.lang.ref.WeakReference
;
import
java.util.HashSet
;
...
...
@@ -80,6 +82,16 @@ public abstract class ViewTarget<T extends View> implements Target {
return
presenter
;
}
@Override
public
void
setRequest
(
Request
request
)
{
view
.
setTag
(
request
);
}
@Override
public
Request
getRequest
()
{
return
(
Request
)
view
.
getTag
();
}
private
static
class
SizeDeterminer
{
private
final
View
view
;
private
Set
<
SizeReadyCallback
>
cbs
=
new
HashSet
<
SizeReadyCallback
>();
...
...
library/src/com/bumptech/glide/resize/BitmapRequest.java
0 → 100644
浏览文件 @
0ba0245a
package
com.bumptech.glide.resize
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.util.Log
;
import
android.view.animation.Animation
;
import
android.view.animation.AnimationUtils
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.loader.bitmap.BitmapLoadFactory
;
import
com.bumptech.glide.presenter.target.Target
;
/**
* A {@link Request} that loads an {@link Bitmap} into a given {@link Target}.
*
* @param <T> The type of the model that the {@link Bitmap} will be loaded from.
*/
public
class
BitmapRequest
<
T
>
implements
Request
,
LoadedCallback
,
Target
.
SizeReadyCallback
{
private
static
final
String
TAG
=
"BitmapRequest"
;
private
final
int
placeholderResourceId
;
private
final
int
errorResourceId
;
private
final
Context
context
;
private
Animation
animation
;
private
final
int
animationId
;
private
final
RequestCoordinator
requestCoordinator
;
private
final
T
model
;
private
final
BitmapLoadFactory
<
T
>
bitmapLoadFactory
;
private
final
ImageManager
imageManager
;
private
final
Priority
priority
;
private
final
Target
target
;
private
final
Glide
.
RequestListener
<
T
>
requestListener
;
private
final
float
sizeMultiplier
;
private
Drawable
placeholderDrawable
;
private
Drawable
errorDrawable
;
private
boolean
isCancelled
;
private
boolean
isError
;
private
boolean
loadedFromMemoryCache
;
private
Bitmap
bitmap
;
private
ImageManager
.
LoadToken
token
;
public
BitmapRequest
(
BitmapRequestBuilder
<
T
>
builder
)
{
this
.
model
=
builder
.
model
;
this
.
context
=
builder
.
context
.
getApplicationContext
();
this
.
bitmapLoadFactory
=
builder
.
bitmapLoadFactory
;
this
.
imageManager
=
builder
.
imageManager
;
this
.
priority
=
builder
.
priority
;
this
.
target
=
builder
.
target
;
this
.
sizeMultiplier
=
builder
.
sizeMultiplier
;
this
.
placeholderDrawable
=
builder
.
placeholderDrawable
;
this
.
placeholderResourceId
=
builder
.
placeholderResourceId
;
this
.
errorDrawable
=
builder
.
errorDrawable
;
this
.
errorResourceId
=
builder
.
errorResourceId
;
this
.
requestListener
=
builder
.
requestListener
;
this
.
animationId
=
builder
.
animationId
;
this
.
animation
=
builder
.
animation
;
this
.
requestCoordinator
=
builder
.
requestCoordinator
;
}
@Override
public
void
run
()
{
loadedFromMemoryCache
=
true
;
target
.
getSize
(
this
);
loadedFromMemoryCache
=
bitmap
!=
null
;
if
(
bitmap
==
null
&&
!
isError
)
{
resetPlaceHolder
();
}
}
public
void
cancel
()
{
isCancelled
=
true
;
if
(
token
!=
null
)
{
token
.
cancel
();
}
}
public
void
clear
()
{
cancel
();
resetPlaceHolder
();
if
(
bitmap
!=
null
)
{
imageManager
.
releaseBitmap
(
bitmap
);
bitmap
=
null
;
}
}
@Override
public
boolean
isComplete
()
{
return
bitmap
!=
null
;
}
private
void
resetPlaceHolder
()
{
if
(!
canSetPlaceholder
())
return
;
if
(
placeholderDrawable
==
null
&&
placeholderResourceId
!=
0
)
{
placeholderDrawable
=
context
.
getResources
().
getDrawable
(
placeholderResourceId
);
}
target
.
setPlaceholder
(
placeholderDrawable
);
}
@Override
public
void
onLoadCompleted
(
Bitmap
loaded
)
{
if
(
isCancelled
||
!
canSetImage
())
{
imageManager
.
releaseBitmap
(
loaded
);
return
;
}
target
.
onImageReady
(
loaded
);
if
(!
loadedFromMemoryCache
&&
!
isAnyImageSet
())
{
if
(
animation
==
null
&&
animationId
!=
0
)
{
animation
=
AnimationUtils
.
loadAnimation
(
context
,
animationId
);
}
if
(
animation
!=
null
)
{
target
.
startAnimation
(
animation
);
}
}
if
(
requestListener
!=
null
)
{
requestListener
.
onImageReady
(
model
,
target
,
loadedFromMemoryCache
,
isAnyImageSet
());
}
bitmap
=
loaded
;
}
@Override
public
void
onLoadFailed
(
Exception
e
)
{
if
(
isCancelled
)
{
return
;
}
else
{
Log
.
e
(
TAG
,
"load failed"
,
e
);
}
isError
=
true
;
if
(
canSetPlaceholder
())
{
if
(
errorDrawable
==
null
&&
errorResourceId
!=
0
)
{
errorDrawable
=
context
.
getResources
().
getDrawable
(
errorResourceId
);
}
target
.
setPlaceholder
(
errorDrawable
);
}
//TODO: what if this is a thumbnail request?
if
(
requestListener
!=
null
)
{
requestListener
.
onException
(
e
,
model
,
target
);
}
}
@Override
public
void
onSizeReady
(
int
width
,
int
height
)
{
// This should only be called once.
if
(
isCancelled
)
{
return
;
}
width
=
Math
.
round
(
sizeMultiplier
*
width
);
height
=
Math
.
round
(
sizeMultiplier
*
height
);
BitmapLoad
loadTask
=
bitmapLoadFactory
.
getLoadTask
(
model
,
width
,
height
);
if
(
loadTask
==
null
)
{
if
(
Log
.
isLoggable
(
TAG
,
Log
.
INFO
))
{
Log
.
i
(
TAG
,
"got null load task for model="
+
model
);
}
clear
();
return
;
}
loadTask
.
setMetadata
(
new
Metadata
(
priority
));
token
=
imageManager
.
getImage
(
loadTask
,
this
);
}
private
boolean
canSetImage
()
{
return
requestCoordinator
==
null
||
requestCoordinator
.
canSetImage
(
this
);
}
private
boolean
canSetPlaceholder
()
{
return
requestCoordinator
==
null
||
requestCoordinator
.
canSetPlaceholder
(
this
);
}
private
boolean
isAnyImageSet
()
{
return
requestCoordinator
!=
null
&&
requestCoordinator
.
isAnyRequestComplete
();
}
}
library/src/com/bumptech/glide/resize/BitmapRequestBuilder.java
0 → 100644
浏览文件 @
0ba0245a
package
com.bumptech.glide.resize
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.view.animation.Animation
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.loader.bitmap.BitmapLoadFactory
;
import
com.bumptech.glide.presenter.target.Target
;
/**
* A simple builder class for {@link BitmapRequest}.
*
* @param <T> The model type the {@link BitmapRequest} will load a {@link Bitmap} from.
*/
public
class
BitmapRequestBuilder
<
T
>
{
T
model
;
BitmapLoadFactory
<
T
>
bitmapLoadFactory
;
ImageManager
imageManager
;
Target
target
;
Priority
priority
;
float
sizeMultiplier
;
Drawable
placeholderDrawable
;
Drawable
errorDrawable
;
Glide
.
RequestListener
<
T
>
requestListener
;
Animation
animation
;
int
placeholderResourceId
;
int
errorResourceId
;
Context
context
;
RequestCoordinator
requestCoordinator
;
int
animationId
;
public
BitmapRequestBuilder
<
T
>
setModel
(
T
model
)
{
this
.
model
=
model
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setContext
(
Context
context
)
{
this
.
context
=
context
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setBitmapLoadFactory
(
BitmapLoadFactory
<
T
>
bitmapLoadFactory
)
{
this
.
bitmapLoadFactory
=
bitmapLoadFactory
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setImageManager
(
ImageManager
imageManager
)
{
this
.
imageManager
=
imageManager
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setTarget
(
Target
target
)
{
this
.
target
=
target
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setPriority
(
Priority
priority
)
{
this
.
priority
=
priority
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setSizeMultiplier
(
float
sizeMultiplier
)
{
this
.
sizeMultiplier
=
sizeMultiplier
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setRequestListener
(
Glide
.
RequestListener
<
T
>
requestListener
)
{
this
.
requestListener
=
requestListener
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setAnimation
(
int
animationId
)
{
this
.
animationId
=
animationId
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setAnimation
(
Animation
animation
)
{
this
.
animation
=
animation
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setPlaceholderResource
(
int
resourceId
)
{
this
.
placeholderResourceId
=
resourceId
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setPlaceholderDrawable
(
Drawable
placeholderDrawable
)
{
this
.
placeholderDrawable
=
placeholderDrawable
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setErrorResource
(
int
resourceId
)
{
this
.
errorResourceId
=
resourceId
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setErrorDrawable
(
Drawable
errorDrawable
)
{
this
.
errorDrawable
=
errorDrawable
;
return
this
;
}
public
BitmapRequestBuilder
<
T
>
setRequestCoordinator
(
RequestCoordinator
requestCoordinator
)
{
this
.
requestCoordinator
=
requestCoordinator
;
return
this
;
}
public
BitmapRequest
<
T
>
build
()
{
return
new
BitmapRequest
<
T
>(
this
);
}
}
\ No newline at end of file
library/src/com/bumptech/glide/resize/Request.java
0 → 100644
浏览文件 @
0ba0245a
package
com.bumptech.glide.resize
;
import
com.bumptech.glide.presenter.target.Target
;
/**
* A request that loads an asset for an {@link Target}.
*/
public
interface
Request
{
/**
* Starts an asynchronous load.
*/
public
void
run
();
/**
* Prevents any bitmaps being loaded from previous requests, releases any resources held by this request and
* displays the current placeholder if one was provided.
*/
public
void
clear
();
/**
* Returns true if the request has successfully completed.
*/
public
boolean
isComplete
();
}
library/src/com/bumptech/glide/resize/RequestCoordinator.java
0 → 100644
浏览文件 @
0ba0245a
package
com.bumptech.glide.resize
;
import
com.bumptech.glide.resize.target.Target
;
/**
* An interface for coordinating multiple requests with the same {@link Target}.
*/
public
interface
RequestCoordinator
{
/**
* Returns true if the {@link Request} can display a loaded bitmap.
*
* @param request The {@link Request} requesting permission to display a bitmap.
*/
public
boolean
canSetImage
(
Request
request
);
/**
* Returns true if the {@link Request} can display a placeholder.
*
* @param request The {@link Request} requesting permission to display a placeholder.
*/
public
boolean
canSetPlaceholder
(
Request
request
);
/**
* Returns true if any coordinated {@link Request} has successfully completed.
*
* @see Request#isComplete()
*/
public
boolean
isAnyRequestComplete
();
}
library/src/com/bumptech/glide/resize/ThumbnailRequestCoordinator.java
0 → 100644
浏览文件 @
0ba0245a
package
com.bumptech.glide.resize
;
/**
* A coordinator that coordinates two individual {@link Request}s that load a small thumbnail version of an image and
* the full size version of the image at the same time.
*/
public
class
ThumbnailRequestCoordinator
implements
RequestCoordinator
,
Request
{
private
Request
full
;
private
Request
thumb
;
public
void
setRequests
(
Request
full
,
Request
thumb
)
{
this
.
full
=
full
;
this
.
thumb
=
thumb
;
}
@Override
public
boolean
canSetImage
(
Request
request
)
{
return
request
==
full
||
!
full
.
isComplete
();
}
@Override
public
boolean
canSetPlaceholder
(
Request
request
)
{
return
request
==
full
;
}
@Override
public
boolean
isAnyRequestComplete
()
{
return
full
.
isComplete
()
||
thumb
.
isComplete
();
}
@Override
public
void
run
()
{
full
.
run
();
if
(!
full
.
isComplete
())
{
thumb
.
run
();
}
}
@Override
public
void
clear
()
{
full
.
clear
();
thumb
.
clear
();
}
@Override
public
boolean
isComplete
()
{
return
full
.
isComplete
();
}
}
library/tests/src/com/bumptech/glide/ListPreloaderTest.java
浏览文件 @
0ba0245a
...
...
@@ -154,7 +154,7 @@ public class ListPreloaderTest extends AndroidTestCase {
}
@Override
protected
Glide
.
Request
getRequest
(
Object
item
)
{
protected
Glide
.
Request
Builder
getRequest
(
Object
item
)
{
loadedObjects
.
add
(
item
);
return
super
.
getRequest
(
item
);
}
...
...
@@ -190,7 +190,7 @@ public class ListPreloaderTest extends AndroidTestCase {
}
@Override
protected
Glide
.
Request
getRequest
(
Object
item
)
{
protected
Glide
.
Request
Builder
getRequest
(
Object
item
)
{
return
Glide
.
with
(
context
).
using
(
new
StreamModelLoader
<
Object
>()
{
@Override
public
ResourceFetcher
<
InputStream
>
getResourceFetcher
(
final
Object
model
,
int
width
,
int
height
)
{
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
浏览文件 @
0ba0245a
...
...
@@ -91,7 +91,7 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer {
}
@Override
protected
Glide
.
Request
<
Photo
>
getRequest
(
Photo
item
)
{
protected
Glide
.
Request
Builder
<
Photo
>
getRequest
(
Photo
item
)
{
return
Glide
.
with
(
context
)
.
using
(
new
FlickrModelLoader
(
getActivity
(),
urlCache
))
.
load
(
item
)
...
...
samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
浏览文件 @
0ba0245a
...
...
@@ -13,7 +13,6 @@ import com.actionbarsherlock.app.SherlockFragment;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.loader.bitmap.model.Cache
;
import
com.bumptech.glide.presenter.target.Target
;
import
com.bumptech.glide.samples.flickr.api.Photo
;
import
java.net.URL
;
...
...
@@ -92,7 +91,7 @@ public class FlickrPhotoList extends SherlockFragment implements PhotoViewer {
}
@Override
protected
Glide
.
Request
getRequest
(
Photo
item
)
{
protected
Glide
.
Request
Builder
getRequest
(
Photo
item
)
{
return
Glide
.
with
(
context
)
.
using
(
new
FlickrModelLoader
(
getActivity
(),
urlCache
))
.
load
(
item
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录