|
1 /* |
|
2 * Copyright (c) 2005 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: Long Tap Detector with animation informing of long tap functionality |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32cmn.h> |
|
21 #include <w32std.h> |
|
22 #include <AknUtils.h> |
|
23 #include <AknCapServerClient.h> // RAknUiServer |
|
24 #include <AknSgcc.h> |
|
25 #include <aknlayoutscalable_avkon.cdl.h> |
|
26 #include <aknlongtapanimation.h> |
|
27 #include <EIKSRVS.H> |
|
28 #include "AknPanic.h" |
|
29 #include "aknlongtapdetector.h" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KTimeDelayBeforeAnimation = 150000; // 0,15 seconds |
|
33 const TInt KLongTapDelay = 600000; // 0,6 seconds |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CAknLongTapDetector::CAknLongTapDetector |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CAknLongTapDetector::CAknLongTapDetector( MAknLongTapDetectorCallBack* aOwner ) |
|
43 : CTimer( 0 ), |
|
44 iState( EWaiting ), |
|
45 iOwner( aOwner ), |
|
46 iTimeDelayBeforeAnimation( KTimeDelayBeforeAnimation ), |
|
47 iLongTapDelay( KLongTapDelay ), |
|
48 iPointerEvent(), |
|
49 iShowAnimation( ETrue ) |
|
50 { |
|
51 } |
|
52 |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CAknLongTapDetector::ConstructL |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CAknLongTapDetector::ConstructL() |
|
59 { |
|
60 CTimer::ConstructL(); |
|
61 CActiveScheduler::Add( this ); |
|
62 } |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CAknLongTapDetector::NewL |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C CAknLongTapDetector* CAknLongTapDetector::NewL( MAknLongTapDetectorCallBack* aOwner ) |
|
70 { |
|
71 CAknLongTapDetector* self = CAknLongTapDetector::NewLC( aOwner ); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CAknLongTapDetector::NewLC |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C CAknLongTapDetector* CAknLongTapDetector::NewLC( MAknLongTapDetectorCallBack* aOwner ) |
|
82 { |
|
83 CAknLongTapDetector* self = new ( ELeave ) CAknLongTapDetector( aOwner ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 return self; |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CAknLongTapDetector::~CAknLongTapDetector |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C CAknLongTapDetector::~CAknLongTapDetector() |
|
95 { |
|
96 Cancel(); // CTimer |
|
97 delete iAnimation; |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CAknLongTapDetector::PointerEventL |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C void CAknLongTapDetector::PointerEventL( const TPointerEvent& aEvent ) |
|
106 { |
|
107 // offset is now 2 layout units, if the pointer is dragged just a few |
|
108 // pixels from the original point, long tap is not cancelled. |
|
109 TInt offset = AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine().iW * 2 / 5; |
|
110 if ( ( iState == EShowingAnimation || iState == EWaitingForAnimation ) |
|
111 && aEvent.iType == TPointerEvent::EDrag |
|
112 ) |
|
113 { |
|
114 TPoint aCenter = iPointerEvent.iPosition; |
|
115 TRect rect( aCenter.iX - offset, aCenter.iY - offset, |
|
116 aCenter.iX + offset, aCenter.iY + offset ); |
|
117 if ( rect.Contains( aEvent.iPosition ) ) |
|
118 { |
|
119 return; |
|
120 } |
|
121 } |
|
122 |
|
123 Cancel(); |
|
124 |
|
125 iPointerEvent = aEvent; |
|
126 |
|
127 const TWsEvent& lastEvent = CCoeEnv::Static()->LastEvent(); |
|
128 |
|
129 CCoeControl* windowControl = |
|
130 reinterpret_cast<CCoeControl*>( lastEvent.Handle() ); |
|
131 |
|
132 if ( windowControl && windowControl->DrawableWindow() && |
|
133 lastEvent.Type() == EEventPointer ) |
|
134 { |
|
135 iPointerEvent.iParentPosition = iPointerEvent.iPosition + |
|
136 windowControl->DrawableWindow()->AbsPosition(); |
|
137 } |
|
138 |
|
139 if ( iShowAnimation && iState == EWaiting |
|
140 && aEvent.iType == TPointerEvent::EButton1Down ) |
|
141 { |
|
142 iState = EWaitingForAnimation; |
|
143 After( TTimeIntervalMicroSeconds32( iTimeDelayBeforeAnimation ) ); |
|
144 } |
|
145 else |
|
146 { |
|
147 iState = EWaiting; |
|
148 } |
|
149 } |
|
150 |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CAknLongTapDetector::SetTimeDelayBeforeAnimation |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C void CAknLongTapDetector::SetTimeDelayBeforeAnimation( |
|
157 const TInt aMicroSeconds ) |
|
158 { |
|
159 if ( aMicroSeconds >= 0 ) |
|
160 { |
|
161 iTimeDelayBeforeAnimation = aMicroSeconds; |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CAknLongTapDetector::SetLongTapDelay |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C void CAknLongTapDetector::SetLongTapDelay( const TInt aMicroSeconds ) |
|
171 { |
|
172 // update longtap delay time only if it is reasonable |
|
173 if ( ( aMicroSeconds >= 0 ) && |
|
174 ( aMicroSeconds > iTimeDelayBeforeAnimation ) ) |
|
175 { |
|
176 iLongTapDelay = aMicroSeconds; |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CAknLongTapDetector::IsAnimationRunning |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 EXPORT_C TBool CAknLongTapDetector::IsAnimationRunning() const |
|
186 { |
|
187 return iState == EShowingAnimation; |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CAknLongTapDetector::CancelAnimationL |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C void CAknLongTapDetector::CancelAnimationL() |
|
195 { |
|
196 Cancel(); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CAknLongTapDetector::EnableLongTapAnimation |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 EXPORT_C void CAknLongTapDetector::EnableLongTapAnimation( |
|
204 const TBool aAnimation ) |
|
205 { |
|
206 iShowAnimation = aAnimation; |
|
207 } |
|
208 |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // CAknLongTapDetector::RunL |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 void CAknLongTapDetector::RunL() |
|
215 { |
|
216 switch ( iState ) |
|
217 { |
|
218 case EWaitingForAnimation: |
|
219 { |
|
220 iState = EShowingAnimation; |
|
221 StartAnimationL(); |
|
222 |
|
223 After( TTimeIntervalMicroSeconds32( iLongTapDelay - iTimeDelayBeforeAnimation ) ); |
|
224 break; |
|
225 } |
|
226 case EShowingAnimation: |
|
227 { |
|
228 iState = EWaiting; |
|
229 StopAnimation(); |
|
230 |
|
231 // Report long tap to owner with locations related to both owner rect and screen rect. |
|
232 iOwner->HandleLongTapEventL( iPointerEvent.iPosition, iPointerEvent.iParentPosition ); |
|
233 break; |
|
234 } |
|
235 default: |
|
236 { |
|
237 // we should never end up here. |
|
238 User::Panic( _L( "LongTapDetector" ), EAknPanicSelfCheckFailure ); |
|
239 break; |
|
240 } |
|
241 } |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CAknLongTapDetector::DoCancel |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CAknLongTapDetector::DoCancel() |
|
250 { |
|
251 CTimer::DoCancel(); |
|
252 |
|
253 if ( iState == EShowingAnimation ) |
|
254 { |
|
255 StopAnimation(); |
|
256 } |
|
257 } |
|
258 |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CAknLongTapDetector::StartAnimationL |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CAknLongTapDetector::StartAnimationL() |
|
265 { |
|
266 if ( iAnimation ) |
|
267 { |
|
268 CCoeEnv::Static()->AddMessageMonitorObserverL( *this ); |
|
269 iAnimation->ShowAnimationL( iPointerEvent.iParentPosition.iX, |
|
270 iPointerEvent.iParentPosition.iY ); |
|
271 } |
|
272 else |
|
273 { |
|
274 CCoeEnv::Static()->AddMessageMonitorObserverL( *this ); |
|
275 RAknUiServer* uiServer = CAknSgcClient::AknSrv(); |
|
276 |
|
277 TInt error = uiServer->ShowLongTapAnimation( iPointerEvent ); |
|
278 |
|
279 if ( error == KErrCouldNotConnect ) |
|
280 { |
|
281 iAnimation = CAknLongTapAnimation::NewL(); |
|
282 iAnimation->ShowAnimationL( iPointerEvent.iParentPosition.iX, |
|
283 iPointerEvent.iParentPosition.iY ); |
|
284 } |
|
285 else if ( error != KErrNone ) |
|
286 { |
|
287 User::Leave( error ); |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CAknLongTapDetector::StopAnimation |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void CAknLongTapDetector::StopAnimation() |
|
298 { |
|
299 if ( iAnimation ) |
|
300 { |
|
301 CCoeEnv::Static()->RemoveMessageMonitorObserver( *this ); |
|
302 iAnimation->HideAnimation(); |
|
303 } |
|
304 else |
|
305 { |
|
306 CCoeEnv::Static()->RemoveMessageMonitorObserver( *this ); |
|
307 RAknUiServer* uiServer = CAknSgcClient::AknSrv(); |
|
308 uiServer->HideLongTapAnimation(); |
|
309 } |
|
310 } |
|
311 |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CAknLongTapDetector::MonitorWsMessage |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CAknLongTapDetector::MonitorWsMessage(const TWsEvent& aEvent) |
|
318 { |
|
319 if ( aEvent.Type() == EEventKey || aEvent.Type() == EEventKeyUp |
|
320 || aEvent.Type() == EEventKeyDown || (aEvent.Type() == EEventPointer |
|
321 && aEvent.Pointer()->iType == TPointerEvent::EButton1Up ) ) |
|
322 { |
|
323 Cancel(); |
|
324 iState = EWaiting; |
|
325 } |
|
326 } |
|
327 |
|
328 // End of File |