9 * Nokia Corporation - initial implementation |
9 * Nokia Corporation - initial implementation |
10 *******************************************************************************/ |
10 *******************************************************************************/ |
11 |
11 |
12 package org.eclipse.swt.internal.extension; |
12 package org.eclipse.swt.internal.extension; |
13 |
13 |
|
14 import org.eclipse.swt.internal.qt.OS; |
14 import org.eclipse.swt.widgets.Display; |
15 import org.eclipse.swt.widgets.Display; |
15 import org.eclipse.swt.widgets.Internal_PackageSupport; |
16 import org.eclipse.swt.widgets.Internal_PackageSupport; |
16 |
17 |
17 public final class DisplayExtension extends Display { |
18 public final class DisplayExtension extends Display { |
|
19 |
|
20 private static final class VibraRunnable implements Runnable { |
|
21 private final int duration; |
|
22 private final Display display; |
|
23 boolean result; |
|
24 private VibraRunnable(int duration, Display display) { |
|
25 this.duration = duration; |
|
26 this.display = display; |
|
27 } |
|
28 |
|
29 public void run() { |
|
30 result= OS.MobileDevice_vibration( |
|
31 Internal_PackageSupport.initializeMobileDevice(display),duration); |
|
32 |
|
33 } |
|
34 } |
|
35 private static final class FlashBacklightsRunnable implements Runnable { |
|
36 private final Display display; |
|
37 private final int duration; |
|
38 boolean result; |
|
39 |
|
40 private FlashBacklightsRunnable(Display display, int duration) { |
|
41 this.display = display; |
|
42 this.duration = duration; |
|
43 } |
|
44 |
|
45 public void run() { |
|
46 result = OS.MobileDevice_flashLights( |
|
47 Internal_PackageSupport.initializeMobileDevice( |
|
48 display),duration); |
|
49 } |
|
50 } |
18 |
51 |
19 /* Image types, same values as MIDP */ |
52 /* Image types, same values as MIDP */ |
20 public static final int LIST_ELEMENT = 1; |
53 public static final int LIST_ELEMENT = 1; |
21 public static final int CHOICE_GROUP_ELEMENT = 2; |
54 public static final int CHOICE_GROUP_ELEMENT = 2; |
22 public static final int ALERT = 3; |
55 public static final int ALERT = 3; |
48 * @return Default display if one has been initialized otherwise null |
81 * @return Default display if one has been initialized otherwise null |
49 */ |
82 */ |
50 public static Display getDisplayInstance() { |
83 public static Display getDisplayInstance() { |
51 return Internal_PackageSupport.getDisplayInstance(); |
84 return Internal_PackageSupport.getDisplayInstance(); |
52 } |
85 } |
53 |
86 /** |
|
87 * Flashes devices backlight. |
|
88 * |
|
89 * @param duration Duration in milliseconds. |
|
90 * @return false if no flashing happened because MIDlet was in background or |
|
91 * feature is not supported. |
|
92 */ |
|
93 public static boolean flashLights( final int duration ){ |
|
94 final Display display = getDisplayInstance(); |
|
95 if (display == null || display.isDisposed() ) return false; |
|
96 FlashBacklightsRunnable runnable = new FlashBacklightsRunnable(display, duration); |
|
97 display.syncExec(runnable); |
|
98 return runnable.result; |
|
99 } |
|
100 /** |
|
101 * Vibrates device |
|
102 * |
|
103 * @param duration Duration in milliseconds. |
|
104 * @return false if no vibration happened because MIDlet was in background |
|
105 * or feature is not supported. |
|
106 */ |
|
107 public static boolean startVibra(final int duration) { |
|
108 final Display display = getDisplayInstance(); |
|
109 if (display == null || display.isDisposed() ) return false; |
|
110 VibraRunnable runnable = new VibraRunnable(duration, display); |
|
111 display.syncExec(runnable); |
|
112 return runnable.result; |
|
113 } |
|
114 /** |
|
115 * |
|
116 * @param imageType |
|
117 * @return |
|
118 */ |
54 private static int getBestImageSize(int imageType) { |
119 private static int getBestImageSize(int imageType) { |
55 switch (imageType) { |
120 switch (imageType) { |
56 case LIST_ELEMENT: |
121 case LIST_ELEMENT: |
57 case CHOICE_GROUP_ELEMENT: |
122 case CHOICE_GROUP_ELEMENT: |
58 return Style.pixelMetric(Style.QSTYLE_PM_SMALLICONSIZE); |
123 return Style.pixelMetric(Style.QSTYLE_PM_SMALLICONSIZE); |