live2d model
This commit is contained in:
95
app/src/main/java/com/digitalperson/ui/Live2DUiManager.kt
Normal file
95
app/src/main/java/com/digitalperson/ui/Live2DUiManager.kt
Normal file
@@ -0,0 +1,95 @@
|
||||
package com.digitalperson.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.opengl.GLSurfaceView
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.widget.Button
|
||||
import android.widget.ScrollView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.digitalperson.live2d.Live2DAvatarManager
|
||||
|
||||
class Live2DUiManager(private val activity: Activity) {
|
||||
private var textView: TextView? = null
|
||||
private var scrollView: ScrollView? = null
|
||||
private var startButton: Button? = null
|
||||
private var stopButton: Button? = null
|
||||
private var avatarManager: Live2DAvatarManager? = null
|
||||
|
||||
private var lastUiText: String = ""
|
||||
|
||||
fun initViews(
|
||||
textViewId: Int,
|
||||
scrollViewId: Int,
|
||||
startButtonId: Int,
|
||||
stopButtonId: Int,
|
||||
silentPlayerViewId: Int,
|
||||
speakingPlayerViewId: Int,
|
||||
live2dViewId: Int
|
||||
) {
|
||||
textView = activity.findViewById(textViewId)
|
||||
scrollView = activity.findViewById(scrollViewId)
|
||||
startButton = activity.findViewById(startButtonId)
|
||||
stopButton = activity.findViewById(stopButtonId)
|
||||
|
||||
textView?.movementMethod = ScrollingMovementMethod()
|
||||
|
||||
val glView = activity.findViewById<GLSurfaceView>(live2dViewId)
|
||||
avatarManager = Live2DAvatarManager(glView)
|
||||
avatarManager?.setSpeaking(false)
|
||||
}
|
||||
|
||||
fun setStartButtonListener(listener: () -> Unit) {
|
||||
startButton?.setOnClickListener { listener() }
|
||||
}
|
||||
|
||||
fun setStopButtonListener(listener: () -> Unit) {
|
||||
stopButton?.setOnClickListener { listener() }
|
||||
}
|
||||
|
||||
fun appendToUi(s: String) {
|
||||
lastUiText += s
|
||||
textView?.text = lastUiText
|
||||
scrollView?.post { scrollView?.fullScroll(ScrollView.FOCUS_DOWN) }
|
||||
}
|
||||
|
||||
fun clearText() {
|
||||
lastUiText = ""
|
||||
textView?.text = ""
|
||||
}
|
||||
|
||||
fun setText(text: String) {
|
||||
lastUiText = text
|
||||
textView?.text = text
|
||||
}
|
||||
|
||||
fun setButtonsEnabled(startEnabled: Boolean, stopEnabled: Boolean) {
|
||||
startButton?.isEnabled = startEnabled
|
||||
stopButton?.isEnabled = stopEnabled
|
||||
}
|
||||
|
||||
fun setSpeaking(speaking: Boolean) {
|
||||
activity.runOnUiThread {
|
||||
avatarManager?.setSpeaking(speaking)
|
||||
}
|
||||
}
|
||||
|
||||
fun showToast(message: String, duration: Int = Toast.LENGTH_SHORT) {
|
||||
activity.runOnUiThread {
|
||||
Toast.makeText(activity, message, duration).show()
|
||||
}
|
||||
}
|
||||
|
||||
fun onResume() {
|
||||
avatarManager?.onResume()
|
||||
}
|
||||
|
||||
fun onPause() {
|
||||
avatarManager?.onPause()
|
||||
}
|
||||
|
||||
fun release() {
|
||||
avatarManager?.release()
|
||||
avatarManager = null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user