20
|
1 |
/*
|
|
2 |
* Copyright (c) 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: Implementation of the class CFMRadioAlfIndicator
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
|
|
21 |
#include <e32cmn.h>
|
|
22 |
#include <alf/alfenv.h>
|
|
23 |
#include <alf/alftextvisual.h>
|
|
24 |
#include <alf/alfevent.h>
|
|
25 |
#include <alf/alftransformation.h>
|
|
26 |
#include <alf/alftextstyle.h>
|
|
27 |
|
|
28 |
// brushes
|
|
29 |
#include <alf/alfgradientbrush.h>
|
|
30 |
#include <alf/alfbrusharray.h>
|
|
31 |
#include <alf/alfborderbrush.h>
|
|
32 |
#include <alf/alfimagebrush.h>
|
|
33 |
|
|
34 |
#include "debug.h"
|
|
35 |
#include "fmradioalfrdsviewer.h"
|
|
36 |
#include "fmradioalfrdsviewobserver.h"
|
|
37 |
// CONSTANTS
|
|
38 |
|
|
39 |
const TInt KIndicatorFadeInDefaultDurationTime = 500;
|
|
40 |
const TInt KIndicatorFadeOutDefaultDurationTime = 500;
|
|
41 |
const TInt KRDSDisplayPeriod = 60000; //milliseconds = 1 min.
|
|
42 |
const TReal KDefaultOpacityInVisibleState = 1.0f;
|
|
43 |
const TReal KDefaultOpacityInHiddenState = 0.0f;
|
|
44 |
const TReal KRelativeFontSize = 0.10;
|
|
45 |
|
|
46 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
47 |
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
// CFMRadioAlfIndicator::NewL
|
|
50 |
// Two-phase constructor of CFMRadioAlfIndicator
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CFMRadioAlfRDSViewer* CFMRadioAlfRDSViewer::NewL( CAlfEnv& aEnv )
|
|
54 |
{
|
|
55 |
CFMRadioAlfRDSViewer* self = new (ELeave) CFMRadioAlfRDSViewer( );
|
|
56 |
CleanupStack::PushL(self);
|
|
57 |
self->ConstructL( aEnv );
|
|
58 |
CleanupStack::Pop(self);
|
|
59 |
return self;
|
|
60 |
}
|
|
61 |
|
|
62 |
// ----------------------------------------------------------------------------
|
|
63 |
// CFMRadioAlfRDSViewer::CFMRadioAlfRDSViewer
|
|
64 |
// Default constructor
|
|
65 |
// ----------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CFMRadioAlfRDSViewer::CFMRadioAlfRDSViewer()
|
|
68 |
: iTextStyleId( KErrNotFound ),
|
|
69 |
iOpacityInVisibleState( KDefaultOpacityInVisibleState ),
|
|
70 |
iOpacityInHiddenState( KDefaultOpacityInHiddenState ),
|
|
71 |
iIsRdsTextVisible( EFalse ),
|
|
72 |
iRdsTextVisibilityTimerCompleted( ETrue )
|
|
73 |
{
|
|
74 |
//No implementation needed
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
// CFMRadioAlfRDSViewer::SetObserver
|
|
80 |
// Sets observer
|
|
81 |
// ----------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
void CFMRadioAlfRDSViewer::SetObserver( MFMRadioAlfRdsViewObserver* aObserver )
|
|
84 |
{
|
|
85 |
FTRACE( FPrint( _L( "CFMRadioAlfRDSViewer::SetObserver" ) ) );
|
|
86 |
TInt index = iObservers.FindInAddressOrder( aObserver );
|
|
87 |
if ( index == KErrNotFound )
|
|
88 |
{
|
|
89 |
iObservers.InsertInAddressOrder( aObserver );
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
// ----------------------------------------------------------------------------
|
|
94 |
// CFMRadioAlfRDSViewer::RemoveObserver
|
|
95 |
// Removes observer
|
|
96 |
// ----------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
void CFMRadioAlfRDSViewer::RemoveObserver( MFMRadioAlfRdsViewObserver* aObserver )
|
|
99 |
{
|
|
100 |
FTRACE( FPrint( _L( "CFMRadioAlfRDSViewer::RemoveObserver" ) ) );
|
|
101 |
TInt index = iObservers.FindInAddressOrder( aObserver );
|
|
102 |
|
|
103 |
if ( index >= 0 )
|
|
104 |
{
|
|
105 |
iObservers.Remove( index );
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
// ----------------------------------------------------------------------------
|
|
110 |
// CFMRadioAlfRDSViewer::ConstructL
|
|
111 |
// Symbian 2nd phase constructor can leave.
|
|
112 |
// ----------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
void CFMRadioAlfRDSViewer::ConstructL( CAlfEnv& aEnv )
|
|
115 |
{
|
|
116 |
FTRACE( FPrint( _L( "CFMRadioAlfRDSViewer::ConstructL" ) ) );
|
|
117 |
CAlfControl::ConstructL( aEnv );
|
|
118 |
AddIndicatorLayerL();
|
|
119 |
Hide();
|
|
120 |
}
|
|
121 |
|
|
122 |
// ---------------------------------------------------------------------------
|
|
123 |
// ~CFMRadioAlfRDSViewer::~CFMRadioAlfRDSViewer
|
|
124 |
// Destructor
|
|
125 |
// ---------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
CFMRadioAlfRDSViewer::~CFMRadioAlfRDSViewer()
|
|
128 |
{
|
|
129 |
FTRACE( FPrint( _L( "CFMRadioAlfRDSViewer::Destructor" ) ) );
|
|
130 |
Env().CancelCustomCommands( this );
|
|
131 |
if( iTextStyleId != KErrNotFound )
|
|
132 |
{
|
|
133 |
CAlfTextStyleManager& manager = Env().TextStyleManager();
|
|
134 |
manager.DeleteTextStyle( iTextStyleId );
|
|
135 |
}
|
|
136 |
iRadioText.Close();
|
|
137 |
iObservers.Close();
|
|
138 |
}
|
|
139 |
|
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
// CFMRadioAlfRDSViewer::OfferEventL
|
|
142 |
// From CAlfControl, takes care of alfred event handling.
|
|
143 |
// ---------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
TBool CFMRadioAlfRDSViewer::OfferEventL( const TAlfEvent& aEvent )
|
|
146 |
{
|
|
147 |
FTRACE( FPrint( _L( "CFMRadioAlfRDSViewer::OfferEventL" ) ) );
|
|
148 |
TBool eventHandled = EFalse;
|
|
149 |
|
|
150 |
if ( aEvent.IsCustomEvent() )
|
|
151 |
{
|
|
152 |
switch( aEvent.CustomParameter() )
|
|
153 |
{
|
|
154 |
case EFadeInCompleted:
|
|
155 |
{
|
|
156 |
eventHandled = ETrue;
|
|
157 |
Env().Send( TAlfCustomEventCommand( ERDSDisplayTimerCompleted, this ), KRDSDisplayPeriod );
|
|
158 |
break;
|
|
159 |
}
|
|
160 |
case EOldTextFadeEffectCompleted:
|
|
161 |
{
|
|
162 |
eventHandled = ETrue;
|
|
163 |
iText->SetTextL( iRadioText );
|
|
164 |
// fade in the new radio text
|
|
165 |
Fade( iText, KIndicatorFadeInDefaultDurationTime, iOpacityInVisibleState );
|
|
166 |
Env().Send( TAlfCustomEventCommand( EFadeInCompleted, this ), KIndicatorFadeOutDefaultDurationTime );
|
|
167 |
break;
|
|
168 |
}
|
|
169 |
case ERDSDisplayTimerCompleted:
|
|
170 |
{
|
|
171 |
eventHandled = ETrue;
|
|
172 |
iRdsTextVisibilityTimerCompleted = ETrue;
|
|
173 |
iIsRdsTextVisible = EFalse;
|
|
174 |
Fade( iText, KIndicatorFadeOutDefaultDurationTime, iOpacityInHiddenState );
|
|
175 |
for ( TInt i = 0 ; i < iObservers.Count() ; i++ )
|
|
176 |
{
|
|
177 |
iObservers[i]->NotifyRdsTextTimerCompletion();
|
|
178 |
}
|
|
179 |
break;
|
|
180 |
}
|
|
181 |
default:
|
|
182 |
{
|
|
183 |
break;
|
|
184 |
}
|
|
185 |
}
|
|
186 |
}
|
|
187 |
return eventHandled;
|
|
188 |
}
|
|
189 |
|
|
190 |
// ---------------------------------------------------------------------------
|
|
191 |
// CFMRadioAlfRDSViewer::SetRect
|
|
192 |
// Sets the indicator rectangle.
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void CFMRadioAlfRDSViewer::SetRect( const TRect& aRect )
|
|
196 |
{
|
|
197 |
iRect = aRect;
|
|
198 |
TRAP_IGNORE( SetTextStyleL() );
|
|
199 |
if ( iIndicatorTextAnchor )
|
|
200 |
{
|
|
201 |
SetAbsoluteCornerAnchors( iIndicatorTextAnchor, 0, iRect.iTl, iRect.iBr );
|
|
202 |
iIndicatorTextAnchor->UpdateChildrenLayout();
|
|
203 |
// It seems that layout is not updated if the text is not changed
|
|
204 |
TRAP_IGNORE( iText->SetTextL( KNullDesC );
|
|
205 |
iText->SetTextL( iRadioText ); )
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
// ---------------------------------------------------------------------------
|
|
210 |
// CFMRadioAlfRDSViewer::AddIndicatorLayerL
|
|
211 |
// Creates the needed drawing layers and visual objects
|
|
212 |
// for the indicator.
|
|
213 |
// ---------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
void CFMRadioAlfRDSViewer::AddIndicatorLayerL()
|
|
216 |
{
|
|
217 |
// Create an anchor for the indicator layout
|
|
218 |
iIndicatorTextAnchor = CAlfAnchorLayout::AddNewL( *this );
|
|
219 |
|
|
220 |
// Create visual object for the indicator
|
|
221 |
iText = CAlfTextVisual::AddNewL( *this, iIndicatorTextAnchor );
|
|
222 |
iText->SetColor( iTextColor );
|
|
223 |
iText->SetAlign( EAlfAlignHCenter, EAlfAlignVCenter );
|
|
224 |
iText->SetWrapping( CAlfTextVisual::ELineWrapBreak );
|
|
225 |
iText->SetClipping( ETrue );
|
|
226 |
}
|
|
227 |
|
|
228 |
// ---------------------------------------------------------------------------
|
|
229 |
// CFMRadioAlfRDSViewer::SetTextStyleL
|
|
230 |
// Creates the text style for indicator
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
void CFMRadioAlfRDSViewer::SetTextStyleL()
|
|
234 |
{
|
|
235 |
CAlfTextStyleManager& manager = Env().TextStyleManager();
|
|
236 |
CAlfTextStyle* textStyle = NULL;
|
|
237 |
if( iTextStyleId == KErrNotFound )
|
|
238 |
{
|
|
239 |
iTextStyleId = manager.CreatePlatformTextStyleL( EAlfTextStyleNormal );
|
|
240 |
}
|
|
241 |
|
|
242 |
textStyle = manager.TextStyle( iTextStyleId );
|
|
243 |
// 5 lines
|
|
244 |
textStyle->SetTextSizeInPixels( ( iRect.Height()*KRelativeFontSize ), ETrue );
|
|
245 |
//textStyle->SetTextPaneHeightInPixels(iRect.Height(), ETrue );
|
|
246 |
iText->SetTextStyle( iTextStyleId );
|
|
247 |
}
|
|
248 |
|
|
249 |
// ---------------------------------------------------------------------------
|
|
250 |
// CFMRadioAlfRDSViewer::SetTextColor
|
|
251 |
// Changes indicator text color.
|
|
252 |
// ---------------------------------------------------------------------------
|
|
253 |
//
|
|
254 |
void CFMRadioAlfRDSViewer::SetTextColor( const TRgb& aTextColor )
|
|
255 |
{
|
|
256 |
iTextColor = aTextColor;
|
|
257 |
if( iText )
|
|
258 |
{
|
|
259 |
iText->SetColor( aTextColor );
|
|
260 |
}
|
|
261 |
}
|
|
262 |
|
|
263 |
// ---------------------------------------------------------
|
|
264 |
// CFMRadioAlfRDSViewer::SetTextL
|
|
265 |
// Sets the indicator text.
|
|
266 |
// ---------------------------------------------------------
|
|
267 |
//
|
|
268 |
TBool CFMRadioAlfRDSViewer::SetTextL( const TDesC& aText )
|
|
269 |
{
|
|
270 |
TBool result = EFalse;
|
|
271 |
if ( aText.Length() > 0 )
|
|
272 |
{
|
|
273 |
if ( iRadioText.Compare( aText ) != 0 )
|
|
274 |
{
|
|
275 |
iRdsTextVisibilityTimerCompleted = EFalse;
|
|
276 |
Env().CancelCustomCommands( this, ERDSDisplayTimerCompleted );
|
|
277 |
|
|
278 |
iRadioText.Close();
|
|
279 |
iRadioText.Create( aText );
|
|
280 |
|
|
281 |
if ( !iIsRdsTextVisible )
|
|
282 |
{
|
|
283 |
iText->SetTextL( aText );
|
|
284 |
}
|
|
285 |
else
|
|
286 |
{
|
|
287 |
// fade out the old radio text
|
|
288 |
Fade( iText, KIndicatorFadeOutDefaultDurationTime, iOpacityInHiddenState );
|
|
289 |
Env().Send( TAlfCustomEventCommand( EOldTextFadeEffectCompleted, this ), KIndicatorFadeOutDefaultDurationTime );
|
|
290 |
}
|
|
291 |
result = ETrue;
|
|
292 |
}
|
|
293 |
}
|
|
294 |
return result;
|
|
295 |
}
|
|
296 |
|
|
297 |
// ---------------------------------------------------------
|
|
298 |
// CFMRadioAlfRDSViewer::Show
|
|
299 |
// Shows the indicator with the defined opacity value.
|
|
300 |
// ---------------------------------------------------------
|
|
301 |
//
|
|
302 |
void CFMRadioAlfRDSViewer::Show()
|
|
303 |
{
|
|
304 |
if ( !iIsRdsTextVisible )
|
|
305 |
{
|
|
306 |
iIsRdsTextVisible = ETrue;
|
|
307 |
Fade( iText, KIndicatorFadeInDefaultDurationTime, iOpacityInVisibleState );
|
|
308 |
Env().Send( TAlfCustomEventCommand( EFadeInCompleted, this ), KIndicatorFadeOutDefaultDurationTime );
|
|
309 |
}
|
|
310 |
}
|
|
311 |
|
|
312 |
// ---------------------------------------------------------
|
|
313 |
// CFMRadioAlfRDSViewer::Hide
|
|
314 |
// Hides the indicator with the defined opacity value.
|
|
315 |
// ---------------------------------------------------------
|
|
316 |
//
|
|
317 |
void CFMRadioAlfRDSViewer::Hide()
|
|
318 |
{
|
|
319 |
if ( iIsRdsTextVisible )
|
|
320 |
{
|
|
321 |
// cancel timer event
|
|
322 |
Env().CancelCustomCommands( this, ERDSDisplayTimerCompleted );
|
|
323 |
iIsRdsTextVisible = EFalse;
|
|
324 |
Fade( iText, KIndicatorFadeOutDefaultDurationTime, iOpacityInHiddenState );
|
|
325 |
}
|
|
326 |
}
|
|
327 |
|
|
328 |
// ---------------------------------------------------------
|
|
329 |
// CFMRadioAlfRDSViewer::Reset
|
|
330 |
// Cancel events and flush radio text cache
|
|
331 |
// ---------------------------------------------------------
|
|
332 |
//
|
|
333 |
void CFMRadioAlfRDSViewer::Reset()
|
|
334 |
{
|
|
335 |
FTRACE( FPrint( _L( "CFMRadioAlfRDSViewer::Reset" ) ) );
|
|
336 |
iRdsTextVisibilityTimerCompleted = ETrue;
|
|
337 |
iRadioText.Close();
|
|
338 |
Env().CancelCustomCommands( this );
|
|
339 |
}
|
|
340 |
// ---------------------------------------------------------------------------
|
|
341 |
// CFMRadioAlfRDSViewer::SetOpacityInVisibleState
|
|
342 |
// Sets the indicator opacity in visible state.
|
|
343 |
// ---------------------------------------------------------------------------
|
|
344 |
//
|
|
345 |
void CFMRadioAlfRDSViewer::SetOpacityInVisibleState( const TReal aOpacity )
|
|
346 |
{
|
|
347 |
iOpacityInVisibleState = aOpacity;
|
|
348 |
}
|
|
349 |
|
|
350 |
// ---------------------------------------------------------------------------
|
|
351 |
// CFMRadioAlfRDSViewer::SetOpacityInHiddenState
|
|
352 |
// Sets the indicator opacity in hidden state.
|
|
353 |
// ---------------------------------------------------------------------------
|
|
354 |
//
|
|
355 |
void CFMRadioAlfRDSViewer::SetOpacityInHiddenState( const TReal aOpacity )
|
|
356 |
{
|
|
357 |
iOpacityInHiddenState = aOpacity;
|
|
358 |
}
|
|
359 |
|
|
360 |
// ---------------------------------------------------------------------------
|
|
361 |
// CFMRadioAlfRDSViewer::SetAbsoluteCornerAnchors
|
|
362 |
// Sets absolute rect of the anchor by top left and bottom right points.
|
|
363 |
// ---------------------------------------------------------------------------
|
|
364 |
//
|
|
365 |
void CFMRadioAlfRDSViewer::SetAbsoluteCornerAnchors( CAlfAnchorLayout* aAnchor,
|
|
366 |
TInt aOrdinal,
|
|
367 |
const TPoint& aTopLeftPosition,
|
|
368 |
const TPoint& aBottomRightPosition )
|
|
369 |
{
|
|
370 |
if ( aAnchor )
|
|
371 |
{
|
|
372 |
// Set top/left anchor.
|
|
373 |
aAnchor->Attach( aOrdinal,
|
|
374 |
EAlfAnchorTypeTopLeft,
|
|
375 |
TAlfXYMetric( TAlfMetric( aTopLeftPosition.iX ), TAlfMetric( aTopLeftPosition.iY ) ),
|
|
376 |
EAlfAnchorAttachmentOriginTopLeft );
|
|
377 |
|
|
378 |
// Set bottom/right anchor.
|
|
379 |
aAnchor->Attach( aOrdinal,
|
|
380 |
EAlfAnchorTypeBottomRight,
|
|
381 |
TAlfXYMetric( TAlfMetric( aBottomRightPosition.iX ), TAlfMetric( aBottomRightPosition.iY ) ),
|
|
382 |
EAlfAnchorAttachmentOriginTopLeft );
|
|
383 |
}
|
|
384 |
}
|
|
385 |
|
|
386 |
// ---------------------------------------------------------------------------
|
|
387 |
// CFMRadioAlfRDSViewer::Fade
|
|
388 |
// Sets the fading animation to the CAlfVisual object.
|
|
389 |
// ---------------------------------------------------------------------------
|
|
390 |
//
|
|
391 |
void CFMRadioAlfRDSViewer::Fade( CAlfVisual* aVisual, TInt aFadingTime, TReal aOpacity ) const
|
|
392 |
{
|
|
393 |
TAlfTimedValue opacity;
|
|
394 |
opacity.SetTarget( aOpacity, aFadingTime ); // and smooth target
|
|
395 |
aVisual->SetOpacity( opacity );
|
|
396 |
}
|
|
397 |
|
|
398 |
// ---------------------------------------------------------------------------
|
|
399 |
// CFMRadioAlfRDSViewer::IsShowingRdsTextArea
|
|
400 |
// ---------------------------------------------------------------------------
|
|
401 |
//
|
|
402 |
TBool CFMRadioAlfRDSViewer::IsShowingRdsTextArea() const
|
|
403 |
{
|
|
404 |
return iIsRdsTextVisible;
|
|
405 |
}
|
|
406 |
|
|
407 |
// ---------------------------------------------------------------------------
|
|
408 |
// CFMRadioAlfRDSViewer::Deactivate
|
|
409 |
// from MFMRadioIdleControlInterface
|
|
410 |
// ---------------------------------------------------------------------------
|
|
411 |
//
|
|
412 |
void CFMRadioAlfRDSViewer::Deactivate()
|
|
413 |
{
|
|
414 |
}
|
|
415 |
|
|
416 |
// ---------------------------------------------------------------------------
|
|
417 |
// CFMRadioAlfRDSViewer::IsRdsTextVisibilityTimerCompleted
|
|
418 |
// ---------------------------------------------------------------------------
|
|
419 |
//
|
|
420 |
TBool CFMRadioAlfRDSViewer::IsRdsTextVisibilityTimerCompleted()
|
|
421 |
{
|
|
422 |
return iRdsTextVisibilityTimerCompleted;
|
|
423 |
}
|
|
424 |
|
|
425 |
// End of File
|