Skip to content

Commit

Permalink
Merge branch 'sweenwolf-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
virresh committed Oct 10, 2021
2 parents 4a30d3a + 68b2aa4 commit 517326e
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 355 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ If you have gotten yourself in this situation, see FAQ.
- Disable Boss Key (If you have a full size remote, you don't need to keep a boss key. Info key and color buttons are sufficient, read how to use section for more info)
- Will Boss Key Toggle (When remotes don't allow long pressing, this will allow people to cycle through various modes on key press in the order: Dpad -> Mouse -> Scroll -> Dpad) `*`
- Override Activation Key (Select this to set a custom keyCode for bossKey)
- Scrolls when mouse touches the edges (thanks to [@sweenwolf](https://github.com/sweenwolf))
- Automatically detect boss key code (again thanks to [@sweenwolf](https://github.com/sweenwolf) !)

` *` Not available on FlipPhone version
`**` Not available on FlipPhones with Android 6.
Expand Down Expand Up @@ -137,7 +139,7 @@ All kinds of contributions are welcome. Two ways of contributing:

# Credits
Thanks to EVA Facial Mouse for open sourcing their code. I've taken lots of ideas from their codebase. You can check them out at https://github.com/cmauri/eva_facial_mouse
Thanks to @sweenwolf for making this app work on remotes with less buttons, and for the app icons and fully transparent cursor images
Thanks to [@sweenwolf](https://github.com/sweenwolf) for making this app work on remotes with less buttons, and for the app icons, fully transparent cursor images, boss key autodetect and autoscroll on borders!
Thanks to TechDoctorUK for making a demo video
Thanks to @hotcereal_twitter for providing more cursor images. [Link](https://gitter.im/virresh/community?at=6102e7b0d8381a2a839bbcfd).

Expand Down
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 106
versionName '1.0.6'

}

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

0 comments on commit 517326e

Please sign in to comment.