|
@@ -2,12 +2,14 @@ package com.bomostory.sceneeditmodule.screen.view
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.graphics.*
|
|
|
+import android.graphics.drawable.BitmapDrawable
|
|
|
import android.graphics.drawable.Drawable
|
|
|
import android.util.AttributeSet
|
|
|
import android.widget.ImageView
|
|
|
import com.bomostory.sceneeditmodule.DialogueDrawer
|
|
|
import com.bomostory.sceneeditmodule.basicdata.Actor
|
|
|
import pl.droidsonroids.gif.GifDrawable
|
|
|
+import kotlin.math.max
|
|
|
|
|
|
class ActorView : ImageView {
|
|
|
|
|
@@ -45,4 +47,43 @@ class ActorView : ImageView {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ fun GifDrawable.getBitmapAt(milliseconds: Int): Bitmap = seekToPositionAndGet(if (loopCount == 0 || milliseconds < duration * loopCount) max(0, milliseconds % duration) else (duration))
|
|
|
+
|
|
|
+ fun isGif(): Boolean {
|
|
|
+ return drawable is GifDrawable
|
|
|
+ }
|
|
|
+
|
|
|
+ fun isGifPlaying(): Boolean {
|
|
|
+ if (drawable is GifDrawable) {
|
|
|
+ val gifDrawable = drawable as GifDrawable
|
|
|
+ return gifDrawable.isPlaying
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ fun startGifAnimation() {
|
|
|
+ if (drawable is GifDrawable) {
|
|
|
+ val gifDrawable = drawable as GifDrawable
|
|
|
+ gifDrawable.start()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun stopGifAnimation() {
|
|
|
+ if (drawable is GifDrawable) {
|
|
|
+ val gifDrawable = drawable as GifDrawable
|
|
|
+ gifDrawable.stop()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getBitmapAt(milliseconds: Int): Bitmap? {
|
|
|
+ if (drawable is GifDrawable) {
|
|
|
+ val gifDrawable = drawable as GifDrawable
|
|
|
+ return gifDrawable.seekToPositionAndGet(milliseconds)
|
|
|
+ } else if (drawable is BitmapDrawable) {
|
|
|
+ val bitmapDrawable = drawable as BitmapDrawable
|
|
|
+ return bitmapDrawable.bitmap
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ }
|
|
|
}
|