|
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: Tuning animation for fmradio |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <aknlayoutscalable_apps.cdl.h> |
|
19 #include <AknUtils.h> |
|
20 #include <alf/alfimage.h> |
|
21 #include <alf/alfimagevisual.h> |
|
22 #include <alf/alfevent.h> |
|
23 #include <AknsItemID.h> |
|
24 #include <barsread.h> |
|
25 #include <data_caging_path_literals.hrh> |
|
26 #include <fmradio.rsg> |
|
27 #include <alf/alfanchorlayout.h> |
|
28 #include <alf/alfenv.h> |
|
29 |
|
30 #include "fmradioalfbitmapanimation.h" |
|
31 #include "fmradiodefines.h" |
|
32 |
|
33 // CONSTANTS |
|
34 //const TInt KBmpAnimationDelay = 90; |
|
35 const TInt KBmpAnimationStartupDelay = 500; |
|
36 const TInt KBmpAnimationFadeInDefaultDurationTime = 200; |
|
37 const TInt KBmpAnimationFadeOutDefaultDurationTime = 200; |
|
38 const TInt KbmpAnimationStopDelay = 210; |
|
39 |
|
40 const TReal KDefaultOpacityInVisibleState = 1.0f; |
|
41 const TReal KDefaultOpacityInHiddenState = 0.0f; |
|
42 |
|
43 _LIT8( KBmpAnimationAnchorTag, "BitmapAnimationAnchorTag" ); |
|
44 // values from fmradio LAF document |
|
45 const TInt KLAFVarietyTuningAnimationPortrait = 7; |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CFMRadioAlfBitmapAnimation::CFMRadioAlfBitmapAnimation |
|
51 // Default constructor |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 CFMRadioAlfBitmapAnimation::CFMRadioAlfBitmapAnimation() : |
|
55 iOpacityInVisibleState( KDefaultOpacityInVisibleState ), |
|
56 iOpacityInHiddenState( KDefaultOpacityInHiddenState ), |
|
57 iAnimationState( EBmpAnimationStopped ) |
|
58 { |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CFMRadioAlfBitmapAnimation::ConstructL |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 void CFMRadioAlfBitmapAnimation::ConstructL( CAlfEnv& aEnv ) |
|
66 { |
|
67 CAlfControl::ConstructL( aEnv ); |
|
68 CreateBitmapAnimationArrayL(); |
|
69 CreateImageAnimationVisualL(); |
|
70 } |
|
71 |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CFMRadioAlfBitmapAnimation::NewL |
|
75 // Two-phase constructor of CFMRadioAlfBitmapAnimation |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CFMRadioAlfBitmapAnimation* CFMRadioAlfBitmapAnimation::NewL( CAlfEnv& aEnv ) |
|
79 { |
|
80 CFMRadioAlfBitmapAnimation* self = new ( ELeave ) CFMRadioAlfBitmapAnimation; |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL( aEnv ); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CFMRadioAlfBitmapAnimation::~CFMRadioAlfBitmapAnimation |
|
90 // Destructor |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CFMRadioAlfBitmapAnimation::~CFMRadioAlfBitmapAnimation() |
|
94 { |
|
95 iFrames.Reset(); |
|
96 iFrames.Close(); |
|
97 delete iBitmapFileName; |
|
98 } |
|
99 |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CFMRadioAlfBitmapAnimation::OfferEventL |
|
103 // From CAlfControl, takes care of alfred event handling. |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 TBool CFMRadioAlfBitmapAnimation::OfferEventL( const TAlfEvent& aEvent ) |
|
107 { |
|
108 TBool eventHandled = EFalse; |
|
109 |
|
110 if ( aEvent.IsCustomEvent() ) |
|
111 { |
|
112 switch( aEvent.CustomParameter() ) |
|
113 { |
|
114 case EBmpAnimationStart: |
|
115 { |
|
116 eventHandled = ETrue; |
|
117 iAnimationState = EBmpAnimationRunning; |
|
118 StartAnimation(); |
|
119 break; |
|
120 } |
|
121 case EBmpAnimationContinue: |
|
122 { |
|
123 eventHandled = ETrue; |
|
124 ContinueBmpAnimation(); |
|
125 break; |
|
126 } |
|
127 case EBmpAnimationStop: |
|
128 { |
|
129 eventHandled = ETrue; |
|
130 Env().CancelCustomCommands( this ); |
|
131 iAnimationState = EBmpAnimationStopped; |
|
132 break; |
|
133 } |
|
134 default: |
|
135 { |
|
136 break; |
|
137 } |
|
138 } |
|
139 } |
|
140 return eventHandled; |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // CFMRadioAlfBitmapAnimation::CreateImageAnimationVisualL |
|
145 // ---------------------------------------------------------------------------- |
|
146 // |
|
147 void CFMRadioAlfBitmapAnimation::CreateImageAnimationVisualL() |
|
148 { |
|
149 |
|
150 //CAlfAnchorLayout* imageAnchorLayout = CAlfAnchorLayout::AddNewL( *this ); |
|
151 //imageAnchorLayout->SetTagL( KBitmapAnimationAnchorTag ); |
|
152 // Create an anchor for the indicator layout |
|
153 iBmpAnimationAnchor = CAlfAnchorLayout::AddNewL( *this ); |
|
154 iBmpAnimationAnchor->SetTagL( KBmpAnimationAnchorTag ); |
|
155 |
|
156 iAnimationImageVisual = CAlfImageVisual::AddNewL( *this, iBmpAnimationAnchor ); |
|
157 iAnimationImageVisual->SetImage( iFrames[0] ); |
|
158 |
|
159 TAlfTimedValue opacity; |
|
160 opacity.SetTarget( iOpacityInHiddenState, 0 ); |
|
161 |
|
162 iAnimationImageVisual->SetOpacity( opacity ); |
|
163 } |
|
164 |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CFMRadioAlfBitmapAnimation::CreateBitmapAnimationArrayL |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 void CFMRadioAlfBitmapAnimation::CreateBitmapAnimationArrayL() |
|
171 { |
|
172 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
173 |
|
174 TResourceReader resourceReader; |
|
175 coeEnv->CreateResourceReaderLC( resourceReader, R_FMRADIO_WAIT_ANIM_TUNING ); |
|
176 |
|
177 iFrameInterval = resourceReader.ReadInt32(); |
|
178 TInt bitmapCount = resourceReader.ReadInt16(); |
|
179 |
|
180 TFindFile finder( coeEnv->FsSession() ); |
|
181 TInt err = finder.FindByDir( KFMRadioBmpFile, KDC_APP_BITMAP_DIR ); |
|
182 if ( err == KErrNone ) |
|
183 { |
|
184 iBitmapFileName = finder.File().AllocL(); |
|
185 } |
|
186 |
|
187 // read bitmap size from layout data |
|
188 TRect tempRect; |
|
189 TAknLayoutRect bitmapLayout; |
|
190 bitmapLayout.LayoutRect( |
|
191 tempRect, |
|
192 AknLayoutScalable_Apps::area_fmrd2_info_pane_g1( KLAFVarietyTuningAnimationPortrait ) ); |
|
193 |
|
194 |
|
195 for ( TInt i = 0; i < bitmapCount; i++ ) |
|
196 { |
|
197 TFileName bmpFile = resourceReader.ReadTPtrC(); |
|
198 TInt bitmapId = resourceReader.ReadInt32(); |
|
199 TInt bitmapMaskId = resourceReader.ReadInt32(); |
|
200 TInt xx = resourceReader.ReadInt16(); |
|
201 TInt xxx = resourceReader.ReadInt8(); |
|
202 |
|
203 TAlfImage alfImage( KAknsIIDNone, |
|
204 bitmapLayout.Rect().Size(), |
|
205 EAspectRatioPreserved, |
|
206 iBitmapFileName, |
|
207 bitmapId, |
|
208 bitmapMaskId ); |
|
209 |
|
210 iFrames.Append( alfImage ); |
|
211 } |
|
212 CleanupStack::PopAndDestroy(); //resourceReader |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // CFMRadioAlfBitmapAnimation::StartBmpAnimation |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 void CFMRadioAlfBitmapAnimation::StartAnimation() |
|
220 { |
|
221 iCurrentFrameIndex = 0; |
|
222 iAnimationImageVisual->SetImage( iFrames[iCurrentFrameIndex] ); |
|
223 |
|
224 Show( ETrue ); |
|
225 |
|
226 Env().Send( TAlfCustomEventCommand( EBmpAnimationContinue, this ), iFrameInterval ); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CFMRadioAlfBitmapAnimation::ContinueBmpAnimation |
|
231 // ---------------------------------------------------------------------------- |
|
232 // |
|
233 void CFMRadioAlfBitmapAnimation::ContinueBmpAnimation() |
|
234 { |
|
235 iCurrentFrameIndex++; |
|
236 |
|
237 if ( iCurrentFrameIndex == 9 ) |
|
238 { |
|
239 iCurrentFrameIndex = 0; |
|
240 } |
|
241 iAnimationImageVisual->SetImage( iFrames[iCurrentFrameIndex] ); |
|
242 Env().Send( TAlfCustomEventCommand( EBmpAnimationContinue, this ), iFrameInterval ); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CFMRadioAlfIndicator::Show |
|
247 // Shows the indicator with the defined opacity value. |
|
248 // --------------------------------------------------------- |
|
249 // |
|
250 void CFMRadioAlfBitmapAnimation::Show( TBool aShowWithFading ) |
|
251 { |
|
252 TAlfTimedValue opacity; |
|
253 |
|
254 if ( aShowWithFading ) |
|
255 { |
|
256 opacity.SetTarget( iOpacityInVisibleState, KBmpAnimationFadeInDefaultDurationTime ); |
|
257 |
|
258 iAnimationImageVisual->SetOpacity( opacity ); |
|
259 } |
|
260 else |
|
261 { |
|
262 opacity.SetValueNow( iOpacityInVisibleState ); |
|
263 iAnimationImageVisual->SetOpacity( opacity ); |
|
264 } |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CFMRadioAlfIndicator::Hide |
|
269 // Hides the indicator with the defined opacity value. |
|
270 // --------------------------------------------------------- |
|
271 // |
|
272 void CFMRadioAlfBitmapAnimation::Hide( TBool aHideWithFading ) |
|
273 { |
|
274 TAlfTimedValue opacity; |
|
275 |
|
276 if ( aHideWithFading ) |
|
277 { |
|
278 opacity.SetTarget( iOpacityInHiddenState, KBmpAnimationFadeOutDefaultDurationTime ); |
|
279 |
|
280 iAnimationImageVisual->SetOpacity( opacity ); |
|
281 } |
|
282 else |
|
283 { |
|
284 opacity.SetValueNow( iOpacityInHiddenState ); |
|
285 iAnimationImageVisual->SetOpacity( opacity ); |
|
286 } |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------- |
|
290 // CFMRadioAlfIndicator::StopBmpAnimation |
|
291 // --------------------------------------------------------- |
|
292 // |
|
293 void CFMRadioAlfBitmapAnimation::StopBmpAnimation() |
|
294 { |
|
295 if ( iAnimationState == EBmpAnimationStartup ) |
|
296 { |
|
297 Env().CancelCustomCommands( this, EBmpAnimationStart ); |
|
298 iAnimationState = EBmpAnimationStopped; |
|
299 } |
|
300 else if ( iAnimationState == EBmpAnimationRunning ) |
|
301 { |
|
302 Hide( ETrue ); |
|
303 |
|
304 Env().Send( TAlfCustomEventCommand( EBmpAnimationStop, this ), KbmpAnimationStopDelay ); |
|
305 } |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // CFMRadioAlfBitmapAnimation::SetRect |
|
310 // Sets the Bmpanimation rectangle. |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 void CFMRadioAlfBitmapAnimation::SetRect( const TRect& aRect ) |
|
314 { |
|
315 iRect = aRect; |
|
316 if ( iBmpAnimationAnchor ) |
|
317 { |
|
318 SetAbsoluteCornerAnchors( iBmpAnimationAnchor, 0, iRect.iTl, iRect.iBr ); |
|
319 iBmpAnimationAnchor->UpdateChildrenLayout(); |
|
320 } |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CFMRadioAlfBitmapAnimation::SetAbsoluteCornerAnchors |
|
325 // Sets absolute rect of the anchor by top left and bottom right points. |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 void CFMRadioAlfBitmapAnimation::SetAbsoluteCornerAnchors( CAlfAnchorLayout* aAnchor, |
|
329 TInt aOrdinal, |
|
330 const TPoint& aTopLeftPosition, |
|
331 const TPoint& aBottomRightPosition ) |
|
332 { |
|
333 if ( aAnchor ) |
|
334 { |
|
335 // Set top/left anchor. |
|
336 aAnchor->Attach( aOrdinal, |
|
337 EAlfAnchorTypeTopLeft, |
|
338 TAlfXYMetric( TAlfMetric( aTopLeftPosition.iX ), TAlfMetric( aTopLeftPosition.iY ) ), |
|
339 EAlfAnchorAttachmentOriginTopLeft ); |
|
340 |
|
341 |
|
342 // Set bottom/right anchor. |
|
343 aAnchor->Attach( aOrdinal, |
|
344 EAlfAnchorTypeBottomRight, |
|
345 TAlfXYMetric( TAlfMetric( aBottomRightPosition.iX ), TAlfMetric( aBottomRightPosition.iY ) ), |
|
346 EAlfAnchorAttachmentOriginTopLeft ); |
|
347 } |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // CFMRadioAlfBitmapAnimation::StartBmpAnimation |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void CFMRadioAlfBitmapAnimation::StartBmpAnimation() |
|
355 { |
|
356 if ( iAnimationState == EBmpAnimationRunning ) |
|
357 { |
|
358 Env().CancelCustomCommands( this ); |
|
359 Hide( EFalse ); // hide without fade |
|
360 } |
|
361 else if ( iAnimationState == EBmpAnimationStartup ) |
|
362 { |
|
363 Env().CancelCustomCommands( this, EBmpAnimationStart ); |
|
364 } |
|
365 iAnimationState = EBmpAnimationStartup; |
|
366 Env().Send( TAlfCustomEventCommand( EBmpAnimationStart, this ), KBmpAnimationStartupDelay ); |
|
367 } |
|
368 |
|
369 // End of file |