53 // lcdui package used with UiToolkitRegister |
58 // lcdui package used with UiToolkitRegister |
54 private static String LCDUI_PACKAGE = |
59 private static String LCDUI_PACKAGE = |
55 "javax.microedition.lcdui"; |
60 "javax.microedition.lcdui"; |
56 // eswt package used with UiToolkitRegister |
61 // eswt package used with UiToolkitRegister |
57 private static String ESWT_PACKAGE = "org.eclipse.swt.widgets"; |
62 private static String ESWT_PACKAGE = "org.eclipse.swt.widgets"; |
58 // ToolkitRegister class name used with eswt and lcdui |
63 // ToolkitRegister class name used with eswt and lcdui |
59 private static String DISPLAY = ".Display"; |
64 private static String DISPLAY = ".Display"; |
60 |
65 |
61 // class name used to check if eswt is included |
66 // class name used to check if eswt is included |
62 private static String LISTENER = ".Listener"; |
67 private static String LISTENER = ".Listener"; |
63 |
68 |
64 // class name used to check if eswt is included |
69 // class name used to check if eswt is included |
65 private static String ESWT_CONTROL = ".control"; |
70 private static String ESWT_CONTROL = ".control"; |
66 // class name used with dynamic display mode initialization |
|
67 private static String GUI_FACTORY_CLASS_NAME = ".Factory"; |
|
68 |
71 |
69 private static final int NOT_INITIALIZED = -1; |
72 private static final int NOT_INITIALIZED = -1; |
70 protected int iStatus = NOT_INITIALIZED; |
73 protected int iStatus = NOT_INITIALIZED; |
71 private static final int UNDEFINED_RETURN_VALUE=0; |
74 private static final int UNDEFINED_RETURN_VALUE=0; |
72 // For integrating with eSWT API |
75 // For integrating with eSWT API |
73 private Display iDisplay; |
76 private Display iDisplay; |
74 // private Shell iShell; |
77 // This is reference of eSWT Control, don't get confused with the Player Control |
75 |
|
76 private Control iControl; |
78 private Control iControl; |
77 |
79 /** |
|
80 * When video display is set to full screen mode, old |
|
81 * video position & size is stored to this member. When |
|
82 * full screen mode is turned off, this member is used to |
|
83 * find out if display size has been changed during full |
|
84 * screen mode. This is needed to generate a SIZE_CHANGED |
|
85 * event. |
|
86 */ |
|
87 private Point iOldDisplaySize; |
|
88 /** |
|
89 * A CustomItem which needs to be returned in case USE_GUI_PRIMITIVE and null to MIDlet |
|
90 * from initDisplayMode function. |
|
91 */ |
78 // Global??? yes because we need to remove it from player listener, while finalizer will be called |
92 // Global??? yes because we need to remove it from player listener, while finalizer will be called |
79 private VideoItem iVideoItem; |
93 private VideoItem iVideoItem; |
80 |
94 |
|
95 |
|
96 /** |
|
97 * Constructor of VideoControl |
|
98 * @param player |
|
99 */ |
|
100 public VideoControl(Player player){ |
|
101 this.iPlayer=player; |
|
102 } |
|
103 /** |
|
104 * |
|
105 */ |
81 private Finalizer mFinalizer = new Finalizer(){ |
106 private Finalizer mFinalizer = new Finalizer(){ |
82 public void finalizeImpl(){ |
107 public void finalizeImpl(){ |
83 doFinalize(); |
108 doFinalize(); |
84 } |
109 } |
85 }; |
110 }; |
86 |
111 /** |
87 /** |
112 * |
88 * Constructor of VideoControl |
113 */ |
89 * @param player |
114 final void registeredFinalize() { |
90 */ |
115 if (iVideoItem != null) { |
91 public VideoControl(Player player){ |
116 iPlayer.removePlayerListener(iVideoItem); |
92 this.iPlayer=player; |
117 } |
93 } |
118 } |
94 |
119 |
95 /** |
120 /** |
96 * |
121 * |
97 */ |
122 */ |
98 private void doFinalize() { |
123 private void doFinalize() { |
99 if (mFinalizer != null) { |
124 if (mFinalizer != null) { |
101 mFinalizer = null; |
126 mFinalizer = null; |
102 } |
127 } |
103 } |
128 } |
104 |
129 |
105 /** |
130 /** |
106 * |
131 * Return the actual height of the current render video. |
107 */ |
132 * @return height of the display video |
108 final void registeredFinalize() { |
133 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. |
109 if (iVideoItem != null) { |
|
110 iPlayer.removePlayerListener(iVideoItem); |
|
111 } |
|
112 } |
|
113 |
|
114 /* (non-Javadoc) |
|
115 * @see javax.microedition.media.control.VideoControl#getDisplayHeight() |
|
116 */ |
134 */ |
117 public int getDisplayHeight() { |
135 public int getDisplayHeight() { |
|
136 // this function can't be called, when the player is in closed state |
|
137 // or until initDisplayMode function is not called |
118 checkState(); |
138 checkState(); |
119 if (iStatus == NOT_INITIALIZED) { |
139 if (iStatus == NOT_INITIALIZED) { |
120 throw new IllegalStateException( |
140 throw new IllegalStateException( |
121 "VideoControl.initDisplayMode() not called yet"); |
141 "VideoControl.initDisplayMode() not called yet"); |
122 } |
142 } |
123 return ((AnimationPlayer)iPlayer).getImageDimension().x; |
143 // Following function will always return Player's current height |
124 } |
144 return ((AnimationPlayer) iPlayer).getImageDimension().x; |
125 |
145 } |
126 /* (non-Javadoc) |
146 |
127 * @see javax.microedition.media.control.VideoControl#getDisplayWidth() |
147 /** |
|
148 * Return the actual width of the current render video. |
|
149 * @return width of the display video |
|
150 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. |
128 */ |
151 */ |
129 public int getDisplayWidth() { |
152 public int getDisplayWidth() { |
130 checkState(); |
153 checkState(); |
131 if (iStatus == NOT_INITIALIZED) { |
154 if (iStatus == NOT_INITIALIZED) { |
132 throw new IllegalStateException( |
155 throw new IllegalStateException( |
133 "VideoControl.initDisplayMode() not called yet"); |
156 "VideoControl.initDisplayMode() not called yet"); |
134 } |
157 } |
135 return ((AnimationPlayer)iPlayer).getImageDimension().x; |
158 return ((AnimationPlayer) iPlayer).getImageDimension().x; |
136 } |
159 } |
137 |
160 |
138 /* (non-Javadoc) |
161 /** |
139 * @see javax.microedition.media.control.VideoControl#getDisplayX() |
162 * Return the X-coordinate of the video with respect to the GUI object where the video is displayed. |
|
163 * The coordinate is specified in pixel values relative to the upper left hand corner of the GUI object. |
|
164 * The return value is undefined if initDisplayMode has not been called. |
|
165 * @return the X-coordinate of the video. |
140 */ |
166 */ |
141 public int getDisplayX() { |
167 public int getDisplayX() { |
142 checkState(); |
168 checkState(); |
143 if (iStatus == NOT_INITIALIZED) |
169 if (iStatus == NOT_INITIALIZED) { |
144 { |
170 return UNDEFINED_RETURN_VALUE; |
145 return UNDEFINED_RETURN_VALUE; |
171 } |
146 } |
172 return ((AnimationPlayer) iPlayer).getiDisplayLocation().x; |
147 return ((AnimationPlayer)iPlayer).getiDisplayLocation().x; |
173 } |
148 } |
174 |
149 |
175 /** |
150 /* (non-Javadoc) |
176 * Return the Y-coordinate of the video with respective to the GUI object where the video is displayed. |
151 * @see javax.microedition.media.control.VideoControl#getDisplayY() |
177 * The coordinate is specified in pixel values relative to the upper left hand corner of the GUI object. |
152 */ |
178 * The return value is undefined if initDisplayMode has not been called. |
|
179 * @return the Y-coordinate of the video. |
|
180 */ |
153 public int getDisplayY() { |
181 public int getDisplayY() { |
154 checkState(); |
182 checkState(); |
155 if (iStatus == NOT_INITIALIZED) |
183 if (iStatus == NOT_INITIALIZED) { |
156 { |
184 return UNDEFINED_RETURN_VALUE; |
157 return UNDEFINED_RETURN_VALUE; |
185 } |
158 } |
186 return ((AnimationPlayer) iPlayer).getiDisplayLocation().y; |
159 return ((AnimationPlayer)iPlayer).getiDisplayLocation().y; |
187 } |
160 } |
188 |
161 |
189 /** |
162 /* (non-Javadoc) |
190 * Get a snapshot of the displayed content. Features and format of the captured image are specified by |
163 * @see javax.microedition.media.control.VideoControl#getSnapshot(java.lang.String) |
191 * imageType. Supported formats can be queried from System.getProperty with video.snapshot.encodings |
164 */ |
192 * as the key. The first format in the supported list is the default capture format. |
|
193 * @param imageType - Format and resolution of the returned image. |
|
194 * If null is given, the default capture format is used. |
|
195 * |
|
196 * @return image as a byte array in required format. |
|
197 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. |
|
198 * @throws MediaException - Thrown if the requested format is not supported or the Player does not support snapshots. |
|
199 * @throws java.lang.SecurityException - Thrown if the caller does not have the security permission to take the snapshot. |
|
200 */ |
|
201 //TODO Implementation pending, need discussion with UI team |
165 public byte[] getSnapshot(String aImageType) throws MediaException { |
202 public byte[] getSnapshot(String aImageType) throws MediaException { |
166 final String DEBUG_STR="VideoControl::getSnapshot(String aImageType)"; |
|
167 System.out.println(DEBUG_STR+"+"); |
|
168 checkState(); |
203 checkState(); |
169 if (iStatus == NOT_INITIALIZED) { |
204 if (iStatus == NOT_INITIALIZED) { |
170 throw new IllegalStateException( |
205 throw new IllegalStateException( |
171 "VideoControl.initDisplayMode() not called yet"); |
206 "VideoControl.initDisplayMode() not called yet"); |
172 } |
207 } |
173 int imageData[]=((AnimationPlayer)iPlayer).getCurrentFrame(aImageType); |
208 Image image=((AnimationPlayer)iPlayer).getCurrentFrame(aImageType); |
174 byte bytArry[]= new byte[imageData.length]; |
209 byte bytArry[]= null;//getByteArray(image); |
175 int pixelCount=bytArry.length; |
210 // TODO Enable the permission check |
176 System.out.println(DEBUG_STR+"imageData receved is "+imageData); |
211 // Commented out below line, because I was getting exception |
177 for(int i=0;i<pixelCount;i++) |
|
178 bytArry[i]=(byte)imageData[i]; |
|
179 // Check the permission here, so 'the moment' is not lost? |
212 // Check the permission here, so 'the moment' is not lost? |
180 //Security.ensurePermission(PERMISSION, PERMISSION, PERM_ARGS); |
213 //Security.ensurePermission(PERMISSION, PERMISSION, PERM_ARGS); |
181 // ApplicationUtils appUtils = ApplicationUtils.getInstance(); |
214 // ApplicationUtils appUtils = ApplicationUtils.getInstance(); |
182 // PlayerPermission per = new PlayerPermission("audio/video recording","snapshot"); |
215 // PlayerPermission per = new PlayerPermission("audio/video recording","snapshot"); |
183 // appUtils.checkPermission(per); |
216 // appUtils.checkPermission(per); |
184 return bytArry; |
217 return bytArry; |
185 } |
218 } |
186 |
219 |
187 /* (non-Javadoc) |
220 /** |
188 * @see javax.microedition.media.control.VideoControl#getSourceHeight() |
221 * Return the height of the source video. The height must be a positive number. |
|
222 * @return the height of the source video. |
189 */ |
223 */ |
190 public int getSourceHeight() { |
224 public int getSourceHeight() { |
191 checkState(); |
225 checkState(); |
192 return ((AnimationPlayer)iPlayer).getSourceDimension().y; |
226 return ((AnimationPlayer)iPlayer).getSourceDimension().y; |
193 } |
227 } |
194 |
228 |
195 /* (non-Javadoc) |
229 /** |
196 * @see javax.microedition.media.control.VideoControl#getSourceWidth() |
230 * Return the width of the source video. The width must be a positive number. |
|
231 * @return the width of the source video |
197 */ |
232 */ |
198 public int getSourceWidth() { |
233 public int getSourceWidth() { |
199 checkState(); |
234 checkState(); |
200 return ((AnimationPlayer)iPlayer).getSourceDimension().x; |
235 return ((AnimationPlayer)iPlayer).getSourceDimension().x; |
201 } |
236 } |
202 |
237 |
203 /* (non-Javadoc) |
238 /** |
|
239 * Initialize the mode on how the video is displayed. |
|
240 * This method must be called before video can be displayed. |
|
241 * Two modes are defined: |
|
242 * USE_GUI_PRIMITIVE (inherited from GUIControl) |
|
243 * USE_DIRECT_VIDEO |
204 * @see javax.microedition.media.control.VideoControl#initDisplayMode(int, java.lang.Object) |
244 * @see javax.microedition.media.control.VideoControl#initDisplayMode(int, java.lang.Object) |
205 */ |
245 */ |
206 public Object initDisplayMode(int aMode, Object aArg) { |
246 public Object initDisplayMode(int aMode, Object aArg) { |
207 final String DEBUG_STRING = "VideoControl::initDisplayMode(int, Object)"; |
247 final String DEBUG_STRING = "VideoControl::initDisplayMode(int, Object)"; |
208 System.out.println(DEBUG_STRING + "+"); |
248 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING + "+"); |
209 // To check if state is in not closed state |
249 // To check if state is in not closed state |
210 checkState(); |
250 checkState(); |
211 System.out.println(DEBUG_STRING+"After checking state "); |
|
212 if (iStatus != NOT_INITIALIZED) { |
251 if (iStatus != NOT_INITIALIZED) { |
213 // IllegalStateException - Thrown if initDisplayMode is |
252 // IllegalStateException - Thrown if initDisplayMode is |
214 // called again after it has previously been called successfully. |
253 // called again after it has previously been called successfully. |
215 throw new IllegalStateException( |
254 throw new IllegalStateException( |
216 "initDisplayMode() already called successfully"); |
255 "initDisplayMode() already called successfully"); |
217 } |
256 } |
218 System.out.println(DEBUG_STRING+"Going to get the eswtDisplay, mode is "+aMode+" argument is "+aArg); |
257 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING+"Mode = "+aMode+" Argument = "+aArg); |
219 // Get the Display object of ESWT |
258 // if the aArg is equal to the name of eSWT Control class name |
|
259 // create the Display object in following, assuming Display |
|
260 // object is already created in MIDlet. |
220 if(aArg!=null && aArg.equals(Control.class.getName())){ |
261 if(aArg!=null && aArg.equals(Control.class.getName())){ |
|
262 // Following line will return the same Display object |
|
263 // Which is created in Midlet |
221 iDisplay =Display.getDefault(); |
264 iDisplay =Display.getDefault(); |
222 // System.out.println(DEBUG_STRING+"Display object created"+iDisplay ); |
265 }else{ |
223 }else{ |
266 // Get the Display object of ESWT |
224 iDisplay = com.nokia.mj.impl.nokialcdui.LCDUIInvoker.getEswtDisplay(); |
267 iDisplay = com.nokia.mj.impl.nokialcdui.LCDUIInvoker.getEswtDisplay(); |
225 } |
268 } |
226 // System.out.println(DEBUG_STRING+"After getting the display"+iDisplay); |
|
227 if (aMode == USE_GUI_PRIMITIVE) { |
269 if (aMode == USE_GUI_PRIMITIVE) { |
228 System.out.println(DEBUG_STRING + " mode is USE_GUI_PRIMITIVE"); |
|
229 Object guiObject = null; |
270 Object guiObject = null; |
230 if (aArg == null) { |
271 if (aArg == null) { |
231 guiObject = initNullMode(); |
272 guiObject = initNullMode(); |
232 } else { |
273 } else { |
233 if (aArg.equals(GUI_OBJECT_CLASS_NAME)) { |
274 if (aArg.equals(GUI_OBJECT_CLASS_NAME)) { |
234 guiObject = initLCDUI(); |
275 guiObject = initLCDUI(); |
235 } else // try load dynamic display mode |
276 } else // try load dynamic display mode |
236 { |
277 { |
237 guiObject = initDynamicDisplayMode(aArg); |
278 guiObject = initDynamicDisplayMode(aArg); |
238 System.out.println(DEBUG_STRING+"After returning from the initDynamicDisplayMode() "+guiObject); |
|
239 // Since it is eswtControl itself so no need of LCDUIInvoker here |
279 // Since it is eswtControl itself so no need of LCDUIInvoker here |
240 // assign it in iControl and return immediately from here |
280 // assign it in iControl and return immediately from here |
241 iControl=(Control)guiObject; |
281 iControl=(Control)guiObject; |
242 // Now we will change the status, when MIDlet developer will call the setParent |
282 // Now we will change the status, when MIDlet developer will call the setParent |
243 iStatus = USE_GUI_PRIMITIVE; |
283 iStatus = USE_GUI_PRIMITIVE; |
267 throw new java.lang.IllegalArgumentException( |
307 throw new java.lang.IllegalArgumentException( |
268 "For USE_DIRECT_VIDEO mode argument should not be null"); |
308 "For USE_DIRECT_VIDEO mode argument should not be null"); |
269 } |
309 } |
270 iControl = com.nokia.mj.impl.nokialcdui.LCDUIInvoker |
310 iControl = com.nokia.mj.impl.nokialcdui.LCDUIInvoker |
271 .getEswtControl(aArg); |
311 .getEswtControl(aArg); |
272 System.out.println(DEBUG_STRING |
312 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING |
273 + "This is USE_DIRECT_VIDEO mode, control is " + iControl); |
313 + "This is USE_DIRECT_VIDEO mode, control is " + iControl); |
274 iStatus = USE_DIRECT_VIDEO; |
314 iStatus = USE_DIRECT_VIDEO; |
275 } else { |
315 } else { |
276 throw new java.lang.IllegalArgumentException( |
316 throw new java.lang.IllegalArgumentException( |
277 "Mode not supported or invalid, " |
317 "Mode not supported or invalid, " |
278 + "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE"); |
318 + "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE"); |
279 } |
319 } |
280 System.out.println(DEBUG_STRING + "-"); |
320 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING + "-"); |
281 return null; |
321 return null; |
282 } |
322 } |
283 /** |
323 /** |
284 * |
324 * Creates the VideoItem object of size of image(gif) |
285 * @return |
325 * @return VideoItem(a CustomItem ) object |
286 */ |
326 */ |
287 private Object initLCDUI(){ |
327 private Object initLCDUI(){ |
288 final String DEBUG_STR="VideoControl::initLCDUI()"; |
328 final String DEBUG_STR="VideoControl::initLCDUI()"; |
289 System.out.println(DEBUG_STR+"+"); |
329 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+"); |
290 iVideoItem = new VideoItem(((AnimationPlayer)iPlayer).getImageDimension()); |
330 iVideoItem = new VideoItem(((AnimationPlayer)iPlayer).getImageDimension()); |
291 iPlayer.addPlayerListener(iVideoItem); |
331 iPlayer.addPlayerListener(iVideoItem); |
292 iStatus = USE_GUI_PRIMITIVE; |
332 iStatus = USE_GUI_PRIMITIVE; |
293 System.out.println(DEBUG_STR+"-"); |
333 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-"); |
294 return iVideoItem; |
334 return iVideoItem; |
295 } |
335 } |
296 |
336 |
297 /** |
337 /** |
298 * Initializes USE_GUI_PRIMITIVE mode when null parameter is given to |
338 * Initializes USE_GUI_PRIMITIVE mode when null parameter is given to |
299 * initDisplayMode method. |
339 * initDisplayMode method. |
300 * UI toolkit gets selected when application uses UI toolkit |
340 * UI toolkit gets selected when application uses UI toolkit |
301 * first time. After this selection null parameter must be |
341 * first time. After this selection null parameter must be |
302 * interpreted as the selected UI toolkit. initDisplayMode call |
342 * interpreted as the selected UI toolkit. initDisplayMode call |
304 * IllegalArgumentException if there are several toolkits. |
344 * IllegalArgumentException if there are several toolkits. |
305 * @return GUI object |
345 * @return GUI object |
306 */ |
346 */ |
307 private Object initNullMode() { |
347 private Object initNullMode() { |
308 String DEBUG_STR = "VideoControl::initNullMode()"; |
348 String DEBUG_STR = "VideoControl::initNullMode()"; |
309 |
349 // Removing following line as per new requirement. |
|
350 // there won't be any toolkit |
|
351 // UiToolkitRegister uiRegister = RuntimeInfoFactory.getRuntimeInfo() |
|
352 // .getUiToolkitRegister(); |
|
353 // // returns always non null array with zero or more strings |
|
354 // String[] toolkits = uiRegister.getRegisteredUiToolkits(); |
|
355 // selected toolkit or null if not selected |
|
356 //String toolkit = (toolkits.length > 0) ? toolkits[0] : null; |
|
357 // TODO remove this 'toolkit' variable |
310 String toolkit = null; |
358 String toolkit = null; |
311 |
|
312 Object guiObject = null; |
359 Object guiObject = null; |
313 |
360 |
314 // If lcdui was selected init it even if there might be several |
361 // If lcdui was selected init it even if there might be several |
315 // toolkits. This is done to support existing applications. |
362 // toolkits. This is done to support existing applications. |
316 if ((LCDUI_PACKAGE + DISPLAY).equals(toolkit)) { |
363 if ((LCDUI_PACKAGE + DISPLAY).equals(toolkit)) { |
317 System.out.println(DEBUG_STR + "going to use initLCDUI function "); |
364 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR + "going to use initLCDUI function "); |
318 guiObject = initLCDUI(); |
365 guiObject = initLCDUI(); |
319 } else { |
366 } else { |
320 try { |
367 try { |
321 System.out.println(DEBUG_STR + "Seems it is ESWT toolkit "); |
|
322 // Several UI toolkits are supported if there are eSWT classes |
368 // Several UI toolkits are supported if there are eSWT classes |
323 // and eSWT direct content component |
369 // and eSWT direct content component |
324 // Trying to load eSWT Listener interface or eSWT GUI factory |
370 // Trying to load eSWT Listener interface or eSWT GUI factory |
325 // does not cause any initialization to eSWT. |
371 // does not cause any initialization to eSWT. |
326 Class.forName(ESWT_PACKAGE + LISTENER); |
372 Class.forName(ESWT_PACKAGE + LISTENER); |
327 Class.forName(ESWT_PACKAGE + ESWT_CONTROL |
|
328 + GUI_FACTORY_CLASS_NAME); |
|
329 |
|
330 // check if eSWT was selected |
373 // check if eSWT was selected |
331 if ((ESWT_PACKAGE + DISPLAY).equals(toolkit)) |
374 if ((ESWT_PACKAGE + DISPLAY).equals(toolkit)) |
332 { |
375 { |
333 System.out |
376 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR |
334 .println(DEBUG_STR |
|
335 + "It is eswtPackage going to call initDynamicDisplay "); |
377 + "It is eswtPackage going to call initDynamicDisplay "); |
336 guiObject = initDynamicDisplayMode(ESWT_PACKAGE |
378 guiObject = initDynamicDisplayMode(ESWT_PACKAGE |
337 + ESWT_CONTROL + GUI_FACTORY_CLASS_NAME); |
379 + ESWT_CONTROL); |
|
380 |
338 } else { |
381 } else { |
339 // If no toolkit is registered and if lcdui library exists |
382 // If no toolkit is registered and if LCDUI library exists |
340 // select it |
383 // select it |
341 try { |
384 try { |
342 Class.forName(LCDUI_PACKAGE + DISPLAY); |
385 Class.forName(LCDUI_PACKAGE + DISPLAY); |
343 |
|
344 guiObject = initLCDUI(); |
386 guiObject = initLCDUI(); |
345 } catch (ClassNotFoundException cnfe) { |
387 } catch (ClassNotFoundException cnfe) { |
346 // If there are several toolkits and none is selected |
388 // If there are several toolkits and none is selected |
347 // IllegalArgumentException must be thrown |
389 // IllegalArgumentException must be thrown |
348 throw new IllegalArgumentException( |
390 throw new IllegalArgumentException( |
349 "UI toolkit is not available or found."); |
391 "UI toolkit is not available or found."); |
350 } |
392 } |
351 } |
393 } |
352 } catch (ClassNotFoundException cnfe) { |
394 } catch (ClassNotFoundException cnfe) { |
353 System.out.println(DEBUG_STR |
395 Logger.LOG(Logger.EJavaMMAPI, Logger.EError,DEBUG_STR |
354 + "Exception caought, going to call initLCDUI funtion"); |
396 + "Exception caought, going to call initLCDUI funtion"); |
355 // Only lcdui is supported |
397 // Only lcdui is supported |
356 guiObject = initLCDUI(); |
398 guiObject = initLCDUI(); |
357 } |
399 } |
358 } |
400 } |
401 } catch (ClassCastException cce) { |
436 } catch (ClassCastException cce) { |
402 // Thrown to indicate that the code has attempted to cast an |
437 // Thrown to indicate that the code has attempted to cast an |
403 // object to a subclass of which it is not an instance. |
438 // object to a subclass of which it is not an instance. |
404 throw new IllegalArgumentException("Mode: " + aMode + " caused " |
439 throw new IllegalArgumentException("Mode: " + aMode + " caused " |
405 + cce); |
440 + cce); |
406 }catch(Exception e){ |
441 } |
407 System.out.println("Exception thrown while creating the control object"+e); |
442 // TODO remove this catch(Exception) block, it is added for testing purpose |
|
443 catch(Exception e){ |
|
444 Logger.LOG(Logger.EJavaMMAPI, Logger.EError,"Exception thrown while creating the control object"+e); |
408 e.printStackTrace(); |
445 e.printStackTrace(); |
409 } |
446 } |
410 // Object guiObject = guiFactory.initDisplayMode(); |
|
411 // return guiObject; |
|
412 return control; |
447 return control; |
413 } |
448 } |
414 |
449 |
415 /* (non-Javadoc) |
450 /* (non-Javadoc) |
416 * @see javax.microedition.media.control.VideoControl#setDisplayFullScreen(boolean) |
451 * @see javax.microedition.media.control.VideoControl#setDisplayFullScreen(boolean) |
417 */ |
452 */ |
418 public void setDisplayFullScreen(final boolean aFullScreenMode) |
453 public void setDisplayFullScreen(final boolean aFullScreenMode) |
419 throws MediaException { |
454 throws MediaException { |
420 if (iStatus == NOT_INITIALIZED) |
455 if (iStatus == NOT_INITIALIZED) { |
421 { |
456 throw new IllegalStateException( |
422 throw new IllegalStateException( |
457 "VideoControl.initDisplayMode() not called yet"); |
423 "VideoControl.initDisplayMode() not called yet"); |
458 } |
424 } |
459 //if this is in case of form, return silently |
|
460 //This is as per earlier NOKIA implementation, |
|
461 // however MMAPI documentation is saying something different |
|
462 // if Full screen mode is not supported, it should throw MediaException |
|
463 // TODO further check and discuss.... |
|
464 if(iVideoItem!=null) { |
|
465 return; |
|
466 } |
425 if(aFullScreenMode){ |
467 if(aFullScreenMode){ |
426 //Image size should be resized to maximum width, |
468 // Before going to full screen mode, we need to store the current display size; |
427 //so that the aspect ratio should be maintained |
469 // so that when user will exit from the full screen, |
428 |
470 // it will return to it's previous size |
429 ((AnimationPlayer)iPlayer).updateImageData(360, 360); |
471 iOldDisplaySize = ((AnimationPlayer)iPlayer).getImageDimension(); |
430 // when the size is set to full screen, set the location to 0,0 |
472 Rectangle displayDimension=calculateFullScreenDimension(); |
431 // but what if user will exit from the full screen mode, |
473 ((AnimationPlayer)iPlayer).updateImageData(displayDimension.width, displayDimension.height); |
432 //we will have to revert back to the original position |
474 setDisplayLocation(displayDimension.x, displayDimension.y); |
433 // Image should be drawn at the center of the screen |
475 ((AnimationPlayer)iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this); |
434 setDisplayLocation(0, 140); |
476 }else{ |
435 } |
477 // user may call setFullScreen(false), prior to setting it full screen |
436 iDisplay.syncExec(new Runnable(){ |
478 if(iOldDisplaySize!=null){ |
437 public void run(){ |
479 ((AnimationPlayer)iPlayer).updateImageData(iOldDisplaySize); |
438 MobileShell shell= (MobileShell)iControl.getShell(); |
480 // Do we need to make it null? |
439 shell.setFullScreenMode(aFullScreenMode); |
481 iOldDisplaySize=null; |
|
482 // post event to player Listener |
|
483 ((AnimationPlayer)iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this); |
440 } |
484 } |
441 }); |
485 } |
442 |
|
443 } |
486 } |
444 |
487 |
445 /* (non-Javadoc) |
488 /* (non-Javadoc) |
446 * @see javax.microedition.media.control.VideoControl#setDisplayLocation(int, int) |
489 * @see javax.microedition.media.control.VideoControl#setDisplayLocation(int, int) |
447 */ |
490 */ |
448 public void setDisplayLocation(int aX, int aY) { |
491 public void setDisplayLocation(int aX, int aY) { |
449 final String DEBUG_STR="VideoControl::setDisplayLocation"; |
|
450 System.out.println(DEBUG_STR+">>>>>>> Control is "+iControl); |
|
451 // in case of customItem, we are getting canvasExtension as control |
492 // in case of customItem, we are getting canvasExtension as control |
452 // and in this case we need to ignore the setDisplayLocation call. |
493 // and in this case we need to ignore the setDisplayLocation call. |
453 // it is also possible that iControl may be null( it will be null until and unless |
494 // it is also possible that iControl may be null( it will be null until and unless |
454 // notifyControlAvailable function is not get called) |
495 // notifyControlAvailable function is not get called) |
455 if(iControl==null || (iControl instanceof org.eclipse.swt.internal.extension.CanvasExtension)) |
496 if(iControl==null || (iControl instanceof org.eclipse.swt.internal.extension.CanvasExtension)) |
456 return ; |
497 return ; |
457 ((AnimationPlayer)iPlayer).setDisplayLocation(aX, aY); |
498 ((AnimationPlayer)iPlayer).setDisplayLocation(aX, aY); |
458 } |
499 } |
459 |
500 |
460 /* (non-Javadoc) |
501 /** |
|
502 * (non-Javadoc) |
461 * @see javax.microedition.media.control.VideoControl#setDisplaySize(int, int) |
503 * @see javax.microedition.media.control.VideoControl#setDisplaySize(int, int) |
462 */ |
504 */ |
|
505 // TODO we need to handle here the following scenario |
|
506 // if the player is in FULL_SCREEN mode, just change the display size in background(means do not exit from |
|
507 // the full screen mode and don't send event to player Listener the player size changed ) |
|
508 // and changed side should take effect |
463 public void setDisplaySize(int aWidth, int aHeight) throws MediaException { |
509 public void setDisplaySize(int aWidth, int aHeight) throws MediaException { |
464 final String DEBUG_STR="VideoControl::setDisplaySize(int aWidth, int aHeight)"; |
510 if (iStatus == NOT_INITIALIZED) { |
465 System.out.println(DEBUG_STR+"width "+aWidth+" aHeight "+aHeight); |
511 throw new IllegalStateException( |
466 if (iStatus == NOT_INITIALIZED) |
512 "VideoControl.initDisplayMode() not called yet"); |
467 { |
513 } |
468 throw new IllegalStateException( |
514 if (aWidth <= 0 || aHeight <= 0) { |
469 "VideoControl.initDisplayMode() not called yet"); |
515 throw new IllegalArgumentException( |
470 } |
516 "Width and height must be positive"); |
471 if (aWidth <= 0 || aHeight <= 0) |
517 } |
472 { |
518 // resize the all frames |
473 throw new IllegalArgumentException( |
519 ((AnimationPlayer) iPlayer).updateImageData(aWidth, aHeight); |
474 "Width and height must be positive"); |
520 // Since the DisplaySize is being changed, we need to change the |
475 } |
521 // size of VideoItem as well |
476 ((AnimationPlayer) iPlayer).updateImageData(aWidth,aHeight); |
522 // if the videoItem is not null, it means currently we are playing |
477 // Since the DisplaySize is being changed, we need to change the |
523 // animation on form |
478 // size of VideoItem as well |
524 if (iVideoItem != null)// means it is for customItem |
479 // if the videoItem is not null, it means currently we are playing animation on form |
525 iVideoItem.setPreferredSize(aWidth, aHeight); |
480 if(iVideoItem!=null)// means it is for customItem |
526 // Notify to all player listener that video Size has been changed |
481 iVideoItem.setPreferredSize(aWidth, aHeight); |
527 ((AnimationPlayer) iPlayer).getiPlayerListenerImpl().postEvent( |
482 // Notify to all player listener that video Size has been changed |
528 PlayerListener.SIZE_CHANGED, this); |
483 ((AnimationPlayer) iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this); |
529 } |
484 System.out.println(DEBUG_STR+"-"); |
530 |
485 } |
531 /** |
486 |
532 * Show or hide the video. |
487 /* (non-Javadoc) |
533 * If USE_GUI_PRIMITIVE is set, the video by default is shown when the GUI primitive is displayed. |
488 * @see javax.microedition.media.control.VideoControl#setVisible(boolean) |
534 * If USE_DIRECT_VIDEO is set, the video by default is not shown when the canvas is displayed until |
|
535 * setVisible(true) is called. If the canvas is removed from the screen, the video will not be displayed. |
|
536 * |
|
537 * @return visible - Show the video if true, hide it otherwise. |
|
538 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. |
489 */ |
539 */ |
490 public void setVisible(final boolean aVisible) { |
540 public void setVisible(final boolean aVisible) { |
|
541 if (iStatus == NOT_INITIALIZED) { |
|
542 throw new IllegalStateException( |
|
543 "VideoControl.initDisplayMode() not called yet"); |
|
544 } |
|
545 // if this is in case of Form and eSWT Control then this implementation is OK |
|
546 // but in case of Canvas, entire Canvas is getting invisible, which is not OK. |
|
547 // TODO handle the case of Canvas case as well |
|
548 //TODO in case of Canvas visiblity should be false by default |
|
549 // while in case of Form it should be true. |
491 if (iControl != null) { |
550 if (iControl != null) { |
492 iDisplay.syncExec(new Runnable() { |
551 iDisplay.syncExec(new Runnable() { |
493 public void run() { |
552 public void run() { |
494 iControl.setVisible(aVisible); |
553 iControl.setVisible(aVisible); |
495 System.out.println("VideoControl::setVisible()"+aVisible); |
|
496 } |
554 } |
497 }); |
555 }); |
498 } |
556 } |
499 } |
557 } |
|
558 /*******************************FOLLOWING FUNCTIONS ARE USED FOR INTERNAL PURPOSE***********************/ |
500 /** |
559 /** |
501 * |
560 * |
502 * @return Display object retrieved from ESWT |
561 * @return Display object retrieved from ESWT |
503 */ |
562 */ |
504 public Display getiDisplay() { |
563 Display getiDisplay() { |
505 return iDisplay; |
564 return iDisplay; |
506 } |
565 } |
507 |
566 |
508 /** |
567 /** |
509 * |
568 * |
510 * @return |
569 * @return |
511 */ |
570 */ |
512 public Control getControl() { |
571 Control getControl() { |
513 return iControl; |
572 return iControl; |
514 } |
573 } |
515 /** |
574 /** |
516 * Function of ItemStateChangeListener |
575 * Function of ItemStateChangeListener |
|
576 * Notified by LCDUI implementation |
517 * @param ctrl |
577 * @param ctrl |
518 * @param item |
578 * @param item |
519 */ |
579 */ |
520 public void notifyControlAvailable(Control ctrl,Item item){ |
580 public void notifyControlAvailable(Control ctrl,Item item){ |
521 final String DEBUG_STR= "VideoControl::notifyControlAvailable(Control ctrl,Item item)"; |
581 final String DEBUG_STR= "VideoControl::notifyControlAvailable(Control ctrl,Item item)"; |
522 System.out.println(DEBUG_STR+"+"); |
|
523 iControl=ctrl; |
582 iControl=ctrl; |
524 System.out.println(DEBUG_STR+"Control is "+ctrl.hashCode()+ " Item is "+item); |
583 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, DEBUG_STR+"Control is "+ctrl.hashCode()+ " Item is "+item); |
525 //TODO is it proper here to put the below line in try/catch?, remove if we can |
584 //TODO is it proper here to put the below line in try/catch?, remove if we can. |
526 // otherwise it may deteriorate the performance, as in case of CustomItem on each |
585 // Otherwise it may deteriorate the performance, as in case of CustomItem on each |
527 // repaint, eSWT control is getting destroyed, and reconstructed |
586 // repaint, eSWT control is getting destroyed, and reconstructed |
528 try { |
587 try { |
529 ((AnimationPlayer)iPlayer).addPaintListener(iControl); |
588 ((AnimationPlayer)iPlayer).addPaintListener(iControl); |
530 } catch (MediaException e) { |
589 } catch (MediaException e) { |
531 // TODO What to do here |
590 // TODO What to do here |
532 e.printStackTrace(); |
591 e.printStackTrace(); |
533 } |
592 } |
534 System.out.println(DEBUG_STR+"-"); |
|
535 } |
593 } |
536 /** |
594 /** |
537 * Function of ItemStateChangeListener |
595 * Function of ItemStateChangeListener |
538 * We don't need to do anything in this function |
596 * We don't need to do anything in this function |
|
597 * |
539 * @param item |
598 * @param item |
540 */ |
599 */ |
541 public void notifyControlDisposed(Item item){ |
600 public void notifyControlDisposed(Item item){ |
542 final String DEBUG_STR= "VideoControl::notifyControlDisposed(Item item)"; |
601 final String DEBUG_STR= "VideoControl::notifyControlDisposed(Item item)"; |
543 System.out.println(DEBUG_STR+"+"); |
602 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, DEBUG_STR+"Item Disposed is "+item); |
544 // System.out.println(DEBUG_STR+"Item Disposed is "+item); |
603 } |
545 // System.out.println(DEBUG_STR+"-"); |
604 |
546 } |
605 /** |
547 |
606 * This function calculate the size and location of the image in case of full screen |
|
607 * So that Aspect ratio should be maintained |
|
608 * @return Rectangle, After calculating the size of the Video(image) in full screen mode |
|
609 */ |
|
610 // It is not the proper way to declare the variable as global variable |
|
611 // only for the reason that it should be accessible in inner class. |
|
612 // Following variable(deviceDimension) declared shouldn't be the part of VideoControl object. |
|
613 // My suggestion:- Move it to some utility class |
|
614 // TODO let's discuss |
|
615 private Rectangle deviceDimension; |
|
616 private Rectangle calculateFullScreenDimension(){ |
|
617 Point actualImageSize = ((AnimationPlayer)iPlayer).getImageDimension(); |
|
618 // initialize the deviceDimension, in local variable |
|
619 iDisplay.syncExec(new Runnable() { |
|
620 public void run() { |
|
621 //deviceDimension=iDisplay.getBounds(); |
|
622 deviceDimension=iDisplay.getClientArea(); |
|
623 } |
|
624 }); |
|
625 int deviceWidth=deviceDimension.width; |
|
626 int deviceHeight=deviceDimension.height; |
|
627 //Returning the following rectangle after alteration |
|
628 Rectangle rect= new Rectangle (0,0,deviceWidth,deviceHeight); |
|
629 |
|
630 // to handle the divide by zero |
|
631 if(actualImageSize.x==0 && actualImageSize.y==0) |
|
632 return rect; |
|
633 // Following logic has been copied from |
|
634 //earlier native implementation ( from cmmadisplay.cpp::ScaleToFullScreen) |
|
635 // Smaller dimension scale ratio will be scaled. |
|
636 // Changed to area calculation to avoid reals and dimension |
|
637 // with smaller area will be scaled. |
|
638 // remember that the argument received in this function is a point |
|
639 // and it's x and y coordinate represent the width and height of the image respectively |
|
640 int vDiff=(deviceWidth - actualImageSize.x)* actualImageSize.y; |
|
641 int hDiff= (deviceHeight - actualImageSize.y) * actualImageSize.x; |
|
642 // Check which side to scale to full screen size. |
|
643 // Width or Height will be full size. |
|
644 if(hDiff > vDiff){ |
|
645 rect.height = (deviceWidth * actualImageSize.y)/actualImageSize.x; |
|
646 rect.y= (deviceHeight - rect.height)>>1;// divide by 2 |
|
647 }else { |
|
648 rect.width = (deviceHeight * actualImageSize.x)/actualImageSize.y; |
|
649 rect.x= (deviceWidth - rect.width)>>1; |
|
650 } |
|
651 return rect; |
|
652 } |
|
653 |
548 } |
654 } |