taskswitcher/taskswitcherui/taskswitcherapp/src/tsappui.cpp
branchRCL_3
changeset 9 f966699dea19
parent 5 c743ef5928ba
child 15 ff572dfe6d86
equal deleted inserted replaced
5:c743ef5928ba 9:f966699dea19
    25 #include <akntitle.h>
    25 #include <akntitle.h>
    26 #include <hlplch.h>
    26 #include <hlplch.h>
    27 #include <avkon.rsg>
    27 #include <avkon.rsg>
    28 #include <bautils.h>
    28 #include <bautils.h>
    29 #include <AknUtils.h>
    29 #include <AknUtils.h>
    30 #include <tstaskswitcher.rsg>
    30 #include <taskswitcher.rsg>
    31 #include <pslninternalcrkeys.h>
    31 #include <pslninternalcrkeys.h>
    32 #include <oommonitorsession.h>
    32 #include <oommonitorsession.h>
    33 #include <hal.h>
    33 #include <hal.h>
    34 #include <hal_data.h>
    34 #include <hal_data.h>
    35 #include <akntranseffect.h>
    35 #include <akntranseffect.h>
       
    36 #include <UikonInternalPSKeys.h>
    36 
    37 
    37 
    38 
    38 // AknCapServer UID, used for P&S category
    39 // AknCapServer UID, used for P&S category
    39 const TUid KTaskswitcherStateCategory = { 0x10207218 };
    40 const TUid KTaskswitcherStateCategory = { 0x10207218 };
    40 
    41 
    41 // Taskswitcher UI, used as P&S key
    42 // Taskswitcher UI, used as P&S key
    42 const TInt KTaskswitcherStateKey = KTsAppUidValue;
    43 const TInt KTaskswitcherStateKey = KTsAppUidValue;
       
    44 
       
    45 const TUid KTransitionsUid = {0x10281F90};
    43 
    46 
    44 // Values for Taskswitcher launching P&S
    47 // Values for Taskswitcher launching P&S
    45 const TInt KTaskswitcherBackgroundValue = 1;
    48 const TInt KTaskswitcherBackgroundValue = 1;
    46 const TInt KTaskswitcherForegroundValue = KTaskswitcherBackgroundValue << 1;
    49 const TInt KTaskswitcherForegroundValue = KTaskswitcherBackgroundValue << 1;
    47 const TInt KTaskswitcherShortAppKeyPressed = KTaskswitcherForegroundValue << 1;
    50 const TInt KTaskswitcherShortAppKeyPressed = KTaskswitcherForegroundValue << 1;
    80 		fs.Close();
    83 		fs.Close();
    81 		}
    84 		}
    82 #endif
    85 #endif
    83 
    86 
    84     // Initialise app UI with standard value.
    87     // Initialise app UI with standard value.
    85     BaseConstructL( CAknAppUi::EAknEnableSkin | CAknAppUi::EAknEnableMSK );
    88     BaseConstructL( CAknAppUi::EAknEnableSkin | 
       
    89 					CAknAppUi::EAknEnableMSK |
       
    90 					CAknAppUi::EAknSingleClickCompatible);
       
    91     SetFullScreenApp(EFalse);
    86 
    92 
    87 #ifndef _DEBUG
    93 #ifndef _DEBUG
    88     // set as system application (in release build) so we never get closed
    94     // set as system application (in release build) so we never get closed
    89     iEikonEnv->SetSystem( ETrue );
    95     iEikonEnv->SetSystem( ETrue );
    90 #endif
    96 #endif
   108     iGoToBackgroundTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   114     iGoToBackgroundTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   109 
   115 
   110     // Create commonly used instances (device state only?)
   116     // Create commonly used instances (device state only?)
   111     iDeviceState = CTsDeviceState::NewL();
   117     iDeviceState = CTsDeviceState::NewL();
   112 
   118 
       
   119     // Create custom window group
       
   120     iWg = RWindowGroup(CCoeEnv::Static()->WsSession());
       
   121     iWg.Construct((TUint32)&iWg, ETrue);
       
   122     
   113     // Create UI
   123     // Create UI
   114     iAppView = CTsAppView::NewL( ApplicationRect(), *iDeviceState );
   124     iAppView = CTsAppView::NewL( ApplicationRect(), *iDeviceState, iWg );
   115     AddToStackL( iAppView );
   125     AddToStackL( iAppView );
   116     
   126     
   117     //Enable effects
   127     //Enable effects
   118     GfxTransEffect::Enable();
   128     GfxTransEffect::Enable();
   119     GfxTransEffect::Register(iAppView,TUid::Uid(KTsAppUidValue));
   129     GfxTransEffect::Register(iAppView,KTransitionsUid);
   120     GfxTransEffect::SetTransitionObserver(this);
   130     GfxTransEffect::SetTransitionObserver(this);
   121 
   131 
   122     // Listen for change in the value of the ts state property.
   132     // Listen for change in the value of the ts state property.
   123     iPropListener = new ( ELeave ) CTsPropertyListener(
   133     iPropListener = new ( ELeave ) CTsPropertyListener(
   124             KTaskswitcherStateCategory, KTaskswitcherStateKey, *this );
   134             KTaskswitcherStateCategory, KTaskswitcherStateKey, *this );
       
   135     
       
   136     // Listen for layout changes
       
   137     iLayoutListener = new ( ELeave ) CTsPropertyListener(
       
   138             KPSUidUikon, KUikLayoutState, *this );
   125 
   139 
   126     // Initialise the application task object with the window group id of
   140     // Initialise the application task object with the window group id of
   127     // our application ( so that it represent our app )
   141     // our application ( so that it represent our app )
   128     iApplicationTask.SetWgId( iCoeEnv->RootWin().Identifier() );
   142     //iApplicationTask.SetWgId( iCoeEnv->RootWin().Identifier() );
       
   143     iApplicationTask.SetWgId( iWg.Identifier() );
   129 
   144 
   130     // And finally, go to background.
   145     // And finally, go to background.
   131     MoveAppToBackground( AknTransEffect::ENone );
   146     MoveAppToBackground( ENoneTransition );
   132 
   147     
       
   148     iEikonEnv->RootWin().SetOrdinalPosition(-1);
       
   149     iEikonEnv->RootWin().EnableReceiptOfFocus(EFalse);
       
   150     
       
   151     iIsPopUpShown = EFalse;
       
   152     
   133     TSLOG_OUT();
   153     TSLOG_OUT();
   134     }
   154     }
   135 
   155 
   136 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   137 // CTsAppUi::CTsAppUi()
   157 // CTsAppUi::CTsAppUi()
   158         }
   178         }
   159     GfxTransEffect::SetTransitionObserver(0);
   179     GfxTransEffect::SetTransitionObserver(0);
   160     
   180     
   161     delete iGoToBackgroundTimer;
   181     delete iGoToBackgroundTimer;
   162     delete iPropListener;
   182     delete iPropListener;
       
   183     delete iLayoutListener;
   163 
   184 
   164     // destroy UI first
   185     // destroy UI first
   165     if ( iAppView )
   186     if ( iAppView )
   166         {
   187         {
   167         RemoveFromStack( iAppView );
   188         RemoveFromStack( iAppView );
   169         }
   190         }
   170 
   191 
   171     delete iDeviceState;
   192     delete iDeviceState;
   172     delete iMemAllocBuf;
   193     delete iMemAllocBuf;
   173     delete iThemeEffectsEnabledWatcher;
   194     delete iThemeEffectsEnabledWatcher;
       
   195     
       
   196     iWg.Close();
   174     }
   197     }
   175 
   198 
   176 // -----------------------------------------------------------------------------
   199 // -----------------------------------------------------------------------------
   177 // CTsAppView::EffectsEnabled
   200 // CTsAppView::EffectsEnabled
   178 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   192         {
   215         {
   193         return;
   216         return;
   194         }
   217         }
   195     switch(aTransitionType)
   218     switch(aTransitionType)
   196         {
   219         {
   197     case AknTransEffect::EApplicationStart:
   220     case EForegroundTransition:
   198         StartTransition( aTransitionType, 
   221         StartTransition( aTransitionType, 
   199                          ETrue, 
   222                          ETrue, 
   200                          EFalse, 
   223                          EFalse, 
   201                          CAknTransitionUtils::EForceVisible);
   224                          CAknTransitionUtils::EForceVisible);
   202         break;
   225         break;
   203     case AknTransEffect::EApplicationExit:
   226     case EBackgroundTransition:
   204         StartTransition( aTransitionType, 
   227         StartTransition( aTransitionType, 
   205                          EFalse, 
   228                          EFalse, 
   206                          EFalse, 
   229                          EFalse, 
   207                          CAknTransitionUtils::EForceInvisible );
   230                          CAknTransitionUtils::EForceInvisible );
   208         break;
   231         break;
   209     case AknTransEffect::EApplicationStartRect:
   232     case EActivationTransition:
   210         StartTransition( aTransitionType, 
   233         StartTransition( aTransitionType, 
   211                          EFalse, 
   234                          EFalse, 
   212                          ETrue, 
   235                          ETrue, 
   213                          CAknTransitionUtils::EForceInvisible );
   236                          CAknTransitionUtils::EForceInvisible );
   214         break;
   237         break;
   222 void CTsAppUi::StartTransition( TUint aTranstionId,
   245 void CTsAppUi::StartTransition( TUint aTranstionId,
   223                                 TBool aVisibility,
   246                                 TBool aVisibility,
   224                                 TBool /*aLayers*/, 
   247                                 TBool /*aLayers*/, 
   225                                 TUint aSubCom )
   248                                 TUint aSubCom )
   226     {
   249     {
       
   250     this->RequestPopUpL();
   227     const TDesC8* ptr = reinterpret_cast<const TDesC8*>(iAppView);
   251     const TDesC8* ptr = reinterpret_cast<const TDesC8*>(iAppView);
   228     GfxTransEffect::Abort(iAppView);
   252     GfxTransEffect::Abort(iAppView);
   229     GfxTransEffect::Begin( iAppView, aTranstionId );
   253     GfxTransEffect::Begin( iAppView, aTranstionId );
   230     GfxTransEffect::SetDemarcation( iAppView, iAppView->Rect() );
   254     GfxTransEffect::SetDemarcation( iAppView, iAppView->Rect() );
   231     GfxTransEffect::NotifyExternalState( ECaptureComponentsBegin, ptr );
   255     GfxTransEffect::NotifyExternalState( ECaptureComponentsBegin, ptr );
   242 // -----------------------------------------------------------------------------
   266 // -----------------------------------------------------------------------------
   243 //
   267 //
   244 void CTsAppUi::TransitionFinished(const CCoeControl* /*aControl*/, 
   268 void CTsAppUi::TransitionFinished(const CCoeControl* /*aControl*/, 
   245                                   TUint /*aAction*/)
   269                                   TUint /*aAction*/)
   246     {
   270     {
       
   271     DisablePopUpL();
   247     /*if( aControl == iAppView )
   272     /*if( aControl == iAppView )
   248         {
   273         {
   249 		@TODO IMPLEMENT
   274 		@TODO IMPLEMENT
   250         }*/
   275         }*/
   251     }
   276     }
   265             break;
   290             break;
   266 
   291 
   267         case EAknSoftkeyExit:
   292         case EAknSoftkeyExit:
   268         case EAknSoftkeyBack:
   293         case EAknSoftkeyBack:
   269             // RSK => just hide
   294             // RSK => just hide
   270             MoveAppToBackground( AknTransEffect::EApplicationExit );
   295             MoveAppToBackground( EBackgroundTransition );
   271             break;
   296             break;
   272 
   297 
   273         case ETsCmdHelp:
   298         case ETsCmdHelp:
   274             {
   299             {
   275             MoveAppToBackground( AknTransEffect::EApplicationExit );
   300             MoveAppToBackground( EBackgroundTransition );
   276             CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
   301             CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
   277             HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), buf );
   302             HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), buf );
   278             }
   303             }
   279             break;
   304             break;
   280 
   305 
   316     // not with the hw key but by other means etc.)
   341     // not with the hw key but by other means etc.)
   317     if ( aForeground )
   342     if ( aForeground )
   318         {
   343         {
   319         HandleSwitchToForegroundEvent();
   344         HandleSwitchToForegroundEvent();
   320         }
   345         }
   321     else
   346     // exclude cases with dialogs like power menu, memory card
       
   347     else if( !IsFaded())
   322         {
   348         {
   323         HandleSwitchToBackgroundEvent();
   349         HandleSwitchToBackgroundEvent();
   324         }
   350         }
   325 
   351 
   326     // Call Base class method
   352     // Call Base class method
   338     TSLOG_CONTEXT( PropertyChanged, TSLOG_LOCAL );
   364     TSLOG_CONTEXT( PropertyChanged, TSLOG_LOCAL );
   339     TSLOG_IN();
   365     TSLOG_IN();
   340 
   366 
   341     TInt value( 0 );
   367     TInt value( 0 );
   342 
   368 
   343     if ( RProperty::Get( aCategory, aKey, value ) == KErrNone )
   369     if ( aCategory == KTaskswitcherStateCategory )
   344         {
   370         {
   345         if ( iForeground && (value & KTaskswitcherBackgroundValue) )
   371         if ( RProperty::Get( aCategory, aKey, value ) == KErrNone )
   346             {
   372             {
   347             MoveAppToBackground( AknTransEffect::EApplicationExit );
   373             if ( iForeground && (value & KTaskswitcherBackgroundValue) )
   348             }
       
   349         else if ( !iForeground && (value & KTaskswitcherForegroundValue) )
       
   350             {
       
   351             MoveAppToForeground( AknTransEffect::EApplicationStart );
       
   352             }
       
   353         else if( value & KTaskswitcherLongAppKeyPressed )
       
   354             {
       
   355             if(!iForeground)
       
   356                 {
   374                 {
   357                 MoveAppToBackground( AknTransEffect::EApplicationExit );
   375                 MoveAppToBackground( EBackgroundTransition );
   358                 }
   376                 }
   359             else
   377             else if ( !iForeground && (value & KTaskswitcherForegroundValue) )
   360                 {
   378                 {
   361                 iAppView->HandleAppKey(KAppKeyTypeLong);
   379                 MoveAppToForeground( EForegroundTransition );
   362                 }
   380                 }
   363             }
   381             else if( value & KTaskswitcherLongAppKeyPressed )
   364         else if(  value & KTaskswitcherShortAppKeyPressed )
   382                 {
   365             {
   383                 if(!iForeground)
   366             iAppView->HandleAppKey(KAppKeyTypeShort);
   384                     {
   367             }
   385                     MoveAppToBackground( EBackgroundTransition );
       
   386                     }
       
   387                 else
       
   388                     {
       
   389                     iAppView->HandleAppKey(KAppKeyTypeLong);
       
   390                     }
       
   391                 }
       
   392             else if(  value & KTaskswitcherShortAppKeyPressed )
       
   393                 {
       
   394                 iAppView->HandleAppKey(KAppKeyTypeShort);
       
   395                 }
       
   396             }
       
   397         }
       
   398     else if ( aCategory == KPSUidUikon && iIsPopUpShown )
       
   399         {
       
   400         TRAP_IGNORE(
       
   401             DisablePopUpL();
       
   402             HandleResourceChangeL(KEikDynamicLayoutVariantSwitch) );
   368         }
   403         }
   369 
   404 
   370     TSLOG_OUT();
   405     TSLOG_OUT();
   371     }
   406     }
   372 
   407 
   374 // CTsAppUi::HandleResourceChangeL
   409 // CTsAppUi::HandleResourceChangeL
   375 // -----------------------------------------------------------------------------
   410 // -----------------------------------------------------------------------------
   376 //
   411 //
   377 void CTsAppUi::HandleResourceChangeL( TInt aType )
   412 void CTsAppUi::HandleResourceChangeL( TInt aType )
   378     {
   413     {
       
   414     TSLOG_CONTEXT( CTsAppUi::HandleResourceChangeL, TSLOG_LOCAL );
       
   415     TSLOG_IN();
   379     // Must call base class implementation first,
   416     // Must call base class implementation first,
   380     // sizes from LayoutMetricsRect etc. will only be correct after this.
   417     // sizes from LayoutMetricsRect etc. will only be correct after this.
   381     CAknAppUi::HandleResourceChangeL( aType );
   418     CAknAppUi::HandleResourceChangeL( aType );
   382     if( aType == KEikDynamicLayoutVariantSwitch && iAppView )
   419     if( aType == KEikDynamicLayoutVariantSwitch && iAppView )
   383         {
   420         {
   384         iAppView->SetRect( ApplicationRect() );
   421         // Check if layout switch is necessary
       
   422         TSizeMode mode = iEikonEnv->ScreenDevice()->GetCurrentScreenModeAttributes();
       
   423         TBool isLandscape = mode.iScreenSize.iWidth > mode.iScreenSize.iHeight;
       
   424         TRect appRect = ApplicationRect();
       
   425         TBool isAppLandscape = appRect.Width() > appRect.Height();
       
   426         if(isLandscape != isAppLandscape)
       
   427             {
       
   428             // Keep displayed orientation
       
   429             return;
       
   430             }
   385         }
   431         }
   386     // forward event
   432     // forward event
   387     iDeviceState->HandleResourceChange( aType );
   433     iDeviceState->HandleResourceChange( aType );
   388     if ( iAppView )
   434     if ( iAppView )
   389         {
   435         {
   390         iAppView->HandleResourceChange( aType );
   436         iAppView->HandleResourceChange( aType );
   391         }
   437         }
       
   438     TSLOG_OUT();
   392     }
   439     }
   393 
   440 
   394 // -----------------------------------------------------------------------------
   441 // -----------------------------------------------------------------------------
   395 // CTsAppUi::MoveAppToBackground()
   442 // CTsAppUi::MoveAppToBackground()
   396 // -----------------------------------------------------------------------------
   443 // -----------------------------------------------------------------------------
   398 void CTsAppUi::MoveAppToBackground( TUint aTransitionType )
   445 void CTsAppUi::MoveAppToBackground( TUint aTransitionType )
   399     {
   446     {
   400     TSLOG_CONTEXT( MoveAppToBackground, TSLOG_LOCAL );
   447     TSLOG_CONTEXT( MoveAppToBackground, TSLOG_LOCAL );
   401     TSLOG_IN();
   448     TSLOG_IN();
   402 
   449 
   403     if ( AknTransEffect::ENone == aTransitionType || !EffectsEnabled() )
   450     if ( ENoneTransition == aTransitionType || !EffectsEnabled() )
   404         {
   451         {
   405         GoToBackgroundTimerCallback( this );
   452         GoToBackgroundTimerCallback( this );
   406         }
   453         }
   407     else
   454     else
   408         {
   455         {
   409         StartTransion(AknTransEffect::EApplicationExit);
   456         StartTransion(aTransitionType);
   410         iGoToBackgroundTimer->Cancel();
   457         iGoToBackgroundTimer->Cancel();
   411         iGoToBackgroundTimer->Start( 
   458         iGoToBackgroundTimer->Start( 
   412                 KWaitBeforeGoingToBackground, 
   459                 KWaitBeforeGoingToBackground, 
   413                 0,
   460                 0,
   414                 TCallBack( GoToBackgroundTimerCallback, this ) );
   461                 TCallBack( GoToBackgroundTimerCallback, this ) );
   474     {
   521     {
   475     TSLOG_CONTEXT( HandleSwitchToBackgroundEvent, TSLOG_LOCAL );
   522     TSLOG_CONTEXT( HandleSwitchToBackgroundEvent, TSLOG_LOCAL );
   476     TSLOG_IN();
   523     TSLOG_IN();
   477 
   524 
   478     // must not do anything if iForeground is already up-to-date
   525     // must not do anything if iForeground is already up-to-date
   479     // exclude cases with dialogs like power menu, memory card
   526 
   480     if( iForeground && !IsFaded() )  
   527     
       
   528     if( iForeground  )  
   481         {
   529         {
   482         iForeground = EFalse;
   530         iForeground = EFalse;
   483         SetTaskswitcherStateProperty( KTaskswitcherBackgroundValue );
   531         SetTaskswitcherStateProperty( KTaskswitcherBackgroundValue );
   484 
   532 
   485         //allocating extra memory space
   533         //allocating extra memory space
   579         }
   627         }
   580     TSLOG_OUT();
   628     TSLOG_OUT();
   581     }
   629     }
   582 
   630 
   583 
   631 
       
   632 // -----------------------------------------------------------------------------
       
   633 // CTsAppUi::RequestPopUpL
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 void CTsAppUi::RequestPopUpL()
       
   637     {
       
   638     TSLOG_CONTEXT( CTsAppUi::RequestPopUpL, TSLOG_LOCAL );
       
   639     TSLOG_IN();
       
   640     if(!iIsPopUpShown)
       
   641         {
       
   642         iIsPopUpShown = ETrue;
       
   643         TSizeMode mode = iEikonEnv->ScreenDevice()->GetCurrentScreenModeAttributes();
       
   644         TInt isLandscape = mode.iScreenSize.iWidth > mode.iScreenSize.iHeight;
       
   645         SetFullScreenApp(ETrue);
       
   646         if(isLandscape)
       
   647             {
       
   648             SetOrientationL(EAppUiOrientationLandscape);
       
   649             }
       
   650         else
       
   651             {
       
   652             SetOrientationL(EAppUiOrientationPortrait);
       
   653             }
       
   654         iEikonEnv->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
       
   655         }
       
   656     TSLOG_OUT();
       
   657     }
       
   658 
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CTsAppUi::DisablePopUpL
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CTsAppUi::DisablePopUpL()
       
   665     {
       
   666     TSLOG_CONTEXT( CTsAppUi::DisablePopUpL, TSLOG_LOCAL );
       
   667     TSLOG_IN();
       
   668     if(iIsPopUpShown)
       
   669         {
       
   670         iIsPopUpShown = EFalse;
       
   671         iEikonEnv->RootWin().SetOrdinalPosition(-1, ECoeWinPriorityNeverAtFront);
       
   672         SetOrientationL(EAppUiOrientationAutomatic);
       
   673         SetFullScreenApp(EFalse);
       
   674         }
       
   675     TSLOG_OUT();
       
   676     }
       
   677 
   584 // End of file
   678 // End of file