-
Notifications
You must be signed in to change notification settings - Fork 215
/
UIDialog.java
97 lines (74 loc) · 2.32 KB
/
UIDialog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.mozilla.vrbrowser.ui.widgets.dialogs;
import android.content.Context;
import android.util.AttributeSet;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import java.util.LinkedList;
public abstract class UIDialog extends UIWidget implements WidgetManagerDelegate.WorldClickListener {
private static LinkedList<UIDialog> mDialogs = new LinkedList<>();
public UIDialog(Context aContext) {
super(aContext);
initialize();
}
public UIDialog(Context aContext, AttributeSet aAttrs) {
super(aContext, aAttrs);
initialize();
}
public UIDialog(Context aContext, AttributeSet aAttrs, int aDefStyle) {
super(aContext, aAttrs, aDefStyle);
initialize();
}
private void initialize() {
mWidgetManager.addWorldClickListener(this);
}
@Override
public void releaseWidget() {
mWidgetManager.removeWorldClickListener(this);
super.releaseWidget();
}
@Override
public boolean isDialog() {
return true;
}
@Override
public void show(int aShowFlags) {
if (!isVisible()) {
super.show(aShowFlags);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
UIDialog head = mDialogs.peek();
if (head != null && head.isVisible()) {
head.hide();
}
mDialogs.push(this);
}
}
@Override
public void hide(int aHideFlags) {
super.hide(aHideFlags);
mWidgetManager.popWorldBrightness(this);
mDialogs.remove(this);
UIDialog head = mDialogs.peek();
if (head != null) {
head.show();
}
}
private void show() {
if (!isVisible()) {
super.show(REQUEST_FOCUS);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
}
}
private void hide() {
super.hide(KEEP_WIDGET);
mWidgetManager.popWorldBrightness(this);
}
@Override
public void onWorldClick() {
if (isVisible()) {
post(this::onDismiss);
}
}
public static void closeAllDialogs() {
new LinkedList<>(mDialogs).forEach(dialog -> dialog.onDismiss());
}
}