internetradio2.0/uiinc/irradioidle.h
changeset 3 ee64f059b8e1
parent 2 2e1adbfc62af
child 4 3f2d53f144fe
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
     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               : vrradioidle.h
       
    20 *  Part of            : S60VisualRadio / UI
       
    21 *  Description        :
       
    22 *  Version    		  :
       
    23 *
       
    24 * ==============================================================================
       
    25 */
       
    26 
       
    27 #ifndef IRRADIOIDLE_H_
       
    28 #define IRRADIOIDLE_H_
       
    29 
       
    30 // INCLUDES
       
    31 
       
    32 #include <AknUtils.h>
       
    33 #include <alf/alfenv.h>
       
    34 #include <alf/alfcontrol.h>
       
    35 #include <alf/alfanchorlayout.h>
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 
       
    39 class CAlfGradientBrush;
       
    40 class CAlfViewportLayout;
       
    41 class CAlfEnv;
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 /** Commands for radio idle. */
       
    46 enum TRadioIdleCommand
       
    47 	{
       
    48 	ESuspend = 0x4A,
       
    49 	EStartup,
       
    50 	EShutdown,
       
    51 	ERefresh,
       
    52 	EResetContent
       
    53 	};
       
    54 
       
    55 // CLASS DEFINITIONS
       
    56 
       
    57 class MIRRadioIdleCommandObserver
       
    58 	{
       
    59 	public:
       
    60 		/**
       
    61 		* Called when change to the state of radio idle is wanted
       
    62 		*/
       
    63 		virtual void HandleCommandL( TRadioIdleCommand aCommand ) = 0;
       
    64 	};
       
    65 
       
    66 /**
       
    67 * CVRRadioIdle class
       
    68 *
       
    69 * Class launches animated information in the defined subregion of the display after startup delay.
       
    70 * Launching and radio idle running can be suspended by giving ESuspend command via
       
    71 * MVRRadioIdleCommandObserver interface.  When suspended,
       
    72 * background bitmap will replace the animated information and startup delay is reset to zero.
       
    73 * The animation will start again after the delay.
       
    74 */
       
    75 NONSHARABLE_CLASS(CIRRadioIdle) : public CAlfControl, public MIRRadioIdleCommandObserver
       
    76 	{
       
    77 public:		// Constructors and destructor
       
    78 
       
    79 		/** Display orientations. */
       
    80 		enum TOrientation
       
    81 			{
       
    82 			EPortrait = 0x4A,
       
    83 			ELandscape,
       
    84 			EOrientationNone
       
    85 			};
       
    86 
       
    87 		/**
       
    88 	    * Epoc two-phased constructor.
       
    89 	    * @param aAlfEnv The Alfred environment.
       
    90 	    * @param aControlGroupId The control group that this control is to be added to.
       
    91 	    * @param aParentLayout The parent layout for the visuals.
       
    92 	    */
       
    93 		static CIRRadioIdle* NewL( CAlfEnv& aEnv, TInt aControlGroupId, CAlfLayout* aParentLayout );
       
    94 		/**
       
    95         * Destructor
       
    96         */
       
    97 		virtual ~CIRRadioIdle();
       
    98 
       
    99 public: 	// Functions from base classes
       
   100 		/**
       
   101  	    * From CAlfControl, takes care of alfred event handling.
       
   102  	    */
       
   103 		TBool OfferEventL( const TAlfEvent& aEvent );
       
   104 
       
   105 public:		// New functions
       
   106 
       
   107 		/** States of radio idle. */
       
   108 		enum TRadioIdleState
       
   109 			{
       
   110 			ERunning = 0xA0,
       
   111 			ESuspended,
       
   112 			EStopped
       
   113 			};
       
   114 
       
   115 		/** Radio idle modes. */
       
   116 		enum TRadioIdleMode
       
   117 			{
       
   118 			EOnlyBackgroundText = 0xB0,
       
   119 			EBackgroundTextAndRadioIdleItems
       
   120 			};
       
   121 
       
   122 		/** Fade styles. */
       
   123 		enum TRadioIdleFadeStyle
       
   124 			{
       
   125 			EFadeLeft = 0xC0,
       
   126 			EFadeRight,
       
   127 			EFadeStyleNone
       
   128 			};
       
   129 
       
   130 		/**
       
   131  	    * Adds radio idle item text to be used in the radio idle
       
   132  	    * @param aRadioIdleItemText Text of the radio idle item
       
   133  	    * @return Index of the added item
       
   134  	    */
       
   135 		TInt AddRadioIdleContentL( const TDesC& aRadioIdleItemText );
       
   136 		/**
       
   137  	    * Updates radio idle item text in specified index
       
   138  	    * @param aRadioIdleItemText Text of the radio idle item
       
   139  	    * @param aIndex Index of the radio idle item to be updated
       
   140  	    */
       
   141 		void UpdateRadioIdleContent( const TDesC& aRadioIdleItemText, TInt aIndex );
       
   142 		/**
       
   143 	    * Removes all radio idle item texts
       
   144 		*/
       
   145 		void ResetRadioIdleContent();
       
   146 		/**
       
   147 	    * Returns number of radio idle content items
       
   148 	    * @return content count
       
   149 		*/
       
   150 		TInt RadioIdleContentCount() const;
       
   151 		/**
       
   152 		 * Sets the fade style for radio idle.
       
   153 		 * @param aFadeStyle  Fade style
       
   154 		 */
       
   155 		void SetIdleFadeStyle( TRadioIdleFadeStyle aFadeStyle );
       
   156 		/**
       
   157 	    * Sets the mode request for mode change. The mode
       
   158 	    * will be changed as soon as possible.
       
   159 	    * @param aRequestedMode Requested mode
       
   160 		*/
       
   161 		void SetModeChangeRequestL( TRadioIdleMode aRequestedMode );
       
   162 		/**
       
   163 	    * Retrieves the radio idle mode
       
   164 		*/
       
   165 		TRadioIdleMode Mode();
       
   166 		/**
       
   167 		 * Retrieves the radio idle state
       
   168 		 */
       
   169 		TRadioIdleState State();
       
   170 		/**
       
   171  	    * Sets primary color for the radio idle
       
   172  	    * @param aColor The color that is used as primary color of radio idle
       
   173  	    */
       
   174 		void SetPrimaryColor( TRgb aColor );
       
   175 		/**
       
   176  	    * Sets secondary color for the radio idle
       
   177  	    * @param aColor The color that is used as secondary color of radio idle
       
   178  	    */
       
   179 		void SetSecondaryColor( TRgb aColor );
       
   180 		/**
       
   181  	    * Sets the background color of the radio idle
       
   182  	    * @param aColor The color that is used as the background color of the radio idle
       
   183  	    */
       
   184 		void SetBackgroundColor( TRgb aColor );
       
   185 		/**
       
   186  	    * Return orientation of the display
       
   187  	    */
       
   188 		TOrientation Orientation();
       
   189 		/**
       
   190  	    * Set orientation of the display
       
   191  	    * @param aOrientation The display orientation
       
   192  	    */
       
   193 		void SetOrientation( TOrientation aOrientation );
       
   194 		/**
       
   195 		* Calculates display layout
       
   196 	    */
       
   197 		void UpdateLayout();
       
   198 		/**
       
   199  	    * From MIRRadioIdleCommandObserver, takes care of radio idle command handling.
       
   200  	    * @param aCommand Radio idle command
       
   201  	    */
       
   202         void HandleCommandL( TRadioIdleCommand aCommand );
       
   203      
       
   204 private:
       
   205 		/**
       
   206 		* C++ default constructor
       
   207 		*/
       
   208 		CIRRadioIdle();
       
   209 		/**
       
   210 	    * EPOC second phase constructor.
       
   211 	    * @param aEnv  Reference to the Hitchcock environment instance.
       
   212 	    * @param aControlGroupId  Id of the control group to which radio idle belongs.
       
   213 	    * @param aParentLayout  Pointer to parent layout.
       
   214 	    */
       
   215 		void ConstructL( CAlfEnv& aEnv, TInt aControlGroupId, CAlfLayout* aParentLayout );
       
   216 
       
   217 private:	// New functions
       
   218 
       
   219 		/** Scroll directions for the radio idle item. */
       
   220 		enum TRadioIdleItemScrollDirection
       
   221 			{
       
   222 			EScrollLeftToRight = 0xA0,
       
   223 			EScrollRightToLeft,
       
   224 			EScrollNone
       
   225 			};
       
   226 
       
   227 		/** Custom events for the radio idle. */
       
   228 		enum TRadioIdleCustomEvent
       
   229 			{
       
   230 			ERadioIdleItemTransformationEnd = 0x5B,
       
   231 			ERadioIdleBackgroundTextScrollEnd,
       
   232 			EAfterStartupDelay,
       
   233 			ERadioIdleChangeMode,
       
   234 			ERadioIdleEventNone,
       
   235 			ERadioIdleFadeOutCompleted
       
   236 			};
       
   237 
       
   238 		/**
       
   239  	    * Suspends radio idle and starts it again after startup delay
       
   240  	    */
       
   241 		void SuspendRadioIdle();
       
   242 		/**
       
   243  	    * Stops radio idle. Radio idle is set to stopped state.
       
   244  	    */
       
   245 		void ShutdownRadioIdle();
       
   246 		/**
       
   247  	    * Launches radio idle immediately.
       
   248  	    * The background bitmap fades out and at the same time radio idle fades in
       
   249  	    */
       
   250 		void StartRadioIdleL();
       
   251 		/**
       
   252 		 * Starts radio idle again without reseting radio idle items.
       
   253 		 */
       
   254 		void RefreshL();
       
   255 		/**
       
   256  	    * Creates radio idle with passed number of the radio idle items
       
   257  	    * @param aNumberOfRadioIdleItems Number of the radio idle items
       
   258  	    */
       
   259 		void AddRadioIdleL( const TInt aNumberOfRadioIdleItems );
       
   260 		/**
       
   261  	    * Creates the radio idle item to the passed radio idle view port.
       
   262  	    * @param aRadioIdle The view port of the radio idle, ownership now transferred
       
   263  	    * @param aRadioIdleItemText Text of the radio idle item
       
   264  	    * @param aRadioIdleItemHasBackground TBool to indicate background visibility
       
   265  	    * @param aBackgroundColor The background color of the radio idle item
       
   266  	    * @param aBackgroundOpacity The background opacity of the radio idle item
       
   267  	    */
       
   268 		CAlfTextVisual* AddRadioIdleItemL( CAlfLayout* aRadioIdle,
       
   269 										   const TDesC& aRadioIdleItemText,
       
   270 										   const TDesC8& aTag,
       
   271 									       TBool aRadioIdleItemHasBackground = EFalse,
       
   272 										   const TRgb& aBackgroundColor = KRgbWhite,
       
   273 										   const TReal32 aBackgroundOpacity = 0.5f );
       
   274 		/**
       
   275  	    * Creates, initializes and animates the radio idle background text visual
       
   276  	    */
       
   277 		void CreateBacgroundTextVisualL();
       
   278 		/**
       
   279  	    * Initializes the radio idle items
       
   280  	    * @param aNumberOfRadioIdleItems Number of the radio idle items
       
   281  	    */
       
   282 		void InitializeRadioIdleItemsL( const TInt aNumberOfRadioIdleItems );
       
   283 		/**
       
   284  	    * Sets defined animation to the created radio idle items
       
   285  	    */
       
   286 		void AnimateRadioIdleItems();
       
   287 		/**
       
   288  	    * Retrieves text from randomly chosen radio idle item.
       
   289  	    * Transfers ownership.
       
   290  	    */
       
   291 		HBufC* GetRandomRadioIdleContentL();
       
   292 		/**
       
   293  	    * Sets color, opacity and scaling settings to the radio idle item
       
   294  	    * @param aRadioIdleItem The radio idle item, ownership not transferred
       
   295  	    * @param aRadioIdleItemText Text of the radio idle item
       
   296  	    * @param aTextStyleId Text style for text of the radio idle item
       
   297  	    */
       
   298 		void SetRadioIdleItemSettingsL( CAlfTextVisual* aRadioIdleItem, const TDesC& aRadioIdleItemText,
       
   299 										const TInt aTextStyleId );
       
   300 		/**
       
   301  	    * Sets translating animations to the radio idle item
       
   302  	    * @param aRadioIdleItem The radio idle item, ownership not transferred
       
   303  	    * @param aRandomSeed
       
   304  	    */
       
   305 		void SetRadioIdleItemAnimation( CAlfTextVisual* aRadioIdleItem );
       
   306 
       
   307 		/**
       
   308 	    * Sets the radio idle mode
       
   309 		*/
       
   310 		void SetMode( TRadioIdleMode aMode );
       
   311 		/**
       
   312 	    * Fades in radio idle
       
   313 	    * @param aNow If ETrue shows radio idle immediately otherwise
       
   314 	    * fades with defined fading duration
       
   315 		*/
       
   316 		void RadioIdleFadeIn( TBool aNow = EFalse );
       
   317 		/**
       
   318 	    * Fades out radio idle
       
   319 	    * @param aNow If ETrue hides radio idle immediately otherwise
       
   320 	    * fades with defined fading duration
       
   321 		*/
       
   322 		void RadioIdleFadeOut( TBool aNow = EFalse );
       
   323 		/**
       
   324  	    * Sets and starts scrolling animation to CAlfTextVisual.
       
   325  	    * The visual object is scrolled from current position to
       
   326  	    * right side of the display
       
   327  	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   328  	    */
       
   329 		void ScrollToRight( CAlfTextVisual* aVisual ) const;
       
   330 		/**
       
   331  	    * Sets and starts scrolling animation to CAlfTextVisual.
       
   332  	    * The visual object is scrolled from current position to
       
   333  	    * left side of the display
       
   334  	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   335  	    */
       
   336 		void ScrollToLeft( CAlfTextVisual* aVisual ) const;
       
   337 		/**
       
   338 	    * todo
       
   339  	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   340  	    * @param aTransitionTime Duration for reaching the target.
       
   341  	    * @param aEventAfterScrollingEnd todo custom even that will be sent when transition time is end
       
   342  	    */
       
   343 		void SetScrollingToBackgroundText( CAlfTextVisual* aVisual,
       
   344 							    TInt aTransitionTime,
       
   345 							    TRadioIdleCustomEvent aEventAfterScrollingEnd = ERadioIdleEventNone ) ;
       
   346 		/**
       
   347 	    * Sets fade-in animation to the CAlfVisual.
       
   348 	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   349 	    * @param aTime Time duration after the visual object has been faded in. Fading duration in milliseconds
       
   350 	    * @param aOpacity Target opacity value
       
   351 	    */
       
   352 		void FadeIn( CAlfVisual* aVisual, TInt aFadingTime, TReal32 aOpacity = 1.0f ) const;
       
   353 		/**
       
   354 	    * Sets fade-out animation to the CAlfVisual.
       
   355 	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   356 	    * @param aTime Time duration after the visual object has been faded out. Fading duration in milliseconds
       
   357 	    * @param aOpacity Target opacity value
       
   358 	    */
       
   359 		void FadeOut( CAlfVisual* aVisual, TInt aFadingTime, TReal32 aOpacity = 0.0f ) const;
       
   360 		/**
       
   361  	    * Translates the visual object with passed arguments
       
   362  	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   363  	    * @param aX Translation value in the horizontal direction
       
   364  	    * @param aY Translation value in the vertical direction
       
   365  	    */
       
   366 		void Translate( CAlfTextVisual* aTextVisual, const TAlfTimedValue& aX, 
       
   367 						const TAlfTimedValue& aY );
       
   368 		/**
       
   369  	    * Scales the visual object with passed arguments
       
   370  	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   371  	    * @param aX Scaling value in the horizontal direction
       
   372  	    * @param aY Scaling value in the vertical direction
       
   373  	    */
       
   374 		void Scale( CAlfTextVisual* aTextVisual, const TAlfTimedValue& aX, const TAlfTimedValue& aY );
       
   375 		/**
       
   376  	    * Removes all transformations of the visual object such as the scaling and translating.
       
   377  	    * @param aVisual a pointer to the visual object, ownership not transferred
       
   378  	    */
       
   379 		void LoadTextVisualIdentity( CAlfTextVisual* aTextVisual );
       
   380 	    /**
       
   381 	     * Converts CAlfVisual reference to pointer
       
   382 	     */
       
   383 	    CAlfVisual* GetPointer( CAlfVisual& aRef );	    
       
   384         /**
       
   385          * Callback for radio idle item transformation end.
       
   386          */
       
   387 		void HandleRadioIdleItemTransformationEndEventL( const TAlfEvent& aEvent );
       
   388 		/**
       
   389 		 * Callback for background text transformation end.
       
   390 		 */
       
   391         void HandleBackgroundTextScrollEndEventL( const TAlfEvent& aEvent );
       
   392 		/**
       
   393 		 * Randomly modifies a component of a radio idle text color.
       
   394 		 */
       
   395         TInt DeviateColorComponent( TInt aBaseValue );
       
   396         
       
   397 private:	// Data
       
   398 
       
   399 		/** Display orientation */
       
   400 	    TOrientation iOrientation;
       
   401 
       
   402 	    /** Visual of radio idle content. Not owned. */
       
   403 	    CAlfViewportLayout* iViewport;
       
   404 	    /** Parent layout. Not owned. */
       
   405 	    CAlfLayout* iParentLayout;
       
   406 	    /** Layout for radio idle */
       
   407 	    TAknLayoutRect iRadioIdleLayout;
       
   408 
       
   409 	    /** Fade style for radio idle */
       
   410 	    TRadioIdleFadeStyle iFadeStyle;
       
   411 	    /** States of radio idle */
       
   412 		TRadioIdleState iRadioIdleState;
       
   413 		/** Keeps track of the current radio idle mode */
       
   414 		TRadioIdleMode  iRadioIdleMode;
       
   415 		/** Keeps track of the requested mode */
       
   416 		TRadioIdleMode  iRadioIdleRequestedMode;
       
   417 	    /** Counts the items that have finished their transformations for mode change */
       
   418 		TInt iItemsTransformationEndEventCounter;
       
   419 
       
   420 	    /** Color to be used for the radio idle items */
       
   421 	    TRgb iRadioIdlePrimaryColor;
       
   422 	    /** Color to be used for the radio idle items */
       
   423 	    TRgb iRadioIdleSecondaryColor;
       
   424 	    /** Scroll direction for the radio idle item */
       
   425 	    TRadioIdleItemScrollDirection iScrollDirection;
       
   426 
       
   427 		/** Array for the strings of the radio idle items. Owned. */
       
   428         CDesCArrayFlat* iRadioIdleItemArray;
       
   429 		/** Array for the text styles of the radio idle items */
       
   430         RArray<TInt> iTextStyleIdArray;
       
   431 
       
   432         /** Background of radio idle. Not owned.*/
       
   433 		CAlfGradientBrush* iRadioIdleBackgroundGradientBrush;
       
   434         /** Text style id of the radio idle background text */
       
   435         TInt iRadioIdleItemBackgroundTextStyleId;
       
   436         /** Color that is used as the background color of radio idle */
       
   437 	    TRgb iRadioIdleBackgroundColor;
       
   438 	    /** Scroll direction for the radio idle background text */
       
   439 	    TRadioIdleItemScrollDirection iBackgroundTextScrollDirection;
       
   440 	    /** Indicates whether fading is ongoing */
       
   441 	    TBool iFading;
       
   442 	    /** Indicates whether there was a startup try when fading out radio idle */
       
   443 	    TBool iDelayedStartup;
       
   444 
       
   445 	};
       
   446 
       
   447 #endif /*VRRADIOIDLE_H_*/