Skip to content

Commit 83fff0b

Browse files
committed
Allow specifying a Picasso instance to use
Add methods to allow configuring the Picasso instance used by the slider when it loads images.
1 parent 323a43f commit 83fff0b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

library/src/main/java/com/daimajia/slider/library/SliderTypes/BaseSliderView.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public abstract class BaseSliderView {
4747

4848
private String mDescription;
4949

50+
private Picasso mPicasso;
51+
5052
/**
5153
* Scale type of the image.
5254
*/
@@ -205,7 +207,7 @@ public void onClick(View v) {
205207
mLoadListener.onStart(me);
206208
}
207209

208-
Picasso p = Picasso.with(mContext);
210+
Picasso p = (mPicasso != null) ? mPicasso : Picasso.with(mContext);
209211
RequestCreator rq = null;
210212
if(mUrl!=null){
211213
rq = p.load(mUrl);
@@ -304,4 +306,23 @@ public interface ImageLoadListener{
304306
public void onEnd(boolean result,BaseSliderView target);
305307
}
306308

309+
/**
310+
* Get the last instance set via setPicasso(), or null if no user provided instance was set
311+
*
312+
* @return The current user-provided Picasso instance, or null if none
313+
*/
314+
public Picasso getPicasso() {
315+
return mPicasso;
316+
}
317+
318+
/**
319+
* Provide a Picasso instance to use when loading pictures, this is useful if you have a
320+
* particular HTTP cache you would like to share.
321+
*
322+
* @param picasso The Picasso instance to use, may be null to let the system use the default
323+
* instance
324+
*/
325+
public void setPicasso(Picasso picasso) {
326+
mPicasso = picasso;
327+
}
307328
}

0 commit comments

Comments
 (0)