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

Commit

Permalink
Fixes keyboard focus issue after pause/resume (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Jun 14, 2019
1 parent 8a7cb54 commit 1493260
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.view.KeyEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;

import org.mozilla.gecko.util.ThreadUtils;
Expand Down Expand Up @@ -158,6 +159,16 @@ private boolean callOnAudioManager(Consumer<AudioManager> fn) {
return false;
}

private ViewTreeObserver.OnGlobalFocusChangeListener globalFocusListener = new ViewTreeObserver.OnGlobalFocusChangeListener() {
@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
Log.d(LOGTAG, "======> OnGlobalFocusChangeListener: old(" + oldFocus + ") new(" + newFocus + ")");
for (FocusChangeListener listener: mFocusChangeListeners) {
listener.onGlobalFocusChanged(oldFocus, newFocus);
}
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
// Fix for infinite restart on startup crashes.
Expand Down Expand Up @@ -203,13 +214,6 @@ protected void onCreate(Bundle savedInstanceState) {

mWidgets = new HashMap<>();
mWidgetContainer = new FrameLayout(this);
mWidgetContainer.getViewTreeObserver().addOnGlobalFocusChangeListener((oldFocus, newFocus) -> {
Log.d(LOGTAG, "======> OnGlobalFocusChangeListener: old(" + oldFocus + ") new(" + newFocus + ")");
for (FocusChangeListener listener: mFocusChangeListeners) {
listener.onGlobalFocusChanged(oldFocus, newFocus);
}
});


mPermissionDelegate = new PermissionDelegate(this, this);

Expand Down Expand Up @@ -314,11 +318,13 @@ protected void onPause() {
if (mOffscreenDisplay != null) {
mOffscreenDisplay.onPause();
}
mWidgetContainer.getViewTreeObserver().removeOnGlobalFocusChangeListener(globalFocusListener);
super.onPause();
}

@Override
protected void onResume() {
mWidgetContainer.getViewTreeObserver().addOnGlobalFocusChangeListener(globalFocusListener);
if (mOffscreenDisplay != null) {
mOffscreenDisplay.onResume();
}
Expand Down

0 comments on commit 1493260

Please sign in to comment.