javauis/mmapi_qt/volumekeys/src/cmmaforeground.cpp
branchRCL_3
changeset 17 0fd27995241b
equal deleted inserted replaced
15:f9bb0fca356a 17:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Class is used to find out from java is midlet foreground or not
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 
       
    23 #include "cmmaforeground.h"
       
    24 #include "cmmaforegroundevent.h"
       
    25 //  INCLUDE FILES
       
    26 #include <logger.h>
       
    27 
       
    28 // xm-radio fix
       
    29 //#include "cmidenv.h"
       
    30 
       
    31 CMMAForeground* CMMAForeground::NewL(MMMAEventPoster* aEventPoster,
       
    32                                      jobject aForegroundListener,
       
    33                                      jmethodID aJavaMethod/* ,
       
    34                                      CMIDToolkit* aToolkit*/)
       
    35 {
       
    36     LOG( EJavaMMAPI, EInfo, "CMMAForeground::NewL + ");
       
    37     CMMAForeground* self = new(ELeave) CMMAForeground;
       
    38 
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL(aEventPoster, aForegroundListener, aJavaMethod/*, aToolkit*/);
       
    41     CleanupStack::Pop();
       
    42 
       
    43     LOG( EJavaMMAPI, EInfo, "CMMAForeground::NewL - ");
       
    44     return self;
       
    45 }
       
    46 
       
    47 CMMAForeground::~CMMAForeground()
       
    48 {
       
    49     LOG( EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() + ");
       
    50    /* if (iMidEnv)
       
    51     {
       
    52         // unregister for getting the foreground change event
       
    53         LOG( EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() : iMidEnv RemoveObserver +");
       
    54         iMidEnv->RemoveObserver(*this);
       
    55         LOG( EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() : iMidEnv RemoveObserver -");
       
    56     }
       
    57 
       
    58     CEikonEnv* eikEnv = ((CEikonEnv*)CEikonEnv::Static());
       
    59 
       
    60     if (eikEnv)
       
    61     {
       
    62         LOG( EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() : eikEnv RemoveForegroundObserver +");
       
    63         eikEnv->RemoveForegroundObserver(*this);
       
    64         LOG( EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() : eikEnv RemoveForegroundObserver -");
       
    65     }
       
    66 */
       
    67     if (iEventPoster && iDeleteRefEvent)
       
    68     {
       
    69         iEventPoster->PostEvent(iDeleteRefEvent);
       
    70     }
       
    71     else
       
    72     {
       
    73         delete iDeleteRefEvent;
       
    74     }
       
    75     delete iForegroundEvent;
       
    76     delete iActiveScheduler;
       
    77     LOG( EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() - ");
       
    78 }
       
    79 
       
    80 CMMAForeground::CMMAForeground()
       
    81         : iIsForeground(ETrue) // Initialize IsForeground to true, we might have already missed the event (HandleForegroundL), events before observer registration
       
    82 {
       
    83 }
       
    84 
       
    85 void CMMAForeground::ConstructL(MMMAEventPoster* aEventPoster,
       
    86                                 jobject aForegroundListener,
       
    87                                 jmethodID aJavaMethod /* ,
       
    88                                 CMIDToolkit* aToolkit*/) // xm-radio fix
       
    89 {
       
    90     LOG1( EJavaMMAPI, EInfo, "CMMAForeground::ConstructL + ISFOREGROUND = %d",iIsForeground);
       
    91 
       
    92     iActiveScheduler = new(ELeave) CActiveSchedulerWait();
       
    93     iEventPoster = aEventPoster;
       
    94     iForegroundListener = aForegroundListener;
       
    95     iJavaMethod = aJavaMethod;
       
    96 
       
    97     iForegroundEvent = new(ELeave) CMMAForegroundEvent(
       
    98         aForegroundListener,
       
    99         aJavaMethod,
       
   100         CMMAEvent::EReusableEvent);
       
   101     iDeleteRefEvent = new(ELeave) CMMADeleteRefEvent(aForegroundListener);
       
   102 
       
   103     // xm-radio fix
       
   104     /*
       
   105     iToolkit = aToolkit;
       
   106 
       
   107     if (iToolkit)
       
   108     {
       
   109         DEBUG("CMMAForeground::ConstructL : iToolkit->Env(); +");
       
   110         iMidEnv = iToolkit->Env();
       
   111         DEBUG("CMMAForeground::ConstructL : iToolkit->Env(); -");
       
   112     }
       
   113 
       
   114     if (iMidEnv)
       
   115     {
       
   116         DEBUG("CMMAForeground::ConstructL : iMidEnv->AddObserverL + ");
       
   117         // register for getting the foreground change event
       
   118         iMidEnv->AddObserverL(*this);
       
   119         DEBUG("CMMAForeground::ConstructL : iMidEnv->AddObserverL - ");
       
   120     }
       
   121 
       
   122     CEikonEnv* eikEnv = ((CEikonEnv*)CEikonEnv::Static());
       
   123 
       
   124     if (eikEnv)
       
   125     {
       
   126         DEBUG("CMMAForeground::ConstructL - eikAppUi->AddForegroundObserverL() + ");
       
   127         eikEnv->AddForegroundObserverL(*this);
       
   128         DEBUG("CMMAForeground::ConstructL - eikAppUi->AddForegroundObserverL() - ");
       
   129     }
       
   130  */
       
   131     LOG( EJavaMMAPI, EInfo, "CMMAForeground::ConstructL - ");
       
   132 }
       
   133 
       
   134 TBool CMMAForeground::IsForeground()
       
   135 {
       
   136     LOG2( EJavaMMAPI, EInfo, "THREADID = %d : CMMAForeground::IsForeground : ISFOREGROUND = %d",RThread().Id().Id(),iIsForeground);
       
   137     return iIsForeground;
       
   138 }
       
   139 
       
   140 void CMMAForeground::SetForeground(TBool aIsForeground)
       
   141 {
       
   142     iIsForeground = aIsForeground;
       
   143     LOG1( EJavaMMAPI, EInfo, "CMMAForeground::SetForeground - ISFOREGROUND = %d",iIsForeground);
       
   144 }
       
   145 
       
   146 // Implement MMIDEnvObserver
       
   147 /*
       
   148 void CMMAForeground::HandleSwitchOnL(TBool aSwitchOn)
       
   149 {
       
   150     // Dummy implementation, no intent to do anything
       
   151 }
       
   152 */
       
   153 /**
       
   154  * Handles the case when the MIDlet is brought to the foreground.
       
   155  */
       
   156  /*
       
   157 void CMMAForeground::HandleForegroundL(TBool aForeground)
       
   158 {
       
   159     LOG1( EJavaMMAPI, EInfo, "CMMAForeground::HandleForegroundL %d", aForeground);
       
   160     iIsForeground = aForeground;
       
   161 }
       
   162 */
       
   163 /**
       
   164  * Handles a change to resources which are shared accross the environment.
       
   165  */
       
   166 /*void CMMAForeground::HandleResourceChangeL(TInt aType)
       
   167 {
       
   168     // Dummy implementation, no intent to do anything
       
   169 }
       
   170 */
       
   171 // Handles the application coming to the foreground.
       
   172 void CMMAForeground::HandleGainingForeground()
       
   173 {
       
   174     iIsForeground = ETrue;
       
   175 }
       
   176 
       
   177 // Handles the application going into the background.
       
   178 void CMMAForeground::HandleLosingForeground()
       
   179 {
       
   180     iIsForeground = EFalse;
       
   181 }
       
   182 //  End of File