From 16281e386de4f7199cf117ee062db78e8c89e290 Mon Sep 17 00:00:00 2001 From: yao-1212 <59220794+yao-1212@users.noreply.github.com> Date: Wed, 26 Nov 2025 17:19:27 +0800 Subject: [PATCH] =?UTF-8?q?2.13=20=E5=8F=96=E6=B6=88=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=87=AA=E5=B8=A6=E7=9A=84=E6=97=8B=E8=BD=AC?= =?UTF-8?q?=EF=BC=88=E6=A0=B9=E6=8D=AE=E9=85=8D=E7=BD=AE=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=97=8B=E8=BD=AC=E6=96=B9=E5=90=91=EF=BC=9A?= =?UTF-8?q?=E6=A8=AA=E3=80=81=E7=AB=96=E3=80=81=E9=9A=8F=E6=84=8F=EF=BC=89?= =?UTF-8?q?=20=20=20=20=20=20=E7=91=9E=E8=8A=AF=E9=80=82=E9=85=8D=E5=99=A8?= =?UTF-8?q?=20=E6=8E=A5=E5=85=A5=20=E6=96=B0=E7=9A=84=E5=9E=8B=E5=8F=B7?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=E7=9A=84=E6=98=AF=20ttyS8=EF=BC=9B?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AFttyS1=EF=BC=9B=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 1 - app/src/main/assets/demo/index.html | 50 ++++---- app/src/main/assets/init.json | 5 +- .../business/activity/MainActivity.java | 112 +++++------------- .../activity/NetworkSettingActivity.java | 5 +- .../business/adapter/RockChipAdapter.java | 8 +- .../engine/entity/NetworkSetting.java | 8 -- .../engine/impl/NetworkSettingEngine.java | 4 +- .../res/layout/activity_setting_network.xml | 28 +---- 10 files changed, 71 insertions(+), 154 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a14a889..2db739d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { minSdk 28 targetSdk 28 versionCode 1 - versionName "2.12" + versionName "2.13" // 1.0 IDATA广播模式处理 // 1.1 霍尼韦尔的监听修改(扫描网站二维码跳出程序,监听失效,调整)、斑马PDA广播模式设置 @@ -47,6 +47,8 @@ android { // 2.10 再次添加了init.json文件,进行初始化ip等参数 // 2.11 优化了保存配置的时候,重新加载页面方法,去设置初始化屏幕方向,已经init.json中添加了字段备注信息 // 2.12 群创科技接入广播模式 中山市古镇人民医院 蒋凡 + // 2.13 取消监听旋转角度,使用系统自带的旋转(根据配置初始化,旋转方向:横、竖、随意) + // 瑞芯适配器 接入 新的型号,使用的是 ttyS8;而不是ttyS1;并且只有一个接口。 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { abiFilters 'armeabi-v7a' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 550c03d..e048d10 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,7 +24,6 @@ android:name=".application.InitApplication" android:theme="@style/Theme.PdaWeb" android:usesCleartextTraffic="true" - android:screenOrientation="user" > @@ -136,13 +139,29 @@
- 屏幕旋转 + 屏幕方向
+ + + + @@ -169,27 +188,6 @@
-
- 默认屏幕方向 -
- - - - -
-
@@ -209,7 +207,6 @@ document.getElementById('path').value = d.path; document.querySelector('input[name="screen_rotation"][value="'+d.screen_rotation+'"]').checked = true; document.querySelector('input[name="hide_bar"][value="'+d.hide_bar+'"]').checked = true; - document.querySelector('input[name="start_direction"][value="'+d.start_direction+'"]').checked = true; console.log("d_data_end_========================="); } } @@ -222,8 +219,7 @@ "port":document.getElementById('port').value, "path":document.getElementById('path').value, "screen_rotation":document.querySelector('input[name="screen_rotation"]:checked').value, - "hide_bar":document.querySelector('input[name="hide_bar"]:checked').value, - "start_direction":document.querySelector('input[name="start_direction"]:checked').value, + "hide_bar":document.querySelector('input[name="hide_bar"]:checked').value }); window.NetworkSettingEngine.saveSetting(data); window.View.reload(); diff --git a/app/src/main/assets/init.json b/app/src/main/assets/init.json index eda6bda..fc77855 100644 --- a/app/src/main/assets/init.json +++ b/app/src/main/assets/init.json @@ -3,7 +3,6 @@ "_ip":"ip地址", "_port":"端口号", "_path":"访问路径", - "_screen_rotation":"屏幕旋转:1竖、2横、3横竖、4禁止", - "_hide_bar":"状态拦:1隐藏、2显示", - "_start_direction":"默认屏幕方向:1正竖、2倒竖、3正横、4倒横" + "_screen_rotation":"屏幕方向:5正竖;6倒竖;7正横;8倒横;1竖;2横;3横竖;4禁止", + "_hide_bar":"状态拦:1隐藏、2显示" } \ No newline at end of file diff --git a/app/src/main/java/chaoran/business/activity/MainActivity.java b/app/src/main/java/chaoran/business/activity/MainActivity.java index b9ea98c..2180214 100644 --- a/app/src/main/java/chaoran/business/activity/MainActivity.java +++ b/app/src/main/java/chaoran/business/activity/MainActivity.java @@ -70,9 +70,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ public static int SCREEN_ROTATION = 3; // 屏幕旋转的设置 public static int hideBar = 0; // 屏幕旋转的设置 - public static int startDirection = 1; // 初始化屏幕方向 - - MyOrientationDetector myOrientationDetector; private WebView webView; private Adapter adapter; @@ -97,9 +94,27 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ //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(); + // 取消监听屏幕方向,使用用户的,等出现了问题再来调整;之前有一款pda系统旋转有bug +// this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE); + if (SCREEN_ROTATION == 1) { + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);//竖 + }else if (SCREEN_ROTATION == 2) { + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);//横 + }else if (SCREEN_ROTATION == 3){ + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);//随便 + }else if (SCREEN_ROTATION == 5) { // 正竖 + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + }else if (SCREEN_ROTATION == 6) {// 倒竖 + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); + }else if (SCREEN_ROTATION == 7) {// 正横 + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); + }else if (SCREEN_ROTATION == 8) {// 倒横 + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + }else { + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); // 禁止 + } +// myOrientationDetector = new MyOrientationDetector(this, this); +// myOrientationDetector.enable(); } @@ -310,22 +325,20 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ // voiceEngine.reload(); super.onResume(); if (adapter != null) { - myOrientationDetector.disable(); - myOrientationDetector.enable(); adapter.stop2(); adapter.start(); } - int rotate = 1; - if (startDirection == 1) { - rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏 - }else if (startDirection == 2) { - rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; // 倒竖屏 - }else if (startDirection == 3) { - rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; // 正横屏 - }else if (startDirection == 4) { - rotate = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 倒横屏 - } - this.setRequestedOrientation(rotate); +// int rotate = 1; +// if (startDirection == 1) { +// rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏 +// }else if (startDirection == 2) { +// rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; // 倒竖屏 +// }else if (startDirection == 3) { +// rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; // 正横屏 +// }else if (startDirection == 4) { +// rotate = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 倒横屏 +// } +// this.setRequestedOrientation(rotate); } @Override @@ -358,7 +371,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ vibrator.cancel(); } completionListener = null; - myOrientationDetector.disable(); } @Override @@ -400,7 +412,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ 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", "0").toString())); - initData.setStart_direction(Integer.parseInt(map.getOrDefault("start_direction", "1").toString())); settingEngine.saveSetting(initData); spf = this.getSharedPreferences("crtech", Context.MODE_PRIVATE); port = initData.getPort(); @@ -421,24 +432,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ String link = address.concat(":").concat(String.valueOf(port)).concat(path); SCREEN_ROTATION = spf.getInt("screen_rotation", 3); hideBar = spf.getInt("hide_bar", 0); - startDirection = spf.getInt("start_direction", 1); return link.startsWith("http://") ? link : "http://".concat(link); } @JavascriptInterface public void reload() { - // 第一次设置,点击保存,初始化屏幕方向问题 - int rotate = 1; - if (startDirection == 1) { - rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏 - }else if (startDirection == 2) { - rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; // 倒竖屏 - }else if (startDirection == 3) { - rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; // 正横屏 - }else if (startDirection == 4) { - rotate = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 倒横屏 - } - this.setRequestedOrientation(rotate); runOnUiThread(() -> { webView.loadUrl(url()); }); @@ -504,52 +502,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{ }); } - /* 监听角度的变化 */ - 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) { diff --git a/app/src/main/java/chaoran/business/activity/NetworkSettingActivity.java b/app/src/main/java/chaoran/business/activity/NetworkSettingActivity.java index a9c366a..8b1227c 100644 --- a/app/src/main/java/chaoran/business/activity/NetworkSettingActivity.java +++ b/app/src/main/java/chaoran/business/activity/NetworkSettingActivity.java @@ -19,7 +19,7 @@ import chaoran.business.R; public class NetworkSettingActivity extends AppCompatActivity { - private EditText address, path, port, screen_rotation, hide_bar,start_direction; + private EditText address, path, port, screen_rotation, hide_bar; private Button save, cancel; @Override @@ -37,7 +37,6 @@ public class NetworkSettingActivity extends AppCompatActivity { port = findViewById(R.id.port); screen_rotation = findViewById(R.id.screen_rotation); hide_bar = findViewById(R.id.hide_bar); - start_direction = findViewById(R.id.start_direction); save = findViewById(R.id.save); cancel = findViewById(R.id.cancel); SharedPreferences sharedPreferences = this.getSharedPreferences("crtech", Context.MODE_PRIVATE); @@ -46,7 +45,6 @@ public class NetworkSettingActivity extends AppCompatActivity { 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))); - start_direction.setText(String.valueOf(sharedPreferences.getInt("start_direction", 1))); cancel.setOnClickListener((e) -> this.finish()); save.setOnClickListener((e) -> saveSetting()); } @@ -58,7 +56,6 @@ public class NetworkSettingActivity extends AppCompatActivity { 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.putInt("start_direction", Integer.parseInt(start_direction.getText().toString().trim())); editor.commit(); this.finish(); } diff --git a/app/src/main/java/chaoran/business/adapter/RockChipAdapter.java b/app/src/main/java/chaoran/business/adapter/RockChipAdapter.java index 0433b2b..64b1164 100644 --- a/app/src/main/java/chaoran/business/adapter/RockChipAdapter.java +++ b/app/src/main/java/chaoran/business/adapter/RockChipAdapter.java @@ -9,6 +9,8 @@ package chaoran.business.adapter; import android.content.Context; +import android.os.Build; + import chaoran.business.activity.ResultListener; import chaoran.business.strategy.Strategy; @@ -40,7 +42,11 @@ public class RockChipAdapter implements Adapter { public RockChipAdapter(Context context, ResultListener resultListener) { this.resultListener = resultListener; this.context = context; - this.strategy = new Reader(new File("/dev/ttyS1"), 115200, 0); + String fileName = "/dev/ttyS1"; + if (Build.MODEL.equalsIgnoreCase("rk3568_r")) { + fileName = "/dev/ttyS8"; + } + this.strategy = new Reader(new File(fileName), 115200, 0); } public class Reader implements Strategy { diff --git a/app/src/main/java/chaoran/business/engine/entity/NetworkSetting.java b/app/src/main/java/chaoran/business/engine/entity/NetworkSetting.java index 2aeba5e..6ce663f 100644 --- a/app/src/main/java/chaoran/business/engine/entity/NetworkSetting.java +++ b/app/src/main/java/chaoran/business/engine/entity/NetworkSetting.java @@ -15,7 +15,6 @@ public class NetworkSetting extends Setting { private Integer screen_rotation; private Integer hide_bar; - private Integer start_direction; public String getAddress() { return address; @@ -57,11 +56,4 @@ public class NetworkSetting extends Setting { this.hide_bar = hide_bar; } - public Integer getStart_direction() { - return start_direction; - } - - public void setStart_direction(Integer start_direction) { - this.start_direction = start_direction; - } } \ No newline at end of file diff --git a/app/src/main/java/chaoran/business/engine/impl/NetworkSettingEngine.java b/app/src/main/java/chaoran/business/engine/impl/NetworkSettingEngine.java index b008b9f..47b2fa2 100644 --- a/app/src/main/java/chaoran/business/engine/impl/NetworkSettingEngine.java +++ b/app/src/main/java/chaoran/business/engine/impl/NetworkSettingEngine.java @@ -46,7 +46,6 @@ public class NetworkSettingEngine implements SettingEngine { networkSetting.setPath(path); networkSetting.setScreen_rotation(screen_rotation); networkSetting.setHide_bar(spf.getInt("hide_bar", 0)); - networkSetting.setStart_direction(spf.getInt("start_direction", 0)); return networkSetting; } @@ -59,11 +58,10 @@ public class NetworkSettingEngine implements SettingEngine { editor.putInt("port", networkSetting.getPort()); editor.putInt("screen_rotation", networkSetting.getScreen_rotation()); editor.putInt("hide_bar", networkSetting.getHide_bar()); - editor.putInt("start_direction", networkSetting.getStart_direction()); editor.commit(); MainActivity.SCREEN_ROTATION = networkSetting.getScreen_rotation(); MainActivity.hideBar = networkSetting.getHide_bar(); - MainActivity.startDirection = networkSetting.getStart_direction(); +// MainActivity.startDirection = networkSetting.getStart_direction(); return true; } diff --git a/app/src/main/res/layout/activity_setting_network.xml b/app/src/main/res/layout/activity_setting_network.xml index 6f4dfc7..2d8e620 100644 --- a/app/src/main/res/layout/activity_setting_network.xml +++ b/app/src/main/res/layout/activity_setting_network.xml @@ -103,7 +103,7 @@ + android:text="屏幕方向:" /> + android:hint="5正竖;6倒竖;7正横;8倒横;1竖;2横;3横竖;4禁止" /> - - - - - - - - - - -