fmradio/fmradio/src/fmradiologo.cpp
changeset 0 f3d95d9c00ab
child 6 3cb097cb90f8
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 CFMRadioLogo
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <AknUtils.h>
       
    22 #include <alf/alfenv.h>
       
    23 #include <alf/alfimagevisual.h>
       
    24 #include <alf/alfevent.h>
       
    25 #include <alf/alfanchorlayout.h>
       
    26 #include <aknlayoutscalable_apps.cdl.h>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <fmradio.mbg>
       
    29 
       
    30 #include "fmradiologo.h"
       
    31 #include "fmradioalfrdsviewobserver.h"
       
    32 #include "fmradiodefines.h"
       
    33 #include "debug.h"
       
    34 #include "fmradiologoobserver.h"
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 const TInt  KLogoFadeInDefaultDurationTime = 500;
       
    39 const TInt  KLogoFadeOutDefaultDurationTime = 500;
       
    40 const TInt  KLogoDisplayPeriod = 2000; // milliseconds = 2 sec
       
    41 const TReal KDefaultOpacityInVisibleState = 1.0f;
       
    42 const TReal KDefaultOpacityInHiddenState = 0.0f;
       
    43 const TInt KLAFVarietyBackgroundImagePortrait = 0;
       
    44 const TInt KLAFVarietyBackgroundImageLandscape = 1;
       
    45 // bitmap file for the background of the display
       
    46 _LIT8( KBitmapAnchorTag, "BitmapAnchorTag" );
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CFMRadioLogo::NewL
       
    52 // Two-phase constructor of CFMRadioAlfLogo
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CFMRadioLogo* CFMRadioLogo::NewL( CAlfEnv& aEnv )
       
    56     {
       
    57     CFMRadioLogo* self = new ( ELeave ) CFMRadioLogo();
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aEnv );
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // CFMRadioLogo::CFMRadioLogo
       
    66 // Default constructor
       
    67 // ----------------------------------------------------------------------------
       
    68 //
       
    69 CFMRadioLogo::CFMRadioLogo()
       
    70 :  iOpacityInVisibleState( KDefaultOpacityInVisibleState ),
       
    71    iOpacityInHiddenState( KDefaultOpacityInHiddenState ),
       
    72    iIsVisible( ETrue ) // visible by default
       
    73     {
       
    74     //No implementation needed
       
    75     }
       
    76 
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // CFMRadioLogo::SetObserver
       
    80 // Sets observer
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 void CFMRadioLogo::SetObserver( MFMRadioLogoObserver* aObserver )
       
    84     {
       
    85     FTRACE( FPrint( _L( "CFMRadioLogo::SetObserver" ) ) );
       
    86     TInt index = iObservers.FindInAddressOrder( aObserver );
       
    87     if ( index == KErrNotFound )
       
    88         {
       
    89         iObservers.InsertInAddressOrder( aObserver );
       
    90         }
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CFMRadioLogo::RemoveObserver
       
    95 // Removes observer
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 void CFMRadioLogo::RemoveObserver( MFMRadioLogoObserver* aObserver )
       
    99     {
       
   100 	FTRACE( FPrint( _L( "CFMRadioLogo::RemoveObserver" ) ) );
       
   101     TInt index = iObservers.FindInAddressOrder( aObserver );
       
   102 
       
   103     if ( index >= 0 )
       
   104         {
       
   105         iObservers.Remove( index );
       
   106         }
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CFMRadioLogo::ConstructL
       
   111 // Symbian 2nd phase constructor can leave.
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 void CFMRadioLogo::ConstructL( CAlfEnv& aEnv )
       
   115     {
       
   116     FTRACE( FPrint( _L( "CFMRadioLogo::ConstructL" ) ) );
       
   117     CAlfControl::ConstructL( aEnv );
       
   118     CreateImageVisualsL();
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // ~CFMRadioLogo::~CFMRadioLogo
       
   123 // Destructor
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 CFMRadioLogo::~CFMRadioLogo()
       
   127     {
       
   128     FTRACE( FPrint( _L( "CFMRadioLogo::Destructor" ) ) );
       
   129     Env().CancelCustomCommands( this );
       
   130     iObservers.Close();
       
   131     delete iBackgroundBitmapFileName;
       
   132     } 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CFMRadioLogo::OfferEventL
       
   136 // From CAlfControl, takes care of alfred event handling. 
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 TBool CFMRadioLogo::OfferEventL( const TAlfEvent& aEvent )
       
   140     {
       
   141     FTRACE( FPrint( _L( "CFMRadioLogo::OfferEventL" ) ) );
       
   142     TBool eventHandled = EFalse;
       
   143 
       
   144     if ( aEvent.IsCustomEvent() )
       
   145         {
       
   146         switch( aEvent.CustomParameter() )
       
   147             {
       
   148         	case EFadeInCompleted:
       
   149                 {
       
   150                 eventHandled = ETrue;
       
   151                 Env().Send( TAlfCustomEventCommand( ELogoDisplayTimerCompleted, this ), KLogoDisplayPeriod );
       
   152                 break;
       
   153                 }
       
   154             case ELogoDisplayTimerCompleted:
       
   155                 {
       
   156                 eventHandled = ETrue;
       
   157                 for ( TInt i = 0 ; i < iObservers.Count() ; i++ )
       
   158                     {
       
   159                     iObservers[i]->LogoDisplayTimeCompleted();
       
   160                     }
       
   161                 break;
       
   162                 }
       
   163             default:
       
   164                 {
       
   165                 break;
       
   166                 }
       
   167             }
       
   168         }
       
   169     return eventHandled;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CFMRadioLogo::SetRect
       
   174 // Sets the logo rectangle. 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void CFMRadioLogo::SetRect( const TRect& aRect )
       
   178     {
       
   179     iRect = aRect;
       
   180     if ( iLogoAnchor )
       
   181         {
       
   182         SetAbsoluteCornerAnchors( iLogoAnchor, 0, iRect.iTl, iRect.iBr );
       
   183         iLogoAnchor->UpdateChildrenLayout();
       
   184         }
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CFMRadioLogo::CreateImageVisualsL
       
   189 // Creates visual for the logo
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CFMRadioLogo::CreateImageVisualsL()
       
   193     {
       
   194     // locate source mbm
       
   195     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   196     TFindFile finder( coeEnv->FsSession() );
       
   197     TInt err = finder.FindByDir( KFMRadioBmpFile, KDC_APP_BITMAP_DIR );
       
   198     if ( err == KErrNone )
       
   199         {
       
   200         iBackgroundBitmapFileName = finder.File().AllocL();
       
   201         }
       
   202 
       
   203     iLogoAnchor = CAlfAnchorLayout::AddNewL( *this );
       
   204     iLogoAnchor->SetTagL( KBitmapAnchorTag );
       
   205 
       
   206     iImageVisual = CAlfImageVisual::AddNewL( *this, iLogoAnchor );
       
   207 
       
   208     // read bitmap size from layout data
       
   209     TRect temp;
       
   210     TAknLayoutRect bitmapLayout;
       
   211     bitmapLayout.LayoutRect(
       
   212             temp,
       
   213             AknLayoutScalable_Apps::area_fmrd2_visual_pane_g1( KLAFVarietyBackgroundImagePortrait ).LayoutLine() );
       
   214 
       
   215     // image for portrait
       
   216     iPortraitImage = TAlfImage( KAknsIIDNone,
       
   217                                        bitmapLayout.Rect().Size(),
       
   218                                        EAspectRatioPreserved,
       
   219                                        iBackgroundBitmapFileName,
       
   220                                        EMbmFmradioQgn_indi_radio_default,
       
   221                                        EMbmFmradioQgn_indi_radio_default_mask );
       
   222 
       
   223     // image for landscape
       
   224     bitmapLayout.LayoutRect(
       
   225             temp,
       
   226             AknLayoutScalable_Apps::area_fmrd2_visual_pane_g1( KLAFVarietyBackgroundImageLandscape ).LayoutLine() );    
       
   227 
       
   228     iLandscapeImage = TAlfImage( KAknsIIDNone,
       
   229                                  bitmapLayout.Rect().Size(),
       
   230                                  EAspectRatioPreserved,
       
   231                                  iBackgroundBitmapFileName,
       
   232                                  EMbmFmradioQgn_indi_radio_default,
       
   233                                  EMbmFmradioQgn_indi_radio_default_mask );
       
   234     
       
   235     iImageVisual->SetImage( iPortraitImage );
       
   236     iImageVisual->SetSecondaryImage( iLandscapeImage );
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------
       
   240 // CFMRadioLogo::Show
       
   241 // Fades in the logo with predefined opacity value.
       
   242 // ---------------------------------------------------------
       
   243 //
       
   244 void CFMRadioLogo::Show()
       
   245     {
       
   246     // change status only, fade in and the event are allways triggered so don't
       
   247     // check visibility here
       
   248     iIsVisible = ETrue; 
       
   249     Env().CancelCustomCommands( this );
       
   250     Fade( iImageVisual, KLogoFadeInDefaultDurationTime, iOpacityInVisibleState );
       
   251     Env().Send( TAlfCustomEventCommand( EFadeInCompleted, this ), KLogoFadeInDefaultDurationTime );
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // CFMRadioLogo::Hide
       
   256 // Fades out the logo with predefined opacity value.
       
   257 // ---------------------------------------------------------
       
   258 //
       
   259 void CFMRadioLogo::Hide()
       
   260     {
       
   261     if ( iIsVisible )
       
   262         {
       
   263         iIsVisible = EFalse;
       
   264         Fade( iImageVisual, KLogoFadeOutDefaultDurationTime, iOpacityInHiddenState );
       
   265         }
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CFMRadioLogo::SetOpacityInVisibleState
       
   270 // Sets the indicator opacity in visible state.
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 void CFMRadioLogo::SetOpacityInVisibleState( const TReal aOpacity )
       
   274 	{
       
   275 	iOpacityInVisibleState = aOpacity;
       
   276 	}
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CFMRadioLogo::SetOpacityInHiddenState
       
   280 // Sets the logo opacity value in hidden state.
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CFMRadioLogo::SetOpacityInHiddenState( const TReal aOpacity )
       
   284 	{
       
   285 	iOpacityInHiddenState = aOpacity;
       
   286 	}
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CFMRadioLogo::SetAbsoluteCornerAnchors
       
   290 // Sets absolute rect of the anchor by top left and bottom right points.
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CFMRadioLogo::SetAbsoluteCornerAnchors( CAlfAnchorLayout* aAnchor,
       
   294                                                      TInt aOrdinal,
       
   295                                                      const TPoint& aTopLeftPosition,
       
   296                                                      const TPoint& aBottomRightPosition )
       
   297 	{
       
   298     if ( aAnchor )
       
   299         {					
       
   300         // Set top/left anchor.
       
   301         aAnchor->Attach( aOrdinal, 
       
   302                          EAlfAnchorTypeTopLeft,
       
   303                          TAlfXYMetric( TAlfMetric( aTopLeftPosition.iX ), TAlfMetric( aTopLeftPosition.iY ) ),
       
   304                          EAlfAnchorAttachmentOriginTopLeft );
       
   305         
       
   306         
       
   307         // Set bottom/right anchor.
       
   308         aAnchor->Attach( aOrdinal, 
       
   309                          EAlfAnchorTypeBottomRight, 
       
   310                          TAlfXYMetric( TAlfMetric( aBottomRightPosition.iX ), TAlfMetric( aBottomRightPosition.iY ) ),
       
   311                          EAlfAnchorAttachmentOriginTopLeft );
       
   312         }
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CFMRadioLogo::Fade
       
   317 // Sets the fading animation to the CAlfVisual object.
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CFMRadioLogo::Fade( CAlfVisual* aVisual, TInt aFadingTime, TReal aOpacity )
       
   321     {
       
   322     TAlfTimedValue opacity;
       
   323     opacity.SetTarget( aOpacity, aFadingTime );
       
   324     aVisual->SetOpacity( opacity );
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CFMRadioLogo::SwitchToLandscapeImage
       
   329 // Use secondary image for landscape and primary for portrait
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CFMRadioLogo::SwitchToLandscapeImage( TBool aShow )
       
   333     {
       
   334     if ( aShow )
       
   335         {
       
   336         iImageVisual->SetSecondaryAlpha( TAlfTimedValue( 1.0 ) );
       
   337         }
       
   338     else
       
   339         {
       
   340         iImageVisual->SetSecondaryAlpha( TAlfTimedValue( 0.0 ) );
       
   341         }
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // CFMRadioLogo::Deactivate
       
   346 // from MFMRadioIdleControlInterface
       
   347 // ---------------------------------------------------------------------------
       
   348 //
       
   349 void CFMRadioLogo::Deactivate()
       
   350     {
       
   351     }
       
   352 
       
   353 //  End of File