|
1 /* |
|
2 * Copyright (c) {Year(s)} {Copyright owner}. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * {Name} {Company} ? Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * {Name} {Company} ? {{Description of contribution}} |
|
14 * |
|
15 * Description: |
|
16 * {{Description of the file}} |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <coemain.h> |
|
23 #include <aknglobalnote.h> |
|
24 #include <aknsconstants.h> |
|
25 #include "TestPublisherAppView.h" |
|
26 #include "hspublisher.h" |
|
27 |
|
28 _LIT( KId, "#replaceuid#:#replace#" ); |
|
29 |
|
30 // Type definitions |
|
31 enum TFlags |
|
32 { |
|
33 ERequirePublish =1, |
|
34 EPublishAllowed |
|
35 }; |
|
36 |
|
37 |
|
38 _LIT( KGNews1, "World news!"); |
|
39 _LIT( KGFeed1, "Bangkok tense as thousands remain on streets." ); |
|
40 _LIT( KGFeed2, "France frees killer of former Iran PM." ); |
|
41 _LIT( KGFeed3, "Lingering ash cloud spurs new rules." ); |
|
42 |
|
43 _LIT( KSNews1, "Sport news!"); |
|
44 _LIT( KSFeed1, "Motorsport: Webber dampens title talk." ); |
|
45 _LIT( KSFeed2, "Cricket: IPL boss seeks reinstatement." ); |
|
46 _LIT( KSFeed3, "Tennis: Nadal too strong for Federer." ); |
|
47 |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // Two-phased constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CTestPublisherAppView* CTestPublisherAppView::NewL(const TRect& aRect) |
|
56 { |
|
57 CTestPublisherAppView* self = CTestPublisherAppView::NewLC(aRect); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CTestPublisherAppView* CTestPublisherAppView::NewLC(const TRect& aRect) |
|
67 { |
|
68 CTestPublisherAppView* self = new (ELeave) CTestPublisherAppView; |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(aRect); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // Symbian 2nd phase constructor can leave. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CTestPublisherAppView::ConstructL(const TRect& aRect) |
|
79 { |
|
80 // Create a window for this application view |
|
81 CreateWindowL(); |
|
82 |
|
83 // Set the windows size |
|
84 SetRect(aRect); |
|
85 |
|
86 iWidgetIds = new (ELeave) CDesCArrayFlat(5); |
|
87 //Create the publihser interface |
|
88 iPublisher = CHsPublisher::NewL( *this ); |
|
89 // Activate the window, which makes it ready to be drawn |
|
90 ActivateL(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // C++ default constructor can NOT contain any code, that might leave. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CTestPublisherAppView::CTestPublisherAppView() |
|
98 { |
|
99 // No implementation required |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // Destructor. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 CTestPublisherAppView::~CTestPublisherAppView() |
|
107 { |
|
108 delete iPublisher; |
|
109 delete iWidgetIds; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // Draws the display. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CTestPublisherAppView::Draw(const TRect& /*aRect*/) const |
|
117 { |
|
118 // Get the standard graphics context |
|
119 CWindowGc& gc = SystemGc(); |
|
120 |
|
121 // Gets the control's extent |
|
122 TRect drawRect(Rect()); |
|
123 |
|
124 // Clears the screen |
|
125 gc.Clear(drawRect); |
|
126 |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // Called by framework when the view size is changed. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CTestPublisherAppView::SizeChanged() |
|
134 { |
|
135 DrawNow(); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // Called by framework to handle pointer touch events. |
|
140 // Note: although this method is compatible with earlier SDKs, |
|
141 // it will not be called in SDKs without Touch support. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CTestPublisherAppView::HandlePointerEventL( |
|
145 const TPointerEvent& aPointerEvent) |
|
146 { |
|
147 |
|
148 // Call base class HandlePointerEventL() |
|
149 CCoeControl::HandlePointerEventL(aPointerEvent); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 // |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 const TDesC& CTestPublisherAppView::Identity() |
|
158 { |
|
159 return KId(); |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 // |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CTestPublisherAppView::NotifyWidgetStarted( const TDesC& aWidgetId, |
|
168 MHsWidgetObserver::EStartReason /*aReason*/ ) |
|
169 { |
|
170 TInt pos( KErrNotFound ); |
|
171 if( iWidgetIds->Find( aWidgetId, pos ) != 0) |
|
172 { |
|
173 iWidgetIds->AppendL( aWidgetId ); |
|
174 } |
|
175 |
|
176 // Publish after widget is alive, lazy. |
|
177 iFlags.Set( ERequirePublish ); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 // |
|
183 // ----------------------------------------------------------------------------- |
|
184 void CTestPublisherAppView::NotifyWidgetStopped( const TDesC& aWidgetId, |
|
185 MHsWidgetObserver::EStopReason /*aReason*/ ) |
|
186 { |
|
187 TInt pos( KErrNotFound ); |
|
188 if( iWidgetIds->Find( aWidgetId, pos ) == 0 ) |
|
189 { |
|
190 // widget removed from homescreen or in invisible page |
|
191 iWidgetIds->Delete( pos ); |
|
192 } |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 // |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void CTestPublisherAppView::NotifyWidgetState( const TDesC& aWidgetId, |
|
201 MHsWidgetObserver::EState aState ) |
|
202 { |
|
203 if ( aState == MHsWidgetObserver::EAlive ) |
|
204 { |
|
205 iFlags.Set( EPublishAllowed ); |
|
206 |
|
207 // PublishL will determine if it is necessary to update widget data |
|
208 TRAP_IGNORE( PublishL( aWidgetId ) ); |
|
209 } |
|
210 else if ( aState == MHsWidgetObserver::ESuspend ) |
|
211 { |
|
212 iFlags.Clear( EPublishAllowed ); |
|
213 } |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 // |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CTestPublisherAppView::NotifyWidgetEvent( const TDesC& aWidgetId, |
|
222 const TDesC& aEvent, const TDesC& /*aParam*/ ) |
|
223 { |
|
224 if ( aEvent == _L("imageclicked")) |
|
225 { |
|
226 CAknGlobalNote* globalNote = CAknGlobalNote::NewLC(); |
|
227 TInt noteId = globalNote->ShowNoteL( EAknGlobalInformationNote, _L("Image clicked")); |
|
228 User::After( 2000 ); // waiting for 3 seconds |
|
229 // discard note |
|
230 globalNote->CancelNoteL( noteId ); |
|
231 CleanupStack::PopAndDestroy(); |
|
232 iPublisher->StartTransaction( aWidgetId ); |
|
233 iPublisher->PublishText( |
|
234 aWidgetId, _L8("text2"), KGFeed3 ); |
|
235 iPublisher->CommitTransaction( aWidgetId ); |
|
236 } |
|
237 else if ( aEvent == _L("textclicked") ) |
|
238 { |
|
239 CAknGlobalNote* globalNote = CAknGlobalNote::NewLC(); |
|
240 TInt noteId = globalNote->ShowNoteL( EAknGlobalInformationNote, _L("Text clicked") ); |
|
241 User::After( 2000 ); // waiting for 3 seconds |
|
242 // discard note |
|
243 globalNote->CancelNoteL( noteId ); |
|
244 CleanupStack::PopAndDestroy(); |
|
245 iPublisher->StartTransaction( aWidgetId ); |
|
246 iPublisher->PublishText( |
|
247 aWidgetId, _L8("text3"), KGFeed2 ); |
|
248 iPublisher->CommitTransaction( aWidgetId ); |
|
249 } |
|
250 else if ( aEvent == _L("widgetclicked") ) |
|
251 { |
|
252 CAknGlobalNote* globalNote = CAknGlobalNote::NewLC(); |
|
253 TInt noteId = globalNote->ShowNoteL( EAknGlobalInformationNote, _L("Widget clicked") ); |
|
254 User::After( 3000 ); // waiting for 3 seconds |
|
255 // discard note |
|
256 globalNote->CancelNoteL( noteId ); |
|
257 CleanupStack::PopAndDestroy(); |
|
258 iPublisher->StartTransaction( aWidgetId ); |
|
259 if( !iFeedCnt ) |
|
260 { |
|
261 iPublisher->PublishText( |
|
262 aWidgetId, _L8("text2"), KGFeed3 ); |
|
263 iFeedCnt = ETrue; |
|
264 } |
|
265 else |
|
266 {iPublisher->PublishText( |
|
267 aWidgetId, _L8("text3"), KGFeed2 ); |
|
268 iFeedCnt = EFalse; |
|
269 } |
|
270 |
|
271 iPublisher->CommitTransaction( aWidgetId ); |
|
272 } |
|
273 else if( aEvent == _L("OnTitleScrolled")) |
|
274 { |
|
275 TInt pos( KErrNotFound ); |
|
276 if( iWidgetIds->Find( aWidgetId, pos ) == 0 && pos % 2 == 1 ) |
|
277 { |
|
278 iPublisher->StartTransaction( aWidgetId ); |
|
279 if( iFeedCnt == 0 ) |
|
280 { |
|
281 iPublisher->PublishImage(aWidgetId, |
|
282 _L8("image1"), _L("c:\\data\\Installs\\cricket.png")); |
|
283 iFeedCnt++; |
|
284 } |
|
285 else if( iFeedCnt == 1 ) |
|
286 { |
|
287 iPublisher->PublishImage(aWidgetId, |
|
288 _L8("image1"), _L("c:\\data\\Installs\\tennis.png")); |
|
289 iFeedCnt++; |
|
290 } |
|
291 else if( iFeedCnt == 2) |
|
292 { |
|
293 iPublisher->PublishImage(aWidgetId, |
|
294 _L8("image1"), _L("c:\\data\\Installs\\f1.png")); |
|
295 iFeedCnt = 0; |
|
296 } |
|
297 iPublisher->CommitTransaction( aWidgetId ); |
|
298 } |
|
299 } |
|
300 |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 // |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CTestPublisherAppView::PublishL( const TDesC& aWidgetId ) |
|
309 { |
|
310 if ( iFlags.IsClear( ERequirePublish ) ) |
|
311 { |
|
312 // Can't publish without widget instance id or no reason to publish |
|
313 return; |
|
314 } |
|
315 if ( iFlags.IsSet( EPublishAllowed ) ) |
|
316 { |
|
317 iPublisher->StartTransaction( aWidgetId ); |
|
318 |
|
319 iPublisher->PublishImage(aWidgetId, |
|
320 _L8("graphic"), _L("c:\\data\\Installs\\rss.png")); |
|
321 |
|
322 iPublisher->PublishText( aWidgetId, _L8("text1"), KGFeed1 ); |
|
323 /* |
|
324 iPublisher->PublishText( |
|
325 aWidgetId, _L8("text2"), KGFeed2 ); |
|
326 iPublisher->PublishText( |
|
327 aWidgetId, _L8("text3"), KGFeed3 ); |
|
328 iPublisher->PublishText( |
|
329 aWidgetId, _L8("text4"), KSFeed1 ); |
|
330 */ |
|
331 iPublisher->PublishText( |
|
332 aWidgetId, _L8("title1"), KGFeed1 ); |
|
333 iPublisher->PublishText( |
|
334 aWidgetId, _L8("title2"), KGFeed2 ); |
|
335 iPublisher->PublishText( |
|
336 aWidgetId, _L8("title4"), KGFeed3 ); |
|
337 |
|
338 iPublisher->PublishText( |
|
339 aWidgetId, _L8("title3"), KSFeed1 ); |
|
340 iPublisher->PublishText( |
|
341 aWidgetId, _L8("title5"), KSFeed2 ); |
|
342 iPublisher->PublishText( |
|
343 aWidgetId, _L8("title6"), KSFeed3 ); |
|
344 |
|
345 |
|
346 iPublisher->PublishImage(aWidgetId, |
|
347 _L8("image1"), _L("c:\\data\\Installs\\rss_small.png")); |
|
348 iPublisher->PublishImage(aWidgetId, |
|
349 _L8("image2"), _L("c:\\data\\Installs\\rss_small.png")); |
|
350 iPublisher->PublishImage(aWidgetId, |
|
351 _L8("image3"), _L("c:\\data\\Installs\\rss_small.png")); |
|
352 |
|
353 iPublisher->CommitTransaction( aWidgetId ); |
|
354 |
|
355 iFlags.Clear( ERequirePublish ); |
|
356 } |
|
357 } |
|
358 |
|
359 // End of File |