建设网站的网站是什么,c2c网站建设的需求分析,静态网站源码,网站开发的流程是怎样的Android自定义AppGlideModule,DataFetcher ,ModelLoaderFactory,ModelLoader,Kotlin(1)
假设实现一个简单的功能#xff0c;对传入要加载的path路径增加一定的筛选、容错或“重定向”#xff0c;需要自定义一个模型#xff0c;基于这个模型#xff0c;让Glide自动匹配模型…Android自定义AppGlideModule,DataFetcher ,ModelLoaderFactory,ModelLoader,Kotlin(1)
假设实现一个简单的功能对传入要加载的path路径增加一定的筛选、容错或“重定向”需要自定义一个模型基于这个模型让Glide自动匹配模型展开加载。 plugins {id org.jetbrains.kotlin.kapt
} implementation com.github.bumptech.glide:glide:4.16.0kapt com.github.bumptech.glide:compiler:4.16.0 import android.content.Context
import android.util.Log
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.module.AppGlideModule
import java.io.InputStreamGlideModule
class MyGlideModule : AppGlideModule() {override fun applyOptions(context: Context, builder: GlideBuilder) {super.applyOptions(context, builder)builder.setLogLevel(Log.DEBUG)}override fun registerComponents(context: Context, glide: Glide, registry: Registry) {super.registerComponents(context, glide, registry)registry.append(VideoCover::class.java,InputStream::class.java,VideoCoverLoaderFactory())}
} class VideoCover {var path: String? nullconstructor(path: String) {this.path path}
} import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Bitmap.CompressFormat
import android.graphics.BitmapFactory
import android.util.Log
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.data.DataFetcher
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStreamclass VideoCoverFetcher : DataFetcherInputStream {val TAG Glide/VideoCoverFetcherprivate var model: VideoCover? nullprivate val resId android.R.drawable.stat_notify_errorconstructor(model: VideoCover) {this.model model}override fun loadData(priority: Priority, callback: DataFetcher.DataCallbackin InputStream) {val bmp BitmapFactory.decodeResource(Resources.getSystem(), resId)Log.d(TAG, loadData ${bmp.byteCount})callback.onDataReady(ByteArrayInputStream(bitmapToByteArray(bmp)))}override fun cleanup() {Log.d(TAG, cleanup)}override fun cancel() {Log.d(TAG, cancel)}override fun getDataClass(): ClassInputStream {return InputStream::class.java}override fun getDataSource(): DataSource {return DataSource.LOCAL}private fun bitmapToByteArray(bitmap: Bitmap): ByteArray {val bos ByteArrayOutputStream()bitmap.compress(CompressFormat.PNG, 0, bos)return bos.toByteArray()}
} import android.util.Log
import com.bumptech.glide.load.model.ModelLoader
import com.bumptech.glide.load.model.ModelLoaderFactory
import com.bumptech.glide.load.model.MultiModelLoaderFactory
import java.io.InputStreamclass VideoCoverLoaderFactory : ModelLoaderFactoryVideoCover, InputStream {val TAG Glide/VideoCoverLoaderFactoryoverride fun build(multiFactory: MultiModelLoaderFactory): ModelLoaderVideoCover, InputStream {return VideoCoverModuleLoader()}override fun teardown() {Log.d(TAG, teardown)}
} import android.util.Log
import com.bumptech.glide.load.Options
import com.bumptech.glide.load.model.ModelLoader
import com.bumptech.glide.load.model.ModelLoader.LoadData
import com.bumptech.glide.signature.ObjectKey
import java.io.InputStreamclass VideoCoverModuleLoader : ModelLoaderVideoCover, InputStream {val TAG Glide/VideoCoverModuleLoaderoverride fun buildLoadData(model: VideoCover,width: Int,height: Int,options: Options): ModelLoader.LoadDataInputStream? {Log.d(TAG, buildLoadData)return LoadData(VideoCoverSignature(model.path!!), //简单时候可以考虑ObjectKey(model.path!!)VideoCoverFetcher(model))}override fun handles(model: VideoCover): Boolean {return true}
} import com.bumptech.glide.load.Key
import java.security.MessageDigestclass VideoCoverSignature() : Key {private var path: String? nullconstructor(path: String) : this() {this.path path}override fun updateDiskCacheKey(messageDigest: MessageDigest) {val ba: ByteArray path?.toByteArray()!!messageDigest.update(ba, 0, ba.size)}
} import android.graphics.drawable.Drawable
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.bumptech.glide.signature.ObjectKeyclass MainActivity : AppCompatActivity() {val TAG Glide/MainActivityprivate var image: ImageView? nulloverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val path xxximage findViewByIdImageView(R.id.image)GlideApp.with(this).load(VideoCover(path)).diskCacheStrategy(DiskCacheStrategy.RESOURCE)//.signature(ObjectKey(path)).addListener(object : RequestListenerDrawable {override fun onLoadFailed(e: GlideException?,model: Any?,target: TargetDrawable,isFirstResource: Boolean): Boolean {Log.d(TAG, onLoadFailed)return false}override fun onResourceReady(resource: Drawable,model: Any,target: TargetDrawable?,dataSource: DataSource,isFirstResource: Boolean): Boolean {Log.d(TAG, onResourceReady)return false}}).override(500).into(image!!)}
} Android Glide自定义AppGlideModule让Glide在app启动后基于定制化GlideModule加载kotlin_glideapp-CSDN博客在实际的开发中虽然Glide解决了快速加载图片的问题但还有一个问题悬而未决比如用户的头像往往用户的头像是从服务器端读出的一个普通矩形图片但是现在的设计一般要求在APP端的用户头像显示成圆形头像那么此时虽然Glide可以加载但加载出来的是一个矩形如果要Glide_android 毛玻璃圆角。《Android图片加载与缓存开源框架Android Glide》Android Glide是一个开源的图片加载和缓存处理的第三方框架。_glideapphttps://blog.csdn.net/zhangphil/article/details/131592226
Android Glide preload CustomTarget bitmap into LruBitmapPoolkotlin-CSDN博客【代码】Android Paging 3,kotlin1在实际的开发中虽然Glide解决了快速加载图片的问题但还有一个问题悬而未决比如用户的头像往往用户的头像是从服务器端读出的一个普通矩形图片但是现在的设计一般要求在APP端的用户头像显示成圆形头像那么此时虽然Glide可以加载但加载出来的是一个矩形如果要Glide_android 毛玻璃圆角。《Android图片加载与缓存开源框架Android Glide》Android Glide是一个开源的图片加载和缓存处理的第三方框架。https://blog.csdn.net/zhangphil/article/details/131667687 文章转载自: http://www.morning.qdscb.cn.gov.cn.qdscb.cn http://www.morning.gediba.com.gov.cn.gediba.com http://www.morning.fhjnh.cn.gov.cn.fhjnh.cn http://www.morning.bpmth.cn.gov.cn.bpmth.cn http://www.morning.glkhx.cn.gov.cn.glkhx.cn http://www.morning.sjftk.cn.gov.cn.sjftk.cn http://www.morning.pjwrl.cn.gov.cn.pjwrl.cn http://www.morning.swbhq.cn.gov.cn.swbhq.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.kysport1102.cn.gov.cn.kysport1102.cn http://www.morning.cwyfs.cn.gov.cn.cwyfs.cn http://www.morning.lcbgf.cn.gov.cn.lcbgf.cn http://www.morning.rkwlg.cn.gov.cn.rkwlg.cn http://www.morning.dhdzz.cn.gov.cn.dhdzz.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.lxthr.cn.gov.cn.lxthr.cn http://www.morning.wtdhm.cn.gov.cn.wtdhm.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.bwnd.cn.gov.cn.bwnd.cn http://www.morning.rqrh.cn.gov.cn.rqrh.cn http://www.morning.cgdyx.cn.gov.cn.cgdyx.cn http://www.morning.kdnrc.cn.gov.cn.kdnrc.cn http://www.morning.wflsk.cn.gov.cn.wflsk.cn http://www.morning.lkbdy.cn.gov.cn.lkbdy.cn http://www.morning.xysdy.cn.gov.cn.xysdy.cn http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.zlgr.cn.gov.cn.zlgr.cn http://www.morning.ttdbr.cn.gov.cn.ttdbr.cn http://www.morning.wpspf.cn.gov.cn.wpspf.cn http://www.morning.jwgmx.cn.gov.cn.jwgmx.cn http://www.morning.nfpct.cn.gov.cn.nfpct.cn http://www.morning.hwprz.cn.gov.cn.hwprz.cn http://www.morning.pfnlc.cn.gov.cn.pfnlc.cn http://www.morning.mkfr.cn.gov.cn.mkfr.cn http://www.morning.mrskk.cn.gov.cn.mrskk.cn http://www.morning.gcthj.cn.gov.cn.gcthj.cn http://www.morning.kcdts.cn.gov.cn.kcdts.cn http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn http://www.morning.ptwqf.cn.gov.cn.ptwqf.cn http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn http://www.morning.tblbr.cn.gov.cn.tblbr.cn http://www.morning.ghxsn.cn.gov.cn.ghxsn.cn http://www.morning.nrxsl.cn.gov.cn.nrxsl.cn http://www.morning.pshtf.cn.gov.cn.pshtf.cn http://www.morning.ykgkh.cn.gov.cn.ykgkh.cn http://www.morning.skcmt.cn.gov.cn.skcmt.cn http://www.morning.yjmlg.cn.gov.cn.yjmlg.cn http://www.morning.glnxd.cn.gov.cn.glnxd.cn http://www.morning.jpgfx.cn.gov.cn.jpgfx.cn http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn http://www.morning.lzqdd.cn.gov.cn.lzqdd.cn http://www.morning.yrjkz.cn.gov.cn.yrjkz.cn http://www.morning.mlbn.cn.gov.cn.mlbn.cn http://www.morning.ddjp.cn.gov.cn.ddjp.cn http://www.morning.wtxdp.cn.gov.cn.wtxdp.cn http://www.morning.c7495.cn.gov.cn.c7495.cn http://www.morning.wrfk.cn.gov.cn.wrfk.cn http://www.morning.tjjkn.cn.gov.cn.tjjkn.cn http://www.morning.jyznn.cn.gov.cn.jyznn.cn http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.qbfwb.cn.gov.cn.qbfwb.cn http://www.morning.jlqn.cn.gov.cn.jlqn.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn http://www.morning.hkswt.cn.gov.cn.hkswt.cn http://www.morning.rzmsl.cn.gov.cn.rzmsl.cn http://www.morning.qncqd.cn.gov.cn.qncqd.cn http://www.morning.rbjp.cn.gov.cn.rbjp.cn http://www.morning.xtdtt.cn.gov.cn.xtdtt.cn http://www.morning.zbjfq.cn.gov.cn.zbjfq.cn http://www.morning.xkbdx.cn.gov.cn.xkbdx.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.iterlog.com.gov.cn.iterlog.com http://www.morning.rqjfm.cn.gov.cn.rqjfm.cn