|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : HWRMTestAppAppUi.cpp 00004 * Part of : HWRMTestApp 00005 * Interface : 00006 * Description : HWRM Test application UI implementation 00007 * Version : 00008 * 00009 * Copyright (c) 2002-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <aknNoteWrappers.h> 00018 #include <eikmenup.h> 00019 #include <avkon.hrh> 00020 #include <aknselectionlist.h> 00021 #include <HWRMPowerStateSDKPSKeys.h> 00022 #include <HWRMTestApp.rsg> 00023 #include "HWRMTestAppPropertyObserver.h" 00024 #include "HWRMTestAppAppUi.h" 00025 #include "HWRMTestAppContainer.h" 00026 #include "HWRMTestApp.hrh" 00027 00028 00029 // ============================ MEMBER FUNCTIONS =============================== 00030 00031 00032 // ----------------------------------------------------------------------------- 00033 // CHWRMTestAppAppUi::ConstructL 00034 // Symbian 2nd phase constructor can leave. 00035 // ----------------------------------------------------------------------------- 00036 // 00037 void CHWRMTestAppAppUi::ConstructL() 00038 { 00039 BaseConstructL(CAknAppUi::EAknEnableSkin); 00040 iAppContainer = new (ELeave) CHWRMTestAppContainer; 00041 iAppContainer->SetMopParent(this); 00042 iAppContainer->ConstructL( ClientRect() ); 00043 AddToStackL( iAppContainer ); 00044 00045 // We can ignore this error, simply dim the menus if 00046 // pointer is null with the DynInitMenuPaneL method 00047 TRAPD( err, iLight = CHWRMLight::NewL(this) ); 00048 if( err == KErrNotSupported ) 00049 { 00050 _LIT( KLightNotSupported, "Light API Not Supported!" ); 00051 iAppContainer->AddMessageL( KLightNotSupported ); 00052 } 00053 TRAP( err, iVibra = CHWRMVibra::NewL(this) ); 00054 if( err == KErrNotSupported ) 00055 { 00056 _LIT( KVibraNotSupported, "Vibra API Not Supported!" ); 00057 iAppContainer->AddMessageL( KVibraNotSupported ); 00058 } 00059 00060 // Create the observers 00061 iBatteryStatusObserver = CHWRMTestAppPropertyObserver::NewL( 00062 KPSUidHWRMPowerState,KHWRMBatteryStatus, iAppContainer ); 00063 iBatteryLevelObserver = CHWRMTestAppPropertyObserver::NewL( 00064 KPSUidHWRMPowerState,KHWRMBatteryLevel, iAppContainer ); 00065 iChargingStatusObserver = CHWRMTestAppPropertyObserver::NewL( 00066 KPSUidHWRMPowerState,KHWRMChargingStatus, iAppContainer ); 00067 } 00068 00069 // ----------------------------------------------------------------------------- 00070 // CHWRMTestAppAppUi::~CHWRMTestAppAppUi 00071 // Destructor 00072 // Frees reserved resources 00073 // ----------------------------------------------------------------------------- 00074 // 00075 CHWRMTestAppAppUi::~CHWRMTestAppAppUi() 00076 { 00077 // Delete the observers 00078 delete iBatteryStatusObserver; 00079 delete iBatteryLevelObserver; 00080 delete iChargingStatusObserver; 00081 00082 delete iLight; // kill light 00083 delete iVibra; // kill vibra 00084 00085 if(iAppContainer) 00086 { 00087 RemoveFromStack( iAppContainer ); 00088 delete iAppContainer; 00089 } 00090 } 00091 00092 // ----------------------------------------------------------------------------- 00093 // CHWRMTestAppAppUi::::DynInitMenuPaneL 00094 // This function is called by the EIKON framework just before it displays 00095 // a menu pane. Its default implementation is empty, and by overriding it, 00096 // the application can set the state of menu items dynamically according 00097 // to the state of application data. 00098 // ----------------------------------------------------------------------------- 00099 // 00100 void CHWRMTestAppAppUi::DynInitMenuPaneL( 00101 TInt aResourceId,CEikMenuPane* aMenuPane) 00102 { 00103 if( aResourceId==R_HWRMTESTAPP_MENU ) 00104 { 00105 //the main application menu 00106 if( iLight ) 00107 { 00108 //enable everything for lights 00109 aMenuPane->SetItemDimmed(EHWRMTestAppCmdLights,EFalse); 00110 } 00111 else 00112 { 00113 //dim everything for lights 00114 aMenuPane->SetItemDimmed(EHWRMTestAppCmdLights,ETrue); 00115 } 00116 if( iVibra ) 00117 { 00118 //enable everything for vibra 00119 aMenuPane->SetItemDimmed(EHWRMTestAppCmdVibra,EFalse); 00120 } 00121 else 00122 { 00123 //dim everything for vibra 00124 aMenuPane->SetItemDimmed(EHWRMTestAppCmdVibra,ETrue); 00125 } 00126 } 00127 } 00128 00129 // ----------------------------------------------------------------------------- 00130 // CHWRMTestAppAppUi::HandleKeyEventL 00131 // Pass key event to app container 00132 // ----------------------------------------------------------------------------- 00133 // 00134 TKeyResponse CHWRMTestAppAppUi::HandleKeyEventL( 00135 const TKeyEvent& aKeyEvent,TEventCode aType) 00136 { 00137 return iAppContainer->OfferKeyEventL( aKeyEvent, aType ); 00138 } 00139 00140 // ----------------------------------------------------------------------------- 00141 // CHWRMTestAppAppUi::HandleCommandL 00142 // Handle command entered by user 00143 // ----------------------------------------------------------------------------- 00144 // 00145 void CHWRMTestAppAppUi::HandleCommandL(TInt aCommand) 00146 { 00147 TInt err(KErrNone); 00148 00149 switch ( aCommand ) 00150 { 00151 case EAknSoftkeyBack: 00152 case EEikCmdExit: 00153 { 00154 Exit(); 00155 break; 00156 } 00157 case EHWRMTestAppCmdVibraReserve: 00158 { 00159 _LIT(KReserveVibra, "Reserve vibra"); 00160 iAppContainer->AddMessageL( KReserveVibra ); 00161 TRAP( err, VibraReserveL() ); 00162 break; 00163 } 00164 case EHWRMTestAppCmdVibraRelease: 00165 { 00166 _LIT(KReleaseVibra, "Release vibra"); 00167 iAppContainer->AddMessageL( KReleaseVibra ); 00168 TRAP( err, VibraReleaseL() ); 00169 break; 00170 } 00171 case EHWRMTestAppCmdVibraStart: 00172 { 00173 _LIT(KStartVibra, "Start vibra"); 00174 iAppContainer->AddMessageL( KStartVibra ); 00175 TRAP( err, VibraStartL() ); 00176 break; 00177 } 00178 case EHWRMTestAppCmdVibraStop: 00179 { 00180 _LIT(KStopVibra, "Stop vibra"); 00181 iAppContainer->AddMessageL( KStopVibra ); 00182 TRAP( err, VibraStopL() ); 00183 break; 00184 } 00185 case EHWRMTestAppCmdVibraSettings: 00186 { 00187 _LIT(KVibraSettings, "Vibra settings"); 00188 iAppContainer->AddMessageL( KVibraSettings ); 00189 VibraSettings(); 00190 break; 00191 } 00192 case EHWRMTestAppCmdVibraStatus: 00193 { 00194 _LIT(KVibraStatus, "Vibra status"); 00195 iAppContainer->AddMessageL( KVibraStatus ); 00196 VibraStatus(); 00197 break; 00198 } 00199 case EHWRMTestAppCmdLightsReserve: 00200 { 00201 _LIT(KReserveLights, "Reserve lights"); 00202 iAppContainer->AddMessageL( KReserveLights ); 00203 TRAP( err, LightsReserveL() ); 00204 break; 00205 } 00206 case EHWRMTestAppCmdLightsRelease: 00207 { 00208 _LIT(KReleaseLights, "Release lights"); 00209 iAppContainer->AddMessageL( KReleaseLights ); 00210 TRAP( err, LightsReleaseL() ); 00211 break; 00212 } 00213 case EHWRMTestAppCmdLightsOn: 00214 { 00215 _LIT(KLightsOn, "Lights on"); 00216 iAppContainer->AddMessageL( KLightsOn ); 00217 TRAP( err, LightsOnL() ); 00218 break; 00219 } 00220 case EHWRMTestAppCmdLightsBlink: 00221 { 00222 _LIT(KBlinkLights, "Blink lights"); 00223 iAppContainer->AddMessageL( KBlinkLights ); 00224 TRAP( err, LightsBlinkL() ); 00225 break; 00226 } 00227 case EHWRMTestAppCmdLightsOff: 00228 { 00229 _LIT(KLightsOff, "Lights off"); 00230 iAppContainer->AddMessageL( KLightsOff ); 00231 TRAP( err, LightsOffL() ); 00232 break; 00233 } 00234 case EHWRMTestAppCmdLightsStatus: 00235 { 00236 _LIT(KLightsStatus, "Lights status"); 00237 iAppContainer->AddMessageL( KLightsStatus ); 00238 TRAP( err, LightsStatusL() ); 00239 break; 00240 } 00241 default: 00242 break; 00243 } 00244 if( err != KErrNone ) 00245 { 00246 TBuf<100> buf; 00247 _LIT(KErrorTrapped, "Error Trapped = %d!!!"); 00248 buf.Format( KErrorTrapped, err ); 00249 iAppContainer->AddMessageL( buf ); 00250 } 00251 } 00252 00253 // ----------------------------------------------------------------------------- 00254 // CHWRMTestAppAppUi::HandleForegroundEventL 00255 // Handle situation when app is sent to the foreground or background 00256 // ----------------------------------------------------------------------------- 00257 // 00258 void CHWRMTestAppAppUi::HandleForegroundEventL(TBool aForeground) 00259 { 00260 // first call base implementation 00261 CEikAppUi::HandleForegroundEventL( aForeground ); 00262 00263 if( aForeground ) 00264 { 00265 _LIT(KAppSentToForeground, "App sent to foreground"); 00266 iAppContainer->AddMessageL( KAppSentToForeground ); 00267 } 00268 else 00269 { 00270 _LIT(KAppSentToBackground, "App sent to background"); 00271 iAppContainer->AddMessageL( KAppSentToBackground ); 00272 } 00273 } 00274 00275 00276 // ============================================================================= 00277 // VIBRA RELATED METHODS 00278 // ============================================================================= 00279 00280 // ----------------------------------------------------------------------------- 00281 // CHWRMTestAppAppUi::VibraReserveL 00282 // Reserve vibra 00283 // ----------------------------------------------------------------------------- 00284 // 00285 void CHWRMTestAppAppUi::VibraReserveL() 00286 { 00287 TInt item(0); 00288 TBuf<100> buf; 00289 TBool restore; 00290 TBool forceNoCCoeEnv; 00291 00292 CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item ); 00293 if( listDlg->ExecuteLD(R_HWRMTESTAPP_RESTORE_LIST) ) 00294 { 00295 // got restore state parameter 00296 item == 0 ? restore = EFalse : restore = ETrue; 00297 //now get force no CCoeEnv parameter 00298 listDlg = new (ELeave)CAknListQueryDialog( &item ); 00299 if( listDlg->ExecuteLD(R_HWRMTESTAPP_NOCCOEENV_LIST) ) 00300 { 00301 // got ForceNoCCoeEnv parameter 00302 item == 0 ? forceNoCCoeEnv = EFalse : forceNoCCoeEnv = ETrue; 00303 _LIT(KReserveVibraLParameters, "ReserveVibraL(restore=%d,forceNoCCoeEnv=%d)"); 00304 buf.Format( KReserveVibraLParameters, restore, forceNoCCoeEnv ); 00305 iAppContainer->AddMessageL( buf ); 00306 iVibra->ReserveVibraL( restore, forceNoCCoeEnv ); 00307 } 00308 else 00309 { 00310 // did not get ForceNoCCoeEnv parameter 00311 _LIT(KReserveVibraLNotCalled, "ReserveVibraL not called, no ForceNoCCoeEnv value"); 00312 iAppContainer->AddMessageL( KReserveVibraLNotCalled ); 00313 } 00314 } 00315 else 00316 { 00317 // did not get restore parameter 00318 _LIT(KReserveVibraL, "ReserveVibraL()"); 00319 iAppContainer->AddMessageL( KReserveVibraL ); 00320 iVibra->ReserveVibraL(); 00321 } 00322 } 00323 00324 // ----------------------------------------------------------------------------- 00325 // CHWRMTestAppAppUi::VibraReleaseL 00326 // Release vibra 00327 // ----------------------------------------------------------------------------- 00328 // 00329 void CHWRMTestAppAppUi::VibraReleaseL() 00330 { 00331 _LIT(KReleaseVibraCalled, "ReleaseVibra called"); 00332 iAppContainer->AddMessageL( KReleaseVibraCalled ); 00333 iVibra->ReleaseVibra(); 00334 } 00335 00336 // ----------------------------------------------------------------------------- 00337 // CHWRMTestAppAppUi::VibraStartL 00338 // Start vibra 00339 // ----------------------------------------------------------------------------- 00340 // 00341 void CHWRMTestAppAppUi::VibraStartL() 00342 { 00343 CAknNumberQueryDialog* dlg; 00344 TInt intensity(0); 00345 TInt duration(0); 00346 TBuf<100> buf; 00347 00348 //duration 00349 dlg = CAknNumberQueryDialog::NewL( duration ); 00350 00351 //KHWRMVibraMinIntensity, KHWRMVibraMaxIntensity, 5 ; 00352 if( dlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) ) 00353 { 00354 // got duration so now optionally get the intensity 00355 dlg = CAknNumberQueryDialog::NewL( intensity ); 00356 //KHWRMVibraMinIntensity, KHWRMVibraMaxIntensity, 5 ; 00357 if( dlg->ExecuteLD( R_HWRMTESTAPP_VIBRA_INTENSITY_QUERY ) ) 00358 { 00359 // got the intenstity 00360 _LIT(KStartVibraL, "StartVibraL(duration=%d,intensity=%d)"); 00361 buf.Format( KStartVibraL, duration, intensity ); 00362 iAppContainer->AddMessageL( buf ); 00363 iVibra->StartVibraL( duration, intensity ); 00364 } 00365 else 00366 { 00367 // user pressed cancel for intensity query 00368 _LIT(KStartVibraLDuration, "StartVibraL(duration=%d)"); 00369 buf.Format( KStartVibraLDuration, duration ); 00370 iAppContainer->AddMessageL( buf ); 00371 iVibra->StartVibraL( duration ); 00372 } 00373 } 00374 else 00375 { 00376 // user pressed cancel for duration query 00377 // do nothing... 00378 _LIT(KStartVibraLNotCalled, "StartVibraL not called!"); 00379 iAppContainer->AddMessageL( KStartVibraLNotCalled ); 00380 } 00381 } 00382 00383 // ----------------------------------------------------------------------------- 00384 // CHWRMTestAppAppUi::VibraStopL 00385 // Stop vibra 00386 // ----------------------------------------------------------------------------- 00387 // 00388 void CHWRMTestAppAppUi::VibraStopL() 00389 { 00390 _LIT(KStopVibraLCalled, "StopVibraL called"); 00391 iAppContainer->AddMessageL( KStopVibraLCalled ); 00392 iVibra->StopVibraL(); 00393 } 00394 00395 // ----------------------------------------------------------------------------- 00396 // CHWRMTestAppAppUi::VibraSettings 00397 // Retrieve vibra settings 00398 // ----------------------------------------------------------------------------- 00399 // 00400 void CHWRMTestAppAppUi::VibraSettings() 00401 { 00402 VibraModeChanged( iVibra->VibraSettings() ); 00403 } 00404 00405 // ----------------------------------------------------------------------------- 00406 // CHWRMTestAppAppUi::VibraStatus 00407 // Retrieve vibra status 00408 // ----------------------------------------------------------------------------- 00409 // 00410 void CHWRMTestAppAppUi::VibraStatus() 00411 { 00412 VibraStatusChanged( iVibra->VibraStatus() ); 00413 } 00414 00415 00416 // ============================================================================= 00417 // LIGHTS RELATED METHODS 00418 // ============================================================================= 00419 00420 // ----------------------------------------------------------------------------- 00421 // CHWRMTestAppAppUi::LightsReserveL 00422 // Reserve lights 00423 // ----------------------------------------------------------------------------- 00424 // 00425 void CHWRMTestAppAppUi::LightsReserveL() 00426 { 00427 TInt item(0); 00428 TBuf<100> buf; 00429 TBool restore; 00430 TBool forceNoCCoeEnv; 00431 TInt target(CHWRMLight::ENoTarget); 00432 00433 // Get the lights target 00434 target = GetLightsTargetL(); 00435 00436 if( target == KErrCancel ) 00437 { 00438 // no target entered 00439 _LIT(KReserveLightLNotCalled, "ReserveLightL not called, no target!"); 00440 iAppContainer->AddMessageL( KReserveLightLNotCalled ); 00441 return; 00442 } 00443 00444 CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item ); 00445 00446 if( listDlg->ExecuteLD(R_HWRMTESTAPP_RESTORE_LIST) ) 00447 { 00448 // got restore state parameter 00449 item == 0 ? restore = EFalse : restore = ETrue; 00450 //now get force no CCoeEnv parameter 00451 listDlg = new (ELeave)CAknListQueryDialog( &item ); 00452 if( listDlg->ExecuteLD(R_HWRMTESTAPP_NOCCOEENV_LIST) ) 00453 { 00454 // got ForceNoCCoeEnv parameter 00455 item == 0 ? forceNoCCoeEnv = EFalse : forceNoCCoeEnv = ETrue; 00456 _LIT(KReserveLightL, "ReserveLightL(target=%d,restore=%d,forceNoCCoeEnv=%d)"); 00457 buf.Format( KReserveLightL, target, restore, forceNoCCoeEnv ); 00458 iAppContainer->AddMessageL( buf ); 00459 iLight->ReserveLightL( target, restore, forceNoCCoeEnv ); 00460 } 00461 else 00462 { 00463 // did not get ForceNoCCoeEnv parameter 00464 _LIT(KReserveLightLNotCalled, "ReserveLightL not called, no ForceNoCCoeEnv value"); 00465 iAppContainer->AddMessageL( KReserveLightLNotCalled ); 00466 } 00467 } 00468 else 00469 { 00470 // did not get restore parameter 00471 _LIT(KReserveLightLTarget, "ReserveLightL(target=%d)"); 00472 buf.Format( KReserveLightLTarget, target ); 00473 iAppContainer->AddMessageL( buf ); 00474 iLight->ReserveLightL( target ); 00475 } 00476 00477 } 00478 00479 // ----------------------------------------------------------------------------- 00480 // CHWRMTestAppAppUi::LightsReleaseL 00481 // Release lights 00482 // ----------------------------------------------------------------------------- 00483 // 00484 void CHWRMTestAppAppUi::LightsReleaseL() 00485 { 00486 TBuf<100> buf; 00487 TInt target(CHWRMLight::ENoTarget); 00488 00489 // Get the lights target 00490 target = GetLightsTargetL(); 00491 00492 if( target == KErrCancel ) 00493 { 00494 // no target entered 00495 _LIT(KReleaseLightNotCalled, "ReleaseLight not called, no target!"); 00496 iAppContainer->AddMessageL( KReleaseLightNotCalled ); 00497 } 00498 else 00499 { 00500 _LIT(KReleaseLight, "ReleaseLight(target=%d)"); 00501 buf.Format( KReleaseLight, target ); 00502 iAppContainer->AddMessageL( buf ); 00503 iLight->ReleaseLight( target ); 00504 } 00505 } 00506 00507 // ----------------------------------------------------------------------------- 00508 // CHWRMTestAppAppUi::LightsOnL 00509 // Turn lights on 00510 // ----------------------------------------------------------------------------- 00511 // 00512 void CHWRMTestAppAppUi::LightsOnL() 00513 { 00514 TInt item(0); 00515 TInt duration(0); 00516 TInt intensity(0); 00517 TInt target(CHWRMLight::ENoTarget); 00518 TBool fade(EFalse); 00519 TBuf<100> buf; 00520 00521 // Get the lights target 00522 target = GetLightsTargetL(); 00523 00524 if( target == KErrCancel ) 00525 { 00526 // no target entered 00527 _LIT(KLightOnLNotCalled, "LightOnL not called, no target!"); 00528 iAppContainer->AddMessageL( KLightOnLNotCalled ); 00529 return; 00530 } 00531 00532 //duration 00533 CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration ); 00534 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) ) 00535 { 00536 // got duration so get intensity 00537 queryDlg = CAknNumberQueryDialog::NewL( intensity ); 00538 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_LIGHT_INTENSITY_QUERY ) ) 00539 { 00540 // got the intenstity 00541 CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item ); 00542 if( listDlg->ExecuteLD(R_HWRMTESTAPP_FADE_LIST) ) 00543 { 00544 // got fade parameter 00545 item == 0 ? fade = EFalse : fade = ETrue; 00546 _LIT(KLightOnLParameters, "LightOnL(target=%d,duration=%d,intensity=%d,fade=%d)"); 00547 buf.Format( KLightOnLParameters, target, duration, intensity, fade ); 00548 iAppContainer->AddMessageL( buf ); 00549 iLight->LightOnL( target, duration, intensity, fade ); 00550 } 00551 else 00552 { 00553 // did not get fade parameter 00554 _LIT(KLightOnL, "LightOnL not called, no fade value!"); 00555 iAppContainer->AddMessageL( KLightOnL ); 00556 } 00557 } 00558 else 00559 { 00560 // user pressed cancel for intensity query 00561 _LIT(KLightOnLTargetDuration, "LightOnL(target=%d,duration=%d)"); 00562 buf.Format( KLightOnLTargetDuration, target, duration ); 00563 iAppContainer->AddMessageL( buf ); 00564 iLight->LightOnL( target, duration ); 00565 } 00566 } 00567 else 00568 { 00569 // didn't get duration so call basic API 00570 _LIT(KLightOnLTarget, "LightOnL(target=%d)"); 00571 buf.Format( KLightOnLTarget, target ); 00572 iAppContainer->AddMessageL( buf ); 00573 } 00574 } 00575 00576 // ----------------------------------------------------------------------------- 00577 // CHWRMTestAppAppUi::LightsBlinkL 00578 // Blink lights 00579 // ----------------------------------------------------------------------------- 00580 // 00581 void CHWRMTestAppAppUi::LightsBlinkL() 00582 { 00583 TInt duration(0); 00584 TInt onDuration(0); 00585 TInt offDuration(0); 00586 TInt intensity(0); 00587 TBuf<100> buf; 00588 00589 // Get the lights target 00590 TInt target = GetLightsTargetL(); 00591 if( target == KErrCancel ) 00592 { 00593 // no target entered 00594 _LIT(KLightsBlinkNotCalled, "LightsBlink not called, no target!"); 00595 iAppContainer->AddMessageL( KLightsBlinkNotCalled ); 00596 return; 00597 } 00598 00599 // get duration 00600 CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration ); 00601 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) ) 00602 { 00603 // got duration so get OnDuration 00604 queryDlg = CAknNumberQueryDialog::NewL( onDuration ); 00605 CleanupStack::PushL( queryDlg ); 00606 00607 _LIT(KEnterONDuration, "Enter ON duration (0 to 2147482)"); 00608 queryDlg->SetPromptL( KEnterONDuration ); 00609 00610 CleanupStack::Pop( queryDlg ); 00611 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) ) 00612 { 00613 // got OnDuration so get OffDuration 00614 queryDlg = CAknNumberQueryDialog::NewL( offDuration ); 00615 CleanupStack::PushL( queryDlg ); 00616 00617 _LIT(KEnterOFFDuration, "Enter OFF duration (0 to 2147482)"); 00618 queryDlg->SetPromptL( KEnterOFFDuration ); 00619 00620 CleanupStack::Pop( queryDlg ); 00621 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) ) 00622 { 00623 // got OffDuration so get intensity 00624 queryDlg = CAknNumberQueryDialog::NewL( intensity ); 00625 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_LIGHT_INTENSITY_QUERY ) ) 00626 { 00627 // got the intenstity 00628 _LIT(KLightBlinkLParameters, "LightBlinkL(target=%d,duration=%d,onDuration=%d,offDuration=%d,intensity=%d)"); 00629 buf.Format( KLightBlinkLParameters,target, duration, onDuration, offDuration, intensity ); 00630 iAppContainer->AddMessageL( buf ); 00631 iLight->LightBlinkL( target, duration, onDuration, 00632 offDuration, intensity ); 00633 } 00634 else 00635 { 00636 // user pressed cancel for intensity 00637 _LIT(KLightBlinkLNoIntensity, "LightBlinkL not called, no intensity value!"); 00638 iAppContainer->AddMessageL( KLightBlinkLNoIntensity ); 00639 } 00640 00641 } 00642 else 00643 { 00644 // user pressed cancel for OffDuration 00645 _LIT(KLightBlinkLNoOffDuration, "LightBlinkL not called, no offDuration value!"); 00646 iAppContainer->AddMessageL( KLightBlinkLNoOffDuration ); 00647 } 00648 } 00649 else 00650 { 00651 // user pressed cancel for OnDuration 00652 _LIT(KLightBlinkLTargetDuration, "LightBlinkL(target=%d,duration=%d)"); 00653 buf.Format( KLightBlinkLTargetDuration, target, duration ); 00654 iAppContainer->AddMessageL( buf ); 00655 } 00656 } 00657 else 00658 { 00659 // user pressed cancel for Duration 00660 _LIT(KLightBlinkLTarget, "LightBlinkL(target=%d)"); 00661 buf.Format( KLightBlinkLTarget, target ); 00662 iAppContainer->AddMessageL( buf ); 00663 } 00664 } 00665 00666 // ----------------------------------------------------------------------------- 00667 // CHWRMTestAppAppUi::LightsOffL 00668 // Turn lights off 00669 // ----------------------------------------------------------------------------- 00670 // 00671 void CHWRMTestAppAppUi::LightsOffL() 00672 { 00673 TInt item(0); 00674 TInt duration(0); 00675 TInt target(CHWRMLight::ENoTarget); 00676 TBool fade(EFalse); 00677 TBuf<100> buf; 00678 00679 // Get the lights target 00680 target = GetLightsTargetL(); 00681 00682 if( target == KErrCancel ) 00683 { 00684 // no target entered 00685 _LIT(KLightsOffLNoTarget, "LightsOffL not called, no target!"); 00686 iAppContainer->AddMessageL( KLightsOffLNoTarget ); 00687 return; 00688 } 00689 00690 //duration 00691 CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration ); 00692 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) ) 00693 { 00694 // got duration so get fade 00695 CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item ); 00696 if( listDlg->ExecuteLD(R_HWRMTESTAPP_FADE_LIST) ) 00697 { 00698 // got fade parameter 00699 item == 0 ? fade = EFalse : fade = ETrue; 00700 _LIT(KLightOffLParameters, "LightOffL(target=%d,duration=%d,fade=%d)"); 00701 buf.Format( KLightOffLParameters, target, duration, fade ); 00702 iAppContainer->AddMessageL( buf ); 00703 iLight->LightOffL( target, duration, fade ); 00704 } 00705 else 00706 { 00707 // did not get fade parameter 00708 _LIT(KLightOffLTargetDuration, "LightOffL(target=%d,duration=%d)"); 00709 buf.Format( KLightOffLTargetDuration, target, duration ); 00710 iAppContainer->AddMessageL( buf ); 00711 iLight->LightOffL( target, duration ); 00712 } 00713 } 00714 else 00715 { 00716 // didn't get duration so call basic API 00717 _LIT(KLightOffLTarget, "LightOffL(target=%d)"); 00718 buf.Format( KLightOffLTarget, target ); 00719 iAppContainer->AddMessageL( buf ); 00720 } 00721 } 00722 00723 // ----------------------------------------------------------------------------- 00724 // CHWRMTestAppAppUi::LightsStatusL 00725 // Retrieve lights status 00726 // ----------------------------------------------------------------------------- 00727 // 00728 void CHWRMTestAppAppUi::LightsStatusL() 00729 { 00730 TInt target(CHWRMLight::ENoTarget); 00731 TBuf<100> buf; 00732 00733 // Get the lights target 00734 target = GetLightsTargetL(); 00735 00736 if( target == KErrCancel ) 00737 { 00738 // no target entered 00739 _LIT(KLightStatusNoTarget, "LightStatus not called, no target!"); 00740 iAppContainer->AddMessageL( KLightStatusNoTarget ); 00741 } 00742 else 00743 { 00744 _LIT(KLightStatusTarget, "LightStatus(target=%d)"); 00745 buf.Format( KLightStatusTarget, target ); 00746 iAppContainer->AddMessageL( buf ); 00747 LightStatusChanged( target, iLight->LightStatus( target ) ); 00748 } 00749 } 00750 00751 // ----------------------------------------------------------------------------- 00752 // CHWRMTestAppAppUi::GetLightsTargetL 00753 // Retrieve lights target 00754 // ----------------------------------------------------------------------------- 00755 // 00756 TInt CHWRMTestAppAppUi::GetLightsTargetL() 00757 { 00758 TInt item(0); 00759 TInt ret(KErrCancel); 00760 00761 CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item ); 00762 if( listDlg->ExecuteLD(R_HWRMTESTAPP_LIGHTSTARGET_LIST) ) 00763 { 00764 // This is a lookup table for the items defined in the 00765 // resource array r_hwrmtestapp_lightstarget_items 00766 switch ( item ) 00767 { 00768 case 0: // ENoTarget 00769 { 00770 ret = CHWRMLight::ENoTarget; 00771 break; 00772 } 00773 case 1: // EPrimaryDisplay 00774 { 00775 ret = CHWRMLight::EPrimaryDisplay; 00776 break; 00777 } 00778 case 2: // EPrimaryKeyboard 00779 { 00780 ret = CHWRMLight::EPrimaryKeyboard; 00781 break; 00782 } 00783 case 3: // EPrimaryDisplayAndKeyboard 00784 { 00785 ret = CHWRMLight::EPrimaryDisplayAndKeyboard; 00786 break; 00787 } 00788 case 4: // ESecondaryDisplay 00789 { 00790 ret = CHWRMLight::ESecondaryDisplay; 00791 break; 00792 } 00793 case 5: // ESecondaryKeyboard 00794 { 00795 ret = CHWRMLight::ESecondaryKeyboard; 00796 break; 00797 } 00798 case 6: // ESecondaryDisplayAndKeyboard 00799 { 00800 ret = CHWRMLight::ESecondaryDisplayAndKeyboard; 00801 break; 00802 } 00803 default: 00804 break; 00805 } 00806 } 00807 else 00808 { 00809 // no target entered 00810 ret = KErrCancel; 00811 } 00812 00813 return ret; 00814 } 00815 00816 00817 // ============================================================================= 00818 // MHWRMVibraObserver METHODS 00819 // ============================================================================= 00820 00821 // ----------------------------------------------------------------------------- 00822 // CHWRMTestAppAppUi::VibraModeChanged 00823 // Callback for when vibra mode is changed 00824 // ----------------------------------------------------------------------------- 00825 // 00826 void CHWRMTestAppAppUi::VibraModeChanged(CHWRMVibra::TVibraModeState aStatus) 00827 { 00828 _LIT(KVibraModeStateChanged, "Vibra mode state changed:"); 00829 TRAP_IGNORE( 00830 iAppContainer->AddMessageL( KVibraModeStateChanged ); 00831 switch ( aStatus ) 00832 { 00833 case CHWRMVibra::EVibraModeUnknown: 00834 { 00835 _LIT(KEVibraModeUnknown, " EVibraModeUnknown"); 00836 iAppContainer->AddMessageL( KEVibraModeUnknown ); 00837 break; 00838 } 00839 case CHWRMVibra::EVibraModeON: 00840 { 00841 _LIT(KEVibraModeOn, " EVibraModeON"); 00842 iAppContainer->AddMessageL( KEVibraModeOn ); 00843 break; 00844 } 00845 case CHWRMVibra::EVibraModeOFF: 00846 { 00847 _LIT(KEVibraModeOff, " EVibraModeOFF"); 00848 iAppContainer->AddMessageL( KEVibraModeOff ); 00849 break; 00850 } 00851 default: 00852 { 00853 _LIT(KVibraModeUndefined, " UNDEFINED !!!"); 00854 iAppContainer->AddMessageL( KVibraModeUndefined ); 00855 break; 00856 } 00857 } 00858 ); // TRAP_IGNORE 00859 } 00860 00861 // ----------------------------------------------------------------------------- 00862 // CHWRMTestAppAppUi::VibraStatusChanged 00863 // Callback for when vibra status is changed 00864 // ----------------------------------------------------------------------------- 00865 // 00866 void CHWRMTestAppAppUi::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus) 00867 { 00868 _LIT(KVibraStateChanged, "Vibra state changed:"); 00869 TRAP_IGNORE( 00870 iAppContainer->AddMessageL( KVibraStateChanged ); 00871 switch ( aStatus ) 00872 { 00873 case CHWRMVibra::EVibraStatusUnknown: 00874 { 00875 _LIT(KEVibraStatusUnknown, " EVibraStatusUnknown"); 00876 iAppContainer->AddMessageL( KEVibraStatusUnknown ); 00877 break; 00878 } 00879 case CHWRMVibra::EVibraStatusNotAllowed: 00880 { 00881 _LIT(KEVibraStatusNotAllowed, " EVibraStatusNotAllowed"); 00882 iAppContainer->AddMessageL( KEVibraStatusNotAllowed ); 00883 break; 00884 } 00885 case CHWRMVibra::EVibraStatusStopped: 00886 { 00887 _LIT(KEVibraStatusStopped, " EVibraStatusStopped"); 00888 iAppContainer->AddMessageL( KEVibraStatusStopped ); 00889 break; 00890 } 00891 case CHWRMVibra::EVibraStatusOn: 00892 { 00893 _LIT(KEVibraStatusOn, " EVibraStatusOn"); 00894 iAppContainer->AddMessageL( KEVibraStatusOn ); 00895 break; 00896 } 00897 default: 00898 { 00899 _LIT(KVibraStatusUndefined, " UNDEFINED !!!"); 00900 iAppContainer->AddMessageL( KVibraStatusUndefined ); 00901 break; 00902 } 00903 } 00904 ); // TRAP_IGNORE 00905 } 00906 00907 00908 // ============================================================================= 00909 // MHWRMLightObserver METHODS 00910 // ============================================================================= 00911 00912 // ----------------------------------------------------------------------------- 00913 // CHWRMTestAppAppUi::LightStatusChanged 00914 // Callback for when lights status is changed 00915 // ----------------------------------------------------------------------------- 00916 // 00917 void CHWRMTestAppAppUi::LightStatusChanged(TInt aTarget, 00918 CHWRMLight::TLightStatus aStatus) 00919 { 00920 TRAP_IGNORE( 00921 TBuf<100> buf; 00922 _LIT(KLightStateChangedForTarget, "Light state changed for target:"); 00923 iAppContainer->AddMessageL( KLightStateChangedForTarget ); 00924 _LIT( KHexTarget, " 0x%x"); 00925 buf.Format(KHexTarget, aTarget); 00926 iAppContainer->AddMessageL( buf ); 00927 00928 switch ( aStatus ) 00929 { 00930 case CHWRMLight::ELightOn: 00931 { 00932 _LIT(KLightChangedOn, "Light state changed: ELightOn"); 00933 iAppContainer->AddMessageL( KLightChangedOn ); 00934 break; 00935 } 00936 case CHWRMLight::ELightOff: 00937 { 00938 _LIT(KLightChangedOff, "Light state changed: ELightOff"); 00939 iAppContainer->AddMessageL( KLightChangedOff ); 00940 break; 00941 } 00942 case CHWRMLight::ELightBlink: 00943 { 00944 _LIT(KLightChangedBlink, "Light state changed: ELightBlink"); 00945 iAppContainer->AddMessageL( KLightChangedBlink ); 00946 break; 00947 } 00948 case CHWRMLight::ELightStatusUnknown: 00949 { 00950 _LIT(KLightChangedUnknown, "Light state changed: ELightStatusUnknown"); 00951 iAppContainer->AddMessageL( KLightChangedUnknown ); 00952 break; 00953 } 00954 default: 00955 { 00956 _LIT(KLightChangedUndefined, "Light state changed: UNDEFINED !!!"); 00957 iAppContainer->AddMessageL( KLightChangedUndefined ); 00958 break; 00959 } 00960 } 00961 ); // TRAP_IGNORE 00962 } 00963 00964 00965 // End of File 00966
|
© Nokia 2006 |