|
Nokia N97 SDK Example Applications Guide |
#include <sensorexampleappui.h>
Inheritance diagram for CSensorExampleAppUi:

Definition at line 35 of file sensorexampleappui.h.
Public Member Functions |
|
| void | ConstructL () |
| CSensorExampleAppUi () | |
| virtual | ~CSensorExampleAppUi () |
Private Member Functions |
|
| void | HandleCommandL (TInt aCommand) |
| void | HandleStatusPaneSizeChange () |
| void | OpenChannelL (CSensrvChannel *&aChannel, TSensrvChannelTypeId aChannelTypeId) |
| void | HandleQueryL (TInt aCommand) |
| void | ShowNoteL (const TDesC &aNoteText) |
| void | ShowPropertyNoteL (TSensrvProperty &aProperty) |
| void | ShowPropertyValueNoteL (TSensrvProperty &aProperty) |
| void | HandlePropertyValueQueryL (TSensrvProperty &aProperty, CSensrvChannel *aChannel) |
Private Attributes |
|
| CSensorExampleAppView * | iAppView |
| CSensrvChannel * | iDblTapChannel |
| CSensrvChannel * | iAccelerometerChannel |
| CSensrvChannel * | iOrientationChannel |
| CSensorExampleDataListener * | iDataListener |
|
|
CSensorExampleAppUi. C++ default constructor. This needs to be public due to the way the framework constructs the AppUi Definition at line 135 of file sensorexampleappui.cpp.
|
|
|
~CSensorExampleAppUi. Virtual Destructor. Definition at line 145 of file sensorexampleappui.cpp. References iAppView, iDataListener, and iDblTapChannel. 00146 { 00147 delete iDataListener; 00148 delete iAppView; 00149 00150 if( iDblTapChannel ) 00151 { 00152 iDblTapChannel->StopDataListening(); 00153 iDblTapChannel->CloseChannel(); 00154 delete iDblTapChannel; 00155 } 00156 00157 if( iAccelerometerChannel ) 00158 { 00159 iAccelerometerChannel->StopDataListening(); 00160 iAccelerometerChannel->CloseChannel(); 00161 delete iAccelerometerChannel; 00162 } 00163 00164 if( iOrientationChannel ) 00165 { 00166 iOrientationChannel->StopDataListening(); 00167 iOrientationChannel->CloseChannel(); 00168 delete iOrientationChannel; 00169 } 00170 00171 }
|
|
|
ConstructL. 2nd phase constructor. Definition at line 47 of file sensorexampleappui.cpp. References iAccelerometerChannel, iAppView, iDataListener, CSensorExampleDataListener::NewL(), CSensorExampleAppView::NewL(), and OpenChannelL(). 00048 { 00049 TBool showWarningNote( EFalse ); 00050 TBuf<KInfoNoteBufferSize> warningText; 00051 00052 // Initialise app UI with standard value. 00053 BaseConstructL( CAknAppUi::EAknEnableSkin ); 00054 00055 // Create view object 00056 iAppView = CSensorExampleAppView::NewL( ClientRect() ); 00057 00058 iDataListener = CSensorExampleDataListener::NewL( iAppView ); 00059 00060 warningText.Append( iCoeEnv->AllocReadResourceLC( R_SE_NOTFOUND )->Des() ); 00061 CleanupStack::PopAndDestroy();//R_SE_NOTFOUND 00062 00063 TRAPD( err , 00064 OpenChannelL( iAccelerometerChannel, 00065 KSensrvChannelTypeIdAccelerometerXYZAxisData ) ); 00066 if( KErrNone != err || !iAccelerometerChannel ) 00067 { 00068 warningText.Append( KNewLine ); 00069 warningText.Append( iCoeEnv->AllocReadResourceLC( R_SE_ACCELEROMETERCHANNEL )->Des() ); 00070 CleanupStack::PopAndDestroy();//R_SE_ACCELEROMETERCHANNEL 00071 showWarningNote = ETrue; 00072 } 00073 00074 TRAP( err , OpenChannelL( iDblTapChannel, 00075 KSensrvChannelTypeIdAccelerometerDoubleTappingData ) ); 00076 if( KErrNone != err || !iDblTapChannel ) 00077 { 00078 warningText.Append( KNewLine ); 00079 warningText.Append( iCoeEnv->AllocReadResourceLC( R_SE_DOUBLETAPCHANNEL )->Des() ); 00080 CleanupStack::PopAndDestroy();//R_SE_DOUBLETAPCHANNEL 00081 showWarningNote = ETrue; 00082 } 00083 00084 TRAP( err , OpenChannelL( iOrientationChannel, KSensrvChannelTypeIdOrientationData ) ); 00085 if( KErrNone != err || !iOrientationChannel ) 00086 { 00087 warningText.Append( KNewLine ); 00088 warningText.Append( iCoeEnv->AllocReadResourceLC( R_SE_ORIENTATIONCHANNEL )->Des() ); 00089 CleanupStack::PopAndDestroy();//R_SE_ORIENTATIONCHANNEL 00090 showWarningNote = ETrue; 00091 } 00092 00093 //In case of some channel opening fails, show error note 00094 if( showWarningNote ) 00095 { 00096 CAknWarningNote* note = new ( ELeave ) CAknWarningNote( ETrue ); 00097 note->ExecuteLD( warningText ); 00098 } 00099 }
|
|
|
From CEikAppUi, HandleCommandL. Takes care of command handling.
Definition at line 178 of file sensorexampleappui.cpp. 00179 { 00180 00181 switch( aCommand ) 00182 { 00183 case EEikCmdExit: 00184 case EAknSoftkeyExit: 00185 { 00186 Exit(); 00187 } 00188 break; 00189 00190 case ESensorProperties: 00191 case EGetValue: 00192 case ESetValue: 00193 { 00194 HandleQueryL( aCommand ); 00195 } 00196 break; 00197 00198 default: 00199 Panic( ESensorExampleUi ); 00200 break; 00201 } 00202 }
|
|
|
HandleStatusPaneSizeChange. Called by the framework when the application status pane size is changed. Definition at line 574 of file sensorexampleappui.cpp. References iAppView. 00575 { 00576 iAppView->SetRect( ClientRect() ); 00577 }
|
|
||||||||||||
|
Open a channel.
Definition at line 105 of file sensorexampleappui.cpp. References iDataListener. Referenced by ConstructL(). 00107 { 00108 CSensrvChannelFinder* finder = CSensrvChannelFinder::NewLC(); 00109 RSensrvChannelInfoList channelList; 00110 CleanupClosePushL( channelList ); 00111 00112 TSensrvChannelInfo info; 00113 info.iChannelType = aChannelTypeId; 00114 finder->FindChannelsL( channelList, info ); 00115 00116 if ( channelList.Count() > 0 ) 00117 { 00118 info = channelList[0]; 00119 00120 aChannel = CSensrvChannel::NewL( info ); 00121 aChannel->OpenChannelL(); 00122 aChannel->StartDataListeningL( iDataListener, 1, 1, 0 ); 00123 } 00124 00125 channelList.Close(); 00126 CleanupStack::Pop( &channelList ); 00127 CleanupStack::PopAndDestroy( finder ); 00128 }
|
|
|
Show a property query
Definition at line 208 of file sensorexampleappui.cpp. References HandlePropertyValueQueryL(), iAppView, ShowPropertyNoteL(), ShowPropertyValueNoteL(), and CSensorExampleAppView::ShowQueryDialogL(). 00209 { 00210 CSensrvChannelFinder* finder = CSensrvChannelFinder::NewLC(); 00211 RSensrvChannelInfoList channelList; 00212 CleanupClosePushL( channelList ); 00213 00214 TSensrvChannelInfo channelInfo; 00215 finder->FindChannelsL( channelList, channelInfo ); 00216 00217 TInt selectedChannelIndex = iAppView->ShowQueryDialogL( channelList ); 00218 00219 if( KErrCancel != selectedChannelIndex ) 00220 { 00221 //List all properties of the selected channel 00222 RSensrvPropertyList channelPropertyList; 00223 CleanupClosePushL( channelPropertyList ); 00224 CSensrvChannel* selectedChannel; 00225 selectedChannel = CSensrvChannel::NewL( channelList[selectedChannelIndex] ); 00226 CleanupStack::PushL( selectedChannel ); 00227 selectedChannel->OpenChannelL(); 00228 00229 selectedChannel->GetAllPropertiesL( channelPropertyList ); 00230 selectedChannelIndex = iAppView->ShowQueryDialogL( channelPropertyList ); 00231 00232 if( KErrCancel != selectedChannelIndex ) 00233 { 00234 switch( aCommand ) 00235 { 00236 case ESensorProperties: 00237 { 00238 ShowPropertyNoteL( channelPropertyList[selectedChannelIndex] ); 00239 } 00240 break; 00241 00242 case EGetValue: 00243 { 00244 ShowPropertyValueNoteL( channelPropertyList[selectedChannelIndex] ); 00245 } 00246 break; 00247 00248 case ESetValue: 00249 { 00250 HandlePropertyValueQueryL( channelPropertyList[selectedChannelIndex], 00251 selectedChannel ); 00252 } 00253 break; 00254 00255 default: 00256 Panic( ESensorExampleUi ); 00257 break; 00258 } 00259 } 00260 00261 selectedChannel->CloseChannel(); 00262 CleanupStack::PopAndDestroy( selectedChannel ); 00263 channelPropertyList.Close(); 00264 CleanupStack::Pop( &channelPropertyList ); 00265 } 00266 00267 channelList.Close(); 00268 CleanupStack::Pop( &channelList ); 00269 CleanupStack::PopAndDestroy( finder ); 00270 }
|
|
|
Show information note
Definition at line 556 of file sensorexampleappui.cpp. 00557 { 00558 CAknNoteDialog* note = NULL; 00559 00560 note = new ( ELeave ) CAknNoteDialog( CAknNoteDialog::ENoTone, CAknNoteDialog::ENoTimeout ); 00561 note->PrepareLC( R_SENSOREXAMPLE_INFORMATION_NOTE ); // Adds to CleanupStack 00562 note->SetTextWrapping( ETrue ); 00563 note->SetTextL( aNoteText ); 00564 note->RunLD(); 00565 // No need to Pop 'note' from Cleanup Stack since it is deleted in RunLD 00566 }
|
|
|
Show content of aProperty on information note
Definition at line 276 of file sensorexampleappui.cpp. Referenced by HandleQueryL(). 00277 { 00278 TBuf<KInfoNoteBufferSize> buffer; 00279 00280 //Property identifier 00281 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYID )->Des() ); 00282 CleanupStack::PopAndDestroy();//R_SE_PROPERTYID 00283 buffer.Append( KColon ); 00284 buffer.Append( KHexPrefix ); 00285 buffer.AppendNumUC( aProperty.GetPropertyId(), EHex ); 00286 00287 //Property type 00288 buffer.Append( KSpace ); 00289 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYTYPE )->Des() ); 00290 CleanupStack::PopAndDestroy();//R_SE_PROPERTYTYPE 00291 buffer.Append( KColon ); 00292 00293 switch( aProperty.PropertyType() ) 00294 { 00295 case ESensrvIntProperty: 00296 { 00297 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYTYPEINT )->Des() ); 00298 CleanupStack::PopAndDestroy();//R_SE_PROPERTYTYPEINT 00299 } 00300 break; 00301 00302 case ESensrvRealProperty: 00303 { 00304 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYTYPEREAL )->Des() ); 00305 CleanupStack::PopAndDestroy();//R_SE_PROPERTYTYPEREAL 00306 } 00307 break; 00308 00309 case ESensrvBufferProperty: 00310 { 00311 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYTYPEBUFFER )->Des() ); 00312 CleanupStack::PopAndDestroy();//R_SE_PROPERTYTYPEBUFFER 00313 } 00314 break; 00315 00316 default: 00317 { 00318 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYTYPENOTYPE )->Des() ); 00319 CleanupStack::PopAndDestroy();//R_SE_PROPERTYTYPENOTYPE 00320 } 00321 break; 00322 } 00323 00324 //Item index 00325 buffer.Append( KNewLine ); 00326 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYITEMINDEX )->Des() ); 00327 CleanupStack::PopAndDestroy();//R_SE_PROPERTYITEMINDEX 00328 buffer.Append( KColon ); 00329 buffer.AppendNum( aProperty.PropertyItemIndex() ); 00330 00331 //Array index 00332 buffer.Append( KSpace ); 00333 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYARRAYINDEX )->Des() ); 00334 CleanupStack::PopAndDestroy();//R_SE_PROPERTYARRAYINDEX 00335 buffer.Append( KColon ); 00336 buffer.AppendNum( aProperty.GetArrayIndex() ); 00337 00338 //Read only 00339 buffer.Append( KNewLine ); 00340 if( aProperty.ReadOnly() ) 00341 { 00342 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYROETRUE )->Des() ); 00343 CleanupStack::PopAndDestroy();//R_SE_PROPERTYROETRUE 00344 } 00345 else 00346 { 00347 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYROEFALSE )->Des() ); 00348 CleanupStack::PopAndDestroy();//R_SE_PROPERTYROEFALSE 00349 } 00350 00351 //Property value 00352 buffer.Append( KNewLine ); 00353 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYVALUE )->Des() ); 00354 CleanupStack::PopAndDestroy();//R_SE_PROPERTYVALUE 00355 buffer.Append( KColon ); 00356 00357 switch( aProperty.PropertyType() ) 00358 { 00359 case ESensrvIntProperty: 00360 { 00361 //Value 00362 TInt value( 0 ); 00363 aProperty.GetValue( value ); 00364 buffer.AppendNum( value ); 00365 00366 //Max value 00367 buffer.Append( KNewLine ); 00368 aProperty.GetMaxValue( value ); 00369 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYMAX )->Des() ); 00370 CleanupStack::PopAndDestroy();//R_SE_PROPERTYMAX 00371 buffer.Append( KColon ); 00372 buffer.AppendNum( value ); 00373 00374 //Min value 00375 buffer.Append( KSpace ); 00376 aProperty.GetMinValue( value ); 00377 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYMIN )->Des() ); 00378 CleanupStack::PopAndDestroy();//R_SE_PROPERTYMIN 00379 buffer.Append( KColon ); 00380 buffer.AppendNum( value ); 00381 } 00382 break; 00383 00384 case ESensrvRealProperty: 00385 { 00386 //Value 00387 TReal value( 0 ); 00388 aProperty.GetValue( value ); 00389 TRealFormat realFormat( KRealFormatWidth, KRealFormatDecimalPlaces ); 00390 buffer.AppendNum( value, realFormat ); 00391 00392 //Max value 00393 buffer.Append( KNewLine ); 00394 aProperty.GetMaxValue( value ); 00395 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYMAX )->Des() ); 00396 CleanupStack::PopAndDestroy();//R_SE_PROPERTYMAX 00397 buffer.Append( KColon ); 00398 buffer.AppendNum( value, realFormat ); 00399 00400 //Min value 00401 buffer.Append( KSpace ); 00402 aProperty.GetMinValue( value ); 00403 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYMIN )->Des() ); 00404 CleanupStack::PopAndDestroy();//R_SE_PROPERTYMIN 00405 buffer.Append( KColon ); 00406 buffer.AppendNum( value, realFormat ); 00407 } 00408 break; 00409 00410 case ESensrvBufferProperty: 00411 { 00412 TBuf8<KSensrvPropertyTextBufferSize> buf8; 00413 TBuf<KSensrvPropertyTextBufferSize> buf; 00414 aProperty.GetValue( buf8 ); 00415 buf.Copy( buf8 ); 00416 buffer.Append( buf ); 00417 } 00418 break; 00419 00420 default: 00421 { 00422 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYUNINITIALIZED )->Des() ); 00423 CleanupStack::PopAndDestroy();//R_SE_PROPERTYUNINITIALIZED 00424 } 00425 break; 00426 } 00427 00428 ShowNoteL( buffer ); 00429 }
|
|
|
Show property's value.
Definition at line 435 of file sensorexampleappui.cpp. Referenced by HandleQueryL(). 00436 { 00437 TBuf<KInfoNoteBufferSize> buffer; 00438 00439 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYVALUE )->Des() ); 00440 CleanupStack::PopAndDestroy();//R_SE_PROPERTYVALUE 00441 buffer.Append( KColon ); 00442 00443 switch( aProperty.PropertyType() ) 00444 { 00445 case ESensrvIntProperty: 00446 { 00447 TInt value( 0 ); 00448 aProperty.GetValue( value ); 00449 buffer.AppendNum( value ); 00450 } 00451 break; 00452 00453 case ESensrvRealProperty: 00454 { 00455 TReal value( 0 ); 00456 aProperty.GetValue( value ); 00457 TRealFormat realFormat( KRealFormatWidth, KRealFormatDecimalPlaces ); 00458 buffer.AppendNum( value, realFormat ); 00459 } 00460 break; 00461 00462 case ESensrvBufferProperty: 00463 { 00464 TBuf8<KSensrvPropertyTextBufferSize> bufValue; 00465 aProperty.GetValue( bufValue ); 00466 buffer.Copy( bufValue ); 00467 } 00468 break; 00469 00470 default: 00471 { 00472 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_PROPERTYUNINITIALIZED )->Des() ); 00473 CleanupStack::PopAndDestroy();//R_SE_PROPERTYUNINITIALIZED 00474 } 00475 break; 00476 } 00477 00478 ShowNoteL( buffer ); 00479 }
|
|
||||||||||||
|
Query new value for property
Definition at line 485 of file sensorexampleappui.cpp. Referenced by HandleQueryL(). 00487 { 00488 TBuf<KInfoNoteBufferSize> buffer; 00489 00490 if( !aProperty.ReadOnly() ) 00491 { 00492 if( ESensrvIntProperty == aProperty.PropertyType() ) 00493 { 00494 TInt value(0); 00495 TInt min(0); 00496 TInt max(0); 00497 aProperty.GetValue( value ); 00498 aProperty.GetMaxValue( max ); 00499 aProperty.GetMinValue( min ); 00500 CAknNumberQueryDialog* dlg; 00501 dlg = CAknNumberQueryDialog::NewL( value ); 00502 TBuf<KInfoNoteTitleBufferSize> title; 00503 title.Format( iCoeEnv->AllocReadResourceLC( R_SE_VALUEQUERYTITLE )->Des(), min, max ); 00504 CleanupStack::PopAndDestroy();//R_SE_VALUEQUERYTITLE 00505 00506 if( EEikBidOk == dlg->ExecuteLD( R_SENSOREXAMPLE_DIALOG_VALUE_EDIT_QUERY, title ) ) 00507 { 00508 aProperty.SetValue( value ); 00509 TInt ret = aChannel->SetProperty( aProperty ); 00510 00511 if( KErrNone == ret ) 00512 { 00513 TSensrvProperty property; 00514 aChannel->GetPropertyL( aProperty.GetPropertyId(), 00515 aProperty.PropertyItemIndex(), 00516 aProperty.GetArrayIndex(), 00517 property ); 00518 property.GetValue( value ); 00519 00520 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_VALUESETTO )->Des() ); 00521 CleanupStack::PopAndDestroy();//R_SE_VALUESETTO 00522 buffer.AppendNum( value ); 00523 } 00524 else 00525 { 00526 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_VALUESETERROR )->Des() ); 00527 CleanupStack::PopAndDestroy();//R_SE_VALUESETERROR 00528 buffer.AppendNum( ret ); 00529 } 00530 ShowNoteL( buffer ); 00531 } 00532 else 00533 { 00534 //Cancel was pressed 00535 } 00536 } 00537 else 00538 { 00539 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_VALUESETINTEGERONLY )->Des() ); 00540 CleanupStack::PopAndDestroy();//R_SE_VALUESETINTEGERONLY 00541 ShowNoteL( buffer ); 00542 } 00543 } 00544 else 00545 { 00546 buffer.Append( iCoeEnv->AllocReadResourceLC( R_SE_VALUESETREADONLY )->Des() ); 00547 CleanupStack::PopAndDestroy();//R_SE_VALUESETREADONLY 00548 ShowNoteL( buffer ); 00549 } 00550 }
|
|
|
The application view Owned by CSensorExampleAppUi Definition at line 129 of file sensorexampleappui.h. Referenced by ConstructL(), HandleQueryL(), HandleStatusPaneSizeChange(), and ~CSensorExampleAppUi(). |
|
|
Opened sensor channels. Owned by CSensorExampleAppUi Definition at line 135 of file sensorexampleappui.h. Referenced by ~CSensorExampleAppUi(). |
|
|
The listener for sensor data Owned by CSensorExampleAppUi Definition at line 143 of file sensorexampleappui.h. Referenced by ConstructL(), OpenChannelL(), and ~CSensorExampleAppUi(). |
|
© Nokia 2009 |