调整UI
调整道路属性面板
This commit is contained in:
@@ -1,149 +0,0 @@
|
||||
package com.navinfo.omqs.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.navinfo.omqs.ui.dialog.FirstDialog;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
//语音类
|
||||
public class SpeakMode extends Activity implements TextToSpeech.OnInitListener{
|
||||
private Activity mActivity;
|
||||
private TextToSpeech mTextToSpeech;//TTS对象
|
||||
private int status;
|
||||
private int MY_DATA_CHECK_CODE = 0;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case 0x11:
|
||||
try {
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
|
||||
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, "STREAM_NOTIFICATION");//设置播放类型(音频流类型)
|
||||
|
||||
mTextToSpeech.speak(msg.obj + "", TextToSpeech.QUEUE_ADD, params);//将这个发音任务添加当前任务之后
|
||||
|
||||
//BaseToast.makeText(mActivity,msg.obj+"",Toast.LENGTH_LONG).show();
|
||||
|
||||
mTextToSpeech.playSilence(100, TextToSpeech.QUEUE_ADD, params);//间隔多长时间
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public SpeakMode(Activity activity) {
|
||||
|
||||
mActivity = activity;
|
||||
|
||||
if (mActivity != null && !mActivity.isFinishing())
|
||||
this.mTextToSpeech = new TextToSpeech(this.mActivity, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent checkIntent = new Intent();
|
||||
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
|
||||
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
|
||||
}
|
||||
|
||||
public void setData(String json) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit(int status) {
|
||||
this.status = status;
|
||||
if (this.mTextToSpeech != null) {
|
||||
int result = this.mTextToSpeech.setLanguage(Locale.CHINESE);
|
||||
if (result == TextToSpeech.LANG_MISSING_DATA
|
||||
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
||||
if (mActivity != null && !mActivity.isFinishing()) {
|
||||
FirstDialog firstDialog = new FirstDialog(mActivity);
|
||||
firstDialog.setTitle("提示");
|
||||
firstDialog.setMessage("设备不支持语音播报,请先下载语音助手。");
|
||||
firstDialog.setConfirmListener(new FirstDialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(Dialog dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
firstDialog.setNegativeView(View.GONE);
|
||||
firstDialog.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i("TextToSpeechDemo", String.valueOf(status));
|
||||
}
|
||||
|
||||
//读语音处理
|
||||
public void speakText(final String message) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (mTextToSpeech != null) {
|
||||
|
||||
int result = mTextToSpeech.setLanguage(Locale.CHINESE);
|
||||
|
||||
if (result == TextToSpeech.LANG_MISSING_DATA
|
||||
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
||||
|
||||
} else {
|
||||
if (mTextToSpeech != null && mTextToSpeech.isSpeaking()) {
|
||||
|
||||
while (mTextToSpeech.isSpeaking()) {
|
||||
|
||||
try {
|
||||
//增加播报停止,解决不能播报最新内容问题
|
||||
mTextToSpeech.stop();
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Message msg = new Message();
|
||||
msg.what = 0x11;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
public void stopSpeek() {
|
||||
try {
|
||||
|
||||
if (this.mTextToSpeech != null && this.mTextToSpeech.isSpeaking()) {
|
||||
this.mTextToSpeech.stop();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
110
app/src/main/java/com/navinfo/omqs/util/SpeakMode.kt
Normal file
110
app/src/main/java/com/navinfo/omqs/util/SpeakMode.kt
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.navinfo.omqs.util
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import android.speech.tts.TextToSpeech
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import com.navinfo.omqs.ui.dialog.FirstDialog
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
//语音类
|
||||
class SpeakMode(private val context: Context) : TextToSpeech.OnInitListener {
|
||||
private var mTextToSpeech: TextToSpeech = TextToSpeech(context, this)
|
||||
private var status = 0
|
||||
private val MY_DATA_CHECK_CODE = 0
|
||||
private val mHandler: Handler = object : Handler() {
|
||||
override fun handleMessage(msg: Message) {
|
||||
when (msg.what) {
|
||||
0x11 -> try {
|
||||
val params = HashMap<String, String>()
|
||||
params[TextToSpeech.Engine.KEY_PARAM_STREAM] =
|
||||
"STREAM_NOTIFICATION" //设置播放类型(音频流类型)
|
||||
mTextToSpeech.speak(
|
||||
msg.obj.toString() + "",
|
||||
TextToSpeech.QUEUE_ADD,
|
||||
params
|
||||
) //将这个发音任务添加当前任务之后
|
||||
|
||||
//BaseToast.makeText(mActivity,msg.obj+"",Toast.LENGTH_LONG).show();
|
||||
mTextToSpeech.playSilence(100, TextToSpeech.QUEUE_ADD, params) //间隔多长时间
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
// if (mActivity != null && !mActivity.isFinishing) mTextToSpeech = TextToSpeech(
|
||||
// mActivity, this
|
||||
// )
|
||||
|
||||
}
|
||||
|
||||
// override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// super.onCreate(savedInstanceState)
|
||||
// val checkIntent = Intent()
|
||||
// checkIntent.action = TextToSpeech.Engine.ACTION_CHECK_TTS_DATA
|
||||
// startActivityForResult(checkIntent, MY_DATA_CHECK_CODE)
|
||||
// }
|
||||
|
||||
fun setData(json: String?) {}
|
||||
override fun onInit(status: Int) {
|
||||
this.status = status
|
||||
val result = mTextToSpeech.setLanguage(Locale.CHINESE)
|
||||
if (result == TextToSpeech.LANG_MISSING_DATA
|
||||
|| result == TextToSpeech.LANG_NOT_SUPPORTED
|
||||
) {
|
||||
if (context != null) {
|
||||
val firstDialog = FirstDialog(context)
|
||||
firstDialog.setTitle("提示")
|
||||
firstDialog.setMessage("设备不支持语音播报,请先下载语音助手。")
|
||||
firstDialog.setConfirmListener { dialog, _ -> dialog.dismiss() }
|
||||
firstDialog.setNegativeView(View.GONE)
|
||||
firstDialog.show()
|
||||
}
|
||||
}
|
||||
Log.i("TextToSpeechDemo", status.toString())
|
||||
}
|
||||
|
||||
//读语音处理
|
||||
fun speakText(message: String) {
|
||||
mTextToSpeech.speak(message, TextToSpeech.QUEUE_FLUSH, null, "")
|
||||
// val result = mTextToSpeech.setLanguage(Locale.CHINESE)
|
||||
// if (result == TextToSpeech.LANG_MISSING_DATA
|
||||
// || result == TextToSpeech.LANG_NOT_SUPPORTED
|
||||
// ) {
|
||||
// } else {
|
||||
// while (mTextToSpeech.isSpeaking) {
|
||||
// try {
|
||||
// //增加播报停止,解决不能播报最新内容问题
|
||||
// mTextToSpeech.stop()
|
||||
// } catch (e: Exception) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// val msg = Message()
|
||||
// msg.what = 0x11
|
||||
// msg.obj = message
|
||||
// mHandler.sendMessage(msg)
|
||||
// }
|
||||
}
|
||||
|
||||
fun stopSpeech() {
|
||||
try {
|
||||
if (mTextToSpeech.isSpeaking) {
|
||||
mTextToSpeech.stop()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
fun shutdown() {
|
||||
stopSpeech()
|
||||
mTextToSpeech.shutdown()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user