live2d model

This commit is contained in:
gcw_4spBpAfv
2026-03-02 09:25:50 +08:00
parent d63d4b03cf
commit 2f6166ab6c
179 changed files with 100625 additions and 2018 deletions

View 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
}
}