Skip to content

Commit

Permalink
反复考虑后决定用glide加载图片
Browse files Browse the repository at this point in the history
  • Loading branch information
luhuan committed Apr 24, 2017
1 parent 1990334 commit 6992327
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions app/src/main/java/com/luhuan/provider/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
Expand All @@ -16,7 +15,7 @@
import com.luhuan.rxprovider.Permission;
import com.luhuan.rxprovider.Resolution;
import com.luhuan.rxprovider.RxListener;
import com.luhuan.rxprovider.RxPicasso;
import com.luhuan.rxprovider.RxGlide;
import com.luhuan.rxprovider.RxToast;
import com.luhuan.rxprovider.Screen;
import com.luhuan.rxprovider.customview.banner.Banner;
Expand Down Expand Up @@ -112,7 +111,7 @@ public void accept(@NonNull Boolean aBoolean) throws Exception {
}
}
});
RxPicasso.init(this,R.mipmap.ic_launcher);
RxGlide.init(this,R.mipmap.ic_launcher);
banner= (Banner) findViewById(R.id.banner);
List<String> list=new ArrayList<>();
for (int i = 0; i < 3; i++) {
Expand Down
2 changes: 1 addition & 1 deletion rxprovider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ dependencies {
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.3@aar'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;

import static com.bumptech.glide.Glide.with;

/**
* Created by Administrator on 2017/4/6 0006.
* 封装Picasso
*/

public class RxPicasso {
public class RxGlide {
@SuppressLint("StaticFieldLeak")
private static Context mContext;
private static Integer mdrawableId;
Expand All @@ -23,27 +25,27 @@ public static void init(Context context, @DrawableRes Integer errorId){
mdrawableId=errorId;
}

public static RequestCreator load(@NonNull String url, @DrawableRes Integer errorId){
public static DrawableRequestBuilder<String> load(@NonNull String url, @DrawableRes Integer errorId){
if (mContext == null) {
throw new NullPointerException("picasso的上下文为空");
}else {
return Picasso.with(mContext).load(url).placeholder(errorId).error(errorId);
return with(mContext).load(url).placeholder(errorId).error(errorId);
}
}

public static RequestCreator load(@NonNull String url){
public static DrawableRequestBuilder<String> load(@NonNull String url){
if (mContext == null) {
throw new NullPointerException("picasso的上下文为空");
}else {
return Picasso.with(mContext).load(url).placeholder(mdrawableId).error(mdrawableId);
return with(mContext).load(url).placeholder(mdrawableId).error(mdrawableId);
}
}

public static RequestCreator load(@DrawableRes Integer drawableId){
public static DrawableRequestBuilder<Integer> load(@DrawableRes Integer drawableId){
if (mContext == null) {
throw new NullPointerException("picasso的上下文为空");
}else {
return Picasso.with(mContext).load(drawableId).placeholder(mdrawableId).error(mdrawableId);
return Glide.with(mContext).load(drawableId).placeholder(mdrawableId).error(mdrawableId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.content.Context;
import android.widget.ImageView;

import com.luhuan.rxprovider.RxPicasso;
import com.luhuan.rxprovider.RxGlide;

/**
* Created by Administrator on 2017/3/10 0010.
Expand All @@ -21,10 +21,10 @@ public void displayImage(Context context, Object path, ImageView imageView) {
*/
if (path instanceof Integer) {
//Picasso 加载图片简单用法
RxPicasso.load((Integer) path).into(imageView);
RxGlide.load((Integer) path).into(imageView);
}else if (path instanceof String){
//Picasso 加载图片简单用法
RxPicasso.load((String) path).into(imageView);
RxGlide.load((String) path).into(imageView);
}

}
Expand Down

0 comments on commit 6992327

Please sign in to comment.