idlehomescreen/xmluirendering/renderingplugins/xnanimationfactory/src/xnanimationadapter.cpp
changeset 4 4d54b72983ae
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  Xuikon Bitmap Plugin.
       
    15 *
       
    16 */
       
    17 #include <AknsUtils.h>
       
    18 #include <aknsdrawutils.h>
       
    19 #include <aknsconstants.h>
       
    20 #include <barsread.h>
       
    21 #include "xnnodepluginif.h"
       
    22 #include "xndomproperty.h"
       
    23 #include "xnproperty.h"
       
    24 #include "xncontroladapter.h"
       
    25 
       
    26 #include "xnanimationadapter.h"
       
    27 
       
    28 const TInt KPeriodicTimerInterval5Sec(100000); // 0.1 sec
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CXnAnimationAdapter::NewL
       
    33 // Symbian static 1st phase constructor
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CXnAnimationAdapter* CXnAnimationAdapter::NewL(CXnNodePluginIf& aNode)
       
    37     {
       
    38 	CXnAnimationAdapter* self = new( ELeave ) CXnAnimationAdapter( aNode );
       
    39     
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL( aNode );
       
    42     CleanupStack::Pop();
       
    43 
       
    44     return self;	
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CXnAnimationAdapter::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CXnAnimationAdapter::ConstructL(CXnNodePluginIf& aNode)
       
    53     {
       
    54     CXnControlAdapter::ConstructL( aNode );
       
    55     iSkinId = KAknsIIDNone;
       
    56     iAnimationSarted = EFalse;
       
    57     }
       
    58     
       
    59 // -----------------------------------------------------------------------------
       
    60 // CXnAnimationAdapter::CXnAnimationAdapter
       
    61 // C++ default constructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CXnAnimationAdapter::CXnAnimationAdapter(CXnNodePluginIf& aNode) : iNode( aNode )    
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CXnAnimationAdapter::~CXnAnimationAdapter
       
    70 // C++ destructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CXnAnimationAdapter::~CXnAnimationAdapter()
       
    74     {
       
    75     if (iPeriodicTimer)
       
    76         {
       
    77         iPeriodicTimer->Cancel();
       
    78         delete iPeriodicTimer;
       
    79         iPeriodicTimer = NULL;
       
    80         }
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CXnAnimationAdapter::Draw
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CXnAnimationAdapter::Draw(const TRect& aRect) const
       
    89     {
       
    90     CXnControlAdapter::Draw( aRect );    
       
    91     AknsDrawUtils::DrawCachedImage( AknsUtils::SkinInstance(),
       
    92                SystemGc(), aRect, iSkinId  );
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CXnAnimationAdapter::HandlePropertyChangeL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CXnAnimationAdapter::DoHandlePropertyChangeL( CXnProperty* aProperty )
       
   100     {
       
   101     if( aProperty )
       
   102         {
       
   103         const TDesC8& name( aProperty->Property()->Name( ) );
       
   104         
       
   105         if( name == XnPropertyNames::style::common::KDisplay )
       
   106            {
       
   107            const TDesC8& display( aProperty->StringValue() );
       
   108  
       
   109            if( display == XnPropertyNames::style::common::display::KBlock )
       
   110                {
       
   111                iDisplay = ETrue; 
       
   112                StartAnimation();
       
   113                }    
       
   114            else
       
   115                {
       
   116                iDisplay = EFalse;
       
   117                StopAnimation();
       
   118                }
       
   119            }
       
   120         }
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CXnNewstickerAdapter::MakeVisible()
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CXnAnimationAdapter::MakeVisible( TBool aVisible )
       
   128     {
       
   129     if( aVisible )
       
   130         {
       
   131         StartAnimation();
       
   132         }
       
   133     else
       
   134         {
       
   135         StopAnimation();
       
   136         }
       
   137     CCoeControl::MakeVisible( aVisible );
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CXnAnimationAdapter::Update
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CXnAnimationAdapter::Update()
       
   145     {
       
   146     if (iAnimationSarted )
       
   147         {
       
   148         switch(iSkinId.iMinor )
       
   149             {
       
   150             case EAknsMinorGenericQgnHomeRefreshing1:
       
   151                 {
       
   152                 iSkinId.Set(KAknsIIDQgnHomeRefreshing2);
       
   153                 }
       
   154                 break;
       
   155             case EAknsMinorGenericQgnHomeRefreshing2:
       
   156                 {
       
   157                 iSkinId.Set(KAknsIIDQgnHomeRefreshing3);
       
   158                 }
       
   159                 break;
       
   160             case EAknsMinorGenericQgnHomeRefreshing3:
       
   161                 {
       
   162                 iSkinId.Set(KAknsIIDQgnHomeRefreshing4);
       
   163                 }
       
   164                 break;                
       
   165             case EAknsMinorGenericQgnHomeRefreshing4:
       
   166                 {
       
   167                 iSkinId.Set(KAknsIIDQgnHomeRefreshing1);
       
   168                 }
       
   169                 break;
       
   170             default :
       
   171                 break;
       
   172             };
       
   173         DrawNow();
       
   174         }
       
   175     }
       
   176 
       
   177 // ----------------------------------------------------------------------------
       
   178 // CXnAnimationAdapter::PeriodicTimerCallBack(TAny* aAny)
       
   179 // The call back function.
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 TInt CXnAnimationAdapter::TimerCallBack(TAny* aAny)
       
   183     {
       
   184     CXnAnimationAdapter* self = static_cast<CXnAnimationAdapter*> (aAny);
       
   185 
       
   186     // Update widget every 5 seconds
       
   187     self->Update();
       
   188 
       
   189     return KErrNone; // Return value ignored by CPeriodic
       
   190     }
       
   191 
       
   192 // ----------------------------------------------------------------------------
       
   193 // CXnAnimationAdapter::StartAnimation()
       
   194 // ----------------------------------------------------------------------------
       
   195 //
       
   196 void CXnAnimationAdapter::StartAnimation()
       
   197     {
       
   198     if ( !iAnimationSarted && iDisplay )
       
   199         {
       
   200        TRAPD(err, iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle) );
       
   201        if ( err == KErrNone )
       
   202            {
       
   203            iPeriodicTimer->Start( KPeriodicTimerInterval5Sec,
       
   204                    KPeriodicTimerInterval5Sec, TCallBack( TimerCallBack, this ) );
       
   205            iSkinId = KAknsIIDQgnHomeRefreshing1;
       
   206            iAnimationSarted = ETrue;
       
   207            }
       
   208         }
       
   209     }
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // CXnAnimationAdapter::StopAnimation()
       
   213 // ----------------------------------------------------------------------------
       
   214 //
       
   215 void CXnAnimationAdapter::StopAnimation()
       
   216     {
       
   217     if ( iAnimationSarted )
       
   218         {
       
   219         iPeriodicTimer->Cancel();
       
   220         delete iPeriodicTimer;
       
   221         iPeriodicTimer = NULL;
       
   222         iSkinId = KAknsIIDNone;
       
   223         iAnimationSarted = EFalse;
       
   224         }
       
   225     }
       
   226 
       
   227 // End of File
       
   228