⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hwrmtestappappui.cpp

📁 平台symbian。 功能:获取系统信息。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
* ==============================================================================
*  Name        : HWRMTestAppAppUi.cpp
*  Part of     : HWRMTestApp
*  Interface   : 
*  Description : HWRM Test application UI implementation
*  Version     : 
*
*  Copyright (c) 2002-2006 Nokia Corporation.
*  This material, including documentation and any related 
*  computer programs, is protected by copyright controlled by 
*  Nokia Corporation. 
* ==============================================================================
*/

// INCLUDE FILES
#include <aknNoteWrappers.h>
#include <eikmenup.h>
#include <avkon.hrh>
#include <aknselectionlist.h>
#include <HWRMPowerStateSDKPSKeys.h>
#include <HWRMTestApp.rsg>
#include "HWRMTestAppPropertyObserver.h"
#include "HWRMTestAppAppUi.h"
#include "HWRMTestAppContainer.h" 
#include "HWRMTestApp.hrh"


// ============================ MEMBER FUNCTIONS ===============================


// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::ConstructL
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::ConstructL()
    {
    BaseConstructL(CAknAppUi::EAknEnableSkin);
    iAppContainer = new (ELeave) CHWRMTestAppContainer;
    iAppContainer->SetMopParent(this);
    iAppContainer->ConstructL( ClientRect() );
    AddToStackL( iAppContainer );
    
    // We can ignore this error, simply dim the menus if 
    // pointer is null with the DynInitMenuPaneL method
    TRAPD( err, iLight = CHWRMLight::NewL(this) );
    if( err == KErrNotSupported )
        {
        _LIT( KLightNotSupported, "Light API Not Supported!" );
        iAppContainer->AddMessageL( KLightNotSupported );
        }
    else
        {
        PrintLightTargetsL();    
        }
    TRAP( err, iVibra = CHWRMVibra::NewL(this) );
    if( err == KErrNotSupported )
        {
        _LIT( KVibraNotSupported, "Vibra API Not Supported!" );
        iAppContainer->AddMessageL( KVibraNotSupported );
        }

    // Create the observers
    iBatteryStatusObserver = CHWRMTestAppPropertyObserver::NewL(
                    KPSUidHWRMPowerState,KHWRMBatteryStatus, iAppContainer );
    iBatteryLevelObserver = CHWRMTestAppPropertyObserver::NewL(
                    KPSUidHWRMPowerState,KHWRMBatteryLevel, iAppContainer );
    iChargingStatusObserver = CHWRMTestAppPropertyObserver::NewL(
                    KPSUidHWRMPowerState,KHWRMChargingStatus, iAppContainer );
    }

// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::~CHWRMTestAppAppUi
// Destructor
// Frees reserved resources
// -----------------------------------------------------------------------------
//
CHWRMTestAppAppUi::~CHWRMTestAppAppUi()
    {
    // Delete the observers
    delete iBatteryStatusObserver;
    delete iBatteryLevelObserver;
    delete iChargingStatusObserver;

    delete iLight; // kill light
    delete iVibra; // kill vibra

    if(iAppContainer)
        {
        RemoveFromStack( iAppContainer );
        delete iAppContainer;
        }
    }

// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::::DynInitMenuPaneL
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::DynInitMenuPaneL(
    TInt aResourceId,CEikMenuPane* aMenuPane)
    {
    if( aResourceId==R_HWRMTESTAPP_MENU )
    	{
    	//the main application menu
    	if( iLight )
            {
            //enable everything for lights
            aMenuPane->SetItemDimmed(EHWRMTestAppCmdLights,EFalse);
            }
        else
            {
            //dim everything for lights
            aMenuPane->SetItemDimmed(EHWRMTestAppCmdLights,ETrue);
            }
    	if( iVibra )
            {
            //enable everything for vibra
            aMenuPane->SetItemDimmed(EHWRMTestAppCmdVibra,EFalse);
            }
        else
            {
            //dim everything for vibra
            aMenuPane->SetItemDimmed(EHWRMTestAppCmdVibra,ETrue);
            }
    	}
	}

// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::HandleKeyEventL
// Pass key event to app container
// -----------------------------------------------------------------------------
//
TKeyResponse CHWRMTestAppAppUi::HandleKeyEventL(
    const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    return iAppContainer->OfferKeyEventL( aKeyEvent, aType );
    }

// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::HandleCommandL
// Handle command entered by user
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::HandleCommandL(TInt aCommand)
    {
    TInt err(KErrNone);
    
    switch ( aCommand )
        {
        case EAknSoftkeyBack:
        case EEikCmdExit:
            {
            Exit();
            break;
            }
        case EHWRMTestAppCmdVibraReserve:
            {
            _LIT(KReserveVibra, "Reserve vibra");
            iAppContainer->AddMessageL( KReserveVibra );
            TRAP( err, VibraReserveL() );
            break;
            }
        case EHWRMTestAppCmdVibraRelease:
            {
            _LIT(KReleaseVibra, "Release vibra");
            iAppContainer->AddMessageL( KReleaseVibra );
            TRAP( err, VibraReleaseL() );
            break;
            }
        case EHWRMTestAppCmdVibraStart:
            {
            _LIT(KStartVibra, "Start vibra");
            iAppContainer->AddMessageL( KStartVibra );
            TRAP( err, VibraStartL() );
            break;
            }
        case EHWRMTestAppCmdVibraStop:
            {
            _LIT(KStopVibra, "Stop vibra");
            iAppContainer->AddMessageL( KStopVibra );
            TRAP( err, VibraStopL() );
            break;
            }
        case EHWRMTestAppCmdVibraSettings:
        	{
        	_LIT(KVibraSettings, "Vibra settings");
        	iAppContainer->AddMessageL( KVibraSettings );
            VibraSettings();
            break;
        	}
        case EHWRMTestAppCmdVibraStatus:
        	{
        	_LIT(KVibraStatus, "Vibra status");
        	iAppContainer->AddMessageL( KVibraStatus );
            VibraStatus();
            break;
        	}
        case EHWRMTestAppCmdLightsReserve:
            {
            _LIT(KReserveLights, "Reserve lights");
            iAppContainer->AddMessageL( KReserveLights );
            TRAP( err, LightsReserveL() );
            break;
            }
        case EHWRMTestAppCmdLightsRelease:
            {
            _LIT(KReleaseLights, "Release lights");
            iAppContainer->AddMessageL( KReleaseLights );
            TRAP( err, LightsReleaseL() );
            break;
            }
        case EHWRMTestAppCmdLightsOn:
        	{
        	_LIT(KLightsOn, "Lights on");
        	iAppContainer->AddMessageL( KLightsOn );
            TRAP( err, LightsOnL() );
            break;
        	}
        case EHWRMTestAppCmdLightsBlink:
        	{
        	_LIT(KBlinkLights, "Blink lights");
        	iAppContainer->AddMessageL( KBlinkLights );
            TRAP( err, LightsBlinkL() );
            break;
        	}
        case EHWRMTestAppCmdLightsOff:
        	{
        	_LIT(KLightsOff, "Lights off");
        	iAppContainer->AddMessageL( KLightsOff );
            TRAP( err, LightsOffL() );
            break;
        	}
        case EHWRMTestAppCmdLightsStatus:
        	{
        	_LIT(KLightsStatus, "Lights status");
        	iAppContainer->AddMessageL( KLightsStatus );
            TRAP( err, LightsStatusL() );
            break;
        	}
        default:
            break;      
        }
    if( err != KErrNone )
        {
        TBuf<100> buf;
        _LIT(KErrorTrapped, "Error Trapped = %d!!!");
        buf.Format( KErrorTrapped, err );
        iAppContainer->AddMessageL( buf );
        }
    }

// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::HandleForegroundEventL
// Handle situation when app is sent to the foreground or background
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::HandleForegroundEventL(TBool aForeground)
    {
    // first call base implementation
    CEikAppUi::HandleForegroundEventL( aForeground );
    
    if( aForeground )
        {
        _LIT(KAppSentToForeground, "App sent to foreground");
        iAppContainer->AddMessageL( KAppSentToForeground );
        }
    else
        {
        _LIT(KAppSentToBackground, "App sent to background");
        iAppContainer->AddMessageL( KAppSentToBackground );
        }
    }


// =============================================================================
//                          VIBRA RELATED METHODS
// =============================================================================

// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::VibraReserveL
// Reserve vibra
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::VibraReserveL()
    {
    TInt item(0);
    TBuf<100> buf;
    TBool restore;
    TBool forceNoCCoeEnv;
    
    CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
    if( listDlg->ExecuteLD(R_HWRMTESTAPP_RESTORE_LIST) )
        {
        // got restore state parameter
        item == 0 ? restore = EFalse : restore = ETrue;
        //now get force no CCoeEnv parameter
        listDlg = new (ELeave)CAknListQueryDialog( &item );
        if( listDlg->ExecuteLD(R_HWRMTESTAPP_NOCCOEENV_LIST) )
            {
            // got ForceNoCCoeEnv parameter
            item == 0 ? forceNoCCoeEnv = EFalse : forceNoCCoeEnv = ETrue;
            _LIT(KReserveVibraLParameters, "ReserveVibraL(restore=%d,forceNoCCoeEnv=%d)");
            buf.Format( KReserveVibraLParameters, restore, forceNoCCoeEnv );
            iAppContainer->AddMessageL( buf );
            iVibra->ReserveVibraL( restore, forceNoCCoeEnv );
            }
        else
            {
            // did not get ForceNoCCoeEnv parameter
            _LIT(KReserveVibraLNotCalled, "ReserveVibraL not called, no ForceNoCCoeEnv value");
            iAppContainer->AddMessageL( KReserveVibraLNotCalled );
            }
        }
    else
        {
        // did not get restore parameter
        _LIT(KReserveVibraL, "ReserveVibraL()");
        iAppContainer->AddMessageL( KReserveVibraL );
        iVibra->ReserveVibraL();
        }
    }
    
// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::VibraReleaseL
// Release vibra
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::VibraReleaseL()
    {
    _LIT(KReleaseVibraCalled, "ReleaseVibra called");
    iAppContainer->AddMessageL( KReleaseVibraCalled );
    iVibra->ReleaseVibra();
    }
    
// -----------------------------------------------------------------------------
// CHWRMTestAppAppUi::VibraStartL
// Start vibra
// -----------------------------------------------------------------------------
//
void CHWRMTestAppAppUi::VibraStartL()
    {
    CAknNumberQueryDialog* dlg;
    TInt intensity(0);
    TInt duration(0);
    TBuf<100> buf;
    
    //duration

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -