javauis/lcdui_akn/lcdui/src/CMIDAppUi.cpp
branchRCL_3
changeset 60 6c158198356e
parent 19 04becd199f91
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include <eikenv.h>
    18 #include <eikenv.h>
    20 #include <eiksrvc.h>
    19 #include <eiksrvc.h>
    21 #include <eikappui.h>
    20 #include <eikappui.h>
    22 #include <Lcdglue.h>
    21 #include <Lcdglue.h>
    23 #include <j2me/jdebug.h>
    22 #include <j2me/jdebug.h>
    24 // needed for javaregistry
    23 // needed for javaregistry
    25 #include <javaregistryentry.h>
    24 #include <javaregistryentry.h>
    26 #include <javaregistry.h>
    25 #include <javaregistry.h>
    27 #include <javaattribute.h>
    26 #include <javaattribute.h>
    28 
    27 #ifdef RD_JAVA_NGA_ENABLED
       
    28 #include <goommonitorsession.h>
       
    29 #include <goommonitorplugin.hrh>
       
    30 #endif // RD_JAVA_NGA_ENABLED
    29 #include "CMIDAppUi.h"
    31 #include "CMIDAppUi.h"
    30 // using CMIDApplication API for iApp
    32 // using CMIDApplication API for iApp
    31 #include "CMIDApplication.h"
    33 #include "CMIDApplication.h"
    32 // needed for creating CMIDComponentFactory
    34 // needed for creating CMIDComponentFactory
    33 #include "CMIDComponentFactory.h"
    35 #include "CMIDComponentFactory.h"
    34 // constants for repeating key events
       
    35 #include "S60LCDUICustomEvents.h"
       
    36 // CMIDDisplayable class for iCurrentDisplayable
    36 // CMIDDisplayable class for iCurrentDisplayable
    37 #include "CMIDDisplayable.h"
    37 #include "CMIDDisplayable.h"
    38 
    38 
    39 #include "LcduiThread.h"
    39 #include "LcduiThread.h"
    40 
    40 
    42 
    42 
    43 using namespace java::ui;
    43 using namespace java::ui;
    44 using namespace Java;
    44 using namespace Java;
    45 
    45 
    46 // class CMIDAppUi
    46 // class CMIDAppUi
    47 CMIDAppUi::CMIDAppUi() : iCurrentDisplayable(NULL)
    47 CMIDAppUi::CMIDAppUi() : iCurrentDisplayable(NULL),
       
    48     iPendingOrientationChange(EFalse), iPauseApp(EFalse)
    48 {
    49 {
    49     mJavaAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaAknAppUi();
    50     mJavaAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaAknAppUi();
    50     mCoreAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi();
    51     mCoreAppUi = java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi();
    51 }
    52 }
    52 
    53 
   130     {
   131     {
   131         iObserver->HandleResourceChangeL(aType);
   132         iObserver->HandleResourceChangeL(aType);
   132     }
   133     }
   133     else
   134     else
   134     {
   135     {
   135         //
   136         if (aType == KEikDynamicLayoutVariantSwitch)
   136         //
   137         {
   137         //
   138             // Observer not set yet. Storing it for use after it is set.
   138     }
   139             iPendingOrientationChange= ETrue;
   139 }
   140         }
   140 
   141     }
   141 void CMIDAppUi::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& /*aEvent*/)
   142 }
   142 {
   143 
   143     if (EEnableMultipleKeyPressedEvent == aType)
   144 void CMIDAppUi::HandleApplicationSpecificEventL(TInt /*aType*/, const TWsEvent& /*aEvent*/)
   144     {
   145 {
   145         mCoreAppUi->glueSetKeyBlockMode(ENoKeyBlock);
       
   146     }
       
   147     else if (EDisableMultipleKeyPressedEvent == aType)
       
   148     {
       
   149         mCoreAppUi->glueSetKeyBlockMode(EDefaultBlockMode);
       
   150     }
       
   151 }
   146 }
   152 
   147 
   153 TBool CMIDAppUi::HandleWsEventL(const TWsEvent& aEvent,
   148 TBool CMIDAppUi::HandleWsEventL(const TWsEvent& aEvent,
   154                                 CCoeControl* /*aDestination*/)
   149                                 CCoeControl* /*aDestination*/)
   155 {
   150 {
   172         }
   167         }
   173     }
   168     }
   174 
   169 
   175     if (aEvent.Type() == EEventUser)
   170     if (aEvent.Type() == EEventUser)
   176     {
   171     {
   177         if ((*reinterpret_cast<TApaSystemEvent*>(aEvent.EventData())) == EApaSystemEventShutdown)
   172         TApaSystemEvent* eventData = reinterpret_cast<TApaSystemEvent*>(aEvent.EventData());
   178         {
   173         if ((*eventData) == EApaSystemEventShutdown)
       
   174         {
       
   175 #ifdef RD_JAVA_NGA_ENABLED
       
   176             // Check the reason
       
   177             eventData++;
       
   178             if ((*eventData) == KGoomMemoryLowEvent)
       
   179             {
       
   180                 return HandleGoomMemoryLowEventL();
       
   181             }
       
   182 #endif // RD_JAVA_NGA_ENABLED    
   179             // Oom or exit from task-list. Ask the CoreUi to shutdown the MIDlet.
   183             // Oom or exit from task-list. Ask the CoreUi to shutdown the MIDlet.
   180             java::ui::CoreUiAvkonLcdui::getInstance().shutDownRequestFromWindowServer();
   184             java::ui::CoreUiAvkonLcdui::getInstance().shutDownRequestFromWindowServer();
   181         }
   185         }
   182     }
   186     }
   183 
   187 
   184     // Workaround to send pauseApp with long-press of the Menu key
   188     // Workaround to send pauseApp with long-press of the Menu key
       
   189     // if no event was send yet
   185     if (aEvent.Type() == EEventKey)
   190     if (aEvent.Type() == EEventKey)
   186     {
   191     {
   187         if (aEvent.Key()->iScanCode == EStdKeyApplication0
   192         if (aEvent.Key()->iScanCode == EStdKeyApplication0
   188                 && aEvent.Key()->iRepeats == 1)
   193                 && aEvent.Key()->iRepeats == 1 && !iPauseApp)
       
   194         {
       
   195             if (iEnv && iEnv->MidletAttributeIsSetToVal(
       
   196                         LcduiMidletAttributes::KAttribFlipClose,
       
   197                         LcduiMidletAttributeValues::KPauseValue))
       
   198             {
       
   199                 iEnv->PostMidletEvent(EPause);
       
   200                 SetPauseAppState(ETrue);
       
   201             }
       
   202         }
       
   203     }
       
   204 
       
   205     if (aEvent.Type() == EEventKeyUp)
       
   206     {
       
   207 
       
   208         if (aEvent.Key()->iScanCode == EStdKeyDeviceA)   // if flip is opened
       
   209         {
       
   210             if (iEnv && iEnv->MidletAttributeIsSetToVal(
       
   211                         LcduiMidletAttributes::KAttribFlipClose,
       
   212                         LcduiMidletAttributeValues::KPauseValue))
       
   213 
       
   214             {
       
   215                 iEnv->PostMidletEvent(EStart);
       
   216             }
       
   217         }
       
   218 
       
   219         if (aEvent.Key()->iScanCode == EStdKeyDeviceB)   // if flip is closed
   189         {
   220         {
   190             if (iEnv && iEnv->MidletAttributeIsSetToVal(
   221             if (iEnv && iEnv->MidletAttributeIsSetToVal(
   191                         LcduiMidletAttributes::KAttribFlipClose,
   222                         LcduiMidletAttributes::KAttribFlipClose,
   192                         LcduiMidletAttributeValues::KPauseValue))
   223                         LcduiMidletAttributeValues::KPauseValue))
   193             {
   224             {
   194                 iEnv->PostMidletEvent(EPause);
   225                 iEnv->PostMidletEvent(EPause);
   195             }
   226             }
   196         }
   227         }
   197     }
   228     }
   198 
   229 
   199     if (aEvent.Type() == EEventKeyUp)
       
   200     {
       
   201 
       
   202         if (aEvent.Key()->iScanCode == EStdKeyDeviceA)   // if flip is opened
       
   203         {
       
   204             if (iEnv && iEnv->MidletAttributeIsSetToVal(
       
   205                         LcduiMidletAttributes::KAttribFlipClose,
       
   206                         LcduiMidletAttributeValues::KPauseValue))
       
   207 
       
   208             {
       
   209                 iEnv->PostMidletEvent(EStart);
       
   210             }
       
   211         }
       
   212 
       
   213         if (aEvent.Key()->iScanCode == EStdKeyDeviceB)   // if flip is closed
       
   214         {
       
   215             if (iEnv && iEnv->MidletAttributeIsSetToVal(
       
   216                         LcduiMidletAttributes::KAttribFlipClose,
       
   217                         LcduiMidletAttributeValues::KPauseValue))
       
   218             {
       
   219                 iEnv->PostMidletEvent(EPause);
       
   220             }
       
   221         }
       
   222     }
       
   223 
       
   224     if (aEvent.Type() == EEventKeyDown)
   230     if (aEvent.Type() == EEventKeyDown)
   225     {
   231     {
   226         if (iEnv)
   232         if (iEnv)
   227         {
   233         {
   228             iEnv->SetLastKeyEvent(*aEvent.Key());
   234             iEnv->SetLastKeyEvent(*aEvent.Key());
   231 
   237 
   232     // Handle application focus lost and notify current Displayable.
   238     // Handle application focus lost and notify current Displayable.
   233     if ((aEvent.Type() == KAknFullOrPartialForegroundLost)
   239     if ((aEvent.Type() == KAknFullOrPartialForegroundLost)
   234             || (aEvent.Type() == EEventFocusLost))
   240             || (aEvent.Type() == EEventFocusLost))
   235     {
   241     {
       
   242 #ifdef RD_JAVA_NGA_ENABLED
       
   243         if (aEvent.Type() == KAknFullOrPartialForegroundLost && iObserver)
       
   244         {
       
   245             iObserver->HandleFullOrPartialForegroundL(EFalse);
       
   246         }
       
   247 #endif // RD_JAVA_NGA_ENABLED
       
   248 
   236         if (iCurrentDisplayable && (iDisplayables.Count() > 0))
   249         if (iCurrentDisplayable && (iDisplayables.Count() > 0))
   237         {
   250         {
   238             iCurrentDisplayable->HandleApplicationBackground();
   251             iCurrentDisplayable->HandleApplicationBackground();
   239         }
   252         }
   240     }
   253     }
   246         {
   259         {
   247             iCurrentDisplayable->HandleResourceChange(aEvent.Type());
   260             iCurrentDisplayable->HandleResourceChange(aEvent.Type());
   248         }
   261         }
   249     }
   262     }
   250 
   263 
       
   264 #ifdef RD_JAVA_NGA_ENABLED
       
   265     if (aEvent.Type() == KAknFullOrPartialForegroundGained && iObserver)
       
   266     {
       
   267         iObserver->HandleFullOrPartialForegroundL(ETrue);
       
   268     }
       
   269 #endif // RD_JAVA_NGA_ENABLED
       
   270 
   251     return EFalse;
   271     return EFalse;
   252 }
   272 }
   253 
   273 
   254 // Sets the link to MMIDEnv - used for jad attribute parsing
   274 // Sets the link to MMIDEnv - used for jad attribute parsing
   255 void CMIDAppUi::SetEnv(MMIDEnv& aEnv)
   275 void CMIDAppUi::SetEnv(MMIDEnv& aEnv)
   260 void CMIDAppUi::UnSetEnv()
   280 void CMIDAppUi::UnSetEnv()
   261 {
   281 {
   262     iEnv = 0;
   282     iEnv = 0;
   263 }
   283 }
   264 
   284 
       
   285 #ifdef RD_JAVA_NGA_ENABLED
       
   286 TBool CMIDAppUi::HandleGoomMemoryLowEventL()
       
   287 {
       
   288     if (iObserver)
       
   289     {
       
   290         iObserver->HandleFreeGraphicsMemory();
       
   291         RGOomMonitorSession session;
       
   292         User::LeaveIfError(session.Connect());
       
   293         session.ThisAppIsNotExiting(CCoeEnv::Static()->RootWin().Identifier());
       
   294         session.Close();
       
   295         return ETrue;
       
   296     }
       
   297     return EFalse;
       
   298 }
       
   299 #endif // RD_JAVA_NGA_ENABLED
       
   300 
   265 //
   301 //
   266 // From MLcduiPlugin
   302 // From MLcduiPlugin
   267 //
   303 //
   268 void CMIDAppUi::SetObserver(MMIDObserver* aObserver)
   304 void CMIDAppUi::SetObserverL(MMIDObserver* aObserver)
   269 {
   305 {
   270     iObserver = aObserver;
   306     iObserver = aObserver;
       
   307     if (iPendingOrientationChange)
       
   308     {
       
   309         // We have received orientation change during the construction phase.
       
   310         // Resending it again in order to ensure correct layout and
       
   311         // orientation.
       
   312         iObserver->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
       
   313         iPendingOrientationChange = EFalse;
       
   314     }
   271 }
   315 }
   272 
   316 
   273 //
   317 //
   274 // From MLcduiPlugin
   318 // From MLcduiPlugin
   275 //
   319 //
   276 MMIDComponentFactory* CMIDAppUi::CreateComponentFactoryL()
   320 MMIDComponentFactory* CMIDAppUi::CreateComponentFactoryL()
   277 {
   321 {
   278     return new(ELeave) CMIDComponentFactory;
   322     return new(ELeave) CMIDComponentFactory;
   279 }
   323 }
   280 
   324 
       
   325 //
       
   326 // From MLcduiPlugin
       
   327 //
       
   328 void CMIDAppUi::SetEnv(MMIDEnv* aEnv)
       
   329 {
       
   330     iEnv = aEnv;
       
   331 }
       
   332 
   281 RPointerArray<CMIDDisplayable>& CMIDAppUi::Displayables()
   333 RPointerArray<CMIDDisplayable>& CMIDAppUi::Displayables()
   282 {
   334 {
   283     return iDisplayables;
   335     return iDisplayables;
   284 }
   336 }
   285 
   337 
   317 {
   369 {
   318     JELOG2(EJavaUI);
   370     JELOG2(EJavaUI);
   319     return mJavaAppUi->StatusPane();
   371     return mJavaAppUi->StatusPane();
   320 }
   372 }
   321 
   373 
       
   374 void CMIDAppUi::SetPauseAppState(TBool aState)
       
   375 {
       
   376     JELOG2(EJavaUI);
       
   377     iPauseApp = aState;
       
   378 }
       
   379 
       
   380 TBool CMIDAppUi::GetPauseAppState()
       
   381 {
       
   382     JELOG2(EJavaUI);
       
   383     return iPauseApp;
       
   384 }
       
   385