Namespaces
Variants
Actions

Detecting focus change with RGA

Jump to: navigation, search
Archived.png
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata

Tested with
Devices(s): Nokia N93, Nokia N95

Compatibility
Platform(s): S60 3rd Edition

Article
Created: stolik (24 Sep 2008)
Last edited: lpvalente (18 Sep 2012)

Contents

Overview

This code snippet shows how to handle an application's actions while it has lost or gained focus with the RGA API.

Note: In order to use this code, you need to install the Open C plug-in.

Preconditions

To use this snippet you need to inherit your class from IApplicationStateObserver and create an instance of the IApplicationState object and set an observer to you class. Also you'll need to define the FocusGained() or/and FocusLost() functions which will be called by the observer.

This example relies on RGA API ngi and examplefw frameworks.

To run this snippet you need to use the ngi and examplefw frameworks provided with Open C/C++ Plug-ins for S60 3rd Edition. Examplefw sources are located in the "\nokia_plugin\rga\s60rgaex\common\gameexfw\src\" folder after the plug-in has been installed.

MMP file

The following capabilities and libraries are required:

CAPABILITY SwEvent
STATICLIBRARY libcrt0.lib
LIBRARY euser.lib
LIBRARY runtime.lib
LIBRARY libc.lib
LIBRARY libm.lib
LIBRARY libpthread.lib

Note: The snippet itself doesn't require any special capabilities, but due to the use of RGA API ngi framework, the resulting application requires SwEvent capability. (See also Open C/C++ DLL.)

Header file

#include <applicationstate.h>    // ngi
using namespace ngi;
 
class CExampleApplication : public IApplicationStateObserver
//...
{
 
//...
 
/**
* Application gained focus.
*
* Observer method for the gained focus event.
*/

virtual void FocusGained() NO_THROW;
/**
* Application lost focus.
*
* Observer method for the lost focus event.
*/

virtual void FocusLost() NO_THROW;
 
//...
 
/// Pointer to the application state object.
IApplicationState* mApplicationState;
 
//...
}

Source file

#include <errorcodes.h>         // ngi
#include <runtime.h> // ngi
#include <standardtypes.h> // ngi
#include "helper.h" //examplefw
 
CExampleApplication::~CExampleApplication()
{
//...
if( mApplicationState )
{
mApplicationState->SetObserver( NULL );
mApplicationState->Release();
mApplicationState = NULL;
}
//...
}
 
bool32 CExampleApplication::Initialize()
{
//...
if( CRuntime::CreateInstance( mApplicationState ) != OK)
{
return FALSE;
}
 
mApplicationState->SetObserver( this );
 
return TRUE;
}
 
// ---------------------------------------------------------
// This method is called when application looses focus.
// ---------------------------------------------------------
void CExampleApplication::FocusLost() NO_THROW
{
//Do necessary action on losing of focus
}
 
// ---------------------------------------------------------
// This method is called when application gets focus.
// ---------------------------------------------------------
void CExampleApplication::FocusGained() NO_THROW
{
//Do necessary action on gaining of focus
}

Postconditions

The observer will call FocusGained() or FocusLost() on focus load or gained events.

This page was last modified on 18 September 2012, at 21:09.
115 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved