This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2 SVGADrawable.kt SVGAImageView.kt SVGAVideoEntity.kt 公开clear()方法. 3 SVGAVideoEntity.kt generateAudioFileMap 方法每次打开同一个文件会解压一次mp3.缓存文件会越来越大.改为固定名字.
- Loading branch information
linjp
committed
Aug 25, 2020
1 parent
88d7296
commit 84fcf55
Showing
7 changed files
with
219 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
library/src/main/java/com/opensource/svgaplayer/SVGACache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.opensource.svgaplayer | ||
|
||
import android.content.Context | ||
import java.io.File | ||
import java.net.URL | ||
import java.security.MessageDigest | ||
|
||
|
||
object SVGACache { | ||
enum class Type { | ||
DEFAULT, | ||
FILE | ||
} | ||
|
||
private var type: Type = Type.DEFAULT | ||
private var cacheDir: String = "/" | ||
|
||
fun onCreate(context: Context?) { | ||
onCreate(context, Type.DEFAULT) | ||
} | ||
|
||
fun onCreate(context: Context?, type: Type) { | ||
if (isInitialized()) return | ||
context ?: return | ||
cacheDir = "${context.cacheDir.absolutePath}/svga/" | ||
File(cacheDir).takeIf { !it.exists() }?.mkdir() | ||
this.type = type | ||
} | ||
|
||
fun isInitialized(): Boolean { | ||
return "/" != cacheDir | ||
} | ||
|
||
fun isDefaultCache(): Boolean = type == Type.DEFAULT | ||
|
||
fun isCached(cacheKey: String): Boolean { | ||
return (if (isDefaultCache()) buildCacheDir(cacheKey) else buildCacheFile( | ||
cacheKey | ||
)).exists() | ||
} | ||
|
||
fun buildCacheKey(str: String): String { | ||
val messageDigest = MessageDigest.getInstance("MD5") | ||
messageDigest.update(str.toByteArray(charset("UTF-8"))) | ||
val digest = messageDigest.digest() | ||
var sb = "" | ||
for (b in digest) { | ||
sb += String.format("%02x", b) | ||
} | ||
return sb | ||
} | ||
|
||
fun buildCacheKey(url: URL): String = buildCacheKey(url.toString()) | ||
|
||
fun buildCacheDir(cacheKey: String): File { | ||
return File("$cacheDir$cacheKey/") | ||
} | ||
|
||
fun buildCacheFile(cacheKey: String): File { | ||
return File("$cacheDir$cacheKey.svga") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.