提交 ac39f44b 编写于 作者: 东方怂天's avatar 东方怂天

优化了启动速度,增加了新页面。

上级 cf0ad4cd
......@@ -22,11 +22,13 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="cn.EasertnDay.HuaZai.UserRegesite"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.SplashActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
......@@ -37,7 +39,8 @@
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.UserInformationSet"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
</activity>
<activity android:name="cn.easternday.huazai.InformationService">
</activity>
......@@ -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">
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.SecondaryPage.GJX"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.SecondaryPage.ZXXL"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.SecondaryPage.KWTBX"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.LauncherActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="singleTask">
</activity>
<activity android:name="cn.EasertnDay.HuaZai.HuaZaiActivity">
android:launchMode="singleTask"
</activity>
<activity
android:name="cn.EasertnDay.HuaZai.BasicMainActivity"
......
......@@ -78,6 +78,18 @@ public class LauncherActivity extends AppCompatActivity {
wifiInfo = wifiManager.getConnectionInfo();//WIFI信息
WifiIcon = findViewById(R.id.wifiIcon);//WIFI图标
//悬浮窗
if (Build.VERSION.SDK_INT >= 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));
}
}
}
}
......@@ -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);
}
}
}
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) {
}
}
};
}
......@@ -9,4 +9,11 @@
android:background="@drawable/splash"
android:id="@+id/SplashMe">
<Button
android:text="跳过"
android:onClick="OnClick"
android:layout_width="150dp"
android:layout_height="75dp" android:id="@+id/Skip_Button"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="50dp" android:layout_marginEnd="100dp"/>
</android.support.constraint.ConstraintLayout>
......@@ -7,11 +7,19 @@
android:layout_height="match_parent"
tools:context="cn.EasertnDay.HuaZai.UserRegesite"
android:background="@drawable/main_background">
<TextView android:layout_width="1000px" android:layout_height="200px" android:gravity="center"
android:background="@drawable/img_dikuang"
<TextView android:layout_width="500px" android:layout_height="200px" android:gravity="center"
android:background="@drawable/img_duihuakuang"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="50dp"
android:text="测试" android:textSize="35dp" android:textColor="@color/colorPrimaryDark"
android:id="@+id/RegisterMessage"/>
app:layout_constraintTop_toTopOf="parent"
android:text="" android:textSize="35dp" android:textColor="@color/colorPrimaryDark"
android:id="@+id/RegisterMessage" app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:layout_width="400dp"
android:layout_height="400dp" app:srcCompat="@drawable/huazai" android:id="@+id/FuckingShow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.8" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5"/>
</android.support.constraint.ConstraintLayout>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册