internetradio2.0/uisrc/irradioidle.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     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: 
       
    15 *
       
    16 */
       
    17 /*
       
    18 * ============================================================================
       
    19 *  Name        : radioidle.cpp
       
    20 *  Part of     :
       
    21 *  Description :
       
    22 *  Version     :
       
    23 *
       
    24 * ==============================================================================
       
    25 */
       
    26 
       
    27 // INCLUDE FILES
       
    28 
       
    29 #include <eikenv.h>
       
    30 #include <stringloader.h>
       
    31 
       
    32 #include <alf/alfcontrolgroup.h>
       
    33 #include <alf/alfenv.h>
       
    34 #include <alf/alftextvisual.h>
       
    35 #include <alf/alfevent.h>
       
    36 #include <alf/alftransformation.h>
       
    37 #include <alf/alfgradientbrush.h>
       
    38 #include <alf/alfbrusharray.h>
       
    39 #include <alf/alfborderbrush.h>
       
    40 #include <alf/alfimagevisual.h>
       
    41 #include <alf/alfimagebrush.h>
       
    42 #include <alf/alftexturemanager.h>
       
    43 #include <alf/alfdisplay.h>
       
    44 #include <alf/alfviewportlayout.h>
       
    45 #include <alf/alfdecklayout.h>
       
    46 #include <alf/alfflowlayout.h>
       
    47 #include <alf/alfutil.h>
       
    48 #include <alf/alfTextStyle.h>
       
    49 #include <aknsitemid.h>
       
    50 
       
    51 #include <e32math.h>
       
    52 #include <data_caging_path_literals.hrh>
       
    53 #include "irradioidle.h"
       
    54 #include "irdebug.h"
       
    55 // CONSTANTS
       
    56 
       
    57 // bitmap file for the background of the display
       
    58 _LIT8( KRadioIdleAnchorTag, "radioIdleAnchor" );
       
    59 _LIT8( KRadioIdleFlowLayoutTag, "radioIdleFlowLayout" );
       
    60 _LIT8( KRadioIdleBackgroundTextTag, "radioIdleBackgroundText" );
       
    61 _LIT8( KRadioIdleItemTag, "radioIdleItem" );
       
    62 
       
    63 const TInt KSizeOfRadioIdleItemBigFont = 400; // background text
       
    64 const TInt KSizeOfRadioIdleItemMediumFont = 60;
       
    65 const TInt KSizeOfRadioIdleItemSmallFont = 30;
       
    66 
       
    67 const TInt KRadioIdleFadeOutDurationTime = 400;
       
    68 const TInt KRadioIdleFadeInDurationTime = 0; 
       
    69 
       
    70 const TInt  KRadioIdleBackgroundTextScrollInterval = 12000;
       
    71 const TReal32 KRadioIdleBackgroundTextOpacity = 0.2f;
       
    72 const TInt  KRadioIdleBackgroundTextSideToSideTransitionDurationTime = 25000;
       
    73 
       
    74 const TInt KMaxNumberOfRadioIdleItems = 5;
       
    75 
       
    76 const TReal32 KMaxRadioIdleItemsOverlap = 0.2f;
       
    77 const TInt KMaxRadioIdleItemScrollDurationTime = 35000;
       
    78 const TInt KMinRadioIdleItemScrollDurationTime = 25000;
       
    79 
       
    80 const TInt KModeChangingFactor = 3;
       
    81 
       
    82 const TReal32 KMaxOpacity = 0.7f;
       
    83 const TReal32 KMinOpacity = 0.3f;
       
    84 
       
    85 const TInt KMaxRadioIdleItemColorDeviation = 30; // must be <= 255
       
    86 const TRgb KRadioIdleItemDefaultColor(128,128,128);
       
    87 const TRgb KRadioIdleItemBackgroundColor(255, 255, 255);
       
    88 const TReal32 KRadioIdleItemBackgroundOpacity = 0.5f;
       
    89 const TReal32 KRadioIdleBackgroundOpacity = 0.4f;
       
    90 
       
    91 const TInt KRadioIdleItemArrayGranularity = 4;
       
    92 const TInt Kone=1;
       
    93 const TInt KTwoFiftyFive=255;
       
    94 const TInt KZero=0;
       
    95 const TInt KTen=10;
       
    96 const TInt KThousand=1000;
       
    97 //const TInt KThree=3
       
    98 
       
    99 // ============================ MEMBER FUNCTIONS ===============================
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CIRRadioIdle::NewL
       
   103 // Two-phase constructor of CIRRadioIdle
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 CIRRadioIdle* CIRRadioIdle::NewL( CAlfEnv& aEnv, TInt aControlGroupId, CAlfLayout* aParentLayout )
       
   107 	{
       
   108 	CIRRadioIdle* self = new (ELeave) CIRRadioIdle();
       
   109 	CleanupStack::PushL(self);
       
   110 	self->ConstructL( aEnv, aControlGroupId, aParentLayout );
       
   111 	CleanupStack::Pop(self);
       
   112 	return self;
       
   113 	}
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // CIRRadioIdle::CIRRadioIdle
       
   117 // Default constructor
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 CIRRadioIdle::CIRRadioIdle()
       
   121 :   iOrientation ( EOrientationNone ),
       
   122 	iFadeStyle( EFadeStyleNone ),
       
   123 	iRadioIdleState( EStopped ),
       
   124 	iRadioIdleMode( EBackgroundTextAndRadioIdleItems ),
       
   125 	iRadioIdleRequestedMode( EBackgroundTextAndRadioIdleItems ),
       
   126     iRadioIdlePrimaryColor(KRadioIdleItemDefaultColor),
       
   127     iRadioIdleSecondaryColor( KRadioIdleItemDefaultColor )
       
   128 	{
       
   129 	}
       
   130 
       
   131 // ----------------------------------------------------------------------------
       
   132 // CIRRadioIdle::ConstructL
       
   133 // Symbian 2nd phase constructor can leave.
       
   134 // ----------------------------------------------------------------------------
       
   135 //
       
   136 void CIRRadioIdle::ConstructL( CAlfEnv& aEnv, TInt aControlGroupId, CAlfLayout* aParentLayout )
       
   137 	{
       
   138 	CAlfControl::ConstructL( aEnv );
       
   139 
       
   140 	iParentLayout = aParentLayout;
       
   141 
       
   142     // Create largest font for the background text of radio idle
       
   143    	CAlfTextStyleManager& manager = Env().TextStyleManager();
       
   144 	iRadioIdleItemBackgroundTextStyleId = manager.CreatePlatformTextStyleL();
       
   145 	CAlfTextStyle* radioIdleItemStyle = manager.TextStyle( iRadioIdleItemBackgroundTextStyleId );
       
   146 	radioIdleItemStyle->SetTextSizeInPixels( KSizeOfRadioIdleItemBigFont, ETrue );
       
   147 
       
   148 	 // Create text styles for other radio idle items
       
   149     RArray<TInt> fontSizeArray;
       
   150     CleanupClosePushL( fontSizeArray );
       
   151     User::LeaveIfError( fontSizeArray.Append( KSizeOfRadioIdleItemMediumFont ) );
       
   152     User::LeaveIfError( fontSizeArray.Append( KSizeOfRadioIdleItemSmallFont ) );
       
   153     fontSizeArray.Sort();
       
   154 
       
   155 	TInt numberOfTextStyles = fontSizeArray.Count();
       
   156 	for( TInt i = 0; i < numberOfTextStyles; i++ )
       
   157 		{
       
   158 		TInt radioIdleItemTextStyleId = manager.CreatePlatformTextStyleL();
       
   159 		radioIdleItemStyle = manager.TextStyle( radioIdleItemTextStyleId );
       
   160 		radioIdleItemStyle->SetTextSizeInPixels( fontSizeArray[i], ETrue );
       
   161 		iTextStyleIdArray.Append( radioIdleItemTextStyleId );
       
   162 		}
       
   163 	CleanupStack::PopAndDestroy( &fontSizeArray );
       
   164 
       
   165 	aEnv.ControlGroup( aControlGroupId ).AppendL( this ); // Takes ownership.
       
   166 			// No leaving code allowed after this call.
       
   167   	}
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // ~CIRRadioIdle::~CIRRadioIdle
       
   171 // Destructor
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 CIRRadioIdle::~CIRRadioIdle()
       
   175 	{
       
   176 	Env().CancelCustomCommands( this );
       
   177 	if( iRadioIdleItemArray )
       
   178 		{
       
   179 		if( iRadioIdleItemArray->Count() > KZero )
       
   180 			{
       
   181 			iRadioIdleItemArray->Reset();
       
   182 			}
       
   183 		delete iRadioIdleItemArray;
       
   184 		}
       
   185 	CAlfTextStyleManager& manager = Env().TextStyleManager();
       
   186 	for( TInt i=0; i < iTextStyleIdArray.Count(); i++ )
       
   187 		{
       
   188 		manager.DeleteTextStyle( iTextStyleIdArray[i] );
       
   189 		}
       
   190 	iTextStyleIdArray.Close();
       
   191 	}
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 // CIRRadioIdle::AddRadioIdleL
       
   195 // Creates the radio idle with passed number of radio idle items
       
   196 // ----------------------------------------------------------------------------
       
   197 //
       
   198 void CIRRadioIdle::AddRadioIdleL( const TInt aNumberOfRadioIdleItems )
       
   199 	{
       
   200 
       
   201 	CAlfAnchorLayout* radioIdleAnchor = static_cast<CAlfAnchorLayout*>
       
   202 								 ( FindTag( KRadioIdleAnchorTag ) );
       
   203 	if ( !radioIdleAnchor )
       
   204 		{
       
   205 		radioIdleAnchor = CAlfAnchorLayout::AddNewL( *this, iParentLayout );
       
   206 		radioIdleAnchor->SetTagL( KRadioIdleAnchorTag );
       
   207 		}
       
   208 
       
   209 	if( !iViewport )
       
   210 		{
       
   211 		iViewport = CAlfViewportLayout::AddNewL( *this, radioIdleAnchor );
       
   212 		iViewport->SetViewportPos( TAlfRealPoint( .0f, .0f ), KZero );
       
   213 		iViewport->SetViewportSize( TAlfRealSize( 1.0f, 1.0f ), KZero );
       
   214 		}
       
   215 
       
   216 	CreateBacgroundTextVisualL();
       
   217 	// Create the flow layout for the other radio idle items
       
   218 	CAlfFlowLayout* radioIdleFlowLayout = static_cast<CAlfFlowLayout*> 
       
   219 		( iViewport->FindTag( KRadioIdleFlowLayoutTag ) );
       
   220 	if( !radioIdleFlowLayout )
       
   221 		{
       
   222 		radioIdleFlowLayout = CAlfFlowLayout::AddNewL( *this, iViewport );
       
   223 		radioIdleFlowLayout->SetTagL( KRadioIdleFlowLayoutTag );
       
   224 		radioIdleFlowLayout->SetFlowDirection( CAlfFlowLayout::EFlowVertical );
       
   225 		radioIdleFlowLayout->SetMode( CAlfFlowLayout::EModeCenterPerpendicular );
       
   226 		}
       
   227 
       
   228 	InitializeRadioIdleItemsL( aNumberOfRadioIdleItems );
       
   229 	AnimateRadioIdleItems();
       
   230 	UpdateLayout();
       
   231 	RadioIdleFadeIn();
       
   232 	}
       
   233 
       
   234 // ----------------------------------------------------------------------------
       
   235 // CRadioIdle::CreateBacgroundTextVisualL
       
   236 // Creates, initializes and animates the radio idle background text visual
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 void CIRRadioIdle::CreateBacgroundTextVisualL()
       
   240 	{
       
   241 	HBufC* itemText = GetRandomRadioIdleContentL();
       
   242 	CleanupStack::PushL( itemText );
       
   243     CAlfTextVisual* backgroundText = static_cast<CAlfTextVisual*> 
       
   244     	( iViewport->FindTag( KRadioIdleBackgroundTextTag ) );
       
   245 	if( !backgroundText && itemText )
       
   246 		{
       
   247 		backgroundText = AddRadioIdleItemL(iViewport, *itemText,KRadioIdleBackgroundTextTag, EFalse,
       
   248                             KRadioIdleItemBackgroundColor,
       
   249                             KRadioIdleItemBackgroundOpacity );
       
   250 
       
   251 		SetRadioIdleItemSettingsL( backgroundText, *itemText, iRadioIdleItemBackgroundTextStyleId );
       
   252         backgroundText->EnableBrushesL();
       
   253 	    backgroundText->EnableShadow( EFalse );
       
   254 	    backgroundText->SetFlag(  EAlfVisualFlagManualLayout  );
       
   255 		SetScrollingToBackgroundText( backgroundText,
       
   256                            KRadioIdleBackgroundTextSideToSideTransitionDurationTime,
       
   257                            ERadioIdleBackgroundTextScrollEnd );
       
   258 		backgroundText->SetOpacity( TAlfTimedValue( KRadioIdleBackgroundTextOpacity ) );
       
   259 		}
       
   260 	else if( itemText )
       
   261 		{
       
   262 		SetRadioIdleItemSettingsL( backgroundText, *itemText,
       
   263 			 iRadioIdleItemBackgroundTextStyleId );
       
   264         SetScrollingToBackgroundText( backgroundText, 
       
   265         	KRadioIdleBackgroundTextSideToSideTransitionDurationTime, 
       
   266         	ERadioIdleBackgroundTextScrollEnd );
       
   267         backgroundText->SetOpacity( TAlfTimedValue( KRadioIdleBackgroundTextOpacity ) );
       
   268         }
       
   269 	else
       
   270 		{
       
   271 		}	
       
   272 	CleanupStack::PopAndDestroy( itemText );
       
   273 	}
       
   274 
       
   275 // ----------------------------------------------------------------------------
       
   276 // CIRRadioIdle::InitializeRadioIdleItemsL
       
   277 // Initializes the radio idle items
       
   278 // ----------------------------------------------------------------------------
       
   279 //
       
   280 void CIRRadioIdle::InitializeRadioIdleItemsL( const TInt aNumberOfRadioIdleItems )
       
   281 	{
       
   282 
       
   283 	CAlfFlowLayout* radioIdleFlowLayout = static_cast<CAlfFlowLayout*> 
       
   284 						( iViewport->FindTag( KRadioIdleFlowLayoutTag ) );
       
   285 	if( radioIdleFlowLayout )
       
   286 		{
       
   287 		// Create the radio idle items
       
   288 		for( TInt i = 0; i < aNumberOfRadioIdleItems; i++ )
       
   289 			{
       
   290 			HBufC* itemText = GetRandomRadioIdleContentL();
       
   291 			if( itemText )
       
   292 				{
       
   293 				CleanupStack::PushL( itemText );
       
   294 				TInt randFontStyleIx = AlfUtil::RandomInt( KZero,
       
   295 				  iTextStyleIdArray.Count() - Kone );
       
   296 			    CAlfTextVisual* radioIdleItem = NULL;
       
   297 			    if( radioIdleFlowLayout->Count() < aNumberOfRadioIdleItems )
       
   298 					{
       
   299                     radioIdleItem  = AddRadioIdleItemL( radioIdleFlowLayout,
       
   300                     	 *itemText, KRadioIdleItemTag,EFalse, 
       
   301                     	 KRadioIdleItemBackgroundColor, KRadioIdleItemBackgroundOpacity );
       
   302 					}
       
   303 			    else
       
   304 			    	{
       
   305 			    	/*lint -save -e826 (Info -- Suspicious pointer-to-pointer conversion (area too small)*/
       
   306 			    	radioIdleItem = static_cast<CAlfTextVisual*> 
       
   307 			    			( GetPointer( radioIdleFlowLayout->Visual( i ) ) );
       
   308 			    	/*lint -restore*/
       
   309 			    	radioIdleItem->SetOpacity( TAlfTimedValue( .0f ) );
       
   310 					radioIdleItem->EnableTransformationL( ETrue );
       
   311 					CAlfTransformation* radioIdleItemTransformation =
       
   312 									 &( radioIdleItem->Transformation() );
       
   313 					radioIdleItemTransformation->LoadIdentity();
       
   314 			    	}
       
   315 			    SetRadioIdleItemSettingsL( radioIdleItem, *itemText, 
       
   316 			    		iTextStyleIdArray[ randFontStyleIx ] );
       
   317 			 	CleanupStack::PopAndDestroy( itemText );
       
   318 				}
       
   319 			}
       
   320 		}
       
   321 
       
   322 
       
   323 	}
       
   324 
       
   325 // ----------------------------------------------------------------------------
       
   326 // CIRRadioIdle::AnimateRadioIdleItems
       
   327 // Sets defined animation to the created radio idle items
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 void CIRRadioIdle::AnimateRadioIdleItems()
       
   331 	{
       
   332 
       
   333 	CAlfFlowLayout* radioIdleFlowLayout = static_cast<CAlfFlowLayout*> 
       
   334 				( iViewport->FindTag( KRadioIdleFlowLayoutTag ) );
       
   335 	if( radioIdleFlowLayout )
       
   336 		{
       
   337 		for( TInt i = 0; i < radioIdleFlowLayout->Count(); i++ )
       
   338 			{
       
   339 	    	/*lint -save -e826 (Info -- Suspicious pointer-to-pointer conversion (area too small)*/
       
   340 		    CAlfTextVisual* radioIdleItem = static_cast<CAlfTextVisual*> 
       
   341 		    	( GetPointer( radioIdleFlowLayout->Visual( i ) ) );
       
   342 		    /*lint -restore*/
       
   343 			 SetRadioIdleItemAnimation( radioIdleItem );
       
   344 			}
       
   345 		}
       
   346 
       
   347 	}
       
   348 
       
   349 // ----------------------------------------------------------------------------
       
   350 // CIRRadioIdle::AddRadioIdleItemL
       
   351 // Creates the radio idle item to the passed radio idle view port.
       
   352 // ----------------------------------------------------------------------------
       
   353 //
       
   354 CAlfTextVisual* CIRRadioIdle::AddRadioIdleItemL( CAlfLayout* aRadioIdle, 
       
   355 					const TDesC& aRadioIdleItemText, 
       
   356 					const TDesC8& aTag, TBool aRadioIdleItemHasBackground,
       
   357 					const TRgb& aBackgroundColor,
       
   358 					const TReal32 aBackgroundOpacity )
       
   359 	{
       
   360 
       
   361 	CAlfTextVisual* radioIdleItem = CAlfTextVisual::AddNewL( *this, aRadioIdle );
       
   362 	// Set text to transparent during initialization
       
   363 	radioIdleItem->SetOpacity( TAlfTimedValue( .0f ) );
       
   364     radioIdleItem->EnableBrushesL();
       
   365     radioIdleItem->SetTextL( aRadioIdleItemText );
       
   366     radioIdleItem->SetTagL( aTag );
       
   367     radioIdleItem->EnableShadow( EFalse );
       
   368     radioIdleItem->SetAlign( EAlfAlignHCenter, EAlfAlignVCenter );
       
   369     radioIdleItem->SetSize( radioIdleItem->TextExtents() );
       
   370 
       
   371     if ( aRadioIdleItemHasBackground )
       
   372 	    {
       
   373 		CAlfGradientBrush* gradientBrush = CAlfGradientBrush::NewLC( Env() );
       
   374 		gradientBrush->SetColor( aBackgroundColor, aBackgroundOpacity );
       
   375 		radioIdleItem->Brushes()->AppendL( gradientBrush, EAlfHasOwnership );
       
   376 		CleanupStack::Pop( gradientBrush );
       
   377 	    }
       
   378 	return radioIdleItem;
       
   379 
       
   380 	}
       
   381 // ----------------------------------------------------------------------------
       
   382 // CIRRadioIdle::DeviateColorComponent
       
   383 // Randomly modifies the value of a color component.
       
   384 // ----------------------------------------------------------------------------
       
   385 //
       
   386 TInt CIRRadioIdle::DeviateColorComponent( TInt aBaseValue )
       
   387     {
       
   388     TInt deviatedValue = aBaseValue
       
   389                        + AlfUtil::RandomInt( 0, KMaxRadioIdleItemColorDeviation )
       
   390                        - AlfUtil::RandomInt( 0, KMaxRadioIdleItemColorDeviation );
       
   391 
       
   392     if( deviatedValue < 0)
       
   393         {
       
   394         deviatedValue = 0;
       
   395         }
       
   396     else if( deviatedValue > KTwoFiftyFive )
       
   397         {
       
   398         deviatedValue = KTwoFiftyFive;
       
   399         }
       
   400     
       
   401     return deviatedValue;
       
   402     }
       
   403 
       
   404 // ----------------------------------------------------------------------------
       
   405 // CIRRadioIdle::SetRadioIdleItemSettings
       
   406 // Sets color, opacity and scaling settings to the radio idle item
       
   407 // ----------------------------------------------------------------------------
       
   408 //
       
   409 void CIRRadioIdle::SetRadioIdleItemSettingsL( CAlfTextVisual* aRadioIdleItem, 
       
   410 											const TDesC& aRadioIdleItemText,
       
   411 											  const TInt aTextStyleId )
       
   412 	{
       
   413 	// Set text of the radio idle item
       
   414 	aRadioIdleItem->SetTextL( aRadioIdleItemText );
       
   415 	// Set text to transparent during initialization
       
   416 	aRadioIdleItem->SetOpacity( TAlfTimedValue( .0f ) );
       
   417 	aRadioIdleItem->EnableTransformationL( ETrue );
       
   418 	CAlfTransformation* radioIdleItemTransformation = &( aRadioIdleItem->Transformation() );
       
   419 	radioIdleItemTransformation->LoadIdentity();
       
   420     
       
   421     // Select base color for text
       
   422 
       
   423     TRgb radioIdleItemColor( iRadioIdlePrimaryColor );
       
   424     if( AlfUtil::RandomInt(0, 1) == 0 )
       
   425         {
       
   426         radioIdleItemColor = iRadioIdleSecondaryColor;
       
   427         }
       
   428     
       
   429     // Modify the color
       
   430     radioIdleItemColor.SetRed( DeviateColorComponent( radioIdleItemColor.Red() ) );
       
   431     radioIdleItemColor.SetGreen( DeviateColorComponent( radioIdleItemColor.Green() ) );
       
   432     radioIdleItemColor.SetBlue( DeviateColorComponent( radioIdleItemColor.Blue() ) );
       
   433 
       
   434 	// Set text color of the radio idle item
       
   435 	aRadioIdleItem->SetColor( radioIdleItemColor );
       
   436 	// Set text style of the radio idle	item
       
   437 	aRadioIdleItem->SetTextStyle( aTextStyleId );
       
   438 
       
   439 	TSize itemSize( 0, 0 );
       
   440 	if ( aRadioIdleItem->TextExtents() != itemSize )
       
   441 		{
       
   442 		aRadioIdleItem->SetSize( aRadioIdleItem->TextExtents() );
       
   443 		}
       
   444 	}
       
   445 
       
   446 // ----------------------------------------------------------------------------
       
   447 // CIRRadioIdle::SetRadioIdleItemAnimation
       
   448 // Sets translating animations to the radio idle item
       
   449 // ----------------------------------------------------------------------------
       
   450 //
       
   451 void CIRRadioIdle::SetRadioIdleItemAnimation( CAlfTextVisual* aRadioIdleItem )
       
   452 	{
       
   453 
       
   454 	CAlfFlowLayout* radioIdleFlowLayout = static_cast<CAlfFlowLayout*> 
       
   455 										( aRadioIdleItem->Layout() );
       
   456 	TInt radioIdleItemCount = radioIdleFlowLayout->Count();
       
   457 	TInt radioIdleItemIndex = radioIdleFlowLayout->FindVisual( aRadioIdleItem );
       
   458 
       
   459 	TReal32 radioIdleItemWidth = aRadioIdleItem->DisplayRect().Width();
       
   460 	TReal32 radioIdleItemHeight = aRadioIdleItem->DisplayRect().Height();
       
   461 	TReal32 radioIdleWidth = radioIdleFlowLayout->Size().Target().iX;
       
   462 
       
   463 	TInt randomTranslateDuration = AlfUtil::RandomInt( KMinRadioIdleItemScrollDurationTime,
       
   464 									 KMaxRadioIdleItemScrollDurationTime );
       
   465 
       
   466 	// Calculate y position of the radio idle item
       
   467 	TReal32 randomMeanDeviationY = 0;
       
   468 	if(radioIdleItemIndex != 0 && radioIdleItemIndex != radioIdleItemCount - Kone )
       
   469 		{
       
   470 		randomMeanDeviationY = AlfUtil::RandomReal( 0.0f,  radioIdleItemHeight * 
       
   471 															KMaxRadioIdleItemsOverlap );
       
   472 		TInt deviationDirection = AlfUtil::RandomInt( KZero,  Kone );
       
   473 		if( deviationDirection )
       
   474 		 	{
       
   475 		 	randomMeanDeviationY = -randomMeanDeviationY;
       
   476 		 	}
       
   477 		}
       
   478 
       
   479 	TInt scrollDirection = AlfUtil::RandomInt( KZero,  Kone );
       
   480 	TAlfTimedValue targetPositionX;
       
   481 	if( scrollDirection )
       
   482 		{
       
   483 		targetPositionX.SetValueNow( -radioIdleWidth/2 - radioIdleItemWidth/2 );
       
   484 		targetPositionX.SetTarget( radioIdleWidth/2 + radioIdleItemWidth/2,
       
   485 								 randomTranslateDuration );
       
   486 		}
       
   487 	else
       
   488 		{
       
   489 		targetPositionX.SetValueNow( radioIdleWidth/2 + radioIdleItemWidth/2  );
       
   490 		targetPositionX.SetTarget( -radioIdleWidth/2 - radioIdleItemWidth/2,
       
   491 													 randomTranslateDuration );
       
   492 		}
       
   493 	Translate( aRadioIdleItem, targetPositionX, TAlfTimedValue( randomMeanDeviationY ) );
       
   494 	if( radioIdleItemIndex >= KZero )
       
   495 		{
       
   496 		Env().Send( TAlfCustomEventCommand( ERadioIdleItemTransformationEnd,
       
   497 											this,
       
   498 											radioIdleItemIndex ),
       
   499 											randomTranslateDuration );
       
   500 		}
       
   501 	// Set text opacity of the radio idle item
       
   502 	TReal32 randomOpacity = AlfUtil::RandomReal( KMinOpacity, KMaxOpacity );
       
   503 	aRadioIdleItem->SetOpacity( TAlfTimedValue( randomOpacity ) );
       
   504 	radioIdleFlowLayout->UpdateChildrenLayout( KMinRadioIdleItemScrollDurationTime );
       
   505 
       
   506 
       
   507 	}
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 // CIRRadioIdle::RadioIdleFadeIn
       
   511 // Fades in radio idle
       
   512 // ---------------------------------------------------------------------------
       
   513 //
       
   514 void CIRRadioIdle::RadioIdleFadeIn( TBool aNow )
       
   515 	{
       
   516 
       
   517 	if ( iViewport )
       
   518 		{
       
   519 		if( aNow )
       
   520 			{
       
   521 			FadeIn( iViewport, KZero );
       
   522 			}
       
   523 		else
       
   524 			{
       
   525 			FadeIn( iViewport, KRadioIdleFadeInDurationTime );
       
   526 			}
       
   527 		}
       
   528 
       
   529 	}
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // CIRRadioIdle::RadioIdleFadeOut
       
   533 // Fades out radio idle
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 void CIRRadioIdle::RadioIdleFadeOut( TBool aNow )
       
   537 	{
       
   538 	
       
   539 
       
   540 	if ( iViewport )
       
   541 		{
       
   542 		iFading = ETrue;
       
   543 		if( aNow )
       
   544 			{
       
   545 			FadeOut( iViewport, KZero );
       
   546 			iFading = EFalse;
       
   547 			}
       
   548 		else if ( iFadeStyle == EFadeStyleNone )
       
   549 			{
       
   550 			FadeOut( iViewport, KRadioIdleFadeOutDurationTime );
       
   551 	        Env().Send( TAlfCustomEventCommand( ERadioIdleFadeOutCompleted, this,
       
   552 												reinterpret_cast<TInt>( iViewport ) ),
       
   553 												KRadioIdleFadeOutDurationTime );
       
   554 	        iViewport = NULL;
       
   555 			}
       
   556 		else
       
   557 			{
       
   558 		    TAlfTimedPoint point( 0.0f, 0.0f );
       
   559 		    point.SetStyle( EAlfTimedValueStyleDecelerate );
       
   560 
       
   561 		    TAlfRealPoint size = iViewport->Size().ValueNow();
       
   562 		    TAlfRealPoint pos = iViewport->Pos().ValueNow();
       
   563 
       
   564 		    point = TAlfTimedPoint( pos.iX, pos.iY );
       
   565 
       
   566 		    TAlfRealPoint target = iViewport->Pos().Target();
       
   567 
       
   568 		    switch ( iFadeStyle )
       
   569 		        {
       
   570 		        case EFadeRight: // Fade left to right
       
   571 		            point.SetTarget( TAlfRealPoint( target.iX + size.iX, target.iY ),
       
   572 		            						 KRadioIdleFadeOutDurationTime );
       
   573 		            break;
       
   574 		        case EFadeLeft: // Fade right to left
       
   575 		            point.SetTarget( TAlfRealPoint( target.iX - size.iX, target.iY ),
       
   576 		            			 KRadioIdleFadeOutDurationTime );
       
   577 		            break;
       
   578 		        default:
       
   579 		            break;
       
   580 		        }
       
   581 
       
   582 		    // Fade the radio idle out.
       
   583 		    TAlfTimedValue opacity( iViewport->Opacity().ValueNow() );
       
   584 		    opacity.SetStyle( EAlfTimedValueStyleAccelerate );
       
   585 		    opacity.SetTarget( 0.0f, KRadioIdleFadeOutDurationTime );
       
   586 
       
   587 		    iViewport->SetFlag( EAlfVisualFlagManualPosition );
       
   588 		    iViewport->SetPos( point );
       
   589 		    iViewport->SetOpacity( opacity );
       
   590 
       
   591 		    iFadeStyle = EFadeStyleNone;
       
   592 
       
   593 	        Env().Send( TAlfCustomEventCommand( ERadioIdleFadeOutCompleted, this,
       
   594 												reinterpret_cast<TInt>( iViewport ) ),
       
   595 												KRadioIdleFadeOutDurationTime );
       
   596 	        iViewport = NULL;
       
   597 	        ResetRadioIdleContent();
       
   598 			}
       
   599 		}
       
   600 
       
   601 	}
       
   602 
       
   603 // ---------------------------------------------------------------------------
       
   604 // CIRRadioIdle::StartRadioIdle
       
   605 // Launches radio idle.
       
   606 // ---------------------------------------------------------------------------
       
   607 //
       
   608 void CIRRadioIdle::StartRadioIdleL()
       
   609     {
       
   610     if( iRadioIdleState == EStopped || iRadioIdleState == ESuspended )
       
   611 	    {
       
   612 		Env().CancelCustomCommands( this );
       
   613 	    AddRadioIdleL( KMaxNumberOfRadioIdleItems );
       
   614 	    }
       
   615     iRadioIdleState = ERunning;
       
   616     iDelayedStartup = EFalse;
       
   617     
       
   618     }
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // CIRRadioIdle::SuspendRadioIdle
       
   622 // Suspends radio idle and starts it again after startup delay
       
   623 // ---------------------------------------------------------------------------
       
   624 //
       
   625 void CIRRadioIdle::SuspendRadioIdle()
       
   626     {
       
   627     Env().CancelCustomCommands( this );
       
   628     if( iRadioIdleState == ERunning )
       
   629 	    {
       
   630 	    RadioIdleFadeOut( ETrue );
       
   631 	    }
       
   632     iRadioIdleState = ESuspended;
       
   633     iFading = EFalse;
       
   634     }
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // CIRRadioIdle::ShutdownRadioIdle
       
   638 // Stops radio idle. Radio idle is set to stopped state.
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 void CIRRadioIdle::ShutdownRadioIdle()
       
   642     {
       
   643 
       
   644     Env().CancelCustomCommands( this );
       
   645     if( iRadioIdleState == ERunning )
       
   646 	    {
       
   647 	    RadioIdleFadeOut();
       
   648 	    }
       
   649     iRadioIdleState = EStopped;
       
   650     iFading = EFalse;
       
   651     }
       
   652 
       
   653 // ----------------------------------------------------------------------------
       
   654 // CIRRadioIdle::AddRadioIdleContentL
       
   655 // Adds radio idle item text to be used in the radio idle
       
   656 // ----------------------------------------------------------------------------
       
   657 //
       
   658 TInt CIRRadioIdle::AddRadioIdleContentL( const TDesC& aRadioIdleItemText )
       
   659 	{
       
   660 	if( !iRadioIdleItemArray )
       
   661 		{
       
   662 		// Array for radio idle items
       
   663     	iRadioIdleItemArray = new( ELeave ) CDesCArrayFlat( KRadioIdleItemArrayGranularity );
       
   664 		}
       
   665 	iRadioIdleItemArray->AppendL( aRadioIdleItemText );
       
   666 	return iRadioIdleItemArray->Count() - Kone;
       
   667 
       
   668 	}
       
   669 
       
   670 // ----------------------------------------------------------------------------
       
   671 // CIRRadioIdle::UpdateRadioIdleContent
       
   672 // Updates radio idle item text in specified index.
       
   673 // Note that the index of a particular radio idle item text is defined by
       
   674 // the order in which it has been added by AddRadioIdleContentL.
       
   675 // ----------------------------------------------------------------------------
       
   676 //
       
   677 void CIRRadioIdle::UpdateRadioIdleContent( const TDesC& aRadioIdleItemText, TInt aIndex )
       
   678 	{
       
   679 
       
   680 	if( aIndex >= 0 && aIndex < iRadioIdleItemArray->MdcaCount() )
       
   681 		{
       
   682 		TPtrC itemContent( iRadioIdleItemArray->MdcaPoint( aIndex ) );
       
   683 		if ( itemContent.Length() )
       
   684 			{ 
       
   685 			iRadioIdleItemArray->Delete( aIndex );
       
   686 			}
       
   687 		
       
   688 		TRAP_IGNORE( iRadioIdleItemArray->InsertL( aIndex, aRadioIdleItemText ) )
       
   689 		}
       
   690 
       
   691 	}
       
   692 
       
   693 // ----------------------------------------------------------------------------
       
   694 // CIRRadioIdle::GetRandomRadioIdleContentL
       
   695 // Retrieves text from randomly chousen radio idle item
       
   696 // ----------------------------------------------------------------------------
       
   697 //
       
   698 HBufC* CIRRadioIdle::GetRandomRadioIdleContentL()
       
   699 	{
       
   700 
       
   701 	if( !iRadioIdleItemArray )
       
   702 		{
       
   703 		return NULL;
       
   704 		}
       
   705 	TInt count = iRadioIdleItemArray->MdcaCount();
       
   706 	if( count > KZero )
       
   707     	{
       
   708     	// Try to find a non-empty radio idle item from the array
       
   709 		TInt radioIdleItemIndex;
       
   710     	for ( TInt i = 0; i < KTen*count; i++ )
       
   711     		{
       
   712     		radioIdleItemIndex = AlfUtil::RandomInt( KZero, count - Kone );
       
   713     		TPtrC itemContent( iRadioIdleItemArray->MdcaPoint( radioIdleItemIndex ) );
       
   714     		// Check if there really is some content
       
   715     		if ( itemContent.Length() )
       
   716     			{
       
   717     			return itemContent.AllocL();
       
   718     			}
       
   719     		}
       
   720     	}
       
   721    	return NULL;
       
   722 
       
   723 	}
       
   724 
       
   725 // ----------------------------------------------------------------------------
       
   726 // CIRRadioIdle::ResetRadioIdleContent
       
   727 // Removes all radio idle item texts
       
   728 // ----------------------------------------------------------------------------
       
   729 //
       
   730 void  CIRRadioIdle::ResetRadioIdleContent()
       
   731 	{
       
   732 	if( iRadioIdleItemArray )
       
   733 		{
       
   734 		if( iRadioIdleItemArray->Count() > KZero )
       
   735 			{
       
   736 			iRadioIdleItemArray->Reset();
       
   737 			iRadioIdleItemArray->Compress();
       
   738 			}
       
   739 		}
       
   740 
       
   741 	}
       
   742 
       
   743 // ----------------------------------------------------------------------------
       
   744 // CIRRadioIdle::RadioIdleContentCount
       
   745 // Returns number of radio idle content items
       
   746 // ----------------------------------------------------------------------------
       
   747 //
       
   748 TInt CIRRadioIdle::RadioIdleContentCount() const
       
   749 	{
       
   750 
       
   751 	if( iRadioIdleItemArray )
       
   752 		{
       
   753 		return iRadioIdleItemArray->Count();
       
   754 		}
       
   755 	else
       
   756 		{
       
   757 		return KZero;
       
   758 		}
       
   759 
       
   760 	}
       
   761 
       
   762 // ----------------------------------------------------------------------------
       
   763 // CIRRadioIdle::SetPrimaryColor
       
   764 // Sets primary color for the radio idle
       
   765 // ----------------------------------------------------------------------------
       
   766 //
       
   767 void CIRRadioIdle::SetPrimaryColor( TRgb aColor )
       
   768 	{
       
   769 	iRadioIdlePrimaryColor = aColor;
       
   770 	}
       
   771 
       
   772 // ----------------------------------------------------------------------------
       
   773 // CIRRadioIdle::SetSecondaryColor
       
   774 // Sets secondary color for the radio idle
       
   775 // ----------------------------------------------------------------------------
       
   776 //
       
   777 void CIRRadioIdle::SetSecondaryColor( TRgb aColor )
       
   778 	{
       
   779 	iRadioIdleSecondaryColor = aColor;
       
   780 	}
       
   781 
       
   782 // ----------------------------------------------------------------------------
       
   783 // CIRRadioIdle::SetBackgroundColor
       
   784 // Sets the background color of the radio idle
       
   785 // ----------------------------------------------------------------------------
       
   786 //
       
   787 void CIRRadioIdle::SetBackgroundColor( TRgb aColor )
       
   788 	{
       
   789 	iRadioIdleBackgroundColor = aColor;
       
   790 	if( iRadioIdleBackgroundGradientBrush )
       
   791 		{
       
   792 		iRadioIdleBackgroundGradientBrush->SetColor( aColor, KRadioIdleBackgroundOpacity );
       
   793 		}
       
   794 	}
       
   795 
       
   796 // ----------------------------------------------------------------------------
       
   797 // CIRRadioIdle::Translate
       
   798 // Translates the visual object with passed arguments
       
   799 // ----------------------------------------------------------------------------
       
   800 //
       
   801 void CIRRadioIdle::Translate( CAlfTextVisual* aTextVisual, const TAlfTimedValue& aX, 
       
   802 															const TAlfTimedValue& aY )
       
   803 	{
       
   804 	if( aTextVisual )
       
   805 		{
       
   806 		TRAPD( err, aTextVisual->EnableTransformationL( ETrue ) );
       
   807 		if( err == KErrNone )
       
   808 			{
       
   809 			CAlfTransformation* visualTransformation = &( aTextVisual->Transformation() );
       
   810 			TAlfTimedValue x(aX);
       
   811 			x.SetStyle( EAlfTimedValueStyleLinear );
       
   812 
       
   813 			TAlfTimedValue y(aY);
       
   814 			y.SetStyle( EAlfTimedValueStyleLinear );
       
   815 
       
   816 			visualTransformation->Translate( x, y );
       
   817 			}
       
   818 		}
       
   819 	}
       
   820 
       
   821 // ----------------------------------------------------------------------------
       
   822 // CIRRadioIdle::Scale
       
   823 // Scales the visual object with passed arguments
       
   824 // ----------------------------------------------------------------------------
       
   825 //
       
   826 void CIRRadioIdle::Scale( CAlfTextVisual* aTextVisual, const TAlfTimedValue& aX, 
       
   827 												const TAlfTimedValue& aY )
       
   828 	{
       
   829 	if( aTextVisual )
       
   830 		{
       
   831 		TRAPD( err, aTextVisual->EnableTransformationL( ETrue ) );
       
   832 		if( err == KErrNone )
       
   833 			{
       
   834 			CAlfTransformation* visualTransformation = &( aTextVisual->Transformation() );
       
   835 			visualTransformation->Scale( aX, aY );
       
   836 			}
       
   837 		}
       
   838 	}
       
   839 
       
   840 // ----------------------------------------------------------------------------
       
   841 // CIRRadioIdle::LoadTextVisualIdentity
       
   842 // Removes all transformations of the visual object such as the scaling and translating.
       
   843 // ----------------------------------------------------------------------------
       
   844 //
       
   845 void CIRRadioIdle::LoadTextVisualIdentity( CAlfTextVisual* aTextVisual )
       
   846 	{
       
   847 	if( aTextVisual )
       
   848 		{
       
   849 		TRAPD( err, aTextVisual->EnableTransformationL( ETrue ) );
       
   850 		if( err == KErrNone )
       
   851 			{
       
   852 			CAlfTransformation* visualTransformation = &( aTextVisual->Transformation() );
       
   853 			visualTransformation->LoadIdentity();
       
   854 			}
       
   855 		}
       
   856 	}
       
   857 
       
   858 // ----------------------------------------------------------------------------
       
   859 // CIRRadioIdle::UpdateLayout
       
   860 // Calculates display layout
       
   861 // ----------------------------------------------------------------------------
       
   862 //
       
   863 void CIRRadioIdle::UpdateLayout()
       
   864 	{
       
   865 	CAlfVisual* visual = FindTag( KRadioIdleAnchorTag );
       
   866 	if( visual )
       
   867 		{
       
   868 		CAlfAnchorLayout* radioIdleAnchor = static_cast<CAlfAnchorLayout*>( visual );
       
   869 		radioIdleAnchor->UpdateChildrenLayout( );
       
   870 		}
       
   871 	}
       
   872 
       
   873 // ----------------------------------------------------------------------------
       
   874 // CIRRadioIdle::Refresh
       
   875 // Starts radio idle again without reseting radio idle items.
       
   876 // ----------------------------------------------------------------------------
       
   877 //
       
   878 void CIRRadioIdle::RefreshL()
       
   879 	{
       
   880 	if ( iRadioIdleState == ERunning )
       
   881 		{
       
   882 		RadioIdleFadeOut();
       
   883 		}
       
   884 	iRadioIdleState = ESuspended;
       
   885     iFading = EFalse;
       
   886 	HandleCommandL( EStartup );
       
   887 	}
       
   888 
       
   889 // ----------------------------------------------------------------------------
       
   890 // CIRRadioIdle::SetIdleFadeStyle
       
   891 // Sets fade style for radio idle
       
   892 // ----------------------------------------------------------------------------
       
   893 //
       
   894 void CIRRadioIdle::SetIdleFadeStyle( TRadioIdleFadeStyle aFadeStyle )
       
   895 	{
       
   896 	iFadeStyle = aFadeStyle;
       
   897 	}
       
   898 
       
   899 // ----------------------------------------------------------------------------
       
   900 // CIRRadioIdle::SetModeChangeRequest
       
   901 // Sets request for mode change
       
   902 // ----------------------------------------------------------------------------
       
   903 //
       
   904 void CIRRadioIdle::SetModeChangeRequestL( TRadioIdleMode aRequestedMode )
       
   905 	{
       
   906 	iRadioIdleRequestedMode = aRequestedMode;
       
   907 	if( iRadioIdleRequestedMode == EBackgroundTextAndRadioIdleItems &&
       
   908 		Mode() == EOnlyBackgroundText )
       
   909 		{
       
   910 		InitializeRadioIdleItemsL( KMaxNumberOfRadioIdleItems );
       
   911 		AnimateRadioIdleItems();
       
   912 		SetMode( EBackgroundTextAndRadioIdleItems );
       
   913 		}
       
   914 	}
       
   915 
       
   916 // ----------------------------------------------------------------------------
       
   917 // CIRRadioIdle::SetMode
       
   918 // Sets the radio idle mode
       
   919 // ----------------------------------------------------------------------------
       
   920 //
       
   921 void CIRRadioIdle::SetMode( TRadioIdleMode aMode )
       
   922 	{
       
   923 	iRadioIdleMode = aMode;
       
   924 	}
       
   925 
       
   926 // ----------------------------------------------------------------------------
       
   927 // CIRRadioIdle::Mode
       
   928 // Retrieves the radio idle mode
       
   929 // ----------------------------------------------------------------------------
       
   930 //
       
   931 CIRRadioIdle::TRadioIdleMode CIRRadioIdle::Mode()
       
   932 	{
       
   933 	return iRadioIdleMode;
       
   934 	}
       
   935 
       
   936 // ----------------------------------------------------------------------------
       
   937 // CIRRadioIdle::State
       
   938 // Retrieves the radio idle state
       
   939 // ----------------------------------------------------------------------------
       
   940 //
       
   941 CIRRadioIdle::TRadioIdleState CIRRadioIdle::State()
       
   942 	{
       
   943 	return iRadioIdleState;
       
   944 	}
       
   945 
       
   946 // ----------------------------------------------------------------------------
       
   947 // CIRRadioIdle::Orientation
       
   948 // Return orientation of the display
       
   949 // ----------------------------------------------------------------------------
       
   950 //
       
   951 CIRRadioIdle::TOrientation CIRRadioIdle::Orientation()
       
   952 	{
       
   953 	return iOrientation;
       
   954 	}
       
   955 
       
   956 // ----------------------------------------------------------------------------
       
   957 // CIRRadioIdle::Orientation
       
   958 // Set orientation of the display
       
   959 // ----------------------------------------------------------------------------
       
   960 //
       
   961 void CIRRadioIdle::SetOrientation( TOrientation aOrientation )
       
   962 	{
       
   963 	iOrientation = aOrientation;
       
   964 	}
       
   965 
       
   966 // ----------------------------------------------------------------------------
       
   967 // CIRRadioIdle::OfferEventL
       
   968 // From CAlfControl, takes care of alfred event handling.
       
   969 // ----------------------------------------------------------------------------
       
   970 //
       
   971 TBool CIRRadioIdle::OfferEventL( const TAlfEvent& aEvent )
       
   972 	{
       
   973 
       
   974 	TBool isHandled = EFalse;
       
   975 	if( aEvent.IsCustomEvent() )
       
   976 		{
       
   977 		switch( aEvent.CustomParameter() )
       
   978 			{
       
   979 			case ERadioIdleItemTransformationEnd:
       
   980 				{
       
   981 				HandleRadioIdleItemTransformationEndEventL( aEvent );
       
   982 				isHandled = ETrue;
       
   983 				}
       
   984 				break;
       
   985 			case ERadioIdleBackgroundTextScrollEnd:
       
   986 				{
       
   987 				HandleBackgroundTextScrollEndEventL( aEvent );
       
   988 				isHandled = ETrue;
       
   989 				}
       
   990 				break;
       
   991 			case ERadioIdleChangeMode:
       
   992 				{
       
   993 				if( Mode() == EBackgroundTextAndRadioIdleItems )
       
   994 					{
       
   995 					SetModeChangeRequestL( EOnlyBackgroundText );
       
   996 					}
       
   997 				else
       
   998 					{
       
   999 					SetModeChangeRequestL( EBackgroundTextAndRadioIdleItems );
       
  1000 					}
       
  1001 				isHandled = ETrue;
       
  1002 				}
       
  1003 				break;
       
  1004 			case ERadioIdleFadeOutCompleted:
       
  1005 				{
       
  1006 				reinterpret_cast<CAlfViewportLayout*>( aEvent.CustomEventData() )
       
  1007 														->RemoveAndDestroyAllD();
       
  1008 				iFading = EFalse;
       
  1009 				
       
  1010 				// Check if there was a startup command during fading out
       
  1011 				if ( iDelayedStartup )
       
  1012 					{
       
  1013 					StartRadioIdleL();
       
  1014 					}
       
  1015 				isHandled = ETrue;
       
  1016 				}
       
  1017 				break;
       
  1018 			default:
       
  1019 			break;
       
  1020 			}
       
  1021 		}
       
  1022 	return isHandled;
       
  1023 
       
  1024 	}
       
  1025 
       
  1026 // ----------------------------------------------------------------------------
       
  1027 // CIRRadioIdle::HandleRadioIdleItemTransformationEndEventL
       
  1028 // ----------------------------------------------------------------------------
       
  1029 //
       
  1030 void CIRRadioIdle::HandleRadioIdleItemTransformationEndEventL( const TAlfEvent& aEvent )
       
  1031 	{
       
  1032 
       
  1033 	iItemsTransformationEndEventCounter++;
       
  1034 	if ( iRadioIdleRequestedMode == EOnlyBackgroundText || Mode() == EOnlyBackgroundText )
       
  1035 		{
       
  1036 		CAlfFlowLayout* radioIdleFlowLayout = static_cast<CAlfFlowLayout*> 
       
  1037 						( iViewport->FindTag( KRadioIdleFlowLayoutTag ) );
       
  1038 		if ( radioIdleFlowLayout )
       
  1039 			{
       
  1040 			TInt radioIdleItemIndex = aEvent.CustomEventData();
       
  1041 	    	/*lint -save -e826 (Info -- Suspicious pointer-to-pointer conversion (area too small)*/
       
  1042 			CAlfTextVisual* radioIdleItem = static_cast<CAlfTextVisual*> ( GetPointer( radioIdleFlowLayout->
       
  1043 													Visual( radioIdleItemIndex ) ) );
       
  1044 			/*lint -restore*/
       
  1045 			radioIdleItem->SetOpacity( TAlfTimedValue( .0f ) );
       
  1046 
       
  1047 			if( iItemsTransformationEndEventCounter == radioIdleFlowLayout->Count() )
       
  1048 				{
       
  1049 				SetMode( EOnlyBackgroundText );
       
  1050 				iItemsTransformationEndEventCounter = 0;
       
  1051 				Env().Send( TAlfCustomEventCommand( ERadioIdleBackgroundTextScrollEnd, this ), KZero );
       
  1052 				}
       
  1053 			}
       
  1054 		}
       
  1055 	else
       
  1056 		{
       
  1057 		CAlfFlowLayout* radioIdleFlowLayout = static_cast<CAlfFlowLayout*> ( iViewport->
       
  1058 												FindTag( KRadioIdleFlowLayoutTag ) );
       
  1059 		if ( radioIdleFlowLayout )
       
  1060 			{
       
  1061 			HBufC* itemText = GetRandomRadioIdleContentL();
       
  1062 			if( itemText )
       
  1063 				{
       
  1064 				CleanupStack::PushL( itemText );
       
  1065 				TInt radioIdleItemIndex = aEvent.CustomEventData();
       
  1066 		    	/*lint -save -e826 (Info -- Suspicious pointer-to-pointer conversion (area too small)*/
       
  1067 				CAlfTextVisual* radioIdleItem = static_cast<CAlfTextVisual*> ( GetPointer(
       
  1068 											 radioIdleFlowLayout->Visual( radioIdleItemIndex ) ) );
       
  1069 				/*lint -restore*/
       
  1070 				if ( iTextStyleIdArray.Count() > KZero )
       
  1071 					{
       
  1072 			    	// First hide the radio idle item
       
  1073 					radioIdleItem->SetOpacity( TAlfTimedValue( .0f ) );
       
  1074 					radioIdleItem->EnableTransformationL( ETrue );
       
  1075 					CAlfTransformation* radioIdleItemTransformation = 
       
  1076 											&( radioIdleItem->Transformation() );
       
  1077 					radioIdleItemTransformation->LoadIdentity();
       
  1078 
       
  1079 					TInt randFontStyleIx = AlfUtil::RandomInt( KZero,  iTextStyleIdArray.Count() - Kone );
       
  1080 					SetRadioIdleItemSettingsL( radioIdleItem, *itemText,
       
  1081 										  iTextStyleIdArray[ randFontStyleIx ] );
       
  1082 					SetRadioIdleItemAnimation( radioIdleItem );
       
  1083 
       
  1084 					if ( iRadioIdleRequestedMode != EOnlyBackgroundText )
       
  1085 						{
       
  1086 						if( iItemsTransformationEndEventCounter == radioIdleFlowLayout->Count() )
       
  1087 							{
       
  1088 							Env().Send( TAlfCustomEventCommand( ERadioIdleChangeMode, this ),
       
  1089 									KMaxRadioIdleItemScrollDurationTime * KModeChangingFactor );
       
  1090 							iItemsTransformationEndEventCounter = 0;
       
  1091 							}
       
  1092 						}
       
  1093 					}
       
  1094 				CleanupStack::PopAndDestroy( itemText );
       
  1095 				}
       
  1096 			}
       
  1097 		}
       
  1098 
       
  1099 	}
       
  1100 
       
  1101 // ----------------------------------------------------------------------------
       
  1102 // CIRRadioIdle::HandleBackgroundTextScrollEndEventL
       
  1103 // ----------------------------------------------------------------------------
       
  1104 //
       
  1105 void CIRRadioIdle::HandleBackgroundTextScrollEndEventL( const TAlfEvent& /*aEvent*/ )
       
  1106 	{
       
  1107 	if( iViewport )
       
  1108 		{
       
  1109 		CAlfTextVisual* backgroundText = static_cast<CAlfTextVisual*> ( iViewport->
       
  1110 										FindTag( KRadioIdleBackgroundTextTag ) );
       
  1111 		if( backgroundText )
       
  1112 			{
       
  1113 			backgroundText->SetOpacity( TAlfTimedValue( .0f ) );
       
  1114 
       
  1115 			if ( iRadioIdleRequestedMode == EOnlyBackgroundText && Mode() == 
       
  1116 											 EBackgroundTextAndRadioIdleItems )
       
  1117 				{
       
  1118 				}
       
  1119 			else
       
  1120 				{
       
  1121 				if( iRadioIdleRequestedMode == EOnlyBackgroundText &&
       
  1122 						Mode() == EOnlyBackgroundText )
       
  1123 					{
       
  1124 					Env().CancelCustomCommands( this );
       
  1125 					Env().Send( TAlfCustomEventCommand( ERadioIdleChangeMode, this ),
       
  1126 							KRadioIdleBackgroundTextSideToSideTransitionDurationTime );
       
  1127 					}
       
  1128 				backgroundText->EnableTransformationL( ETrue );
       
  1129 				CAlfTransformation* radioIdleItemTransformation = 
       
  1130 										&( backgroundText->Transformation() );
       
  1131 				radioIdleItemTransformation->LoadIdentity();
       
  1132 				HBufC* itemText = GetRandomRadioIdleContentL();
       
  1133 				if( itemText )
       
  1134 					{
       
  1135 					CleanupStack::PushL( itemText );
       
  1136 					SetRadioIdleItemSettingsL( backgroundText, *itemText,
       
  1137 									 iRadioIdleItemBackgroundTextStyleId );
       
  1138 					CleanupStack::PopAndDestroy( itemText );
       
  1139 					}
       
  1140 				backgroundText->SetOpacity( TAlfTimedValue( KRadioIdleBackgroundTextOpacity ) );
       
  1141 				SetScrollingToBackgroundText( backgroundText,
       
  1142 								   KRadioIdleBackgroundTextSideToSideTransitionDurationTime,
       
  1143 								   ERadioIdleBackgroundTextScrollEnd );
       
  1144 				}
       
  1145 			}
       
  1146 		}
       
  1147 	}
       
  1148 
       
  1149 // ---------------------------------------------------------------------------
       
  1150 // CIRRadioIdle::HandleCommandL
       
  1151 // From MRadioIdleCommandObserver, takes care of radio idle command handling.
       
  1152 // ---------------------------------------------------------------------------
       
  1153 //
       
  1154 void CIRRadioIdle::HandleCommandL( TRadioIdleCommand aCommand )
       
  1155     {
       
  1156     switch ( aCommand )
       
  1157 	    {
       
  1158 		case ESuspend:
       
  1159 			SuspendRadioIdle();
       
  1160 			break;
       
  1161 		case EStartup:
       
  1162 			{
       
  1163 			// Check if radio idle can be started right away
       
  1164 			if ( !iFading )
       
  1165 				{
       
  1166 				StartRadioIdleL();
       
  1167 				}
       
  1168 			else
       
  1169 				{
       
  1170 				iDelayedStartup = ETrue;
       
  1171 				}
       
  1172 			}	
       
  1173 			break;
       
  1174 		case EShutdown:
       
  1175 			ShutdownRadioIdle();
       
  1176 			break;
       
  1177 		case ERefresh:
       
  1178 			RefreshL();
       
  1179 			break;
       
  1180 		case EResetContent:
       
  1181 			ResetRadioIdleContent();
       
  1182 			break;
       
  1183 		default:
       
  1184 			break;
       
  1185 		}
       
  1186     }
       
  1187 
       
  1188 // ----------------------------------------------------------------------------
       
  1189 // CIRRadioIdle::SetScrollingToBackgroundText
       
  1190 // ----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CIRRadioIdle::SetScrollingToBackgroundText( CAlfTextVisual* aVisual, TInt aTransitionTime,
       
  1193 						 TRadioIdleCustomEvent aEventAfterScrollingEnd )
       
  1194 	{
       
  1195 	CAlfViewportLayout* radioIdle = static_cast<CAlfViewportLayout*> ( aVisual->Layout() );
       
  1196 	TReal32 radioIdleItemWidth = aVisual->DisplayRect().Width();
       
  1197 	TReal32 radioIdleWidth = radioIdle->Size().Target().iX;
       
  1198 
       
  1199 	TAlfTimedValue targetPositionX;
       
  1200 	if( iBackgroundTextScrollDirection == EScrollRightToLeft  )
       
  1201 	 	{
       
  1202 		targetPositionX.SetValueNow(  -radioIdleItemWidth );
       
  1203 		targetPositionX.SetTarget( radioIdleWidth, aTransitionTime );
       
  1204 		iBackgroundTextScrollDirection = EScrollLeftToRight;
       
  1205 	 	}
       
  1206 	else
       
  1207 	 	{
       
  1208 		targetPositionX.SetValueNow( radioIdleWidth );
       
  1209 		targetPositionX.SetTarget( -radioIdleItemWidth, aTransitionTime );
       
  1210 		iBackgroundTextScrollDirection = EScrollRightToLeft;
       
  1211 	 	}
       
  1212 	Translate( aVisual, targetPositionX, TAlfTimedValue( -30.0f ) ); 
       
  1213 	Env().Send( TAlfCustomEventCommand( aEventAfterScrollingEnd, this ),
       
  1214 			    aTransitionTime + KRadioIdleBackgroundTextScrollInterval );
       
  1215 	}
       
  1216 
       
  1217 // ----------------------------------------------------------------------------
       
  1218 // CIRRadioIdle::ScrollToLeft
       
  1219 // Sets and starts scrolling animation to CAlfTextVisual.
       
  1220 // The visual object is scrolled from current position to
       
  1221 // left side of the display
       
  1222 // ----------------------------------------------------------------------------
       
  1223 //
       
  1224 void CIRRadioIdle::ScrollToLeft( CAlfTextVisual* aVisual ) const
       
  1225 	{
       
  1226 	if( aVisual )
       
  1227 		{
       
  1228 		TReal32 visualWidth = aVisual->DisplayRect().Width();
       
  1229 		TInt textWidth = aVisual->TextExtents().iWidth;
       
  1230 		TReal32 scrollValue = visualWidth;
       
  1231 		if( textWidth > visualWidth )
       
  1232 			{
       
  1233 			scrollValue += textWidth - visualWidth;
       
  1234 			}
       
  1235 		TAlfTimedPoint timedPosition = aVisual->Pos();
       
  1236 		TAlfRealPoint positionZero( 0.0f, timedPosition.iY.ValueNow() );
       
  1237 		TAlfRealPoint positionLeft( - ( scrollValue ), timedPosition.iY.ValueNow() );
       
  1238 		aVisual->SetPos( positionZero );
       
  1239 		aVisual->SetPos( positionLeft, KThousand );
       
  1240 		}
       
  1241 	}
       
  1242 
       
  1243 // ----------------------------------------------------------------------------
       
  1244 // CIRRadioIdle::ScrollToRight
       
  1245 // Sets and starts scrolling animation to CAlfTextVisual.
       
  1246 // The visual object is scrolled from current position to
       
  1247 // right side of the display
       
  1248 // ----------------------------------------------------------------------------
       
  1249 //
       
  1250 void CIRRadioIdle::ScrollToRight( CAlfTextVisual* aVisual ) const
       
  1251 	{
       
  1252 	TReal32 visualWidth = aVisual->DisplayRect().Width();
       
  1253 	TInt textWidth = aVisual->TextExtents().iWidth;
       
  1254 	TReal32 scrollValue = visualWidth;
       
  1255 	if( textWidth > visualWidth )
       
  1256 		{
       
  1257 		scrollValue += textWidth - visualWidth;
       
  1258 		}
       
  1259 	TAlfTimedPoint timedPosition = aVisual->Pos();
       
  1260 	TAlfRealPoint positionZero( 0.0f, timedPosition.iY.ValueNow() );
       
  1261 	TAlfRealPoint positionRight( scrollValue, timedPosition.iY.ValueNow() );
       
  1262 	aVisual->SetPos( positionZero );
       
  1263 	aVisual->SetPos( positionRight, KThousand );
       
  1264 	}
       
  1265 
       
  1266 // ---------------------------------------------------------------------------
       
  1267 // CIRRadioIdle::FadeIn
       
  1268 // Sets fade-in animation to the CAlfVisual.
       
  1269 // ---------------------------------------------------------------------------
       
  1270 //
       
  1271 void CIRRadioIdle::FadeIn( CAlfVisual* aVisual, TInt aTime, TReal32 aOpacity ) const
       
  1272 	{
       
  1273 	TAlfTimedValue opacity;
       
  1274 	opacity.SetValueNow( 0.0f ); // immediate change
       
  1275 	opacity.SetTarget( aOpacity, aTime ); // and smooth target
       
  1276 	aVisual->SetOpacity( opacity );
       
  1277 	}
       
  1278 
       
  1279 // ---------------------------------------------------------------------------
       
  1280 // CIRRadioIdle::FadeOut
       
  1281 // Sets fade-out animation to the CAlfVisual.
       
  1282 // ---------------------------------------------------------------------------
       
  1283 //
       
  1284 void CIRRadioIdle::FadeOut( CAlfVisual* aVisual, TInt aTime, TReal32 aOpacity ) const
       
  1285 	{
       
  1286 	TAlfTimedValue opacity;
       
  1287 	opacity.SetTarget( aOpacity, aTime );
       
  1288 	aVisual->SetOpacity( opacity );
       
  1289 	}
       
  1290 
       
  1291 // ---------------------------------------------------------------------------
       
  1292 // CIRRadioIdle::GetPointer
       
  1293 // Converts reference to a AlfVisual to pointer.
       
  1294 // ---------------------------------------------------------------------------
       
  1295 //
       
  1296 CAlfVisual* CIRRadioIdle::GetPointer( CAlfVisual& aRef )
       
  1297 	{
       
  1298 	return &aRef;
       
  1299 	}
       
  1300 
       
  1301 //  End of File
       
  1302