📄 camtestappui.cpp
字号:
/*
============================================================================
Name : CamTestAppUi.cpp
Author :
Version :
Copyright : Your copyright notice
Description : Main application UI class (controller)
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <eikmenup.h>
#include <CamTest.rsg>
#include <apgcli.h>
#include <hal.h>
#include <hlplch.h> // HlpLauncher
#include <aknnotewrappers.h>
#include <centralrepository.h>
#include <ProfileEngineSDKCRKeys.h>
#include <aknmessagequerydialog.h> // CAknMessageQueryDialog
#include <stringloader.h>
#include "CamTest.pan"
#include "CamTestAppUi.h"
#include "CamTestAppView.h"
#include "CamTest.hrh"
#include "CameraAppController.h"
#include "CameraAppBaseContainer.h"
#include "MyLogger.h"
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CCamTestAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CCamTestAppUi::ConstructL()
{
// Initialise app UI with standard value.
// Try to resolve the best orientation for the app
BaseConstructL(EAknEnableSkin/*|ResolveCameraOrientation()*/);
// Resolve the Media Gallery application's UID (a native app)
// iMediaGalleryUid3 = KMediaGalleryUID3PostFP1;
// Create a camera controller 创建一个照相机控制器
iController = new (ELeave) CCameraAppController(*this);
iController->ConstructL();
iView = CCamTestAppView::NewLC();
AddViewL( iView ); // transfer ownership to CAknViewAppUi
CleanupStack::Pop(iView);
SetDefaultViewL(*iView);
// Make this class observe changes in foreground events
// iEikonEnv->AddForegroundObserverL( *this );
// Default mode is viewfinding 默认模式viewfinding
iCameraMode = EViewFinding;
// Create view object
// iView = CCamTestAppView::NewL( ClientRect() );
}
// -----------------------------------------------------------------------------
// CCamTestAppUi::CCamTestAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
TCameraMode CCamTestAppUi::CameraMode()
{
return iCameraMode;
}
CCamTestAppUi::CCamTestAppUi()
: CAknViewAppUi(),
iController( 0 )
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CCamTestAppUi::~CCamTestAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CCamTestAppUi::~CCamTestAppUi()
{
if (iController)
delete iController;
}
// -----------------------------------------------------------------------------
// CCamTestAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CCamTestAppUi::HandleCommandL( TInt aCommand )
{
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
{
Exit();
break;
}
case ECameraAppCmdSnap:
{
DoSnapL();
break;
}
case ECameraAppCmdNewImage:
{
DoNewImageL();
break;
}
default:
Panic( ECamTestUi );
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CCamTestAppUi::HandleGainingForeground()
{
// Application gets focused so reserve the camera
// if it was disabled (ResetEngine() called)
MyLogger::Log(_L("kkk"));
if (!iController)
{
ResetEngine();
}
MyLogger::Log(_L("ooo"));
}
void CCamTestAppUi::HandleLosingForeground() //释放摄像头资源
{
// Application loses focus so release the camera
if (iController)
{
// Delete old controller and capture engine
delete iController;
iController = NULL;
}
}
/*
-------------------------------------------------------------------------------
Reset controller and capture engine 复位控制器和 捕捉引擎
-------------------------------------------------------------------------------
*/
void CCamTestAppUi::ResetEngine()
{
// Delete old controller and capture engine
if (iController)
{
delete iController;
iController = NULL;
}
// Create new controller and capture engine 创建新的控制器
iController = new (ELeave) CCameraAppController(*this);
iController->ConstructL();
// Set new controller pointers 设置新的 控制器 指针
iView->iContainer->SetController(iController);
iController->SetAppContainer(iView->iContainer);
// Check orientation 检查方向
CAknAppUiBase::TAppUiOrientation orientation = Orientation();
if (orientation == CAknAppUiBase::EAppUiOrientationPortrait)
{
iController->SetCameraOrientation(ECameraPortrait);
}
else
{
iController->SetCameraOrientation(ECameraLandscape);
}
iController->SkipFrames(KNumOfFrames);
iController->InitializeCameraL( ClientRect() );
iController->StartViewFinderL();
iCameraMode = EViewFinding;
}
/*
-------------------------------------------------------------------------------
Starts the viewfinder after taking a picture. Also updates the navi tabs.
启动后取景拍照 更新标签
-------------------------------------------------------------------------------
*/
void CCamTestAppUi::DoNewImageL()
{
// Redisplay the default navi pane
//重新默认导航窗格
iController->RedrawNaviPaneL();
//Start the viewfinder
//启动器
iController->StartViewFinderL();
iCameraMode = EViewFinding;
}
void CCamTestAppUi::DoSnapL()
{
// If the image is still being converted, then stop going further.
//如果图像被转换 停止更进
TEngineState state = iController->GetEngineState();//返回引擎状态
if ( state != EEngineIdle && state != EConverted )
return;
if ( iController->IsCameraUsedByAnotherApp() )
return;
// Snap the picture and save the image into the specific location
//捕获图像和 保存图像的位置
if ( iCameraMode == EViewFinding )
{
// Ensure that there is enough free space left 确定有足够的空间
if (iController->DiskSpaceBelowCriticalLevel())
{
HBufC* resMemoryLow = StringLoader::LoadLC(R_MEMORY_LOW);
_LIT(KMemoryLowHdr, "");
iEikonEnv->InfoWinL(*resMemoryLow, KMemoryLowHdr);
CleanupStack::PopAndDestroy(resMemoryLow);
}
else
{
MyLogger::Log(_L("www"));
iController->SnapL(); //拍摄图片
MyLogger::Log(_L("qqq"));
iCameraMode = EImageSnapped;
}
}
else if ( iCameraMode == EImageSnapped )
{
// Since the camera has taken one picture, then do the viewfinding
// again
//已经拍摄了图片, 再次拍照调用DoNewImageL
DoNewImageL();
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -