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