106 lines
3.5 KiB
Kotlin
106 lines
3.5 KiB
Kotlin
package com.keypalette.theme.dataabout
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import android.graphics.BitmapFactory
|
|
import android.graphics.drawable.BitmapDrawable
|
|
import android.graphics.drawable.Drawable
|
|
import android.util.Log
|
|
import com.keypalette.theme.KeyApp
|
|
import com.keypalette.theme.other.ResName
|
|
import com.keypalette.theme.other.SpSkins
|
|
import com.keypalette.theme.code.CodeKeyBoard
|
|
import java.io.File
|
|
|
|
object KeyUtils {
|
|
|
|
fun keyToUpper(mKeyBoard: CodeKeyBoard) {
|
|
for (key in mKeyBoard.keys) {
|
|
if (key.label != null) {
|
|
if (key.label.length == 1) {
|
|
val charLabel = key.label.toString()[0]
|
|
val toUpperCase = charLabel.uppercaseChar()
|
|
key.codes[0] = toUpperCase.toInt()
|
|
key.label = toUpperCase.toString()
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fun keyToLowerCase(mKeyBoard: CodeKeyBoard) {
|
|
for (key in mKeyBoard.keys) {
|
|
if (key.label != null) {
|
|
if (key.label.length == 1) {
|
|
val charLabel = key.label.toString()[0]
|
|
val toLowerCase = charLabel.lowercaseChar()
|
|
key.codes[0] = toLowerCase.toInt()
|
|
key.label = toLowerCase.toString()
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
fun primaryCodeToChar(primCode: Int): String {
|
|
val toString = primCode.toChar().toString()
|
|
|
|
return toString
|
|
}
|
|
|
|
@SuppressLint("SuspiciousIndentation")
|
|
fun readBgOrVideo(
|
|
context: Context,
|
|
playAction: (gif: String?, bgDraw: Drawable?) -> Unit
|
|
) {
|
|
|
|
SpSkins.getSkinPath()?.let { resPath ->
|
|
val videoPath = "${resPath}res/raw/${ResName.videoName}"
|
|
val videoPath2 = "${resPath}res/raw/${ResName.video}"
|
|
val backgroundPath = "${resPath}res/drawable-xxhdpi-v4/${ResName.bgName}"
|
|
val backgroundPath_png = "${resPath}res/drawable-xxhdpi-v4/${ResName.bgName_png}"
|
|
val file = File(videoPath)
|
|
val file2 = File(videoPath2)
|
|
val file3 = File(backgroundPath)
|
|
val file4 = File(backgroundPath_png)
|
|
if (file.exists() || file2.exists()) {
|
|
Log.d(KeyApp.Companion.TAG, "--------11111111= resPath=${resPath}")
|
|
val path: String = if (file.exists()) {
|
|
videoPath
|
|
} else {
|
|
videoPath2
|
|
}
|
|
|
|
|
|
val bitmapDrawable =
|
|
BitmapDrawable(context.resources, BitmapFactory.decodeFile(path))
|
|
|
|
playAction.invoke(path, null)
|
|
|
|
// playAction.invoke(mediaPlayer,null);
|
|
} else {
|
|
Log.d(
|
|
KeyApp.Companion.TAG,
|
|
"--------11111111= file3.exists()" + file3.exists() + "---resPath=" + resPath
|
|
)
|
|
if (file3.exists()) {
|
|
val bitmapDrawable =
|
|
BitmapDrawable(context.resources, BitmapFactory.decodeFile(backgroundPath))
|
|
playAction.invoke(null, bitmapDrawable)
|
|
} else if (file4.exists()) {
|
|
val bitmapDrawable =
|
|
BitmapDrawable(context.resources, BitmapFactory.decodeFile(backgroundPath_png))
|
|
playAction.invoke(null, bitmapDrawable)
|
|
} else {
|
|
playAction.invoke(null, null)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
} |