当前位置: 首页 > news >正文

技术支持 东莞网站建设东莞天助wordpress模特主题

技术支持 东莞网站建设东莞天助,wordpress模特主题,文创做的好的网站推荐,财务公司业务范围文章目录 Android 优雅封装Glide核心思想定义策略接口定义图片选项实现Glide策略图片管理类使用 Android 优雅封装Glide 核心思想 使用策略模式实现不同图片加载框架的切换#xff0c;使用建造者设计模式处理不同参数#xff0c;最后通过 ImageLoader 进行管理。 定义策略… 文章目录 Android 优雅封装Glide核心思想定义策略接口定义图片选项实现Glide策略图片管理类使用 Android 优雅封装Glide 核心思想 使用策略模式实现不同图片加载框架的切换使用建造者设计模式处理不同参数最后通过 ImageLoader 进行管理。 定义策略接口 interface ILoaderStrategy {fun loadImage(configs: ImageOptions)fun clearDiskCache(context: Context)fun clearMemoryCache(context: Context)fun clearAll(context: Context) {clearDiskCache(context)clearMemoryCache(context)}fun clear(imageView: ImageView) }定义图片选项 class ImageOptions private constructor() {var targetObj: Any? null // 生命周期对象var targetView: ImageView? null // 目标ImageViewvar resource: Any? null // 加载资源var width -1 // 指定宽度var height -1 // 指定高度var isDiskCache true // 磁盘缓存var isMemoryCache true // 内存缓存DrawableResvar placeholder: Int -1 // 占位图资源DrawableResvar error: Int -1 // 失败图资源var listener: Listener? nullcompanion object {fun create(): ImageOptions {return ImageOptions()}}fun with(targetObj: Any): ImageOptions {this.targetObj targetObjreturn this}fun loadResource(resource: Any): ImageOptions {this.resource resourcereturn this}fun size(size: Int): ImageOptions {return size(width, height)}fun size(width: Int, height: Int): ImageOptions {this.width widththis.height heightreturn this}fun placeholder(DrawableRes placeholder: Int): ImageOptions {this.placeholder placeholderreturn this}fun error(DrawableRes error: Int): ImageOptions {this.error errorreturn this}fun setDiskCache(isCache: Boolean): ImageOptions {isDiskCache isCachereturn this}fun setMemoryCache(isCache: Boolean): ImageOptions {isMemoryCache isCachereturn this}fun setListener(listener: Listener): ImageOptions {this.listener listenerreturn this}fun into(imageView: ImageView) {this.targetView imageViewImageLoader.loadOptions(this)}interface Listener {fun onSuccess(model: Any?)fun onFail(model: Any?)} }实现Glide策略 class GlideLoader : ILoaderStrategy {private lateinit var requestManager: RequestManageroverride fun loadImage(options: ImageOptions) {requestManager getRequestManager(options.targetObj)var requestBuilder: RequestBuilderDrawable? nulloptions.resource?.let {requestBuilder generateRequestBuilder(it)}requestBuilder?.let {if (options.placeholder ! -1) {it.placeholder(options.placeholder)}if (options.error ! -1) {it.error(options.error)}if (options.width ! -1 || options.height ! -1) {it.override(options.width, options.height)}it.skipMemoryCache(options.isMemoryCache)it.diskCacheStrategy(if (options.isDiskCache) DiskCacheStrategy.AUTOMATIC else DiskCacheStrategy.NONE)options.listener?.let { listener -it.addListener(object : RequestListenerDrawable {override fun onLoadFailed(e: GlideException?,model: Any?,target: TargetDrawable?,isFirstResource: Boolean): Boolean {listener.onFail(model)return false}override fun onResourceReady(resource: Drawable?,model: Any?,target: TargetDrawable?,dataSource: DataSource?,isFirstResource: Boolean): Boolean {listener.onSuccess(model)return false}})}if (options.targetView null) {throw IllegalArgumentException(targetView cannot be null);}it.into(options.targetView!!)}}private fun getRequestManager(targetObj: Any?): RequestManager {return if (targetObj is FragmentActivity) {Glide.with(targetObj)} else if (targetObj is Context) {Glide.with(targetObj)} else if (targetObj is View) {Glide.with(targetObj)} else if (targetObj is Fragment) {Glide.with(targetObj)} else {throw IllegalArgumentException(You cannot start a load on a null Context);}}private fun generateRequestBuilder(res: Any): RequestBuilderDrawable? {return if (res is String) {requestManager.load(res)} else if (res is File) {requestManager.load(res)} else {return null}}override fun clearDiskCache(context: Context) {thread {Glide.get(context).clearDiskCache()}}override fun clearMemoryCache(context: Context) {Glide.get(context).clearMemory()}override fun clear(imageView: ImageView) {Glide.with(imageView.context).clear(imageView)} }图片管理类 object ImageLoader {private var imageLoader: ILoaderStrategy? nullfun setImageLoader(imageLoader: ILoaderStrategy) {this.imageLoader imageLoader}fun with(targetObj: Any): ImageOptions {val options ImageOptions.create()options.with(targetObj)return options}fun loadOptions(options: ImageOptions) {imageLoader!!.loadImage(options)}fun clearDiskCache(context: Context){imageLoader!!.clearDiskCache(context)}fun clearMemoryCache(context: Context){imageLoader!!.clearMemoryCache(context)}fun clearAll(context:Context){imageLoader!!.clearAll(context)}fun clear(imageView: ImageView){imageLoader!!.clear(imageView)}}使用 override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_image_loader)imageView0 findViewById(R.id.imageView0)imageView1 findViewById(R.id.imageView1)imageView2 findViewById(R.id.imageView2)ImageLoader.setImageLoader(GlideLoader())val url https://i-blog.csdnimg.cn/blog_migrate/de6e3262387d57977e53af596a87f582.pngImageLoader.with(this).loadResource(url).size(100).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(imageView1)ImageLoader.with(this).loadResource(File(cacheDir, aaa.png)).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(imageView2) } ImageLoader.clear(imageView1) ImageLoader.clearAll(this) ImageLoader.clearMemoryCache(this) ImageLoader.clearDiskCache(this)
http://www.hkea.cn/news/14303169/

相关文章:

  • wordpress网站全过程天山网官网
  • 天河建设网站专家河南省新闻最新消息
  • 成都建设网站建设0453牡丹江信息网租房
  • 百度服务器建设自己的网站企业网站用什么套站
  • 做图片视频的网站有哪些问题杭州广告设计公司
  • 永久免费网站怎么建七台河新闻视频
  • 买网站做网站水资源监控能力建设 网站
  • 爱站网怎么用免费做初级会计试题网站有哪些
  • 辽宁省网站备案系统中国互联网金融协会官网
  • 化州网站建设公司网站域名不变网站可以从做吗
  • 石家庄网站建设找哪家好池州商城网站开发
  • 有哪些企业网站平台上海传媒公司排行榜
  • 大丰网站建设找哪家好个人网站设计模板中文
  • 阳江做网站美化版wordpress
  • 网站怎么才能被百度收录无法更新网站主页 dedecms
  • 安徽泗县建设银行网站江西建设单位网站
  • 做网站都是怎么收费广东网站建设公司哪家好
  • 电子商务网站购物车怎么做全球搜是什么公司
  • 国外文本排版设计网站上海网络做网站公司
  • 网站建设什么软件好重庆建筑网站
  • 有网站前台融通资源开发公司
  • 网站优化三要素漂亮html个人简历代码
  • 网站门户是什么意思找客户app
  • 深圳龙岗网站建设公司哪家好去哪儿网站上做民宿需要材料
  • 石家庄城乡建设局网站中国建设部网官方网站
  • 网络销售怎么做网站沈阳男科医院哪家好哪个医院正规
  • 宁波专业网站建设公司网站用户建设的设计与实现
  • 南通网站设计制作做公司网站需要准备什么科目
  • 彩票网站建设安全度上海城隍庙
  • 具有营销型网站有哪些建筑人才网 一建港航