1 /* |
|
2 * Copyright (c) 2006 - 2008 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: AppUi class of the application. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <aknnotewrappers.h> |
|
21 #include <touchscreencalib.rsg> |
|
22 #include <e32property.h> |
|
23 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
24 #include "touchscprivatepskeys.h" |
|
25 #else //RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
26 #include <StartupAppInternalPSKeys.h> |
|
27 #endif //RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
28 #include <aknlayoutscalable_apps.cdl.h> |
|
29 #include <layoutmetadata.cdl.h> |
|
30 #include <centralrepository.h> |
|
31 #include <starterdomaincrkeys.h> |
|
32 #include <starterclient.h> //used for RemoveSplashScreen |
|
33 |
|
34 // USER INCLUDES |
|
35 #include "TouchScreenCalibApplication.h" |
|
36 #include "TouchScreenCalibAppUi.h" |
|
37 #include "TouchScreenCalibDefines.h" |
|
38 #include "TouchScreenCalibDocument.h" |
|
39 #include "TouchScreenCalibView.h" |
|
40 #include "TouchScreenCalibPubSubObserver.h" |
|
41 |
|
42 // CONSTANTS |
|
43 |
|
44 _LIT_SECURITY_POLICY_C1(KReadDeviceDataPolicy, ECapabilityReadDeviceData); |
|
45 _LIT_SECURITY_POLICY_C1(KWriteDeviceDataPolicy, ECapabilityWriteDeviceData); |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 // |
|
49 // ---------------------------------------------------- |
|
50 // CTouchScreenCalibAppUi::CTouchScreenCalibAppUi() |
|
51 // ---------------------------------------------------- |
|
52 CTouchScreenCalibAppUi::CTouchScreenCalibAppUi(): |
|
53 iTouchScreenCalibPubSubObserver( NULL ), |
|
54 iCurrentCalibrationStep( 0 ), |
|
55 iExitting( EFalse ), |
|
56 iCalibrationDone( EFalse ), |
|
57 iCalibrationCancel( EFalse ) |
|
58 { |
|
59 TRACES("CTouchScreenCalibAppUi::CTouchScreenCalibAppUi"); |
|
60 iNativeOrientation = KUnknownOrientation; |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------- |
|
64 // CTouchScreenCalibAppUi::ConstructL() |
|
65 // ---------------------------------------------------- |
|
66 void CTouchScreenCalibAppUi::ConstructL() |
|
67 { |
|
68 TRACES("CTouchScreenCalibAppUi::ConstructL()"); |
|
69 TInt flags = EStandardApp|EAknEnableSkin; |
|
70 |
|
71 BaseConstructL(flags); |
|
72 |
|
73 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
74 RProperty::Define(KPSUidTouchScreenCalibration, |
|
75 #else //RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
76 RProperty::Define(KPSUidStartup, |
|
77 #endif //RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
78 KPSTouchScreenCalibration, |
|
79 RProperty::EInt, |
|
80 KReadDeviceDataPolicy, |
|
81 KWriteDeviceDataPolicy ); |
|
82 |
|
83 // Clearing the calibration before doing the actual calibration |
|
84 TDigitizerCalibrationType caltype = EFactory; |
|
85 UserHal::RestoreXYInputCalibration(caltype); |
|
86 ResetTapPoints(); |
|
87 |
|
88 // SetOrientation(); |
|
89 |
|
90 iCalibrationPoints = CalibrationPoints(); |
|
91 |
|
92 // Set TSC application to be system application |
|
93 CEikonEnv& eikEnv = *CEikonEnv::Static(); |
|
94 eikEnv.SetSystem( ETrue ); |
|
95 |
|
96 iTouchScreenCalibLayout.iAnimImageLayout1.LayoutRect(Rect(),AknLayoutScalable_Apps::main_touch_calib_pane_g1().LayoutLine()); |
|
97 iTouchScreenCalibLayout.iAnimImageLayout2.LayoutRect(Rect(),AknLayoutScalable_Apps::main_touch_calib_pane_g2().LayoutLine()); |
|
98 iTouchScreenCalibLayout.iAnimImageLayout3.LayoutRect(Rect(),AknLayoutScalable_Apps::main_touch_calib_pane_g3().LayoutLine()); |
|
99 iTouchScreenCalibLayout.iAnimImageLayout4.LayoutRect(Rect(),AknLayoutScalable_Apps::main_touch_calib_pane_g4().LayoutLine()); |
|
100 |
|
101 iTouchScreenCalibView = CTouchScreenCalibView::NewL( this ); |
|
102 AddToStackL( iTouchScreenCalibView ); |
|
103 |
|
104 iTouchScreenCalibView->SetWinPriority(0); |
|
105 // Disable priority changes of window server |
|
106 eikEnv.WsSession().ComputeMode( RWsSession::EPriorityControlDisabled ); |
|
107 |
|
108 UpdateL(); |
|
109 |
|
110 iTouchScreenCalibPubSubObserver = CTouchScreenCalibPubSubObserver::NewL( this ); |
|
111 |
|
112 if (FirstBoot()) |
|
113 { |
|
114 TRACES("CTouchScreenCalibAppUi::ConstructL(): First boot ongoing"); |
|
115 TRACES("CTouchScreenCalibAppUi::ConstructL(): Connect to Starter"); |
|
116 RStarterSession startersession; |
|
117 if( startersession.Connect() == KErrNone ) |
|
118 { |
|
119 TRACES("CTouchScreenCalibAppUi::ConstructL(): Connected to Starter"); |
|
120 startersession.EndSplashScreen(); |
|
121 TRACES("CTouchScreenCalibAppUi::ConstructL(): Splash screen removed"); |
|
122 startersession.Close(); |
|
123 } |
|
124 } |
|
125 NextCalibrationStepL(); |
|
126 |
|
127 TRACES("CTouchScreenCalibAppUi::ConstructL(): End"); |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------- |
|
131 // CTouchScreenCalibAppUi::~CTouchScreenCalibAppUi() |
|
132 // ---------------------------------------------------- |
|
133 CTouchScreenCalibAppUi::~CTouchScreenCalibAppUi() |
|
134 { |
|
135 TRACES("CTouchScreenCalibAppUi::~CTouchScreenCalibAppUi()"); |
|
136 if (iTouchScreenCalibView) |
|
137 { |
|
138 TRACES("CTouchScreenCalibAppUi::~CTouchScreenCalibAppUi(): delete iTouchScreenCalibView"); |
|
139 RemoveFromStack( iTouchScreenCalibView ); |
|
140 delete iTouchScreenCalibView; |
|
141 } |
|
142 if (iTouchScreenCalibPubSubObserver) |
|
143 { |
|
144 TRACES("CTouchScreenCalibAppUi::~CTouchScreenCalibAppUi(): delete iTouchScreenCalibPubSubObserver"); |
|
145 delete iTouchScreenCalibPubSubObserver; |
|
146 } |
|
147 TRACES("CTouchScreenCalibAppUi::~CTouchScreenCalibAppUi(): End"); |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------- |
|
151 // CTouchScreenCalibAppUi::NextCalibrationStepL() |
|
152 // ---------------------------------------------------- |
|
153 void CTouchScreenCalibAppUi::NextCalibrationStepL() |
|
154 { |
|
155 TRACES("CTouchScreenCalibAppUi::NextCalibrationStepL()"); |
|
156 TRACES2("CTouchScreenCalibAppUi::NextCalibrationStepL(): TapPoint1: %d %d",iTapPoints.iTl.iX, iTapPoints.iTl.iY); |
|
157 TRACES2("CTouchScreenCalibAppUi::NextCalibrationStepL(): TapPoint2: %d %d",iTapPoints.iTr.iX, iTapPoints.iTr.iY); |
|
158 TRACES2("CTouchScreenCalibAppUi::NextCalibrationStepL(): TapPoint3: %d %d",iTapPoints.iBr.iX, iTapPoints.iBr.iY); |
|
159 TRACES2("CTouchScreenCalibAppUi::NextCalibrationStepL(): TapPoint4: %d %d",iTapPoints.iBl.iX, iTapPoints.iBl.iY); |
|
160 iCurrentCalibrationStep++; |
|
161 TRACES1("CTouchScreenCalibAppUi::NextCalibrationStepL(): CurrentCalibrationStep: %d",iCurrentCalibrationStep); |
|
162 |
|
163 if (iCurrentCalibrationStep > 4) |
|
164 { |
|
165 TRACES("CTouchScreenCalibAppUi::NextCalibrationStepL(): Calibration succesfully completed. Save it and exit application."); |
|
166 SaveCalibration(); |
|
167 iCalibrationDone = ETrue; |
|
168 |
|
169 iTouchScreenCalibView->EndTargetAnimation(); |
|
170 iTouchScreenCalibView->SetWinPriority(ECoeWinPriorityNormal); |
|
171 TRACES("CTouchScreenCalibAppUi::NextCalibrationStepL(): Show 'Calibration Done' note"); |
|
172 HBufC* noteText = CEikonEnv::Static()->AllocReadResourceLC(R_QTN_TOUCH_SCREEN_CALI_DONE ); |
|
173 CAknInformationNote* note = |
|
174 new( ELeave ) CAknInformationNote( ETrue ); |
|
175 note->ExecuteLD( *noteText ); |
|
176 CleanupStack::PopAndDestroy( noteText ); |
|
177 if ( FirstBoot() ) |
|
178 { |
|
179 iTouchScreenCalibView->DrawEndingBackground(); |
|
180 #ifdef RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
181 RProperty::Set( KPSUidTouchScreenCalibration, KPSTouchScreenCalibration, ETouchScreenCalibrationOk ); |
|
182 #else //RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
183 RProperty::Set( KPSUidStartup, KPSTouchScreenCalibration, ETouchScreenCalibrationOk ); |
|
184 #endif //RD_STARTUP_ANIMATION_CUSTOMIZATION |
|
185 iTouchScreenCalibView->SetWinPriority(0); |
|
186 } |
|
187 else |
|
188 { |
|
189 PrepareToExit(); |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 TRACES("CTouchScreenCalibAppUi::NextCalibrationStepL(): Update next step."); |
|
195 UpdateL(); |
|
196 } |
|
197 TRACES("CTouchScreenCalibAppUi::NextCalibrationStepL(): End"); |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------- |
|
201 // CTouchScreenCalibAppUi::SaveCalibration() |
|
202 // ---------------------------------------------------- |
|
203 void CTouchScreenCalibAppUi::SaveCalibration() |
|
204 { |
|
205 TRACES("CTouchScreenCalibAppUi::SaveCalibration()"); |
|
206 |
|
207 // Touch Screen driver supports only portrait orientation. If device is now in |
|
208 // landscape mode, convert points to portrait. |
|
209 TDigitizerCalibration tapPoints = ConvertToCorrectOrientation(iTapPoints, |
|
210 KConvertSaveCase); |
|
211 UserHal::SetXYInputCalibration(tapPoints); |
|
212 TRACES("CTouchScreenCalibAppUi::SaveCalibration(): End"); |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------- |
|
216 // CTouchScreenCalibAppUi::ResetCalibrationStepsL() |
|
217 // ---------------------------------------------------- |
|
218 void CTouchScreenCalibAppUi::ResetCalibrationStepsL() |
|
219 { |
|
220 iCurrentCalibrationStep = 0; |
|
221 ResetTapPoints(); |
|
222 NextCalibrationStepL(); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // CTouchScreenCalibAppUi::HandleForegroundEventL(TBool aForeground) |
|
227 // --------------------------------------------------------------------------- |
|
228 void CTouchScreenCalibAppUi::HandleForegroundEventL( TBool aForeground ) |
|
229 { |
|
230 // call super-class first |
|
231 CAknAppUi::HandleForegroundEventL( aForeground ); |
|
232 TRACES1("CTouchScreenCalibAppUi::HandleForegroundEventL( %d )", aForeground); |
|
233 if ( aForeground ) |
|
234 { |
|
235 // if we are coming to foreground |
|
236 UpdateL(); |
|
237 } |
|
238 else |
|
239 { |
|
240 if (!FirstBoot()) |
|
241 { |
|
242 // Take old calibration in use |
|
243 TDigitizerCalibrationType caltype = ESaved; |
|
244 UserHal::RestoreXYInputCalibration(caltype); |
|
245 PrepareToExit(); |
|
246 } |
|
247 } |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // CTouchScreenCalibAppUi::HandleKeyL(const TKeyEvent& aKeyEvent, TEventCode /*aType*/ ) |
|
252 // --------------------------------------------------------------------------- |
|
253 void CTouchScreenCalibAppUi::HandleKeyL( const TKeyEvent& aKeyEvent, TEventCode /*aType*/ ) |
|
254 { |
|
255 TRACES1("CTouchScreenCalibAppUi::HandleKeyL(): %d",aKeyEvent.iCode); |
|
256 |
|
257 if (aKeyEvent.iCode == EKeyYes) //Send key |
|
258 { |
|
259 TRACES("CTouchScreenCalibAppUi::HandleKeyL(): Send Key"); |
|
260 if (FirstBoot()) // Restart calibration from step 1 |
|
261 { |
|
262 TRACES("CTouchScreenCalibAppUi::HandleKey(): Go to first calibration step"); |
|
263 ResetCalibrationStepsL(); |
|
264 } |
|
265 else// Show "Calibration cancelled" Information note. |
|
266 { |
|
267 TRACES("CTouchScreenCalibAppUi::HandleKeyL(): Show cancel note"); |
|
268 iCalibrationCancel = ETrue; |
|
269 |
|
270 iTouchScreenCalibView->EndAnimation(); |
|
271 iTouchScreenCalibView->SetWinPriority(ECoeWinPriorityNormal); |
|
272 HBufC* noteText = CEikonEnv::Static()->AllocReadResourceLC(R_QTN_TOUCH_SCREEN_CALI_CANCEL ); |
|
273 CAknInformationNote* note = |
|
274 new( ELeave ) CAknInformationNote( ETrue ); |
|
275 note->ExecuteLD( *noteText ); |
|
276 CleanupStack::PopAndDestroy( noteText ); |
|
277 |
|
278 // Take old calibration in use |
|
279 TDigitizerCalibrationType caltype = ESaved; |
|
280 UserHal::RestoreXYInputCalibration(caltype); |
|
281 PrepareToExit(); |
|
282 } |
|
283 } |
|
284 else if ( aKeyEvent.iCode == EKeyNo || aKeyEvent.iCode == EKeyApplication0 |
|
285 || ( aKeyEvent.iCode == EKeyNull && aKeyEvent.iScanCode == EStdKeyDevice7 )) |
|
286 { |
|
287 TRACES("CTouchScreenCalibAppUi::HandleKeyL(): End Key or App Key"); |
|
288 if (!FirstBoot()) |
|
289 { |
|
290 // Take old calibration in use |
|
291 TDigitizerCalibrationType caltype = ESaved; |
|
292 UserHal::RestoreXYInputCalibration(caltype); |
|
293 PrepareToExit(); |
|
294 } |
|
295 } |
|
296 TRACES("CTouchScreenCalibAppUi::HandleKeyL(): End"); |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // CTouchScreenCalibAppUi::HandlePointerL() |
|
301 // --------------------------------------------------------------------------- |
|
302 void CTouchScreenCalibAppUi::HandlePointerL( TPoint aPos ) |
|
303 { |
|
304 TRACES("CTouchScreenCalibAppUi::HandlePointerL()"); |
|
305 |
|
306 switch(iCurrentCalibrationStep) |
|
307 { |
|
308 case 1: |
|
309 TRACES("CTouchScreenCalibAppUi::HandlePointerL(): case 1"); |
|
310 iTapPoints.iTl.iX = aPos.iX; |
|
311 iTapPoints.iTl.iY = aPos.iY; |
|
312 break; |
|
313 case 2: |
|
314 TRACES("CTouchScreenCalibAppUi::HandlePointerL(): case 2"); |
|
315 iTapPoints.iTr.iX = aPos.iX; |
|
316 iTapPoints.iTr.iY = aPos.iY; |
|
317 break; |
|
318 case 3: |
|
319 TRACES("CTouchScreenCalibAppUi::HandlePointerL(): case 4"); |
|
320 iTapPoints.iBr.iX = aPos.iX; |
|
321 iTapPoints.iBr.iY = aPos.iY; |
|
322 break; |
|
323 case 4: |
|
324 TRACES("CTouchScreenCalibAppUi::HandlePointerL(): case 3"); |
|
325 iTapPoints.iBl.iX = aPos.iX; |
|
326 iTapPoints.iBl.iY = aPos.iY; |
|
327 break; |
|
328 default: |
|
329 TRACES("CTouchScreenCalibAppUi::HandlePointerL(): case default"); |
|
330 break; |
|
331 } |
|
332 TRACES("CTouchScreenCalibAppUi::HandlePointerL(): End: Continue calibration"); |
|
333 NextCalibrationStepL(); |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CTouchScreenCalibAppUi::PrepareToExit() |
|
338 // --------------------------------------------------------------------------- |
|
339 void CTouchScreenCalibAppUi::PrepareToExit() |
|
340 { |
|
341 TRACES("CTouchScreenCalibAppUi::PrepareToExit()"); |
|
342 if (!iExitting) |
|
343 { |
|
344 iExitting = ETrue; |
|
345 CEikAppUi::PrepareToExit(); |
|
346 Exit(); |
|
347 } |
|
348 TRACES("CTouchScreenCalibAppUi::PrepareToExit(): End"); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // CTouchScreenCalibAppUi::ResetTapPoints() |
|
353 // --------------------------------------------------------------------------- |
|
354 void CTouchScreenCalibAppUi::ResetTapPoints() |
|
355 { |
|
356 TRACES("CTouchScreenCalibAppUi::ResetTapPoints()"); |
|
357 iTapPoints.iTl.iX = 0; |
|
358 iTapPoints.iTl.iY = 0; |
|
359 iTapPoints.iTr.iX = 0; |
|
360 iTapPoints.iTr.iY = 0; |
|
361 iTapPoints.iBr.iX = 0; |
|
362 iTapPoints.iBr.iY = 0; |
|
363 iTapPoints.iBl.iX = 0; |
|
364 iTapPoints.iBl.iY = 0; |
|
365 TRACES("CTouchScreenCalibAppUi::ResetTapPoints(): End"); |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // CTouchScreenCalibAppUi::UpdateL() |
|
370 // --------------------------------------------------------------------------- |
|
371 void CTouchScreenCalibAppUi::UpdateL() |
|
372 { |
|
373 TRACES("CTouchScreenCalibAppUi::UpdateL()"); |
|
374 TRACES1("CTouchScreenCalibAppUi::UpdateL(): iCurrentCalibrationStep: %d",iCurrentCalibrationStep); |
|
375 |
|
376 TAknLayoutText textLayout; |
|
377 textLayout.LayoutText(TRect(), AknLayoutScalable_Apps::main_touch_calib_pane_t1().LayoutLine()); |
|
378 |
|
379 TRACES2("CTouchScreenCalibAppUi::UpdateL(): Text rect top: X:%d Y:%d",textLayout.TextRect().iTl.iX, textLayout.TextRect().iTl.iY); |
|
380 TRACES2("CTouchScreenCalibAppUi::UpdateL(): Text rect:bottom: X:%d Y:%d",textLayout.TextRect().iBr.iX, textLayout.TextRect().iBr.iY); |
|
381 |
|
382 iTouchScreenCalibView->UpdateL(textLayout); |
|
383 |
|
384 TRACES("CTouchScreenCalibAppUi::UpdateL(): End"); |
|
385 } |
|
386 |
|
387 // --------------------------------------------------------------------------- |
|
388 // CTouchScreenCalibAppUi::GetCalibrationStep() |
|
389 // --------------------------------------------------------------------------- |
|
390 TInt CTouchScreenCalibAppUi::GetCalibrationStep() |
|
391 { |
|
392 return iCurrentCalibrationStep; |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // CTouchScreenCalibAppUi::GetAnimImageRect() |
|
397 // --------------------------------------------------------------------------- |
|
398 TRect CTouchScreenCalibAppUi::GetAnimImageRect(TInt aPointNumber) |
|
399 { |
|
400 TRACES1("CTouchScreenCalibAppUi::GetAnimImageRect(%d)", aPointNumber); |
|
401 TRect rect; |
|
402 TInt width(0); |
|
403 TInt height(0); |
|
404 |
|
405 // If aPointNumber is 0, return current calibration point. |
|
406 if (aPointNumber == 0) |
|
407 { |
|
408 aPointNumber = GetCalibrationStep(); |
|
409 } |
|
410 |
|
411 switch (aPointNumber) |
|
412 { |
|
413 case 1: |
|
414 width = iTouchScreenCalibLayout.iAnimImageLayout1.Rect().iBr.iX - |
|
415 iTouchScreenCalibLayout.iAnimImageLayout1.Rect().iTl.iX; |
|
416 height= iTouchScreenCalibLayout.iAnimImageLayout1.Rect().iBr.iY - |
|
417 iTouchScreenCalibLayout.iAnimImageLayout1.Rect().iTl.iY; |
|
418 |
|
419 rect = TRect(TPoint( iCalibrationPoints.iTl.iX - (width/2), |
|
420 iCalibrationPoints.iTl.iY - (height/2)), |
|
421 TPoint( iCalibrationPoints.iTl.iX + (width/2), |
|
422 iCalibrationPoints.iTl.iY + (height/2))); |
|
423 break; |
|
424 case 2: |
|
425 width = iTouchScreenCalibLayout.iAnimImageLayout2.Rect().iBr.iX - |
|
426 iTouchScreenCalibLayout.iAnimImageLayout2.Rect().iTl.iX; |
|
427 height= iTouchScreenCalibLayout.iAnimImageLayout2.Rect().iBr.iY - |
|
428 iTouchScreenCalibLayout.iAnimImageLayout2.Rect().iTl.iY; |
|
429 |
|
430 rect = TRect(TPoint( iCalibrationPoints.iTr.iX - (width/2), |
|
431 iCalibrationPoints.iTr.iY - (height/2)), |
|
432 TPoint( iCalibrationPoints.iTr.iX + (width/2), |
|
433 iCalibrationPoints.iTr.iY + (height/2))); |
|
434 break; |
|
435 case 3: |
|
436 width = iTouchScreenCalibLayout.iAnimImageLayout3.Rect().iBr.iX - |
|
437 iTouchScreenCalibLayout.iAnimImageLayout3.Rect().iTl.iX; |
|
438 height= iTouchScreenCalibLayout.iAnimImageLayout3.Rect().iBr.iY - |
|
439 iTouchScreenCalibLayout.iAnimImageLayout3.Rect().iTl.iY; |
|
440 |
|
441 rect = TRect(TPoint( iCalibrationPoints.iBr.iX - (width/2), |
|
442 iCalibrationPoints.iBr.iY - (height/2)), |
|
443 TPoint( iCalibrationPoints.iBr.iX + (width/2), |
|
444 iCalibrationPoints.iBr.iY + (height/2))); |
|
445 break; |
|
446 case 4: |
|
447 width = iTouchScreenCalibLayout.iAnimImageLayout4.Rect().iBr.iX - |
|
448 iTouchScreenCalibLayout.iAnimImageLayout4.Rect().iTl.iX; |
|
449 height= iTouchScreenCalibLayout.iAnimImageLayout4.Rect().iBr.iY - |
|
450 iTouchScreenCalibLayout.iAnimImageLayout4.Rect().iTl.iY; |
|
451 |
|
452 rect = TRect(TPoint( iCalibrationPoints.iBl.iX - (width/2), |
|
453 iCalibrationPoints.iBl.iY - (height/2)), |
|
454 TPoint( iCalibrationPoints.iBl.iX + (width/2), |
|
455 iCalibrationPoints.iBl.iY + (height/2))); |
|
456 break; |
|
457 default: |
|
458 break; |
|
459 } |
|
460 TRACES("CTouchScreenCalibAppUi::GetAnimImageRect(): End"); |
|
461 return rect; |
|
462 } |
|
463 |
|
464 // --------------------------------------------------------------------------- |
|
465 // CTouchScreenCalibAppUi::HandleResourceChange(...) |
|
466 // --------------------------------------------------------------------------- |
|
467 void CTouchScreenCalibAppUi::HandleScreenDeviceChangedL() |
|
468 { |
|
469 TRACES("CTouchScreenCalibAppUi::HandleResourceChange()"); |
|
470 CAknAppUiBase::HandleScreenDeviceChangedL(); |
|
471 |
|
472 if (!iCalibrationDone && !iCalibrationCancel ) |
|
473 { |
|
474 TRACES("CTouchScreenCalibAppUi::HandleResourceChange(): Restart calibration"); |
|
475 iCalibrationPoints = CalibrationPoints(); |
|
476 if (iTouchScreenCalibView) |
|
477 { |
|
478 RemoveFromStack( iTouchScreenCalibView ); |
|
479 delete iTouchScreenCalibView; |
|
480 iTouchScreenCalibView = NULL; |
|
481 } |
|
482 iTouchScreenCalibView = CTouchScreenCalibView::NewL( this ); |
|
483 AddToStackL( iTouchScreenCalibView ); |
|
484 ResetCalibrationStepsL(); |
|
485 } |
|
486 else |
|
487 { |
|
488 TRACES("CTouchScreenCalibAppUi::HandleResourceChange(): Update ending background"); |
|
489 iTouchScreenCalibView->DrawEndingBackground(); |
|
490 } |
|
491 TRACES("CTouchScreenCalibAppUi::HandleResourceChange(): End"); |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // CTouchScreenCalibAppUi::CalibrationPoints(); |
|
496 // --------------------------------------------------------------------------- |
|
497 TDigitizerCalibration CTouchScreenCalibAppUi::CalibrationPoints() |
|
498 { |
|
499 TRACES("CTouchScreenCalibAppUi::CalibrationPoints()"); |
|
500 TDigitizerCalibration calibrationPoints; |
|
501 #if defined(__WINS__) |
|
502 // Dummy values for emulator for testing purposes |
|
503 TRect rect = iAvkonAppUi->ApplicationRect(); |
|
504 TRACES2("CTouchScreenCalibAppUi::CalibrationPoints(): Window resolution: (%d. %d)",rect.iBr.iX,rect.iBr.iY); |
|
505 |
|
506 calibrationPoints.iTl.iX = rect.iTl.iX+50; |
|
507 calibrationPoints.iTl.iY = rect.iTl.iY+50; |
|
508 calibrationPoints.iTr.iX = rect.iBr.iX-50; |
|
509 calibrationPoints.iTr.iY = rect.iTl.iY+50; |
|
510 calibrationPoints.iBr.iX = rect.iBr.iX-50; |
|
511 calibrationPoints.iBr.iY = rect.iBr.iY-50; |
|
512 calibrationPoints.iBl.iX = rect.iTl.iX+50; |
|
513 calibrationPoints.iBl.iY = rect.iBr.iY-50; |
|
514 #else |
|
515 UserHal::CalibrationPoints(calibrationPoints); |
|
516 #endif |
|
517 |
|
518 // Orientation in driver level could be different than window orientation. Convert |
|
519 // points to correct orientation. |
|
520 if (calibrationPoints.iBr.iX > calibrationPoints.iBr.iY ) |
|
521 { |
|
522 TRACES("CTouchScreenCalibAppUi::CalibrationPoints(): Native orientation: landscape"); |
|
523 iNativeOrientation = KLandscapeOrientation; |
|
524 } |
|
525 else |
|
526 { |
|
527 TRACES("CTouchScreenCalibAppUi::CalibrationPoints(): Native orientation: portrait"); |
|
528 iNativeOrientation = KPortraitOrientation; |
|
529 } |
|
530 calibrationPoints = ConvertToCorrectOrientation(calibrationPoints, KConvertGetCase); |
|
531 |
|
532 TRACES("CTouchScreenCalibAppUi::CalibrationPoints(): End"); |
|
533 return calibrationPoints; |
|
534 } |
|
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // CTouchScreenCalibAppUi::ConvertToCorrectOrientation(TDigitizerCalibration aPoints); |
|
538 // --------------------------------------------------------------------------- |
|
539 TDigitizerCalibration CTouchScreenCalibAppUi::ConvertToCorrectOrientation(TDigitizerCalibration aPoints, |
|
540 TInt aConvertCase) |
|
541 { |
|
542 TRACES("CTouchScreenCalibAppUi::ConvertToCorrectOrientation()"); |
|
543 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", aPoints.iTl.iX,aPoints.iTl.iY); |
|
544 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", aPoints.iTr.iX,aPoints.iTr.iY); |
|
545 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", aPoints.iBr.iX,aPoints.iBr.iY); |
|
546 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", aPoints.iBl.iX,aPoints.iBl.iY); |
|
547 TDigitizerCalibration points; |
|
548 TPoint destReso; |
|
549 |
|
550 TRect rect = iAvkonAppUi->ApplicationRect(); |
|
551 |
|
552 if (!IsCorrectOrientation(rect)) |
|
553 { |
|
554 TRACES("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): Points are not for current layout."); |
|
555 if (aConvertCase == KConvertGetCase) |
|
556 { |
|
557 destReso.iX = rect.iBr.iX; |
|
558 destReso.iY = rect.iBr.iY; |
|
559 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): Destin reso: X:%d Y:%d", destReso.iX,destReso.iY); |
|
560 points = ChangeOrientation(aPoints, destReso); |
|
561 } |
|
562 else |
|
563 { |
|
564 destReso.iX = rect.iBr.iY; |
|
565 destReso.iY = rect.iBr.iX; |
|
566 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): Destin reso: X:%d Y:%d", destReso.iX,destReso.iY); |
|
567 points = ChangeOrientation(aPoints, destReso); |
|
568 } |
|
569 } |
|
570 else |
|
571 { |
|
572 points = aPoints; |
|
573 } |
|
574 |
|
575 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", points.iTl.iX,points.iTl.iY); |
|
576 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", points.iTr.iX,points.iTr.iY); |
|
577 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", points.iBr.iX,points.iBr.iY); |
|
578 TRACES2("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): X:%d Y:%d", points.iBl.iX,points.iBl.iY); |
|
579 |
|
580 TRACES("CTouchScreenCalibAppUi::ConvertToCorrectOrientation(): End"); |
|
581 return points; |
|
582 } |
|
583 |
|
584 // --------------------------------------------------------------------------- |
|
585 // CTouchScreenCalibAppUi::IsCorrectOrientation(TRect aRect) |
|
586 // --------------------------------------------------------------------------- |
|
587 TBool CTouchScreenCalibAppUi::IsCorrectOrientation(TRect aRect) |
|
588 { |
|
589 TRACES("CTouchScreenCalibAppUi::IsCorrectOrientation()"); |
|
590 TBool ret(ETrue); |
|
591 TBool nativePortrait(ETrue); |
|
592 |
|
593 if (iNativeOrientation == KLandscapeOrientation) |
|
594 { |
|
595 TRACES("CTouchScreenCalibAppUi::IsCorrectOrientation(): Native orientation: landscape"); |
|
596 nativePortrait = EFalse; |
|
597 } |
|
598 |
|
599 TBool windowsPortrait(ETrue); |
|
600 |
|
601 if (aRect.iBr.iX > aRect.iBr.iY) |
|
602 { |
|
603 TRACES("CTouchScreenCalibAppUi::IsCorrectOrientation(): Window orientation: landscape"); |
|
604 windowsPortrait = EFalse; |
|
605 } |
|
606 else |
|
607 { |
|
608 windowsPortrait = ETrue; |
|
609 } |
|
610 |
|
611 if (nativePortrait != windowsPortrait) |
|
612 { |
|
613 ret = EFalse; |
|
614 } |
|
615 |
|
616 TRACES1("CTouchScreenCalibAppUi::IsCorrectOrientation(): End: returns %d",ret); |
|
617 return ret; |
|
618 } |
|
619 |
|
620 // --------------------------------------------------------------------------- |
|
621 // CTouchScreenCalibAppUi::ChangeOrientation(TDigitizerCalibration aPoints); |
|
622 // --------------------------------------------------------------------------- |
|
623 TDigitizerCalibration CTouchScreenCalibAppUi::ChangeOrientation(TDigitizerCalibration aSourcePoints, |
|
624 TPoint aDestReso) |
|
625 { |
|
626 TRACES("CTouchScreenCalibAppUi::ChangeOrientation()"); |
|
627 TDigitizerCalibration destPoints; |
|
628 |
|
629 destPoints.iTl.iX = aSourcePoints.iTr.iY; |
|
630 destPoints.iTl.iY = aDestReso.iY - aSourcePoints.iTr.iX; |
|
631 destPoints.iTr.iX = aSourcePoints.iBr.iY; |
|
632 destPoints.iTr.iY = aDestReso.iY - aSourcePoints.iBr.iX; |
|
633 destPoints.iBr.iX = aSourcePoints.iBl.iY; |
|
634 destPoints.iBr.iY = aDestReso.iY - aSourcePoints.iBl.iX; |
|
635 destPoints.iBl.iX = aSourcePoints.iTl.iY; |
|
636 destPoints.iBl.iY = aDestReso.iY - aSourcePoints.iTl.iX; |
|
637 |
|
638 |
|
639 TRACES("CTouchScreenCalibAppUi::ChangeOrientation(): End"); |
|
640 return destPoints; |
|
641 } |
|
642 |
|
643 // --------------------------------------------------------- |
|
644 // CTouchScreenCalibAppUi::FirstBoot() |
|
645 // --------------------------------------------------------- |
|
646 TBool CTouchScreenCalibAppUi::FirstBoot() |
|
647 { |
|
648 TRACES("CTouchScreenCalibAppUi::FirstBoot()"); |
|
649 TInt value( 0 ); |
|
650 |
|
651 TRACES("CTouchScreenCalibAppUi::FirstBoot(): Read first boot info from Central Repository "); |
|
652 CRepository* repository(NULL); |
|
653 |
|
654 TRAPD( err, repository = CRepository::NewL( KCRUidStartup ) ); |
|
655 if ( err == KErrNone ) |
|
656 { |
|
657 err = repository->Get( KStartupFirstBoot, value ); |
|
658 } |
|
659 |
|
660 delete repository; |
|
661 |
|
662 if (value) |
|
663 { |
|
664 TRACES("CTouchScreenCalibAppUi::FirstBoot(): End, return EFalse"); |
|
665 return EFalse; |
|
666 } |
|
667 |
|
668 else |
|
669 { |
|
670 TRACES("CTouchScreenCalibAppUi::FirstBoot(): End, return ETrue"); |
|
671 return ETrue; |
|
672 } |
|
673 } |
|
674 |
|
675 |
|
676 /* |
|
677 * This funcntion is used to change the screen orientation to the |
|
678 * same orientation with the factory given calibration data. But it |
|
679 * is not used now. So just leave it here! |
|
680 * */ |
|
681 |
|
682 |
|
683 void CTouchScreenCalibAppUi::SetOrientation() |
|
684 { |
|
685 #ifndef __WINS__ |
|
686 |
|
687 TInt orientation = KUnknownOrientation; |
|
688 TInt nativeOrientation = KUnknownOrientation; |
|
689 TDigitizerCalibration Points; |
|
690 UserHal::CalibrationPoints( Points ); |
|
691 if ( Points.iBr.iX > Points.iBr.iY) |
|
692 { |
|
693 orientation = KLandscapeOrientation; |
|
694 } |
|
695 else |
|
696 { |
|
697 orientation = KPortraitOrientation; |
|
698 } |
|
699 TRect rect = iAvkonAppUi->ApplicationRect(); |
|
700 if ( rect.iBr.iX > rect.iBr.iY ) |
|
701 { |
|
702 nativeOrientation = KLandscapeOrientation; |
|
703 } |
|
704 else |
|
705 { |
|
706 nativeOrientation = KPortraitOrientation; |
|
707 } |
|
708 |
|
709 if (orientation != nativeOrientation ) |
|
710 { |
|
711 if ( orientation == KLandscapeOrientation ) |
|
712 { |
|
713 SetOrientationL( CAknAppUiBase::EAppUiOrientationLandscape ); |
|
714 } |
|
715 else |
|
716 { |
|
717 SetOrientationL( CAknAppUiBase::EAppUiOrientationPortrait ); |
|
718 } |
|
719 } |
|
720 #endif |
|
721 } |
|
722 // End of file |
|