diff --git a/build.gradle b/build.gradle index 2d344fae..74de56df 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.1.1' apply false - id 'com.android.library' version '8.1.1' apply false + id 'com.android.application' version '8.1.2' apply false + id 'com.android.library' version '8.1.2' apply false id 'org.jetbrains.kotlin.android' version '1.8.10' apply false id 'com.google.devtools.ksp' version '1.8.10-1.0.9' apply false } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index f312a0c6..b1725fa4 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -9,7 +9,7 @@ dependencies { // implementation localGroovy() implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.21" // 添加了这个,就可以看 Android Gradle 插件的源码了 - implementation 'com.android.tools.build:gradle-api:8.1.1' + implementation 'com.android.tools.build:gradle-api:8.1.2' // implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.3.40" implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.android.tools:common:31.0.2' diff --git a/imitate/build.gradle b/imitate/build.gradle index c1ae6ae3..3ba5cba0 100644 --- a/imitate/build.gradle +++ b/imitate/build.gradle @@ -151,6 +151,8 @@ dependencies { implementation "com.alibaba:arouter-api:$ext.arouter_api" kapt "com.alibaba:arouter-compiler:$ext.arouter_compiler" implementation 'com.facebook.fresco:fresco:3.1.0' + implementation 'com.facebook.fresco:animated-webp:3.1.3' + implementation 'com.facebook.fresco:webpsupport:3.1.3' implementation 'com.github.REBOOTERS:Matisse:0.5.3' implementation 'com.guolindev.permissionx:permissionx:1.7.1' implementation 'io.reactivex.rxjava2:rxjava:2.2.21' diff --git a/imitate/src/main/java/com/engineer/imitate/ui/fragments/FrescoFragment.kt b/imitate/src/main/java/com/engineer/imitate/ui/fragments/FrescoFragment.kt index 9c5d6d02..577dca5f 100644 --- a/imitate/src/main/java/com/engineer/imitate/ui/fragments/FrescoFragment.kt +++ b/imitate/src/main/java/com/engineer/imitate/ui/fragments/FrescoFragment.kt @@ -7,12 +7,12 @@ import android.app.WallpaperManager import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Color +import android.graphics.drawable.Animatable import android.graphics.drawable.ClipDrawable import android.graphics.drawable.Drawable import android.net.Uri import android.os.Build import android.os.Bundle -import android.os.Looper import android.util.Log import android.view.LayoutInflater import android.view.View @@ -22,17 +22,23 @@ import com.alibaba.android.arouter.facade.annotation.Route import com.bumptech.glide.Glide import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition +import com.didichuxing.doraemonkit.util.ScreenUtils import com.engineer.imitate.R import com.engineer.imitate.databinding.FragmentFrescoBinding +import com.engineer.imitate.util.dp import com.facebook.common.executors.CallerThreadExecutor import com.facebook.common.references.CloseableReference +import com.facebook.common.util.UriUtil import com.facebook.datasource.DataSource import com.facebook.drawee.backends.pipeline.Fresco +import com.facebook.drawee.controller.BaseControllerListener import com.facebook.drawee.generic.GenericDraweeHierarchy import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder import com.facebook.drawee.generic.RoundingParams +import com.facebook.drawee.interfaces.DraweeController import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber import com.facebook.imagepipeline.image.CloseableImage +import com.facebook.imagepipeline.image.ImageInfo import com.facebook.imagepipeline.request.ImageRequestBuilder import io.reactivex.Observable import io.reactivex.ObservableOnSubscribe @@ -40,6 +46,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers + /** * A simple [Fragment] subclass. * @@ -50,8 +57,7 @@ class FrescoFragment : Fragment() { val c: CompositeDisposable = CompositeDisposable() override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment viewBinding = FragmentFrescoBinding.inflate(inflater, container, false) @@ -62,13 +68,39 @@ class FrescoFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val listener = object : BaseControllerListener() { + override fun onFinalImageSet(id: String?, imageInfo: ImageInfo?, animatable: Animatable?) { + super.onFinalImageSet(id, imageInfo, animatable) + imageInfo?.let { + val w1 = it.width + val h1 = it.height + val width = ScreenUtils.getScreenWidth() - 16.dp + val height = ScreenUtils.getScreenHeight() + Log.d("Fresco", "onFinalImageSet() called w1=$w1,h1=$h1") + Log.d("Fresco", "onFinalImageSet() called w=$width,h=$height") + Log.d("Fresco", "onFinalImageSet() called ${it.qualityInfo.isOfFullQuality}") + Log.d("Fresco", "onFinalImageSet() called ${it.qualityInfo.isOfGoodEnoughQuality}") + Log.d("Fresco", "onFinalImageSet() called ${it.extras}") + viewBinding.s0.layoutParams.width = width +// viewBinding.s0.layoutParams.height = h1 + viewBinding.s0.aspectRatio = 1f * width / height + } +// viewBinding.s0.layoutParams.width = imageInfo?.width ?: 0 + + } + } + + val controller: DraweeController = + Fresco.newDraweeControllerBuilder().setUri(UriUtil.getUriForResourceId(R.drawable.anim)) + .setControllerListener(listener).setAutoPlayAnimations(true).build() + viewBinding.s0.controller = controller + viewBinding.s1.setActualImageResource(R.drawable.totoro) //获取GenericDraweeHierarchy对象 //获取GenericDraweeHierarchy对象 - val hierarchy: GenericDraweeHierarchy = - GenericDraweeHierarchyBuilder(resources).build() + val hierarchy: GenericDraweeHierarchy = GenericDraweeHierarchyBuilder(resources).build() val roundingParams = RoundingParams() roundingParams.roundAsCircle = true roundingParams.borderWidth = 10f @@ -77,8 +109,7 @@ class FrescoFragment : Fragment() { viewBinding.s2.hierarchy = hierarchy viewBinding.s2.setActualImageResource(R.drawable.totoro) - val url = - "http://h.hiphotos.baidu.com/image/pic/item/960a304e251f95ca060674a0c7177f3e67095231.jpg" + val url = "http://h.hiphotos.baidu.com/image/pic/item/960a304e251f95ca060674a0c7177f3e67095231.jpg" val t = System.currentTimeMillis() @@ -111,8 +142,7 @@ class FrescoFragment : Fragment() { override fun onNewResultImpl(bitmap: Bitmap?) { if (bitmap != null) { Log.e( - "zyq", - "thread ==${Thread.currentThread().name}" + "zyq", "thread ==${Thread.currentThread().name}" ) viewBinding.imageView1.post { viewBinding.imageView1.setImageBitmap(bitmap) @@ -158,29 +188,26 @@ class FrescoFragment : Fragment() { private fun bitmapMagic() { viewBinding.shimmerLayout.startShimmerAnimation() - c.add( - Observable.create(ObservableOnSubscribe { emitter -> - val bitmap = BitmapFactory.decodeResource(resources, R.drawable.star) - val width = bitmap.width - val height = bitmap.height - val colorArray = Array(width) { IntArray(height) } - for (i in 0 until width) { - for (j in 0 until height) { + c.add(Observable.create(ObservableOnSubscribe { emitter -> + val bitmap = BitmapFactory.decodeResource(resources, R.drawable.star) + val width = bitmap.width + val height = bitmap.height + val colorArray = Array(width) { IntArray(height) } + for (i in 0 until width) { + for (j in 0 until height) { // Log.e("zyq", "i==$i j==$j") // Log.e("zyq", "live=${emitter.isDisposed}") - if (emitter.isDisposed) { - break - } - colorArray[i][j] = bitmap.getPixel(i, j) + if (emitter.isDisposed) { + break } + colorArray[i][j] = bitmap.getPixel(i, j) } - Log.e("bitmapMagic", "colorArray==$colorArray") - emitter.onNext(bitmap) - }).subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ bitmap -> - setupBitmap(bitmap) - }, { t -> t.printStackTrace() }) + } + Log.e("bitmapMagic", "colorArray==$colorArray") + emitter.onNext(bitmap) + }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe({ bitmap -> + setupBitmap(bitmap) + }, { t -> t.printStackTrace() }) ) } diff --git a/imitate/src/main/res/drawable/anim.webp b/imitate/src/main/res/drawable/anim.webp new file mode 100644 index 00000000..38637fb9 Binary files /dev/null and b/imitate/src/main/res/drawable/anim.webp differ diff --git a/imitate/src/main/res/layout/fragment_fresco.xml b/imitate/src/main/res/layout/fragment_fresco.xml index f0e0ae3a..dc3ec41c 100644 --- a/imitate/src/main/res/layout/fragment_fresco.xml +++ b/imitate/src/main/res/layout/fragment_fresco.xml @@ -13,6 +13,13 @@ android:orientation="vertical" android:paddingBottom="60dp"> + +