idlefw/src/framework/aifocusobserver.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Focus observer for Active idle 2
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aipspropertyobserver.h>
       
    20 #include <activeidle2domainpskeys.h>
       
    21 #include "aistatemanager.h"
       
    22 #include "aifocusobserver.h"
       
    23 #include "aifwpanic.h"
       
    24 #include "debug.h"
       
    25 
       
    26 CAiFocusObserver::CAiFocusObserver()
       
    27     {
       
    28     }
       
    29     
       
    30 CAiFocusObserver::~CAiFocusObserver()
       
    31     {
       
    32     }
       
    33 
       
    34 CAiFocusObserver* CAiFocusObserver::NewL(
       
    35                                         MAiStateManager* aStateManager )
       
    36     {
       
    37     CAiFocusObserver* self = new (ELeave) CAiFocusObserver();
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL( aStateManager );
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 void CAiFocusObserver::ConstructL( MAiStateManager* aStateManager )
       
    45     {
       
    46  //++HV
       
    47     BaseConstructL( TCallBack( StaticHandleFocusChangeEvent, this ),
       
    48                     KPSUidAiInformation, 
       
    49                     KActiveIdleState, 
       
    50                     aStateManager );
       
    51 //--HV
       
    52     }
       
    53     
       
    54 TAiStateChanges CAiFocusObserver::Status()
       
    55     {
       
    56     TInt value = 0;
       
    57     TInt err = iObserver->Get( value );
       
    58     if( ( value == EPSAiForeground ) &&
       
    59         ( err == KErrNone ) )
       
    60         {
       
    61         return ESMAIIdleForeground;
       
    62         }
       
    63     else
       
    64         {
       
    65         return ESMAIIdleBackground;
       
    66         } 
       
    67     }
       
    68 
       
    69  //++HV
       
    70                 
       
    71  TInt CAiFocusObserver::StaticHandleFocusChangeEvent( TAny* aPtr )
       
    72     {
       
    73     CAiFocusObserver* self =
       
    74                 static_cast<CAiFocusObserver*>( aPtr );
       
    75     
       
    76     __ASSERT_DEBUG( self, 
       
    77                     AiFwPanic::Panic( AiFwPanic::EAiFwPanic_NullPointerReference ) );
       
    78                     
       
    79     return( self->HandleFocusChangeEvent() );                
       
    80     }
       
    81     
       
    82     
       
    83 TInt CAiFocusObserver::HandleFocusChangeEvent()
       
    84     {
       
    85     if( iTfxEffectActive )
       
    86 		{
       
    87        	return KErrNone;
       
    88         }  
       
    89     
       
    90     TInt value = 0;
       
    91     TInt err = iObserver->Get( value );
       
    92     
       
    93     // Check the PS keys value and call manager with approriate parameter.
       
    94     // Repowrt either "idle foreground" or "idle background"
       
    95     if( ( value == EPSAiForeground ) &&
       
    96         ( err == KErrNone ) )
       
    97         {
       
    98        	// Check if the transition effect is active
       
    99        	
       
   100        	// This has to be called first, otherwise the state might not be valid.
       
   101 		CAknTransitionUtils::AddObserver( this, CAknTransitionUtils::EEventWsBufferRedirection );
       
   102 
       
   103  		TInt redirState = 0;
       
   104  		CAknTransitionUtils::GetState( CAknTransitionUtils::EEventWsBufferRedirection, &redirState );
       
   105  		if ( (TBool)redirState )
       
   106  			{
       
   107  			// The effect is on-going. Prevent view refresh until the effect is finished.
       
   108 			iTfxEffectActive = ETrue; 
       
   109  			} 
       
   110  		else
       
   111  			{			
       
   112     		// No effect on-going. Observer is not needed.    
       
   113 			CAknTransitionUtils::RemoveObserver( this, CAknTransitionUtils::EEventWsBufferRedirection );
       
   114         	iStateManager->ReportStateChange( ESMAIIdleForeground );
       
   115  			}
       
   116         }
       
   117     else if( value == EPSAiBackground )
       
   118         {
       
   119     	// Do not receive callbacks in background. Remove observer if it still exists.
       
   120     	CAknTransitionUtils::RemoveObserver( this, CAknTransitionUtils::EEventWsBufferRedirection );
       
   121     	iTfxEffectActive = EFalse;
       
   122     		
       
   123         iStateManager->ReportStateChange( ESMAIIdleBackground );
       
   124         } 
       
   125 
       
   126     return KErrNone;
       
   127     }
       
   128 
       
   129 
       
   130 TInt CAiFocusObserver::AknTransitionCallback( TInt aEvent, TInt aState, const TDesC8* /*aParams*/ )
       
   131 	{
       
   132 	if ( ( aEvent & CAknTransitionUtils::EEventWsBufferRedirection ) && ( !(TBool)aState ) )
       
   133 		{
       
   134 		// The effect has been finished
       
   135 		iTfxEffectActive = EFalse;
       
   136    		// Observer is not needed any more.    
       
   137     	CAknTransitionUtils::RemoveObserver( this, CAknTransitionUtils::EEventWsBufferRedirection );
       
   138     	
       
   139     	// Issue one focus change event
       
   140     	TInt value = 0;
       
   141     	TInt err = iObserver->Get( value );
       
   142     	if( ( value == EPSAiForeground ) &&
       
   143         	( err == KErrNone ) )
       
   144         	{
       
   145     	 	iStateManager->ReportStateChange( ESMAIIdleForeground );
       
   146         	}
       
   147     	else if( value == EPSAiBackground )
       
   148         	{
       
   149         	iStateManager->ReportStateChange( ESMAIIdleBackground );
       
   150         	} 
       
   151 		}
       
   152 	
       
   153 	return 0;	
       
   154 	}
       
   155 	
       
   156 
       
   157 //--HV