Skip to content

Commit

Permalink
增加启用直接关闭换台菜单
Browse files Browse the repository at this point in the history
允许用户设置是否在换台抽屉中按返回键时直接关闭抽屉,而不是返回上一级
  • Loading branch information
Eanya-Tonic committed Oct 3, 2024
1 parent 9ef1562 commit b8f4104
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
37 changes: 26 additions & 11 deletions app/src/main/java/com/eanyatonic/cctvViewer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ public class MainActivity extends AppCompatActivity {
private int SubMenuCCTVSelectedIndex = 0;
private int SubMenuLocalSelectedIndex = 0;

// 可自定义设置项
private int TEXT_SIZE = 22;
private Boolean enableDualWebView = true;
private Boolean enableDirectChannelChange = false;
private Boolean enableDirectBack = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -155,6 +157,9 @@ protected void onCreate(Bundle savedInstanceState) {
// 读取直接频道切换设置
enableDirectChannelChange = sharedPreferences.getBoolean("direct_channel_change", false);

// 读取直接返回设置
enableDirectBack = sharedPreferences.getBoolean("direct_back", false);

// 读取双缓冲设置
enableDualWebView = sharedPreferences.getBoolean("dual_webview", true);

Expand Down Expand Up @@ -884,11 +889,16 @@ function zoomOut() {
} else if (SubMenuCCTV.hasFocus()) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_B) {
// 按下返回键
DrawerLayout.getChildAt(DrawerLayoutSelectedIndex).requestFocus();
SubMenuCCTV.setVisibility(View.GONE);
DrawerLayoutDetailed.setVisibility(View.GONE);
findViewById(R.id.CCTVScroll).setVisibility(View.GONE);
return true;
if (enableDirectBack) {
showChannelList();
return true;
} else {
DrawerLayout.getChildAt(DrawerLayoutSelectedIndex).requestFocus();
SubMenuCCTV.setVisibility(View.GONE);
DrawerLayoutDetailed.setVisibility(View.GONE);
findViewById(R.id.CCTVScroll).setVisibility(View.GONE);
return true;
}
} else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
DrawerLayout.getChildAt(DrawerLayoutSelectedIndex).requestFocus();
SubMenuCCTV.setVisibility(View.GONE);
Expand Down Expand Up @@ -925,12 +935,17 @@ function zoomOut() {
}
} else if (SubMenuLocal.hasFocus()) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_B) {
// 按下返回键
DrawerLayout.getChildAt(DrawerLayoutSelectedIndex).requestFocus();
SubMenuLocal.setVisibility(View.GONE);
DrawerLayoutDetailed.setVisibility(View.GONE);
findViewById(R.id.LocalScroll).setVisibility(View.GONE);
return true;
if (enableDirectBack) {
showChannelList();
return true;
} else {
// 按下返回键
DrawerLayout.getChildAt(DrawerLayoutSelectedIndex).requestFocus();
SubMenuLocal.setVisibility(View.GONE);
DrawerLayoutDetailed.setVisibility(View.GONE);
findViewById(R.id.LocalScroll).setVisibility(View.GONE);
return true;
}
} else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
DrawerLayout.getChildAt(DrawerLayoutSelectedIndex).requestFocus();
SubMenuLocal.setVisibility(View.GONE);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
android:summary="按上下键时,直接换台,而不是弹出换台抽屉"
android:defaultValue="false" />

<SwitchPreference
android:key="direct_back"
android:title="换台抽屉直接返回"
android:summary="在换台抽屉中按返回键时,直接关闭抽屉,而不是返回上一级"
android:defaultValue="false" />

<SwitchPreference
android:key="dual_webview"
android:title="启用双缓冲加载"
Expand Down

0 comments on commit b8f4104

Please sign in to comment.