|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: VideoControl is used to control the display of video. |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.microedition.media.control; |
|
19 |
|
20 import javax.microedition.media.Player; |
|
21 import javax.microedition.media.MediaException; |
|
22 import javax.microedition.lcdui.Canvas; |
|
23 import javax.microedition.lcdui.Display; |
|
24 import javax.microedition.midlet.MIDlet; |
|
25 import com.nokia.microedition.media.NativeError; |
|
26 |
|
27 //import com.symbian.midp.runtime.MIDletExecutor; |
|
28 import com.nokia.mj.impl.media.PlayerPermission; |
|
29 import com.nokia.mj.impl.rt.support.ApplicationUtils; |
|
30 |
|
31 |
|
32 import javax.microedition.lcdui.Displayable; |
|
33 import javax.microedition.lcdui.Display; |
|
34 //import com.symbian.midp.runtime.MIDletInstance; |
|
35 |
|
36 //import com.symbian.midp.runtime.ToolkitInvoker; |
|
37 |
|
38 import com.nokia.mj.impl.rt.support.Finalizer; |
|
39 import com.nokia.mj.impl.utils.Logger; |
|
40 |
|
41 // MMAPI 3.x UI req. |
|
42 import com.nokia.microedition.media.*; |
|
43 |
|
44 import org.eclipse.swt.*; |
|
45 import org.eclipse.swt.widgets.*; |
|
46 import javax.microedition.lcdui.*; |
|
47 import org.eclipse.ercp.swt.mobile.MobileShell; |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 public class VideoControl |
|
53 extends ControlImpl |
|
54 implements javax.microedition.media.control.VideoControl |
|
55 { |
|
56 private static final String GUI_OBJECT_CLASS_NAME = |
|
57 "javax.microedition.lcdui.Item"; |
|
58 private static final int NOT_INITIALIZED = -1; |
|
59 private static final int ERROR_ARGUMENT = -6; // KErrArgument |
|
60 |
|
61 // use contans to avoid making native methods |
|
62 // which has same prototypes |
|
63 |
|
64 // getter constants for native side |
|
65 private static final int PROPERTY_DISPLAY_WIDTH = 1; |
|
66 private static final int PROPERTY_DISPLAY_HEIGHT = 2; |
|
67 private static final int PROPERTY_DISPLAY_X = 3; |
|
68 private static final int PROPERTY_DISPLAY_Y = 4; |
|
69 private static final int PROPERTY_SOURCE_WIDTH = 5; |
|
70 private static final int PROPERTY_SOURCE_HEIGHT = 6; |
|
71 |
|
72 // setter constants for native side |
|
73 private static final int SET_DISPLAY_SIZE = 20; |
|
74 private static final int SET_DISPLAY_LOCATION = 21; |
|
75 private static final int SET_DISPLAY_VISIBLE_TRUE = 22; |
|
76 private static final int SET_DISPLAY_VISIBLE_FALSE = 23; |
|
77 private static final int SET_DISPLAY_FULLSCREEN_TRUE = 24; |
|
78 private static final int SET_DISPLAY_FULLSCREEN_FALSE = 25; |
|
79 |
|
80 // MMA API defines return values like 'return value is undefined' |
|
81 // then UNDEFINED_RETURN_VALUE is returned |
|
82 private static final int UNDEFINED_RETURN_VALUE = 0; |
|
83 |
|
84 // class name used with dynamic display mode initialization |
|
85 private static String GUI_FACTORY_CLASS_NAME = ".Factory"; |
|
86 |
|
87 // lcdui package used with UiToolkitRegister |
|
88 private static String LCDUI_PACKAGE = |
|
89 "javax.microedition.lcdui"; |
|
90 |
|
91 // eswt package used with UiToolkitRegister |
|
92 private static String ESWT_PACKAGE = "org.eclipse.swt.widgets"; |
|
93 |
|
94 // ToolkitRegister class name used with eswt and lcdui |
|
95 private static String DISPLAY = ".Display"; |
|
96 |
|
97 // class name used to check if eswt is included |
|
98 private static String LISTENER = ".Listener"; |
|
99 |
|
100 // class name used to check if eswt is included |
|
101 private static String ESWT_CONTROL = ".control"; |
|
102 |
|
103 protected int iStatus = NOT_INITIALIZED; |
|
104 |
|
105 // Needed for getting native handle from lcdui components |
|
106 //com.symbian.midp.runtime.ToolkitInvoker iToolkitInvoker; |
|
107 |
|
108 private VideoItem iVideoItem; |
|
109 private Canvas iVideoCanvas; |
|
110 |
|
111 BaseDisplay display; |
|
112 // private MIDletInstance iMIDletInstance; |
|
113 |
|
114 // error code used asynchronous native calls |
|
115 private int iError; |
|
116 |
|
117 // used in asynchronous getSnapshot method |
|
118 private byte[] iImageData; |
|
119 private int iToolkitHandle = 0; |
|
120 |
|
121 // toolkit, stored as object as we don't have access to Toolkit class. |
|
122 private Object iToolkit; |
|
123 // for midlet foreground statelistening |
|
124 //ToolkitInvoker iTlkitInvoker; |
|
125 |
|
126 private Finalizer mFinalizer = new Finalizer() |
|
127 { |
|
128 public void finalizeImpl() |
|
129 { |
|
130 doFinalize(); |
|
131 } |
|
132 }; |
|
133 |
|
134 public VideoControl() |
|
135 { |
|
136 // iToolkitInvoker = com.symbian.midp.runtime.ToolkitInvoker.getToolkitInvoker(); |
|
137 // lcduiinvoker = new com.nokia.microedition.volumekeys.MMAPILCDUIInvokerImpl(); |
|
138 // eswtObserver = new MMAPIeSWTObserver(); |
|
139 } |
|
140 |
|
141 private void doFinalize() |
|
142 { |
|
143 if (mFinalizer != null) |
|
144 { |
|
145 registeredFinalize(); |
|
146 mFinalizer = null; |
|
147 } |
|
148 } |
|
149 |
|
150 final void registeredFinalize() |
|
151 { |
|
152 if (iVideoItem != null) |
|
153 { |
|
154 iPlayer.removePlayerListener(iVideoItem); |
|
155 iVideoItem.iNativeHandle = 0; |
|
156 } |
|
157 } |
|
158 |
|
159 public void setHandles(Player aPlayer, int aEventSource, int aControlHandle) |
|
160 { |
|
161 iPlayer = aPlayer; |
|
162 iEventSource = aEventSource; |
|
163 iControlHandle = aControlHandle; |
|
164 iToolkitHandle = 0; // TODO: remove once implementation is done. |
|
165 int error = _construct(iControlHandle, |
|
166 aEventSource, |
|
167 iToolkitHandle); |
|
168 |
|
169 NativeError.check(error); |
|
170 } |
|
171 |
|
172 /** |
|
173 * from Interface VideoControl |
|
174 * |
|
175 */ |
|
176 public void setDisplaySize(int aWidth, int aHeight) throws MediaException |
|
177 { |
|
178 // checkState(); |
|
179 |
|
180 if (iStatus == NOT_INITIALIZED) |
|
181 { |
|
182 throw new IllegalStateException( |
|
183 "VideoControl.initDisplayMode() not called yet"); |
|
184 } |
|
185 if (aWidth <= 0 || aHeight <= 0) |
|
186 { |
|
187 throw new IllegalArgumentException( |
|
188 "Width and height must be positive"); |
|
189 } |
|
190 |
|
191 |
|
192 |
|
193 System.out.println("before display.setDisplaySize()"); |
|
194 |
|
195 |
|
196 //canvasdisplay.setDisplaySize( aWidth, aHeight); |
|
197 display.setDisplaySize( aWidth, aHeight); |
|
198 |
|
199 System.out.println("after display.setDisplaySize()"); |
|
200 /* |
|
201 int ret = setDisplayProperty(aWidth, aHeight, SET_DISPLAY_SIZE); |
|
202 if (ret < 0) |
|
203 { |
|
204 throw new MediaException("setDisplaySize() failed, SymbianOS error: " |
|
205 + ret); |
|
206 } |
|
207 if (iStatus == USE_GUI_PRIMITIVE && |
|
208 iVideoItem != null) // with dynamic display mode item can be null |
|
209 { |
|
210 iVideoItem.privateInvalidate(); |
|
211 } |
|
212 |
|
213 */ |
|
214 } |
|
215 |
|
216 /** |
|
217 * from Interface VideoControl |
|
218 * |
|
219 */ |
|
220 public void setDisplayFullScreen(boolean aFullScreenMode) throws MediaException |
|
221 { |
|
222 // checkState(); |
|
223 if (iStatus == NOT_INITIALIZED) |
|
224 { |
|
225 throw new IllegalStateException( |
|
226 "VideoControl.initDisplayMode() not called yet"); |
|
227 } |
|
228 /* |
|
229 int ret; |
|
230 if (aFullScreenMode) |
|
231 { |
|
232 ret = setDisplayProperty(SET_DISPLAY_FULLSCREEN_TRUE); |
|
233 } |
|
234 else |
|
235 { |
|
236 ret = setDisplayProperty(SET_DISPLAY_FULLSCREEN_FALSE); |
|
237 } |
|
238 |
|
239 if (ret < 0) |
|
240 { |
|
241 throw new MediaException(); |
|
242 } |
|
243 |
|
244 */ |
|
245 System.out.println("inside setDisplayFullScreen()"); |
|
246 //canvasdisplay.setDisplayFullScreen( aFullScreenMode); |
|
247 display.setDisplayFullScreen( aFullScreenMode); |
|
248 |
|
249 |
|
250 } |
|
251 |
|
252 /** |
|
253 * from Interface VideoControl |
|
254 * |
|
255 */ |
|
256 public void setDisplayLocation(int aX, int aY) |
|
257 { |
|
258 // checkState(); |
|
259 System.out.println("VideoControl.java :: setDisplayLocation x, y = " + aX + ","+ aY); |
|
260 if (iStatus == USE_GUI_PRIMITIVE) |
|
261 { |
|
262 // In USE_GUI_PRIMITIVE mode, this call will be ignored. |
|
263 return; |
|
264 } |
|
265 if (iStatus != USE_DIRECT_VIDEO) |
|
266 { |
|
267 // This method only works when the USE_DIRECT_VIDEO mode is set. |
|
268 throw new IllegalStateException(); |
|
269 } |
|
270 /* |
|
271 // cannot fail -> ignore return value |
|
272 setDisplayProperty(aX, aY, SET_DISPLAY_LOCATION); |
|
273 */ |
|
274 |
|
275 System.out.println("inside setDisplayLocation()"); |
|
276 //canvasdisplay.setDisplayLocation( aX , aY); |
|
277 display.setDisplayLocation( aX , aY); |
|
278 |
|
279 } |
|
280 |
|
281 /** |
|
282 * from Interface VideoControl |
|
283 * |
|
284 */ |
|
285 public void setVisible(boolean aVisible) |
|
286 { |
|
287 // checkState(); |
|
288 if (iStatus == NOT_INITIALIZED) |
|
289 { |
|
290 throw new IllegalStateException( |
|
291 "VideoControl.initDisplayMode() not called yet"); |
|
292 } |
|
293 /*if (aVisible) |
|
294 { |
|
295 // Update the foreground or background state of the midlet before |
|
296 // setting the visibility of the control |
|
297 updateForeground(); |
|
298 // cannot fail -> ignore return value |
|
299 setDisplayProperty(SET_DISPLAY_VISIBLE_TRUE); |
|
300 } |
|
301 else |
|
302 { |
|
303 // cannot fail -> ignore return value |
|
304 setDisplayProperty(SET_DISPLAY_VISIBLE_FALSE); |
|
305 } |
|
306 */ |
|
307 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, |
|
308 " before display.setVisible()"); |
|
309 System.out.println("inside setVisible()"); |
|
310 if(aVisible) |
|
311 { |
|
312 // set the Midlet BG/FG status to native |
|
313 updateForeground(); |
|
314 } |
|
315 display.setVisible( aVisible ); |
|
316 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, |
|
317 "after display.setVisible()"); |
|
318 |
|
319 |
|
320 |
|
321 } |
|
322 |
|
323 /** |
|
324 * from Interface VideoControl |
|
325 * |
|
326 */ |
|
327 public int getDisplayWidth() |
|
328 {/* |
|
329 checkState(); |
|
330 if (iStatus == NOT_INITIALIZED) |
|
331 { |
|
332 throw new IllegalStateException( |
|
333 "VideoControl.initDisplayMode() not called yet"); |
|
334 } |
|
335 int width = getControlProperty(PROPERTY_DISPLAY_WIDTH); |
|
336 return width; |
|
337 */ |
|
338 //return canvasdisplay.getDisplayWidth( ); |
|
339 return display.getDisplayWidth( ); |
|
340 } |
|
341 |
|
342 /** |
|
343 * from Interface VideoControl |
|
344 * |
|
345 */ |
|
346 public int getDisplayHeight() |
|
347 { |
|
348 /* checkState(); |
|
349 if (iStatus == NOT_INITIALIZED) |
|
350 { |
|
351 throw new IllegalStateException( |
|
352 "VideoControl.initDisplayMode() not called yet"); |
|
353 } |
|
354 int height = getControlProperty(PROPERTY_DISPLAY_HEIGHT); |
|
355 return height; |
|
356 |
|
357 */ |
|
358 return display.getDisplayHeight( ); |
|
359 } |
|
360 |
|
361 /** |
|
362 * from Interface VideoControl |
|
363 * |
|
364 */ |
|
365 public int getDisplayX() |
|
366 { |
|
367 /* checkState(); |
|
368 if (iStatus == NOT_INITIALIZED) |
|
369 { |
|
370 return UNDEFINED_RETURN_VALUE; |
|
371 } |
|
372 int x = getControlProperty(PROPERTY_DISPLAY_X); |
|
373 return x; |
|
374 */ |
|
375 return display.getDisplayX( ); |
|
376 } |
|
377 |
|
378 /** |
|
379 * from Interface VideoControl |
|
380 * |
|
381 */ |
|
382 public int getDisplayY() |
|
383 { |
|
384 /* |
|
385 checkState(); |
|
386 if (iStatus == NOT_INITIALIZED) |
|
387 { |
|
388 return UNDEFINED_RETURN_VALUE; |
|
389 } |
|
390 int y = getControlProperty(PROPERTY_DISPLAY_Y); |
|
391 return y; |
|
392 |
|
393 */ |
|
394 return display.getDisplayY( ); |
|
395 } |
|
396 |
|
397 /** |
|
398 * from Interface VideoControl |
|
399 * |
|
400 */ |
|
401 public int getSourceWidth() |
|
402 { |
|
403 /* checkState(); |
|
404 int width = getControlProperty(PROPERTY_SOURCE_WIDTH); |
|
405 if (width <= 0) |
|
406 { |
|
407 width = 1; |
|
408 } |
|
409 return width; |
|
410 |
|
411 */ |
|
412 return display.getSourceWidth( ); |
|
413 } |
|
414 |
|
415 /** |
|
416 * from Interface VideoControl |
|
417 * |
|
418 */ |
|
419 public int getSourceHeight() |
|
420 { |
|
421 /*checkState(); |
|
422 int height = getControlProperty(PROPERTY_SOURCE_HEIGHT); |
|
423 if (height <= 0) |
|
424 { |
|
425 height = 1; |
|
426 } |
|
427 return height; |
|
428 */ |
|
429 return display.getSourceHeight( ); |
|
430 |
|
431 } |
|
432 |
|
433 /** |
|
434 * from Interface VideoControl |
|
435 * |
|
436 */ |
|
437 synchronized public byte[] getSnapshot(String aImageType) throws MediaException |
|
438 { |
|
439 checkState(); |
|
440 if (iStatus == NOT_INITIALIZED) |
|
441 { |
|
442 throw new IllegalStateException( |
|
443 "VideoControl.initDisplayMode() not called yet"); |
|
444 } |
|
445 |
|
446 // starts native side. Native will release wait lock if |
|
447 // _getSnapshot doesn't leave. |
|
448 int error = _getSnapshot(iControlHandle, |
|
449 iEventSource, aImageType); |
|
450 if (error == ERROR_ARGUMENT) |
|
451 { |
|
452 throw new MediaException("Unsupported image type: " + aImageType); |
|
453 } |
|
454 else if (error < 0) |
|
455 { |
|
456 throw new MediaException("getSnapshot() failed, Symbian OS error: " + error); |
|
457 } |
|
458 |
|
459 synchronized (this) |
|
460 { |
|
461 try |
|
462 { |
|
463 // wait native side |
|
464 wait(); |
|
465 } |
|
466 catch (Exception e) |
|
467 { |
|
468 throw new MediaException("" + e); |
|
469 } |
|
470 } |
|
471 if (iError < 0) |
|
472 { |
|
473 throw new MediaException("Symbian OS error: " + iError); |
|
474 } |
|
475 |
|
476 // Check the permission here, so 'the moment' is not lost? |
|
477 //Security.ensurePermission(PERMISSION, PERMISSION, PERM_ARGS); |
|
478 ApplicationUtils appUtils = ApplicationUtils.getInstance(); |
|
479 PlayerPermission per = new PlayerPermission("audio/video recording","snapshot"); |
|
480 appUtils.checkPermission(per); |
|
481 |
|
482 return iImageData; |
|
483 } |
|
484 |
|
485 /** |
|
486 * from Interface VideoControl |
|
487 * |
|
488 */ |
|
489 public Object initDisplayMode(int aMode, Object aArg) |
|
490 { |
|
491 checkState(); |
|
492 if (iStatus != NOT_INITIALIZED) |
|
493 { |
|
494 // IllegalStateException - Thrown if initDisplayMode is |
|
495 // called again after it has previously been called successfully. |
|
496 throw new IllegalStateException( |
|
497 "initDisplayMode() already called successfully"); |
|
498 } |
|
499 |
|
500 if (aMode == USE_GUI_PRIMITIVE) |
|
501 { |
|
502 Object guiObject = null; |
|
503 if (aArg == null) |
|
504 { |
|
505 guiObject = initNullMode(); |
|
506 } |
|
507 else |
|
508 { |
|
509 if (aArg.equals(GUI_OBJECT_CLASS_NAME)) |
|
510 { |
|
511 guiObject = initLCDUI(); |
|
512 } |
|
513 else // try load dynamic display mode |
|
514 { |
|
515 guiObject = initDynamicDisplayMode(aArg); |
|
516 } |
|
517 } |
|
518 |
|
519 iStatus = USE_GUI_PRIMITIVE; |
|
520 return guiObject; |
|
521 } |
|
522 else if (aMode == USE_DIRECT_VIDEO) |
|
523 { |
|
524 if (aArg != null) |
|
525 { |
|
526 if (!(aArg instanceof javax.microedition.lcdui.Canvas)) |
|
527 { |
|
528 throw new java.lang.IllegalArgumentException( |
|
529 "For USE_DIRECT_VIDEO mode argument should be of type Canvas"); |
|
530 } |
|
531 } |
|
532 else |
|
533 { |
|
534 throw new java.lang.IllegalArgumentException( |
|
535 "For USE_DIRECT_VIDEO mode argument should not be null"); |
|
536 } |
|
537 iVideoCanvas = (Canvas)aArg; |
|
538 // MMAPI UI 3.x req. |
|
539 |
|
540 display = new MMACanvasDisplay(iEventSource , iVideoCanvas); |
|
541 |
|
542 System.out.println("VideoControl.java: after eswt control got from canvas has added observer"); |
|
543 |
|
544 int handle = initNativeDisplay(iVideoCanvas, display); |
|
545 // here actual listener is added to display |
|
546 display.setNativeHandle(handle); |
|
547 // Window resource initialization is done to the native video player |
|
548 display.setWindowResources(); |
|
549 iStatus = USE_DIRECT_VIDEO; |
|
550 |
|
551 /*( try |
|
552 { |
|
553 this.setVisible(false); |
|
554 } |
|
555 |
|
556 catch (IllegalStateException ex) { } |
|
557 */ |
|
558 return null; |
|
559 } |
|
560 else |
|
561 { |
|
562 // java.lang.IllegalArgumentException - Thrown if the mode is invalid. |
|
563 throw new java.lang.IllegalArgumentException( |
|
564 "Mode not supported or invalid, " + |
|
565 "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE"); |
|
566 } |
|
567 } |
|
568 |
|
569 /** |
|
570 * Called from java for early initialization of native handle to java peer |
|
571 * Because it will be used to make a jni call |
|
572 */ |
|
573 public void setNativeDisplayHandleToJavaPeer(int handle) |
|
574 { |
|
575 System.out.println("VideoControl.java: setNativeDisplayHandleToJavaPeer handle =" + handle); |
|
576 display.setNativeHandle(handle); |
|
577 } |
|
578 |
|
579 /** |
|
580 * Initializes native display. |
|
581 * |
|
582 */ |
|
583 private int initNativeDisplay(Object aGuiObject, Object mmadisplay) |
|
584 { |
|
585 int handle = _initDisplayMode(iControlHandle, |
|
586 iEventSource, |
|
587 mmadisplay, |
|
588 aGuiObject); |
|
589 NativeError.check(handle); |
|
590 return handle; |
|
591 } |
|
592 |
|
593 /** |
|
594 * Gets control property from native side. |
|
595 * @param aPropertyType One of the types defined in this class |
|
596 * |
|
597 */ |
|
598 private int getControlProperty(int aPropertyType) |
|
599 { |
|
600 return _getControlProperty(iControlHandle, |
|
601 iEventSource, |
|
602 aPropertyType); |
|
603 } |
|
604 |
|
605 /** |
|
606 * Sets two properties to native side. |
|
607 * |
|
608 * @param aParamA Specific parameter A for property type. |
|
609 * @param aParamB Specific parameter B for property type. |
|
610 * @param aPropertyType One of the types defined in this class |
|
611 */ |
|
612 private int setDisplayProperty(int aParamA, int aParamB, int aPropertyType) |
|
613 { |
|
614 return _setDisplayProperty(iControlHandle, |
|
615 iEventSource, |
|
616 aParamA, |
|
617 aParamB, |
|
618 aPropertyType); |
|
619 } |
|
620 |
|
621 /** |
|
622 * Sets one property to native side. |
|
623 * |
|
624 * @param aPropertyType One of the types defined in this class |
|
625 */ |
|
626 private int setDisplayProperty(int aPropertyType) |
|
627 { |
|
628 return _setDisplayProperty(iControlHandle, |
|
629 iEventSource, |
|
630 0, |
|
631 0, |
|
632 aPropertyType); |
|
633 } |
|
634 |
|
635 /** |
|
636 * Called from native side when snapshot is ready |
|
637 * |
|
638 */ |
|
639 private void snapshotReady(int aError, byte[] aImageData) |
|
640 { |
|
641 iImageData = aImageData; |
|
642 iError = aError; |
|
643 |
|
644 synchronized (this) |
|
645 { |
|
646 notify(); |
|
647 } |
|
648 } |
|
649 |
|
650 /** |
|
651 * This method will try to use dynamic class loading to instantiate GUI |
|
652 * object for given mode. |
|
653 * @param aMode parameter for display mode |
|
654 * @return GUI object |
|
655 */ |
|
656 private Object initDynamicDisplayMode(Object aMode) |
|
657 { |
|
658 MMAGUIFactory guiFactory = null; |
|
659 try |
|
660 { |
|
661 String className = ((String)aMode).toLowerCase() + |
|
662 GUI_FACTORY_CLASS_NAME; |
|
663 Class guiClass = Class.forName(className); |
|
664 guiFactory = (MMAGUIFactory)guiClass.newInstance(); |
|
665 } |
|
666 catch (ClassNotFoundException cnfe) |
|
667 { |
|
668 // if the class could not be found |
|
669 throw new IllegalArgumentException( |
|
670 "Mode not supported or invalid, " + |
|
671 "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE"); |
|
672 } |
|
673 catch (IllegalAccessException iae) |
|
674 { |
|
675 // if the class or initializer is not accessible |
|
676 throw new IllegalArgumentException("Mode: " + aMode + |
|
677 " caused " + iae); |
|
678 } |
|
679 catch (InstantiationException ie) |
|
680 { |
|
681 // if an application tries to instantiate an abstract class or an |
|
682 // interface, or if the instantiation fails for some other reason |
|
683 throw new IllegalArgumentException("Mode: " + aMode + |
|
684 " caused " + ie); |
|
685 } |
|
686 catch (ClassCastException cce) |
|
687 { |
|
688 // Thrown to indicate that the code has attempted to cast an |
|
689 // object to a subclass of which it is not an instance. |
|
690 throw new IllegalArgumentException("Mode: " + aMode + |
|
691 " caused " + cce); |
|
692 } |
|
693 |
|
694 Object guiObject = guiFactory.initDisplayMode(); |
|
695 // initNativeDisplay return handle MMMADirectContainer, 0 parameter |
|
696 // indicates that dynamic display will be used |
|
697 // MMAPI UI 3.x req. |
|
698 // guiFactory.setContentHandle(initNativeDisplay(guiObject, 0)); |
|
699 return guiObject; |
|
700 } |
|
701 |
|
702 /** |
|
703 * Initializes LCDUI display mode. |
|
704 * @return LCDUI Item |
|
705 */ |
|
706 private Object initLCDUI() |
|
707 { |
|
708 iVideoItem = new VideoItem(iEventSource); |
|
709 iPlayer.addPlayerListener(iVideoItem); |
|
710 |
|
711 // MMAPI UI 3.x req. |
|
712 // int handle = initNativeDisplay(iVideoItem, |
|
713 // 1 /*iToolkitInvoker.itemGetHandle(iVideoItem)*/); |
|
714 |
|
715 // iVideoItem.setNativeHandle(handle); |
|
716 |
|
717 iStatus = USE_GUI_PRIMITIVE; |
|
718 return iVideoItem; |
|
719 } |
|
720 |
|
721 /** |
|
722 * Initializes USE_GUI_PRIMITIVE mode when null parameter is given to |
|
723 * initDisplayMode method. |
|
724 * UI toolkit gets selected when application uses UI toolkit |
|
725 * first time. After this selection null parameter must be |
|
726 * interpreted as the selected UI toolkit. initDisplayMode call |
|
727 * with null parameter before the selection must cause |
|
728 * IllegalArgumentException if there are several toolkits. |
|
729 * @return GUI object |
|
730 */ |
|
731 private Object initNullMode() |
|
732 { |
|
733 String toolkit = null; |
|
734 |
|
735 Object guiObject = null; |
|
736 |
|
737 // If lcdui was selected init it even if there might be several |
|
738 // toolkits. This is done to support existing applications. |
|
739 if ((LCDUI_PACKAGE + DISPLAY).equals(toolkit)) |
|
740 { |
|
741 guiObject = initLCDUI(); |
|
742 } |
|
743 else |
|
744 { |
|
745 try |
|
746 { |
|
747 // Several UI toolkits are supported if there are eSWT classes |
|
748 // and eSWT direct content component |
|
749 // Trying to load eSWT Listener interface or eSWT GUI factory |
|
750 // does not cause any initialization to eSWT. |
|
751 Class.forName(ESWT_PACKAGE + LISTENER); |
|
752 Class.forName(ESWT_PACKAGE + |
|
753 ESWT_CONTROL + |
|
754 GUI_FACTORY_CLASS_NAME); |
|
755 |
|
756 // check if eSWT was selected |
|
757 if ((ESWT_PACKAGE + DISPLAY).equals(toolkit)) |
|
758 |
|
759 { |
|
760 guiObject = initDynamicDisplayMode( |
|
761 ESWT_PACKAGE + |
|
762 ESWT_CONTROL + |
|
763 GUI_FACTORY_CLASS_NAME); |
|
764 } |
|
765 else |
|
766 { |
|
767 // If no toolkit is registered and if lcdui library exists select it |
|
768 try |
|
769 { |
|
770 Class.forName(LCDUI_PACKAGE + DISPLAY); |
|
771 |
|
772 guiObject = initLCDUI(); |
|
773 } |
|
774 catch (ClassNotFoundException cnfe) |
|
775 { |
|
776 // If there are several toolkits and none is selected |
|
777 // IllegalArgumentException must be thrown |
|
778 throw new IllegalArgumentException( |
|
779 "UI toolkit is not available or found."); |
|
780 } |
|
781 } |
|
782 } |
|
783 catch (ClassNotFoundException cnfe) |
|
784 { |
|
785 // Only lcdui is supported |
|
786 guiObject = initLCDUI(); |
|
787 } |
|
788 } |
|
789 return guiObject; |
|
790 } |
|
791 |
|
792 |
|
793 // private int updateForeground() // MMAPI UI 3.x changes |
|
794 private void updateForeground() |
|
795 { |
|
796 |
|
797 int isFG = 1; |
|
798 /* |
|
799 // Check whether display is initialized |
|
800 checkState(); |
|
801 if (iStatus == NOT_INITIALIZED) |
|
802 { |
|
803 return visible; |
|
804 } |
|
805 |
|
806 iMIDletInstance = MIDletExecutor.getCurrentMIDlet(); |
|
807 MIDlet midlet = iMIDletInstance.getMIDlet(); |
|
808 //Displayable displayable; |
|
809 if (midlet == null) |
|
810 { |
|
811 return visible; |
|
812 } |
|
813 else |
|
814 { |
|
815 Displayable displayable = Display.getDisplay(midlet).getCurrent(); |
|
816 |
|
817 if (displayable != null && displayable.isShown()) |
|
818 { |
|
819 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, |
|
820 "VideoControl.updateForeground isShown() = 1"); |
|
821 // visible |
|
822 } |
|
823 else |
|
824 { |
|
825 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, |
|
826 "VideoControl.updateForeground isShown() = 0"); |
|
827 // not visible |
|
828 visible = 0; |
|
829 } |
|
830 |
|
831 // Set the foreground state |
|
832 _setForeground(iControlHandle, |
|
833 iEventSource, |
|
834 visible); |
|
835 } |
|
836 |
|
837 return visible; |
|
838 */ |
|
839 |
|
840 // MMAPI UI 3.x req. |
|
841 // Get the midlet position BG/FG |
|
842 boolean visible = ManagerImpl.getInstance().isForground(); |
|
843 if(visible) |
|
844 isFG = 1; |
|
845 else |
|
846 isFG = 0; |
|
847 |
|
848 _setForeground(iControlHandle, |
|
849 iEventSource, |
|
850 isFG); |
|
851 // return visible; |
|
852 } |
|
853 |
|
854 private native int _construct(int aControlHandle, |
|
855 int aEventSourceHandle, |
|
856 int aToolkitHandle); |
|
857 |
|
858 private native int _getControlProperty(int aControlHandle, |
|
859 int aEventSourceHandle, |
|
860 int aPropertyType); |
|
861 |
|
862 private native int _setDisplayProperty(int aControlHandle, |
|
863 int aEventSourceHandle, |
|
864 int aParamA, |
|
865 int aParamB, |
|
866 int aPropertyType); |
|
867 |
|
868 private native int _getSnapshot(int aControlHandle, |
|
869 int aEventSourceHandle, |
|
870 String aProperties); |
|
871 |
|
872 private native int _initDisplayMode(int aControlHandle, |
|
873 int aEventSourceHandle, |
|
874 Object aJavaDisplay, |
|
875 Object aJavaDisplayObject); |
|
876 private native int _setForeground(int aControlHandle, |
|
877 int aEventSourceHandle, |
|
878 int aIsForeground); |
|
879 |
|
880 private native boolean _isESWT(); |
|
881 } |