2021-02-08 10:34:29 +08:00
|
|
|
|
package chaoran.business.activity;
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
2024-05-29 14:06:56 +08:00
|
|
|
|
import android.app.Activity;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
import android.content.SharedPreferences;
|
2022-11-01 11:28:44 +08:00
|
|
|
|
import android.content.pm.ActivityInfo;
|
2024-11-14 16:05:54 +08:00
|
|
|
|
import android.content.res.AssetManager;
|
2022-11-02 09:32:52 +08:00
|
|
|
|
import android.content.res.Configuration;
|
2021-02-09 17:31:40 +08:00
|
|
|
|
import android.graphics.Bitmap;
|
2024-05-29 14:06:56 +08:00
|
|
|
|
import android.hardware.Sensor;
|
|
|
|
|
|
import android.hardware.SensorEvent;
|
|
|
|
|
|
import android.hardware.SensorEventListener;
|
2022-11-01 11:28:44 +08:00
|
|
|
|
import android.hardware.SensorManager;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
import android.media.MediaPlayer;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
import android.os.Bundle;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
import android.os.Vibrator;
|
2024-11-14 16:05:54 +08:00
|
|
|
|
import android.util.JsonReader;
|
2021-05-27 18:14:01 +08:00
|
|
|
|
import android.util.Log;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
import android.view.Menu;
|
|
|
|
|
|
import android.view.MenuItem;
|
2022-11-01 11:28:44 +08:00
|
|
|
|
import android.view.OrientationEventListener;
|
2024-05-29 14:06:56 +08:00
|
|
|
|
import android.view.Surface;
|
2021-02-09 17:31:40 +08:00
|
|
|
|
import android.view.View;
|
2024-05-29 14:06:56 +08:00
|
|
|
|
import android.view.WindowManager;
|
2021-02-09 17:31:40 +08:00
|
|
|
|
import android.webkit.*;
|
|
|
|
|
|
import android.widget.ProgressBar;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
2021-02-19 14:09:07 +08:00
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
|
2024-05-29 14:06:56 +08:00
|
|
|
|
import com.google.gson.Gson;
|
2024-11-14 16:05:54 +08:00
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
2024-05-29 14:06:56 +08:00
|
|
|
|
|
2024-11-14 16:05:54 +08:00
|
|
|
|
import java.io.BufferedReader;
|
2022-11-07 14:32:46 +08:00
|
|
|
|
import java.io.IOException;
|
2024-11-14 16:05:54 +08:00
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
import java.util.HashMap;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
import chaoran.business.BrandEnum;
|
|
|
|
|
|
import chaoran.business.R;
|
|
|
|
|
|
import chaoran.business.adapter.*;
|
2024-11-14 16:05:54 +08:00
|
|
|
|
import chaoran.business.engine.entity.NetworkSetting;
|
2021-02-20 13:58:47 +08:00
|
|
|
|
import chaoran.business.engine.impl.NetworkSettingEngine;
|
2021-02-19 14:09:07 +08:00
|
|
|
|
import chaoran.business.engine.SettingEngine;
|
2021-02-20 13:58:47 +08:00
|
|
|
|
import chaoran.business.engine.impl.TekVoiceEngine;
|
2021-02-19 14:09:07 +08:00
|
|
|
|
import chaoran.business.engine.VoiceEngine;
|
2023-04-10 10:51:36 +08:00
|
|
|
|
import chaoran.business.service.ScanServiceEDA50P;
|
|
|
|
|
|
import chaoran.business.service.ScanServiceZEBRA;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
import chaoran.business.utils.LocalAddressUtil;
|
2022-10-31 11:51:27 +08:00
|
|
|
|
import chaoran.business.utils.StatusBarUtil;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 流程:联网认证设备型号,验证通过,查找设备品牌进行调用驱动操作
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 提供文字转语音功能,实时播报PDA状态
|
|
|
|
|
|
*/
|
2021-05-27 18:14:01 +08:00
|
|
|
|
public class MainActivity extends AppCompatActivity implements ResultListener{
|
2021-02-08 10:34:29 +08:00
|
|
|
|
|
2024-05-29 14:06:56 +08:00
|
|
|
|
public static int SCREEN_ROTATION = 3; // 屏幕旋转的设置
|
2024-08-04 18:03:08 +08:00
|
|
|
|
public static int hideBar = 0; // 屏幕旋转的设置
|
2024-05-29 14:06:56 +08:00
|
|
|
|
|
|
|
|
|
|
MyOrientationDetector myOrientationDetector;
|
|
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
private WebView webView;
|
|
|
|
|
|
private Adapter adapter;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
private VoiceEngine voiceEngine;
|
2021-02-19 14:09:07 +08:00
|
|
|
|
private SettingEngine settingEngine;
|
2021-02-09 17:31:40 +08:00
|
|
|
|
private ProgressBar progressBar;
|
2021-02-19 14:09:07 +08:00
|
|
|
|
private ActionBar actionBar;
|
|
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
initView();
|
|
|
|
|
|
initData();
|
2022-11-04 13:46:57 +08:00
|
|
|
|
//SCREEN_ORIENTATION_USER,不能旋转180,0、90、270都可以旋转
|
|
|
|
|
|
//SCREEN_ORIENTATION_FULL_SENSOR 都可以旋转,但是在不打开旋转的情况下,一样可以旋转
|
|
|
|
|
|
//SCREEN_ORIENTATION_FULL_USER 关闭旋转则不会旋转了
|
|
|
|
|
|
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
|
2024-05-29 14:06:56 +08:00
|
|
|
|
myOrientationDetector = new MyOrientationDetector(this, this);
|
|
|
|
|
|
myOrientationDetector.enable();
|
2021-05-27 18:14:01 +08:00
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-14 16:05:54 +08:00
|
|
|
|
public static String readInitFile(Context context) {
|
|
|
|
|
|
StringBuffer init = new StringBuffer();
|
|
|
|
|
|
try {
|
|
|
|
|
|
AssetManager assetManager = context.getAssets();
|
|
|
|
|
|
// 打开文件输入流
|
|
|
|
|
|
InputStream inputStream = assetManager.open("init.json");
|
|
|
|
|
|
// 使用BufferedReader进行逐行读取
|
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
|
|
String line;
|
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
|
init.append(line);
|
|
|
|
|
|
}
|
|
|
|
|
|
reader.close();
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
Log.e("AssetError", "Failed to read asset file: init.json", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
return init.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
private void initData() {
|
|
|
|
|
|
BrandEnum brand = BrandEnum.code(Build.MANUFACTURER);
|
|
|
|
|
|
Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show();
|
2021-05-27 18:14:01 +08:00
|
|
|
|
Log.i("brand===",brand.toString());
|
2023-04-10 10:51:36 +08:00
|
|
|
|
switch (brand) {
|
2021-02-08 10:34:29 +08:00
|
|
|
|
case UROBO:
|
|
|
|
|
|
adapter = new UroBoAdapter(this, this);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ROCKCHIP:
|
|
|
|
|
|
adapter = new RockChipAdapter(this, this);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case IDATA:
|
|
|
|
|
|
adapter = new IDataAdapter(this, this);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ALPS:
|
|
|
|
|
|
adapter = new AlpsAdapter(this, this);
|
|
|
|
|
|
break;
|
2023-07-11 12:01:43 +08:00
|
|
|
|
case SEUIC:
|
|
|
|
|
|
adapter = new SeuicAdapter(this, this);
|
|
|
|
|
|
break;
|
2023-04-10 16:17:49 +08:00
|
|
|
|
case HONEY_WELL_EDA50P:
|
2023-06-13 14:01:07 +08:00
|
|
|
|
// 51、56都是同一个code
|
2023-04-10 16:17:49 +08:00
|
|
|
|
case HONEY_WELL_EDA51:
|
2024-05-07 14:51:31 +08:00
|
|
|
|
if (
|
|
|
|
|
|
"eda50p".equals(Build.MODEL.toLowerCase())
|
|
|
|
|
|
|| "eda51".equals(Build.MODEL.toLowerCase())
|
|
|
|
|
|
|| "tc26".equals(Build.MODEL.toLowerCase())
|
|
|
|
|
|
) {
|
|
|
|
|
|
// 走服务模式
|
2023-06-13 14:01:07 +08:00
|
|
|
|
adapter = new HoneywellAdapter(this, this);
|
2024-05-07 14:51:31 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
// 走广播模式
|
|
|
|
|
|
adapter = new HoneywellEda56Adapter(this, this);
|
2023-06-13 14:01:07 +08:00
|
|
|
|
}
|
2023-04-10 15:37:18 +08:00
|
|
|
|
break;
|
2023-04-21 15:03:30 +08:00
|
|
|
|
case ZEBRA_TECHNOLOGIES:
|
|
|
|
|
|
adapter = new ZebraAdapter(this, this);
|
2024-04-07 16:41:32 +08:00
|
|
|
|
break;
|
2023-06-12 17:52:13 +08:00
|
|
|
|
case HISENSE:
|
|
|
|
|
|
adapter = new HisenseAdapter(this, this);
|
2024-04-07 16:41:32 +08:00
|
|
|
|
break;
|
2023-08-21 13:35:56 +08:00
|
|
|
|
case LACHESIS:
|
|
|
|
|
|
adapter = new LachesisAdapter(this, this);
|
2024-04-07 16:41:32 +08:00
|
|
|
|
break;
|
2023-09-01 09:51:56 +08:00
|
|
|
|
case UROVO:
|
|
|
|
|
|
adapter = new UrovoAdapter(this, this);
|
2024-04-07 16:41:32 +08:00
|
|
|
|
break;
|
2024-03-11 13:53:23 +08:00
|
|
|
|
case HKWS:
|
|
|
|
|
|
adapter = new HkwsAdapter(this, this);
|
2024-04-07 16:41:32 +08:00
|
|
|
|
break;
|
2024-06-06 16:50:49 +08:00
|
|
|
|
case NEW_LAND:
|
|
|
|
|
|
adapter = new NewlandAdapter(this, this);
|
|
|
|
|
|
break;
|
2024-12-31 14:02:52 +08:00
|
|
|
|
case IOT_DEVICE:
|
|
|
|
|
|
adapter = new IOT_DeviceAdapter(this, this);
|
|
|
|
|
|
break;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (null != adapter) {
|
|
|
|
|
|
adapter.start();
|
2023-04-10 10:51:36 +08:00
|
|
|
|
}
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
@SuppressLint("JavascriptInterface")
|
|
|
|
|
|
private void initView() {
|
2021-02-19 14:09:07 +08:00
|
|
|
|
actionBar = getSupportActionBar();
|
2022-10-20 14:12:18 +08:00
|
|
|
|
voiceEngine = new TekVoiceEngine(this);
|
2021-02-19 14:09:07 +08:00
|
|
|
|
settingEngine = new NetworkSettingEngine(this);
|
2021-02-08 10:34:29 +08:00
|
|
|
|
webView = findViewById(R.id.webView);
|
2021-02-09 17:31:40 +08:00
|
|
|
|
progressBar = findViewById(R.id.loading);
|
|
|
|
|
|
webView.setWebViewClient(disposeView());
|
2021-02-08 10:34:29 +08:00
|
|
|
|
WebSettings settings = webView.getSettings();
|
|
|
|
|
|
settings.setJavaScriptEnabled(true);
|
2022-10-31 11:51:27 +08:00
|
|
|
|
|
2024-08-04 18:03:08 +08:00
|
|
|
|
|
2022-10-31 11:51:27 +08:00
|
|
|
|
|
2021-02-19 14:09:07 +08:00
|
|
|
|
//设置接口进行windows暴露
|
2021-02-09 17:31:40 +08:00
|
|
|
|
settings.setDomStorageEnabled(true);
|
2021-02-19 14:09:07 +08:00
|
|
|
|
//语音引擎
|
2022-10-20 14:12:18 +08:00
|
|
|
|
webView.addJavascriptInterface(voiceEngine, "TekVoiceEngine");
|
2021-02-19 14:09:07 +08:00
|
|
|
|
//网络设置展示
|
|
|
|
|
|
webView.addJavascriptInterface(settingEngine, "NetworkSettingEngine");
|
|
|
|
|
|
//重新加载页面
|
|
|
|
|
|
webView.addJavascriptInterface(this, "View");
|
2022-11-01 11:28:44 +08:00
|
|
|
|
webView.addJavascriptInterface(new LocalAddressUtil(this, this, webView), "Localpda");
|
2021-02-08 10:34:29 +08:00
|
|
|
|
webView.loadUrl(url());
|
2024-08-04 18:03:08 +08:00
|
|
|
|
// StatusBarUtil.transparencyBar( this); // 设置全部透明,需要在页面设置一个参数进行布局的样式跳转,不同的手机端,状态栏高度不一样(apk设置状态栏高度无效,这个是安卓9的一个bug),所以在此采取隐藏状态栏
|
|
|
|
|
|
if (hideBar == 1) {
|
|
|
|
|
|
StatusBarUtil.hideStatusBar( this); // 设置全部透明
|
|
|
|
|
|
}
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-09 17:31:40 +08:00
|
|
|
|
//配置客户端
|
|
|
|
|
|
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) {
|
2021-02-19 14:09:07 +08:00
|
|
|
|
if (!url.startsWith("file"))
|
|
|
|
|
|
actionBar.hide();
|
|
|
|
|
|
else
|
|
|
|
|
|
actionBar.show();
|
2021-02-09 17:31:40 +08:00
|
|
|
|
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");
|
|
|
|
|
|
}
|
2021-02-19 14:09:07 +08:00
|
|
|
|
actionBar.show();
|
|
|
|
|
|
actionBar.setTitle(R.string.title_activity_main);
|
2021-02-09 17:31:40 +08:00
|
|
|
|
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");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-02-19 14:09:07 +08:00
|
|
|
|
actionBar.show();
|
|
|
|
|
|
actionBar.setTitle(R.string.title_activity_main);
|
2021-02-09 17:31:40 +08:00
|
|
|
|
super.onReceivedError(view, request, error);
|
|
|
|
|
|
progressBar.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
|
//再次唤醒该页面时,重新加载页面和语音配置
|
2021-05-27 18:14:01 +08:00
|
|
|
|
//webView.loadUrl(url());
|
|
|
|
|
|
// voiceEngine.reload();
|
2021-02-08 10:34:29 +08:00
|
|
|
|
super.onResume();
|
2023-08-21 13:35:56 +08:00
|
|
|
|
if (adapter != null) {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
myOrientationDetector.disable();
|
2024-01-11 17:27:22 +08:00
|
|
|
|
adapter.stop2();
|
2023-08-21 13:35:56 +08:00
|
|
|
|
adapter.start();
|
|
|
|
|
|
}
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
@SuppressLint("SetJavaScriptEnabled")
|
|
|
|
|
|
public void result(String result) {
|
|
|
|
|
|
runOnUiThread(() -> webView.loadUrl("javascript:render(\'" + result + "\')"));
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void onDestroy() {
|
2023-08-21 13:35:56 +08:00
|
|
|
|
if (adapter != null) {
|
|
|
|
|
|
adapter.stop();
|
|
|
|
|
|
}
|
2021-02-08 10:34:29 +08:00
|
|
|
|
super.onDestroy();
|
2022-10-20 14:12:18 +08:00
|
|
|
|
if (diPlayer != null) {
|
|
|
|
|
|
diPlayer.stop();
|
|
|
|
|
|
diPlayer.release();
|
|
|
|
|
|
diPlayer = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (duPlayer != null) {
|
|
|
|
|
|
duPlayer.stop();
|
|
|
|
|
|
duPlayer.release();
|
|
|
|
|
|
duPlayer = null;
|
|
|
|
|
|
}
|
2022-11-07 14:32:46 +08:00
|
|
|
|
if (dingPlayer != null) {
|
|
|
|
|
|
dingPlayer.stop();
|
|
|
|
|
|
dingPlayer.release();
|
|
|
|
|
|
dingPlayer = null;
|
|
|
|
|
|
}
|
2022-10-20 14:12:18 +08:00
|
|
|
|
if (vibrator != null) {
|
|
|
|
|
|
vibrator.cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
completionListener = null;
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
|
case R.id.action_setting_network:
|
|
|
|
|
|
startActivity(new Intent(this, NetworkSettingActivity.class));
|
|
|
|
|
|
break;
|
|
|
|
|
|
case R.id.action_setting_voice:
|
|
|
|
|
|
startActivity(new Intent(this, VoiceSettingActivity.class));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-19 14:09:07 +08:00
|
|
|
|
//拼接url
|
2021-02-08 10:34:29 +08:00
|
|
|
|
private String url() {
|
|
|
|
|
|
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
2021-02-09 17:31:40 +08:00
|
|
|
|
Integer port = spf.getInt("port", -1);
|
2024-11-14 16:05:54 +08:00
|
|
|
|
Map<String, Object> map = null;
|
2021-02-09 17:31:40 +08:00
|
|
|
|
if (port == -1) {
|
2024-11-14 16:05:54 +08:00
|
|
|
|
try {
|
|
|
|
|
|
// String init = readInitFile(this);
|
|
|
|
|
|
String init = null;
|
|
|
|
|
|
if (init != null && init.length() > 0) {
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
map = gson.fromJson(init, new TypeToken<Map<String, Object>>(){}.getType());
|
|
|
|
|
|
// 说明采取了配置,并且存在ip才认为是一个合法的json配置
|
|
|
|
|
|
if (map.containsKey("ip") && map.get("ip").toString().length() > 0) {
|
|
|
|
|
|
NetworkSetting initData = new NetworkSetting();
|
|
|
|
|
|
initData.setAddress(map.get("ip").toString());
|
|
|
|
|
|
initData.setPort(Integer.parseInt(map.get("port").toString()));
|
|
|
|
|
|
initData.setPath(map.get("path").toString());
|
|
|
|
|
|
initData.setScreen_rotation(Integer.parseInt(map.getOrDefault("screen_rotation", "3").toString()));
|
|
|
|
|
|
initData.setHide_bar(Integer.parseInt(map.getOrDefault("hide_bar", "3").toString()));
|
|
|
|
|
|
settingEngine.saveSetting(initData);
|
|
|
|
|
|
spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
|
|
|
|
|
port = initData.getPort();
|
|
|
|
|
|
}else {
|
|
|
|
|
|
map = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
|
Log.e("MainActivity", "get init file error");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (map == null) {
|
|
|
|
|
|
return "file:///android_asset/demo/index.html";
|
|
|
|
|
|
}
|
2021-02-09 17:31:40 +08:00
|
|
|
|
}
|
2021-02-08 10:34:29 +08:00
|
|
|
|
String address = spf.getString("address", "").replaceAll(" ", "");
|
|
|
|
|
|
String path = spf.getString("path", "").replaceAll(" ", "");
|
|
|
|
|
|
String link = address.concat(":").concat(String.valueOf(port)).concat(path);
|
2024-05-29 14:06:56 +08:00
|
|
|
|
SCREEN_ROTATION = spf.getInt("screen_rotation", 3);
|
2024-08-04 18:03:08 +08:00
|
|
|
|
hideBar = spf.getInt("hide_bar", 3);
|
2021-02-08 10:34:29 +08:00
|
|
|
|
return link.startsWith("http://") ? link : "http://".concat(link);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-19 14:09:07 +08:00
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public void reload() {
|
|
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
|
|
webView.loadUrl(url());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-10-20 14:12:18 +08:00
|
|
|
|
private MediaPlayer diPlayer = null;
|
|
|
|
|
|
private MediaPlayer duPlayer = null;
|
2022-11-07 14:32:46 +08:00
|
|
|
|
private MediaPlayer dingPlayer = null;
|
2022-10-20 14:12:18 +08:00
|
|
|
|
private String ttsNr;
|
|
|
|
|
|
public Vibrator vibrator;
|
|
|
|
|
|
|
|
|
|
|
|
@JavascriptInterface
|
2022-11-07 14:32:46 +08:00
|
|
|
|
public void play(String msg, String type, int isZd) throws IOException {
|
2022-10-20 14:12:18 +08:00
|
|
|
|
ttsNr = msg;
|
|
|
|
|
|
if ("1".equals(type)) {
|
2022-11-07 14:32:46 +08:00
|
|
|
|
if (diPlayer == null) {
|
|
|
|
|
|
diPlayer = MediaPlayer.create(this, R.raw.didi);
|
|
|
|
|
|
diPlayer.setOnCompletionListener(completionListener);
|
|
|
|
|
|
}
|
2022-10-20 14:12:18 +08:00
|
|
|
|
diPlayer.start();
|
|
|
|
|
|
} else if ("2".equals(type)) {
|
2022-11-07 14:32:46 +08:00
|
|
|
|
if (duPlayer == null) {
|
|
|
|
|
|
duPlayer = MediaPlayer.create(this, R.raw.dudu);
|
|
|
|
|
|
duPlayer.setOnCompletionListener(completionListener);
|
|
|
|
|
|
}
|
2022-11-03 17:24:16 +08:00
|
|
|
|
duPlayer.start();
|
|
|
|
|
|
} else if ("10".equals(type)) {
|
2022-11-07 14:32:46 +08:00
|
|
|
|
if (dingPlayer == null) {
|
|
|
|
|
|
dingPlayer = MediaPlayer.create(this, R.raw.ding);
|
|
|
|
|
|
dingPlayer.setOnCompletionListener(completionListener);
|
|
|
|
|
|
}
|
|
|
|
|
|
dingPlayer.start();
|
2022-10-20 14:12:18 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
//isZd = 1;
|
|
|
|
|
|
if (voiceEngine != null) {
|
|
|
|
|
|
voiceEngine.startSpeaking(msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isZd == 1) {
|
|
|
|
|
|
if (vibrator == null) {
|
|
|
|
|
|
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
|
|
|
}
|
|
|
|
|
|
vibrator.vibrate(2000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-07 14:32:46 +08:00
|
|
|
|
|
2022-10-20 14:12:18 +08:00
|
|
|
|
private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() {
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
public void onCompletion(MediaPlayer mp) {
|
|
|
|
|
|
if (ttsNr != null) {
|
|
|
|
|
|
if (voiceEngine != null) {
|
|
|
|
|
|
voiceEngine.startSpeaking(ttsNr);
|
|
|
|
|
|
}
|
|
|
|
|
|
ttsNr = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2022-10-31 11:51:27 +08:00
|
|
|
|
|
2024-01-09 11:47:38 +08:00
|
|
|
|
@SuppressLint("JavascriptInterface")
|
|
|
|
|
|
@JavascriptInterface
|
|
|
|
|
|
public void openIndex() throws IOException {
|
|
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
|
|
webView.loadUrl("file:///android_asset/demo/index.html");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-11-02 09:32:52 +08:00
|
|
|
|
|
2024-05-29 14:06:56 +08:00
|
|
|
|
/* 监听角度的变化 */
|
2022-11-02 09:32:52 +08:00
|
|
|
|
class MyOrientationDetector extends OrientationEventListener {
|
|
|
|
|
|
|
|
|
|
|
|
private int rotate;
|
|
|
|
|
|
|
2024-05-29 14:06:56 +08:00
|
|
|
|
private Activity activity;
|
|
|
|
|
|
|
|
|
|
|
|
public MyOrientationDetector(Context context, Activity activity) {
|
2022-11-02 09:32:52 +08:00
|
|
|
|
super(context);
|
2024-05-29 14:06:56 +08:00
|
|
|
|
this.activity = activity;
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onOrientationChanged(int orientation) {
|
|
|
|
|
|
//假设屏幕旋转被打开。则设置屏幕可旋转
|
|
|
|
|
|
//0-57度 125-236度 306-360度 这些区间范围内为竖屏
|
|
|
|
|
|
//58-124度 237-305度 这些区间范围内为横屏
|
|
|
|
|
|
if (orientation >=0 && orientation <= 57 ) {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}else if (orientation >=125 && orientation <= 236 ) {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; // 倒竖屏
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}else if (orientation >=306 && orientation <= 360 ) {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}else if (orientation >=58 && orientation <= 124 ) {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; // 正横屏
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}else if (orientation >=237 && orientation <= 305 ) {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
rotate = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 倒横屏
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}else {
|
2024-05-29 14:06:56 +08:00
|
|
|
|
rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 默认正竖屏
|
|
|
|
|
|
}
|
|
|
|
|
|
if (SCREEN_ROTATION == 1 || SCREEN_ROTATION == 3) {
|
|
|
|
|
|
if (rotate == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
|
|
|
|
|
|
activity.setRequestedOrientation(rotate);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (SCREEN_ROTATION == 2 || SCREEN_ROTATION == 3) {
|
|
|
|
|
|
if (rotate == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
|
|
|
|
|
activity.setRequestedOrientation(rotate);
|
|
|
|
|
|
}
|
2022-11-02 09:32:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 14:06:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("WrongConstant")
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-08 10:34:29 +08:00
|
|
|
|
}
|