Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
da4ce795
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,发现更多精彩内容 >>
提交
da4ce795
编写于
6月 22, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve thumbnail performance.
上级
4a5c5613
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
172 addition
and
11 deletion
+172
-11
library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java
...umptech/glide/request/target/DrawableImageViewTarget.java
+14
-0
library/src/main/java/com/bumptech/glide/request/target/SquaringDrawable.java
...a/com/bumptech/glide/request/target/SquaringDrawable.java
+149
-0
library/src/main/java/com/bumptech/glide/request/target/Target.java
...c/main/java/com/bumptech/glide/request/target/Target.java
+1
-1
samples/flickr/res/layout/flickr_photo_grid_item.xml
samples/flickr/res/layout/flickr_photo_grid_item.xml
+0
-1
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
...va/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
+3
-5
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
...va/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
+4
-3
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/api/Api.java
.../main/java/com/bumptech/glide/samples/flickr/api/Api.java
+1
-1
未找到文件。
library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java
浏览文件 @
da4ce795
...
...
@@ -5,6 +5,7 @@ import android.widget.ImageView;
import
com.bumptech.glide.request.GlideAnimation
;
public
class
DrawableImageViewTarget
extends
ViewTarget
<
ImageView
,
Drawable
>
{
private
static
final
float
SQUARE_RATIO_MARGIN
=
0.05f
;
private
final
ImageView
view
;
public
DrawableImageViewTarget
(
ImageView
view
)
{
...
...
@@ -14,6 +15,19 @@ public class DrawableImageViewTarget extends ViewTarget<ImageView, Drawable> {
@Override
public
void
onResourceReady
(
Drawable
resource
,
GlideAnimation
<
Drawable
>
animation
)
{
//TODO: Try to generalize this to other sizes/shapes.
// This is a dirty hack that tries to make loading square thumbnails and then square full images less costly by
// forcing both the smaller thumb and the larger version to have exactly the same intrinsic dimensions. If a
// drawable is replaced in an ImageView by another drawable with different intrinsic dimensions, the ImageView
// requests a layout. Scrolling rapidly while replacing thumbs with larger images triggers lots of these calls
// and causes significant amounts of jank.
float
viewRatio
=
view
.
getWidth
()
/
(
float
)
view
.
getHeight
();
float
drawableRatio
=
resource
.
getIntrinsicWidth
()
/
(
float
)
resource
.
getIntrinsicHeight
();
if
(
Math
.
abs
(
viewRatio
-
1
f
)
<=
SQUARE_RATIO_MARGIN
&&
Math
.
abs
(
drawableRatio
-
1
f
)
<=
SQUARE_RATIO_MARGIN
)
{
resource
=
new
SquaringDrawable
(
resource
,
view
.
getWidth
());
}
if
(
animation
==
null
||
!
animation
.
animate
(
view
.
getDrawable
(),
resource
,
view
,
this
))
{
view
.
setImageDrawable
(
resource
);
}
...
...
library/src/main/java/com/bumptech/glide/request/target/SquaringDrawable.java
0 → 100644
浏览文件 @
da4ce795
package
com.bumptech.glide.request.target
;
import
android.annotation.TargetApi
;
import
android.graphics.Canvas
;
import
android.graphics.ColorFilter
;
import
android.graphics.PorterDuff
;
import
android.graphics.Rect
;
import
android.graphics.drawable.Drawable
;
/**
* A wrapper drawable to square the wrapped drawable so that it expands to fill a square with exactly the given side
* length. The goal of this drawable is to ensure that square thumbnail drawables always match the size of the view
* they will be displayed in to avoid a costly requestLayout call. This class should not be used with views or drawables
* that are not square.
*/
public
class
SquaringDrawable
extends
Drawable
{
private
final
Drawable
wrapped
;
private
int
side
;
public
SquaringDrawable
(
Drawable
wrapped
,
int
side
)
{
this
.
wrapped
=
wrapped
;
this
.
side
=
side
;
}
@Override
public
void
setBounds
(
int
left
,
int
top
,
int
right
,
int
bottom
)
{
super
.
setBounds
(
left
,
top
,
right
,
bottom
);
wrapped
.
setBounds
(
left
,
top
,
right
,
bottom
);
}
@Override
public
void
setBounds
(
Rect
bounds
)
{
super
.
setBounds
(
bounds
);
wrapped
.
setBounds
(
bounds
);
}
public
void
setChangingConfigurations
(
int
configs
)
{
wrapped
.
setChangingConfigurations
(
configs
);
}
@Override
public
int
getChangingConfigurations
()
{
return
wrapped
.
getChangingConfigurations
();
}
@Override
public
void
setDither
(
boolean
dither
)
{
wrapped
.
setDither
(
dither
);
}
@Override
public
void
setFilterBitmap
(
boolean
filter
)
{
wrapped
.
setFilterBitmap
(
filter
);
}
@TargetApi
(
11
)
@Override
public
Callback
getCallback
()
{
return
wrapped
.
getCallback
();
}
@TargetApi
(
19
)
@Override
public
int
getAlpha
()
{
return
wrapped
.
getAlpha
();
}
@Override
public
void
setColorFilter
(
int
color
,
PorterDuff
.
Mode
mode
)
{
wrapped
.
setColorFilter
(
color
,
mode
);
}
@Override
public
void
clearColorFilter
()
{
wrapped
.
clearColorFilter
();
}
@Override
public
Drawable
getCurrent
()
{
return
wrapped
.
getCurrent
();
}
@Override
public
boolean
setVisible
(
boolean
visible
,
boolean
restart
)
{
return
wrapped
.
setVisible
(
visible
,
restart
);
}
@Override
public
int
getIntrinsicWidth
()
{
return
side
;
}
@Override
public
int
getIntrinsicHeight
()
{
return
side
;
}
@Override
public
int
getMinimumWidth
()
{
return
wrapped
.
getMinimumWidth
();
}
@Override
public
int
getMinimumHeight
()
{
return
wrapped
.
getMinimumHeight
();
}
@Override
public
boolean
getPadding
(
Rect
padding
)
{
return
wrapped
.
getPadding
(
padding
);
}
@Override
public
void
invalidateSelf
()
{
super
.
invalidateSelf
();
//To change body of overridden methods use File | Settings | File Templates.
wrapped
.
invalidateSelf
();
}
@Override
public
void
unscheduleSelf
(
Runnable
what
)
{
super
.
unscheduleSelf
(
what
);
//To change body of overridden methods use File | Settings | File Templates.
wrapped
.
unscheduleSelf
(
what
);
}
@Override
public
void
scheduleSelf
(
Runnable
what
,
long
when
)
{
super
.
scheduleSelf
(
what
,
when
);
//To change body of overridden methods use File | Settings | File Templates.
wrapped
.
scheduleSelf
(
what
,
when
);
}
@Override
public
void
draw
(
Canvas
canvas
)
{
wrapped
.
draw
(
canvas
);
}
@Override
public
void
setAlpha
(
int
i
)
{
wrapped
.
setAlpha
(
i
);
}
@Override
public
void
setColorFilter
(
ColorFilter
colorFilter
)
{
wrapped
.
setColorFilter
(
colorFilter
);
}
@Override
public
int
getOpacity
()
{
return
wrapped
.
getOpacity
();
}
}
library/src/main/java/com/bumptech/glide/request/target/Target.java
浏览文件 @
da4ce795
...
...
@@ -7,7 +7,7 @@ import com.bumptech.glide.request.Request;
/**
* An interface that Glide can load an image into
*
* @param <
Z
> The type of resource the target can display.
* @param <
R
> The type of resource the target can display.
*/
public
interface
Target
<
R
>
{
...
...
samples/flickr/res/layout/flickr_photo_grid_item.xml
浏览文件 @
da4ce795
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:scaleType=
"centerCrop"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
/>
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
浏览文件 @
da4ce795
...
...
@@ -99,9 +99,8 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer {
protected
GenericRequestBuilder
getRequestBuilder
(
Photo
item
)
{
return
Glide
.
with
(
FlickrPhotoGrid
.
this
)
.
loadFromImage
(
item
)
.
override
(
Api
.
THUMB_SIZE
,
Api
.
THUMB_SIZE
)
.
priority
(
Priority
.
HIGH
)
.
centerCrop
();
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
)
.
priority
(
Priority
.
HIGH
);
}
}
...
...
@@ -150,8 +149,7 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer {
.
loadFromImage
(
current
)
.
thumbnail
(
Glide
.
with
(
FlickrPhotoGrid
.
this
)
.
loadFromImage
(
current
)
.
override
(
Api
.
THUMB_SIZE
,
Api
.
THUMB_SIZE
)
.
centerCrop
()
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
)
)
.
animate
(
R
.
anim
.
fade_in
)
.
centerCrop
()
...
...
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
浏览文件 @
da4ce795
...
...
@@ -116,7 +116,8 @@ public class FlickrPhotoList extends SherlockFragment implements PhotoViewer {
.
loadFromImage
(
item
)
.
thumbnail
(
Glide
.
with
(
FlickrPhotoList
.
this
)
.
loadFromImage
(
item
)
.
override
(
Api
.
THUMB_SIZE
,
Api
.
THUMB_SIZE
))
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
)
)
.
centerCrop
();
}
}
...
...
@@ -176,7 +177,7 @@ public class FlickrPhotoList extends SherlockFragment implements PhotoViewer {
.
placeholder
(
new
ColorDrawable
(
Color
.
GRAY
))
.
thumbnail
(
Glide
.
with
(
FlickrPhotoList
.
this
)
.
loadFromImage
(
current
)
.
override
(
Api
.
THUMB_SIZE
,
Api
.
THUMB_SIZE
))
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_
THUMB_SIZE
))
.
centerCrop
()
.
crossFade
(
R
.
anim
.
fade_in
,
150
)
.
into
(
viewHolder
.
imageView
);
...
...
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/api/Api.java
浏览文件 @
da4ce795
...
...
@@ -45,7 +45,7 @@ public class Api {
Collections
.
sort
(
SORTED_SIZE_KEYS
);
}
public
static
final
int
THUMB_SIZE
=
SORTED_SIZE_KEYS
.
get
(
0
);
public
static
final
int
SQUARE_
THUMB_SIZE
=
SORTED_SIZE_KEYS
.
get
(
0
);
private
static
String
getSizeKey
(
int
width
,
int
height
)
{
final
int
largestEdge
=
Math
.
max
(
width
,
height
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录