Skip to content

Commit a3f0e7d

Browse files
committed
Use Glide instead of Picasso
1 parent 0b686d9 commit a3f0e7d

3 files changed

Lines changed: 19 additions & 36 deletions

File tree

demo/src/main/java/com/daimajia/slider/demo/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
5252
textSliderView
5353
.description(name)
5454
.image(file_maps.get(name))
55-
.setScaleType(BaseSliderView.ScaleType.Fit)
55+
.setScaleType(BaseSliderView.ScaleType.FitCenter)
5656
.setOnSliderClickListener(this);
5757

5858
//add your extra information

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies {
4848
compile fileTree(dir: 'libs', include: ['*.jar'])
4949
compile 'com.android.support:appcompat-v7:22.1.1'
5050
compile "com.android.support:support-v4:22.1.1"
51-
compile 'com.squareup.picasso:picasso:2.5.2'
51+
compile 'com.github.bumptech.glide:glide:3.7.0'
5252
compile 'com.nineoldandroids:library:2.4.0'
5353
}
5454
apply from: './gradle-mvn-push.gradle'

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

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import android.view.View;
66
import android.widget.ImageView;
77

8+
import com.bumptech.glide.DrawableTypeRequest;
9+
import com.bumptech.glide.Glide;
10+
import com.bumptech.glide.RequestManager;
811
import com.daimajia.slider.library.R;
9-
import com.squareup.picasso.Callback;
10-
import com.squareup.picasso.Picasso;
11-
import com.squareup.picasso.RequestCreator;
1212

1313
import java.io.File;
1414

@@ -50,10 +50,10 @@ public abstract class BaseSliderView {
5050
/**
5151
* Scale type of the image.
5252
*/
53-
private ScaleType mScaleType = ScaleType.Fit;
53+
private ScaleType mScaleType = ScaleType.FitCenter;
5454

5555
public enum ScaleType{
56-
CenterCrop, CenterInside, Fit, FitCenterCrop
56+
CenterCrop, FitCenter
5757
}
5858

5959
protected BaseSliderView(Context context) {
@@ -205,14 +205,14 @@ public void onClick(View v) {
205205
mLoadListener.onStart(me);
206206
}
207207

208-
Picasso p = Picasso.with(mContext);
209-
RequestCreator rq = null;
208+
RequestManager g = Glide.with(mContext);
209+
DrawableTypeRequest rq;
210210
if(mUrl!=null){
211-
rq = p.load(mUrl);
211+
rq = g.load(mUrl);
212212
}else if(mFile != null){
213-
rq = p.load(mFile);
213+
rq = g.load(mFile);
214214
}else if(mRes != 0){
215-
rq = p.load(mRes);
215+
rq = g.load(mRes);
216216
}else{
217217
return;
218218
}
@@ -230,35 +230,18 @@ public void onClick(View v) {
230230
}
231231

232232
switch (mScaleType){
233-
case Fit:
234-
rq.fit();
233+
case FitCenter:
234+
rq.fitCenter();
235235
break;
236236
case CenterCrop:
237-
rq.fit().centerCrop();
238-
break;
239-
case CenterInside:
240-
rq.fit().centerInside();
237+
rq.centerCrop();
241238
break;
242239
}
243240

244-
rq.into(targetImageView,new Callback() {
245-
@Override
246-
public void onSuccess() {
247-
if(v.findViewById(R.id.loading_bar) != null){
248-
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
249-
}
250-
}
251-
252-
@Override
253-
public void onError() {
254-
if(mLoadListener != null){
255-
mLoadListener.onEnd(false,me);
256-
}
257-
if(v.findViewById(R.id.loading_bar) != null){
258-
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
259-
}
260-
}
261-
});
241+
rq.into(targetImageView);
242+
if(v.findViewById(R.id.loading_bar) != null){
243+
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
244+
}
262245
}
263246

264247

0 commit comments

Comments
 (0)