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

📄 backlightswitch.cpp

📁 基于Symbian平台下随心所欲控制屏幕的灯亮熄.在观看视频和发短信时这一点非常重要.
💻 CPP
字号:
/**
*
* Definition of CBackLightSwitch
*
* Copyright (c) 2004 Nokia Corporation
* version 2.0
*/

// INCLUDE FILES

#include "BackLightSwitch.h"

#include <PowerResMan.rsg>
#include <stringloader.h>
#include <aknnotewrappers.h>

const TInt KTimeOutTime = 10000000;

// Creates instance of CBackLight object
CBackLightSwitch* CBackLightSwitch::NewL()
    {
    CBackLightSwitch* self = new (ELeave) CBackLightSwitch();
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
    }

// Constructor
CBackLightSwitch::CBackLightSwitch()
 :  CActive(EPriorityStandard)
    {
    iBackLightOn = EFalse;
    }

// Destructor
CBackLightSwitch::~CBackLightSwitch()
    {
    // Make sure this active object is cancelled and close the timer
    Cancel();
    iTimer.Close();
    }

// 2nd Phase Constuctor
void CBackLightSwitch::ConstructL()
    {
    // Create a timer so that we can reset the inactivity time
    // after a given period
    User::LeaveIfError(iTimer.CreateLocal());

    // Add this active object to the active scheduler
    CActiveScheduler::Add(this);
    }


// Handles request completion - called by the Active Scheduler
void CBackLightSwitch::RunL()
    {
    Cancel();
    // The backlight is de-activated after a period of inactivity
    // This method will reset the current inactivity time to zero
    User::ResetInactivityTime();
    // We will need to reset the inactivity period
    // again before the backlight goes off
    // We therefore set of a time that will expire after 10 seconds
    // (The backlight is de-activated after approx 13secs of inactivity)
    iTimer.After(iStatus, KTimeOutTime);
    SetActive();
    }

// Cancel outstanding request - called by Cancel()
void CBackLightSwitch::DoCancel()
    {
    iTimer.Cancel();
    }


// This method will switch the requirement to keep the backlight on
void CBackLightSwitch::ChangeToNormal()
{
      Cancel();
	iBackLightOn =EFalse;
}
void CBackLightSwitch::ChangeTolongLight()
{
	// This code can only keep the backlight on - not switch it on
	User::ResetInactivityTime();
	// Start a timer so that we can reset the inactivity time
	// before the light goes out
	iTimer.After(iStatus, KTimeOutTime);
	SetActive();
   iBackLightOn =ETrue;
}
void CBackLightSwitch::ChangeStateL()
    {
    if (iBackLightOn)
        {
        // if the light was locked on, cancel the timer so that
        // the inactivity time will not be reset by this app
        Cancel();
        //CAknInformationNote* note = new(ELeave)CAknInformationNote();
        //HBufC* noteText;
        //noteText = StringLoader::LoadLC(R_BKLIGHT_NORMAL);

        //note->ExecuteLD(*noteText);
        //CleanupStack::PopAndDestroy(noteText);

        }
    else
        {
        // This code can only keep the backlight on - not switch it on
        User::ResetInactivityTime();
        // Start a timer so that we can reset the inactivity time
        // before the light goes out
        iTimer.After(iStatus, KTimeOutTime);
        SetActive();
        //CAknInformationNote* note = new(ELeave)CAknInformationNote();
        //HBufC* noteText;
        //noteText = StringLoader::LoadLC(R_BKLIGHT_ON);

        //note->ExecuteLD(*noteText);
        //CleanupStack::PopAndDestroy(noteText);

        }
    iBackLightOn = !iBackLightOn;
    }

⌨️ 快捷键说明

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