1.18 瑞兴平板,读取扫描结果,使用同步加锁模式
This commit is contained in:
@ -11,7 +11,7 @@ android {
|
|||||||
minSdk 28
|
minSdk 28
|
||||||
targetSdk 28
|
targetSdk 28
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.17"
|
versionName "1.18"
|
||||||
|
|
||||||
// 1.0 IDATA广播模式处理
|
// 1.0 IDATA广播模式处理
|
||||||
// 1.1 霍尼韦尔的监听修改(扫描网站二维码跳出程序,监听失效,调整)、斑马PDA广播模式设置
|
// 1.1 霍尼韦尔的监听修改(扫描网站二维码跳出程序,监听失效,调整)、斑马PDA广播模式设置
|
||||||
@ -31,6 +31,7 @@ android {
|
|||||||
// 1.15 系统状态栏根据配置进行设置
|
// 1.15 系统状态栏根据配置进行设置
|
||||||
// 1.16 idata pda 不设置模式
|
// 1.16 idata pda 不设置模式
|
||||||
// 1.17 霍尼韦尔EDA51、EDA50P,调用扫描枪的方法,在关闭的时候停止调用扫描枪
|
// 1.17 霍尼韦尔EDA51、EDA50P,调用扫描枪的方法,在关闭的时候停止调用扫描枪
|
||||||
|
// 1.18 瑞兴平板,读取扫描结果,使用同步加锁模式
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters 'armeabi-v7a'
|
abiFilters 'armeabi-v7a'
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
@ -16,6 +17,7 @@ import android.media.MediaPlayer;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.util.JsonReader;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -32,13 +34,19 @@ import androidx.appcompat.app.ActionBar;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import chaoran.business.BrandEnum;
|
import chaoran.business.BrandEnum;
|
||||||
import chaoran.business.R;
|
import chaoran.business.R;
|
||||||
import chaoran.business.adapter.*;
|
import chaoran.business.adapter.*;
|
||||||
|
import chaoran.business.engine.entity.NetworkSetting;
|
||||||
import chaoran.business.engine.impl.NetworkSettingEngine;
|
import chaoran.business.engine.impl.NetworkSettingEngine;
|
||||||
import chaoran.business.engine.SettingEngine;
|
import chaoran.business.engine.SettingEngine;
|
||||||
import chaoran.business.engine.impl.TekVoiceEngine;
|
import chaoran.business.engine.impl.TekVoiceEngine;
|
||||||
@ -62,8 +70,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
|||||||
|
|
||||||
MyOrientationDetector myOrientationDetector;
|
MyOrientationDetector myOrientationDetector;
|
||||||
|
|
||||||
private static int latestOrientation = 0; // 添加一个标志位;最后屏幕的方向
|
|
||||||
|
|
||||||
private WebView webView;
|
private WebView webView;
|
||||||
private Adapter adapter;
|
private Adapter adapter;
|
||||||
private VoiceEngine voiceEngine;
|
private VoiceEngine voiceEngine;
|
||||||
@ -86,6 +92,25 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private void initData() {
|
||||||
BrandEnum brand = BrandEnum.code(Build.MANUFACTURER);
|
BrandEnum brand = BrandEnum.code(Build.MANUFACTURER);
|
||||||
Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show();
|
||||||
@ -305,9 +330,36 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
|||||||
private String url() {
|
private String url() {
|
||||||
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
SharedPreferences spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE);
|
||||||
Integer port = spf.getInt("port", -1);
|
Integer port = spf.getInt("port", -1);
|
||||||
|
Map<String, Object> map = null;
|
||||||
if (port == -1) {
|
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";
|
return "file:///android_asset/demo/index.html";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String address = spf.getString("address", "").replaceAll(" ", "");
|
String address = spf.getString("address", "").replaceAll(" ", "");
|
||||||
String path = spf.getString("path", "").replaceAll(" ", "");
|
String path = spf.getString("path", "").replaceAll(" ", "");
|
||||||
String link = address.concat(":").concat(String.valueOf(port)).concat(path);
|
String link = address.concat(":").concat(String.valueOf(port)).concat(path);
|
||||||
@ -416,13 +468,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
|||||||
if (SCREEN_ROTATION == 1 || SCREEN_ROTATION == 3) {
|
if (SCREEN_ROTATION == 1 || SCREEN_ROTATION == 3) {
|
||||||
if (rotate == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
|
if (rotate == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
|
||||||
activity.setRequestedOrientation(rotate);
|
activity.setRequestedOrientation(rotate);
|
||||||
latestOrientation = rotate;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SCREEN_ROTATION == 2 || SCREEN_ROTATION == 3) {
|
if (SCREEN_ROTATION == 2 || SCREEN_ROTATION == 3) {
|
||||||
if (rotate == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
if (rotate == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || rotate == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
|
||||||
activity.setRequestedOrientation(rotate);
|
activity.setRequestedOrientation(rotate);
|
||||||
latestOrientation = rotate;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -431,69 +481,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*class MyOrientationDetector implements SensorEventListener {
|
|
||||||
|
|
||||||
private Activity activity;
|
|
||||||
|
|
||||||
public MyOrientationDetector(Activity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
Sensor orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
|
||||||
sensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
|
|
||||||
int angle = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
|
||||||
if (latestOrientation == angle) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (SCREEN_ROTATION == 1) {
|
|
||||||
if (Surface.ROTATION_0 == angle) {
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
||||||
latestOrientation = angle;
|
|
||||||
}else if (Surface.ROTATION_180 == angle) {
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
|
||||||
latestOrientation = angle;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}else if (SCREEN_ROTATION == 2) {
|
|
||||||
if (Surface.ROTATION_90 == angle) {
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
||||||
latestOrientation = angle;
|
|
||||||
}else if (Surface.ROTATION_270 == angle) {
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
|
||||||
latestOrientation = angle;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int tmpAngle = latestOrientation;
|
|
||||||
latestOrientation = angle;
|
|
||||||
switch (angle) {
|
|
||||||
case Surface.ROTATION_0:
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
||||||
break;
|
|
||||||
case Surface.ROTATION_90:
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
||||||
break;
|
|
||||||
case Surface.ROTATION_180:
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
|
||||||
break;
|
|
||||||
case Surface.ROTATION_270:
|
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
latestOrientation = tmpAngle;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
|||||||
@ -9,10 +9,6 @@ package chaoran.business.adapter;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
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.activity.ResultListener;
|
||||||
import chaoran.business.strategy.Strategy;
|
import chaoran.business.strategy.Strategy;
|
||||||
|
|
||||||
@ -83,18 +79,23 @@ public class RockChipAdapter implements Adapter {
|
|||||||
while (running) {
|
while (running) {
|
||||||
String data = data();
|
String data = data();
|
||||||
if (!data.equals("")) {
|
if (!data.equals("")) {
|
||||||
|
synchronized (RockChipAdapter.class) {
|
||||||
barcode[0] = barcode[0] + data;
|
barcode[0] = barcode[0] + data;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20);
|
Thread.sleep(20);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
synchronized (RockChipAdapter.class) {
|
||||||
if (!"".equals(barcode[0])) {
|
if (!"".equals(barcode[0])) {
|
||||||
|
// Log.i("listen", "Thread result data: \t\t" + barcode[0] + "\t\t" + System.currentTimeMillis());
|
||||||
resultListener.result(barcode[0]);
|
resultListener.result(barcode[0]);
|
||||||
barcode[0] = "";
|
barcode[0] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,17 +106,22 @@ public class RockChipAdapter implements Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String data() {
|
private String data() {
|
||||||
if (mFileInputStream == null) return "";
|
if (mFileInputStream == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
synchronized (RockChipAdapter.class) {
|
||||||
try {
|
try {
|
||||||
int size = mFileInputStream.available();
|
int size = mFileInputStream.available();
|
||||||
byte[] buffer = new byte[size];
|
byte[] buffer = new byte[size];
|
||||||
size = mFileInputStream.read(buffer);
|
size = mFileInputStream.read(buffer);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
return new String(buffer);
|
String data = new String(buffer);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user