Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Boss Key Detection Method #20

Merged
merged 2 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "io.github.virresh.matvt"
minSdkVersion 24
targetSdkVersion 29
versionCode 105
versionName '1.0.5'
versionCode 107
versionName '1.0.7'

}

Expand All @@ -29,6 +29,6 @@ android {

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:screenOrientation="sensorLandscape"
android:name=".gui.GuiActivity"
android:launchMode="singleTop">
<intent-filter>
Expand All @@ -28,7 +29,10 @@
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>

<activity
android:screenOrientation="sensorLandscape"
android:name=".helper.KeyDetection"
android:launchMode="singleTop"/>
<service
android:name=".services.MouseEventService"
android:label="Mouse Toggle Service"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.virresh.matvt.engine.impl;

import static io.github.virresh.matvt.helper.Helper.helperContext;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.content.Context;
Expand All @@ -11,8 +13,10 @@
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand All @@ -25,11 +29,13 @@
import java.util.Map;
import java.util.Set;

import io.github.virresh.matvt.helper.Helper;
import io.github.virresh.matvt.view.MouseCursorView;
import io.github.virresh.matvt.view.OverlayView;

public class MouseEmulationEngine {

private static boolean DPAD_SELECT_PRESSED = false;
private static String LOG_TAG = "MOUSE_EMULATION";

CountDownTimer waitToChange;
Expand All @@ -43,6 +49,8 @@ public class MouseEmulationEngine {

private final PointerControl mPointerControl;

public static int stuckAtSide = 0;

private int momentumStack;

private boolean isEnabled;
Expand All @@ -57,6 +65,8 @@ public class MouseEmulationEngine {

private Handler timerHandler;

private Point DPAD_Center_Init_Point = new Point();

private Runnable previousRunnable;

// tells which keycodes correspond to which pointer movement in scroll and movement mode
Expand Down Expand Up @@ -165,6 +175,23 @@ public void run() {
timerHandler.postDelayed(previousRunnable, 0);
}

private void createSwipeForSingle (final PointF originPoint, final int direction) {
if (previousRunnable != null) {
detachPreviousTimer();
}
previousRunnable = new Runnable() {
@Override
public void run() {
mPointerControl.reappear();
mService.dispatchGesture(createSwipe(originPoint, direction, 20 + momentumStack), null, null);
momentumStack += 1;
timerHandler.postDelayed(this, 30);
}
};
timerHandler.postDelayed(previousRunnable, 0);
}


/**
* Auto Disappear mouse after some duration and reset momentum
*/
Expand Down Expand Up @@ -282,16 +309,18 @@ else if (keyEvent.getKeyCode() == bossKey && isBossKeyDisabled) {
boolean consumed = false;
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN){
if (scrollCodeMap.containsKey(keyEvent.getKeyCode())) {
if (isInScrollMode || colorSet.contains(keyEvent.getKeyCode())) {
if (isInScrollMode || colorSet.contains(keyEvent.getKeyCode()))
attachGesture(mPointerControl.getPointerLocation(), scrollCodeMap.get(keyEvent.getKeyCode()));
}
else if (movementCodeMap.containsKey(keyEvent.getKeyCode())){
else if (!isInScrollMode && stuckAtSide != 0 && keyEvent.getKeyCode() == stuckAtSide)
createSwipeForSingle(mPointerControl.getCenterPointOfView(), scrollCodeMap.get(keyEvent.getKeyCode()));
else if (movementCodeMap.containsKey(keyEvent.getKeyCode()))
attachTimer(movementCodeMap.get(keyEvent.getKeyCode()));
}
consumed = true;
}
else if(keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
// just consume this event to prevent propagation
DPAD_Center_Init_Point = new Point((int) mPointerControl.getPointerLocation().x, (int) mPointerControl.getPointerLocation().y);
DPAD_SELECT_PRESSED = true;
consumed = true;
}
}
Expand All @@ -304,50 +333,63 @@ else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
consumed = true;
}
else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
DPAD_SELECT_PRESSED = false;
detachPreviousTimer();
// if (keyEvent.getEventTime() - keyEvent.getDownTime() > 500) {
// unreliable long click event if button was pressed for more than 500 ms
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, 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 || focused) {
break;
};
AccessibilityNodeInfo hitNode = nodeHierarchy.get(i);
List<AccessibilityNodeInfo.AccessibilityAction> availableActions = hitNode.getActionList();
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);
// }
// if (hitNode.isFocused() && availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK)){
// consumed = hitNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
// }
if (window.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) {
wasIME = true;
consumed = hitNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
if (DPAD_Center_Init_Point.equals(pInt)) {
List<AccessibilityWindowInfo> windowList = mService.getWindows();
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 || focused) {
break;
}
;
AccessibilityNodeInfo hitNode = nodeHierarchy.get(i);
List<AccessibilityNodeInfo.AccessibilityAction> availableActions = hitNode.getActionList();
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);
}
if (hitNode.isFocused() && availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK)) {
consumed = hitNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
if (window.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD && !(hitNode.getPackageName()).toString().contains("leankeyboard")) {
if (hitNode.getPackageName().equals("com.amazon.tv.ime") && keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && helperContext != null) {
InputMethodManager imm = (InputMethodManager) helperContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
consumed = wasIME = true;
} else {
wasIME = true;
consumed = hitNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
break;
}

if ((hitNode.getPackageName().equals("com.google.android.tvlauncher")
&& availableActions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK))) {
if (hitNode.isFocusable()) {
focused = hitNode.performAction(AccessibilityNodeInfo.FOCUS_INPUT);
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);
}
consumed = hitNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}
if (!consumed && !wasIME) {
mService.dispatchGesture(createClick(mPointerControl.getPointerLocation(), keyEvent.getEventTime() - keyEvent.getDownTime()), null, null);
}
}
if (!consumed && !wasIME) {
mService.dispatchGesture(createClick(mPointerControl.getPointerLocation(), keyEvent.getEventTime() - keyEvent.getDownTime()), null, null);
else{
//Implement Drag Function here
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import android.graphics.PointF;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

import androidx.annotation.NonNull;

import io.github.virresh.matvt.helper.Helper;
import io.github.virresh.matvt.view.MouseCursorView;
import io.github.virresh.matvt.view.OverlayView;

Expand Down Expand Up @@ -66,6 +66,7 @@ public void reappear () {
public static boolean isBordered = false;

public void move (int direction, int momentum) {

int movementX = (int) (dirX[direction] * ((momentum)));
int movementY = (int) (dirY[direction] * ((momentum)));

Expand All @@ -87,21 +88,30 @@ public void move (int direction, int momentum) {
}

else {
MouseEmulationEngine.stuckAtSide = 0;

if (mPointerLocation.x + movementX >= 0 && mPointerLocation.x + movementX <= mPointerLayerView.getWidth())
mPointerLocation.x += movementX;
else {
if (mPointerLocation.x < (mPointerLayerView.getWidth() / 2f))
if (mPointerLocation.x < (mPointerLayerView.getWidth() / 2f)) {
MouseEmulationEngine.stuckAtSide = KeyEvent.KEYCODE_DPAD_LEFT;
mPointerLocation.x = 0;
else mPointerLocation.x = mPointerLayerView.getWidth();
}
else {
MouseEmulationEngine.stuckAtSide = KeyEvent.KEYCODE_DPAD_RIGHT;
mPointerLocation.x = mPointerLayerView.getWidth();
}
}

if (mPointerLocation.y + movementY >= 0 && mPointerLocation.y + movementY <= mPointerLayerView.getHeight())
mPointerLocation.y += movementY;
else {
if (mPointerLocation.y < (mPointerLayerView.getHeight() / 2f)) {
MouseEmulationEngine.stuckAtSide = KeyEvent.KEYCODE_DPAD_UP;
mPointerLocation.y = 0;
} else mPointerLocation.y = mPointerLayerView.getHeight();
} else {
MouseEmulationEngine.stuckAtSide = KeyEvent.KEYCODE_DPAD_DOWN;
mPointerLocation.y = mPointerLayerView.getHeight();
}
}
}

Expand All @@ -112,4 +122,8 @@ public void move (int direction, int momentum) {
PointF getPointerLocation() {
return mPointerLocation;
}

PointF getCenterPointOfView() {
return new PointF(mPointerLayerView.getWidth() / 2f,mPointerLayerView.getWidth() / 2f);
}
}
Loading