idlehomescreen/nativeuicontroller/src/ainavipaneanimator.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Navipane animator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ainavipaneanimator.h"
       
    20 #include "aistatuspanel.h"
       
    21 #include "ainavipaneanimatorcallback.h"
       
    22 
       
    23 using namespace AiNativeUiController;
       
    24 
       
    25 const TInt KAnimDelay = 2000000;
       
    26 
       
    27 
       
    28 CAiNaviPaneAnimator::CAiNaviPaneAnimator( CAiStatusPanel& aStatusPane,
       
    29                 AiNativeUiModel::TRenderingPriorities& aPriorities,
       
    30                 MAiNaviPaneAnimatorCallback& aCallback )
       
    31     : iStatusPane( aStatusPane ),
       
    32         iPriorities( aPriorities ),
       
    33         iCallback( aCallback )
       
    34     {
       
    35     }
       
    36 
       
    37 
       
    38 void CAiNaviPaneAnimator::ConstructL()
       
    39     {
       
    40     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
    41     }
       
    42 
       
    43 
       
    44 CAiNaviPaneAnimator* CAiNaviPaneAnimator::NewL( CAiStatusPanel& aStatusPane,
       
    45                 AiNativeUiModel::TRenderingPriorities& aPriorities,
       
    46                 MAiNaviPaneAnimatorCallback& aCallback )
       
    47     {
       
    48     CAiNaviPaneAnimator* self = new( ELeave )CAiNaviPaneAnimator( aStatusPane,
       
    49                                                             aPriorities,
       
    50                                                             aCallback );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 CAiNaviPaneAnimator::~CAiNaviPaneAnimator()
       
    59     {
       
    60     iAnimArray.ResetAndDestroy();
       
    61     if( iPeriodic )
       
    62         {
       
    63         iPeriodic->Cancel();
       
    64         delete iPeriodic;
       
    65         }
       
    66     }
       
    67 
       
    68 
       
    69 void CAiNaviPaneAnimator::AddItemL( TInt aContentId, const TDesC16& aText )
       
    70     {
       
    71     const TInt count = iAnimArray.Count();
       
    72     for( TInt i = 0; i < count; i++ )
       
    73         {
       
    74         if( iAnimArray[i]->Name() == aContentId )
       
    75             {
       
    76             iAnimArray[i]->SetValueL( aText );
       
    77             return;
       
    78             }
       
    79         }
       
    80 
       
    81     CAiNameValuePair* newItem = CAiNameValuePair::NewLC(
       
    82                                                     aContentId,
       
    83                                                     aText );
       
    84     User::LeaveIfError( iAnimArray.Append( newItem ) );
       
    85     CleanupStack::Pop( newItem );
       
    86     }
       
    87 
       
    88 
       
    89 void CAiNaviPaneAnimator::RemoveItem( TInt aContentId )
       
    90     {
       
    91     const TInt count = iAnimArray.Count();
       
    92     for( TInt i = 0; i < count; i++ )
       
    93         {
       
    94         if( iAnimArray[i]->Name() == aContentId )
       
    95             {
       
    96             delete iAnimArray[i];
       
    97             iAnimArray[i] = NULL;
       
    98             iAnimArray.Remove( i );
       
    99             return;
       
   100             }
       
   101         }
       
   102     }
       
   103 
       
   104 
       
   105 void CAiNaviPaneAnimator::CancelAnimationL()
       
   106     {
       
   107     if( iPeriodic->IsActive() )
       
   108         {
       
   109         iPeriodic->Cancel();
       
   110         iCurrentItem = 0;
       
   111         iCallback.AnimationCompleteL();
       
   112         }
       
   113     }
       
   114 
       
   115 TBool CAiNaviPaneAnimator::IsActive()
       
   116 	{
       
   117 	return iPeriodic->IsActive();
       
   118 	}
       
   119 
       
   120 void CAiNaviPaneAnimator::AnimateL()
       
   121     {
       
   122     if( !iPeriodic->IsActive() )
       
   123         {
       
   124         SortAnimArrayL();
       
   125         //draw first item immediately
       
   126         if( DrawTextL() )
       
   127             {
       
   128             iPeriodic->Start( KAnimDelay, KAnimDelay, TCallBack( AnimCallback, this ) );
       
   129             }
       
   130         }
       
   131     }
       
   132 
       
   133 
       
   134 TInt CAiNaviPaneAnimator::AnimCallback( TAny* aPtr )
       
   135     {
       
   136     CAiNaviPaneAnimator* self = static_cast<CAiNaviPaneAnimator*>( aPtr );
       
   137 
       
   138     if( self )
       
   139         {
       
   140         TRAP_IGNORE( self->DrawTextL() );
       
   141         }
       
   142 
       
   143     return KErrNone;
       
   144     }
       
   145 
       
   146 
       
   147 TBool CAiNaviPaneAnimator::DrawTextL()
       
   148     {
       
   149     if( iCurrentItem < iAnimArray.Count() )
       
   150         {
       
   151         iStatusPane.SetNaviPaneTextL( iAnimArray[iCurrentItem]->Value() );
       
   152         iStatusPane.RenderNaviPaneL();
       
   153         ++iCurrentItem;
       
   154         return ETrue;
       
   155         }
       
   156     else
       
   157         {
       
   158         iPeriodic->Cancel();
       
   159         iCurrentItem = 0;
       
   160         iCallback.AnimationCompleteL();
       
   161         return EFalse;
       
   162         }
       
   163     }
       
   164 
       
   165 void CAiNaviPaneAnimator::SortAnimArrayL()
       
   166     {
       
   167     const TInt count = iAnimArray.Count();
       
   168     
       
   169     // loop through the animator array and sort items in priority order
       
   170     for( TInt i = 0; i < count - 1; i++ )
       
   171         {
       
   172         for( TInt k = i + 1; k < count; k++)
       
   173             {
       
   174             if( iPriorities.RenderingPriority( iAnimArray[i]->Name() ) <
       
   175                 iPriorities.RenderingPriority( iAnimArray[k]->Name() ) )
       
   176                 {
       
   177                 CAiNameValuePair* temp = iAnimArray[k];
       
   178                 iAnimArray[k] = iAnimArray[i];
       
   179                 iAnimArray[i] = temp;
       
   180                 }
       
   181             }
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 CAiNaviPaneAnimator::CAiNameValuePair*
       
   187 CAiNaviPaneAnimator::CAiNameValuePair::NewLC( const TInt aName,
       
   188                                                 const TDesC& aValue )
       
   189     {
       
   190     CAiNameValuePair* self = new( ELeave ) CAiNameValuePair();
       
   191     CleanupStack::PushL( self );
       
   192     self->ConstructL( aName, aValue );
       
   193     return self;
       
   194     }
       
   195 
       
   196 
       
   197 void CAiNaviPaneAnimator::CAiNameValuePair::ConstructL( const TInt aName,
       
   198                                                         const TDesC& aValue )
       
   199     {
       
   200     iName = aName;
       
   201     iValue = aValue.AllocL();
       
   202     }
       
   203 
       
   204 
       
   205 CAiNaviPaneAnimator::CAiNameValuePair::~CAiNameValuePair()
       
   206     {
       
   207     delete iValue;
       
   208     }
       
   209 
       
   210 
       
   211 TInt CAiNaviPaneAnimator::CAiNameValuePair::Name() const
       
   212     {
       
   213     return iName;
       
   214     }
       
   215 
       
   216 
       
   217 const TDesC16& CAiNaviPaneAnimator::CAiNameValuePair::Value() const
       
   218     {
       
   219     return *iValue;
       
   220     }
       
   221 
       
   222 
       
   223 void CAiNaviPaneAnimator::CAiNameValuePair::SetValueL( const TDesC& aValue )
       
   224     {
       
   225     HBufC* temp = aValue.AllocL();
       
   226     delete iValue;
       
   227     iValue = temp;
       
   228     }