diff --git a/app/src/main/java/io/github/virresh/matvt/engine/impl/MouseEmulationEngine.java b/app/src/main/java/io/github/virresh/matvt/engine/impl/MouseEmulationEngine.java index e99aefa..44d86ab 100644 --- a/app/src/main/java/io/github/virresh/matvt/engine/impl/MouseEmulationEngine.java +++ b/app/src/main/java/io/github/virresh/matvt/engine/impl/MouseEmulationEngine.java @@ -49,6 +49,8 @@ public class MouseEmulationEngine { public static int scrollSpeed; + public static boolean isBossKeyDisabled; + private Handler timerHandler; private Runnable previousRunnable; @@ -199,7 +201,7 @@ private static GestureDescription createSwipe (PointF originPoint, int direction public boolean perform (KeyEvent keyEvent) { // toggle mouse mode if going via bossKey - if (keyEvent.getKeyCode() == bossKey) { + if (keyEvent.getKeyCode() == bossKey && !isBossKeyDisabled) { if (keyEvent.getAction() == KeyEvent.ACTION_UP) { if (waitToChange != null) { // cancel change countdown @@ -217,6 +219,10 @@ public boolean perform (KeyEvent keyEvent) { } } } + else if (keyEvent.getKeyCode() == bossKey) { + // bossKey is set to disabled, let system do it's thing + return false; + } // keep full functionality on full size remotes if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_INFO) { if (this.isEnabled) { @@ -269,18 +275,20 @@ else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) { int action = AccessibilityNodeInfo.ACTION_CLICK; Point pInt = new Point((int) mPointerControl.getPointerLocation().x, (int) mPointerControl.getPointerLocation().y); List windowList= mService.getWindows(); - boolean wasIME = false; + boolean wasIME = false, focused = false; for (AccessibilityWindowInfo window : windowList) { if (consumed || wasIME) { break; } List nodeHierarchy = findNode(window.getRoot(), action, pInt); for (int i=nodeHierarchy.size()-1; i>=0; i--){ - if (consumed) return consumed; + if (consumed || focused) { + break; + }; AccessibilityNodeInfo hitNode = nodeHierarchy.get(i); List availableActions = hitNode.getActionList(); - if (availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_FOCUS)){ - hitNode.performAction(AccessibilityNodeInfo.FOCUS_INPUT); + if (availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS)){ + focused = hitNode.performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); } // if (hitNode.isFocused() && availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_SELECT)){ // hitNode.performAction(AccessibilityNodeInfo.ACTION_SELECT); @@ -294,12 +302,16 @@ else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) { break; } - if (hitNode.getPackageName().equals("com.google.android.tvlauncher") && availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK)) { + if ((hitNode.getPackageName().equals("com.google.android.tvlauncher") + && availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK))) { + if (hitNode.isFocusable()) { + focused = hitNode.performAction(AccessibilityNodeInfo.FOCUS_INPUT); + } consumed = hitNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); } } } - if (!consumed || !wasIME) { + if (!consumed && !wasIME) { mService.dispatchGesture(createClick(mPointerControl.getPointerLocation(), keyEvent.getEventTime() - keyEvent.getDownTime()), null, null); } } diff --git a/app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java b/app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java index 8ec95bb..dadeb43 100644 --- a/app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java +++ b/app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java @@ -28,6 +28,7 @@ import java.util.List; import io.github.virresh.matvt.R; +import io.github.virresh.matvt.engine.impl.MouseEmulationEngine; import io.github.virresh.matvt.engine.impl.PointerControl; import io.github.virresh.matvt.helper.Helper; @@ -36,7 +37,7 @@ public class GuiActivity extends AppCompatActivity { CountDownTimer repopulate; - CheckBox cb_override, cb_mouse_bordered; + CheckBox cb_override, cb_mouse_bordered, cb_disable_bossKey; TextView gui_acc_perm, gui_acc_serv, gui_overlay_perm, gui_overlay_serv; EditText et_override; @@ -63,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState) { et_override = findViewById(R.id.et_override); cb_override = findViewById(R.id.cb_override); cb_mouse_bordered = findViewById(R.id.cb_border_window); + cb_disable_bossKey = findViewById(R.id.cb_disable_bossKey); sp_mouse_icon = findViewById(R.id.sp_mouse_icon); dsbar_mouse_size = findViewById(R.id.dsbar_mouse_size); dsbar_scroll_speed = findViewById(R.id.dsbar_mouse_scspeed); @@ -144,6 +146,11 @@ public void onStopTrackingTouch(SeekBar seekBar) {} PointerControl.isBordered = b; }); + cb_disable_bossKey.setOnCheckedChangeListener(((compoundButton, value) -> { + Helper.setBossKeyDisabled(getApplicationContext(), value); + MouseEmulationEngine.isBossKeyDisabled = value; + })); + populateText(); findViewById(R.id.gui_setup_perm).setOnClickListener(view -> askPermissions()); } @@ -163,6 +170,12 @@ private void checkValues(IconStyleSpinnerAdapter adapter) { int scrollSpeed = Helper.getScrollSpeed(ctx); dsbar_scroll_speed.setProgress(Math.max(Math.min(scrollSpeed, dsbar_scroll_speed.getMax()), 0)); + + boolean bordered = Helper.getMouseBordered(ctx); + cb_mouse_bordered.setChecked(bordered); + + boolean bossKeyStatus = Helper.isBossKeyDisabled(ctx); + cb_disable_bossKey.setChecked(bossKeyStatus); } private void showBossLayout(boolean status) { diff --git a/app/src/main/java/io/github/virresh/matvt/helper/Helper.java b/app/src/main/java/io/github/virresh/matvt/helper/Helper.java index c1654e4..cae5a83 100644 --- a/app/src/main/java/io/github/virresh/matvt/helper/Helper.java +++ b/app/src/main/java/io/github/virresh/matvt/helper/Helper.java @@ -19,6 +19,7 @@ public class Helper { static final String PREF_KEY_MOUSE_SIZE = "MOUSE_SIZE"; static final String PREF_KEY_SCROLL_SPEED = "SCROLL_SPEED"; static final String PREF_KEY_MOUSE_BORDERED = "MOUSE_BORDERED"; + static final String PREF_KEY_CB_DISABLE_BOSSKEY = "DISABLE_BOSSKEY"; public static boolean isAccessibilityDisabled(Context ctx) { return !isAccServiceInstalled(ctx.getPackageName() + "/.services.MouseEventService", ctx); @@ -125,4 +126,17 @@ public static boolean getMouseBordered(Context ctx) { return sp.getBoolean(PREF_KEY_MOUSE_BORDERED, false); } + @SuppressLint("ApplySharedPref") + public static void setBossKeyDisabled(Context ctx, Boolean val) { + SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putBoolean(PREF_KEY_CB_DISABLE_BOSSKEY, val); + editor.commit(); + } + + public static boolean isBossKeyDisabled(Context ctx) { + SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE); + return sp.getBoolean(PREF_KEY_CB_DISABLE_BOSSKEY, false); + } + } diff --git a/app/src/main/java/io/github/virresh/matvt/services/MouseEventService.java b/app/src/main/java/io/github/virresh/matvt/services/MouseEventService.java index 74c45da..47ca1d3 100644 --- a/app/src/main/java/io/github/virresh/matvt/services/MouseEventService.java +++ b/app/src/main/java/io/github/virresh/matvt/services/MouseEventService.java @@ -43,6 +43,7 @@ protected void onServiceConnected() { bossKey = KeyEvent.KEYCODE_VOLUME_MUTE; PointerControl.isBordered = Helper.getMouseBordered(this); scrollSpeed = Helper.getScrollSpeed(this); + MouseEmulationEngine.isBossKeyDisabled = Helper.isBossKeyDisabled(this); if (Helper.isOverriding(this)) bossKey = Helper.getOverrideValue(this); if (Settings.canDrawOverlays(this)) init(); } diff --git a/app/src/main/res/layout-land/activity_gui.xml b/app/src/main/res/layout-land/activity_gui.xml index 32b2b05..d6f6f4d 100644 --- a/app/src/main/res/layout-land/activity_gui.xml +++ b/app/src/main/res/layout-land/activity_gui.xml @@ -189,7 +189,6 @@ + + + +