/**
 * Set a new animation
 *
 * Redo layout and full redraw (partial layout and redraw left
 * for future extensions)
 */
void CAknNoteAttributes::SetAnimationL(TInt aResourceId)
{
    if (aResourceId <= 0)
        return;

    delete iAnimation;
    iAnimation = NULL;
    iAnimation = CAknBitmapAnimation::NewL();

    iAnimationID = aResourceId;

    if (iAnimationID == R_QGN_GRAF_WAIT_BAR_ANIM)
    {
        iAnimation->SetScaleModeForAnimationFrames(EAspectRatioNotPreserved);
    }

    CCoeEnv* coe = CCoeEnv::Static();

    TAknsItemID iid;
    iid.Set( EAknsMajorAvkon, aResourceId );

    TBool animation ( EFalse );
    TRAPD( err, animation = iAnimation->ConstructFromSkinL ( iid ) );

    if ( err != KErrNone || !animation )
    {
        TResourceReader readerForAnimation;
        coe->CreateResourceReaderLC(readerForAnimation,aResourceId);
        iAnimation->ConstructFromResourceL(readerForAnimation);
        CleanupStack::PopAndDestroy(); // readerForAnimation
    }

// FIXME: Experimental heuristics for finding out popup context from image/animation
#ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
    switch ( aResourceId )
    {
    case EAknsMinorQgnNoteOkAnim:
        CAknTransitionUtils::SetData( ( TInt )iNoteControl,
                                      ( TAny* )KGfxConfirmationNoteControlUid.iUid );
        break;
    case EAknsMinorQgnNoteErrorAnim:
        CAknTransitionUtils::SetData( ( TInt )iNoteControl,
                                      ( TAny* )KGfxErrorNoteControlUid.iUid );
        break;
    case EAknsMinorQgnNoteInfoAnim:
        CAknTransitionUtils::SetData( ( TInt )iNoteControl,
                                      ( TAny* )KGfxInformationNoteControlUid.iUid );
        break;
    case EAknsMinorQgnNoteWarningAnim:
        CAknTransitionUtils::SetData( ( TInt )iNoteControl,
                                      ( TAny* )KGfxWarningNoteControlUid.iUid );
        break;
    case EAknsMinorQgnGrafBarWaitAnim:
        CAknTransitionUtils::SetData( ( TInt )iNoteControl,
                                      ( TAny* )KGfxWaitNoteControlUid.iUid );
        break;
    default:
        break;
    }
#endif

    // If the image exists, but the dialog does not need it (is neither progress
    // nor wait dialog), delete the image
    if (iImage && iNoteControl->NoteLayout() != EProgressLayout &&
            iNoteControl->NoteLayout() != EWaitLayout )
    {
        delete iImage;
        iImage = NULL;
    }

    TransferToControlL(iAnimation);
    if (iNoteControl)
    {
        iNoteControl->ParseTextL();
    }
    InvalidateLayout();
}