|
1 /* |
|
2 * Copyright (c) 2007 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: THIS FILE IS NOT INCLUDED INTO ECLIPSE CVS DELIVERY |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <remconcoreapitarget.h> |
|
20 #include <remconinterfaceselector.h> |
|
21 #include <aknconsts.h> |
|
22 |
|
23 #include <javaremconobserver.h> |
|
24 #include <javaremconmanager.h> |
|
25 |
|
26 #include "swtmidremconobserver.h" |
|
27 |
|
28 // Keyboard delays and repeat periods |
|
29 const TInt KFirstTimerExpiryInterval = KAknKeyboardRepeatInitialDelay; |
|
30 // For second time onwards ,the duration of the time interval, is below |
|
31 // Should not be greater than 1 Minute |
|
32 const TInt KTimerExpiryInterval = KAknStandardKeyboardRepeatRate; |
|
33 |
|
34 |
|
35 EXPORT_C CSwtMIDRemConObserver* CSwtMIDRemConObserver::NewL() |
|
36 { |
|
37 CSwtMIDRemConObserver* self = new(ELeave) CSwtMIDRemConObserver(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 |
|
45 EXPORT_C CSwtMIDRemConObserver::~CSwtMIDRemConObserver() |
|
46 { |
|
47 iListeners.Close(); |
|
48 if (iJavaRemConManager) |
|
49 { |
|
50 iJavaRemConManager->RemoveObserver(*iJavaRemConObserver); |
|
51 delete iJavaRemConObserver; |
|
52 iJavaRemConObserver = NULL; |
|
53 delete iJavaRemConManager; |
|
54 iJavaRemConManager = NULL; |
|
55 } |
|
56 |
|
57 if (iRepeatTimer) |
|
58 { |
|
59 iRepeatTimer->Cancel(); |
|
60 delete iRepeatTimer; |
|
61 } |
|
62 } |
|
63 |
|
64 |
|
65 EXPORT_C void CSwtMIDRemConObserver::AddMediaKeysListenerL(MSwtMediaKeysListener* aListener) |
|
66 { |
|
67 User::LeaveIfError(iListeners.Append(aListener)); |
|
68 } |
|
69 |
|
70 |
|
71 EXPORT_C void CSwtMIDRemConObserver::RemoveMediaKeysListener(MSwtMediaKeysListener* aListener) |
|
72 { |
|
73 for (TInt i = 0; i < iListeners.Count(); i++) |
|
74 { |
|
75 if (iListeners[i] == aListener) |
|
76 { |
|
77 iListeners.Remove(i); |
|
78 } |
|
79 } |
|
80 |
|
81 } |
|
82 |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // This function handles the events when following buttons are press/click/rel |
|
86 // - Play, Stop, Forward, Backward |
|
87 // --------------------------------------------------------------------------- |
|
88 void CSwtMIDRemConObserver::MrccatoCommand(TRemConCoreApiOperationId aOperationId, |
|
89 TRemConCoreApiButtonAction aButtonAct) |
|
90 { |
|
91 MSwtMediaKeysListener::TMediaKey mediaKey = MSwtMediaKeysListener::ESwtMediaKeyNone; |
|
92 |
|
93 switch (aOperationId) |
|
94 { |
|
95 case ERemConCoreApiPausePlayFunction: |
|
96 mediaKey = MSwtMediaKeysListener::ESwtMediaKeyPlay; |
|
97 break; |
|
98 case ERemConCoreApiStop: |
|
99 mediaKey = MSwtMediaKeysListener::ESwtMediaKeyStop; |
|
100 break; |
|
101 case ERemConCoreApiForward: |
|
102 case ERemConCoreApiFastForward: |
|
103 mediaKey = MSwtMediaKeysListener::ESwtMediaKeyNext; |
|
104 break; |
|
105 case ERemConCoreApiBackward: |
|
106 case ERemConCoreApiRewind: |
|
107 mediaKey = MSwtMediaKeysListener::ESwtMediaKeyPrevious; |
|
108 break; |
|
109 default: |
|
110 return; |
|
111 } |
|
112 |
|
113 TInt eventType = EEventKeyDown; |
|
114 |
|
115 // Next/Previous keys produce Click event only if pressed briefly, otherwise they |
|
116 // produce Press events followed by Release event when the key is released. |
|
117 |
|
118 // Play/Stop keys produce Click event immediately when the key is pressed. |
|
119 |
|
120 switch (aButtonAct) |
|
121 { |
|
122 case ERemConCoreApiButtonPress: // Long key press |
|
123 iKeyRepeating = mediaKey; |
|
124 break; |
|
125 case ERemConCoreApiButtonClick: // Short key press |
|
126 eventType = EEventKeyDown; |
|
127 break; |
|
128 case ERemConCoreApiButtonRelease: // Key released after long key press. |
|
129 eventType = EEventKeyUp; |
|
130 break; |
|
131 default: |
|
132 return; |
|
133 } |
|
134 |
|
135 |
|
136 // Media keys do not provide keyReleased events when a key is pressed shortly. |
|
137 // However, keyReleased events are posted after long key press of next and previous keys. |
|
138 |
|
139 // Play and Stop does not provide keyRepeated nor keyReleased Java events at all. |
|
140 // Reason for these limitation is RemCon that does not provide such events for us. |
|
141 |
|
142 iRepeatTimer->Cancel(); //Repeat timer is always canceled if any Media key event occurs. |
|
143 |
|
144 if (aButtonAct == ERemConCoreApiButtonPress |
|
145 && !(mediaKey == MSwtMediaKeysListener::ESwtMediaKeyPlay || mediaKey == MSwtMediaKeysListener::ESwtMediaKeyStop)) |
|
146 { |
|
147 // keyPressed event is posted first, then timer for key repeats is started. |
|
148 PostRawEventToListeners(mediaKey, eventType); |
|
149 iRepeatTimer->Start(KFirstTimerExpiryInterval, KTimerExpiryInterval, |
|
150 TCallBack(RepeatTimerCallback, this)); |
|
151 } |
|
152 else if (aButtonAct == ERemConCoreApiButtonRelease |
|
153 && !(mediaKey == MSwtMediaKeysListener::ESwtMediaKeyPlay || mediaKey == MSwtMediaKeysListener::ESwtMediaKeyStop)) |
|
154 { |
|
155 // post key release event after holding Next/Previous key. |
|
156 PostRawEventToListeners(mediaKey, eventType); |
|
157 iKeyRepeating = MSwtMediaKeysListener::ESwtMediaKeyNone; |
|
158 } |
|
159 else if ((aButtonAct == ERemConCoreApiButtonRelease || aButtonAct == ERemConCoreApiButtonPress) |
|
160 && (mediaKey == MSwtMediaKeysListener::ESwtMediaKeyPlay || mediaKey == MSwtMediaKeysListener::ESwtMediaKeyStop)) |
|
161 { |
|
162 // If Press or Release event occur for Play or Stop keys we just ignore them. |
|
163 // This should not happen normally, but is possible e.g. in certain error situations. |
|
164 // Also some media key accessories differ from each other so that some might post these events. |
|
165 iKeyRepeating = MSwtMediaKeysListener::ESwtMediaKeyNone; |
|
166 return; |
|
167 } |
|
168 else |
|
169 { |
|
170 PostClickEventToListeners(mediaKey); |
|
171 iKeyRepeating = MSwtMediaKeysListener::ESwtMediaKeyNone; |
|
172 } |
|
173 } |
|
174 |
|
175 |
|
176 void CSwtMIDRemConObserver::MrccatoPlay(TRemConCoreApiPlaybackSpeed /*aSpeed*/, TRemConCoreApiButtonAction aButtonAct) |
|
177 { |
|
178 switch (aButtonAct) |
|
179 { |
|
180 case ERemConCoreApiButtonPress: |
|
181 case ERemConCoreApiButtonClick: |
|
182 { |
|
183 PostClickEventToListeners(MSwtMediaKeysListener::ESwtMediaKeyPlay); |
|
184 break; |
|
185 } |
|
186 default: |
|
187 { |
|
188 break; |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 void CSwtMIDRemConObserver::MrceoError(TInt /*aError*/) |
|
194 { |
|
195 iRepeatTimer->Cancel(); |
|
196 iKeyRepeating = MSwtMediaKeysListener::ESwtMediaKeyNone; |
|
197 } |
|
198 |
|
199 |
|
200 CSwtMIDRemConObserver::CSwtMIDRemConObserver() |
|
201 { |
|
202 } |
|
203 |
|
204 |
|
205 void CSwtMIDRemConObserver::ConstructL() |
|
206 { |
|
207 iJavaRemConObserver = CJavaRemConObserver::NewL(*this); |
|
208 iJavaRemConManager = CJavaRemConManager::NewL(); |
|
209 iJavaRemConManager->SetObserverL(*iJavaRemConObserver); |
|
210 |
|
211 // Timer for implementing key repeat feature. |
|
212 iRepeatTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
213 |
|
214 iKeyRepeating = MSwtMediaKeysListener::ESwtMediaKeyNone; |
|
215 } |
|
216 |
|
217 |
|
218 void CSwtMIDRemConObserver::PostRawEventToListeners(MSwtMediaKeysListener::TMediaKey aKeyCode, TInt aEventType) |
|
219 { |
|
220 TKeyEvent event; |
|
221 event.iCode = 0; |
|
222 event.iScanCode = aKeyCode; |
|
223 event.iModifiers = 0; |
|
224 event.iRepeats = 0; // no repeats |
|
225 |
|
226 if (iKeyRepeating != MSwtMediaKeysListener::ESwtMediaKeyNone) |
|
227 { |
|
228 event.iRepeats = 1; // repeats |
|
229 } |
|
230 else if (aEventType == EEventKeyUp) |
|
231 { |
|
232 event.iModifiers |= EModifierKeyUp; |
|
233 } |
|
234 |
|
235 for (TInt i = 0; i < iListeners.Count(); i++) |
|
236 { |
|
237 iListeners[i]->HandleMediaKeyEvent(event, aEventType); |
|
238 } |
|
239 } |
|
240 |
|
241 void CSwtMIDRemConObserver::PostClickEventToListeners(MSwtMediaKeysListener::TMediaKey aKeyCode) |
|
242 { |
|
243 PostRawEventToListeners(aKeyCode, EEventKeyDown); |
|
244 PostRawEventToListeners(aKeyCode, EEventKey); |
|
245 PostRawEventToListeners(aKeyCode, EEventKeyUp); |
|
246 } |
|
247 |
|
248 |
|
249 TInt CSwtMIDRemConObserver::RepeatTimerCallback(TAny* aThis) |
|
250 { |
|
251 CSwtMIDRemConObserver* observer = static_cast<CSwtMIDRemConObserver*>(aThis); |
|
252 observer->HandleRepeatTimerEvent(); |
|
253 return 0; |
|
254 } |
|
255 |
|
256 |
|
257 void CSwtMIDRemConObserver::HandleRepeatTimerEvent() |
|
258 { |
|
259 if (iKeyRepeating != MSwtMediaKeysListener::ESwtMediaKeyNone) |
|
260 { |
|
261 PostRawEventToListeners(iKeyRepeating, EEventKey); |
|
262 } |
|
263 } |
|
264 |
|
265 // End of File |