mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Fix issue with gif search and emoji loading on lowmem devices.
This commit is contained in:
committed by
Cody Henthorne
parent
5e2a3ac644
commit
02d060ca0a
@@ -0,0 +1,40 @@
|
||||
package org.thoughtcrime.securesms.emoji
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import com.bumptech.glide.load.Option
|
||||
import com.bumptech.glide.load.Options
|
||||
import com.bumptech.glide.load.ResourceDecoder
|
||||
import com.bumptech.glide.load.engine.Resource
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Allows fine grain control over how we decode Emoji pages via a scale factor.
|
||||
*
|
||||
* This can be set via RequestOptions on a Glide request:
|
||||
*
|
||||
* ```
|
||||
* .apply(RequestOptions().set(EmojiBitmapDecoder.OPTION, inSampleSize)
|
||||
* ```
|
||||
*/
|
||||
class EmojiBitmapDecoder(private val bitmapPool: BitmapPool) : ResourceDecoder<InputStream, Bitmap> {
|
||||
|
||||
override fun handles(source: InputStream, options: Options): Boolean {
|
||||
return options.get(OPTION)?.let { it > 1 } ?: false
|
||||
}
|
||||
|
||||
override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<Bitmap>? {
|
||||
val bitmapOptions = BitmapFactory.Options()
|
||||
|
||||
bitmapOptions.inSampleSize = requireNotNull(options.get(OPTION))
|
||||
|
||||
return BitmapResource.obtain(BitmapFactory.decodeStream(source, null, bitmapOptions), bitmapPool)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val OPTION: Option<Int> = Option.memory("emoji_sample_size", 1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user