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

Commit

Permalink
Fixes UIDialog focus issues (#2351)
Browse files Browse the repository at this point in the history
* Fix focus issues in dialogs

* Refactored common behaviors to UIDialog

* Just use WorldClickListener for UIDialog dismiss
  • Loading branch information
keianhzo authored and MortimerGoro committed Nov 25, 2019
1 parent 87543c3 commit e312506
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void onCheckedChanged(RadioGroup compoundButton, @IdRes int checkedId) {
}

setChecked(checkedId, true);
compoundButton.requestFocus();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,4 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.visible = false;
}

@Override
public void show(int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

@Override
public void hide(int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.popWorldBrightness(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import org.mozilla.vrbrowser.ui.widgets.dialogs.SendTabDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.UIDialog;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.ArrayList;

public class TabsWidget extends UIDialog implements WidgetManagerDelegate.WorldClickListener {
public class TabsWidget extends UIDialog {
protected BitmapCache mBitmapCache;
protected RecyclerView mTabsList;
protected GridLayoutManager mLayoutManager;
Expand Down Expand Up @@ -136,8 +135,6 @@ private void initialize() {
mAdapter.notifyDataSetChanged();
updateSelectionMode();
});

mWidgetManager.addWorldClickListener(this);
}

public void attachToWindow(WindowWidget aWindow) {
Expand All @@ -147,9 +144,6 @@ public void attachToWindow(WindowWidget aWindow) {

@Override
public void releaseWidget() {
if (mWidgetManager != null) {
mWidgetManager.removeWorldClickListener(this);
}
super.releaseWidget();
}

Expand All @@ -158,15 +152,13 @@ public void show(int aShowFlags) {
super.show(aShowFlags);
refreshTabs();
invalidate();
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
mTabsList.requestFocusFromTouch();
}

@Override
public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);
mRenderer.clearSurface();
mWidgetManager.popWorldBrightness(this);
}

public void setTabDelegate(TabDelegate aDelegate) {
Expand Down Expand Up @@ -378,19 +370,4 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
}
}

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
if (ViewUtils.isEqualOrChildrenOf(this, oldFocus) && this.isVisible() &&
!ViewUtils.isEqualOrChildrenOf(this, newFocus)) {
onDismiss();
}
}

@Override
public void onWorldClick() {
if (this.isVisible()) {
onDismiss();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public void show(@ShowFlags int aShowFlags) {
mWidgetManager.pushBackHandler(mBackHandler);
}

setFocusableInTouchMode(false);
setFocusableInTouchMode(true);
if (aShowFlags == REQUEST_FOCUS) {
requestFocusFromTouch();
post(this::requestFocusFromTouch);
} else if (aShowFlags == CLEAR_FOCUS) {
clearFocus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public void show(@ShowFlags int aShowFlags) {
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);

ViewTreeObserver viewTreeObserver = getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
Expand All @@ -95,20 +93,6 @@ public void onGlobalLayout() {
}
}

public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);
mWidgetManager.popWorldBrightness(this);
}

// WidgetManagerDelegate.FocusChangeListener

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
if (oldFocus == this && isVisible() && findViewById(newFocus.getId()) == null) {
onDismiss();
}
}

public void setButtonsDelegate(Delegate delegate) {
mAppDialogDelegate = delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;

public class CrashDialogWidget extends UIDialog {
Expand Down Expand Up @@ -51,8 +50,6 @@ public CrashDialogWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {
private void initialize(Context aContext) {
inflate(aContext, R.layout.crash_dialog, this);

mWidgetManager.addFocusChangeListener(this);

mLearnMoreButton = findViewById(R.id.learnMoreButton);
mDoNotSendButton = findViewById(R.id.dontSendButton);
mSendDataButton = findViewById(R.id.sendDataButton);
Expand Down Expand Up @@ -106,13 +103,6 @@ private void initialize(Context aContext) {
mAudio = AudioEngine.fromContext(aContext);
}

@Override
public void releaseWidget() {
mWidgetManager.removeFocusChangeListener(this);

super.releaseWidget();
}

@Override
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.visible = false;
Expand All @@ -126,20 +116,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.crash_dialog_world_z);
}

@Override
public void show(@ShowFlags int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

@Override
public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.popWorldBrightness(this);
}

public void setCrashDialogDelegate(CrashDialogDelegate aDelegate) {
mCrashDialogDelegate = aDelegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.net.URI;

public class PermissionWidget extends UIDialog implements WidgetManagerDelegate.FocusChangeListener {
public class PermissionWidget extends UIDialog {

private TextView mPermissionMessage;
private ImageView mPermissionIcon;
Expand Down Expand Up @@ -80,20 +76,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.anchorY = 0.5f;
}

@Override
public void show(@ShowFlags int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

@Override
public void hide(@HideFlags int aHideFlag) {
super.hide(aHideFlag);

mWidgetManager.popWorldBrightness(this);
}

public void showPrompt(String aUri, PermissionType aType, GeckoSession.PermissionDelegate.Callback aCallback) {
int messageId;
int iconId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,4 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.restart_dialog_world_z);
}

@Override
public void show(int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

@Override
public void hide(int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.popWorldBrightness(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.utils.ViewUtils;

public abstract class UIDialog extends UIWidget implements WidgetManagerDelegate.FocusChangeListener {
public abstract class UIDialog extends UIWidget implements WidgetManagerDelegate.WorldClickListener {
public UIDialog(Context aContext) {
super(aContext);
initialize();
Expand All @@ -25,12 +23,12 @@ public UIDialog(Context aContext, AttributeSet aAttrs, int aDefStyle) {
}

private void initialize() {
mWidgetManager.addFocusChangeListener(this);
mWidgetManager.addWorldClickListener(this);
}

@Override
public void releaseWidget() {
mWidgetManager.removeFocusChangeListener(this);
mWidgetManager.removeWorldClickListener(this);
super.releaseWidget();
}

Expand All @@ -39,13 +37,24 @@ public boolean isDialog() {
return true;
}

// WidgetManagerDelegate.FocusChangeListener
@Override
public void show(int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

@Override
public void hide(int aHideFlags) {
super.hide(aHideFlags);

mWidgetManager.popWorldBrightness(this);
}

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
if (!ViewUtils.isEqualOrChildrenOf(this, newFocus) && isVisible()) {
public void onWorldClick() {
if (this.isVisible()) {
onDismiss();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.concurrent.Executor;

public class WhatsNewWidget extends UIDialog implements WidgetManagerDelegate.WorldClickListener {
public class WhatsNewWidget extends UIDialog {

private Accounts mAccounts;
private Runnable mSignInCallback;
Expand Down Expand Up @@ -80,22 +80,11 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_z);
}

@Override
public void show(@ShowFlags int aShowFlags) {
super.show(aShowFlags);

mWidgetManager.addWorldClickListener(this);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

@Override
public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);

SettingsStore.getInstance(getContext()).setWhatsNewDisplayed(true);

mWidgetManager.popWorldBrightness(this);
mWidgetManager.removeWorldClickListener(this);
}

private void signIn(View view) {
Expand Down Expand Up @@ -124,11 +113,4 @@ private void startBrowsing(View view) {
}
}

// WidgetManagerDelegate.WorldClickListener

@Override
public void onWorldClick() {
onDismiss();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import androidx.annotation.NonNull;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSession.PromptDelegate.ChoicePrompt.Choice;
import org.mozilla.geckoview.GeckoSession.PromptDelegate.ChoicePrompt.Type;
import org.mozilla.vrbrowser.R;
Expand Down Expand Up @@ -61,8 +60,6 @@ public ChoicePromptWidget(Context aContext, AttributeSet aAttrs, int aDefStyle)
protected void initialize(Context aContext) {
inflate(aContext, R.layout.prompt_choice, this);

mWidgetManager.addFocusChangeListener(this);

mAudio = AudioEngine.fromContext(aContext);

mLayout = findViewById(R.id.layout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public ConfirmPromptWidget(Context aContext, AttributeSet aAttrs, int aDefStyle)
protected void initialize(Context aContext) {
inflate(aContext, R.layout.prompt_confirm, this);

mWidgetManager.addFocusChangeListener(this);

mAudio = AudioEngine.fromContext(aContext);

mLayout = findViewById(R.id.layout);
Expand Down
Loading

0 comments on commit e312506

Please sign in to comment.