Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
7ace7e95
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,发现更多精彩内容 >>
提交
7ace7e95
编写于
10月 12, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add from() api to allow builders to be re-used.
上级
b0108222
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
317 addition
and
155 deletion
+317
-155
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
...c/main/java/com/bumptech/glide/GenericRequestBuilder.java
+0
-1
library/src/main/java/com/bumptech/glide/Glide.java
library/src/main/java/com/bumptech/glide/Glide.java
+7
-7
library/src/main/java/com/bumptech/glide/RequestManager.java
library/src/main/java/com/bumptech/glide/RequestManager.java
+215
-75
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
...va/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
+23
-23
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
...va/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
+27
-16
samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java
...n/java/com/bumptech/glide/samples/giphy/MainActivity.java
+19
-7
samples/svg/src/main/java/com/bumptech/svgsample/app/MainActivity.java
...rc/main/java/com/bumptech/svgsample/app/MainActivity.java
+26
-26
未找到文件。
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
7ace7e95
...
@@ -559,7 +559,6 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
...
@@ -559,7 +559,6 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
return
this
;
return
this
;
}
}
/**
/**
* Set the target the resource will be loaded into.
* Set the target the resource will be loaded into.
*
*
...
...
library/src/main/java/com/bumptech/glide/Glide.java
浏览文件 @
7ace7e95
...
@@ -474,6 +474,12 @@ public class Glide {
...
@@ -474,6 +474,12 @@ public class Glide {
*/
*/
public
static
<
T
,
Y
>
ModelLoader
<
T
,
Y
>
buildModelLoader
(
Class
<
T
>
modelClass
,
Class
<
Y
>
resourceClass
,
public
static
<
T
,
Y
>
ModelLoader
<
T
,
Y
>
buildModelLoader
(
Class
<
T
>
modelClass
,
Class
<
Y
>
resourceClass
,
Context
context
)
{
Context
context
)
{
if
(
modelClass
==
null
)
{
if
(
Log
.
isLoggable
(
TAG
,
Log
.
DEBUG
))
{
Log
.
d
(
TAG
,
"Unable to load null model, setting placeholder only"
);
}
return
null
;
}
return
Glide
.
get
(
context
).
getLoaderFactory
().
buildModelLoader
(
modelClass
,
resourceClass
,
context
);
return
Glide
.
get
(
context
).
getLoaderFactory
().
buildModelLoader
(
modelClass
,
resourceClass
,
context
);
}
}
...
@@ -492,13 +498,7 @@ public class Glide {
...
@@ -492,13 +498,7 @@ public class Glide {
*/
*/
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
,
Y
>
ModelLoader
<
T
,
Y
>
buildModelLoader
(
T
model
,
Class
<
Y
>
resourceClass
,
Context
context
)
{
public
static
<
T
,
Y
>
ModelLoader
<
T
,
Y
>
buildModelLoader
(
T
model
,
Class
<
Y
>
resourceClass
,
Context
context
)
{
if
(
model
==
null
)
{
return
buildModelLoader
(
model
!=
null
?
(
Class
<
T
>)
model
.
getClass
()
:
null
,
resourceClass
,
context
);
if
(
Log
.
isLoggable
(
TAG
,
Log
.
DEBUG
))
{
Log
.
d
(
TAG
,
"Unable to load null model, setting placeholder only"
);
}
return
null
;
}
return
buildModelLoader
((
Class
<
T
>)
model
.
getClass
(),
resourceClass
,
context
);
}
}
/**
/**
...
...
library/src/main/java/com/bumptech/glide/RequestManager.java
浏览文件 @
7ace7e95
此差异已折叠。
点击以展开。
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
浏览文件 @
7ace7e95
...
@@ -37,6 +37,9 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
...
@@ -37,6 +37,9 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
private
int
photoSize
;
private
int
photoSize
;
private
GridView
grid
;
private
GridView
grid
;
private
boolean
thumbnail
;
private
boolean
thumbnail
;
private
DrawableRequestBuilder
<
Photo
>
fullRequest
;
private
DrawableRequestBuilder
<
Photo
>
thumbnailRequest
;
private
DrawableRequestBuilder
<
Photo
>
preloadRequest
;
public
static
FlickrPhotoGrid
newInstance
(
int
size
,
int
preloadCount
,
boolean
thumbnail
)
{
public
static
FlickrPhotoGrid
newInstance
(
int
size
,
int
preloadCount
,
boolean
thumbnail
)
{
FlickrPhotoGrid
photoGrid
=
new
FlickrPhotoGrid
();
FlickrPhotoGrid
photoGrid
=
new
FlickrPhotoGrid
();
...
@@ -54,6 +57,22 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
...
@@ -54,6 +57,22 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
photoSize
=
args
.
getInt
(
IMAGE_SIZE_KEY
);
photoSize
=
args
.
getInt
(
IMAGE_SIZE_KEY
);
thumbnail
=
args
.
getBoolean
(
THUMBNAIL_KEY
);
thumbnail
=
args
.
getBoolean
(
THUMBNAIL_KEY
);
fullRequest
=
Glide
.
with
(
this
)
.
from
(
Photo
.
class
)
.
centerCrop
()
.
crossFade
(
R
.
anim
.
fade_in
,
150
);
thumbnailRequest
=
Glide
.
with
(
this
)
.
from
(
Photo
.
class
)
.
priority
(
Priority
.
HIGH
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
);
preloadRequest
=
thumbnail
?
thumbnailRequest
:
Glide
.
with
(
this
)
.
from
(
Photo
.
class
)
.
priority
(
Priority
.
HIGH
)
.
centerCrop
();
final
View
result
=
inflater
.
inflate
(
R
.
layout
.
flickr_photo_grid
,
container
,
false
);
final
View
result
=
inflater
.
inflate
(
R
.
layout
.
flickr_photo_grid
,
container
,
false
);
grid
=
(
GridView
)
result
.
findViewById
(
R
.
id
.
images
);
grid
=
(
GridView
)
result
.
findViewById
(
R
.
id
.
images
);
grid
.
setColumnWidth
(
photoSize
);
grid
.
setColumnWidth
(
photoSize
);
...
@@ -109,16 +128,7 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
...
@@ -109,16 +128,7 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
@Override
@Override
protected
GenericRequestBuilder
getRequestBuilder
(
Photo
item
)
{
protected
GenericRequestBuilder
getRequestBuilder
(
Photo
item
)
{
DrawableRequestBuilder
<
Photo
>
request
=
Glide
.
with
(
FlickrPhotoGrid
.
this
)
return
preloadRequest
.
load
(
item
);
.
load
(
item
)
.
priority
(
Priority
.
HIGH
);
if
(
thumbnail
)
{
request
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
);
}
else
{
request
.
centerCrop
();
}
return
request
;
}
}
}
}
...
@@ -163,20 +173,10 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
...
@@ -163,20 +173,10 @@ public class FlickrPhotoGrid extends Fragment implements PhotoViewer {
imageView
=
(
ImageView
)
view
;
imageView
=
(
ImageView
)
view
;
}
}
DrawableRequestBuilder
<
Photo
>
request
=
Glide
.
with
(
FlickrPhotoGrid
.
this
)
fullRequest
.
load
(
current
)
.
load
(
current
)
.
centerCrop
()
.
thumbnail
(
thumbnail
?
thumbnailRequest
.
load
(
current
)
:
null
)
.
crossFade
(
R
.
anim
.
fade_in
,
150
);
.
into
(
imageView
);
if
(
thumbnail
)
{
request
.
thumbnail
(
Glide
.
with
(
FlickrPhotoGrid
.
this
)
.
load
(
current
)
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
);
}
request
.
into
(
imageView
);
return
imageView
;
return
imageView
;
}
}
...
...
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
浏览文件 @
7ace7e95
...
@@ -12,9 +12,11 @@ import android.widget.ImageView;
...
@@ -12,9 +12,11 @@ import android.widget.ImageView;
import
android.widget.ListView
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.bumptech.glide.DrawableRequestBuilder
;
import
com.bumptech.glide.GenericRequestBuilder
;
import
com.bumptech.glide.GenericRequestBuilder
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.Priority
;
import
com.bumptech.glide.load.engine.DiskCacheStrategy
;
import
com.bumptech.glide.load.engine.DiskCacheStrategy
;
import
com.bumptech.glide.samples.flickr.api.Api
;
import
com.bumptech.glide.samples.flickr.api.Api
;
import
com.bumptech.glide.samples.flickr.api.Photo
;
import
com.bumptech.glide.samples.flickr.api.Photo
;
...
@@ -32,6 +34,9 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
...
@@ -32,6 +34,9 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
private
List
<
Photo
>
currentPhotos
;
private
List
<
Photo
>
currentPhotos
;
private
FlickrListPreloader
preloader
;
private
FlickrListPreloader
preloader
;
private
ListView
list
;
private
ListView
list
;
private
DrawableRequestBuilder
<
Photo
>
fullRequest
;
private
DrawableRequestBuilder
<
Photo
>
thumbRequest
;
private
DrawableRequestBuilder
<
Photo
>
preloadRequest
;
public
static
FlickrPhotoList
newInstance
()
{
public
static
FlickrPhotoList
newInstance
()
{
return
new
FlickrPhotoList
();
return
new
FlickrPhotoList
();
...
@@ -57,6 +62,23 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
...
@@ -57,6 +62,23 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
adapter
.
setPhotos
(
currentPhotos
);
adapter
.
setPhotos
(
currentPhotos
);
}
}
fullRequest
=
Glide
.
with
(
FlickrPhotoList
.
this
)
.
from
(
Photo
.
class
)
.
placeholder
(
new
ColorDrawable
(
Color
.
GRAY
))
.
centerCrop
();
preloadRequest
=
Glide
.
with
(
FlickrPhotoList
.
this
)
.
from
(
Photo
.
class
)
.
placeholder
(
new
ColorDrawable
(
Color
.
GRAY
))
.
centerCrop
()
.
priority
(
Priority
.
HIGH
);
thumbRequest
=
Glide
.
with
(
FlickrPhotoList
.
this
)
.
from
(
Photo
.
class
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
);
if
(
savedInstanceState
!=
null
)
{
if
(
savedInstanceState
!=
null
)
{
int
index
=
savedInstanceState
.
getInt
(
STATE_POSITION_INDEX
);
int
index
=
savedInstanceState
.
getInt
(
STATE_POSITION_INDEX
);
int
offset
=
savedInstanceState
.
getInt
(
STATE_POSITION_OFFSET
);
int
offset
=
savedInstanceState
.
getInt
(
STATE_POSITION_OFFSET
);
...
@@ -117,14 +139,9 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
...
@@ -117,14 +139,9 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
@Override
@Override
protected
GenericRequestBuilder
getRequestBuilder
(
Photo
item
)
{
protected
GenericRequestBuilder
getRequestBuilder
(
Photo
item
)
{
return
Glide
.
with
(
FlickrPhotoList
.
this
)
return
preloadRequest
.
load
(
item
)
.
thumbnail
(
thumbRequest
.
load
(
item
))
.
centerCrop
()
.
load
(
item
);
.
thumbnail
(
Glide
.
with
(
FlickrPhotoList
.
this
)
.
load
(
item
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
)
);
}
}
}
}
...
@@ -178,15 +195,9 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
...
@@ -178,15 +195,9 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
viewHolder
=
(
ViewHolder
)
view
.
getTag
();
viewHolder
=
(
ViewHolder
)
view
.
getTag
();
}
}
Glide
.
with
(
FlickrPhotoList
.
this
)
fullRequest
.
thumbnail
(
thumbRequest
.
load
(
current
))
.
load
(
current
)
.
load
(
current
)
.
placeholder
(
new
ColorDrawable
(
Color
.
GRAY
))
.
centerCrop
()
.
crossFade
(
R
.
anim
.
fade_in
,
150
)
.
thumbnail
(
Glide
.
with
(
FlickrPhotoList
.
this
)
.
load
(
current
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
.
override
(
Api
.
SQUARE_THUMB_SIZE
,
Api
.
SQUARE_THUMB_SIZE
))
.
into
(
viewHolder
.
imageView
);
.
into
(
viewHolder
.
imageView
);
viewHolder
.
titleText
.
setText
(
current
.
getTitle
());
viewHolder
.
titleText
.
setText
(
current
.
getTitle
());
...
...
samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java
浏览文件 @
7ace7e95
...
@@ -8,9 +8,11 @@ import android.view.ViewGroup;
...
@@ -8,9 +8,11 @@ import android.view.ViewGroup;
import
android.widget.BaseAdapter
;
import
android.widget.BaseAdapter
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.ListView
;
import
com.bumptech.glide.DrawableRequestBuilder
;
import
com.bumptech.glide.GenericRequestBuilder
;
import
com.bumptech.glide.GenericRequestBuilder
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.ListPreloader
;
import
com.bumptech.glide.Priority
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -23,6 +25,7 @@ public class MainActivity extends Activity implements Api.Monitor {
...
@@ -23,6 +25,7 @@ public class MainActivity extends Activity implements Api.Monitor {
private
static
final
String
TAG
=
"GiphyActivity"
;
private
static
final
String
TAG
=
"GiphyActivity"
;
private
GifAdapter
adapter
;
private
GifAdapter
adapter
;
private
DrawableRequestBuilder
<
Api
.
GifResult
>
preloadRequest
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -41,7 +44,16 @@ public class MainActivity extends Activity implements Api.Monitor {
...
@@ -41,7 +44,16 @@ public class MainActivity extends Activity implements Api.Monitor {
ListView
gifList
=
(
ListView
)
findViewById
(
R
.
id
.
gif_list
);
ListView
gifList
=
(
ListView
)
findViewById
(
R
.
id
.
gif_list
);
GiphyPreloader
preloader
=
new
GiphyPreloader
(
2
);
GiphyPreloader
preloader
=
new
GiphyPreloader
(
2
);
adapter
=
new
GifAdapter
(
this
,
preloader
);
DrawableRequestBuilder
<
Api
.
GifResult
>
fullRequest
=
Glide
.
with
(
this
)
.
from
(
Api
.
GifResult
.
class
)
.
fitCenter
();
preloadRequest
=
Glide
.
with
(
this
)
.
from
(
Api
.
GifResult
.
class
)
.
fitCenter
()
.
priority
(
Priority
.
HIGH
);
adapter
=
new
GifAdapter
(
this
,
preloader
,
fullRequest
);
gifList
.
setAdapter
(
adapter
);
gifList
.
setAdapter
(
adapter
);
gifList
.
setOnScrollListener
(
preloader
);
gifList
.
setOnScrollListener
(
preloader
);
}
}
...
@@ -87,9 +99,7 @@ public class MainActivity extends Activity implements Api.Monitor {
...
@@ -87,9 +99,7 @@ public class MainActivity extends Activity implements Api.Monitor {
@Override
@Override
protected
GenericRequestBuilder
getRequestBuilder
(
Api
.
GifResult
item
)
{
protected
GenericRequestBuilder
getRequestBuilder
(
Api
.
GifResult
item
)
{
return
Glide
.
with
(
MainActivity
.
this
)
return
preloadRequest
.
load
(
item
);
.
load
(
item
)
.
fitCenter
();
}
}
}
}
...
@@ -98,12 +108,15 @@ public class MainActivity extends Activity implements Api.Monitor {
...
@@ -98,12 +108,15 @@ public class MainActivity extends Activity implements Api.Monitor {
private
final
Activity
activity
;
private
final
Activity
activity
;
private
final
GiphyPreloader
preloader
;
private
final
GiphyPreloader
preloader
;
private
DrawableRequestBuilder
<
Api
.
GifResult
>
requestBuilder
;
private
Api
.
GifResult
[]
results
=
EMPTY_RESULTS
;
private
Api
.
GifResult
[]
results
=
EMPTY_RESULTS
;
public
GifAdapter
(
Activity
activity
,
GiphyPreloader
preloader
)
{
public
GifAdapter
(
Activity
activity
,
GiphyPreloader
preloader
,
DrawableRequestBuilder
<
Api
.
GifResult
>
requestBuilder
)
{
this
.
activity
=
activity
;
this
.
activity
=
activity
;
this
.
preloader
=
preloader
;
this
.
preloader
=
preloader
;
this
.
requestBuilder
=
requestBuilder
;
}
}
public
void
setResults
(
Api
.
GifResult
[]
results
)
{
public
void
setResults
(
Api
.
GifResult
[]
results
)
{
...
@@ -142,9 +155,8 @@ public class MainActivity extends Activity implements Api.Monitor {
...
@@ -142,9 +155,8 @@ public class MainActivity extends Activity implements Api.Monitor {
}
}
final
ImageView
gifView
=
(
ImageView
)
convertView
.
findViewById
(
R
.
id
.
gif_view
);
final
ImageView
gifView
=
(
ImageView
)
convertView
.
findViewById
(
R
.
id
.
gif_view
);
Glide
.
with
(
activity
)
requestBuilder
.
load
(
result
)
.
load
(
result
)
.
fitCenter
()
.
into
(
gifView
);
.
into
(
gifView
);
if
(
preloader
.
dimensions
==
null
)
{
if
(
preloader
.
dimensions
==
null
)
{
...
...
samples/svg/src/main/java/com/bumptech/svgsample/app/MainActivity.java
浏览文件 @
7ace7e95
package
com.bumptech.svgsample.app
;
package
com.bumptech.svgsample.app
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.ContentResolver
;
import
android.graphics.drawable.PictureDrawable
;
import
android.graphics.drawable.PictureDrawable
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.bumptech.glide.GenericRequestBuilder
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.load.engine.DiskCacheStrategy
;
import
com.bumptech.glide.load.engine.DiskCacheStrategy
;
import
com.bumptech.glide.load.model.StreamEncoder
;
import
com.bumptech.glide.load.model.StreamEncoder
;
...
@@ -23,8 +25,9 @@ import java.io.InputStream;
...
@@ -23,8 +25,9 @@ import java.io.InputStream;
public
class
MainActivity
extends
Activity
{
public
class
MainActivity
extends
Activity
{
private
static
final
String
TAG
=
"SVGActivity"
;
private
static
final
String
TAG
=
"SVGActivity"
;
ImageView
imageViewRes
;
private
ImageView
imageViewRes
;
ImageView
imageViewNet
;
private
ImageView
imageViewNet
;
private
GenericRequestBuilder
<
Uri
,
InputStream
,
SVG
,
PictureDrawable
>
requestBuilder
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -33,6 +36,19 @@ public class MainActivity extends Activity {
...
@@ -33,6 +36,19 @@ public class MainActivity extends Activity {
imageViewRes
=
(
ImageView
)
findViewById
(
R
.
id
.
svg_image_view1
);
imageViewRes
=
(
ImageView
)
findViewById
(
R
.
id
.
svg_image_view1
);
imageViewNet
=
(
ImageView
)
findViewById
(
R
.
id
.
svg_image_view2
);
imageViewNet
=
(
ImageView
)
findViewById
(
R
.
id
.
svg_image_view2
);
requestBuilder
=
Glide
.
with
(
this
)
.
using
(
Glide
.
buildStreamModelLoader
(
Uri
.
class
,
this
),
InputStream
.
class
)
.
from
(
Uri
.
class
)
.
as
(
SVG
.
class
)
.
transcode
(
new
SvgDrawableTranscoder
(),
PictureDrawable
.
class
)
.
sourceEncoder
(
new
StreamEncoder
())
.
cacheDecoder
(
new
FileToStreamDecoder
<
SVG
>(
new
SvgDecoder
()))
.
decoder
(
new
SvgDecoder
())
.
placeholder
(
R
.
drawable
.
image_loading
)
.
error
(
R
.
drawable
.
image_error
)
.
animate
(
android
.
R
.
anim
.
fade_in
)
.
listener
(
new
SvgSoftwareLayerSetter
<
Uri
>());
}
}
@Override
@Override
...
@@ -77,38 +93,22 @@ public class MainActivity extends Activity {
...
@@ -77,38 +93,22 @@ public class MainActivity extends Activity {
}
}
private
void
loadRes
()
{
private
void
loadRes
()
{
Glide
.
with
(
this
)
Uri
uri
=
Uri
.
parse
(
ContentResolver
.
SCHEME_ANDROID_RESOURCE
+
"://"
+
getPackageName
()
+
"/"
.
using
(
Glide
.
buildStreamModelLoader
(
Integer
.
class
,
this
),
InputStream
.
class
)
+
R
.
raw
.
android_toy_h
);
.
load
(
R
.
raw
.
android_toy_h
)
requestBuilder
.
as
(
SVG
.
class
)
.
transcode
(
new
SvgDrawableTranscoder
(),
PictureDrawable
.
class
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
NONE
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
NONE
)
// SVG cannot be serialized so it's not worth to cache it
// SVG cannot be serialized so it's not worth to cache it
// and the getResources() should be fast enough when acquiring the InputStream
// and the getResources() should be fast enough when acquiring the InputStream
.
decoder
(
new
SvgDecoder
())
.
load
(
uri
)
.
placeholder
(
R
.
drawable
.
image_loading
)
.
error
(
R
.
drawable
.
image_error
)
.
animate
(
android
.
R
.
anim
.
fade_in
)
.
listener
(
new
SvgSoftwareLayerSetter
<
Integer
>())
.
into
(
imageViewRes
);
.
into
(
imageViewRes
);
}
}
private
void
loadNet
()
{
private
void
loadNet
()
{
Glide
.
with
(
this
)
Uri
uri
=
Uri
.
parse
(
"http://www.clker.com/cliparts/u/Z/2/b/a/6/android-toy-h.svg"
);
.
using
(
Glide
.
buildStreamModelLoader
(
String
.
class
,
this
),
InputStream
.
class
)
requestBuilder
.
load
(
"http://www.clker.com/cliparts/u/Z/2/b/a/6/android-toy-h.svg"
)
.
as
(
SVG
.
class
)
.
transcode
(
new
SvgDrawableTranscoder
(),
PictureDrawable
.
class
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
.
diskCacheStrategy
(
DiskCacheStrategy
.
SOURCE
)
// SVG cannot be serialized so it's not worth to cache it
// SVG cannot be serialized so it's not worth to cache it
.
sourceEncoder
(
new
StreamEncoder
())
.
load
(
uri
)
// however loading from the network can be cached via StreamEncoder
.
cacheDecoder
(
new
FileToStreamDecoder
<
SVG
>(
new
SvgDecoder
()))
.
decoder
(
new
SvgDecoder
())
.
placeholder
(
R
.
drawable
.
image_loading
)
.
error
(
R
.
drawable
.
image_error
)
.
animate
(
android
.
R
.
anim
.
fade_in
)
.
listener
(
new
SvgSoftwareLayerSetter
<
String
>())
.
into
(
imageViewNet
);
.
into
(
imageViewNet
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录