fmradio/fmradio/src/fmradiomaincontainer.cpp
changeset 0 f3d95d9c00ab
child 5 108d9820af01
equal deleted inserted replaced
-1:000000000000 0:f3d95d9c00ab
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Implementation of the class CFMRadioMainContainer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <alf/alfcontrolgroup.h>
       
    22 #include <alf/alfdisplay.h>
       
    23 #include <alf/alfroster.h>
       
    24 #include <alf/alflayoutmetrics.h>
       
    25 #include <AknLayoutFont.h>
       
    26 #include <aknlayoutscalable_apps.cdl.h>
       
    27 #include <AknsBasicBackgroundControlContext.h>
       
    28 #include <AknsDrawUtils.h>
       
    29 #include <AknsSkinInstance.h>
       
    30 #include <AknsUtils.h>
       
    31 #include <aknconsts.h>
       
    32 #include <AknDef.h>
       
    33 #include <StringLoader.h>
       
    34 #include <barsread.h>
       
    35 #include <w32std.h>
       
    36 #include <e32base.h>
       
    37 #include <fontids.hrh>
       
    38 #include <gulfont.h>
       
    39 #include <fmradio.rsg>
       
    40 #include <fmradiouids.h>
       
    41 
       
    42 #include "fmradiomaincontainer.h"
       
    43 #if defined __SERIES60_HELP || defined FF_S60_HELPS_IN_USE
       
    44 #include "radio.hlp.hrh"
       
    45 #endif
       
    46 #include "fmradioengine.h"
       
    47 #include "fmradioalfrdsviewer.h"
       
    48 #include "fmradioalfvisualizer.h"
       
    49 #include "fmradioalfmediaidle.h"
       
    50 #include "fmradioalfindicator.h"
       
    51 #include "fmradiologo.h"
       
    52 #include "fmradiordsreceiverbase.h"
       
    53 #include "fmradioalfrdsviewer.h"
       
    54 #include "fmradiomainview.h"
       
    55 #include "fmradioidlecontroller.h"
       
    56 #include "debug.h"
       
    57 
       
    58 
       
    59 // ~3 seconds, 10 frames / second is used
       
    60 const TInt KFadeFrames = 30;   
       
    61 const TInt KTenMilliSecondsInMicroSeconds = 100000;
       
    62 // values from fmradio LAF document
       
    63 const TInt KLAFVarietyRDSViewerPortrait = 0;
       
    64 const TInt KLAFVarietyRDSViewerLandscape = 1;
       
    65 const TInt KLAFVarietyRDSPlusIndicatorPortrait = 0;
       
    66 const TInt KLAFVarietyRDSPlusIndicatorLandscape = 1;
       
    67 const TInt KLAFVarietyAFIndicatorPortrait = 0;
       
    68 const TInt KLAFVarietyAFIndicatorLandscape = 1;
       
    69 const TInt KLAFVarietyRDSIndicatorPortrait = 0;
       
    70 const TInt KLAFVarietyRDSIndicatorLandscape = 1;
       
    71 const TInt KLAFVarietyLogoImagePortrait = 0;
       
    72 const TInt KLAFVarietyLogoImageLandscape = 1;
       
    73 const TInt KLAFVarietyIndicatorPanePortrait = 0;
       
    74 const TInt KLAFVarietyIndicatorPaneLandscape = 1;
       
    75 const TInt KLAFVarietyVisualPanePortrait = 0;
       
    76 const TInt KLAFVarietyVisualPaneLandscape = 1;
       
    77 
       
    78 // ================= MEMBER FUNCTIONS =======================
       
    79 
       
    80 // ---------------------------------------------------------------------------------
       
    81 // CFMRadioTimer::CFMRadioTimer
       
    82 // ---------------------------------------------------------------------------------
       
    83 CFMRadioTimer::CFMRadioTimer( MFMRadioTimer* aTimerObserver  ) : 
       
    84 	CActive( EPriorityStandard ),
       
    85 	iTimerObserver( aTimerObserver )
       
    86 	{
       
    87 	CActiveScheduler::Add( this );
       
    88 	}
       
    89 	
       
    90 // ---------------------------------------------------------------------------------
       
    91 // CFMRadioTimer::~CFMRadioTimer
       
    92 // ---------------------------------------------------------------------------------
       
    93 CFMRadioTimer::~CFMRadioTimer()
       
    94 	{
       
    95 	
       
    96 	Cancel();
       
    97 	}
       
    98 	
       
    99 // ---------------------------------------------------------------------------------
       
   100 // CFMRadioTimer::RunL
       
   101 // ---------------------------------------------------------------------------------
       
   102 void CFMRadioTimer::RunL()
       
   103 	{
       
   104 	
       
   105 	iTimerObserver->TimerTimeOut( iStatus.Int() );
       
   106 	}
       
   107 	
       
   108 // ---------------------------------------------------------------------------------
       
   109 // CFMRadioTimer::DoCancel
       
   110 // ---------------------------------------------------------------------------------
       
   111 void CFMRadioTimer::DoCancel()
       
   112 	{
       
   113 	
       
   114 	TInt ret = KErrCancel;
       
   115 	iTimerObserver->TimerTimeOut( ret );
       
   116 	}
       
   117 	
       
   118 // ---------------------------------------------------------------------------------
       
   119 // CFMRadioTimer::Activate
       
   120 // ---------------------------------------------------------------------------------
       
   121 void CFMRadioTimer::Activate()
       
   122 	{
       
   123 	SetActive();	
       
   124 	}
       
   125 
       
   126 
       
   127 // --------------------------------------------------------------------------------
       
   128 // CFMRadioMainContainer::NewL
       
   129 // Two-phase constructor of CFMRadioDelayTimer
       
   130 // --------------------------------------------------------------------------------
       
   131 //
       
   132 CFMRadioMainContainer* CFMRadioMainContainer::NewL(
       
   133     const TRect& aRect,
       
   134     CAlfEnv& aAlfEnv,
       
   135     CRadioEngine& aRadioEngine )
       
   136     {
       
   137     CFMRadioMainContainer* self = new (ELeave) CFMRadioMainContainer( aAlfEnv, aRadioEngine  );
       
   138     CleanupStack::PushL( self );
       
   139     self->ConstructL( aRect );
       
   140     CleanupStack::Pop( self );
       
   141     return self;
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------------
       
   145 // CFMRadioMainContainer::CFMRadioMainContainer
       
   146 // Default constructor
       
   147 // --------------------------------------------------------------------------------
       
   148 //
       
   149 CFMRadioMainContainer::CFMRadioMainContainer( CAlfEnv& aAlfEnv, CRadioEngine& aRadioEngine ) :
       
   150 	iAlfEnv ( aAlfEnv ),
       
   151 	iRadioEngine (aRadioEngine ),
       
   152 	iLightsOffCounter(0)
       
   153 	{
       
   154 	//No implementation needed		
       
   155 	}
       
   156 	
       
   157 // --------------------------------------------------------------------------------
       
   158 // CFMRadioMainContainer::ConstructL
       
   159 // EPOC two phased constructor
       
   160 // --------------------------------------------------------------------------------
       
   161 //
       
   162 void CFMRadioMainContainer::ConstructL(
       
   163     const TRect& aRect )
       
   164     {
       
   165     iCoeEnv = CCoeEnv::Static();
       
   166 
       
   167     TRAP_IGNORE( iLight = CHWRMLight::NewL(this) );
       
   168 	iTimer = new(ELeave) CFMRadioTimer( this );
       
   169 	timer.CreateLocal();
       
   170 	
       
   171     // check the layout orientation
       
   172     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
   173     TBool isLandscape = appUi->IsLandscapeOrientation();
       
   174 
       
   175     TRgb color;
       
   176 
       
   177     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
       
   178 	//CreateWindowL(); // create a window for the container
       
   179     	
       
   180     // Create alfred display
       
   181     CAlfDisplay* display = NULL; 
       
   182     if ( iAlfEnv.DisplayCount() > 0 )
       
   183     	{
       
   184     	display = &(iAlfEnv.PrimaryDisplay());
       
   185     	}
       
   186     else
       
   187     	{
       
   188     	display = &(iAlfEnv.NewDisplayL( aRect, CAlfEnv::ENewDisplayAsCoeControl ));
       
   189     	}
       
   190 
       
   191 	// Setup background.
       
   192 	display->SetClearBackgroundL( CAlfDisplay::EClearWithSkinBackground );	
       
   193 	
       
   194 	// Create the control group for HUI visual controls
       
   195 	CAlfControlGroup* group;
       
   196 	if( display->Roster().Count() > 0)
       
   197 		{
       
   198 		group = &( iAlfEnv.ControlGroup( KFMRadioVisualControlsGroupId ) );	
       
   199 		
       
   200 		iVisualControl = static_cast<CFMRadioAlfVisualizer*> 
       
   201 								( display->Roster().FindControl( KFMRadioVisualControlId ) );
       
   202 		iMediaIdle = static_cast<CFMRadioAlfMediaIdle*> 
       
   203 								( display->Roster().FindControl( KFMRadioMediaIdleId ) );
       
   204 		iRdsIndicator = static_cast<CFMRadioAlfIndicator*> 
       
   205 								( display->Roster().FindControl( KFMRadioRdsIndicatorId ) ); 		
       
   206 		iRdsAfIndicator = static_cast<CFMRadioAlfIndicator*> 
       
   207 								( display->Roster().FindControl( KFMRadioRdsAfIndicatorId ) );								
       
   208 		iRdsViewer = static_cast<CFMRadioAlfRDSViewer*> 
       
   209 								( display->Roster().FindControl( KFMRadioRdsViewer ) );
       
   210 		iRdsInteractionIndicator = static_cast<CFMRadioAlfIndicator*> 
       
   211 						        ( display->Roster().FindControl( KFMRadioRdsInteractionIndicatorId ) ); 								
       
   212 
       
   213         iRadioLogo = static_cast<CFMRadioLogo*> 
       
   214             ( display->Roster().FindControl( KFMRadioLogoId ) );
       
   215         }
       
   216 	else
       
   217 		{
       
   218 	    group = &(iAlfEnv.NewControlGroupL( KFMRadioVisualControlsGroupId ) );
       
   219 	    // Create the vizualizer control for information of the FMRadio
       
   220 	    iVisualControl = CFMRadioAlfVisualizer::NewL( iAlfEnv );
       
   221 	    iVisualControl->SetId( KFMRadioVisualControlId );
       
   222 	    // Create the media idle
       
   223 	    iMediaIdle = CFMRadioAlfMediaIdle::NewL( iAlfEnv );
       
   224 	    iMediaIdle->SetId( KFMRadioMediaIdleId );
       
   225 	    
       
   226 	    // RDS
       
   227 	    HBufC* rdsText = StringLoader::LoadLC( R_QTN_FMRADIO_RDS, iCoeEnv );
       
   228 	    iRdsIndicator = CFMRadioAlfIndicator::NewL( iAlfEnv );
       
   229 	    iRdsIndicator->SetId( KFMRadioRdsIndicatorId );
       
   230 	    iRdsIndicator->SetTextColor( color );
       
   231 	    iRdsIndicator->SetTextL( *rdsText );
       
   232 	    iRdsIndicator->SetOpacityInHiddenState( KFMRadioIndicatorOpacityInHiddenState );
       
   233 	    CleanupStack::PopAndDestroy( rdsText );
       
   234 	    
       
   235 	    // AF
       
   236 	    HBufC* afText = StringLoader::LoadLC( R_QTN_FMRADIO_AF, iCoeEnv );
       
   237 	    iRdsAfIndicator = CFMRadioAlfIndicator::NewL( iAlfEnv );
       
   238 	    iRdsAfIndicator->SetId( KFMRadioRdsAfIndicatorId );
       
   239 	    iRdsAfIndicator->SetTextColor( color );
       
   240 	    iRdsAfIndicator->SetTextL( *afText );
       
   241 	    iRdsAfIndicator->SetOpacityInHiddenState( KFMRadioIndicatorOpacityInHiddenState );
       
   242 	    CleanupStack::PopAndDestroy( afText );
       
   243 	    
       
   244 	    iRdsViewer = CFMRadioAlfRDSViewer::NewL( iAlfEnv );
       
   245 	    iRdsViewer->SetId( KFMRadioRdsViewer );
       
   246 	    iRdsViewer->SetTextColor( color );
       
   247 	    iRdsViewer->SetOpacityInHiddenState( KFMRadioRdsViewerOpacityHidden );
       
   248 	    
       
   249         // +
       
   250 	    HBufC* interactionText = StringLoader::LoadLC( R_QTN_FMRADIO_RTPLUS_INDICATOR_TEXT, iCoeEnv );
       
   251 	    iRdsInteractionIndicator = CFMRadioAlfIndicator::NewL( iAlfEnv );
       
   252         iRdsInteractionIndicator->SetId( KFMRadioRdsInteractionIndicatorId );
       
   253         iRdsInteractionIndicator->SetTextColor( color );
       
   254         iRdsInteractionIndicator->SetTextL( *interactionText );
       
   255         iRdsInteractionIndicator->SetOpacityInHiddenState( KFMRadioIndicatorOpacityInHiddenState );
       
   256         CleanupStack::PopAndDestroy( interactionText );
       
   257         
       
   258         // radio icon
       
   259         iRadioLogo = CFMRadioLogo::NewL( iAlfEnv );
       
   260         iRadioLogo->SetId( KFMRadioLogoId );
       
   261         
       
   262 	    // Append the controls into the control group.	    
       
   263 	    group->AppendL( iMediaIdle );
       
   264 	    group->AppendL( iVisualControl );
       
   265         group->AppendL( iRdsIndicator );
       
   266         group->AppendL( iRdsAfIndicator );
       
   267         group->AppendL( iRdsViewer );
       
   268         group->AppendL( iRdsInteractionIndicator );
       
   269         group->AppendL( iRadioLogo );
       
   270         }
       
   271 
       
   272     iIdleController = CFMRadioIdleController::NewL();
       
   273     // Add media idle visuals to the controller.
       
   274     // Only one of the media idle visuals is visible at a time.
       
   275     iIdleController->AddControlItem( *iRdsViewer );
       
   276     iIdleController->AddControlItem( *iMediaIdle );
       
   277     iIdleController->AddControlItem( *iRadioLogo );
       
   278 
       
   279     iMainPaneRect = aRect;
       
   280     
       
   281     UpdateTextColorFromSkin();
       
   282     SizeChanged();
       
   283     //Make the control group active on the display        
       
   284 	display->Roster().ShowL( *group );
       
   285 	display->SetClearBackgroundL( CAlfDisplay::EClearWithSkinBackground );		
       
   286     }
       
   287 
       
   288 // --------------------------------------------------------------------------------
       
   289 // CFMRadioMainContainer::Destructor
       
   290 // --------------------------------------------------------------------------------
       
   291 //
       
   292 CFMRadioMainContainer::~CFMRadioMainContainer()
       
   293     {
       
   294     if ( iTimer->IsActive() )
       
   295         {
       
   296         iTimer->Cancel();
       
   297         }
       
   298 
       
   299     delete iTimer;
       
   300     iTimer = NULL;
       
   301     timer.Close();
       
   302 
       
   303     delete iLight;
       
   304     iLight = NULL;
       
   305     delete iIdleController;
       
   306     }
       
   307 
       
   308 // --------------------------------------------------------------------------------
       
   309 // CFMRadioMainContainer::SetFaded
       
   310 // Fades the entire window and controls in the window owned
       
   311 // by this container control.
       
   312 // -------------------------------------------------------------------------------
       
   313 //
       
   314 void CFMRadioMainContainer::SetFaded( TBool aFaded )
       
   315     {
       
   316     iFadeStatus = aFaded;
       
   317     }
       
   318 
       
   319 // --------------------------------------------------------------------------------
       
   320 // CFMRadioMainContainer::DisplayChannelInfoL
       
   321 // Display the channel information
       
   322 // --------------------------------------------------------------------------------
       
   323 //
       
   324 void CFMRadioMainContainer::DisplayChannelInfoL(
       
   325         TInt aChannelNumber,
       
   326         const TDesC& aStationName,
       
   327         TFMRadioStationChangeType aChangeType,
       
   328         TInt aFrequency )
       
   329     {
       
   330     HBufC* firstLine = NULL;
       
   331     HBufC* secondLine = NULL;
       
   332     TBool programmeServiceNameExists = iRadioEngine.RdsReceiver().ProgrammeService().Length();
       
   333     CFMRadioRdsReceiverBase::TFMRadioProgrammeSeviceType PSNameType = 
       
   334         iRadioEngine.RdsReceiver().ProgrammeServiceNameType();
       
   335     
       
   336     TBool useStaticPsName = EFalse;
       
   337     if ( !aStationName.Length() && 
       
   338          PSNameType == CFMRadioRdsReceiverBase::EFMRadioPSNameStatic &&
       
   339          programmeServiceNameExists )
       
   340         {
       
   341         useStaticPsName = ETrue;
       
   342         }
       
   343     const TDesC& stationName = useStaticPsName ? iRadioEngine.RdsReceiver().ProgrammeService() : aStationName;
       
   344     
       
   345     if ( !stationName.Length() )
       
   346         {
       
   347         // PS Name is concidered as dynamic
       
   348         if( aChannelNumber == KErrNotFound )
       
   349             {
       
   350             firstLine = FormattedFrequencyStringL( aFrequency, R_QTN_FMRADIO_FREQ );
       
   351             CleanupStack::PushL( firstLine );
       
   352             if( programmeServiceNameExists )
       
   353                 {
       
   354                 secondLine = iRadioEngine.RdsReceiver().ProgrammeService().AllocL();
       
   355                 }
       
   356             }
       
   357         else
       
   358             {
       
   359             TReal frequency = static_cast<TReal>( aFrequency / static_cast<TReal>( KHzConversionFactor ));
       
   360     
       
   361             // Gets locale decimal separator automatically
       
   362             TInt maxDecimalPlaces = iRadioEngine.DecimalCount();
       
   363             TRealFormat format( KFrequencyMaxLength, maxDecimalPlaces );
       
   364             TBuf<KFrequencyMaxLength> frequencyString;
       
   365             frequencyString.Num( frequency, format );
       
   366             AknTextUtils::LanguageSpecificNumberConversion( frequencyString );
       
   367             
       
   368             firstLine = StringLoader::LoadLC( R_QTN_FMRADIO_MEM_LOCATION_FREQ,
       
   369                     frequencyString, aChannelNumber, iCoeEnv );
       
   370             
       
   371             if( programmeServiceNameExists )
       
   372                 {
       
   373                 secondLine = iRadioEngine.RdsReceiver().ProgrammeService().AllocL();
       
   374                 }
       
   375             }
       
   376         }
       
   377     else
       
   378         {
       
   379         if( aChannelNumber == KErrNotFound )
       
   380             {
       
   381             firstLine = stationName.AllocLC();
       
   382             }
       
   383         else
       
   384             {
       
   385             firstLine = StringLoader::LoadLC( R_QTN_FMRADIO_MEM_LOCATION_NAME,
       
   386                     stationName, aChannelNumber, iCoeEnv );
       
   387             }
       
   388         
       
   389         if ( programmeServiceNameExists &&
       
   390              PSNameType == CFMRadioRdsReceiverBase::EFMRadioPSNameDynamic )
       
   391             {
       
   392             // PS Name is concidered as dynamic
       
   393             secondLine = iRadioEngine.RdsReceiver().ProgrammeService().AllocL();
       
   394             }
       
   395         else
       
   396             {
       
   397             secondLine = FormattedFrequencyStringL( aFrequency, R_QTN_FMRADIO_FREQ );
       
   398             }
       
   399         }
       
   400     CleanupStack::PushL( secondLine );
       
   401     
       
   402     if( AknLayoutUtils::LayoutMirrored() )
       
   403         {
       
   404         // Add right to left mark in the beginning so that the text is laid out correctly
       
   405         firstLine = firstLine->ReAllocL( firstLine->Length() + KRightToLeftMark().Length() );
       
   406         CleanupStack::Pop( 2 ); // secondLine and old firstLine
       
   407         CleanupStack::PushL( firstLine );
       
   408         CleanupStack::PushL( secondLine );
       
   409         firstLine->Des().Insert( 0, KRightToLeftMark );
       
   410         
       
   411         if ( secondLine )
       
   412             {
       
   413             secondLine = secondLine->ReAllocL( secondLine->Length() + KRightToLeftMark().Length() );
       
   414             CleanupStack::Pop(); // old secondLine
       
   415             CleanupStack::PushL( secondLine );
       
   416             secondLine->Des().Insert( 0, KRightToLeftMark );
       
   417             }
       
   418         }
       
   419     
       
   420     iVisualControl->ChangeStationL( aChangeType, *firstLine, secondLine );
       
   421     
       
   422     HBufC* frequencyString = FormattedFrequencyStringL( aFrequency, R_QTN_FMRADIO_MEDIA_IDLE_FREQ );
       
   423     CleanupStack::PushL( frequencyString );
       
   424     iMediaIdle->AddMediaIdleContentL( *frequencyString );
       
   425     CleanupStack::PopAndDestroy( frequencyString );
       
   426     if( aStationName.Length() )
       
   427         {
       
   428         iMediaIdle->AddMediaIdleContentL( stationName );
       
   429         }
       
   430     if ( aStationName != iRadioEngine.RdsReceiver().ProgrammeService() &&
       
   431          PSNameType == CFMRadioRdsReceiverBase::EFMRadioPSNameStatic )
       
   432         {
       
   433         iMediaIdle->AddPsNameToMediaIdleL( iRadioEngine.RdsReceiver().ProgrammeService() );
       
   434         }
       
   435     
       
   436     CleanupStack::PopAndDestroy( 2, firstLine );
       
   437     }
       
   438 
       
   439 // --------------------------------------------------------------------------------
       
   440 // CFMRadioMainContainer::FormattedFrequencyStringL
       
   441 // Format the frequency
       
   442 // --------------------------------------------------------------------------------
       
   443 //
       
   444 HBufC* CFMRadioMainContainer::FormattedFrequencyStringL( TInt aFrequency, TInt aResourceId  )
       
   445     {
       
   446     TReal frequency = static_cast<TReal>( aFrequency / static_cast<TReal>( KHzConversionFactor ));
       
   447 
       
   448     // Gets locale decimal separator automatically
       
   449     TInt maxDecimalPlaces = iRadioEngine.DecimalCount();
       
   450     TRealFormat format( KFrequencyMaxLength, maxDecimalPlaces );
       
   451     TBuf<KFrequencyMaxLength> frequencyString;
       
   452     frequencyString.Num( frequency, format );
       
   453     AknTextUtils::LanguageSpecificNumberConversion( frequencyString );
       
   454     
       
   455     return StringLoader::LoadL( aResourceId, frequencyString, iCoeEnv );;
       
   456     }
       
   457 
       
   458 // --------------------------------------------------------------------------------
       
   459 // CFMRadioMainContainer::ShowRTPlusInteractionIndicator
       
   460 // Hide/show the RT+ interaction indicator with optional fade effecct
       
   461 // --------------------------------------------------------------------------------
       
   462 //
       
   463 void CFMRadioMainContainer::ShowRTPlusInteractionIndicator( TBool aVisible, TBool aFadeEffect)
       
   464     {
       
   465     if (aVisible)
       
   466         iRdsInteractionIndicator->Show( aFadeEffect );
       
   467     else
       
   468         iRdsInteractionIndicator->Hide( aFadeEffect );
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------
       
   472 // CFMRadioMainContainer::ShowRdsInfo
       
   473 // ---------------------------------------------------------
       
   474 //
       
   475 void CFMRadioMainContainer::ShowRdsInfo( TBool aShow, TBool aFade, TBool aShowAfMarquee )
       
   476     {    
       
   477     if( aShow )
       
   478     	{
       
   479     	iRdsIndicator->Show( aFade );
       
   480     	
       
   481     	if( aShowAfMarquee )
       
   482         	{
       
   483         	iRdsAfIndicator->Show( aFade );
       
   484         	}
       
   485     	else
       
   486     		{
       
   487     		iRdsAfIndicator->Hide( aFade ); 
       
   488     		}
       
   489     	}
       
   490     else
       
   491     	{
       
   492     	iRdsIndicator->Hide( aFade );
       
   493     	    	
       
   494     	iRdsAfIndicator->Hide( aFade ); 
       
   495     	}
       
   496     }
       
   497 
       
   498 // ----------------------------------------------------------------------------------------------------
       
   499 // CFMRadioMainContainer::HandleResourceChange
       
   500 // Handles resource changes
       
   501 // ----------------------------------------------------------------------------------------------------
       
   502 //
       
   503 void CFMRadioMainContainer::HandleResourceChange( TInt aType )
       
   504     {
       
   505 	if ( aType ==  KEikDynamicLayoutVariantSwitch )
       
   506 		{						
       
   507 		AknLayoutUtils::LayoutMetricsRect(
       
   508 		AknLayoutUtils::EMainPane, iMainPaneRect);
       
   509 		SizeChanged();
       
   510         TRAP_IGNORE( iAlfEnv.NotifyLayoutChangedL() )
       
   511         iIdleController->ShowControl( *iRadioLogo );
       
   512 		}
       
   513 	else if ( aType == KAknsMessageSkinChange  )
       
   514 	  	{
       
   515 	    UpdateTextColorFromSkin();
       
   516 	    TRAP_IGNORE( iAlfEnv.NotifySkinChangedL() );
       
   517 	    }
       
   518     }
       
   519 
       
   520 // --------------------------------------------------------------------------------
       
   521 // CFMRadioMainContainer::SetRect
       
   522 // Sets rectangle of the alfred display
       
   523 // --------------------------------------------------------------------------------
       
   524 //
       
   525 void CFMRadioMainContainer::SetRect( const TRect& aRect )
       
   526 	{
       
   527 	iMainPaneRect = aRect;
       
   528 	SizeChanged();
       
   529 	}
       
   530 
       
   531 // --------------------------------------------------------------------------------
       
   532 // CFMRadioMainContainer::SizeChanged
       
   533 // Called when the view size is changed
       
   534 // --------------------------------------------------------------------------------
       
   535 //
       
   536 void CFMRadioMainContainer::SizeChanged()
       
   537     {
       
   538     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
   539     
       
   540     iAlfEnv.PrimaryDisplay().ForceSetVisibleArea( iMainPaneRect ); 
       
   541     
       
   542     TAknLayoutRect layoutRect;
       
   543     TAknLayoutText textLayout;
       
   544     TAknLayoutRect indicatorLayoutRect;
       
   545     TAknLayoutRect visualPaneLayoutRect;
       
   546     
       
   547     TRect displayRect( iMainPaneRect.Size() );
       
   548     
       
   549     iVisualControl->SetMirrored( appUi->IsLayoutMirrored() );
       
   550     TBool isLandscape = appUi->IsLandscapeOrientation();
       
   551     
       
   552     TDisplayOrientation alfDisplayOrientation = EPortrait;
       
   553     CFMRadioAlfMediaIdle::TOrientation mediaIdleOrientation = CFMRadioAlfMediaIdle::EPortrait;
       
   554     
       
   555     TInt lafVarietyRdsIndicator = 0;
       
   556     TInt lafVarietyAfIndicator = 0;
       
   557     TInt lafVarietyPlusIndicator = 0;
       
   558     TInt lafVarietyRdsText = 0;
       
   559     TInt lafVarietyLogo = 0;
       
   560     TInt lafVarietyIndicatorPane = 0;
       
   561     TInt lafVarietyVisualPane = 0;
       
   562     TBool useLandscapeImage = EFalse;
       
   563     
       
   564     if ( isLandscape )
       
   565     	{
       
   566     	alfDisplayOrientation = ELandscape;
       
   567     	mediaIdleOrientation = CFMRadioAlfMediaIdle::ELandscape;
       
   568     	
       
   569     	lafVarietyRdsIndicator = KLAFVarietyRDSIndicatorLandscape;
       
   570     	lafVarietyAfIndicator = KLAFVarietyAFIndicatorLandscape;
       
   571     	lafVarietyPlusIndicator = KLAFVarietyRDSPlusIndicatorLandscape;
       
   572     	lafVarietyRdsText = KLAFVarietyRDSViewerLandscape;
       
   573         lafVarietyLogo = KLAFVarietyLogoImageLandscape;
       
   574         lafVarietyIndicatorPane = KLAFVarietyIndicatorPaneLandscape;
       
   575         lafVarietyVisualPane = KLAFVarietyVisualPaneLandscape;
       
   576         useLandscapeImage = ETrue;
       
   577         }
       
   578     else
       
   579     	{
       
   580     	lafVarietyRdsIndicator = KLAFVarietyRDSIndicatorPortrait;
       
   581     	lafVarietyAfIndicator = KLAFVarietyAFIndicatorPortrait;
       
   582         lafVarietyPlusIndicator = KLAFVarietyRDSPlusIndicatorPortrait;
       
   583         lafVarietyRdsText = KLAFVarietyRDSViewerPortrait;
       
   584         lafVarietyLogo = KLAFVarietyLogoImagePortrait;
       
   585         lafVarietyIndicatorPane = KLAFVarietyIndicatorPanePortrait;
       
   586         lafVarietyVisualPane = KLAFVarietyVisualPanePortrait;
       
   587         }
       
   588     // indicator pane
       
   589     indicatorLayoutRect.LayoutRect( displayRect,
       
   590                                     AknLayoutScalable_Apps::fmrd2_indi_pane( lafVarietyIndicatorPane ) );
       
   591     
       
   592     // RDS indicator
       
   593     textLayout.LayoutText( indicatorLayoutRect.Rect(),
       
   594             AknLayoutScalable_Apps::fmrd2_indi_pane_t3( lafVarietyRdsIndicator ).LayoutLine() );
       
   595             
       
   596     iRdsIndicator->SetRect( textLayout.TextRect() );
       
   597 	
       
   598     // AF indicator    
       
   599     textLayout.LayoutText( indicatorLayoutRect.Rect(),
       
   600             AknLayoutScalable_Apps::fmrd2_indi_pane_t2( lafVarietyAfIndicator ).LayoutLine() );
       
   601     
       
   602     iRdsAfIndicator->SetRect( textLayout.TextRect() );
       
   603     
       
   604     // + indicator
       
   605     textLayout.LayoutText( indicatorLayoutRect.Rect(),
       
   606             AknLayoutScalable_Apps::fmrd2_indi_pane_t1( lafVarietyPlusIndicator ).LayoutLine() );
       
   607     
       
   608     iRdsInteractionIndicator->SetRect( textLayout.TextRect() );
       
   609 
       
   610     // RDS Text pane      
       
   611     layoutRect.LayoutRect( displayRect,
       
   612             AknLayoutScalable_Apps::area_fmrd2_visual_pane( lafVarietyRdsText ).LayoutLine() );
       
   613     
       
   614     iRdsViewer->SetRect( layoutRect.Rect() );
       
   615     
       
   616     // radio icon    
       
   617     visualPaneLayoutRect.LayoutRect( displayRect,
       
   618             AknLayoutScalable_Apps::area_fmrd2_visual_pane( lafVarietyVisualPane ).LayoutLine() );
       
   619     
       
   620     layoutRect.LayoutRect( visualPaneLayoutRect.Rect(),
       
   621             AknLayoutScalable_Apps::area_fmrd2_visual_pane_g1( lafVarietyLogo ).LayoutLine() );
       
   622 
       
   623     // change image
       
   624     iRadioLogo->SwitchToLandscapeImage( useLandscapeImage );
       
   625     iRadioLogo->SetRect( layoutRect.Rect() );
       
   626     
       
   627     iVisualControl->SetOrientation( alfDisplayOrientation );
       
   628     iVisualControl->UpdateLayout( );
       
   629     iMediaIdle->SetOrientation( mediaIdleOrientation );
       
   630     iMediaIdle->UpdateLayout( );
       
   631     }
       
   632 
       
   633 // --------------------------------------------------------------------------------------------------
       
   634 // CFMRadioMainContainer::GetHelpContext
       
   635 // --------------------------------------------------------------------------------------------------
       
   636 //
       
   637 void CFMRadioMainContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   638     {
       
   639 #if defined __SERIES60_HELP || defined FF_S60_HELPS_IN_USE
       
   640     aContext.iMajor = TUid::Uid( KUidFMRadioApplication );
       
   641     aContext.iContext = KFMRADIO_HLP_MAIN;
       
   642 #endif
       
   643     }
       
   644 
       
   645 // --------------------------------------------------------------------------------
       
   646 // CFMRadioMainContainer::UpdateTextColorFromSkin
       
   647 // Handles updating main area text colors using current skin.
       
   648 // --------------------------------------------------------------------------------
       
   649 //
       
   650 void CFMRadioMainContainer::UpdateTextColorFromSkin()
       
   651     {
       
   652 	// Update text using skin color
       
   653     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   654    
       
   655     TRgb color( KRgbBlue );
       
   656     AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );  
       
   657        
       
   658     iVisualControl->SetStationInformationTextColor( color );  
       
   659                    
       
   660     iMediaIdle->SetPrimaryColor( color );     
       
   661     
       
   662     AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 );
       
   663     
       
   664     iMediaIdle->SetSecondaryColor( color );    
       
   665     }
       
   666 
       
   667 // ----------------------------------------------------------------------------------------------------
       
   668 // CFMRadioMainContainer::VisualControl
       
   669 // Returns a pointer to the station information visualizer
       
   670 // ----------------------------------------------------------------------------------------------------
       
   671 //
       
   672 CFMRadioAlfVisualizer* CFMRadioMainContainer::VisualControl()
       
   673 	{
       
   674 	return iVisualControl;
       
   675 	}
       
   676 
       
   677 // ----------------------------------------------------------------------------------------------------
       
   678 // CFMRadioMainContainer::MediaIdle
       
   679 // Returns a pointer to Media Idle
       
   680 // ----------------------------------------------------------------------------------------------------
       
   681 //
       
   682 CFMRadioAlfMediaIdle& CFMRadioMainContainer::MediaIdle()
       
   683     {
       
   684     return *iMediaIdle;
       
   685     }
       
   686 
       
   687 // ---------------------------------------------------------------------------
       
   688 // CFMRadioMainContainer::SetRdsRadioTextL
       
   689 // Updates the rds information.
       
   690 // ---------------------------------------------------------------------------
       
   691 //
       
   692 void CFMRadioMainContainer::SetRdsRadioTextL( const TDesC& aRadioText )
       
   693     {
       
   694     // Trim the text and check if there is actual content before showing it
       
   695     HBufC* text = aRadioText.AllocLC();
       
   696     text->Des().Trim();
       
   697     if ( text->Length() )
       
   698         {
       
   699         if ( iRdsViewer->SetTextL( *text ) )
       
   700             {
       
   701             iIdleController->ShowControl( *iRdsViewer );
       
   702             }
       
   703         }
       
   704     CleanupStack::PopAndDestroy( text );
       
   705     }
       
   706 
       
   707 // ----------------------------------------------------------------------------------------------------
       
   708 // TimerTimeOut
       
   709 // ----------------------------------------------------------------------------------------------------
       
   710 void CFMRadioMainContainer::TimerTimeOut( TInt aErrorStatus )
       
   711 	{
       
   712 	
       
   713 	if ( aErrorStatus == KErrNone && iLightsOffCounter < KFadeFrames )
       
   714 		{		
       
   715 		iAlfEnv.RefreshCallBack( &( iAlfEnv ) );
       
   716 		TTimeIntervalMicroSeconds32 time( KTenMilliSecondsInMicroSeconds );
       
   717 				
       
   718 		timer.After(iTimer->iStatus, time );
       
   719 			
       
   720 		iTimer->Activate();
       
   721 		
       
   722 		iLightsOffCounter++;
       
   723 					
       
   724 		}
       
   725 	else
       
   726 		{
       
   727 		timer.Cancel();
       
   728 		}
       
   729 	
       
   730 	}	
       
   731 
       
   732 // ---------------------------------------------------------------------------
       
   733 // CFMRadioAlfMediaIdle::LightStatusChangedL
       
   734 // From MHWRMLightObserver
       
   735 // Prepares media idle to handle new channel information
       
   736 // ---------------------------------------------------------------------------
       
   737 //	
       
   738 void CFMRadioMainContainer::LightStatusChanged(TInt aTarget, 
       
   739                                         CHWRMLight::TLightStatus aStatus)
       
   740 	{
       
   741     FTRACE( FPrint( _L("CFMRadioMainContainer::LightStatusChanged( Target: %d Lights: %d )"), aTarget, aStatus ) );
       
   742 	if ( CHWRMLight::ELightOff == aStatus && aTarget == 1 )
       
   743 		{
       
   744 		CAlfDisplay* display = NULL; 
       
   745 		
       
   746 	    if( iAlfEnv.DisplayCount() > 0 )
       
   747 	    	{	    	
       
   748 	    	display = &(iAlfEnv.PrimaryDisplay());
       
   749 
       
   750 	    	if ( display->Roster().Count() > 0 )
       
   751 				{
       
   752                 iIdleController->DeactivateControls();
       
   753 				
       
   754 
       
   755 				iAlfEnv.RefreshCallBack( &(iAlfEnv) );
       
   756 				
       
   757 				if ( !iTimer->IsActive() )
       
   758 					{			
       
   759 					TTimeIntervalMicroSeconds32 time( KTenMilliSecondsInMicroSeconds );
       
   760 					// Just to make sure, that dimming is really happening
       
   761 					iLightsOffCounter = 0;
       
   762 					timer.After(iTimer->iStatus, time );
       
   763 					iTimer->Activate();
       
   764 					}
       
   765 				}	
       
   766 	    	}
       
   767 	    }
       
   768 	else if (  CHWRMLight::ELightOn == aStatus && aTarget == 1 )
       
   769 		{
       
   770 		if ( iTimer )
       
   771 			{		
       
   772 			if ( iTimer->IsActive() )
       
   773 				{
       
   774 				iTimer->Cancel();
       
   775 				}
       
   776 			}
       
   777 			
       
   778 		if ( iLightsOffCounter != 0 )
       
   779             {
       
   780             CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
   781             CFMRadioMainView* mainView = static_cast<CFMRadioMainView*>( appUi->View( KFMRadioMainViewId ) );
       
   782             mainView->DetermineActiveMediaIdleComponent();
       
   783             
       
   784             iLightsOffCounter = 0;
       
   785             }
       
   786         }
       
   787     }
       
   788 
       
   789 // --------------------------------------------------------------------------------
       
   790 // CFMRadioMainContainer::RdsViewer
       
   791 // --------------------------------------------------------------------------------
       
   792 //
       
   793 CFMRadioAlfRDSViewer& CFMRadioMainContainer::RdsViewer() const
       
   794     {
       
   795     return *iRdsViewer;
       
   796     }
       
   797 
       
   798 // --------------------------------------------------------------------------------
       
   799 // CFMRadioMainContainer::IdleController
       
   800 // --------------------------------------------------------------------------------
       
   801 //
       
   802 CFMRadioIdleController& CFMRadioMainContainer::IdleController() const
       
   803     {
       
   804     return *iIdleController;
       
   805     }
       
   806 
       
   807 // --------------------------------------------------------------------------------
       
   808 // CFMRadioMainContainer::Logo
       
   809 // --------------------------------------------------------------------------------
       
   810 //
       
   811 CFMRadioLogo& CFMRadioMainContainer::Logo() const
       
   812     {
       
   813     return *iRadioLogo;
       
   814     }
       
   815 // End of File