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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
package org.holoeverywhere.app;
import java.util.Map;
import org.holoeverywhere.HoloEverywhere;
import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.R;
import org.holoeverywhere.internal.WindowDecorView;
import org.holoeverywhere.util.WeaklyMap;
import android.content.Context;
import android.util.TypedValue;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import com.actionbarsherlock.internal.view.menu.ContextMenuDecorView.ContextMenuListenersProvider;
import com.actionbarsherlock.internal.view.menu.ContextMenuItemWrapper;
import com.actionbarsherlock.internal.view.menu.ContextMenuListener;
import com.actionbarsherlock.internal.view.menu.ContextMenuWrapper;
import com.actionbarsherlock.view.ContextMenu;
import com.actionbarsherlock.view.MenuItem;
public class Dialog extends android.app.Dialog implements ContextMenuListener,
ContextMenuListenersProvider {
private static final int checkTheme(Context context, int theme) {
if (theme >= 0x01000000) {
return theme;
}
TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(R.attr.dialogTheme, value, true);
if (value.resourceId > 0) {
return value.resourceId;
}
return R.style.Holo_Theme_Dialog;
}
private Map<View, ContextMenuListener> mContextMenuListeners;
private WindowDecorView mDecorView;
public Dialog(Context context) {
this(context, 0);
}
public Dialog(Context context, boolean cancelable,
OnCancelListener cancelListener) {
this(context);
setCancelable(cancelable);
setOnCancelListener(cancelListener);
}
public Dialog(Context context, int theme) {
this(context, checkTheme(context, theme), -1);
setCancelable(true);
}
private Dialog(Context context, int theme, int fallback) {
super(new ContextThemeWrapperPlus(context, theme), theme);
}
@Override
public void addContentView(View view, LayoutParams params) {
if (requestDecorView(view, params, -1)) {
mDecorView.addView(view, params);
}
}
@Override
public ContextMenuListener getContextMenuListener(View view) {
if (mContextMenuListeners == null) {
return null;
}
return mContextMenuListeners.get(view);
}
@Override
public LayoutInflater getLayoutInflater() {
return LayoutInflater.from(getContext());
}
@Override
public final boolean onContextItemSelected(android.view.MenuItem item) {
return onContextItemSelected(new ContextMenuItemWrapper(item));
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (item instanceof ContextMenuItemWrapper) {
return super.onContextItemSelected(((ContextMenuItemWrapper) item)
.unwrap());
}
return false;
}
@Override
public void onContextMenuClosed(ContextMenu menu) {
if (menu instanceof ContextMenuWrapper) {
super.onContextMenuClosed(((ContextMenuWrapper) menu).unwrap());
}
}
@Override
public final void onContextMenuClosed(Menu menu) {
if (menu instanceof android.view.ContextMenu) {
onContextMenuClosed(new ContextMenuWrapper(
(android.view.ContextMenu) menu));
} else {
super.onContextMenuClosed(menu);
}
}
@Override
public final void onCreateContextMenu(android.view.ContextMenu menu,
View view, ContextMenuInfo menuInfo) {
onCreateContextMenu(new ContextMenuWrapper(menu), view, menuInfo);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view,
ContextMenuInfo menuInfo) {
if (menu instanceof ContextMenuWrapper) {
super.onCreateContextMenu(((ContextMenuWrapper) menu).unwrap(),
view, menuInfo);
}
}
@Override
public void registerForContextMenu(View view) {
if (HoloEverywhere.WRAP_TO_NATIVE_CONTEXT_MENU) {
super.registerForContextMenu(view);
} else {
registerForContextMenu(view, this);
}
}
public void registerForContextMenu(View view, ContextMenuListener listener) {
if (mContextMenuListeners == null) {
mContextMenuListeners = new WeaklyMap<View, ContextMenuListener>();
}
mContextMenuListeners.put(view, listener);
}
private boolean requestDecorView(View view, LayoutParams params, int layoutRes) {
if (mDecorView != null) {
return true;
}
mDecorView = new WindowDecorView(getContext());
mDecorView.setId(android.R.id.content);
mDecorView.setProvider(this);
if (view != null) {
mDecorView.addView(view, params);
} else if (layoutRes > 0) {
getLayoutInflater().inflate(layoutRes, mDecorView, true);
}
getWindow().setContentView(mDecorView, new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return false;
}
@Override
public void setCancelable(boolean flag) {
super.setCancelable(flag);
setCanceledOnTouchOutside(flag);
}
@Override
public void setContentView(int layoutResID) {
if (requestDecorView(null, null, layoutResID)) {
mDecorView.removeAllViewsInLayout();
getLayoutInflater().inflate(layoutResID, mDecorView, true);
}
}
@Override
public void setContentView(View view) {
setContentView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
@Override
public void setContentView(View view, LayoutParams params) {
if (requestDecorView(view, params, -1)) {
mDecorView.removeAllViewsInLayout();
mDecorView.addView(view, params);
}
}
@Override
public void unregisterForContextMenu(View view) {
if (HoloEverywhere.WRAP_TO_NATIVE_CONTEXT_MENU) {
super.unregisterForContextMenu(view);
} else {
if (mContextMenuListeners != null) {
mContextMenuListeners.remove(view);
}
}
}
}
|