Skip to content

Commit

Permalink
[Vision Glass] Back button when VR is not active
Browse files Browse the repository at this point in the history
Fix the issue that the Back button on the phone is not responsive
before we have entered VR mode.

The fix is to add a method onBackPressed() to PlatformActivityPlugin
which returns true if the platform activity has handled the Back press.

In the Vision Glass implementation, we use the default Back behaviour
if the user presses that button before we have started VR mode.
  • Loading branch information
felipeerias authored and svillar committed Jun 13, 2024
1 parent e34bf98 commit 2d74fe9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface PlatformActivityPluginListener {
}
abstract void onKeyboardVisibilityChange(boolean isVisible);
abstract void onVideoAvailabilityChange();
abstract boolean onBackPressed();
void registerListener(PlatformActivityPluginListener listener) {
if (mListeners == null)
mListeners = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,9 @@ private void showAppExitDialog() {
@Override
@Deprecated
public void onBackPressed() {
if (mPlatformPlugin != null && mPlatformPlugin.onBackPressed()) {
return;
}
if (mIsPresentingImmersive) {
queueRunnable(this::exitImmersiveNative);
return;
Expand Down
10 changes: 10 additions & 0 deletions app/src/visionglass/java/com/igalia/wolvic/PlatformActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ public void onLongPress(MotionEvent e) {
return mGestureDetector.onTouchEvent(event);
});
}

@Override
boolean onBackPressed() {
// User pressed Back on the phone and VR is not active, so we use the default behaviour.
if (mViewModel.getConnectionState().getValue() != PhoneUIViewModel.ConnectionState.ACTIVE) {
PlatformActivity.super.onBackPressed();
return true;
}
return false;
}
}

private final DisplayManager.DisplayListener mDisplayListener =
Expand Down

0 comments on commit 2d74fe9

Please sign in to comment.