Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.

Commit bf4d307

Browse files
committed
double tap handler is now only on AOD screen
1 parent 193b9f3 commit bf4d307

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

app/src/main/java/org/xjiop/oneplusaoddoubletapmod/KeyService.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ public class KeyService extends AccessibilityService {
1212
private final String TAG = "DBG | KeyService";
1313

1414
private long CLICK_DELAY;
15+
private PowerManager powerManager;
16+
17+
@Override
18+
public void onCreate() {
19+
super.onCreate();
20+
21+
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
22+
}
1523

1624
@Override
1725
public void onAccessibilityEvent(AccessibilityEvent event) {
@@ -26,21 +34,24 @@ public void onInterrupt() {
2634
@Override
2735
protected boolean onKeyEvent(KeyEvent event) {
2836
//Log.d(TAG, "onKeyEvent: " + event);
37+
//Log.d(TAG, "isScreenOn: " + powerManager.isInteractive());
2938

3039
boolean result = false;
40+
boolean isScreenOn = powerManager != null && powerManager.isInteractive();
3141

32-
if(event.getKeyCode() == KeyEvent.KEYCODE_F4)
42+
if(!isScreenOn && event.getKeyCode() == KeyEvent.KEYCODE_F4)
3343
result = doubleClick();
3444

3545
return result || super.onKeyEvent(event);
3646
}
3747

3848
private boolean doubleClick() {
3949

40-
boolean result;
50+
boolean result = false;
4151

4252
long thisTime = System.currentTimeMillis();
4353
if ((thisTime - CLICK_DELAY) < 250) {
54+
//Log.d(TAG, "doubleClick");
4455

4556
CLICK_DELAY = -1;
4657
result = true;
@@ -54,11 +65,8 @@ private boolean doubleClick() {
5465
}
5566
else {
5667
CLICK_DELAY = thisTime;
57-
result = false;
5868
}
5969

60-
//Log.d(TAG, "doubleClick: " + result);
61-
6270
return result;
6371
}
6472
}

app/src/main/res/xml/key_monitor_service_config.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
xmlns:android="http://schemas.android.com/apk/res/android"
33
android:description="@string/key_service_description"
44
android:canRequestFilterKeyEvents="true"
5-
android:canRetrieveWindowContent="false"
6-
android:canRequestTouchExplorationMode="false"
75
android:notificationTimeout="100"
8-
android:accessibilityFeedbackType="feedbackGeneric"
6+
android:accessibilityFeedbackType="feedbackHaptic"
97
android:accessibilityFlags="flagRequestFilterKeyEvents" />

0 commit comments

Comments
 (0)