push2talk
This commit is contained in:
@@ -3,7 +3,9 @@ package com.digitalperson.ui
|
||||
import android.app.Activity
|
||||
import android.opengl.GLSurfaceView
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.view.MotionEvent
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ScrollView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
@@ -14,6 +16,8 @@ class Live2DUiManager(private val activity: Activity) {
|
||||
private var scrollView: ScrollView? = null
|
||||
private var startButton: Button? = null
|
||||
private var stopButton: Button? = null
|
||||
private var recordButton: Button? = null
|
||||
private var traditionalButtons: LinearLayout? = null
|
||||
private var avatarManager: Live2DAvatarManager? = null
|
||||
|
||||
private var lastUiText: String = ""
|
||||
@@ -21,16 +25,20 @@ class Live2DUiManager(private val activity: Activity) {
|
||||
fun initViews(
|
||||
textViewId: Int,
|
||||
scrollViewId: Int,
|
||||
startButtonId: Int,
|
||||
stopButtonId: Int,
|
||||
startButtonId: Int = -1,
|
||||
stopButtonId: Int = -1,
|
||||
recordButtonId: Int = -1,
|
||||
traditionalButtonsId: Int = -1,
|
||||
silentPlayerViewId: Int,
|
||||
speakingPlayerViewId: Int,
|
||||
live2dViewId: Int
|
||||
) {
|
||||
textView = activity.findViewById(textViewId)
|
||||
scrollView = activity.findViewById(scrollViewId)
|
||||
startButton = activity.findViewById(startButtonId)
|
||||
stopButton = activity.findViewById(stopButtonId)
|
||||
if (startButtonId != -1) startButton = activity.findViewById(startButtonId)
|
||||
if (stopButtonId != -1) stopButton = activity.findViewById(stopButtonId)
|
||||
if (recordButtonId != -1) recordButton = activity.findViewById(recordButtonId)
|
||||
if (traditionalButtonsId != -1) traditionalButtons = activity.findViewById(traditionalButtonsId)
|
||||
|
||||
textView?.movementMethod = ScrollingMovementMethod()
|
||||
|
||||
@@ -46,6 +54,36 @@ class Live2DUiManager(private val activity: Activity) {
|
||||
fun setStopButtonListener(listener: () -> Unit) {
|
||||
stopButton?.setOnClickListener { listener() }
|
||||
}
|
||||
|
||||
fun setRecordButtonTouchListener(listener: (Boolean) -> Unit) {
|
||||
recordButton?.setOnTouchListener {
|
||||
_, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
recordButton?.isPressed = true
|
||||
listener(true)
|
||||
true
|
||||
}
|
||||
MotionEvent.ACTION_UP,
|
||||
MotionEvent.ACTION_CANCEL -> {
|
||||
recordButton?.isPressed = false
|
||||
listener(false)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setUseHoldToSpeak(useHoldToSpeak: Boolean) {
|
||||
if (useHoldToSpeak) {
|
||||
traditionalButtons?.visibility = LinearLayout.GONE
|
||||
recordButton?.visibility = Button.VISIBLE
|
||||
} else {
|
||||
traditionalButtons?.visibility = LinearLayout.VISIBLE
|
||||
recordButton?.visibility = Button.GONE
|
||||
}
|
||||
}
|
||||
|
||||
fun appendToUi(s: String) {
|
||||
lastUiText += s
|
||||
@@ -63,9 +101,10 @@ class Live2DUiManager(private val activity: Activity) {
|
||||
textView?.text = text
|
||||
}
|
||||
|
||||
fun setButtonsEnabled(startEnabled: Boolean, stopEnabled: Boolean) {
|
||||
fun setButtonsEnabled(startEnabled: Boolean = false, stopEnabled: Boolean = false, recordEnabled: Boolean = true) {
|
||||
startButton?.isEnabled = startEnabled
|
||||
stopButton?.isEnabled = stopEnabled
|
||||
recordButton?.isEnabled = recordEnabled
|
||||
}
|
||||
|
||||
fun setSpeaking(speaking: Boolean) {
|
||||
@@ -74,6 +113,18 @@ class Live2DUiManager(private val activity: Activity) {
|
||||
}
|
||||
}
|
||||
|
||||
fun setMood(mood: String) {
|
||||
activity.runOnUiThread {
|
||||
avatarManager?.setMood(mood)
|
||||
}
|
||||
}
|
||||
|
||||
fun startSpecificMotion(motionName: String) {
|
||||
activity.runOnUiThread {
|
||||
avatarManager?.startSpecificMotion(motionName)
|
||||
}
|
||||
}
|
||||
|
||||
fun showToast(message: String, duration: Int = Toast.LENGTH_SHORT) {
|
||||
activity.runOnUiThread {
|
||||
Toast.makeText(activity, message, duration).show()
|
||||
@@ -92,4 +143,4 @@ class Live2DUiManager(private val activity: Activity) {
|
||||
avatarManager?.release()
|
||||
avatarManager = null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user