Skip to content

Commit

Permalink
Fix more click bugs
Browse files Browse the repository at this point in the history
Also add ability to disable bossKey for full size remotes
Fix bug in loading initial GUI state from preferences
  • Loading branch information
virresh committed Mar 13, 2021
1 parent 7ebb07c commit 1a163bc
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class MouseEmulationEngine {

public static int scrollSpeed;

public static boolean isBossKeyDisabled;

private Handler timerHandler;

private Runnable previousRunnable;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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<AccessibilityWindowInfo> windowList= mService.getWindows();
boolean wasIME = false;
boolean wasIME = false, focused = false;
for (AccessibilityWindowInfo window : windowList) {
if (consumed || wasIME) {
break;
}
List<AccessibilityNodeInfo> 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<AccessibilityNodeInfo.AccessibilityAction> 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);
Expand All @@ -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);
}
}
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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());
}
Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/io/github/virresh/matvt/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout-land/activity_gui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@
</LinearLayout>

<CheckBox
android:nextFocusUp="@id/sp_mouse_icon"
android:id="@+id/cb_border_window"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -200,6 +199,18 @@
android:textColor="@color/white"
android:textSize="20sp" />

<CheckBox
android:id="@+id/cb_disable_bossKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:buttonTint="@color/white"
android:layoutDirection="rtl"
android:nextFocusUp="@id/cb_border_window"
android:text="Disable Boss Key (useful for full size remotes)"
android:textColor="@color/white"
android:textSize="20sp" />

<CheckBox
android:id="@+id/cb_override"
android:layout_width="match_parent"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_gui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@
android:textColor="@color/white"
android:textSize="20sp" />

<CheckBox
android:id="@+id/cb_disable_bossKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:buttonTint="@color/white"
android:layoutDirection="rtl"
android:nextFocusUp="@id/cb_border_window"
android:text="Disable Boss Key (useful for full size remotes)"
android:textColor="@color/white"
android:textSize="20sp" />

<CheckBox
android:id="@+id/cb_override"
android:layout_width="match_parent"
Expand Down

0 comments on commit 1a163bc

Please sign in to comment.