2.13 取消监听旋转角度,使用系统自带的旋转(根据配置初始化,旋转方向:横、竖、随意)

瑞芯适配器 接入 新的型号,使用的是 ttyS8;而不是ttyS1;并且只有一个接口。
This commit is contained in:
yao-1212
2025-11-26 17:19:27 +08:00
parent 55e624111d
commit 16281e386d
10 changed files with 71 additions and 154 deletions

View File

@ -24,7 +24,6 @@
android:name=".application.InitApplication"
android:theme="@style/Theme.PdaWeb"
android:usesCleartextTraffic="true"
android:screenOrientation="user"
>
<uses-library android:name="com.symbol.emdk" android:required="false"/>
<activity

View File

@ -114,6 +114,9 @@
.radio-group .radio-group-box .radio-item {
width: calc(50% - 10px);
}
.radio-group .radio-group-box .radio-item.full {
width: 100%;
}
</style>
@ -136,13 +139,29 @@
<input id="path" name="path" placeholder="访问子路径">
</div>
<div class="radio-group">
<span>屏幕旋转</span>
<span>屏幕方向</span>
<div class="radio-group-box">
<label class="radio-item">
<input type="radio" name="screen_rotation" value="1" checked>
<input type="radio" name="screen_rotation" value="5" checked>
</label>
<label class="radio-item">
<input type="radio" name="screen_rotation" value="6" checked>
倒竖
</label>
<label class="radio-item full">
<input type="radio" name="screen_rotation" value="1" checked>
竖屏(系统可能不支持)
</label>
<label class="radio-item">
<input type="radio" name="screen_rotation" value="7">
正横
</label>
<label class="radio-item">
<input type="radio" name="screen_rotation" value="8">
倒横
</label>
<label class="radio-item full">
<input type="radio" name="screen_rotation" value="2">
横屏
</label>
@ -169,27 +188,6 @@
</label>
</div>
</div>
<div class="radio-group">
<span>默认屏幕方向</span>
<div class="radio-group-box">
<label class="radio-item">
<input type="radio" name="start_direction" value="1" checked>
正竖屏
</label>
<label class="radio-item">
<input type="radio" name="start_direction" value="2">
倒竖屏
</label>
<label class="radio-item">
<input type="radio" name="start_direction" value="3">
正横屏
</label>
<label class="radio-item">
<input type="radio" name="start_direction" value="4">
倒横屏
</label>
</div>
</div>
</div>
<div class="operation">
<button style="background: #1989fa;" onclick="saveSetting()">保存</button>
@ -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();

View File

@ -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显示"
}

View File

@ -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不能旋转1800、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) {

View File

@ -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();
}

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -103,7 +103,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="屏幕旋转" />
android:text="屏幕方向" />
<EditText
android:layout_width="wrap_content"
@ -113,36 +113,12 @@
android:singleLine="true"
android:inputType="number"
android:digits="1234"
android:hint="1:竖屏2:横屏3:横竖4:禁止" />
android:hint="5正竖;6倒竖;7正横;8倒横;1竖;2横;3横竖;4禁止" />
<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/start_direction"
android:singleLine="true"
android:inputType="number"
android:digits="1234"
android:hint="1:正竖2:倒竖3:正横4:倒横" />
<TextView />
</TableRow>
<TableRow>