毕加索和glide加载https图片的问题处理
This commit is contained in:
parent
487f7c4ee1
commit
816ad0831d
|
|
@ -26,5 +26,5 @@ android.enableJetifier=true
|
|||
android.useAndroidX=true
|
||||
android.useDeprecatedNdk=true
|
||||
|
||||
versionCode=42
|
||||
versionName=4.11.2
|
||||
versionCode=43
|
||||
versionName=4.11.3
|
||||
|
|
@ -83,6 +83,7 @@ dependencies {
|
|||
|
||||
implementation 'de.greenrobot:eventbus:2.4.0'
|
||||
implementation 'com.squareup.picasso:picasso:2.5.2'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
|
||||
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
|
||||
implementation 'com.google.zxing:core:3.3.0'
|
||||
//云信聊天
|
||||
|
|
@ -97,7 +98,10 @@ dependencies {
|
|||
implementation 'jp.wasabeef:picasso-transformations:2.1.0'
|
||||
//Picasso 显示圆形图片
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'com.github.bumptech.glide:glide:3.7.0'
|
||||
// implementation 'com.github.bumptech.glide:glide:3.7.0'
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
||||
|
||||
//Glide
|
||||
implementation 'cn.bingoogolapple:bga-refreshlayout:1.1.7@aar'
|
||||
//下拉刷新
|
||||
|
|
@ -158,5 +162,8 @@ dependencies {
|
|||
|
||||
implementation 'com.tencent:mmkv:1.3.3'
|
||||
|
||||
implementation("com.github.bumptech.glide:okhttp3-integration:4.11.0" )
|
||||
//
|
||||
// annotationProcessor 'com.github.bumptech.glide:compiler:3.7.0'
|
||||
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ import com.ifish.utils.Commons;
|
|||
import com.ifish.utils.Commons.LoginSPKey;
|
||||
import com.ifish.utils.Commons.NetWork;
|
||||
import com.ifish.utils.Commons.Text;
|
||||
import com.ifish.utils.GlideApp;
|
||||
import com.ifish.utils.HttpListener;
|
||||
import com.ifish.utils.HttpManager;
|
||||
import com.ifish.utils.L;
|
||||
|
|
@ -59,7 +60,7 @@ public class HotSpotConnentDeviceActivity extends BaseActivity {
|
|||
connectDevice = new ConnectDevice(20000, 1000);
|
||||
initTitle("尝试与设备建立连接");
|
||||
ImageView iv_wifiset = findMyViewById(R.id.iv_wifiset);
|
||||
Glide.with(this).load(R.drawable.hotconnectgif).asGif().into(iv_wifiset);
|
||||
GlideApp.with(this).load(R.drawable.hotconnectgif).into(iv_wifiset);
|
||||
sp = SPUtil.getInstance(HotSpotConnentDeviceActivity.this);
|
||||
// device_mac="5ccf7f99e929";
|
||||
// doPostBindDevice();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.ifish.utils.Commons;
|
|||
import com.ifish.utils.Commons.LoginSPKey;
|
||||
import com.ifish.utils.Commons.NetWork;
|
||||
import com.ifish.utils.Commons.Text;
|
||||
import com.ifish.utils.GlideApp;
|
||||
import com.ifish.utils.HttpListener;
|
||||
import com.ifish.utils.HttpManager;
|
||||
import com.ifish.utils.SPUtil;
|
||||
|
|
@ -61,7 +62,7 @@ public class HotSpotConnentDeviceCameraActivity extends BaseActivity {
|
|||
connectDevice = new ConnectDevice(20000, 1000);
|
||||
initTitle("尝试与设备建立连接");
|
||||
ImageView iv_wifiset = findMyViewById(R.id.iv_wifiset);
|
||||
Glide.with(this).load(R.drawable.hotconnectgif).asGif().into(iv_wifiset);
|
||||
GlideApp.with(this).load(R.drawable.hotconnectgif).into(iv_wifiset);
|
||||
sp = SPUtil.getInstance(HotSpotConnentDeviceCameraActivity.this);
|
||||
// device_mac="5ccf7f99e929";
|
||||
// doPostBindDevice();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import com.ifish.utils.Commons;
|
|||
import com.ifish.utils.Commons.LoginSPKey;
|
||||
import com.ifish.utils.Commons.NetWork;
|
||||
import com.ifish.utils.Commons.Text;
|
||||
import com.ifish.utils.GlideApp;
|
||||
import com.ifish.utils.HttpListener;
|
||||
import com.ifish.utils.HttpManager;
|
||||
import com.ifish.utils.L;
|
||||
|
|
@ -61,7 +62,7 @@ public class HotSpotConnentPetDeviceActivity extends BaseActivity {
|
|||
connectDevice = new ConnectDevice(20000, 1000);
|
||||
initTitle("尝试与设备建立连接");
|
||||
ImageView iv_wifiset = findMyViewById(R.id.iv_wifiset);
|
||||
Glide.with(this).load(R.drawable.hotconnectgif).asGif().into(iv_wifiset);
|
||||
GlideApp.with(this).load(R.drawable.hotconnectgif).into(iv_wifiset);
|
||||
sp = SPUtil.getInstance(HotSpotConnentPetDeviceActivity.this);
|
||||
// device_mac="5ccf7f99e929";
|
||||
// doPostBindDevice();
|
||||
|
|
|
|||
|
|
@ -329,12 +329,9 @@ public class MainSixControlActivity extends BaseGradeActivity implements SwipeRe
|
|||
private void ReviewBrand() {
|
||||
try {//展示厂家
|
||||
if (Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList()!=null) {//厂家为空则展示默认的鱼影
|
||||
|
||||
String imageName = HttpManager.Store_URL+Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0))
|
||||
.getVenderList().getLogo();
|
||||
|
||||
Picasso.with(MainSixControlActivity.this)
|
||||
.load(imageName.replace("https","http")).error(R.drawable.ifish_logo_default)
|
||||
.load(HttpManager.Store_URL+Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0))
|
||||
.getVenderList().getLogo()).error(R.drawable.ifish_logo_default)
|
||||
.placeholder(getDrawable(R.drawable.ifish_logo_default))
|
||||
.into(iv_left);
|
||||
String brandName = Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList().getBrandName();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
package com.ifish.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.ifish.baseclass.BaseActivity;
|
||||
|
|
@ -36,128 +40,129 @@ public class ShowDeviceImageActivity extends BaseActivity {
|
|||
if(device_type != 0){
|
||||
switch (device_type){
|
||||
case R.id.iv_no_connect:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.no_connect_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.no_connect_image).listener(new RequestListener< Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_camera:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.camera_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.camera_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_move_camera:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.move_camera_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.move_camera_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_sw7:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.sw7_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.sw7_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_sw10:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.sw10_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.sw10_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_cw2:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.cw2_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.cw2_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_sw1sw6:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.sw1_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.sw1_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
}).into(iv_show);
|
||||
break;
|
||||
case R.id.iv_wy01:
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.wy01_image).listener(new RequestListener<Integer, GlideDrawable>() {
|
||||
Glide.with(ShowDeviceImageActivity.this).load(R.drawable.wy01_image).listener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onException(Exception e, Integer model, Target<GlideDrawable> target, boolean isFirstResource) {
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
ToastUtil.show(getApplicationContext(),"加载失败,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(GlideDrawable resource, Integer model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
|
||||
public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
|
||||
progressDialog.setVisibility(View.GONE);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.ifish.activity.EditVideoActivity;
|
||||
import com.ifish.activity.R;
|
||||
import com.ifish.basebean.IfishVideo;
|
||||
|
|
@ -69,7 +70,11 @@ public class VideoListAdapter extends BaseAdapter {
|
|||
}
|
||||
final IfishVideo bean = list.get(position);
|
||||
if (bean!=null) {
|
||||
Glide.with(context).load(HttpManager.VIDEO_IMG_URL+bean.userId+"/"+ bean.commodityImg).placeholder(R.drawable.error_lookfishlist).error(R.drawable.error_lookfishlist).into(holder.iv_commodityImg);
|
||||
|
||||
Glide.with(context).load(HttpManager.VIDEO_IMG_URL+bean.userId+"/"+ bean.commodityImg)
|
||||
.apply( new RequestOptions().placeholder(R.drawable.error_lookfishlist)
|
||||
.error(R.drawable.error_lookfishlist))
|
||||
.into(holder.iv_commodityImg);
|
||||
holder.tv_commodityName.setText(bean.commodityName);
|
||||
holder.tv_click.setText("浏览次数:"+bean.click+"次");
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -52,4 +52,5 @@ public class LiveRoomInfo implements Serializable {
|
|||
public LiveRoomInfo(String roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,15 +30,29 @@ import com.alibaba.sdk.android.push.huawei.HuaWeiRegister;
|
|||
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
|
||||
import com.alibaba.sdk.android.push.register.MiPushRegister;
|
||||
import com.ifish.activity.BuildConfig;
|
||||
import com.ifish.utils.ImageDownLoader;
|
||||
import com.ifish.utils.KVUtil;
|
||||
import com.ifish.utils.SystemUtil;
|
||||
import com.ifish.utils.TrustAllCerts;
|
||||
import com.p2p.core.P2PSpecial.P2PSpecial;
|
||||
//import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.tendcloud.tenddata.TCAgent;
|
||||
import com.umeng.commonsdk.UMConfigure;
|
||||
import com.umeng.socialize.PlatformConfig;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/**
|
||||
* @author Jacky dada
|
||||
* @ClassName: BaseApplication
|
||||
|
|
@ -79,6 +93,7 @@ public class BaseApplication extends MultiDexApplication {
|
|||
initLog();
|
||||
//初始化MMKV
|
||||
// KVUtil.init(this);
|
||||
initPicasso();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,4 +255,65 @@ public class BaseApplication extends MultiDexApplication {
|
|||
String processName = SystemUtil.getProcessName(this);
|
||||
return packageName.equals(processName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化picasso使用okhttp作为网络请求框架
|
||||
*/
|
||||
private void initPicasso() {
|
||||
|
||||
Picasso
|
||||
.setSingletonInstance(new Picasso.Builder(this).
|
||||
downloader(new ImageDownLoader(getSOkHttpClient())).loggingEnabled(true)
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建全局OkHttpClient对象
|
||||
* <p>
|
||||
* OkHttpClient 用于管理所有的请求,内部支持并发,
|
||||
* 所以我们不必每次请求都创建一个 OkHttpClient 对象,这是非常耗费资源的。接下来就是创建一个 Request 对象了
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static OkHttpClient getSOkHttpClient() {
|
||||
//创建okhttp的请求对象 参考地址 http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0106/2275.html
|
||||
|
||||
// if (sOkHttpClient == null) {
|
||||
// sOkHttpClient =
|
||||
return new OkHttpClient.Builder()
|
||||
.readTimeout(20000, TimeUnit.SECONDS)//设置读取超时时间
|
||||
.writeTimeout(20000, TimeUnit.SECONDS)//设置写的超时时间
|
||||
.connectTimeout(20000, TimeUnit.SECONDS)//设置连接超时时间
|
||||
.sslSocketFactory(createSSLSocketFactory()) //添加信任所有证书
|
||||
.hostnameVerifier(new HostnameVerifier() { //信任规则全部信任
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
// }
|
||||
// return sOkHttpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试环境https添加全部信任
|
||||
* okhttp的配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static SSLSocketFactory createSSLSocketFactory() {
|
||||
SSLSocketFactory ssfFactory = null;
|
||||
|
||||
try {
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, new TrustManager[]{new TrustAllCerts()}, new SecureRandom());
|
||||
|
||||
ssfFactory = sc.getSocketFactory();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return ssfFactory;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,6 +188,8 @@ public class LookFishLeftFragment extends BaseV4Fragment implements BGARefreshLa
|
|||
*/
|
||||
position=position-2;//自定义GridView 添加头部后position改变
|
||||
Intent i =new Intent(getActivity(),LookFishMonitorActivity.class);
|
||||
|
||||
L.i(this.getClass().getName() + "----------------onCreate"+liveRoomList.get(position).toString());
|
||||
i.putExtra("LiveRoomInfo",liveRoomList.get(position));
|
||||
startActivity(i);
|
||||
AnimationUtil.startAnimation(getActivity());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package com.ifish.utils;
|
||||
|
||||
import android.net.Uri;
|
||||
import com.squareup.picasso.Downloader;
|
||||
import com.squareup.picasso.NetworkPolicy;
|
||||
import java.io.IOException;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.CacheControl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.Request;
|
||||
|
||||
|
||||
public class ImageDownLoader implements Downloader {
|
||||
/* OkHttpClient client = new OkHttpClient.Builder()
|
||||
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
|
||||
.build();*/
|
||||
private OkHttpClient client= null;
|
||||
|
||||
public ImageDownLoader(OkHttpClient okHttpClient) {
|
||||
this.client = okHttpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response load(Uri uri, int networkPolicy) throws IOException {
|
||||
CacheControl cacheControl = null;
|
||||
if (networkPolicy != 0) {
|
||||
if (NetworkPolicy.isOfflineOnly(networkPolicy)) {
|
||||
cacheControl = CacheControl.FORCE_CACHE;
|
||||
} else {
|
||||
CacheControl.Builder builder = new CacheControl.Builder();
|
||||
if (!NetworkPolicy.shouldReadFromDiskCache(networkPolicy)) {
|
||||
builder.noCache();
|
||||
}
|
||||
if (!NetworkPolicy.shouldWriteToDiskCache(networkPolicy)) {
|
||||
builder.noStore();
|
||||
}
|
||||
cacheControl = builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(uri.toString());
|
||||
if (cacheControl != null) {
|
||||
builder.cacheControl(cacheControl);
|
||||
}
|
||||
|
||||
okhttp3.Response response = client.newCall(builder.build()).execute();
|
||||
int responseCode = response.code();
|
||||
if (responseCode >= 300) {
|
||||
response.body().close();
|
||||
throw new ResponseException(responseCode + " " + response.message(), networkPolicy,
|
||||
responseCode);
|
||||
}
|
||||
|
||||
boolean fromCache = response.cacheResponse() != null;
|
||||
|
||||
ResponseBody responseBody = response.body();
|
||||
return new Response(responseBody.byteStream(), fromCache, responseBody.contentLength());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
Cache cache = client.cache();
|
||||
if (cache != null) {
|
||||
try {
|
||||
cache.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.ifish.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.GlideBuilder;
|
||||
import com.bumptech.glide.Registry;
|
||||
import com.bumptech.glide.annotation.GlideModule;
|
||||
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.bumptech.glide.module.AppGlideModule;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@GlideModule
|
||||
public class OkHttpAppGlideModule extends AppGlideModule {
|
||||
|
||||
@Override
|
||||
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
|
||||
super.applyOptions(context, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
|
||||
super.registerComponents(context, glide, registry);
|
||||
//设置请求方式为okhttp 并设置okhttpClient的证书及超时时间
|
||||
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(UnsafeOkHttpClient.getUnsafeOkHttpClient());
|
||||
registry.replace(GlideUrl.class, InputStream.class,factory);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish.utils;
|
||||
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
|
||||
|
||||
|
||||
public class TrustAllCerts implements X509TrustManager {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {return new X509Certificate[0];}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.ifish.utils;
|
||||
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class UnsafeOkHttpClient {
|
||||
public static OkHttpClient getUnsafeOkHttpClient() {
|
||||
try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
final TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return new java.security.cert.X509Certificate[]{};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Install the all-trusting trust manager
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
|
||||
// Create an ssl socket factory with our all-trusting manager
|
||||
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
|
||||
builder.hostnameVerifier(new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
builder.connectTimeout(20, TimeUnit.SECONDS);
|
||||
builder.readTimeout(20,TimeUnit.SECONDS);
|
||||
|
||||
OkHttpClient okHttpClient = builder.build();
|
||||
return okHttpClient;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue