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

Commit

Permalink
User enum in widget show (#1352)
Browse files Browse the repository at this point in the history
* User enum in widget show

Refactored the show methods into a single method that uses a enum for readability.

* Fixed Suggestions widget show override
  • Loading branch information
keianhzo authored and bluemarvin committed Jul 5, 2019
1 parent b9e4984 commit 374f724
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.mozilla.vrbrowser.ui.widgets.TopBarWidget;
import org.mozilla.vrbrowser.ui.widgets.TrayListener;
import org.mozilla.vrbrowser.ui.widgets.TrayWidget;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.VideoProjectionMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.Widget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
Expand Down Expand Up @@ -447,7 +448,7 @@ private void handleCrashIntent(final Intent intent) {
mCrashDialog.setCrashDialogDelegate(() -> sendCrashData(intent));
}

mCrashDialog.show();
mCrashDialog.show(UIWidget.REQUEST_FOCUS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ private void handleVoiceInput() {
}
mIsInVoiceInput = true;
TelemetryWrapper.voiceInputEvent();
mVoiceSearchWidget.show(false);
mVoiceSearchWidget.show(CLEAR_FOCUS);
mWidgetPlacement.visible = false;
mWidgetManager.updateWidget(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ public void OnVoiceSearchClicked() {
mVoiceSearchWidget.hide(REMOVE_WIDGET);

} else {
mVoiceSearchWidget.show();
mVoiceSearchWidget.show(REQUEST_FOCUS);
}
}

Expand Down Expand Up @@ -881,7 +881,7 @@ public void OnShowSearchPopup() {

if (!mPopup.isVisible()) {
mPopup.updatePlacement((int)WidgetPlacement.convertPixelsToDp(getContext(), mURLBar.getWidth()));
mPopup.show();
mPopup.show(CLEAR_FOCUS);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
}

@Override
public void show() {
super.show(false);
public void show(@ShowFlags int aShowFlags) {
super.show(aShowFlags);
mList.startAnimation(mScaleUpAnimation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void toggleSettingsDialog() {
if (widget.isVisible()) {
widget.hide(REMOVE_WIDGET);
} else {
widget.show();
widget.show(REQUEST_FOCUS);
}
}

Expand All @@ -281,14 +281,14 @@ public void setTrayVisible(boolean aVisible) {

private void updateVisibility() {
if (mTrayVisible && !mKeyboardVisible) {
this.show();
this.show(REQUEST_FOCUS);
} else {
this.hide(UIWidget.KEEP_WIDGET);
}
}

@Override
public void show() {
public void show(@ShowFlags int aShowFlags) {
if (!mWidgetPlacement.visible) {
mWidgetPlacement.visible = true;
mWidgetManager.addWidget(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,28 @@ public void toggle() {
hide(REMOVE_WIDGET);

} else {
show();
show(REQUEST_FOCUS);
}
}

public void show() {
show(true);
}
@IntDef(value = { REQUEST_FOCUS, CLEAR_FOCUS })
public @interface ShowFlags {}
public static final int REQUEST_FOCUS = 0;
public static final int CLEAR_FOCUS = 1;

public void show(boolean focus) {
public void show(@ShowFlags int aShowFlags) {
if (!mWidgetPlacement.visible) {
mWidgetPlacement.visible = true;
mWidgetManager.addWidget(this);
mWidgetManager.pushBackHandler(mBackHandler);
}

if (focus) {
setFocusableInTouchMode(true);
setFocusableInTouchMode(false);
if (aShowFlags == REQUEST_FOCUS) {
requestFocusFromTouch();

} else {
clearFocus();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
}

@Override
public void show(boolean focus) {
public void show(@ShowFlags int aShowFlags) {
if (!mWidgetPlacement.visible) {
mWidgetPlacement.visible = true;
}

mWidgetManager.updateWidget(this);

if (focus) {
setFocusableInTouchMode(true);
setFocusableInTouchMode(false);
if (aShowFlags == REQUEST_FOCUS) {
requestFocusFromTouch();

} else {
clearFocus();
}
}

Expand Down Expand Up @@ -581,7 +584,7 @@ public void setNoInternetToastVisible(boolean aVisible) {
mNoInternetToast.mWidgetPlacement.parentHandle = getHandle();
}
if (aVisible && !mNoInternetToast.isVisible()) {
mNoInternetToast.show();
mNoInternetToast.show(REQUEST_FOCUS);
} else if (!aVisible && mNoInternetToast.isVisible()) {
mNoInternetToast.hide(REMOVE_WIDGET);
}
Expand All @@ -593,7 +596,7 @@ public void showAlert(String title, @NonNull String msg, @NonNull AlertCallback
mAlertPrompt.setTitle(title);
mAlertPrompt.setMessage(msg);
mAlertPrompt.setDelegate(callback);
mAlertPrompt.show();
mAlertPrompt.show(REQUEST_FOCUS);
}

// PromptDelegate
Expand All @@ -605,7 +608,7 @@ public void onAlert(GeckoSession session, String title, String msg, AlertCallbac
mAlertPrompt.setTitle(title);
mAlertPrompt.setMessage(msg);
mAlertPrompt.setDelegate(callback);
mAlertPrompt.show();
mAlertPrompt.show(REQUEST_FOCUS);
}

@Override
Expand All @@ -616,7 +619,7 @@ public void onButtonPrompt(GeckoSession session, String title, String msg, Strin
mConfirmPrompt.setMessage(msg);
mConfirmPrompt.setButtons(btnMsg);
mConfirmPrompt.setDelegate(callback);
mConfirmPrompt.show();
mConfirmPrompt.show(REQUEST_FOCUS);
}

@Override
Expand All @@ -627,7 +630,7 @@ public void onTextPrompt(GeckoSession session, String title, String msg, String
mTextPrompt.setMessage(msg);
mTextPrompt.setDefaultText(value);
mTextPrompt.setDelegate(callback);
mTextPrompt.show();
mTextPrompt.show(REQUEST_FOCUS);
}

@Override
Expand All @@ -637,7 +640,7 @@ public void onAuthPrompt(GeckoSession session, String title, String msg, AuthOpt
mAuthPrompt.setTitle(title);
mAuthPrompt.setMessage(msg);
mAuthPrompt.setAuthOptions(options, callback);
mAuthPrompt.show();
mAuthPrompt.show(REQUEST_FOCUS);
}

@Override
Expand All @@ -649,7 +652,7 @@ public void onChoicePrompt(GeckoSession session, String title, String msg, int t
mChoicePrompt.setChoices(choices);
mChoicePrompt.setMenuType(type);
mChoicePrompt.setDelegate(callback);
mChoicePrompt.show();
mChoicePrompt.show(REQUEST_FOCUS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
}

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

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
}

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

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public void showPrompt(String aUri, PermissionType aType, GeckoSession.Permissio
mPermissionMessage.setText(str);
mPermissionIcon.setImageResource(iconId);

show();
show(REQUEST_FOCUS);
}

String getRequesterName(String aUri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
}

if (granted) {
show();
show(REQUEST_FOCUS);

} else {
super.show(true);
super.show(REQUEST_FOCUS);
setPermissionNotGranted();
}
}
}

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

setStartListeningState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ protected void onDismiss() {
}

@Override
public void show() {
show(true);
public void show(@ShowFlags int aShowFlags) {
show(aShowFlags);
for (int i = 0; i < mListItems.length; i++) {
mList.setItemChecked(i, mListItems[i].mChoice.selected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {


@Override
public void show() {
public void show(@ShowFlags int aShowFlags) {
mLayout.measure(View.MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mWidgetPlacement.height = (int)(mLayout.getMeasuredHeight()/mWidgetPlacement.density);
super.show();
super.show(aShowFlags);

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);

ViewTreeObserver viewTreeObserver = mLayout.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
Expand All @@ -84,11 +86,6 @@ public void onGlobalLayout() {
}
}

public void show(boolean focus) {
super.show(focus);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}

public void hide(@HideFlags int aHideFlags) {
super.hide(aHideFlags);
mWidgetManager.popWorldBrightness(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ public void onGlobalFocusChanged(View oldFocus, View newFocus) {
}

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

mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}
Expand Down Expand Up @@ -413,10 +413,10 @@ public void showRestartDialog() {
if (widget == null) {
widget = createChild(RestartDialogWidget.class, false);
mRestartDialogHandle = widget.getHandle();
widget.setDelegate(this::show);
widget.setDelegate(() -> show(REQUEST_FOCUS));
}

widget.show();
widget.show(REQUEST_FOCUS);
}

@Override
Expand All @@ -427,13 +427,13 @@ public void showAlert(String aTitle, String aMessage) {
if (widget == null) {
widget = createChild(AlertPromptWidget.class, false);
mAlertDialogHandle = widget.getHandle();
widget.setDelegate(this::show);
widget.setDelegate(() -> show(REQUEST_FOCUS));
}
widget.getPlacement().translationZ = 0;
widget.getPlacement().parentHandle = mHandle;
widget.setTitle(aTitle);
widget.setMessage(aMessage);

widget.show();
widget.show(REQUEST_FOCUS);
}
}

0 comments on commit 374f724

Please sign in to comment.