diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0c084243bc5ae30c326d7ed017199d407944e30b..492b57375fe526b9c143106d9aabe973ce0c80c0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,11 +22,13 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> @@ -37,7 +39,8 @@ + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> @@ -52,33 +55,39 @@ android:name="cn.EasertnDay.HuaZai.SecondaryPage.TZXX" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="landscape" - android:theme="@style/Theme.AppCompat.NoActionBar"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> + android:theme="@style/Theme.AppCompat.NoActionBar" + android:launchMode="singleTask"> + android:launchMode="singleTask" = Build.VERSION_CODES.M) {//判断系统版本 + if (!Settings.canDrawOverlays(this)) { + Toast.makeText(this, "当前无权限,请授权", Toast.LENGTH_SHORT); + startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), 0); + } else { + startService(new Intent(LauncherActivity.this, InformationService.class)); + } + } else { + startService(new Intent(LauncherActivity.this, InformationService.class)); + } + //触摸设置进入调试 SettingButton.setOnTouchListener(new View.OnTouchListener() { @Override @@ -322,4 +334,17 @@ public class LauncherActivity extends AppCompatActivity { } } }; + + //悬浮窗判断 + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 0) { + if (!Settings.canDrawOverlays(this)) { + Toast.makeText(this, "授权失败", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(this, "授权成功", Toast.LENGTH_SHORT).show(); + startService(new Intent(LauncherActivity.this, InformationService.class)); + } + } + } } diff --git a/app/src/main/java/cn/EasertnDay/HuaZai/SplashActivity.java b/app/src/main/java/cn/EasertnDay/HuaZai/SplashActivity.java index 2615c56321a6e17503d8d02909dcdb1f8f88e22b..37b9d894a54786081d8f1c405dc296aa766b2c6c 100644 --- a/app/src/main/java/cn/EasertnDay/HuaZai/SplashActivity.java +++ b/app/src/main/java/cn/EasertnDay/HuaZai/SplashActivity.java @@ -14,6 +14,7 @@ import android.support.constraint.ConstraintLayout; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.util.Log; +import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.Toast; @@ -42,6 +43,8 @@ public class SplashActivity extends AppCompatActivity implements IAsrResultListe ConstraintLayout mLinearLayout;//总布局 ImageView SplashMaskImage;//启动图遮罩 + Intent ii = new Intent(SplashActivity.this, InformationService.class); + //学生信息 File file = new File(InformationService.savePath + InformationService.fileName); boolean IsInit = false; @@ -222,4 +225,12 @@ public class SplashActivity extends AppCompatActivity implements IAsrResultListe e.printStackTrace(); } } + + public void OnClick(View view) { + if (IsInit){ + Log.d("WHZ","垃圾应用"); + Intent myIntent = new Intent(context, LauncherActivity.class); + startActivity(myIntent); + } + } } diff --git a/app/src/main/java/cn/EasertnDay/HuaZai/UserRegesite.java b/app/src/main/java/cn/EasertnDay/HuaZai/UserRegesite.java index d349045039c6db92c32e8fb719fee8ae0099d037..79bf4c5aeb2af059299fab103414725b81e4ccdc 100644 --- a/app/src/main/java/cn/EasertnDay/HuaZai/UserRegesite.java +++ b/app/src/main/java/cn/EasertnDay/HuaZai/UserRegesite.java @@ -1,10 +1,15 @@ package cn.EasertnDay.HuaZai; import android.app.Activity; -import android.os.Handler; +import android.content.Intent; +import android.os.*; import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; +import cn.EasertnDay.HuaZai.SecondaryPage.VoicePage; import cn.EasternDay.HuaZai.R; import com.unisound.sdk.asr.AsrEvent; import com.unisound.sdk.asr.UnisoundAsrEngine; @@ -12,23 +17,55 @@ import com.unisound.sdk.asr.impl.IAsrResultListener; import com.unisound.sdk.tts.TtsOption; import com.unisound.sdk.tts.UnisoundTtsEngine; import com.unisound.sdk.tts.audiotrack.AndroidAudioTrack; +import com.unisound.sdk.tts.impl.ITtsEventListener; import com.unisound.sdk.tts.param.UnisoundTtsPlayMode; +import com.unisound.sdk.utils.SdkLogMgr; import org.json.JSONObject; -public class UserRegesite extends AppCompatActivity implements IAsrResultListener { +import java.util.regex.Pattern; + +public class UserRegesite extends AppCompatActivity { Activity context = this; + String TAG = "纣纣"; + + static String UserName; + static boolean IsChinese = true; + static int STATUS = 0; + //语音识别需要的 private UnisoundAsrEngine unisoundAsrEngine; //语音合成需要的 private UnisoundTtsEngine unisoundTtsEngine; + TextView Mess; + ImageView Show; + + //语音交互 + public Handler handler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case 0: + handler.postDelayed(new Runnable() { + @Override + public void run() { + STATUS++; + } + }, 3000); + } + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_regesite); + Mess = findViewById(R.id.RegisterMessage); + Show = findViewById(R.id.FuckingShow); + //语音识别 unisoundAsrEngine = VoicePresenter.getInstance().getUnisoundAsrEngine(); @@ -45,42 +82,103 @@ public class UserRegesite extends AppCompatActivity implements IAsrResultListene unisoundTtsEngine.setTtsOption(TtsOption.TTS_OPTION_BACK_SIL, 50); unisoundTtsEngine.setTtsOption(TtsOption.TTS_OPTION_VOICE_NAME, "tangtang"); + stopService(new Intent(UserRegesite.this, InformationService.class)); + } + + + @Override + protected void onResume() { + super.onResume(); //开始收声 - VoicePresenter.getInstance().setAsrListener((IAsrResultListener) context); + VoicePresenter.getInstance().setAsrListener(iAsrResultListener); if (unisoundAsrEngine.startWakeUp()) { - unisoundTtsEngine.playTts("小朋友你叫什么名字?"); + unisoundAsrEngine.startAsr(false); } - } - @Override - public void onResult(int event, String result) { - if (event == AsrEvent.ASR_EVENT_ASR_RESULT) { - try { - JSONObject jsonObject = new JSONObject(result); - String asrResult = jsonObject.getString("asr_recongize"); - if (!TextUtils.isEmpty(asrResult)) { - + //语音监听 + private IAsrResultListener iAsrResultListener = new IAsrResultListener() { + @Override + public void onResult(int event, String result) { + Log.d(TAG, event + "||onResult: " + result); + if (event == AsrEvent.ASR_EVENT_ASR_RESULT) { + try { + Log.d(TAG + TAG, String.valueOf(STATUS)); + JSONObject jsonObject = new JSONObject(result); + String asrResult = jsonObject.getString("asr_recongize"); + Log.d(TAG, String.valueOf(STATUS)); + if (STATUS == 0) { + handler.sendEmptyMessage(0); + unisoundTtsEngine.playTts("请选择语言"); + Mess.setText("请选择语言|Please select language\n【中文|English】"); + STATUS++; + } else if (STATUS == 2 && asrResult != "") { + IsChinese = !asrResult.contains("English"); + STATUS++; + } else if (STATUS == 3 && asrResult != "") { + unisoundTtsEngine.playTts("好的小朋友你选择了" + (IsChinese ? "中文," : "English,") + "那么,小朋友你叫什么名字呢?"); + Mess.setText("小朋友你叫什么名字"); + handler.sendEmptyMessage(0); + STATUS++; + } else if (STATUS == 5 && asrResult != "") { + UserName = asrResult.replace("我叫", ""); + unisoundTtsEngine.playTts("小朋友你是叫" + UserName + "吗?"); + STATUS++; + } else if (STATUS == 6 && asrResult != "") { + if (Pattern.matches(".*不.*", asrResult) + || Pattern.matches("退出", asrResult) + || Pattern.matches("否定", asrResult) + || Pattern.matches(".*no.*", asrResult) + || Pattern.matches("否定", asrResult) + || Pattern.matches("i'm really want to but.*", asrResult) + || Pattern.matches("我还有其他事", asrResult) + || Pattern.matches("让我休息一下", asrResult) + || Pattern.matches("我累了", asrResult) + || Pattern.matches("改天吧", asrResult) + || Pattern.matches("错", asrResult) + || Pattern.matches("i'm not sure", asrResult) + || Pattern.matches("never", asrResult) + || Pattern.matches("none", asrResult) + || Pattern.matches("can't", asrResult) + || Pattern.matches("be a let down", asrResult) + || Pattern.matches("turn .* down", asrResult)) { + unisoundTtsEngine.playTts("请小朋友你自己设置吧!"); + STATUS++; + Intent myIntent = new Intent(context, UserInformationSet.class); + startActivity(myIntent); + } else if (Pattern.matches(".*是.*", asrResult)) { + unisoundTtsEngine.playTts("好的," + UserName + "小朋友!"); + STATUS++; + Intent myIntent = new Intent(context, LauncherActivity.class); + startActivity(myIntent); + } + } + } catch (Exception e) { + SdkLogMgr.d(TAG, "error:" + e.toString()); } - } catch (Exception e) { - unisoundAsrEngine.startWakeUp(); + unisoundAsrEngine.startAsr(false); + } + if (event == AsrEvent.ASR_EVENT_WAKEUP_RESULT) { unisoundAsrEngine.startAsr(false); } } - } - @Override - public void onEvent(int event) { - - } + @Override + public void onEvent(int event) { + Log.d(TAG, "onEvent:" + event); + if (event == AsrEvent.ASR_EVENT_VAD_SPEECH_END) { + VoicePresenter.getInstance().getUnisoundAsrEngine().stopAsr(false); + } + } - @Override - public void onError(int error) { - unisoundAsrEngine.startWakeUp(); - } + @Override + public void onError(int error) { + Log.d(TAG, "onError:" + error); + } - @Override - public void onSessionId(String sessionId) { + @Override + public void onSessionId(String s) { - } + } + }; } diff --git a/app/src/main/res/layout/activity_splash.xml b/app/src/main/res/layout/activity_splash.xml index 37ada5248a2f4166e9728721d3771c9911056f63..2ff521129a6276de23bcada6c3a81a8455f20dab 100644 --- a/app/src/main/res/layout/activity_splash.xml +++ b/app/src/main/res/layout/activity_splash.xml @@ -9,4 +9,11 @@ android:background="@drawable/splash" android:id="@+id/SplashMe"> +