javauis/mmapi_qt/volumekeys/src/cmmaforeground.cpp
branchRCL_3
changeset 25 ae942d28ec0e
equal deleted inserted replaced
24:6c158198356e 25:ae942d28ec0e
       
     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     //TODO MemoryLeak need to delete the above object.
       
    76     delete iForegroundEvent;
       
    77     delete iActiveScheduler;
       
    78     LOG(EJavaMMAPI, EInfo, "CMMAForeground::~CMMAForeground() - ");
       
    79 }
       
    80 
       
    81 CMMAForeground::CMMAForeground()
       
    82         : iIsForeground(ETrue) // Initialize IsForeground to true, we might have already missed the event (HandleForegroundL), events before observer registration
       
    83 {
       
    84 }
       
    85 
       
    86 void CMMAForeground::ConstructL(MMMAEventPoster* aEventPoster,
       
    87                                 jobject aForegroundListener,
       
    88                                 jmethodID aJavaMethod /* ,
       
    89                                 CMIDToolkit* aToolkit*/) // xm-radio fix
       
    90 {
       
    91     LOG1(EJavaMMAPI, EInfo, "CMMAForeground::ConstructL + ISFOREGROUND = %d",iIsForeground);
       
    92 
       
    93     iActiveScheduler = new(ELeave) CActiveSchedulerWait();
       
    94     iEventPoster = aEventPoster;
       
    95     iForegroundListener = aForegroundListener;
       
    96     iJavaMethod = aJavaMethod;
       
    97 
       
    98     iForegroundEvent = new(ELeave) CMMAForegroundEvent(
       
    99         aForegroundListener,
       
   100         aJavaMethod,
       
   101         CMMAEvent::EReusableEvent);
       
   102     iDeleteRefEvent = new(ELeave) CMMADeleteRefEvent(aForegroundListener);
       
   103 
       
   104     // xm-radio fix
       
   105     /*
       
   106     iToolkit = aToolkit;
       
   107 
       
   108     if (iToolkit)
       
   109     {
       
   110         DEBUG("CMMAForeground::ConstructL : iToolkit->Env(); +");
       
   111         iMidEnv = iToolkit->Env();
       
   112         DEBUG("CMMAForeground::ConstructL : iToolkit->Env(); -");
       
   113     }
       
   114 
       
   115     if (iMidEnv)
       
   116     {
       
   117         DEBUG("CMMAForeground::ConstructL : iMidEnv->AddObserverL + ");
       
   118         // register for getting the foreground change event
       
   119         iMidEnv->AddObserverL(*this);
       
   120         DEBUG("CMMAForeground::ConstructL : iMidEnv->AddObserverL - ");
       
   121     }
       
   122 
       
   123     CEikonEnv* eikEnv = ((CEikonEnv*)CEikonEnv::Static());
       
   124 
       
   125     if (eikEnv)
       
   126     {
       
   127         DEBUG("CMMAForeground::ConstructL - eikAppUi->AddForegroundObserverL() + ");
       
   128         eikEnv->AddForegroundObserverL(*this);
       
   129         DEBUG("CMMAForeground::ConstructL - eikAppUi->AddForegroundObserverL() - ");
       
   130     }
       
   131      */
       
   132     LOG(EJavaMMAPI, EInfo, "CMMAForeground::ConstructL - ");
       
   133 }
       
   134 
       
   135 TBool CMMAForeground::IsForeground()
       
   136 {
       
   137     LOG2(EJavaMMAPI, EInfo, "THREADID = %d : CMMAForeground::IsForeground : ISFOREGROUND = %d",RThread().Id().Id(),iIsForeground);
       
   138     return iIsForeground;
       
   139 }
       
   140 
       
   141 void CMMAForeground::SetForeground(TBool aIsForeground)
       
   142 {
       
   143     iIsForeground = aIsForeground;
       
   144     LOG1(EJavaMMAPI, EInfo, "CMMAForeground::SetForeground - ISFOREGROUND = %d",iIsForeground);
       
   145 }
       
   146 
       
   147 // Implement MMIDEnvObserver
       
   148 /*
       
   149 void CMMAForeground::HandleSwitchOnL(TBool aSwitchOn)
       
   150 {
       
   151     // Dummy implementation, no intent to do anything
       
   152 }
       
   153 */
       
   154 /**
       
   155  * Handles the case when the MIDlet is brought to the foreground.
       
   156  */
       
   157 /*
       
   158 void CMMAForeground::HandleForegroundL(TBool aForeground)
       
   159 {
       
   160    LOG1( EJavaMMAPI, EInfo, "CMMAForeground::HandleForegroundL %d", aForeground);
       
   161    iIsForeground = aForeground;
       
   162 }
       
   163 */
       
   164 /**
       
   165  * Handles a change to resources which are shared accross the environment.
       
   166  */
       
   167 /*void CMMAForeground::HandleResourceChangeL(TInt aType)
       
   168 {
       
   169     // Dummy implementation, no intent to do anything
       
   170 }
       
   171 */
       
   172 // Handles the application coming to the foreground.
       
   173 void CMMAForeground::HandleGainingForeground()
       
   174 {
       
   175     iIsForeground = ETrue;
       
   176 }
       
   177 
       
   178 // Handles the application going into the background.
       
   179 void CMMAForeground::HandleLosingForeground()
       
   180 {
       
   181     iIsForeground = EFalse;
       
   182 }
       
   183 //  End of File