00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <avkon.hrh>
00032 #include <eikon.hrh>
00033 #include <aknmessagequerydialog.h>
00034 #include <aknnotewrappers.h>
00035 #include <eikenv.h>
00036
00037 #include <CameraExample_0xEF24C10A.rsg>
00038 #include "CameraWrapperExample.hrh"
00039 #include "CameraWrapperExample.pan"
00040 #include "CameraWrapperExampleApplication.h"
00041 #include "CameraWrapperExampleAppUi.h"
00042 #include "CameraWrapperExampleAppView.h"
00043
00044
00045
00046
00047 void CCameraWrapperExampleAppUi::ConstructL ()
00048 {
00049
00050 BaseConstructL (CAknAppUi::EAknEnableSkin );
00051
00052
00053 #ifdef ENABLE_CAMERA_SHUTTER
00054 CaptureCameraShutter(ETrue);
00055 #endif
00056
00057
00058 iEikonEnv->AddForegroundObserverL(*this);
00059
00060
00061 iAppView = CCameraWrapperExampleAppView::NewL (ClientRect () );
00062 }
00063
00064 CCameraWrapperExampleAppUi::CCameraWrapperExampleAppUi ()
00065 {
00066 }
00067
00068 CCameraWrapperExampleAppUi::~CCameraWrapperExampleAppUi ()
00069 {
00070 delete iAppView;
00071
00072 #ifdef ENABLE_CAMERA_SHUTTER
00073 CaptureCameraShutter(EFalse);
00074 #endif
00075
00076 iShutterKeyHandles.Close();
00077 }
00078
00079 #ifdef ENABLE_CAMERA_SHUTTER
00080
00081 void CCameraWrapperExampleAppUi::CaptureCameraShutter(TBool aEnable)
00082 {
00083
00084
00085 if (aEnable && !iCameraKeyCaptured)
00086 {
00087 iCameraKeyCaptured = ETrue;
00088
00089 RProcess proc;
00090 iShutterKeyHandles.Reset();
00091 if(proc.HasCapability(ECapabilitySwEvent))
00092 {
00093 for(TInt i=0; KCameraShutterKeyEventCodes[i] != 0; i++)
00094 {
00095 TInt32 handle = iEikonEnv->RootWin().CaptureKey( KCameraShutterKeyEventCodes[i], 0, 0 );
00096 if(handle >= 0)
00097 {
00098 iShutterKeyHandles.Append(handle);
00099 }
00100 }
00101 }
00102 }
00103 else if(!aEnable && iCameraKeyCaptured)
00104 {
00105 iCameraKeyCaptured = EFalse;
00106
00107
00108 for(TInt i=0; i < iShutterKeyHandles.Count(); i++)
00109 {
00110 iEikonEnv->RootWin().CancelCaptureKey( iShutterKeyHandles[i] );
00111 }
00112 }
00113 }
00114 #endif
00115
00116
00117 void CCameraWrapperExampleAppUi::HandleGainingForeground()
00118 {
00119
00120
00121 if ( iAppView &&
00122 iAppView->CameraEngine() &&
00123 iAppView->CameraEngine()->State() != CCameraEngine::EEngineNotReady )
00124 {
00125 iAppView->CameraEngine()->ReserveAndPowerOn();
00126
00127 #ifdef ENABLE_CAMERA_SHUTTER
00128 CaptureCameraShutter(ETrue);
00129 #endif
00130 }
00131 }
00132
00133 void CCameraWrapperExampleAppUi::HandleLosingForeground()
00134 {
00135
00136
00137 if ( iAppView &&
00138 iAppView->CameraEngine() &&
00139 iAppView->CameraEngine()->State() != CCameraEngine::EEngineNotReady )
00140 {
00141 iAppView->CameraEngine()->ReleaseAndPowerOff();
00142
00143 #ifdef ENABLE_CAMERA_SHUTTER
00144 CaptureCameraShutter(EFalse);
00145 #endif
00146 }
00147 }
00148
00149 void CCameraWrapperExampleAppUi::UseOptionsExitCbaL()
00150 {
00151 CEikButtonGroupContainer* cba = Cba();
00152 if (cba)
00153 {
00154 cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
00155 cba->DrawNow();
00156 }
00157 }
00158
00159 void CCameraWrapperExampleAppUi::UseOptionsBackCbaL()
00160 {
00161 CEikButtonGroupContainer* cba = Cba();
00162 if (cba)
00163 {
00164 cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
00165 cba->DrawNow();
00166 }
00167 }
00168
00169 TBool CCameraWrapperExampleAppUi::IsBackCBA()
00170 {
00171 CEikButtonGroupContainer* cba = Cba();
00172
00173
00174 CCoeControl* back = cba->ControlOrNull(EAknSoftkeyBack);
00175 CCoeControl* cancel = cba->ControlOrNull(EAknSoftkeyCancel);
00176 if (back || cancel)
00177 return ETrue;
00178 else
00179 return EFalse;
00180 }
00181
00182 TKeyResponse CCameraWrapperExampleAppUi::HandleKeyEventL(
00183 const TKeyEvent& aKeyEvent,TEventCode aType)
00184 {
00185
00186 switch ( aKeyEvent.iCode )
00187 {
00188 case EKeyOK:
00189 case EStdKeyDevice3:
00190 case EKeyUpArrow:
00191 case EKeyDownArrow:
00192 {
00193
00194 return iAppView->OfferKeyEventL(aKeyEvent,aType);
00195 }
00196 default:
00197 {
00198 break;
00199 }
00200 };
00201
00202
00203 #ifdef ENABLE_CAMERA_SHUTTER
00204
00205 switch ( aKeyEvent.iScanCode )
00206 {
00207 case KStdKeyCameraFocus:
00208 case KStdKeyCameraFocus2:
00209 {
00210
00211 return iAppView->OfferKeyEventL(aKeyEvent,aType);
00212 }
00213 default:
00214 {
00215 break;
00216 }
00217 };
00218
00219 for(TInt i=0; KCameraShutterKeyEventCodes[i] != 0; i++)
00220 {
00221 if( KCameraShutterKeyEventCodes[i] == aKeyEvent.iCode )
00222 {
00223
00224 iAppView->Capture();
00225 return EKeyWasConsumed;
00226 }
00227 }
00228 #endif
00229
00230 return EKeyWasNotConsumed;
00231 }
00232
00233 void CCameraWrapperExampleAppUi::HandleCommandL (TInt aCommand )
00234 {
00235 switch (aCommand )
00236 {
00237 case EEikCmdExit:
00238 case EAknSoftkeyExit:
00239 {
00240 Exit();
00241 break;
00242 }
00243 case EAknSoftkeyBack:
00244 {
00245 iAppView->CancelCapturedPicture();
00246 UseOptionsExitCbaL();
00247 break;
00248 }
00249 case EAbout:
00250 {
00251 CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog ();
00252 dlg->PrepareLC (R_ABOUT_QUERY_DIALOG );
00253 HBufC* title = iEikonEnv->AllocReadResourceLC (R_ABOUT_DIALOG_TITLE );
00254 dlg->QueryHeading ()->SetTextL (*title );
00255 CleanupStack::PopAndDestroy ();
00256 HBufC* msg = iEikonEnv->AllocReadResourceLC (R_ABOUT_DIALOG_TEXT );
00257 dlg->SetMessageTextL (*msg );
00258 CleanupStack::PopAndDestroy ();
00259 dlg->RunLD();
00260 break;
00261 }
00262 default:
00263 {
00264 break;
00265 }
00266 };
00267 }
00268
00269 void CCameraWrapperExampleAppUi::HandleResourceChangeL(TInt aType)
00270 {
00271 CAknAppUi::HandleResourceChangeL( aType );
00272
00273 if ( aType==KEikDynamicLayoutVariantSwitch )
00274 {
00275 if (iAppView)
00276 {
00277 TRect rect;
00278 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect);
00279 iAppView->SetRect(rect);
00280 }
00281 }
00282
00283 }
00284
00285