Compare commits
46 Commits
8ce4133e50
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d43980458 | |||
| 0800e0eaf0 | |||
| ce30c6cf7b | |||
| cdc07256ee | |||
| 47715f0fd6 | |||
| 59c228f36c | |||
| 5769b7670b | |||
| 12c928f059 | |||
| 724e691188 | |||
| e24a8955a2 | |||
| ec798944ad | |||
| 57094bfbd4 | |||
| 4af4aac1e5 | |||
| 23df4da1ff | |||
| 5f9b5cd2e5 | |||
| 3e4af1c2d1 | |||
| 2a13c1a886 | |||
| 832b0e3368 | |||
| bcfb6155d2 | |||
| 10fdade4da | |||
| 17a0889e08 | |||
| 483cce8fd5 | |||
| 46199cda0f | |||
| 3bc08317d0 | |||
| 40c330795c | |||
| 0a19e1f587 | |||
| e2a34d76a6 | |||
| 4aa71457fe | |||
| 3613dd6a21 | |||
| 26e9ad63f5 | |||
| 2485332d77 | |||
| 27216aa2af | |||
| 2c72ce04f6 | |||
| f80dd211f1 | |||
| 5199147f58 | |||
| d80325553d | |||
| 0f435a565d | |||
| 0cb5922557 | |||
| d63d7ecee3 | |||
| 6786cf2908 | |||
| a56e76f552 | |||
| 9cad5923d8 | |||
| 6fb1768a1b | |||
| b4e1d2c06f | |||
| f1137bfbf2 | |||
| 4bd42b98d5 |
2
.idea/compiler.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
||||
2
.idea/encodings.xml
generated
@ -7,8 +7,6 @@
|
||||
<file url="file://$PROJECT_DIR$/app/jni/gen_SerialPort_h.sh" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/app/jni/rockchip.c" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/app/libs/armeabi" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/app/libs/armeabi-v7a" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/app/libs/armeabi-v7a/libmsc.so" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/app/libs/armeabi/librockchip.so" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/app/libs/x86" charset="GBK" />
|
||||
<file url="file://$PROJECT_DIR$/app/src/main/java/chaoran/business/adapter/librockchip.so" charset="GBK" />
|
||||
|
||||
2
.idea/misc.xml
generated
@ -10,7 +10,7 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" interpreter_name="PHP-5.6.25" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@ -3,17 +3,44 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
compileSdk 28
|
||||
buildToolsVersion '30.0.3'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "chaoran.business.pda"
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 29
|
||||
minSdk 28
|
||||
targetSdk 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionName "2.4"
|
||||
|
||||
// 1.0 IDATA广播模式处理
|
||||
// 1.1 霍尼韦尔的监听修改(扫描网站二维码跳出程序,监听失效,调整)、斑马PDA广播模式设置
|
||||
// 1.2 霍尼韦尔EDA56、jdk11,gradle7.3、海信PDA广播支持
|
||||
// 1.3 东集 pda的支持
|
||||
// 1.4 联新 pda的支持 已经 adapter 关闭的判断
|
||||
// 1.5 urovo DT50 Lite pda的支持
|
||||
// 1.6 瑞星平板扫描,线程读取一半就返回处理
|
||||
// 1.7 暴露一个方法,跳转到index初始化页面
|
||||
// 1.8 霍尼韦尔EDA50p,在返回桌面,点击了新的扫描之后,出现再进入程序(新打开一样)无法扫描,从而导致问题,添加了一个stop2的方法,针对霍尼韦尔eda50p,不进行销毁,在真正销毁的方法关闭服务,还是存在程序返回桌面无法扫描问题,但是退出程序之后,新打开程序可以扫描
|
||||
// 1.9 海康威视 mv-idp5102 适配广播模式
|
||||
// 1.10 bug 代码判断没有结束
|
||||
// 1.11 霍尼韦尔EDA52
|
||||
// 1.12 屏幕旋转,采取配置化模式(只能竖屏、横屏);取消旋转屏幕就重置activity生命周期
|
||||
// 1.13 新大陆pda 兼容广播模式;NLS-NFT10
|
||||
// 1.14 瑞芯 rk3566_r 添加引用 librockchip.so; 新加一个方法,返回当前PDA的厂家和型号
|
||||
// 1.15 系统状态栏根据配置进行设置
|
||||
// 1.16 idata pda 不设置模式
|
||||
// 1.17 霍尼韦尔EDA51、EDA50P,调用扫描枪的方法,在关闭的时候停止调用扫描枪
|
||||
// 1.18 瑞兴平板,读取扫描结果,使用同步加锁模式
|
||||
// 1.19 index页面接入初始化数据
|
||||
// 2.1 注册PDA的信息存储到文件内部,采取mac+固定加密串的MD5加密校验
|
||||
// 2.2 安卓14以上,无法获取mac地址,修改成获取唯一id作为mac地址
|
||||
// 2.3 适配IOT_Device:sc55g PDA 广播模式
|
||||
// 2.4 适配 qualcomm:mc50 PDA 广播模式
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a'
|
||||
}
|
||||
}
|
||||
|
||||
//签名配置
|
||||
@ -54,12 +81,22 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
/* repositories {
|
||||
flatDir {
|
||||
dirs 'libs'
|
||||
}
|
||||
}*/
|
||||
}
|
||||
dependencies {
|
||||
compileOnly 'com.symbol:emdk:9.1.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'com.google.code.gson:gson:2.6.2'
|
||||
//加载jar包
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
//implementation fileTree(include: ['*.aar'], dir: 'libs')
|
||||
// 全屏,没有状态栏
|
||||
api 'com.readystatesoftware.systembartint:systembartint:1.0.3'
|
||||
implementation files('libs/armeabi-v7a/librockchip.so')
|
||||
}
|
||||
BIN
app/libs/DataCollection.jar
Normal file
BIN
app/libs/Msc.jar
Normal file
BIN
app/libs/arm64-v8a/libmsc.so
Normal file
@ -2,7 +2,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="chaoran.business">
|
||||
|
||||
<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" />
|
||||
@ -11,15 +10,23 @@
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="com.symbol.emdk.permission.EMDK"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="com.honeywell.decode.permission.DECODE" />
|
||||
<uses-permission android:name="android.permission.STOP_SERVICE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:name=".application.InitApplication"
|
||||
android:theme="@style/Theme.PdaWeb"
|
||||
android:usesCleartextTraffic="true">
|
||||
android:usesCleartextTraffic="true"
|
||||
android:screenOrientation="user"
|
||||
>
|
||||
<uses-library android:name="com.symbol.emdk" android:required="false"/>
|
||||
<activity
|
||||
android:name=".activity.NetworkSettingActivity"
|
||||
android:label="@string/title_activity_setting_network" />
|
||||
@ -28,6 +35,7 @@
|
||||
android:label="@string/title_activity_setting_voice" />
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -35,6 +43,17 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".service.ScanServiceEDA50P" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.example.chaoran.ScanServiceEDA50P"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service android:name=".service.ScanServiceZEBRA">
|
||||
<intent-filter>
|
||||
<action android:name="com.example.chaoran.ScanServiceZEBRA"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -99,18 +99,6 @@
|
||||
|
||||
|
||||
</style>
|
||||
<script>
|
||||
function saveSetting(){
|
||||
var data=JSON.stringify({
|
||||
"address":document.getElementById('address').value,
|
||||
"port":document.getElementById('port').value,
|
||||
"path":document.getElementById('path').value
|
||||
});
|
||||
window.NetworkSettingEngine.save(data);
|
||||
window.View.reload();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
@ -130,6 +118,14 @@
|
||||
<label>访问子路径</label>
|
||||
<input id="path" name="path" placeholder="访问子路径">
|
||||
</div>
|
||||
<div class="net-list">
|
||||
<label>屏幕旋转</label>
|
||||
<input id="screen_rotation" value="3" name="screen_rotation" placeholder="1:强制竖屏;2:强制横屏;3:横竖都转">
|
||||
</div>
|
||||
<div class="net-list">
|
||||
<label>隐藏状态栏</label>
|
||||
<input id="hide_bar" value="1" name="hide_bar" placeholder="1:隐藏;0:显示">
|
||||
</div>
|
||||
</div>
|
||||
<div class="operation">
|
||||
<button style="background: #1989fa;" onclick="saveSetting()">保存</button>
|
||||
@ -138,4 +134,35 @@
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
function init() {
|
||||
var dstr = window.NetworkSettingEngine.getStringSetting();
|
||||
if (dstr.length > 0) {
|
||||
var d = JSON.parse(dstr);
|
||||
document.getElementById('address').value = d.address;
|
||||
document.getElementById('port').value = d.port;
|
||||
document.getElementById('path').value = d.path;
|
||||
document.getElementById('screen_rotation').value = d.screen_rotation;
|
||||
document.getElementById('hide_bar').value = d.hide_bar;
|
||||
console.log("d_data_end_=========================");
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
function saveSetting(){
|
||||
var data=JSON.stringify({
|
||||
"address":document.getElementById('address').value,
|
||||
"port":document.getElementById('port').value,
|
||||
"path":document.getElementById('path').value,
|
||||
"screen_rotation":document.getElementById('screen_rotation').value,
|
||||
"hide_bar":document.getElementById('hide_bar').value
|
||||
});
|
||||
window.NetworkSettingEngine.saveSetting(data);
|
||||
window.View.reload();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
||||
@ -10,11 +10,22 @@ package chaoran.business;
|
||||
|
||||
public enum BrandEnum {
|
||||
//枚举名即为valueOf()
|
||||
QUALCOMM("qualcomm", "qualcomm"),
|
||||
IOT_DEVICE("新大陆", "iot_device"),
|
||||
NEW_LAND("新大陆", "newland"),
|
||||
HISENSE("海信", "hisense"),
|
||||
UROVO("DT50 Lite", "urovo"),
|
||||
LACHESIS("联新", "lachesis"),
|
||||
UROBO("优博讯", "urobo"),
|
||||
ROCKCHIP("瑞芯微电子", "rockchip"),
|
||||
TEST("测试设备", "test"),
|
||||
IDATA("匿名设备", "idata"),
|
||||
ALPS("阿尔卑斯", "alps");
|
||||
HONEY_WELL_EDA50P("霍尼维尔EDA50P", "mobiwire"),
|
||||
HONEY_WELL_EDA51("霍尼维尔EDA51", "honeywell"),
|
||||
ZEBRA_TECHNOLOGIES("斑马TP26CK", "zebra technologies"),
|
||||
SEUIC("东集", "seuic"),
|
||||
ALPS("阿尔卑斯", "alps"),
|
||||
HKWS("海康威视", "mv-idp5102");
|
||||
|
||||
private String name;
|
||||
private String code;
|
||||
@ -35,7 +46,7 @@ public enum BrandEnum {
|
||||
code = new String();
|
||||
}
|
||||
for (BrandEnum brandEnum : values()) {
|
||||
if (brandEnum.code.equals(code.toLowerCase())) {
|
||||
if (brandEnum.code.equalsIgnoreCase(code)) {
|
||||
return brandEnum;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,30 @@
|
||||
package chaoran.business.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.util.JsonReader;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.*;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
@ -18,13 +32,29 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import chaoran.business.BrandEnum;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.adapter.*;
|
||||
import chaoran.business.engine.entity.NetworkSetting;
|
||||
import chaoran.business.engine.impl.NetworkSettingEngine;
|
||||
import chaoran.business.engine.SettingEngine;
|
||||
import chaoran.business.engine.impl.TekVoiceEngine;
|
||||
import chaoran.business.engine.VoiceEngine;
|
||||
import chaoran.business.service.ScanServiceEDA50P;
|
||||
import chaoran.business.service.ScanServiceZEBRA;
|
||||
import chaoran.business.utils.LocalAddressUtil;
|
||||
import chaoran.business.utils.StatusBarUtil;
|
||||
|
||||
/**
|
||||
* 流程:联网认证设备型号,验证通过,查找设备品牌进行调用驱动操作
|
||||
@ -35,23 +65,52 @@ import chaoran.business.engine.VoiceEngine;
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
|
||||
public static int SCREEN_ROTATION = 3; // 屏幕旋转的设置
|
||||
public static int hideBar = 0; // 屏幕旋转的设置
|
||||
|
||||
MyOrientationDetector myOrientationDetector;
|
||||
|
||||
private WebView webView;
|
||||
private Adapter adapter;
|
||||
//private VoiceEngine voiceEngine;
|
||||
private VoiceEngine voiceEngine;
|
||||
private SettingEngine settingEngine;
|
||||
private ProgressBar progressBar;
|
||||
private ActionBar actionBar;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
initView();
|
||||
initData();
|
||||
//SCREEN_ORIENTATION_USER,不能旋转180,0、90、270都可以旋转
|
||||
//SCREEN_ORIENTATION_FULL_SENSOR 都可以旋转,但是在不打开旋转的情况下,一样可以旋转
|
||||
//SCREEN_ORIENTATION_FULL_USER 关闭旋转则不会旋转了
|
||||
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
|
||||
myOrientationDetector = new MyOrientationDetector(this, this);
|
||||
myOrientationDetector.enable();
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
BrandEnum brand = BrandEnum.code(Build.MANUFACTURER);
|
||||
Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show();
|
||||
@ -69,31 +128,80 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
case ALPS:
|
||||
adapter = new AlpsAdapter(this, this);
|
||||
break;
|
||||
case SEUIC:
|
||||
adapter = new SeuicAdapter(this, this);
|
||||
break;
|
||||
case HONEY_WELL_EDA50P:
|
||||
// 51、56都是同一个code
|
||||
case HONEY_WELL_EDA51:
|
||||
if (
|
||||
"eda50p".equals(Build.MODEL.toLowerCase())
|
||||
|| "eda51".equals(Build.MODEL.toLowerCase())
|
||||
|| "tc26".equals(Build.MODEL.toLowerCase())
|
||||
) {
|
||||
// 走服务模式
|
||||
adapter = new HoneywellAdapter(this, this);
|
||||
}else {
|
||||
// 走广播模式
|
||||
adapter = new HoneywellEda56Adapter(this, this);
|
||||
}
|
||||
break;
|
||||
case ZEBRA_TECHNOLOGIES:
|
||||
adapter = new ZebraAdapter(this, this);
|
||||
break;
|
||||
case HISENSE:
|
||||
adapter = new HisenseAdapter(this, this);
|
||||
break;
|
||||
case LACHESIS:
|
||||
adapter = new LachesisAdapter(this, this);
|
||||
break;
|
||||
case UROVO:
|
||||
adapter = new UrovoAdapter(this, this);
|
||||
break;
|
||||
case HKWS:
|
||||
adapter = new HkwsAdapter(this, this);
|
||||
break;
|
||||
case NEW_LAND:
|
||||
adapter = new NewlandAdapter(this, this);
|
||||
break;
|
||||
case IOT_DEVICE:
|
||||
adapter = new IOT_DeviceAdapter(this, this);
|
||||
break;
|
||||
case QUALCOMM:
|
||||
adapter = new QualcommAdapter(this, this);
|
||||
break;
|
||||
}
|
||||
if (null != adapter) {
|
||||
adapter.start();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
private void initView() {
|
||||
actionBar = getSupportActionBar();
|
||||
// voiceEngine = new TekVoiceEngine(this);
|
||||
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, "TekVoiceEngine");
|
||||
webView.addJavascriptInterface(voiceEngine, "TekVoiceEngine");
|
||||
//网络设置展示
|
||||
webView.addJavascriptInterface(settingEngine, "NetworkSettingEngine");
|
||||
//重新加载页面
|
||||
webView.addJavascriptInterface(this, "View");
|
||||
webView.addJavascriptInterface(new LocalAddressUtil(this, this, webView), "Localpda");
|
||||
webView.loadUrl(url());
|
||||
// StatusBarUtil.transparencyBar( this); // 设置全部透明,需要在页面设置一个参数进行布局的样式跳转,不同的手机端,状态栏高度不一样(apk设置状态栏高度无效,这个是安卓9的一个bug),所以在此采取隐藏状态栏
|
||||
if (hideBar == 1) {
|
||||
StatusBarUtil.hideStatusBar( this); // 设置全部透明
|
||||
}
|
||||
}
|
||||
|
||||
//配置客户端
|
||||
@ -166,6 +274,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
//webView.loadUrl(url());
|
||||
// voiceEngine.reload();
|
||||
super.onResume();
|
||||
if (adapter != null) {
|
||||
myOrientationDetector.disable();
|
||||
adapter.stop2();
|
||||
adapter.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -173,11 +286,31 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
public void result(String result) {
|
||||
runOnUiThread(() -> webView.loadUrl("javascript:render(\'" + result + "\')"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (adapter != null) {
|
||||
adapter.stop();
|
||||
}
|
||||
super.onDestroy();
|
||||
if (diPlayer != null) {
|
||||
diPlayer.stop();
|
||||
diPlayer.release();
|
||||
diPlayer = null;
|
||||
}
|
||||
if (duPlayer != null) {
|
||||
duPlayer.stop();
|
||||
duPlayer.release();
|
||||
duPlayer = null;
|
||||
}
|
||||
if (dingPlayer != null) {
|
||||
dingPlayer.stop();
|
||||
dingPlayer.release();
|
||||
dingPlayer = null;
|
||||
}
|
||||
if (vibrator != null) {
|
||||
vibrator.cancel();
|
||||
}
|
||||
completionListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -203,12 +336,41 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
private String url() {
|
||||
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||
Integer port = spf.getInt("port", -1);
|
||||
Map<String, Object> map = null;
|
||||
if (port == -1) {
|
||||
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";
|
||||
}
|
||||
}
|
||||
String address = spf.getString("address", "").replaceAll(" ", "");
|
||||
String path = spf.getString("path", "").replaceAll(" ", "");
|
||||
String link = address.concat(":").concat(String.valueOf(port)).concat(path);
|
||||
SCREEN_ROTATION = spf.getInt("screen_rotation", 3);
|
||||
hideBar = spf.getInt("hide_bar", 3);
|
||||
return link.startsWith("http://") ? link : "http://".concat(link);
|
||||
}
|
||||
|
||||
@ -218,4 +380,118 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
webView.loadUrl(url());
|
||||
});
|
||||
}
|
||||
private MediaPlayer diPlayer = null;
|
||||
private MediaPlayer duPlayer = null;
|
||||
private MediaPlayer dingPlayer = null;
|
||||
private String ttsNr;
|
||||
public Vibrator vibrator;
|
||||
|
||||
@JavascriptInterface
|
||||
public void play(String msg, String type, int isZd) throws IOException {
|
||||
ttsNr = msg;
|
||||
if ("1".equals(type)) {
|
||||
if (diPlayer == null) {
|
||||
diPlayer = MediaPlayer.create(this, R.raw.didi);
|
||||
diPlayer.setOnCompletionListener(completionListener);
|
||||
}
|
||||
diPlayer.start();
|
||||
} else if ("2".equals(type)) {
|
||||
if (duPlayer == null) {
|
||||
duPlayer = MediaPlayer.create(this, R.raw.dudu);
|
||||
duPlayer.setOnCompletionListener(completionListener);
|
||||
}
|
||||
duPlayer.start();
|
||||
} else if ("10".equals(type)) {
|
||||
if (dingPlayer == null) {
|
||||
dingPlayer = MediaPlayer.create(this, R.raw.ding);
|
||||
dingPlayer.setOnCompletionListener(completionListener);
|
||||
}
|
||||
dingPlayer.start();
|
||||
} else {
|
||||
//isZd = 1;
|
||||
if (voiceEngine != null) {
|
||||
voiceEngine.startSpeaking(msg);
|
||||
}
|
||||
}
|
||||
if (isZd == 1) {
|
||||
if (vibrator == null) {
|
||||
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
vibrator.vibrate(2000);
|
||||
}
|
||||
}
|
||||
|
||||
private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() {
|
||||
// @Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
if (ttsNr != null) {
|
||||
if (voiceEngine != null) {
|
||||
voiceEngine.startSpeaking(ttsNr);
|
||||
}
|
||||
ttsNr = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public void openIndex() throws IOException {
|
||||
runOnUiThread(() -> {
|
||||
webView.loadUrl("file:///android_asset/demo/index.html");
|
||||
});
|
||||
}
|
||||
|
||||
/* 监听角度的变化 */
|
||||
class MyOrientationDetector extends OrientationEventListener {
|
||||
|
||||
private int rotate;
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public MyOrientationDetector(Context context, Activity activity) {
|
||||
super(context);
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOrientationChanged(int orientation) {
|
||||
//假设屏幕旋转被打开。则设置屏幕可旋转
|
||||
//0-57度 125-236度 306-360度 这些区间范围内为竖屏
|
||||
//58-124度 237-305度 这些区间范围内为横屏
|
||||
if (orientation >=0 && orientation <= 57 ) {
|
||||
rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏
|
||||
}else if (orientation >=125 && orientation <= 236 ) {
|
||||
rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; // 倒竖屏
|
||||
}else if (orientation >=306 && orientation <= 360 ) {
|
||||
rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏
|
||||
}else if (orientation >=58 && orientation <= 124 ) {
|
||||
rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; // 正横屏
|
||||
}else if (orientation >=237 && orientation <= 305 ) {
|
||||
rotate = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 倒横屏
|
||||
}else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -19,7 +19,7 @@ import chaoran.business.R;
|
||||
|
||||
public class NetworkSettingActivity extends AppCompatActivity {
|
||||
|
||||
private EditText address, path, port;
|
||||
private EditText address, path, port, screen_rotation, hide_bar;
|
||||
private Button save, cancel;
|
||||
|
||||
@Override
|
||||
@ -35,12 +35,16 @@ public class NetworkSettingActivity extends AppCompatActivity {
|
||||
address = findViewById(R.id.address);
|
||||
path = findViewById(R.id.path);
|
||||
port = findViewById(R.id.port);
|
||||
screen_rotation = findViewById(R.id.screen_rotation);
|
||||
hide_bar = findViewById(R.id.hide_bar);
|
||||
save = findViewById(R.id.save);
|
||||
cancel = findViewById(R.id.cancel);
|
||||
SharedPreferences sharedPreferences = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||
address.setText(sharedPreferences.getString("address", ""));
|
||||
path.setText(sharedPreferences.getString("path", ""));
|
||||
port.setText(String.valueOf(sharedPreferences.getInt("port", -1)));
|
||||
screen_rotation.setText(String.valueOf(sharedPreferences.getInt("screen_rotation", 3)));
|
||||
hide_bar.setText(String.valueOf(sharedPreferences.getInt("hide_bar", 0)));
|
||||
cancel.setOnClickListener((e) -> this.finish());
|
||||
save.setOnClickListener((e) -> saveSetting());
|
||||
}
|
||||
@ -50,6 +54,8 @@ public class NetworkSettingActivity extends AppCompatActivity {
|
||||
editor.putString("address", address.getText().toString().trim());
|
||||
editor.putString("path", path.getText().toString().trim());
|
||||
editor.putInt("port", Integer.parseInt(port.getText().toString().trim()));
|
||||
editor.putInt("screen_rotation", Integer.parseInt(screen_rotation.getText().toString().trim()));
|
||||
editor.putInt("hide_bar", Integer.parseInt(hide_bar.getText().toString().trim()));
|
||||
editor.commit();
|
||||
this.finish();
|
||||
}
|
||||
|
||||
@ -29,4 +29,8 @@ public interface Adapter{
|
||||
*/
|
||||
public void stop();
|
||||
|
||||
public default void stop2() {
|
||||
stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ import chaoran.business.strategy.Strategy;
|
||||
|
||||
/**
|
||||
* 阿尔卑斯适配器
|
||||
* CR-5W适用
|
||||
* CR-5W适用;Android Handheld Terminal
|
||||
*/
|
||||
public class AlpsAdapter implements Adapter {
|
||||
private Context context;
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class HisenseAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public HisenseAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("msg"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("chaoran");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
app/src/main/java/chaoran/business/adapter/HkwsAdapter.java
Normal file
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class HkwsAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public HkwsAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("barcode"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("android.intent.ACTION_SCAN_OUTPUT");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
125
app/src/main/java/chaoran/business/adapter/HoneywellAdapter.java
Normal file
@ -0,0 +1,125 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.service.ScanServiceEDA50P;
|
||||
import chaoran.business.service.ScanServiceZEBRA;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
|
||||
public class HoneywellAdapter implements Adapter {
|
||||
private Context context;
|
||||
private Strategy strategy;
|
||||
private ResultListener resultListener;
|
||||
private Intent intent = null;
|
||||
|
||||
public HoneywellAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
openContinueScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop2() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
new ScanServiceEDA50P().onDestroy();
|
||||
strategy.exclusiveStrategy();
|
||||
this.stopContinueScan();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("data"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.honeywell.scan.broadcast");
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopContinueScan() {
|
||||
Class clazz = null;
|
||||
if("eda50p".equals(Build.MODEL.toLowerCase())){ // 扫描正常
|
||||
intent = new Intent(context, ScanServiceEDA50P.class);
|
||||
clazz = ScanServiceEDA50P.class;
|
||||
}else if("eda51".equals(Build.MODEL.toLowerCase())){ // 扫描正常
|
||||
intent = new Intent(context, ScanServiceEDA50P.class);
|
||||
clazz = ScanServiceEDA50P.class;
|
||||
}
|
||||
else if("tc26".equals(Build.MODEL.toLowerCase())){
|
||||
intent = new Intent(context, ScanServiceZEBRA.class);
|
||||
clazz = ScanServiceZEBRA.class;
|
||||
}
|
||||
if (clazz != null && isServiceRunning(clazz)) {
|
||||
context.stopService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isServiceRunning(Class<?> serviceClass) {
|
||||
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningServiceInfo> runningServices = manager.getRunningServices(Integer.MAX_VALUE);
|
||||
|
||||
for (ActivityManager.RunningServiceInfo service : runningServices) {
|
||||
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void openContinueScan(){
|
||||
|
||||
if("eda50p".equals(Build.MODEL.toLowerCase())){ // 扫描正常
|
||||
intent = new Intent(context, ScanServiceEDA50P.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.getApplicationContext().startForegroundService(intent);
|
||||
}else {
|
||||
context.getApplicationContext().startService(intent);
|
||||
}
|
||||
}else if("eda51".equals(Build.MODEL.toLowerCase())){ // 扫描正常
|
||||
intent = new Intent(context, ScanServiceEDA50P.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.getApplicationContext().startForegroundService(intent);
|
||||
}else {
|
||||
context.getApplicationContext().startService(intent);
|
||||
}
|
||||
}
|
||||
else if("tc26".equals(Build.MODEL.toLowerCase())){
|
||||
intent = new Intent(context, ScanServiceZEBRA.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.getApplicationContext().startForegroundService(intent);
|
||||
}else {
|
||||
context.getApplicationContext().startService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
/**
|
||||
* 23-6-13 霍尼韦尔EDA56使用
|
||||
* 25-1-14 兰陵县人民医院 测试可以使用(唐圆圆)
|
||||
*/
|
||||
public class HoneywellEda56Adapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public HoneywellEda56Adapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new HoneywellEda56Adapter.Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("data"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("chaoran");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,5 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-02 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -45,7 +39,7 @@ public class IDataAdapter implements Adapter {
|
||||
|
||||
public Receiver() {
|
||||
scannerInerface = new ScannerInerface(context);
|
||||
scannerInerface.setOutputMode(1);
|
||||
// scannerInerface.setOutputMode(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +49,7 @@ public class IDataAdapter implements Adapter {
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
scannerInerface.open();
|
||||
// scannerInerface.open();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("android.intent.action.SCANRESULT");
|
||||
context.registerReceiver(this, filter);
|
||||
@ -64,7 +58,7 @@ public class IDataAdapter implements Adapter {
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
scannerInerface.close();
|
||||
// scannerInerface.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
/**
|
||||
* 适配 sc55g
|
||||
*/
|
||||
public class IOT_DeviceAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public IOT_DeviceAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("message"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.speedata.showdecodedata");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class LachesisAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public LachesisAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("data"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("chaoran");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class NewlandAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public NewlandAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("SCAN_BARCODE1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("nlscan.action.SCANNER_RESULT");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
/**
|
||||
* 适配 mc50
|
||||
*/
|
||||
public class QualcommAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public QualcommAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("data"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.scanner.broadcast");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,10 +9,6 @@ package chaoran.business.adapter;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.SoundPool;
|
||||
import android.os.Vibrator;
|
||||
import chaoran.business.R;
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
@ -29,6 +25,8 @@ public class RockChipAdapter implements Adapter {
|
||||
|
||||
private Context context;
|
||||
|
||||
public static final String[] barcode = {""};
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
@ -76,11 +74,26 @@ public class RockChipAdapter implements Adapter {
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
running = true;
|
||||
new Thread(() -> {
|
||||
while (running) {
|
||||
String data = data();
|
||||
if (!data.equals("")) {
|
||||
resultListener.result(data);
|
||||
synchronized (RockChipAdapter.class) {
|
||||
barcode[0] = barcode[0] + data;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
synchronized (RockChipAdapter.class) {
|
||||
if (!"".equals(barcode[0])) {
|
||||
// Log.i("listen", "Thread result data: \t\t" + barcode[0] + "\t\t" + System.currentTimeMillis());
|
||||
resultListener.result(barcode[0]);
|
||||
barcode[0] = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@ -88,22 +101,27 @@ public class RockChipAdapter implements Adapter {
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
running = false;
|
||||
close();
|
||||
// running = false;
|
||||
// close();
|
||||
}
|
||||
|
||||
private String data() {
|
||||
if (mFileInputStream == null) return "";
|
||||
if (mFileInputStream == null) {
|
||||
return "";
|
||||
}
|
||||
synchronized (RockChipAdapter.class) {
|
||||
try {
|
||||
int size = mFileInputStream.available();
|
||||
byte[] buffer = new byte[size];
|
||||
size = mFileInputStream.read(buffer);
|
||||
if (size > 0) {
|
||||
return new String(buffer);
|
||||
String data = new String(buffer);
|
||||
return data;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
61
app/src/main/java/chaoran/business/adapter/SeuicAdapter.java
Normal file
@ -0,0 +1,61 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
/*
|
||||
**********************************************
|
||||
* DATE PERSON REASON
|
||||
* 2021-02-03 FXY Created
|
||||
**********************************************
|
||||
*/
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
/**
|
||||
* 东集 pda
|
||||
*/
|
||||
public class SeuicAdapter implements Adapter {
|
||||
private Context context;
|
||||
private Strategy strategy;
|
||||
private ResultListener resultListener;
|
||||
|
||||
public SeuicAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("scannerdata"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.android.server.scannerservice.broadcast");
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
app/src/main/java/chaoran/business/adapter/UrovoAdapter.java
Normal file
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class UrovoAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public UrovoAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("barcode_string"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("android.intent.ACTION_DECODE_DATA");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
app/src/main/java/chaoran/business/adapter/ZebraAdapter.java
Normal file
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class ZebraAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public ZebraAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new ZebraAdapter.Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("com.motorolasolutions.emdk.datawedge.data_string"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("chaoran");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,10 @@ public class NetworkSetting extends Setting {
|
||||
private Integer port;
|
||||
private String path;
|
||||
|
||||
private Integer screen_rotation;
|
||||
|
||||
private Integer hide_bar;
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
@ -35,4 +39,20 @@ public class NetworkSetting extends Setting {
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public Integer getScreen_rotation() {
|
||||
return screen_rotation;
|
||||
}
|
||||
|
||||
public void setScreen_rotation(Integer screen_rotation) {
|
||||
this.screen_rotation = screen_rotation;
|
||||
}
|
||||
|
||||
public Integer getHide_bar() {
|
||||
return hide_bar;
|
||||
}
|
||||
|
||||
public void setHide_bar(Integer hide_bar) {
|
||||
this.hide_bar = hide_bar;
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,8 @@ package chaoran.business.engine.impl;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.webkit.JavascriptInterface;
|
||||
|
||||
import chaoran.business.activity.MainActivity;
|
||||
import chaoran.business.engine.SettingEngine;
|
||||
import chaoran.business.engine.entity.NetworkSetting;
|
||||
import chaoran.business.engine.entity.Setting;
|
||||
@ -35,12 +37,15 @@ public class NetworkSettingEngine implements SettingEngine {
|
||||
public Setting getSetting() {
|
||||
SharedPreferences spf = context.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||
Integer port = spf.getInt("port", -1);
|
||||
Integer screen_rotation = spf.getInt("screen_rotation", 3);
|
||||
String address = spf.getString("address", "").replaceAll(" ", "");
|
||||
String path = spf.getString("path", "").replaceAll(" ", "");
|
||||
NetworkSetting networkSetting = new NetworkSetting();
|
||||
networkSetting.setAddress(address);
|
||||
networkSetting.setPort(port);
|
||||
networkSetting.setPath(path);
|
||||
networkSetting.setScreen_rotation(screen_rotation);
|
||||
networkSetting.setHide_bar(spf.getInt("hide_bar", 3));
|
||||
return networkSetting;
|
||||
}
|
||||
|
||||
@ -51,7 +56,11 @@ public class NetworkSettingEngine implements SettingEngine {
|
||||
editor.putString("address", networkSetting.getAddress());
|
||||
editor.putString("path", networkSetting.getPath());
|
||||
editor.putInt("port", networkSetting.getPort());
|
||||
editor.putInt("screen_rotation", networkSetting.getScreen_rotation());
|
||||
editor.putInt("hide_bar", networkSetting.getHide_bar());
|
||||
editor.commit();
|
||||
MainActivity.SCREEN_ROTATION = networkSetting.getScreen_rotation();
|
||||
MainActivity.hideBar = networkSetting.getHide_bar();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -109,22 +109,22 @@ public class TekVoiceEngine extends OfflineVoiceEngine {
|
||||
String info) {
|
||||
// 合成进度
|
||||
mPercentForBuffering = percent;
|
||||
showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
mPercentForBuffering, mPercentForPlaying));
|
||||
// showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
// mPercentForBuffering, mPercentForPlaying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakProgress(int percent, int beginPos, int endPos) {
|
||||
// 播放进度
|
||||
mPercentForPlaying = percent;
|
||||
showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
mPercentForBuffering, mPercentForPlaying));
|
||||
// showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
// mPercentForBuffering, mPercentForPlaying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(SpeechError error) {
|
||||
if (error == null) {
|
||||
showTip("播放完成");
|
||||
// showTip("播放完成");
|
||||
} else if (error != null) {
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
@ -0,0 +1,261 @@
|
||||
package chaoran.business.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.honeywell.aidc.AidcManager;
|
||||
import com.honeywell.aidc.BarcodeDeviceConnectionEvent;
|
||||
import com.honeywell.aidc.BarcodeFailureEvent;
|
||||
import com.honeywell.aidc.BarcodeReadEvent;
|
||||
import com.honeywell.aidc.BarcodeReader;
|
||||
import com.honeywell.aidc.BarcodeReaderInfo;
|
||||
import com.honeywell.aidc.ScannerNotClaimedException;
|
||||
import com.honeywell.aidc.ScannerUnavailableException;
|
||||
import com.honeywell.aidc.TriggerStateChangeEvent;
|
||||
import com.honeywell.aidc.UnsupportedPropertyException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
public class ScanServiceEDA50P extends Service
|
||||
implements BarcodeReader.BarcodeListener, BarcodeReader.TriggerListener, AidcManager.BarcodeDeviceListener{
|
||||
private final String TAG = "TestScanService";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private String notificationId = "channelId";
|
||||
private String notificationName = "channelName";
|
||||
|
||||
private String _Suffix = "\n";
|
||||
|
||||
|
||||
private AidcManager mAidcManager;
|
||||
private BarcodeReader mBarcodeReader;
|
||||
private BarcodeReader mInternalScannerReader;
|
||||
private boolean mKeyPressed = false;
|
||||
private boolean isContinue = true;
|
||||
|
||||
//必须要实现的方法
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// Log.i(TAG, "onBind方法被调用!");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Service被创建时调用
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Log.i(TAG, "onCreate方法被调用!");
|
||||
super.onCreate();
|
||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { //适配9.0service
|
||||
// if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { //适配9.0service
|
||||
channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
Notification notification = new Notification.Builder(getApplicationContext(), notificationId).build();
|
||||
//startForeground(1,getNotification());
|
||||
startForeground(1, notification);
|
||||
}
|
||||
|
||||
AidcManager.create(this, new MyCreatedCallback());
|
||||
}
|
||||
|
||||
//Service被启动时调用
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.i(TAG, "onStartCommand方法被调用!");
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
//Service被关闭之前回调
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.i(TAG, "onDestroy方法被调用!");
|
||||
super.onDestroy();
|
||||
if (mBarcodeReader != null) {
|
||||
mBarcodeReader.release();
|
||||
}
|
||||
if (this.mInternalScannerReader != null) {
|
||||
this.mInternalScannerReader.removeBarcodeListener(this);
|
||||
this.mInternalScannerReader.removeTriggerListener(this);
|
||||
this.mInternalScannerReader.close();
|
||||
this.mInternalScannerReader = null;
|
||||
Log.d(TAG, "Close internal scanner");
|
||||
}
|
||||
if (this.mAidcManager != null) {
|
||||
this.mAidcManager.removeBarcodeDeviceListener(this);
|
||||
this.mAidcManager.close();
|
||||
}
|
||||
|
||||
}
|
||||
class MyCreatedCallback implements AidcManager.CreatedCallback {
|
||||
MyCreatedCallback() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(AidcManager aidcManager) {
|
||||
Log.d(TAG, "MyCreatedCallback onCreate !!!");
|
||||
mAidcManager = aidcManager;
|
||||
mAidcManager.addBarcodeDeviceListener(ScanServiceEDA50P.this);
|
||||
initAllBarcodeReaderAndSetDefault();
|
||||
}
|
||||
}
|
||||
void initAllBarcodeReaderAndSetDefault() {
|
||||
List<BarcodeReaderInfo> readerList = mAidcManager.listBarcodeDevices();
|
||||
Log.d(TAG, "initAllBarcodeReaderAndSetDefault readerList = "+readerList);
|
||||
mInternalScannerReader = null;
|
||||
for (BarcodeReaderInfo reader : readerList) {
|
||||
if ("dcs.scanner.imager".equals(reader.getName())) {
|
||||
mInternalScannerReader = initBarcodeReader(mInternalScannerReader, reader.getName());
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "initAllBarcodeReaderAndSetDefault mInternalScannerReader = "+mInternalScannerReader);
|
||||
|
||||
if (mInternalScannerReader != null) {
|
||||
mBarcodeReader = mInternalScannerReader;
|
||||
}
|
||||
else {
|
||||
Log.d(TAG, "No reader find");
|
||||
}
|
||||
if (mBarcodeReader != null) {
|
||||
try {
|
||||
mBarcodeReader.addBarcodeListener(this);
|
||||
mBarcodeReader.addTriggerListener(this);
|
||||
}
|
||||
catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
try {
|
||||
mBarcodeReader.setProperty(BarcodeReader.PROPERTY_NOTIFICATION_GOOD_READ_ENABLED, true);
|
||||
mBarcodeReader.setProperty(BarcodeReader.PROPERTY_EAN_13_CHECK_DIGIT_TRANSMIT_ENABLED, true);
|
||||
|
||||
} catch (UnsupportedPropertyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BarcodeReader initBarcodeReader(BarcodeReader mReader, String mReaderName) {
|
||||
if (mReader == null) {
|
||||
try {
|
||||
if (mReaderName == null) {
|
||||
mReader = mAidcManager.createBarcodeReader();
|
||||
} else {
|
||||
mReader = mAidcManager.createBarcodeReader(mReaderName);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e(TAG, "error", e);
|
||||
}
|
||||
try {
|
||||
mReader.claim();
|
||||
Log.d(TAG, "Call DCS interface claim() " + mReaderName);
|
||||
} catch (ScannerUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
mReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE, BarcodeReader.TRIGGER_CONTROL_MODE_CLIENT_CONTROL);
|
||||
mReader.setProperty(BarcodeReader.PROPERTY_DATA_PROCESSOR_LAUNCH_EZ_CONFIG, false);
|
||||
mReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_AUTO_MODE_TIMEOUT, 300);
|
||||
|
||||
} catch (UnsupportedPropertyException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mReader;
|
||||
}
|
||||
|
||||
public void onBarcodeDeviceConnectionEvent(BarcodeDeviceConnectionEvent event) {
|
||||
Log.d(TAG, event.getBarcodeReaderInfo() + " Connection status: " + event.getConnectionStatus());
|
||||
}
|
||||
|
||||
public void onBarcodeEvent(final BarcodeReadEvent event) {
|
||||
String barcodeDate = new String(event.getBarcodeData().getBytes(event.getCharset()));
|
||||
Intent intent2 = new Intent("com.honeywell.scan.broadcast");
|
||||
intent2.putExtra("data",barcodeDate);
|
||||
sendBroadcast(intent2);
|
||||
if(isContinue) {
|
||||
executorService.execute(new MyThread(mBarcodeReader));
|
||||
}
|
||||
}
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
class MyThread implements Runnable{
|
||||
private BarcodeReader mBarcodeReader;
|
||||
public MyThread(BarcodeReader mBarcodeReader){
|
||||
this.mBarcodeReader = mBarcodeReader;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
{
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
mBarcodeReader.decode(true);
|
||||
} catch (ScannerNotClaimedException e) {
|
||||
Log.e(TAG, "catch ScannerNotClaimedException",e);
|
||||
e.printStackTrace();
|
||||
} catch (ScannerUnavailableException e2) {
|
||||
Log.e(TAG, "catch ScannerUnavailableException",e2);
|
||||
e2.printStackTrace();
|
||||
} catch (Exception e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onFailureEvent(final BarcodeFailureEvent event) {
|
||||
//Log.d(TAG, "Enter onFailureEvent ===> " + event.getTimestamp());
|
||||
if(isContinue) {
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// doScan(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onTriggerEvent(TriggerStateChangeEvent event) {
|
||||
if (event.getState()) {
|
||||
if (!mKeyPressed) {
|
||||
mKeyPressed = true;
|
||||
doScan(true);
|
||||
}else{
|
||||
mKeyPressed = false;
|
||||
doScan(false);
|
||||
}
|
||||
} else {
|
||||
//mKeyPressed = false;
|
||||
// doScan(false);
|
||||
}
|
||||
// Log.d(TAG, "OnTriggerEvent status: " + event.getState());
|
||||
}
|
||||
void doScan(boolean do_scan) {
|
||||
try {
|
||||
if (do_scan) {
|
||||
// Log.d(TAG, "Start a new Scan!");
|
||||
} else {
|
||||
// Log.d(TAG, "Cancel last Scan!");
|
||||
}
|
||||
mBarcodeReader.decode(do_scan);
|
||||
} catch (ScannerNotClaimedException e) {
|
||||
Log.e(TAG, "catch ScannerNotClaimedException",e);
|
||||
e.printStackTrace();
|
||||
} catch (ScannerUnavailableException e2) {
|
||||
Log.e(TAG, "catch ScannerUnavailableException",e2);
|
||||
e2.printStackTrace();
|
||||
} catch (Exception e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
333
app/src/main/java/chaoran/business/service/ScanServiceZEBRA.java
Normal file
@ -0,0 +1,333 @@
|
||||
package chaoran.business.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.symbol.emdk.EMDKManager;
|
||||
import com.symbol.emdk.EMDKResults;
|
||||
import com.symbol.emdk.barcode.BarcodeManager;
|
||||
import com.symbol.emdk.barcode.ScanDataCollection;
|
||||
import com.symbol.emdk.barcode.Scanner;
|
||||
import com.symbol.emdk.barcode.ScannerConfig;
|
||||
import com.symbol.emdk.barcode.ScannerException;
|
||||
import com.symbol.emdk.barcode.ScannerResults;
|
||||
import com.symbol.emdk.barcode.StatusData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ScanServiceZEBRA extends Service implements EMDKManager.EMDKListener, Scanner.DataListener, Scanner.StatusListener {
|
||||
private final String TAG = "ScanService";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private String notificationId = "ScanServiceId";
|
||||
private String notificationName = "ScanServiceName";
|
||||
|
||||
private EMDKManager emdkManager = null;
|
||||
private BarcodeManager barcodeManager = null;
|
||||
private Scanner scanner = null;
|
||||
|
||||
private String statusString = "";
|
||||
|
||||
private boolean bSoftTriggerSelected = true;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
Log.i(TAG, "onBind方法被调用!");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Service被创建时调用
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.i(TAG, "onCreate方法被调用!");
|
||||
super.onCreate();
|
||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { //适配8.0service
|
||||
channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
Notification notification = new Notification.Builder(getApplicationContext(), notificationId).build();
|
||||
//startForeground(1,getNotification());
|
||||
startForeground(1, notification);
|
||||
}
|
||||
EMDKResults results = EMDKManager.getEMDKManager(getApplicationContext(), this);
|
||||
final IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("com.pda.scan.trigger");
|
||||
registerReceiver(myCodeReceiver, intentFilter);
|
||||
}
|
||||
private MyCodeReceiver myCodeReceiver = new MyCodeReceiver();
|
||||
|
||||
public class MyCodeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int keyCode = intent.getIntExtra("data",0);
|
||||
if(keyCode == 103 || keyCode == 10036){
|
||||
if(bSoftTriggerSelected){
|
||||
bSoftTriggerSelected = false;
|
||||
}else{
|
||||
bSoftTriggerSelected = true;
|
||||
cancelRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* private Notification getNotification() {
|
||||
Notification.Builder builder = new Notification.Builder(this)
|
||||
.setContentTitle("连续扫描服务")
|
||||
.setContentText("正在运行");
|
||||
builder.setChannelId(notificationId);
|
||||
Notification notification = builder.build();
|
||||
return notification;
|
||||
}*/
|
||||
|
||||
//Service被启动时调用
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.i(TAG, "onStartCommand方法被调用!");
|
||||
|
||||
//setconfig();
|
||||
initScanner();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
public void setconfig(){
|
||||
Intent i = new Intent();
|
||||
i.setAction("com.symbol.datawedge.api.ACTION");
|
||||
i.putExtra("com.symbol.datawedge.api.SET_DEFAULT_PROFILE", "myProfile");
|
||||
sendBroadcast(i);
|
||||
}
|
||||
@Override
|
||||
public void onOpened(EMDKManager emdkManager) {
|
||||
updateStatus("EMDK open success!");
|
||||
this.emdkManager = emdkManager;
|
||||
// Acquire the barcode manager resources
|
||||
initBarcodeManager();
|
||||
// Enumerate scanner devices
|
||||
// enumerateScannerDevices();
|
||||
initScanner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed() {
|
||||
// Release all the resources
|
||||
if (emdkManager != null) {
|
||||
emdkManager.release();
|
||||
emdkManager = null;
|
||||
}
|
||||
updateStatus("EMDK closed unexpectedly! Please close and restart the application.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Release all the resources
|
||||
if (emdkManager != null) {
|
||||
emdkManager.release();
|
||||
emdkManager = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onData(ScanDataCollection scanDataCollection) {
|
||||
if ((scanDataCollection != null) && (scanDataCollection.getResult() == ScannerResults.SUCCESS)) {
|
||||
ArrayList<ScanDataCollection.ScanData> scanData = scanDataCollection.getScanData();
|
||||
for (ScanDataCollection.ScanData data : scanData) {
|
||||
updateData(data.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatus(StatusData statusData) {
|
||||
StatusData.ScannerStates state = statusData.getState();
|
||||
switch (state) {
|
||||
case IDLE:
|
||||
statusString = statusData.getFriendlyName() + " is enabled and idle...";
|
||||
updateStatus(statusString);
|
||||
// set trigger type
|
||||
if(bSoftTriggerSelected) {
|
||||
scanner.triggerType = Scanner.TriggerType.SOFT_ALWAYS;
|
||||
setDecoders();
|
||||
} else {
|
||||
scanner.triggerType = Scanner.TriggerType.HARD;
|
||||
cancelRead();
|
||||
}
|
||||
// submit read
|
||||
if (!scanner.isReadPending()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Log.i("jqtest:", "scan");
|
||||
scanner.read();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
updateStatus(e.getMessage());
|
||||
try {
|
||||
deInitScanner();
|
||||
Thread.sleep(200);
|
||||
}catch (Exception e1){
|
||||
e1.printStackTrace();
|
||||
}
|
||||
initScanner();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WAITING:
|
||||
statusString = "Scanner is waiting for trigger press...";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
case SCANNING:
|
||||
statusString = "Scanning...";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
case DISABLED:
|
||||
statusString = statusData.getFriendlyName() + " is disabled.";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
case ERROR:
|
||||
statusString = "An error has occurred.";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void initScanner() {
|
||||
if (scanner == null) {
|
||||
if (barcodeManager != null) {
|
||||
scanner = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT);
|
||||
} else {
|
||||
updateStatus("Failed to get the specified scanner device! Please close and restart the application.");
|
||||
return;
|
||||
}
|
||||
if (scanner != null) {
|
||||
scanner.addDataListener(this);
|
||||
scanner.addStatusListener(this);
|
||||
try {
|
||||
scanner.enable();
|
||||
} catch (ScannerException e) {
|
||||
updateStatus(e.getMessage());
|
||||
deInitScanner();
|
||||
}
|
||||
} else {
|
||||
updateStatus("Failed to initialize the scanner device.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deInitScanner() {
|
||||
if (scanner != null) {
|
||||
try {
|
||||
scanner.disable();
|
||||
} catch (Exception e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
scanner.removeDataListener(this);
|
||||
scanner.removeStatusListener(this);
|
||||
} catch (Exception e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
scanner.release();
|
||||
} catch (Exception e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
scanner = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initBarcodeManager() {
|
||||
barcodeManager = (BarcodeManager) emdkManager.getInstance(EMDKManager.FEATURE_TYPE.BARCODE);
|
||||
|
||||
}
|
||||
|
||||
private void deInitBarcodeManager() {
|
||||
if (emdkManager != null) {
|
||||
emdkManager.release(EMDKManager.FEATURE_TYPE.BARCODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* private void enumerateScannerDevices() {
|
||||
if (barcodeManager != null) {
|
||||
List<ScannerInfo> deviceList = barcodeManager.getSupportedDevicesInfo();
|
||||
if ((deviceList != null) && (deviceList.size() != 0)) {
|
||||
Iterator<ScannerInfo> it = deviceList.iterator();
|
||||
while (it.hasNext()) {
|
||||
ScannerInfo scnInfo = it.next();
|
||||
if (scnInfo.isDefaultScanner()) {
|
||||
scannerInfo = scnInfo;
|
||||
Log.i("scannerInfo", scannerInfo.getFriendlyName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private void setDecoders() {
|
||||
if (scanner != null) {
|
||||
try {
|
||||
ScannerConfig config = scanner.getConfig();
|
||||
// Set EAN8
|
||||
config.decoderParams.ean8.enabled = true;
|
||||
// Set EAN13
|
||||
config.decoderParams.ean13.enabled = true;
|
||||
// Set Code39
|
||||
config.decoderParams.code39.enabled = true;
|
||||
//Set Code128
|
||||
config.decoderParams.code128.enabled = true;
|
||||
// config.readerParams.readerSpecific.imagerSpecific.aimType = ScannerConfig.AimType.PRESENTATION;
|
||||
scanner.setConfig(config);
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelRead() {
|
||||
if (scanner != null) {
|
||||
if (scanner.isReadPending()) {
|
||||
try {
|
||||
scanner.cancelRead();
|
||||
} catch (ScannerException e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStatus(final String status) {
|
||||
//Log.i("status",status);
|
||||
// runOnUiThread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// textViewStatus.setText("" + status);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void updateData(final String result) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
Intent intent2 = new Intent("com.pda.scan.result");
|
||||
intent2.putExtra("data", result);
|
||||
sendBroadcast(intent2);
|
||||
Log.i(TAG, result);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
216
app/src/main/java/chaoran/business/utils/LocalAddressUtil.java
Normal file
@ -0,0 +1,216 @@
|
||||
package chaoran.business.utils;
|
||||
|
||||
import static androidx.core.content.ContextCompat.getSystemService;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.JavascriptInterface;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import chaoran.business.BuildConfig;
|
||||
|
||||
public class LocalAddressUtil {
|
||||
|
||||
public final static String SSO_KEY = "!~CROP@CRTECH@PDA~!";
|
||||
|
||||
private Context context;
|
||||
|
||||
private Activity activity;
|
||||
|
||||
private View view;
|
||||
|
||||
private int[] heights;
|
||||
|
||||
public LocalAddressUtil(Context context, Activity activity, View view) {
|
||||
this.context = context;
|
||||
this.activity = activity;
|
||||
this.view = view;
|
||||
this.heights = StatusBarUtil.getStatusBarHeight(context);
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getIpAddress() {
|
||||
try {
|
||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||
NetworkInterface intf = en.nextElement();
|
||||
// if(!intf.getDisplayName().equals("eth0")) continue;
|
||||
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
||||
return inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
Log.e("address: local", ex.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getMacAddress(){//可以兼容安卓7以下
|
||||
if (Build.VERSION.SDK_INT >= 34) { // Android 14 is code-named Tiramisu
|
||||
try {
|
||||
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "02:00:00:00:00:02";
|
||||
}
|
||||
}
|
||||
String macAddress = null;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
NetworkInterface networkInterface = null;
|
||||
try {
|
||||
networkInterface = NetworkInterface.getByName("eth1");
|
||||
if (networkInterface == null) {
|
||||
networkInterface = NetworkInterface.getByName("wlan0");
|
||||
}
|
||||
if (networkInterface == null) {
|
||||
return "02:00:00:00:00:02";
|
||||
}
|
||||
byte[] addr = networkInterface.getHardwareAddress();
|
||||
for (byte b : addr) {
|
||||
buf.append(String.format("%02X:", b));
|
||||
}
|
||||
if (buf.length() > 0) {
|
||||
buf.deleteCharAt(buf.length() - 1);
|
||||
}
|
||||
macAddress = buf.toString();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
return "02:00:00:00:00:02";
|
||||
}
|
||||
return macAddress;
|
||||
}
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getInfo(int type){
|
||||
String info;
|
||||
switch (type) {
|
||||
case 1: info = Build.BRAND;break;//品牌
|
||||
case 2: info = Build.MODEL;break;//型号
|
||||
case 3: info = Build.MANUFACTURER;break;//厂商
|
||||
case 4: info = Build.DEVICE;break;//设备名
|
||||
case 5: info = Build.ID;break;//设备硬件id
|
||||
// case 6: info = Build.SERIAL;break;//序列号,可能获取不到
|
||||
default: info = "";break;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getHeight(int type) {
|
||||
String info = "";
|
||||
switch (type) {
|
||||
case 1 : info = String.valueOf(this.heights[0]); break;
|
||||
case 2 : info = String.valueOf(this.heights[1]); break;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public void test(){
|
||||
Log.e("test", "MANUFACTURER=" + Build.MANUFACTURER);
|
||||
Log.e("test", "BRAND=" + Build.BRAND);
|
||||
Log.e("test", "MODEL=" + Build.MODEL);
|
||||
Log.e("test", "VERSION.RELEASE=" + Build.VERSION.RELEASE);
|
||||
Log.e("test", "VERSION.SDK_INT=" + Build.VERSION.SDK_INT);
|
||||
Log.e("test", "DEVICE=" + Build.DEVICE);
|
||||
Log.e("test", "HOST=" + Build.HOST);
|
||||
Log.e("test", "ID=" + Build.ID);
|
||||
Log.e("test", "TIME=" + Build.TIME);
|
||||
Log.e("test", "TYPE=" + Build.TYPE);
|
||||
Log.e("test", "PRODUCT=" + Build.PRODUCT);
|
||||
Log.e("test", "BOARD=" + Build.BOARD);
|
||||
Log.e("test", "DISPLAY=" + Build.DISPLAY);
|
||||
Log.e("test", "FINGERPRINT=" + Build.FINGERPRINT);
|
||||
Log.e("test", "HARDWARE=" + Build.HARDWARE);
|
||||
Log.e("test", "BOOTLOADER=" + Build.BOOTLOADER);
|
||||
Log.e("test", "TAGS=" + Build.TAGS);
|
||||
Log.e("test", "UNKNOWN=" + Build.UNKNOWN);
|
||||
Log.e("test", "USER=" + Build.USER);
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public void rotateScreen() {
|
||||
int angle = ((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
||||
|
||||
switch (angle) {
|
||||
case Surface.ROTATION_0:
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String registerMac(String applyMac) {
|
||||
try {
|
||||
String mac = this.getMacAddress();
|
||||
String md5Hash = MD5.md5(mac + SSO_KEY);
|
||||
if (md5Hash != null && md5Hash.equals(applyMac)) {
|
||||
// 将允许注册适配的mac写入文件中
|
||||
SharedPreferences.Editor editor = context.getSharedPreferences("CrtechPdaConfig", Context.MODE_PRIVATE).edit();
|
||||
editor.putString("checkMac", "success");
|
||||
editor.commit();
|
||||
return "success";
|
||||
}
|
||||
}catch (Exception ignored) {
|
||||
|
||||
}
|
||||
return "error";
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String checkMacRegister() {
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("CrtechPdaConfig", Context.MODE_PRIVATE);
|
||||
return sharedPreferences.getString("checkMac", "error");
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getApkVersion() {
|
||||
return BuildConfig.VERSION_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* 暴露PDA的厂家和型号
|
||||
* @return String 格式:厂家:型号
|
||||
*/
|
||||
@SuppressLint("JavascriptInterface")
|
||||
@JavascriptInterface
|
||||
public String getPdaInfo() {
|
||||
return Build.MANUFACTURER + ":" + Build.MODEL.toLowerCase();
|
||||
}
|
||||
}
|
||||
34
app/src/main/java/chaoran/business/utils/MD5.java
Normal file
@ -0,0 +1,34 @@
|
||||
package chaoran.business.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
// 从框架的MD5加密类拷贝过来的
|
||||
public class MD5 {
|
||||
private static final String key = "aa";
|
||||
private static final char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
public static final String md5(String s) {
|
||||
return s == null ? null : md5(s.getBytes());
|
||||
}
|
||||
|
||||
public static final String md5(byte[] bytes) {
|
||||
try {
|
||||
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
||||
mdTemp.update(bytes);
|
||||
byte[] md = mdTemp.digest();
|
||||
int j = md.length;
|
||||
char[] str = new char[j * 2];
|
||||
int k = 0;
|
||||
|
||||
for(int i = 0; i < j; ++i) {
|
||||
byte byte0 = md[i];
|
||||
str[k++] = hexDigits[byte0 >>> 4 & 15];
|
||||
str[k++] = hexDigits[byte0 & 15];
|
||||
}
|
||||
|
||||
return new String(str);
|
||||
} catch (Exception var8) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
217
app/src/main/java/chaoran/business/utils/StatusBarUtil.java
Normal file
@ -0,0 +1,217 @@
|
||||
package chaoran.business.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 状态栏工具类
|
||||
*/
|
||||
public class StatusBarUtil {
|
||||
/**
|
||||
* 修改状态栏为全透明
|
||||
*
|
||||
* @param activity
|
||||
*/
|
||||
@TargetApi(19)
|
||||
public static void transparencyBar(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window window = activity.getWindow();
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(Color.TRANSPARENT);
|
||||
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Window window = activity.getWindow();
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕的高度和状态栏高度
|
||||
* @param context
|
||||
* @return 第一个是屏幕,第二个是状态栏
|
||||
*/
|
||||
public static int[] getStatusBarHeight(Context context) {
|
||||
int[] result = new int[]{0,0};
|
||||
int resourceld = context.getResources().getIdentifier(
|
||||
"status_bar_height", "dimen", "android"
|
||||
);
|
||||
if (resourceld > 0) {
|
||||
result[0] = context.getResources().getDisplayMetrics().heightPixels;
|
||||
result[1] = context.getResources().getDimensionPixelSize(resourceld);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//隐藏状态栏
|
||||
public static void hideStatusBar(Activity activity){
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
activity.getWindow()
|
||||
.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态栏颜色,支持4.4以上版本
|
||||
*
|
||||
* @param activity
|
||||
* @param colorId
|
||||
*/
|
||||
public static void setStatusBarColor(Activity activity, int colorId) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window window = activity.getWindow();
|
||||
window.setStatusBarColor(activity.getResources().getColor(colorId));
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
//使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明
|
||||
transparencyBar(activity);
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(activity);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(colorId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态栏亮色模式,设置状态栏黑色文字、图标,
|
||||
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
|
||||
*
|
||||
* @param activity
|
||||
* @return 1:MIUUI 2:Flyme 3:android6.0
|
||||
*/
|
||||
public static int StatusBarLightMode(Activity activity) {
|
||||
int result = 0;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (MIUISetStatusBarLightMode(activity, true)) {
|
||||
result = 1;
|
||||
} else if (FlymeSetStatusBarLightMode(activity.getWindow(), true)) {
|
||||
result = 2;
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
result = 3;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 已知系统类型时,设置状态栏黑色文字、图标。
|
||||
* 适配4.4以上版本MIUIV、Flyme和6.0以上版本其他Android
|
||||
*
|
||||
* @param activity
|
||||
* @param type 1:MIUUI 2:Flyme 3:android6.0
|
||||
*/
|
||||
public static void StatusBarLightMode(Activity activity, int type) {
|
||||
if (type == 1) {
|
||||
MIUISetStatusBarLightMode(activity, true);
|
||||
} else if (type == 2) {
|
||||
FlymeSetStatusBarLightMode(activity.getWindow(), true);
|
||||
} else if (type == 3) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态栏暗色模式,清除MIUI、flyme或6.0以上版本状态栏黑色文字、图标
|
||||
*/
|
||||
public static void StatusBarDarkMode(Activity activity, int type) {
|
||||
if (type == 1) {
|
||||
MIUISetStatusBarLightMode(activity, false);
|
||||
} else if (type == 2) {
|
||||
FlymeSetStatusBarLightMode(activity.getWindow(), false);
|
||||
} else if (type == 3) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置状态栏图标为深色和魅族特定的文字风格
|
||||
* 可以用来判断是否为Flyme用户
|
||||
*
|
||||
* @param window 需要设置的窗口
|
||||
* @param dark 是否把状态栏文字及图标颜色设置为深色
|
||||
* @return boolean 成功执行返回true
|
||||
*/
|
||||
public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {
|
||||
boolean result = false;
|
||||
if (window != null) {
|
||||
try {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
Field darkFlag = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
|
||||
Field meizuFlags = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("meizuFlags");
|
||||
darkFlag.setAccessible(true);
|
||||
meizuFlags.setAccessible(true);
|
||||
int bit = darkFlag.getInt(null);
|
||||
int value = meizuFlags.getInt(lp);
|
||||
if (dark) {
|
||||
value |= bit;
|
||||
} else {
|
||||
value &= ~bit;
|
||||
}
|
||||
meizuFlags.setInt(lp, value);
|
||||
window.setAttributes(lp);
|
||||
result = true;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要MIUIV6以上
|
||||
*
|
||||
* @param activity
|
||||
* @param dark 是否把状态栏文字及图标颜色设置为深色
|
||||
* @return boolean 成功执行返回true
|
||||
*/
|
||||
public static boolean MIUISetStatusBarLightMode(Activity activity, boolean dark) {
|
||||
boolean result = false;
|
||||
Window window = activity.getWindow();
|
||||
if (window != null) {
|
||||
Class clazz = window.getClass();
|
||||
try {
|
||||
int darkModeFlag = 0;
|
||||
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
|
||||
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
|
||||
darkModeFlag = field.getInt(layoutParams);
|
||||
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
|
||||
if (dark) {
|
||||
extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
|
||||
} else {
|
||||
extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
|
||||
}
|
||||
result = true;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
//开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上
|
||||
if (dark) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
} else {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
@ -7,6 +7,50 @@
|
||||
android:id="@+id/table">
|
||||
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="隐藏状态栏:" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/hide_bar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="1:隐藏;0显示"
|
||||
android:minWidth="150dp"
|
||||
android:singleLine="true" />
|
||||
|
||||
<TextView />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="屏幕旋转:" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="150dp"
|
||||
android:id="@+id/screen_rotation"
|
||||
android:singleLine="true"
|
||||
android:hint="1:强制竖屏;2:强制横屏;3:横竖都转" />
|
||||
|
||||
<TextView />
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView />
|
||||
|
||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
BIN
app/src/main/res/raw/ding.wav
Normal file
@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:4.1.0"
|
||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||