SimpleCommand框架ImageLoader API詳解(三)
ImageLoader API 詳細(xì)介紹,具體內(nèi)容如下
在ImageLoader中有以下幾個(gè)不同的構(gòu)造器:
/**
* 注意: 次構(gòu)造器不支持下載進(jìn)度提示功能
* @param context
* @param withCache 是否支持緩存
* false--不帶緩存
* true--支持緩存功能,默認(rèn)緩存路徑在外置存儲(chǔ)緩沖目錄中的picasso-big-cache文件夾中
*/
public ImageLoader(Context context, boolean withCache) {
this(context, null, withCache);
}
/**
* 支持下載進(jìn)度提示,以及設(shè)置緩存路徑
* @param context
* @param listener 下載進(jìn)度監(jiān)聽器
* @param cachePath 緩存路徑字符串
*/
public ImageLoader(Context context, ProgressListener listener, String cachePath) {
// TODO extend to support multiple libraries as Glide
// TODO must be initialized and kept as an member instance to avoid losing cache
Picasso.Builder builder = setupLoaderClientWithCachePath(context, listener, cachePath);
setupListener(builder);
picasso = builder.build();
picasso.setIndicatorsEnabled(BuildConfig.DEBUG);
picasso.setLoggingEnabled(BuildConfig.DEBUG);
}
/**
* 支持下載進(jìn)度提示,以及設(shè)置緩存路徑為默認(rèn)路徑picasso-big-cache
* @param context
* @param listener 下載進(jìn)度監(jiān)聽器
* @param withCache 是否支持緩存
*/
public ImageLoader(Context context, ProgressListener listener, boolean withCache) {
// TODO extend to support multiple libraries as Glide
// TODO must be initialized and kept as an member instance to avoid losing cache
Picasso.Builder builder = setupLoaderClient(context, listener, withCache);
setupListener(builder);
picasso = builder.build();
picasso.setIndicatorsEnabled(BuildConfig.DEBUG);
picasso.setLoggingEnabled(BuildConfig.DEBUG);
}
public void shutdown() {
if (picasso == null) return;
Logger.d(Logger.TAG, "Image loader has been shutdown");
picasso.shutdown();
callback = null;
}
將ImageLoader停止,一般在Activity停止,或者任務(wù)結(jié)束時(shí)調(diào)用此方法將其關(guān)閉
public ImageLoader cancelRequest(ImageView imageView) {
picasso.cancelRequest(imageView);
return this;
}
取消之前顯示到ImageView上的請(qǐng)求
public ImageLoader load(final int resourceId) {
cleanResources();
this.imageResourceId = resourceId;
return this;
}
public ImageLoader load(final String imageUri) {
cleanResources();
this.imageUri = imageUri;
return this;
}
分別加載本地drawable文件夾下的圖片,以及網(wǎng)絡(luò)圖片
public ImageLoader withPlaceholder(final int placeholder) {
this.placeholder = placeholder;
return this;
}
設(shè)置ImageLoader下載圖片時(shí)的預(yù)覽圖
public ImageLoader withErrorImage(final int errorImage) {
this.errorImage = errorImage;
return this;
}
下載圖片失敗時(shí)顯示的圖片
public ImageLoader withTag(final String tag) {
this.tag = tag;
return this;
}
public void pause(final String tag) {
if (picasso == null) return;
picasso.pauseTag(tag);
}
public void resume(final String tag) {
if (picasso == null) return;
picasso.resumeTag(tag);
}
以上三個(gè)方法依次是
1 下載圖片時(shí)添加標(biāo)簽tag
2 暫停tag標(biāo)簽的下載任務(wù)
3 resume tag標(biāo)簽的下載任務(wù)
public ImageLoader withCallback(final Callback callback) {
this.callback = callback;
return this;
}
給ImageLoader設(shè)置下載完成的回調(diào),包含onSuccess和onFailed方法
public ImageLoader fit() {
this.fit = true;
return this;
}
public ImageLoader centerCrop() {
this.centerCrop = true;
return this;
}
public ImageLoader centerInside() {
this.centerInside = true;
return this;
}
public ImageLoader resize(final int widthResId, final int heightResId) {
this.widthResId = widthResId;
this.heigthResId = heightResId;
return this;
}
分別設(shè)置Picasso下載圖片時(shí)的相應(yīng)屬性, 可以參考ImageView的scaleType屬性
public void into(final ImageView imageView) {
run(imageView);
}
into方法調(diào)用內(nèi)部run方法,并啟動(dòng)下載任務(wù)。 此方法需要在以上所有的API之后調(diào)用。
框架github地址: SimpleCommand框架
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android自定義StepView仿外賣配送進(jìn)度
這篇文章主要為大家詳細(xì)介紹了Android自定義StepView仿外賣配送進(jìn)度,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android Handler的postDelayed()關(guān)閉的方法及遇到問題
這篇文章主要介紹了Android Handler的postDelayed()關(guān)閉的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
Android計(jì)時(shí)器chronometer使用實(shí)例講解
這篇文章主要為大家詳細(xì)介紹了Android計(jì)時(shí)器chronometer使用實(shí)例,介紹了Android計(jì)時(shí)器chronometer基本使用方法,感興趣的小伙伴們可以參考一下2016-04-04
Android實(shí)現(xiàn)圖片預(yù)覽與保存功能
在App開發(fā)中,通常為了省流提高加載速度提升用戶體驗(yàn)我們通常在列表中或新聞中的插圖都是以縮略圖壓縮過的圖片來進(jìn)行展示,當(dāng)用戶點(diǎn)擊圖片時(shí)我們?cè)偃ゼ虞d真正像素的大圖讓用戶預(yù)覽。本文將利用Flutter實(shí)現(xiàn)這一功能,需要的可以參考一下2022-04-04
Android 利用三階貝塞爾曲線繪制運(yùn)動(dòng)軌跡的示例
本篇文章主要介紹了Android 利用三階貝塞爾曲線繪制運(yùn)動(dòng)軌跡的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03
Android自定義View設(shè)定到FrameLayout布局中實(shí)現(xiàn)多組件顯示的方法 分享
Android自定義View設(shè)定到FrameLayout布局中實(shí)現(xiàn)多組件顯示的方法 分享,需要的朋友可以參考一下2013-05-05

