2 * Copyright (c) 2009 Nokia Corporation.
\r
8 #include <aknmessagequerydialog.h>
\r
9 #include <aknnotewrappers.h>
\r
12 #include <ZXingBarcodeReader_0xEF24C10A.rsg>
\r
13 #include "ZXingBarcodeReader.hrh"
\r
14 #include "ZXingBarcodeReader.pan"
\r
15 #include "ZXingBarcodeReaderApplication.h"
\r
16 #include "ZXingBarcodeReaderAppUi.h"
\r
17 #include "ZXingBarcodeReaderAppView.h"
\r
20 // ============================ MEMBER FUNCTIONS ===============================
\r
22 void CZXingBarcodeReaderAppUi::ConstructL ()
\r
24 // Initialise app UI with standard value.
\r
25 BaseConstructL (CAknAppUi::EAknEnableSkin );
\r
27 // Start receiving camera shutter key events
\r
28 #ifdef ENABLE_CAMERA_SHUTTER
\r
29 CaptureCameraShutter(ETrue);
\r
32 // Make this class observe changes in foreground events
\r
33 iEikonEnv->AddForegroundObserverL(*this);
\r
36 iAppView = CZXingBarcodeReaderAppView::NewL (ClientRect () );
\r
39 CZXingBarcodeReaderAppUi::CZXingBarcodeReaderAppUi ()
\r
43 CZXingBarcodeReaderAppUi::~CZXingBarcodeReaderAppUi ()
\r
47 #ifdef ENABLE_CAMERA_SHUTTER
\r
48 CaptureCameraShutter(EFalse);
\r
51 iShutterKeyHandles.Close();
\r
54 #ifdef ENABLE_CAMERA_SHUTTER
\r
56 void CZXingBarcodeReaderAppUi::CaptureCameraShutter(TBool aEnable)
\r
58 // Try to capture events from the camera shutter key(s)
\r
59 // http://wiki.forum.nokia.com/index.php/KIS000563_-_Camera_shutter_key_(EKeyCamera_events)_cannot_be_used_in_3rd_party_applications
\r
60 if (aEnable && !iCameraKeyCaptured)
\r
62 iCameraKeyCaptured = ETrue;
\r
65 iShutterKeyHandles.Reset();
\r
66 if(proc.HasCapability(ECapabilitySwEvent))
\r
68 for(TInt i=0; KCameraShutterKeyEventCodes[i] != 0; i++)
\r
70 TInt32 handle = iEikonEnv->RootWin().CaptureKey( KCameraShutterKeyEventCodes[i], 0, 0 );
\r
73 iShutterKeyHandles.Append(handle);
\r
78 else if(!aEnable && iCameraKeyCaptured)
\r
80 iCameraKeyCaptured = EFalse;
\r
81 // Disable capturing
\r
82 // Release the captured camera shutter key(s)
\r
83 for(TInt i=0; i < iShutterKeyHandles.Count(); i++)
\r
85 iEikonEnv->RootWin().CancelCaptureKey( iShutterKeyHandles[i] );
\r
92 void CZXingBarcodeReaderAppUi::HandleGainingForeground()
\r
94 // Application gets focused so reserve the camera
\r
95 // http://wiki.forum.nokia.com/index.php/CS000821_-_Handling_Camera_resource
\r
97 iAppView->CameraEngine() &&
\r
98 iAppView->CameraEngine()->State() != CCameraEngine::EEngineNotReady )
\r
100 iAppView->CameraEngine()->ReserveAndPowerOn();
\r
102 #ifdef ENABLE_CAMERA_SHUTTER
\r
103 CaptureCameraShutter(ETrue);
\r
108 void CZXingBarcodeReaderAppUi::HandleLosingForeground()
\r
110 // Application loses focus so release the camera
\r
111 // http://wiki.forum.nokia.com/index.php/CS000821_-_Handling_Camera_resource
\r
113 iAppView->CameraEngine() &&
\r
114 iAppView->CameraEngine()->State() != CCameraEngine::EEngineNotReady )
\r
116 iAppView->CameraEngine()->ReleaseAndPowerOff();
\r
118 #ifdef ENABLE_CAMERA_SHUTTER
\r
119 CaptureCameraShutter(EFalse);
\r
124 void CZXingBarcodeReaderAppUi::UseOptionsExitCbaL()
\r
126 CEikButtonGroupContainer* cba = Cba();
\r
129 cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
\r
134 void CZXingBarcodeReaderAppUi::UseOptionsBackCbaL()
\r
136 CEikButtonGroupContainer* cba = Cba();
\r
139 cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
\r
144 TBool CZXingBarcodeReaderAppUi::IsBackCBA()
\r
146 CEikButtonGroupContainer* cba = Cba();
\r
147 // NOTE: There should be EAknSoftkeyBack in the application because
\r
148 // we use R_AVKON_SOFTKEYS_SELECT_BACK, but it seems that there is EAknSoftkeyCancel
\r
149 CCoeControl* back = cba->ControlOrNull(EAknSoftkeyBack);
\r
150 CCoeControl* cancel = cba->ControlOrNull(EAknSoftkeyCancel);
\r
151 if (back || cancel)
\r
157 TKeyResponse CZXingBarcodeReaderAppUi::HandleKeyEventL(
\r
158 const TKeyEvent& aKeyEvent,TEventCode aType)
\r
160 // Capture picture with selection key
\r
161 switch ( aKeyEvent.iCode )
\r
164 case EStdKeyDevice3:
\r
166 case EKeyDownArrow:
\r
169 return iAppView->OfferKeyEventL(aKeyEvent,aType);
\r
177 // Camera shutter events handling
\r
178 #ifdef ENABLE_CAMERA_SHUTTER
\r
179 // Camera shutter autofocus
\r
180 switch ( aKeyEvent.iScanCode )
\r
182 case KStdKeyCameraFocus:
\r
183 case KStdKeyCameraFocus2:
\r
185 // Camera shutter autofocus
\r
186 return iAppView->OfferKeyEventL(aKeyEvent,aType);
\r
193 // Camera shutter key
\r
194 for(TInt i=0; KCameraShutterKeyEventCodes[i] != 0; i++)
\r
196 if( KCameraShutterKeyEventCodes[i] == aKeyEvent.iCode )
\r
199 iAppView->Capture();
\r
200 return EKeyWasConsumed;
\r
205 return EKeyWasNotConsumed;
\r
208 void CZXingBarcodeReaderAppUi::HandleCommandL (TInt aCommand )
\r
213 case EAknSoftkeyExit:
\r
218 case EAknSoftkeyBack:
\r
220 iAppView->CancelCapturedPicture();
\r
221 UseOptionsExitCbaL();
\r
226 CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog ();
\r
227 dlg->PrepareLC (R_ABOUT_QUERY_DIALOG );
\r
228 HBufC* title = iEikonEnv->AllocReadResourceLC (R_ABOUT_DIALOG_TITLE );
\r
229 dlg->QueryHeading ()->SetTextL (*title );
\r
230 CleanupStack::PopAndDestroy (); //title
\r
231 HBufC* msg = iEikonEnv->AllocReadResourceLC (R_ABOUT_DIALOG_TEXT );
\r
232 dlg->SetMessageTextL (*msg );
\r
233 CleanupStack::PopAndDestroy (); //msg
\r
244 void CZXingBarcodeReaderAppUi::HandleResourceChangeL(TInt aType)
\r
246 CAknAppUi::HandleResourceChangeL( aType );
\r
248 if ( aType==KEikDynamicLayoutVariantSwitch )
\r
253 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect);
\r
254 iAppView->SetRect(rect);
\r