startupservices/Startup/src/StartupOperatorAnimation.cpp
branchRCL_3
changeset 19 924385140d98
parent 18 0818dd463d41
child 20 c2c61fdca848
equal deleted inserted replaced
18:0818dd463d41 19:924385140d98
     1 /*
       
     2 * Copyright (c) 2003 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 *     This class is the container class of the CStartupOperatorAnimation.
       
    16 *     Is used to show operator animation.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <aknappui.h>
       
    23 #include <aknnotewrappers.h>
       
    24 #include <barsread.h> //use of TResourceReader
       
    25 #include <aknbitmapanimation.h>
       
    26 #include "StartupOperatorAnimation.h"
       
    27 #include <Startup.rsg>
       
    28 #include "StartupDefines.h"
       
    29 #include "Startup.hrh"
       
    30 #include "StartupAppUi.h"
       
    31 #include <operatoranimation.rsg>
       
    32 #include <ConeResLoader.h>
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // Path to operator variated animation
       
    37 _LIT( KOperatorAnimationResource, "z:operatoranimation.rsc" );
       
    38 
       
    39 //Constants used in OfferKeyEventL
       
    40 const TInt KTimerDelay( 10000);
       
    41 const TInt KTimerInterval( 10000);
       
    42 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CStartupOperatorAnimation::ConstructL(const TRect& aRect)
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // Need different ConstructL from base class CStartupWelcomeAnimation
       
    49 // because different animation file and time are loaded.
       
    50 // ---------------------------------------------------------------------------
       
    51 void CStartupOperatorAnimation::ConstructL(const TRect& /*aRect*/)
       
    52     {
       
    53     TRACES("CStartupOperatorAnimation::ConstructL()");
       
    54     UpdateDrawInfo( EStartupDIStart );
       
    55     CreateWindowL();
       
    56     iAnimCancelTimer = CPeriodic::NewL( EPriorityNormal );
       
    57 
       
    58     TRACES("CStartupOperatorAnimation::ConstructL(): Animation loading started");
       
    59     iAnim = CAknBitmapAnimation::NewL();
       
    60     iAnim->ExcludeAnimationFramesFromCache();
       
    61     iAnim->SetContainerWindowL( *this );
       
    62     iAnim->SetScaleModeForAnimationFrames(EAspectRatioPreservedAndUnusedSpaceRemoved);
       
    63     TResourceReader rr;
       
    64     RConeResourceLoader loader( *CEikonEnv::Static() );
       
    65 
       
    66     TParse* fp = new(ELeave) TParse(); 
       
    67     fp->Set(KOperatorAnimationResource, &KDC_APP_RESOURCE_DIR, NULL);
       
    68     TRACES1("CStartupOperatorAnimation::ConstructL(): Operator animation resource path: '%S'", &fp->FullName());
       
    69     TFileName name( fp->FullName() );
       
    70     delete fp;
       
    71 
       
    72     TInt fileError = loader.Open( name );
       
    73     if ( fileError == KErrNone )
       
    74         {
       
    75         CleanupClosePushL( loader );
       
    76         iCoeEnv->CreateResourceReaderLC(rr, R_OPERATOR_IMAGE);
       
    77         TRAPD(err, iAnim->ConstructFromResourceL( rr ));
       
    78         TRACES1("CStartupOperatorAnimation::ConstructL(): Operator animation: err = %d", err);
       
    79         if( err == KErrNone )
       
    80             {
       
    81             TResourceReader timeReader;
       
    82             iCoeEnv->CreateResourceReaderLC(timeReader, R_ANIM_DURATION);
       
    83             iShowingTime = timeReader.ReadInt16();
       
    84             TRACES1("CStartupOperatorAnimation::ConstructL(): Operator animation showing time: %d", iShowingTime );
       
    85             CleanupStack::PopAndDestroy(); // pop timeReader
       
    86             }
       
    87         else
       
    88             {
       
    89             iShowingTime = 0;
       
    90             TRACES("CStartupOperatorAnimation::ConstructL(): Animation loading failed");
       
    91             }
       
    92         CleanupStack::PopAndDestroy(); //pop rr
       
    93         TRACES("CStartupOperatorAnimation::ConstructL(): Animation loading ended");
       
    94         CleanupStack::PopAndDestroy(); //pop loader
       
    95         }
       
    96     else
       
    97         {
       
    98         TRACES("CStartupOperatorAnimation::ConstructL(): Resource file loading failed");
       
    99         }
       
   100 
       
   101     
       
   102     SetRect(iAvkonAppUi->ApplicationRect());
       
   103     iAnim->SetPosition( TPoint( (iAvkonAppUi->ApplicationRect().Width()/2) - (iAnim->BitmapAnimData()->Size().iWidth/2), 
       
   104                                 (iAvkonAppUi->ApplicationRect().Height()/2) - (iAnim->BitmapAnimData()->Size().iHeight/2) ) );
       
   105     ActivateL();
       
   106 
       
   107     TRACES("CStartupOperatorAnimation::ConstructL(): End");
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CStartupOperatorAnimation::NewL
       
   112 // Two-phased constructor.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 CStartupOperatorAnimation* CStartupOperatorAnimation::NewL( CStartupAppUi* aStartupAppUi,
       
   116                                                             const TRect& aRect)
       
   117     {
       
   118     TRACES("CStartupOperatorAnimation::NewL()");
       
   119     CStartupOperatorAnimation* self = new (ELeave) CStartupOperatorAnimation( aStartupAppUi );
       
   120     CleanupStack::PushL(self);
       
   121     self->ConstructL(aRect);
       
   122     CleanupStack::Pop();
       
   123     return self;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CStartupOperatorAnimation::CStartupOperatorAnimation()
       
   128 // ---------------------------------------------------------
       
   129 CStartupOperatorAnimation::CStartupOperatorAnimation( CStartupAppUi* aStartupAppUi ) : 
       
   130     CStartupWelcomeAnimation(aStartupAppUi)
       
   131     { 
       
   132     TRACES("CStartupOperatorAnimation::CStartupOperatorAnimation()");
       
   133     iShowingTime = 0;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CStartupOperatorAnimation::OfferKeyEventL(...)
       
   138 // ---------------------------------------------------------------------------
       
   139 TKeyResponse CStartupOperatorAnimation::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
       
   140     {
       
   141     TRACES("CStartupWelcomeAnimation::OfferKeyEventL()");
       
   142     if( iAnimationShowing && !iStartupAppUi->HiddenReset() && !iAnimationCancelled )
       
   143         {
       
   144         // Cancel animation
       
   145         UpdateDrawInfo( EStartupDIOperatorAnimCancelled );
       
   146         EndAnimation();
       
   147         TRACES("CStartupWelcomeAnimation::OfferKeyEventL(): Timer activated - before");
       
   148         iAnimCancelTimer->Start( KTimerDelay, KTimerInterval,
       
   149             TCallBack( iStartupAppUi->DoStopTimingL, iStartupAppUi ) );
       
   150         TRACES("CStartupOperatorAnimation::OfferKeyEventL(): Timer activated - after");
       
   151         iAnimationCancelled = ETrue;
       
   152         }
       
   153     else if( !iAnimationShowing && iStartupAppUi->OperatorTonePlaying())
       
   154         {
       
   155         TRACES("CStartupOperatorAnimation::OfferKeyEventL() Animation has completed but tone is still playing. Stop it.");
       
   156         iStartupAppUi->StopOperatorTone();
       
   157         }
       
   158 
       
   159     TRACES("CStartupOperatorAnimation::OfferKeyEventL(): End");
       
   160     return EKeyWasConsumed;
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CStartupOperatorAnimation::DoDrawing()
       
   165 // ---------------------------------------------------------------------------
       
   166 void CStartupOperatorAnimation::DoDrawing() const
       
   167     {
       
   168 //    These are the cases handled in this function
       
   169 //    EStartupDIOperatorAnimStart,
       
   170 //    EStartupDIOperatorAnimCancelled,
       
   171 //    EStartupDIOperatorAnimEnd
       
   172 //    EStartupDISystemFatalError
       
   173     TRACES("CStartupOperatorAnimation::DoDrawing()");
       
   174     TRACES1("CStartupOperatorAnimation::DoDrawing():  %d ", iDrawUpdateInfo );
       
   175     switch ( iDrawUpdateInfo )
       
   176         {
       
   177 
       
   178         case EStartupDIOperatorAnimStart:
       
   179             {
       
   180             TRACES("CStartupOperatorAnimation::DoDrawing(): EStartupDIOperatorAnimStart");
       
   181             }
       
   182             break;
       
   183         case EStartupDIOperatorAnimCancelled:
       
   184             {
       
   185             TRACES("CStartupOperatorAnimation::DoDrawing(): EStartupDIOperatorAnimCancelled");
       
   186             EndAnimation();
       
   187             TRAPD(err,iStartupAppUi->StopTimingL());
       
   188             if (err != KErrNone)
       
   189                 {
       
   190                 TRACES1("CStartupOperatorAnimation::DoDrawing(): StopTimingL() leaves, err = %d", err );
       
   191                 }
       
   192             }
       
   193             break;
       
   194         case EStartupDIOperatorAnimEnd:
       
   195             {
       
   196             TRACES("CStartupOperatorAnimation::DoDrawing(): EStartupDIOperatorAnimEnd");
       
   197             }
       
   198             break;
       
   199         case EStartupDISystemFatalError:
       
   200             {
       
   201             }
       
   202             break;
       
   203         default:
       
   204             break;
       
   205         }
       
   206     }