@@ -35,43 +35,22 @@ class SVGAVideoEntity {
3535 var frames: Int = 0
3636 private set
3737
38- internal var reqHeight = 0
39- internal var reqWidth = 0
38+ private var reqHeight = 0
39+ private var reqWidth = 0
4040 internal var spriteList: List <SVGAVideoSpriteEntity > = emptyList()
4141 internal var audioList: List <SVGAAudioEntity > = emptyList()
4242 internal var soundPool: SoundPool ? = null
4343 internal var imageMap = HashMap <String , Bitmap >()
4444 private var mCacheDir: File
45+ private var mJsonMovie: JSONObject ? = null
4546
4647 constructor (json: JSONObject , cacheDir: File ) {
47- this .mCacheDir = cacheDir
48- json.optJSONObject(" movie" )?.let (this ::setup)
49- try {
50- parserImages(json)
51- } catch (e: Exception ) {
52- e.printStackTrace()
53- } catch (e: OutOfMemoryError ) {
54- e.printStackTrace()
55- }
56- resetSprites(json)
57- }
58-
59- internal constructor (entity: MovieEntity , cacheDir: File ) {
60- this .movieItem = entity
61- this .mCacheDir = cacheDir
62- entity.params?.let (this ::setup)
63-
64- try {
65- parserImages(entity)
66- } catch (e: Exception ) {
67- e.printStackTrace()
68- } catch (e: OutOfMemoryError ) {
69- e.printStackTrace()
70- }
71- resetSprites(entity)
48+ mJsonMovie = json
49+ mCacheDir = cacheDir
50+ json.optJSONObject(" movie" )?.let (this ::setupByJson)
7251 }
7352
74- private fun setup (movieObject : JSONObject ) {
53+ private fun setupByJson (movieObject : JSONObject ) {
7554 movieObject.optJSONObject(" viewBox" )?.let { viewBoxObject ->
7655 val width = viewBoxObject.optDouble(" width" , 0.0 )
7756 val height = viewBoxObject.optDouble(" height" , 0.0 )
@@ -81,14 +60,52 @@ class SVGAVideoEntity {
8160 frames = movieObject.optInt(" frames" , 0 )
8261 }
8362
84- private fun setup (movieParams : MovieParams ) {
63+ internal constructor (entity: MovieEntity , cacheDir: File ) {
64+ this .movieItem = entity
65+ this .mCacheDir = cacheDir
66+ entity.params?.let (this ::setupByMovie)
67+ }
68+
69+ private fun setupByMovie (movieParams : MovieParams ) {
8570 val width = (movieParams.viewBoxWidth ? : 0.0f ).toDouble()
8671 val height = (movieParams.viewBoxHeight ? : 0.0f ).toDouble()
8772 videoSize = SVGARect (0.0 , 0.0 , width, height)
8873 FPS = movieParams.fps ? : 20
8974 frames = movieParams.frames ? : 0
9075 }
9176
77+ internal fun init (reqWidth : Int , reqHeight : Int ) {
78+ this .reqWidth = reqWidth
79+ this .reqHeight = reqHeight
80+ if (mJsonMovie != null ) {
81+ parsResourceByJson()
82+ } else if (movieItem != null ) {
83+ parsResourceByMovie()
84+ }
85+ }
86+
87+ private fun parsResourceByJson () {
88+ try {
89+ parserImages(mJsonMovie!! )
90+ } catch (e: Exception ) {
91+ e.printStackTrace()
92+ } catch (e: OutOfMemoryError ) {
93+ e.printStackTrace()
94+ }
95+ resetSprites(mJsonMovie!! )
96+ }
97+
98+ private fun parsResourceByMovie () {
99+ try {
100+ parserImages(movieItem!! )
101+ } catch (e: Exception ) {
102+ e.printStackTrace()
103+ } catch (e: OutOfMemoryError ) {
104+ e.printStackTrace()
105+ }
106+ resetSprites(movieItem!! )
107+ }
108+
92109 internal fun prepare (callback : () -> Unit ) {
93110 if (movieItem == null ) {
94111 callback()
0 commit comments