Merge branch 'master' of http://chaoran.crtech.cn:3000/PDA/pda-web
This commit is contained in:
@ -3,9 +3,12 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="chaoran.business">
|
package="chaoran.business">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|||||||
12
app/src/main/assets/demo/index.html
Normal file
12
app/src/main/assets/demo/index.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<html lang="zh-CN">
|
||||||
|
<p id='p'>hello world</p>
|
||||||
|
<button onclick="VoiceEngine.startSpeaking('js调用安卓方法!')">调用安卓方法</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function render(result){
|
||||||
|
result+="<br/>"
|
||||||
|
document.getElementById("p").innerHTML += result
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
5
app/src/main/assets/error/404.html
Normal file
5
app/src/main/assets/error/404.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<html lang="zh-CN">
|
||||||
|
<body>
|
||||||
|
<p>未找到资源,访问路径错误!</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
5
app/src/main/assets/error/500.html
Normal file
5
app/src/main/assets/error/500.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<html lang="zh-CN">
|
||||||
|
<body>
|
||||||
|
<p>服务器内部发生严重错误!</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
5
app/src/main/assets/error/index.html
Normal file
5
app/src/main/assets/error/index.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<html lang="zh-CN">
|
||||||
|
<body>
|
||||||
|
<p>发生未知错误,请联系管理员</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -20,7 +20,8 @@ public class AboutActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_about);
|
setContentView(R.layout.activity_about);
|
||||||
setTitle(R.string.activity_about);
|
//隐藏状态栏
|
||||||
|
getSupportActionBar().hide();
|
||||||
TextView textView = findViewById(R.id.about_content);
|
TextView textView = findViewById(R.id.about_content);
|
||||||
textView.setText(R.string.activity_about_content);
|
textView.setText(R.string.activity_about_content);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,14 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.webkit.WebSettings;
|
import android.view.View;
|
||||||
import android.webkit.WebView;
|
import android.webkit.*;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -32,6 +34,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
|||||||
private WebView webView;
|
private WebView webView;
|
||||||
private Adapter adapter;
|
private Adapter adapter;
|
||||||
private VoiceEngine voiceEngine;
|
private VoiceEngine voiceEngine;
|
||||||
|
private ProgressBar progressBar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -65,15 +68,75 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
|||||||
|
|
||||||
@SuppressLint("JavascriptInterface")
|
@SuppressLint("JavascriptInterface")
|
||||||
private void initView() {
|
private void initView() {
|
||||||
setTitle(R.string.title_activity_main);
|
//隐藏状态栏
|
||||||
|
getSupportActionBar().hide();
|
||||||
voiceEngine = new TekVoiceEngine(this);
|
voiceEngine = new TekVoiceEngine(this);
|
||||||
webView = findViewById(R.id.webView);
|
webView = findViewById(R.id.webView);
|
||||||
|
progressBar = findViewById(R.id.loading);
|
||||||
|
webView.setWebViewClient(disposeView());
|
||||||
WebSettings settings = webView.getSettings();
|
WebSettings settings = webView.getSettings();
|
||||||
settings.setJavaScriptEnabled(true);
|
settings.setJavaScriptEnabled(true);
|
||||||
|
settings.setDomStorageEnabled(true);
|
||||||
webView.addJavascriptInterface(voiceEngine, "VoiceEngine");
|
webView.addJavascriptInterface(voiceEngine, "VoiceEngine");
|
||||||
webView.loadUrl(url());
|
webView.loadUrl(url());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//配置客户端
|
||||||
|
private WebViewClient disposeView() {
|
||||||
|
return new WebViewClient() {
|
||||||
|
//页面开始加载时
|
||||||
|
@Override
|
||||||
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||||
|
super.onPageStarted(view, url, favicon);
|
||||||
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//页面加载完成时
|
||||||
|
@Override
|
||||||
|
public void onPageFinished(WebView view, String url) {
|
||||||
|
super.onPageFinished(view, url);
|
||||||
|
progressBar.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//网络发生错误时,先展示错误界面,然后关闭加载条
|
||||||
|
@Override
|
||||||
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||||
|
switch (errorCode) {
|
||||||
|
case 404:
|
||||||
|
webView.loadUrl("file:///android_asset/error/404.html");
|
||||||
|
break;
|
||||||
|
case 500:
|
||||||
|
webView.loadUrl("file:///android_asset/error/500.html");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
webView.loadUrl("file:///android_asset/error/index.html");
|
||||||
|
}
|
||||||
|
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||||
|
progressBar.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//安卓6.0以上发生错误时回调
|
||||||
|
@Override
|
||||||
|
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
switch (error.getErrorCode()) {
|
||||||
|
case 404:
|
||||||
|
webView.loadUrl("file:///android_asset/error/404.html");
|
||||||
|
break;
|
||||||
|
case 500:
|
||||||
|
webView.loadUrl("file:///android_asset/error/500.html");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
webView.loadUrl("file:///android_asset/error/index.html");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onReceivedError(view, request, error);
|
||||||
|
progressBar.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
//再次唤醒该页面时,重新加载页面和语音配置
|
//再次唤醒该页面时,重新加载页面和语音配置
|
||||||
@ -118,9 +181,12 @@ public class MainActivity extends AppCompatActivity implements ResultListener {
|
|||||||
|
|
||||||
private String url() {
|
private String url() {
|
||||||
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||||
|
Integer port = spf.getInt("port", -1);
|
||||||
|
if (port == -1) {
|
||||||
|
return "file:///android_asset/demo/index.html";
|
||||||
|
}
|
||||||
String address = spf.getString("address", "").replaceAll(" ", "");
|
String address = spf.getString("address", "").replaceAll(" ", "");
|
||||||
String path = spf.getString("path", "").replaceAll(" ", "");
|
String path = spf.getString("path", "").replaceAll(" ", "");
|
||||||
Integer port = spf.getInt("port", -1);
|
|
||||||
String link = address.concat(":").concat(String.valueOf(port)).concat(path);
|
String link = address.concat(":").concat(String.valueOf(port)).concat(path);
|
||||||
return link.startsWith("http://") ? link : "http://".concat(link);
|
return link.startsWith("http://") ? link : "http://".concat(link);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,12 +31,13 @@ public class NetworkSettingActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
|
|
||||||
private void initView() {
|
private void initView() {
|
||||||
|
//隐藏状态栏
|
||||||
|
getSupportActionBar().hide();
|
||||||
address = findViewById(R.id.address);
|
address = findViewById(R.id.address);
|
||||||
path = findViewById(R.id.path);
|
path = findViewById(R.id.path);
|
||||||
port = findViewById(R.id.port);
|
port = findViewById(R.id.port);
|
||||||
save = findViewById(R.id.save);
|
save = findViewById(R.id.save);
|
||||||
cancel = findViewById(R.id.cancel);
|
cancel = findViewById(R.id.cancel);
|
||||||
setTitle(R.string.title_activity_setting_network);
|
|
||||||
SharedPreferences sharedPreferences = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
SharedPreferences sharedPreferences = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||||
address.setText(sharedPreferences.getString("address", ""));
|
address.setText(sharedPreferences.getString("address", ""));
|
||||||
path.setText(sharedPreferences.getString("path", ""));
|
path.setText(sharedPreferences.getString("path", ""));
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import android.app.Activity;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import chaoran.business.R;
|
import chaoran.business.R;
|
||||||
import chaoran.business.vioce.TekVoiceEngine;
|
import chaoran.business.vioce.TekVoiceEngine;
|
||||||
import chaoran.business.vioce.VoiceEngine;
|
import chaoran.business.vioce.VoiceEngine;
|
||||||
@ -19,7 +20,7 @@ import chaoran.business.vioce.VoiceEngine;
|
|||||||
/**
|
/**
|
||||||
* 播报语音设置
|
* 播报语音设置
|
||||||
*/
|
*/
|
||||||
public class VoiceSettingActivity extends Activity {
|
public class VoiceSettingActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private EditText testText;
|
private EditText testText;
|
||||||
private RadioButton voiceF, voiceY;
|
private RadioButton voiceF, voiceY;
|
||||||
@ -40,6 +41,8 @@ public class VoiceSettingActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initView() {
|
private void initView() {
|
||||||
|
//隐藏状态栏
|
||||||
|
getSupportActionBar().hide();
|
||||||
testText = findViewById(R.id.voice_test_text);
|
testText = findViewById(R.id.voice_test_text);
|
||||||
voiceF = findViewById(R.id.voice_member_xiaofeng);
|
voiceF = findViewById(R.id.voice_member_xiaofeng);
|
||||||
voiceY = findViewById(R.id.voice_member_xiaoyan);
|
voiceY = findViewById(R.id.voice_member_xiaoyan);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -8,4 +8,11 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/webView" />
|
android:id="@+id/webView" />
|
||||||
|
|
||||||
</LinearLayout>
|
<ProgressBar
|
||||||
|
android:id="@+id/loading"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
Reference in New Issue
Block a user