This source file includes following definitions.
- attachWindow
- getAttachedWindow
- detachWindow
- destroy
- registerWindowConsumer
- registerWindow
- removeWindowConsumer
- detachWindow
- noticeIconified
- noticeDeiconified
- copyWindows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.gnu.emacs;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import android.app.ActivityOptions;
26 import android.content.Intent;
27 import android.os.Build;
28 import android.util.Log;
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 public final class EmacsWindowAttachmentManager
55 {
56 private final static String TAG = "EmacsWindowAttachmentManager";
57
58
59 public static final EmacsWindowAttachmentManager MANAGER;
60
61 static
62 {
63 MANAGER = new EmacsWindowAttachmentManager ();
64 };
65
66 public interface WindowConsumer
67 {
68 public void attachWindow (EmacsWindow window);
69 public EmacsWindow getAttachedWindow ();
70 public void detachWindow ();
71 public void destroy ();
72 };
73
74
75 public List<WindowConsumer> consumers;
76
77
78 public List<EmacsWindow> windows;
79
80 public
81 EmacsWindowAttachmentManager ()
82 {
83 consumers = new ArrayList<WindowConsumer> ();
84 windows = new ArrayList<EmacsWindow> ();
85 }
86
87 public void
88 registerWindowConsumer (WindowConsumer consumer)
89 {
90 Log.d (TAG, "registerWindowConsumer " + consumer);
91
92 consumers.add (consumer);
93
94 for (EmacsWindow window : windows)
95 {
96 if (window.getAttachedConsumer () == null)
97 {
98 Log.d (TAG, "registerWindowConsumer: attaching " + window);
99 consumer.attachWindow (window);
100 return;
101 }
102 }
103
104 Log.d (TAG, "registerWindowConsumer: sendWindowAction 0, 0");
105 EmacsNative.sendWindowAction ((short) 0, 0);
106 }
107
108 public synchronized void
109 registerWindow (EmacsWindow window)
110 {
111 Intent intent;
112 ActivityOptions options;
113
114 Log.d (TAG, "registerWindow (maybe): " + window);
115
116 if (windows.contains (window))
117
118 return;
119
120 Log.d (TAG, "registerWindow: " + window);
121
122 windows.add (window);
123
124 for (WindowConsumer consumer : consumers)
125 {
126 if (consumer.getAttachedWindow () == null)
127 {
128 Log.d (TAG, "registerWindow: attaching " + consumer);
129 consumer.attachWindow (window);
130 return;
131 }
132 }
133
134 intent = new Intent (EmacsService.SERVICE,
135 EmacsMultitaskActivity.class);
136 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_DOCUMENT
137 | Intent.FLAG_ACTIVITY_NEW_TASK
138 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
139
140 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
141 EmacsService.SERVICE.startActivity (intent);
142 else
143 {
144
145 options = ActivityOptions.makeBasic ();
146 options.setLaunchBounds (window.getGeometry ());
147 EmacsService.SERVICE.startActivity (intent,
148 options.toBundle ());
149 }
150
151 Log.d (TAG, "registerWindow: startActivity");
152 }
153
154 public void
155 removeWindowConsumer (WindowConsumer consumer, boolean isFinishing)
156 {
157 EmacsWindow window;
158
159 Log.d (TAG, "removeWindowConsumer " + consumer);
160
161 window = consumer.getAttachedWindow ();
162
163 if (window != null)
164 {
165 Log.d (TAG, "removeWindowConsumer: detaching " + window);
166
167 consumer.detachWindow ();
168 window.onActivityDetached (isFinishing);
169 }
170
171 Log.d (TAG, "removeWindowConsumer: removing " + consumer);
172 consumers.remove (consumer);
173 }
174
175 public synchronized void
176 detachWindow (EmacsWindow window)
177 {
178 WindowConsumer consumer;
179
180 Log.d (TAG, "detachWindow " + window);
181
182 if (window.getAttachedConsumer () != null)
183 {
184 consumer = window.getAttachedConsumer ();
185
186 Log.d (TAG, "detachWindow: removing" + consumer);
187
188 consumers.remove (consumer);
189 consumer.destroy ();
190 }
191
192 windows.remove (window);
193 }
194
195 public void
196 noticeIconified (WindowConsumer consumer)
197 {
198 EmacsWindow window;
199
200 Log.d (TAG, "noticeIconified " + consumer);
201
202
203
204 window = consumer.getAttachedWindow ();
205
206 if (window != null)
207 window.noticeIconified ();
208 }
209
210 public void
211 noticeDeiconified (WindowConsumer consumer)
212 {
213 EmacsWindow window;
214
215 Log.d (TAG, "noticeDeiconified " + consumer);
216
217
218
219 window = consumer.getAttachedWindow ();
220
221 if (window != null)
222 window.noticeDeiconified ();
223 }
224
225 public synchronized List<EmacsWindow>
226 copyWindows ()
227 {
228 return new ArrayList<EmacsWindow> (windows);
229 }
230 };