//Fresco
//1.导依赖
//官网https://www.fresco-cn.org/docs/index.html
implementation 'com.facebook.fresco:fresco:0.12.0''
//2.布局
//**3.新建App类,继承Application **
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
//Fresco的初始化
//磁盘缓存的配置
DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(this)
.setBaseDirectoryPath(getCacheDir())
.setMaxCacheSize(8*1024*1024)
.build();
//把磁盘缓存的设置,设置到三级缓存中
ImagePipelineConfig pipelineConfig = ImagePipelineConfig.newBuilder(this)
.setMainDiskCacheConfig(diskCacheConfig)
.build();
Fresco.initialize(this,pipelineConfig);//pipelineConfig可不写
}
}
//5.Activity中用法
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);
//全的sdvIcon和sdvGifIcon为控件
//加载Fresco图片
Uri imageUri = Uri.parse("https://ws1.sinaimg.cn/large/0065oQSqgy1fze94uew3jj30qo10cdka.jpg");
//圆角效果
RoundingParams roundingParams = RoundingParams.fromCornersRadius(20f);
sdvIcon.getHierarchy().setRoundingParams(roundingParams);
//加载显示时的进度条
sdvIcon.getHierarchy().setProgressBarImage(new ProgressBarDrawable());
sdvIcon.setImageURI(imageUri);
//加载Fresco动图
Uri gifUri = Uri.parse("https://ww1.sinaimg.cn/large/0073sXn7ly1fze96rdfhmg308w0ft7wh");
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(gifUri)
.setAutoPlayAnimations(true)
.build();
sdvGifIcon.setController(controller);
//EventBus
//1.依赖
implementation 'org.greenrobot:eventbus:3.1.1'
//2.建一个bean类,放入你要传的数据类型
//3.Activity中的使用,我这个是点击条目,吐司下标
//CrimeBean 为自己创建的bean类
CrimeBean crimeBean = new CrimeBean();
//将下标存入bean类中
crimeBean.setNumber(position);
EventBus eventBus = EventBus.getDefault();
eventBus.postSticky(crimeBean);
//跳转到下一个页面吐司去!
Intent intent=new Intent(ShowActivity.this,LoginActivity.class);
startActivity(intent);
//另一个界面
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
public void cathZpp(CrimeBean bean_two){
Toast.makeText(this, "下标是:" + bean_two.getNumber(), Toast.LENGTH_SHORT).show();
}