新增异常处理机制,页面语音设置,网络设置
This commit is contained in:
@ -1,28 +0,0 @@
|
||||
package chaoran.business.activity;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-04 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import chaoran.business.R;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
TextView textView = findViewById(R.id.about_content);
|
||||
textView.setText(R.string.activity_about_content);
|
||||
}
|
||||
}
|
||||
@ -15,12 +15,15 @@ import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import chaoran.business.BrandEnum;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.adapter.*;
|
||||
import chaoran.business.vioce.TekVoiceEngine;
|
||||
import chaoran.business.vioce.VoiceEngine;
|
||||
import chaoran.business.engine.NetworkSettingEngine;
|
||||
import chaoran.business.engine.SettingEngine;
|
||||
import chaoran.business.engine.TekVoiceEngine;
|
||||
import chaoran.business.engine.VoiceEngine;
|
||||
|
||||
/**
|
||||
* 流程:联网认证设备型号,验证通过,查找设备品牌进行调用驱动操作
|
||||
@ -34,7 +37,10 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
private WebView webView;
|
||||
private Adapter adapter;
|
||||
private VoiceEngine voiceEngine;
|
||||
private SettingEngine settingEngine;
|
||||
private ProgressBar progressBar;
|
||||
private ActionBar actionBar;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -68,16 +74,22 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
private void initView() {
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
actionBar = getSupportActionBar();
|
||||
voiceEngine = new TekVoiceEngine(this);
|
||||
settingEngine = new NetworkSettingEngine(this);
|
||||
webView = findViewById(R.id.webView);
|
||||
progressBar = findViewById(R.id.loading);
|
||||
webView.setWebViewClient(disposeView());
|
||||
WebSettings settings = webView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
//设置接口进行windows暴露
|
||||
settings.setDomStorageEnabled(true);
|
||||
webView.addJavascriptInterface(voiceEngine, "VoiceEngine");
|
||||
//语音引擎
|
||||
webView.addJavascriptInterface(voiceEngine, "TekVoiceEngine");
|
||||
//网络设置展示
|
||||
webView.addJavascriptInterface(settingEngine, "NetworkSettingEngine");
|
||||
//重新加载页面
|
||||
webView.addJavascriptInterface(this, "View");
|
||||
webView.loadUrl(url());
|
||||
}
|
||||
|
||||
@ -94,6 +106,10 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
//页面加载完成时
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
if (!url.startsWith("file"))
|
||||
actionBar.hide();
|
||||
else
|
||||
actionBar.show();
|
||||
super.onPageFinished(view, url);
|
||||
progressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@ -111,6 +127,8 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
default:
|
||||
webView.loadUrl("file:///android_asset/error/index.html");
|
||||
}
|
||||
actionBar.show();
|
||||
actionBar.setTitle(R.string.title_activity_main);
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
progressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@ -130,6 +148,8 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
webView.loadUrl("file:///android_asset/error/index.html");
|
||||
}
|
||||
}
|
||||
actionBar.show();
|
||||
actionBar.setTitle(R.string.title_activity_main);
|
||||
super.onReceivedError(view, request, error);
|
||||
progressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@ -172,13 +192,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
case R.id.action_setting_voice:
|
||||
startActivity(new Intent(this, VoiceSettingActivity.class));
|
||||
break;
|
||||
case R.id.action_about:
|
||||
startActivity(new Intent(this, AboutActivity.class));
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//拼接url
|
||||
private String url() {
|
||||
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||
Integer port = spf.getInt("port", -1);
|
||||
@ -191,4 +209,10 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
||||
return link.startsWith("http://") ? link : "http://".concat(link);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void reload() {
|
||||
runOnUiThread(() -> {
|
||||
webView.loadUrl(url());
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -31,8 +31,7 @@ public class NetworkSettingActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private void initView() {
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
setTitle(R.string.title_activity_setting_network);
|
||||
address = findViewById(R.id.address);
|
||||
path = findViewById(R.id.path);
|
||||
port = findViewById(R.id.port);
|
||||
|
||||
@ -8,14 +8,13 @@ package chaoran.business.activity;
|
||||
*/
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.widget.*;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.vioce.TekVoiceEngine;
|
||||
import chaoran.business.vioce.VoiceEngine;
|
||||
import chaoran.business.engine.TekVoiceEngine;
|
||||
import chaoran.business.engine.VoiceEngine;
|
||||
|
||||
/**
|
||||
* 播报语音设置
|
||||
@ -41,8 +40,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
//隐藏状态栏
|
||||
getSupportActionBar().hide();
|
||||
setTitle(R.string.title_activity_setting_voice);
|
||||
testText = findViewById(R.id.voice_test_text);
|
||||
voiceF = findViewById(R.id.voice_member_xiaofeng);
|
||||
voiceY = findViewById(R.id.voice_member_xiaoyan);
|
||||
@ -69,9 +67,9 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
voiceF.setChecked(false);
|
||||
}
|
||||
//设置功能选项
|
||||
voiceSize.setProgress(sharedPreferences.getInt("voiceSize", 100));
|
||||
voiceSpeed.setProgress(sharedPreferences.getInt("voiceSpeed", 80));
|
||||
voiceIndicate.setProgress(sharedPreferences.getInt("voiceIndicate", 50));
|
||||
voiceSize.setProgress(Integer.parseInt(sharedPreferences.getString("voiceSize", "100")));
|
||||
voiceSpeed.setProgress(Integer.parseInt(sharedPreferences.getString("voiceSpeed", "80")));
|
||||
voiceIndicate.setProgress(Integer.parseInt(sharedPreferences.getString("voiceIndicate", "50")));
|
||||
}
|
||||
|
||||
public void initListener() {
|
||||
@ -90,7 +88,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
//播放语音
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", voiceSize.getProgress(), voiceIndicate.getProgress(), voiceSpeed.getProgress());
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", String.valueOf(voiceSize.getProgress()), String.valueOf(voiceIndicate.getProgress()), String.valueOf(voiceSpeed.getProgress()));
|
||||
voiceEngine.startSpeaking(testText.getText().toString());
|
||||
}
|
||||
};
|
||||
@ -99,9 +97,9 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
voiceSpeed.setOnSeekBarChangeListener(seekBarChangeListener);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
save.setOnClickListener(a -> {
|
||||
editor.putInt("voiceSize", voiceSize.getProgress());
|
||||
editor.putInt("voiceIndicate", voiceIndicate.getProgress());
|
||||
editor.putInt("voiceSpeed", voiceSpeed.getProgress());
|
||||
editor.putString("voiceSize", String.valueOf(voiceSize.getProgress()));
|
||||
editor.putString("voiceIndicate", String.valueOf(voiceIndicate.getProgress()));
|
||||
editor.putString("voiceSpeed", String.valueOf(voiceSpeed.getProgress()));
|
||||
editor.putString("testText", testText.getText().toString());
|
||||
editor.putString("voiceMember", voiceF.isChecked() ? "xiaofeng" : "xiaoyan");
|
||||
editor.commit();
|
||||
@ -118,7 +116,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
|
||||
voiceMemberGroup.setOnCheckedChangeListener((a, b) -> {
|
||||
//播放语音
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", voiceSize.getProgress(), voiceIndicate.getProgress(), voiceSpeed.getProgress());
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", String.valueOf(voiceSize.getProgress()), String.valueOf(voiceIndicate.getProgress()), String.valueOf(voiceSpeed.getProgress()));
|
||||
voiceEngine.startSpeaking(testText.getText().toString());
|
||||
});
|
||||
}
|
||||
@ -127,7 +125,7 @@ public class VoiceSettingActivity extends AppCompatActivity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
//初始化加载一次
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", voiceSize.getProgress(), voiceIndicate.getProgress(), voiceSpeed.getProgress());
|
||||
voiceEngine.setParam(voiceF.isChecked() ? "xiaofeng" : "xiaoyan", String.valueOf(voiceSize.getProgress()), String.valueOf(voiceIndicate.getProgress()), String.valueOf(voiceSpeed.getProgress()));
|
||||
voiceEngine.startSpeaking(testText.getText().toString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user