|
1 /* |
|
2 * Copyright (c) 2002 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: Pictograph drawer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "AknPictographAnimator.h" |
|
22 #include "AknPictographDrawer.h" |
|
23 #include "AknPictographConstants.h" |
|
24 #include "AknPictographFactory.h" |
|
25 |
|
26 #include <gdi.h> |
|
27 #include <fbs.h> |
|
28 #include <activitymanager.h> |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 const TInt KUserActivityTimeout = 15; |
|
33 const TInt KClientArrayGranularity = 4; |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CAknPictographAnimator::CAknPictographAnimator |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CAknPictographAnimator::CAknPictographAnimator() : |
|
44 CCoeStatic( KUidAknPictographAnimator ), iClients( KClientArrayGranularity ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CAknPictographAnimator::ConstructL |
|
50 // Symbian 2nd phase constructor can leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CAknPictographAnimator::ConstructL() |
|
54 { |
|
55 AknPictographFactory::LoadBitmapsL(iBitmaps, iMasks); |
|
56 |
|
57 AknPictographFactory::CreateWhiteBitmapsL( |
|
58 iWhiteBitmap, |
|
59 iWhiteBitmapMask, |
|
60 iWhiteBitmapMaskDevice, |
|
61 iWhiteBitmapMaskGc |
|
62 ); |
|
63 |
|
64 // Needs to be very low priority so that animator cannot prevent any other |
|
65 // active objects from running. |
|
66 iTimer = CPeriodic::NewL( CActive::EPriorityIdle ); |
|
67 |
|
68 iUserActivityManager = |
|
69 CUserActivityManager::NewL( CActive::EPriorityStandard ); |
|
70 // start monitoring user activity |
|
71 iUserActivityManager->Start( |
|
72 KUserActivityTimeout, |
|
73 TCallBack( InactiveCallBack, this ), |
|
74 TCallBack( ActiveCallBack, this ) ); |
|
75 |
|
76 CCoeEnv* env = CCoeEnv::Static(); |
|
77 |
|
78 env->AddForegroundObserverL( *this ); |
|
79 } |
|
80 |
|
81 CAknPictographAnimator* CAknPictographAnimator::CreateSingletonL() |
|
82 { |
|
83 CAknPictographAnimator* self = new( ELeave ) CAknPictographAnimator(); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // Destructor |
|
91 CAknPictographAnimator::~CAknPictographAnimator() |
|
92 { |
|
93 CCoeEnv* env = CCoeEnv::Static(); |
|
94 env->RemoveForegroundObserver( *this ); |
|
95 |
|
96 delete iTimer; // calls Cancel() |
|
97 delete iUserActivityManager; |
|
98 iClients.Reset(); |
|
99 |
|
100 if (iBitmaps) |
|
101 { |
|
102 iBitmaps->ResetAndDestroy(); |
|
103 } |
|
104 delete iBitmaps; |
|
105 if (iMasks) |
|
106 { |
|
107 iMasks->ResetAndDestroy(); |
|
108 } |
|
109 delete iMasks; |
|
110 delete iWhiteBitmapMaskGc; |
|
111 delete iWhiteBitmapMaskDevice, |
|
112 delete iWhiteBitmapMask; |
|
113 delete iWhiteBitmap; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CAknPictographAnimator::AddClientL |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CAknPictographAnimator::AddClientL( CAknPictographDrawer& aDrawer ) |
|
121 { |
|
122 User::LeaveIfError( iClients.InsertInAddressOrder( &aDrawer ) ); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CAknPictographAnimator::RemoveClient |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 TInt CAknPictographAnimator::RemoveClient( CAknPictographDrawer& aDrawer ) |
|
130 { |
|
131 TInt index = iClients.FindInAddressOrder( &aDrawer ); |
|
132 |
|
133 if ( index >= 0 ) |
|
134 { |
|
135 iClients.Remove( index ); |
|
136 } |
|
137 |
|
138 return iClients.Count(); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CAknPictographAnimator::TimerCallBack |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CAknPictographAnimator::TimerCallBack( TAny* aParameter ) |
|
146 { |
|
147 static_cast<CAknPictographAnimator*>( aParameter )->AnimationTick(); |
|
148 return KErrNone; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CAknPictographAnimator::AnimationTick |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CAknPictographAnimator::AnimationTick() |
|
156 { |
|
157 iCounter++; |
|
158 |
|
159 TInt count = iClients.Count(); |
|
160 for ( TInt i = 0 ; i < count ; i++ ) |
|
161 { |
|
162 CAknPictographDrawer* drawer = |
|
163 const_cast<CAknPictographDrawer*>( iClients[i] ); |
|
164 |
|
165 if ( drawer->IsAnimating() ) |
|
166 { |
|
167 drawer->AnimationTick(); |
|
168 } |
|
169 } |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CAknPictographAnimator::ActiveCallBack |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CAknPictographAnimator::ActiveCallBack( TAny* aParameter ) |
|
177 { |
|
178 static_cast<CAknPictographAnimator*>( aParameter )->HandleActiveCallBack(); |
|
179 return KErrNone; |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CAknPictographAnimator::InactiveCallBack |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TInt CAknPictographAnimator::InactiveCallBack( TAny* aParameter ) |
|
187 { |
|
188 static_cast<CAknPictographAnimator*>( aParameter )->HandleInactiveCallBack(); |
|
189 return KErrNone; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CAknPictographAnimator::HandleActiveCallBack |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CAknPictographAnimator::HandleActiveCallBack() |
|
197 { |
|
198 if ( iAnimatedClients > 0 && !iTimer->IsActive() ) |
|
199 { |
|
200 iTimer->Start( |
|
201 KAknPictographAnimationDelay, |
|
202 KAknPictographAnimationDelay, |
|
203 TCallBack( TimerCallBack, this ) ); |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CAknPictographAnimator::HandleInactiveCallBack |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CAknPictographAnimator::HandleInactiveCallBack() |
|
212 { |
|
213 iTimer->Cancel(); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CAknPictographAnimator::HandleGainingForeground |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 void CAknPictographAnimator::HandleGainingForeground() |
|
221 { |
|
222 TInt count = iClients.Count(); |
|
223 for ( TInt i = 0 ; i < count ; i++ ) |
|
224 { |
|
225 iClients[i]->HandleGainingForeground(); |
|
226 } |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CAknPictographAnimator::HandleLosingForeground |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CAknPictographAnimator::HandleLosingForeground() |
|
234 { |
|
235 TInt count = iClients.Count(); |
|
236 for ( TInt i = 0 ; i < count ; i++ ) |
|
237 { |
|
238 iClients[i]->HandleLosingForeground(); |
|
239 } |
|
240 } |
|
241 |
|
242 // End of File |