Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e220d29
Author: Twaik Yont <[email protected]>
Date:   Mon Jul 15 22:30:07 2024 +0300

    Make changing xrMode preference restart activity to apply changes.

commit 1cc9125
Author: Twaik Yont <[email protected]>
Date:   Mon Jul 15 21:12:59 2024 +0300

    Fixing Back key in Settings on Meta Oculus devices

commit 647e787
Author: Twaik Yont <[email protected]>
Date:   Mon Jul 15 21:08:43 2024 +0300

    Fixing KeyInterceptor collapsing notification bar
  • Loading branch information
ewt45 committed Jul 18, 2024
1 parent d3bc0ef commit fab13e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/termux/x11/LoriePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == android.R.id.home) {
onBackPressed();
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
finish();
else
onBackPressed();

return true;
}

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public class MainActivity extends AppCompatActivity implements View.OnApplyWindo

public static Prefs prefs = null;

private static boolean oldFullscreen = false;
private static boolean oldHideCutout = false;
private static boolean oldFullscreen = false, oldHideCutout = false, oldXrMode = false;
private final SharedPreferences.OnSharedPreferenceChangeListener preferencesChangedListener = (__, key) -> onPreferencesChanged(key);

private final BroadcastReceiver receiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -162,6 +161,7 @@ protected void onCreate(Bundle savedInstanceState) {

oldFullscreen = prefs.fullscreen.get();
oldHideCutout = prefs.hideCutout.get();
oldXrMode = prefs.xrMode.get();

prefs.get().registerOnSharedPreferenceChangeListener(preferencesChangedListener);

Expand Down Expand Up @@ -514,6 +514,12 @@ void tryConnect() {
void onPreferencesChanged(String key) {
prefs.recheckStoringSecondaryDisplayPreferences();

if (oldXrMode != prefs.xrMode.get() && XrActivity.isSupported() &&
prefs.xrMode.get() != this instanceof XrActivity) {
startActivity(Intent.makeRestartActivityTask(getComponentName()));
finish();
}

if ("additionalKbdVisible".equals(key))
return;

Expand Down
25 changes: 22 additions & 3 deletions app/src/main/java/com/termux/x11/utils/KeyInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.view.KeyEvent;
import android.view.accessibility.AccessibilityEvent;
Expand All @@ -17,6 +19,7 @@
public class KeyInterceptor extends AccessibilityService {
LinkedHashSet<Integer> pressedKeys = new LinkedHashSet<>();

private static final Handler handler = new Handler(Looper.getMainLooper());
private static KeyInterceptor self;
private static boolean launchedAutomatically = false;
private boolean enabled = false;
Expand Down Expand Up @@ -60,13 +63,29 @@ public static boolean isLaunched() {
return info != null && info.getId() != null;
}

private static final Runnable disableImmediatelyCallback = KeyInterceptor::disableImmediately;
private static void disableImmediately() {
if (self == null)
return;

android.util.Log.d("KeyInterceptor", "disabling interception service");
self.setServiceInfo(new AccessibilityServiceInfo() {{ flags = DEFAULT; }});
self.enabled = false;
}

public static void recheck() {
MainActivity a = MainActivity.getInstance();
boolean shouldBeEnabled = (a != null && self != null) && (a.hasWindowFocus() || !self.pressedKeys.isEmpty());
if (self != null && shouldBeEnabled != self.enabled) {
android.util.Log.d("KeyInterceptor", (shouldBeEnabled ? "en" : "dis") + "abling interception");
self.setServiceInfo(new AccessibilityServiceInfo() {{ flags = shouldBeEnabled ? FLAG_REQUEST_FILTER_KEY_EVENTS : DEFAULT; }});
self.enabled = shouldBeEnabled;
if (shouldBeEnabled) {
handler.removeCallbacks(disableImmediatelyCallback);
android.util.Log.d("KeyInterceptor", "enabling interception service");
self.setServiceInfo(new AccessibilityServiceInfo() {{ flags = FLAG_REQUEST_FILTER_KEY_EVENTS; }});
self.enabled = true;
} else
// In the case if service info is changed Android current dragging processes
// so it is impossible to pull notification bar or call recents screen by swiping activity up.
handler.postDelayed(disableImmediatelyCallback, 120000);
}
}

Expand Down

0 comments on commit fab13e2

Please sign in to comment.