|
1 /* |
|
2 * Copyright (c) 2008 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: Taskswitcher Fast Swap area UI |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <gulicon.h> |
|
20 #include <eikenv.h> |
|
21 #include <AknUtils.h> |
|
22 #include <AknIconUtils.h> |
|
23 #include <AknIconArray.h> |
|
24 #include <aknstyluspopupmenu.h> |
|
25 #include <AknQueryDialog.h> |
|
26 #include <StringLoader.h> |
|
27 #include <taskswitcher.rsg> |
|
28 #include <aknlayoutscalable_apps.cdl.h> |
|
29 #include <layoutmetadata.cdl.h> |
|
30 #include <aknlists.h> |
|
31 #include <touchfeedback.h> |
|
32 #include <akntransitionutils.h> |
|
33 #include <akntranseffect.h> |
|
34 #include <aknlongtapanimation.h> |
|
35 |
|
36 #include "tsfastswaparea.h" |
|
37 #include "tsapplogging.h" |
|
38 #include "tsfswclient.h" |
|
39 #include "tsappui.h" |
|
40 #include "tsdatachangeobserver.h" |
|
41 #include "tseventcontroler.h" |
|
42 #include "tsappview.h" |
|
43 |
|
44 /** command ids for the fsw popup */ |
|
45 enum TPopupCommands |
|
46 { |
|
47 EFswCmdClose = 10000, |
|
48 EFswCmdCloseAll |
|
49 }; |
|
50 |
|
51 /** Number of closable applications, to show "close all" option. */ |
|
52 const TInt KTsMaxClosableApps = 2; |
|
53 |
|
54 /** Default grid item to highlight.*/ |
|
55 const TInt KItemToHighlight = 2; |
|
56 |
|
57 const TInt KAppKeyTypeShort = 1; |
|
58 const TInt KAppKeyTypeLong = 2; |
|
59 |
|
60 const TInt KLayoutItemCount = 4; |
|
61 |
|
62 const TInt KRedrawTime = 250000; // 0.25 sec |
|
63 const TInt KRedrawTimeForLayoutSwitch = 700000; // 0.7 sec |
|
64 const TInt KHighlighActivationTime = 100000; // 100 ms |
|
65 const TInt KUpdateGridTime = 0; // imediately |
|
66 const TInt KOrientationSwitchTime = 1000000; // 1 sec |
|
67 const TInt KLongTapAnimationInitTime = 150000; // 0.15 sec |
|
68 const TInt KLongTapAnimationTimeout = 1000000; // 1 sec |
|
69 |
|
70 const TInt KMaxGranularity = 4; |
|
71 |
|
72 const TUid KTsMenuUid = { 0x101f4cd2 }; |
|
73 const TUid KTsHomescreenUid = { 0x102750f0 }; |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CTsFastSwapArea::NewL |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CTsFastSwapArea* CTsFastSwapArea::NewL( const TRect& aRect, |
|
80 CCoeControl& aParent, CTsDeviceState& aDeviceState, |
|
81 CTsEventControler& aEventHandler ) |
|
82 { |
|
83 CTsFastSwapArea* self = CTsFastSwapArea::NewLC(aRect, |
|
84 aParent, aDeviceState, aEventHandler); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CTsFastSwapArea::NewLC |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CTsFastSwapArea* CTsFastSwapArea::NewLC( const TRect& aRect, |
|
94 CCoeControl& aParent, CTsDeviceState& aDeviceState, |
|
95 CTsEventControler& aEventHandler) |
|
96 { |
|
97 CTsFastSwapArea* self = new (ELeave) CTsFastSwapArea( |
|
98 aParent, aDeviceState, aEventHandler); |
|
99 CleanupStack::PushL( self ); |
|
100 self->ConstructL( aRect ); |
|
101 return self; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CTsFastSwapArea::CTsFastSwapArea |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CTsFastSwapArea::CTsFastSwapArea(CCoeControl& aParent, |
|
109 CTsDeviceState& aDeviceState, |
|
110 CTsEventControler& aEventHandler) : |
|
111 iParent(aParent), iDeviceState(aDeviceState), iEvtHandler(aEventHandler), |
|
112 iIgnoreLayoutSwitch(EFalse), iWidgetClosingCount(0), iLongTapAnimationRunning(EFalse) |
|
113 { |
|
114 // no implementation required |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CTsFastSwapArea::~CTsFastSwapArea |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CTsFastSwapArea::~CTsFastSwapArea() |
|
122 { |
|
123 iArray.ResetAndDestroy(); |
|
124 iIsClosing.Close(); |
|
125 delete iGrid; |
|
126 delete iFSClient; |
|
127 delete iPopup; |
|
128 delete iHighlightTimer; |
|
129 delete iRedrawTimer; |
|
130 delete iUpdateGridTimer; |
|
131 delete iOrientationSignalTimer; |
|
132 delete iLongTapAnimation; |
|
133 delete iLongTapAnimationTimer; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CTsFastSwapArea::ConstructL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CTsFastSwapArea::ConstructL( const TRect& aRect ) |
|
141 { |
|
142 SetContainerWindowL( iParent ); |
|
143 |
|
144 SetRect( aRect ); |
|
145 |
|
146 // setup grid |
|
147 ReCreateGridL(); |
|
148 |
|
149 // create stylus popup instance |
|
150 PreCreatePopupL(); |
|
151 |
|
152 // connect to fsw server |
|
153 iFSClient = CTsFswClient::NewL(); |
|
154 |
|
155 iEvtHandler.ReInitPhysicsL(GridWorldSize(), ViewSize(), ETrue); |
|
156 |
|
157 // add self to device state observer |
|
158 iDeviceState.AddObserverL( *this, EDeviceType ); |
|
159 |
|
160 iHighlightTimer = new (ELeave) CTsFastSwapTimer( *this ); |
|
161 iHighlightTimer->ConstructL(); |
|
162 |
|
163 iRedrawTimer = new (ELeave) CTsFastSwapTimer( *this ); |
|
164 iRedrawTimer->ConstructL(); |
|
165 |
|
166 iUpdateGridTimer = new (ELeave) CTsFastSwapTimer( *this ); |
|
167 iUpdateGridTimer->ConstructL(); |
|
168 |
|
169 iOrientationSignalTimer = new (ELeave) CTsFastSwapTimer( *this ); |
|
170 iOrientationSignalTimer->ConstructL(); |
|
171 |
|
172 iLongTapAnimationTimer = new (ELeave) CTsFastSwapTimer( *this ); |
|
173 iLongTapAnimationTimer->ConstructL(); |
|
174 |
|
175 iActivateOnPointerRelease = TPoint(); |
|
176 iHandlePointerCandidate = EFalse; |
|
177 |
|
178 ActivateL(); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CTsFastSwapArea::ReCreateGridL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CTsFastSwapArea::ReCreateGridL() |
|
186 { |
|
187 MCoeControlObserver* obs = NULL; |
|
188 TBool wasHighlight = iDeviceState.DeviceType() == |
|
189 CTsDeviceState::EHybrid ? ETrue : EFalse; |
|
190 if ( iGrid ) |
|
191 { |
|
192 obs = iGrid->Observer(); |
|
193 iDeviceState.RemoveObserver(*iGrid); |
|
194 wasHighlight = iGrid->IsHighlightVisible(); |
|
195 delete iGrid; |
|
196 iGrid = NULL; |
|
197 } |
|
198 |
|
199 iGrid = new( ELeave ) CTsFastSwapGrid; |
|
200 iGrid->ConstructL( this ); |
|
201 iGrid->DisableSingleClick(ETrue);//enables highlight on pointer |
|
202 iDeviceState.AddObserverL(*iGrid, MTsDeviceStateObserver::ESkin); |
|
203 |
|
204 AknListBoxLayouts::SetupStandardGrid( *iGrid ); |
|
205 |
|
206 // Setup layout |
|
207 LayoutGridL(); |
|
208 |
|
209 if( wasHighlight ) |
|
210 { |
|
211 iGrid->ShowHighlight(); |
|
212 } |
|
213 else |
|
214 { |
|
215 iGrid->HideHighlight(); |
|
216 } |
|
217 |
|
218 // Setup empty text |
|
219 HBufC* text = StringLoader::LoadLC( R_TS_FSW_NO_APPS ); |
|
220 iGrid->SetEmptyGridTextL( *text ); |
|
221 CleanupStack::PopAndDestroy( text ); |
|
222 |
|
223 // Setup grid observers |
|
224 if ( obs ) |
|
225 { |
|
226 iGrid->SetObserver( obs ); |
|
227 } |
|
228 iGrid->SetListBoxObserver(this); |
|
229 iGrid->SetFastSwapGridObserver(this); |
|
230 iGrid->SetContainerWindowL(*this); |
|
231 |
|
232 // Make sure that there is an ActivateL call even when we are not |
|
233 // called from ConstructL. (in order to have the grid's parent ptr set properly) |
|
234 ActivateL(); |
|
235 } |
|
236 |
|
237 |
|
238 // -------------------------------------------------------------------------- |
|
239 // CTsFastSwapArea::LayoutGridL |
|
240 // -------------------------------------------------------------------------- |
|
241 // |
|
242 void CTsFastSwapArea::LayoutGridL() |
|
243 { |
|
244 RArray<TAknLayoutRect> rects; |
|
245 CleanupClosePushL(rects); |
|
246 rects.ReserveL(KLayoutItemCount); |
|
247 GetFastSwapAreaRects(rects); |
|
248 TAknLayoutRect gridAppPane = rects[0]; |
|
249 TAknLayoutRect gridItem = rects[1]; |
|
250 TAknLayoutRect gridImage = rects[2]; |
|
251 TAknLayoutRect gridNextItem = rects[3]; |
|
252 CleanupStack::PopAndDestroy(&rects); |
|
253 |
|
254 iGrid->SetRect(gridAppPane.Rect()); |
|
255 |
|
256 TInt variety; |
|
257 TBool disable = GetVariety(variety); |
|
258 if ( disable ) |
|
259 { |
|
260 TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL()); |
|
261 } |
|
262 variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic |
|
263 |
|
264 TAknLayoutScalableParameterLimits gridParams = |
|
265 AknLayoutScalable_Apps::cell_tport_appsw_pane_ParamLimits( variety ); |
|
266 TPoint empty( ELayoutEmpty, ELayoutEmpty ); |
|
267 |
|
268 // Setup bitmap layout |
|
269 AknListBoxLayouts::SetupFormGfxCell( *iGrid, iGrid->ItemDrawer(), 0, |
|
270 AknLayoutScalable_Apps::cell_tport_appsw_pane_g1( variety ).LayoutLine(), |
|
271 empty, empty ); |
|
272 |
|
273 // Setup text layout |
|
274 AknListBoxLayouts::SetupFormTextCell(*iGrid, iGrid->ItemDrawer(), 1, |
|
275 AknLayoutScalable_Apps::cell_tport_appsw_pane_t1( variety ).LayoutLine(), |
|
276 empty, empty); |
|
277 |
|
278 // Text colors |
|
279 TRgb textColor; |
|
280 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, |
|
281 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG19 ); |
|
282 TRgb highlightTextColor; |
|
283 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), highlightTextColor, |
|
284 KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 ); |
|
285 CFormattedCellListBoxData::TColors colors; |
|
286 colors.iText = textColor; |
|
287 colors.iBack = iGrid->ItemDrawer()->BackColor(); |
|
288 colors.iHighlightedText = highlightTextColor; |
|
289 colors.iHighlightedBack = iGrid->ItemDrawer()->HighlightedBackColor(); |
|
290 iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL(1, colors); |
|
291 iGrid->SetStrokeColors(textColor, highlightTextColor); |
|
292 |
|
293 if ( AknLayoutUtils::LayoutMirrored() ) |
|
294 { |
|
295 iGridItemGap = gridItem.Rect().iTl.iX - gridNextItem.Rect().iBr.iX; |
|
296 } |
|
297 else |
|
298 { |
|
299 iGridItemGap = gridNextItem.Rect().iTl.iX - gridItem.Rect().iBr.iX; |
|
300 } |
|
301 iMaxItemsOnScreen = Rect().Width() / gridItem.Rect().Width(); |
|
302 if ( iMaxItemsOnScreen > 1 ) |
|
303 { |
|
304 TInt widthWithGaps = |
|
305 (iMaxItemsOnScreen - 1) * iGridItemGap + iMaxItemsOnScreen * gridItem.Rect().Width(); |
|
306 if ( widthWithGaps > Rect().Width() ) |
|
307 { |
|
308 iMaxItemsOnScreen--; |
|
309 } |
|
310 } |
|
311 iGridItemWidth = gridItem.Rect().Width(); |
|
312 |
|
313 // Update item drawer |
|
314 iGrid->UpdateItemDrawerLayoutDataL(); |
|
315 |
|
316 // Update state |
|
317 HandleDeviceStateChanged( EDeviceType ); |
|
318 |
|
319 if ( disable ) |
|
320 { |
|
321 TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL()); |
|
322 } |
|
323 } |
|
324 |
|
325 |
|
326 // -------------------------------------------------------------------------- |
|
327 // CTsFastSwapArea::LayoutGridView |
|
328 // -------------------------------------------------------------------------- |
|
329 // |
|
330 void CTsFastSwapArea::LayoutGridViewL( TInt aItemCount ) |
|
331 { |
|
332 RArray<TAknLayoutRect> rects; |
|
333 CleanupClosePushL(rects); |
|
334 rects.ReserveL(KLayoutItemCount); |
|
335 GetFastSwapAreaRects(rects); |
|
336 TAknLayoutRect gridItem = rects[1]; |
|
337 CleanupStack::PopAndDestroy(&rects); |
|
338 if ( aItemCount ) |
|
339 { |
|
340 iGrid->ItemDrawer()->ColumnData()->SetDrawBackground(EFalse); |
|
341 static_cast<CTsAppView*>(&iParent)->EnableDragEvents(ETrue); |
|
342 if ( AknLayoutUtils::LayoutMirrored() ) |
|
343 { |
|
344 iGrid->SetLayoutL( EFalse, EFalse, ETrue, aItemCount, 1, gridItem.Rect().Size(), iGridItemGap ); |
|
345 } |
|
346 else |
|
347 { |
|
348 iGrid->SetLayoutL( EFalse, ETrue, ETrue, aItemCount, 1, gridItem.Rect().Size(), iGridItemGap ); |
|
349 } |
|
350 } |
|
351 else |
|
352 { |
|
353 iGrid->ItemDrawer()->ColumnData()->SetDrawBackground(ETrue); |
|
354 static_cast<CTsAppView*>(&iParent)->EnableDragEvents(EFalse); |
|
355 } |
|
356 |
|
357 // Update scrollbar frame |
|
358 if( iGrid->ScrollBarFrame() ) |
|
359 { |
|
360 iGrid->SetScrollBarFrame(NULL,CEikListBox::EOwnedExternally); |
|
361 } |
|
362 } |
|
363 |
|
364 |
|
365 // -------------------------------------------------------------------------- |
|
366 // CTsFastSwapArea::GetFastSwapAreaRects |
|
367 // -------------------------------------------------------------------------- |
|
368 // |
|
369 void CTsFastSwapArea::GetFastSwapAreaRects( RArray<TAknLayoutRect>& aRects ) |
|
370 { |
|
371 TAknLayoutRect gridAppPane; |
|
372 TAknLayoutRect gridItem; |
|
373 TAknLayoutRect gridImage; |
|
374 TAknLayoutRect gridNextItem; |
|
375 |
|
376 TInt variety; |
|
377 TBool disable = GetVariety(variety); |
|
378 if ( disable ) |
|
379 { |
|
380 TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL()); |
|
381 } |
|
382 variety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; // double check to avoid layout panic |
|
383 |
|
384 gridAppPane.LayoutRect( Rect(), |
|
385 AknLayoutScalable_Apps::tport_appsw_pane( variety ) ); |
|
386 aRects.Append(gridAppPane); |
|
387 |
|
388 gridItem.LayoutRect( gridAppPane.Rect(), |
|
389 AknLayoutScalable_Apps::cell_tport_appsw_pane( variety, 0, 0 ) ); |
|
390 aRects.Append(gridItem); |
|
391 |
|
392 gridImage.LayoutRect( gridItem.Rect(), |
|
393 AknLayoutScalable_Apps::cell_tport_appsw_pane_g1( variety ) ); |
|
394 aRects.Append(gridImage); |
|
395 gridNextItem.LayoutRect( gridAppPane.Rect(), |
|
396 AknLayoutScalable_Apps::cell_tport_appsw_pane_cp03( variety ) ); |
|
397 aRects.Append(gridNextItem); |
|
398 |
|
399 if ( disable ) |
|
400 { |
|
401 TRAP_IGNORE(static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL()); |
|
402 } |
|
403 } |
|
404 |
|
405 |
|
406 // -------------------------------------------------------------------------- |
|
407 // CTsFastSwapArea::Setup |
|
408 // -------------------------------------------------------------------------- |
|
409 // |
|
410 void CTsFastSwapArea::Setup( MCoeControlObserver& aControlObserver ) |
|
411 { |
|
412 iGrid->SetObserver( &aControlObserver ); |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CTsFastSwapArea::SizeChanged |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 void CTsFastSwapArea::SizeChanged() |
|
420 { |
|
421 TSLOG_CONTEXT( CTsFastSwapArea::SizeChanged, TSLOG_LOCAL ); |
|
422 TSLOG_IN(); |
|
423 |
|
424 if ( iGrid && !iIgnoreLayoutSwitch ) |
|
425 { |
|
426 // Cancel ongoing pointer event |
|
427 iHandlePointerCandidate = EFalse; |
|
428 // Grid needs to be recreated to proper reinitilize |
|
429 // data with new layout values |
|
430 TInt selIdx = SelectedIndex(); |
|
431 TRAPD(err, |
|
432 LayoutGridL(); |
|
433 LayoutGridViewL( iArray.Count() ); |
|
434 iEvtHandler.ReInitPhysicsL( GridWorldSize(), ViewSize(), ETrue ); |
|
435 ); |
|
436 |
|
437 if ( err != KErrNone ) |
|
438 { |
|
439 TSLOG1( TSLOG_INFO, "LayoutGridL leaves with %d", err ); |
|
440 } |
|
441 |
|
442 // Update grid view |
|
443 iGrid->SetCurrentDataIndex(selIdx); |
|
444 UpdateGrid(ETrue, EFalse); |
|
445 iGrid->DrawDeferred(); |
|
446 |
|
447 // Order full redraw after switch |
|
448 if(iRedrawTimer) |
|
449 { |
|
450 iRedrawTimer->Cancel(); |
|
451 iRedrawTimer->After(KRedrawTimeForLayoutSwitch); |
|
452 } |
|
453 } |
|
454 |
|
455 TSLOG_OUT(); |
|
456 } |
|
457 |
|
458 // ----------------------------------------------------------------------------- |
|
459 // CTsFastSwapArea::Draw |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 void CTsFastSwapArea::Draw( const TRect& /*aRect*/ ) const |
|
463 { |
|
464 // CWindowGc& gc = SystemGc(); |
|
465 // MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
466 // MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); |
|
467 // AknsDrawUtils::Background( skin, |
|
468 // cc, |
|
469 // this, |
|
470 // gc, |
|
471 // Rect() ); |
|
472 } |
|
473 |
|
474 // -------------------------------------------------------------------------- |
|
475 // CTsFastSwapArea::SwitchToApp |
|
476 // -------------------------------------------------------------------------- |
|
477 // |
|
478 void CTsFastSwapArea::SwitchToApp( TInt aIndex ) |
|
479 { |
|
480 if ( aIndex >= 0 && aIndex < iArray.Count() ) |
|
481 { |
|
482 TInt wgId = iArray[aIndex]->WgId(); |
|
483 TUid appUid = iArray[aIndex]->AppUid(); |
|
484 SwitchToApp( wgId, appUid ); |
|
485 } |
|
486 } |
|
487 |
|
488 // -------------------------------------------------------------------------- |
|
489 // CTsFastSwapArea::SwitchToApp |
|
490 // -------------------------------------------------------------------------- |
|
491 // |
|
492 void CTsFastSwapArea::SwitchToApp( const TUid& aUid ) |
|
493 { |
|
494 TApaTaskList taskList( iEikonEnv->WsSession() ); |
|
495 TApaTask task = taskList.FindApp( aUid ); |
|
496 TInt wgId = task.WgId(); |
|
497 SwitchToApp( wgId, aUid ); |
|
498 } |
|
499 |
|
500 |
|
501 // -------------------------------------------------------------------------- |
|
502 // CTsFastSwapArea::SwitchToApp |
|
503 // -------------------------------------------------------------------------- |
|
504 // |
|
505 void CTsFastSwapArea::SwitchToApp( TInt aWgId, const TUid& aUid ) |
|
506 { |
|
507 CTsAppUi* appui = |
|
508 static_cast<CTsAppUi*>( iEikonEnv->AppUi() ); |
|
509 TBool effectsEnabled = appui->EffectsEnabled(); |
|
510 |
|
511 // Move other app to foreground |
|
512 if ( !effectsEnabled ) |
|
513 { |
|
514 iFSClient->SwitchToApp( aWgId ); |
|
515 } |
|
516 |
|
517 // We do not want to come back to ts if the activated app is closed. |
|
518 // Therefore ts must be moved to background. Ignore orientation updates, it |
|
519 // will be done after task switcher is sent to background |
|
520 iIgnoreLayoutSwitch = ETrue; |
|
521 appui->MoveAppToBackground( CTsAppUi::EActivationTransition, aUid, aWgId ); |
|
522 iIgnoreLayoutSwitch = EFalse; |
|
523 |
|
524 // Move other app to foreground |
|
525 if ( effectsEnabled ) |
|
526 { |
|
527 iFSClient->SwitchToApp( aWgId ); |
|
528 } |
|
529 |
|
530 // Orientation update |
|
531 iPrevScreenOrientation = -1; // force orientation reinit |
|
532 iOrientationSignalTimer->Cancel(); |
|
533 iOrientationSignalTimer->After(KOrientationSwitchTime); |
|
534 } |
|
535 |
|
536 // -------------------------------------------------------------------------- |
|
537 // CTsFastSwapArea::TryCloseAppL |
|
538 // -------------------------------------------------------------------------- |
|
539 // |
|
540 void CTsFastSwapArea::TryCloseAppL( TInt aIndex, |
|
541 TBool aSuppressRendering ) |
|
542 { |
|
543 TSLOG_CONTEXT( TryCloseAppL, TSLOG_LOCAL ); |
|
544 TSLOG2_IN( "%d %d", aIndex, aSuppressRendering ); |
|
545 |
|
546 if ( aIndex >= 0 && aIndex < iArray.Count() && CanClose( aIndex ) ) |
|
547 { |
|
548 TInt wgId = iArray[aIndex]->WgId(); |
|
549 iFSClient->CloseApp( wgId ); |
|
550 iIsClosing.Append(wgId); |
|
551 if ( iArray[aIndex]->Widget() ) |
|
552 { |
|
553 iWidgetClosingCount++; |
|
554 } |
|
555 |
|
556 // Orientation update |
|
557 iPrevScreenOrientation = GetCurrentScreenOrientation(); |
|
558 iOrientationSignalTimer->Cancel(); |
|
559 iOrientationSignalTimer->After(KOrientationSwitchTime); |
|
560 } |
|
561 |
|
562 TSLOG_OUT(); |
|
563 } |
|
564 |
|
565 // -------------------------------------------------------------------------- |
|
566 // CTsFastSwapArea::TryCloseAllL |
|
567 // -------------------------------------------------------------------------- |
|
568 // |
|
569 void CTsFastSwapArea::TryCloseAllL() |
|
570 { |
|
571 for ( TInt i = iArray.Count() - 1; i >= 0; --i ) |
|
572 { |
|
573 if ( CanClose( i ) ) |
|
574 { |
|
575 TryCloseAppL( i, ETrue ); |
|
576 } |
|
577 } |
|
578 } |
|
579 |
|
580 // -------------------------------------------------------------------------- |
|
581 // CTsFastSwapArea::CanClose |
|
582 // -------------------------------------------------------------------------- |
|
583 // |
|
584 TBool CTsFastSwapArea::CanClose( TInt aIndex ) const |
|
585 { |
|
586 TBool canClose(EFalse); |
|
587 if ( aIndex >= 0 && aIndex < iArray.Count() ) |
|
588 { |
|
589 CTsFswEntry* e = iArray[aIndex]; |
|
590 canClose = !e->AlwaysShown() && !e->SystemApp(); |
|
591 // Special cases: Menu |
|
592 canClose |= e->AppUid() == KTsMenuUid; |
|
593 } |
|
594 return canClose; |
|
595 } |
|
596 |
|
597 // -------------------------------------------------------------------------- |
|
598 // CTsFastSwapArea::CanCloseOthers |
|
599 // -------------------------------------------------------------------------- |
|
600 // |
|
601 TBool CTsFastSwapArea::CanCloseAll( TInt aSelectedItem ) const |
|
602 { |
|
603 TInt count( 0 ); |
|
604 |
|
605 // Count number of closable applications and if number exceeds 2 finish |
|
606 // counting, because it is already enough to show the option. |
|
607 for ( TInt i = iArray.Count(); --i >= 0 && count < KTsMaxClosableApps; ) |
|
608 { |
|
609 if ( CanClose( i ) ) |
|
610 { |
|
611 count++; |
|
612 } |
|
613 } |
|
614 return ( count >= KTsMaxClosableApps ) || |
|
615 ( count && !CanClose( aSelectedItem ) ); |
|
616 } |
|
617 |
|
618 // -------------------------------------------------------------------------- |
|
619 // CTsFastSwapArea::HandleFswContentChanged |
|
620 // From MTsFswObserver |
|
621 // -------------------------------------------------------------------------- |
|
622 // |
|
623 void CTsFastSwapArea::HandleFswContentChanged() |
|
624 { |
|
625 TSLOG_CONTEXT( HandleFswContentChanged, TSLOG_LOCAL ); |
|
626 TSLOG_IN(); |
|
627 |
|
628 TRAPD( err, HandleFswContentChangedL() ); |
|
629 if ( err != KErrNone ) |
|
630 { |
|
631 TSLOG1( TSLOG_INFO, "leave occured: %d", err ); |
|
632 } |
|
633 |
|
634 TSLOG_OUT(); |
|
635 } |
|
636 |
|
637 // -------------------------------------------------------------------------- |
|
638 // CTsFastSwapArea::HandleFswContentChangedL |
|
639 // -------------------------------------------------------------------------- |
|
640 // |
|
641 void CTsFastSwapArea::HandleFswContentChangedL() |
|
642 { |
|
643 TSLOG_CONTEXT( HandleFswContentChangedL, TSLOG_LOCAL ); |
|
644 TSLOG_IN(); |
|
645 |
|
646 // get current content from fastswap server |
|
647 iFSClient->GetContentL( iArray ); |
|
648 |
|
649 #ifdef _DEBUG |
|
650 for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i ) |
|
651 { |
|
652 CTsFswEntry* e = iArray[i]; |
|
653 const TDesC& name( e->AppName() ); |
|
654 TSLOG4( TSLOG_INFO, "[%d]: %d %d %S", i, e->WgId(), e->AppUid(), &name ); |
|
655 } |
|
656 #endif |
|
657 |
|
658 // Update closing widget count if necessary |
|
659 if ( iWidgetClosingCount ) |
|
660 { |
|
661 TInt widgetCount(0); |
|
662 for ( TInt i = 0, ie = iArray.Count(); i != ie; ++i ) |
|
663 { |
|
664 if ( iArray[i]->Widget() ) |
|
665 { |
|
666 widgetCount++; |
|
667 } |
|
668 } |
|
669 iWidgetClosingCount = widgetCount; |
|
670 } |
|
671 |
|
672 // draw |
|
673 RenderContentL(); |
|
674 |
|
675 // notify observer, if present |
|
676 NotifyChange(); |
|
677 |
|
678 TSLOG_OUT(); |
|
679 } |
|
680 |
|
681 // -------------------------------------------------------------------------- |
|
682 // CTsFastSwapArea::RenderContentL |
|
683 // -------------------------------------------------------------------------- |
|
684 // |
|
685 void CTsFastSwapArea::RenderContentL( TBool aSuppressAnimation ) |
|
686 { |
|
687 TSLOG_CONTEXT( RenderContentL, TSLOG_LOCAL ); |
|
688 TSLOG_IN(); |
|
689 |
|
690 _LIT(KSeparator, "\t"); |
|
691 |
|
692 CArrayPtr<CGulIcon>* iconArray = new ( ELeave ) CAknIconArray( KMaxGranularity ); |
|
693 CleanupStack::PushL( iconArray ); |
|
694 CDesCArrayFlat* textArray = new ( ELeave ) CDesCArrayFlat( KMaxGranularity ); |
|
695 CleanupStack::PushL( textArray ); |
|
696 RArray<TInt> closeItemArray; |
|
697 CleanupClosePushL(closeItemArray); |
|
698 RArray<TInt> strokeItemArray; |
|
699 CleanupClosePushL(strokeItemArray); |
|
700 |
|
701 // Update view based on number of items |
|
702 LayoutGridViewL( iArray.Count() ); |
|
703 |
|
704 for ( TInt i = 0; i < iArray.Count(); ++i ) |
|
705 { |
|
706 const TDesC& appName( iArray[i]->AppName() ); |
|
707 const TInt formatLen = 3 + 2; |
|
708 RBuf formAppName; |
|
709 CleanupClosePushL(formAppName); |
|
710 formAppName.CreateL(appName.Length() + formatLen); |
|
711 formAppName.AppendNum(i); |
|
712 formAppName.Append(KSeparator); |
|
713 formAppName.Append(appName); |
|
714 textArray->AppendL(formAppName); |
|
715 CleanupStack::PopAndDestroy(&formAppName); |
|
716 TSize sz = PreferredImageSize(); |
|
717 |
|
718 // take the screenshot or appicon+mask and make a copy and scale |
|
719 CFbsBitmap* bitmap = 0; |
|
720 TInt h = iArray[i]->ScreenshotHandle(); |
|
721 TSLOG2( TSLOG_INFO, "'%S' screenshot handle %d", &appName, h ); |
|
722 TInt maskh = 0; |
|
723 CFbsBitmap* mask = 0; |
|
724 if ( !h ) |
|
725 { |
|
726 // No screenshot, take app icon |
|
727 h = iArray[i]->AppIconBitmapHandle(); |
|
728 maskh = iArray[i]->AppIconMaskHandle(); |
|
729 TSLOG1( TSLOG_INFO, "using appicon, handle = %d", h ); |
|
730 } |
|
731 else |
|
732 { |
|
733 // Screenshot exists, mark it for stroke |
|
734 strokeItemArray.AppendL(i); |
|
735 } |
|
736 __ASSERT_DEBUG( h, User::Invariant() ); |
|
737 bitmap = CopyBitmapL( h, sz ); |
|
738 CleanupStack::PushL( bitmap ); |
|
739 if ( maskh ) |
|
740 { |
|
741 mask = CopyBitmapL( maskh, sz ); |
|
742 } |
|
743 CleanupStack::PushL( mask ); |
|
744 |
|
745 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
746 CleanupStack::PushL(icon); |
|
747 iconArray->AppendL(icon); |
|
748 CleanupStack::Pop( 3, bitmap ); // mask, bitmap, icon |
|
749 |
|
750 // Check if item can be closed |
|
751 if ( CanClose(i) && AknLayoutUtils::PenEnabled() ) |
|
752 { |
|
753 closeItemArray.AppendL(i); |
|
754 } |
|
755 } |
|
756 // Setup grid |
|
757 iGrid->Model()->SetItemTextArray(textArray); |
|
758 CArrayPtr<CGulIcon>* oldIconArray = |
|
759 iGrid->ItemDrawer()->FormattedCellData()->IconArray(); |
|
760 if(oldIconArray) |
|
761 { |
|
762 delete oldIconArray; |
|
763 oldIconArray = NULL; |
|
764 } |
|
765 iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL(iconArray); |
|
766 iGrid->SetCloseItemsL(closeItemArray); |
|
767 iGrid->SetStrokeItemsL(strokeItemArray); |
|
768 |
|
769 // Update scrollbar visibility |
|
770 if( iGrid->ScrollBarFrame() ) |
|
771 { |
|
772 iGrid->SetScrollBarFrame(NULL,CEikListBox::EOwnedExternally); |
|
773 } |
|
774 |
|
775 // Cleanup |
|
776 CleanupStack::PopAndDestroy(&strokeItemArray); |
|
777 CleanupStack::PopAndDestroy(&closeItemArray); |
|
778 CleanupStack::Pop(textArray); |
|
779 CleanupStack::Pop(iconArray); |
|
780 |
|
781 // refresh the items in the grid |
|
782 iGrid->HandleItemAdditionL(); |
|
783 iEvtHandler.ReInitPhysicsL( GridWorldSize(), ViewSize(), ETrue ); |
|
784 if ( SelectedIndex() >= GridItemCount() && GridItemCount() ) |
|
785 { |
|
786 iGrid->SetCurrentDataIndex( GridItemCount() - 1 ); |
|
787 } |
|
788 UpdateGrid( ETrue, !aSuppressAnimation ); |
|
789 |
|
790 TSLOG_OUT(); |
|
791 } |
|
792 |
|
793 // -------------------------------------------------------------------------- |
|
794 // CTsFastSwapArea::CopyBitmapL |
|
795 // Copy and scale. |
|
796 // -------------------------------------------------------------------------- |
|
797 // |
|
798 CFbsBitmap* CTsFastSwapArea::CopyBitmapL( TInt aFbsHandle, TSize aSize ) |
|
799 { |
|
800 CFbsBitmap* ret = new (ELeave) CFbsBitmap(); |
|
801 CleanupStack::PushL( ret ); |
|
802 |
|
803 CFbsBitmap* bmp = new (ELeave) CFbsBitmap(); |
|
804 CleanupStack::PushL( bmp ); |
|
805 User::LeaveIfError( bmp->Duplicate( aFbsHandle ) ); |
|
806 |
|
807 // do not always use aSize, preserving the aspect ratio is quite |
|
808 // important when showing app icons instead of screenshots |
|
809 TSize sz = CalculateSizePreserveRatio( aSize, bmp->SizeInPixels() ); |
|
810 User::LeaveIfError( ret->Create( sz, bmp->DisplayMode() ) ); |
|
811 |
|
812 AknIconUtils::ScaleBitmapL( sz, ret, bmp ); |
|
813 |
|
814 CleanupStack::PopAndDestroy( bmp ); |
|
815 CleanupStack::Pop( ret ); |
|
816 |
|
817 return ret; |
|
818 } |
|
819 |
|
820 // -------------------------------------------------------------------------- |
|
821 // CTsFastSwapArea::CountComponentControls |
|
822 // -------------------------------------------------------------------------- |
|
823 // |
|
824 TInt CTsFastSwapArea::CountComponentControls() const |
|
825 { |
|
826 return 1; |
|
827 } |
|
828 |
|
829 // -------------------------------------------------------------------------- |
|
830 // CTsFastSwapArea::ComponentControl |
|
831 // -------------------------------------------------------------------------- |
|
832 // |
|
833 CCoeControl* CTsFastSwapArea::ComponentControl( TInt aIndex ) const |
|
834 { |
|
835 if ( aIndex == 0 ) |
|
836 { |
|
837 return iGrid; |
|
838 } |
|
839 return NULL; |
|
840 } |
|
841 |
|
842 // ----------------------------------------------------------------------------- |
|
843 // CTsFastSwapArea::HandleSwitchToBackgroundEvent |
|
844 // ----------------------------------------------------------------------------- |
|
845 // |
|
846 void CTsFastSwapArea::HandleSwitchToBackgroundEvent() |
|
847 { |
|
848 // stop listening for changes in fsw content |
|
849 iFSClient->CancelSubscribe(); |
|
850 // Hide highlight |
|
851 if ( iGrid->GridBehaviour() == CTsFastSwapGrid::ETouchOnly ) |
|
852 { |
|
853 iGrid->HideHighlight(); |
|
854 } |
|
855 CancelLongTapAnimation(); |
|
856 iGrid->MakeVisible(EFalse); |
|
857 iGrid->DrawNow(); |
|
858 } |
|
859 |
|
860 // ----------------------------------------------------------------------------- |
|
861 // CTsFastSwapArea::HandleSwitchToForegroundEvent |
|
862 // ----------------------------------------------------------------------------- |
|
863 // |
|
864 void CTsFastSwapArea::HandleSwitchToForegroundEvent() |
|
865 { |
|
866 TSLOG_CONTEXT( CTsFastSwapArea::HandleSwitchToForegroundEvent, TSLOG_LOCAL ); |
|
867 TSLOG_IN(); |
|
868 |
|
869 iIsClosing.Reset(); |
|
870 iWidgetClosingCount = 0; |
|
871 iHandlePointerCandidate = EFalse; |
|
872 |
|
873 CTsGridItemDrawer* itemDrawer = |
|
874 static_cast<CTsGridItemDrawer*>( iGrid->ItemDrawer() ); |
|
875 itemDrawer->SetRedrawBackground(ETrue); |
|
876 |
|
877 // Update Layout |
|
878 CTsAppUi* appUi = static_cast<CTsAppUi*>(iEikonEnv->AppUi()); |
|
879 if ( appUi && appUi->EffectsEnabled() ) |
|
880 { |
|
881 TRAP_IGNORE( LayoutGridL() ); |
|
882 } |
|
883 |
|
884 // Reset grid |
|
885 if ( iDeviceState.DeviceType() == CTsDeviceState::EFullTouch ) |
|
886 { |
|
887 iGrid->HideHighlight(); |
|
888 } |
|
889 else |
|
890 { |
|
891 iGrid->ShowHighlight(); |
|
892 } |
|
893 |
|
894 // get the current task list |
|
895 HandleFswContentChanged(); |
|
896 // and then start listening for changes |
|
897 iFSClient->Subscribe( *this ); |
|
898 |
|
899 RestoreSelectedIndex(); |
|
900 UpdateGrid(EFalse, EFalse); |
|
901 |
|
902 iRedrawTimer->Cancel(); |
|
903 iRedrawTimer->After(KRedrawTime); |
|
904 |
|
905 // give feedback |
|
906 LaunchPopupFeedback(); |
|
907 |
|
908 iPrevAppCount = iArray.Count(); |
|
909 |
|
910 if ( !appUi->DelayedForegroundLaunched() ) |
|
911 { |
|
912 iGrid->MakeVisible(ETrue); |
|
913 } |
|
914 |
|
915 TSLOG_OUT(); |
|
916 } |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // CTsFastSwapArea::FocusChanged |
|
920 // ----------------------------------------------------------------------------- |
|
921 // |
|
922 void CTsFastSwapArea::FocusChanged( TDrawNow /*aDrawNow*/ ) |
|
923 { |
|
924 if ( IsFocused() ) |
|
925 { |
|
926 // if in non-touch mode then select (highlight) some item |
|
927 if ( !AknLayoutUtils::PenEnabled() |
|
928 && SelectedIndex() == KErrNotFound |
|
929 && GridItemCount() ) |
|
930 { |
|
931 RestoreSelectedIndex(); |
|
932 } |
|
933 } |
|
934 else |
|
935 { |
|
936 // store the currently selected index if there is one |
|
937 SaveSelectedIndex(); |
|
938 } |
|
939 } |
|
940 |
|
941 // ----------------------------------------------------------------------------- |
|
942 // CTsFastSwapArea::OfferKeyEventL |
|
943 // ----------------------------------------------------------------------------- |
|
944 // |
|
945 TKeyResponse CTsFastSwapArea::OfferKeyEventL( |
|
946 const TKeyEvent& aKeyEvent, |
|
947 TEventCode aType ) |
|
948 { |
|
949 CancelLongTapAnimation(); |
|
950 |
|
951 iKeyEvent = ETrue; |
|
952 |
|
953 //do not forward the event until item is higlighted |
|
954 TKeyResponse response = ShowHighlightOnKeyEvent(aKeyEvent, aType); |
|
955 if( response == EKeyWasConsumed ) |
|
956 { |
|
957 return EKeyWasConsumed; |
|
958 } |
|
959 |
|
960 // handle the 'clear' key |
|
961 if ( aType == EEventKey && aKeyEvent.iCode == EKeyBackspace ) |
|
962 { |
|
963 TInt idx = SelectedIndex(); |
|
964 if ( idx >= 0 ) |
|
965 { |
|
966 TryCloseAppL( idx ); |
|
967 } |
|
968 return EKeyWasConsumed; |
|
969 } |
|
970 |
|
971 // pass the event to grid |
|
972 // do not pass down and up arrow key events |
|
973 if ( aKeyEvent.iScanCode != EStdKeyUpArrow && |
|
974 aKeyEvent.iScanCode != EStdKeyDownArrow && |
|
975 aKeyEvent.iScanCode != EStdKeyApplication0 ) |
|
976 { |
|
977 TBool animate(ETrue); |
|
978 TBool redraw(EFalse); |
|
979 TInt prevItem = SelectedIndex(); |
|
980 TKeyResponse response = iGrid->OfferKeyEventL( aKeyEvent, aType ); |
|
981 if ( prevItem != SelectedIndex() && // item changed |
|
982 ( ( prevItem == 0 && |
|
983 SelectedIndex() == GridItemCount() - 1 && |
|
984 GridItemCount() > iMaxItemsOnScreen + 1 ) || // loop from first to last item |
|
985 ( prevItem == GridItemCount() - 1 && |
|
986 SelectedIndex() == 0 && |
|
987 GridItemCount() > iMaxItemsOnScreen + 1) // loop from last to first item |
|
988 ) // loop |
|
989 ) |
|
990 { |
|
991 // Loop occured |
|
992 animate = EFalse; |
|
993 } |
|
994 if ( prevItem != SelectedIndex() ) |
|
995 { |
|
996 redraw = ETrue; |
|
997 iGrid->ShowHighlight(); |
|
998 } |
|
999 UpdateGrid( redraw, animate ); |
|
1000 return response; |
|
1001 } |
|
1002 |
|
1003 return EKeyWasNotConsumed; |
|
1004 } |
|
1005 |
|
1006 // ----------------------------------------------------------------------------- |
|
1007 // CTsFastSwapArea::CatchKeyEvent |
|
1008 // ----------------------------------------------------------------------------- |
|
1009 // |
|
1010 TKeyResponse CTsFastSwapArea::ShowHighlightOnKeyEvent( |
|
1011 const TKeyEvent& aKeyEvent, TEventCode aType) |
|
1012 { |
|
1013 TKeyResponse retVal(EKeyWasNotConsumed); |
|
1014 |
|
1015 if (aKeyEvent.iScanCode == EStdKeyLeftArrow || |
|
1016 aKeyEvent.iScanCode == EStdKeyRightArrow || |
|
1017 aKeyEvent.iScanCode == EStdKeyDevice3 || |
|
1018 aKeyEvent.iScanCode == EStdKeyBackspace || |
|
1019 aKeyEvent.iScanCode == EStdKeyEnter ) |
|
1020 { |
|
1021 if (!iGrid->IsHighlightVisible()) |
|
1022 { |
|
1023 if (aType == EEventKey) |
|
1024 { |
|
1025 iGrid->ShowHighlight(); |
|
1026 iConsumeEvent = ETrue; |
|
1027 } |
|
1028 retVal = EKeyWasConsumed; |
|
1029 } |
|
1030 else if (iConsumeEvent) |
|
1031 { |
|
1032 if (aType == EEventKeyUp) |
|
1033 { |
|
1034 retVal = EKeyWasConsumed; |
|
1035 } |
|
1036 else |
|
1037 { |
|
1038 iConsumeEvent = EFalse; |
|
1039 } |
|
1040 } |
|
1041 } |
|
1042 return retVal; |
|
1043 } |
|
1044 |
|
1045 |
|
1046 // ----------------------------------------------------------------------------- |
|
1047 // CTsFastSwapArea::HandlePointerEventL |
|
1048 // ----------------------------------------------------------------------------- |
|
1049 // |
|
1050 void CTsFastSwapArea::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
1051 { |
|
1052 iKeyEvent = EFalse; |
|
1053 if(aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
1054 { |
|
1055 iHandlePointerCandidate = ETrue; |
|
1056 iTapEvent = aPointerEvent; |
|
1057 iGrid->EnableAknEventHandling(EFalse); |
|
1058 iGrid->HandlePointerEventL(aPointerEvent); |
|
1059 iGrid->EnableAknEventHandling(ETrue); |
|
1060 // Check if long tap animation should be launched |
|
1061 if ( LongTapAnimForPos(aPointerEvent.iParentPosition) ) |
|
1062 { |
|
1063 iLongTapAnimationTimer->Cancel(); |
|
1064 iLongTapAnimationTimer->After(KLongTapAnimationInitTime); |
|
1065 } |
|
1066 } |
|
1067 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
1068 { |
|
1069 CancelLongTapAnimation( EFalse ); |
|
1070 if( iActivateOnPointerRelease != TPoint() ) |
|
1071 { |
|
1072 iHandlePointerCandidate = ETrue; |
|
1073 TapL(iActivateOnPointerRelease); |
|
1074 iActivateOnPointerRelease = TPoint(); |
|
1075 } |
|
1076 } |
|
1077 } |
|
1078 |
|
1079 // ----------------------------------------------------------------------------- |
|
1080 // CTsFastSwapArea::SelectedIndex |
|
1081 // ----------------------------------------------------------------------------- |
|
1082 // |
|
1083 TInt CTsFastSwapArea::SelectedIndex() const |
|
1084 { |
|
1085 return iGrid->CurrentDataIndex(); |
|
1086 } |
|
1087 |
|
1088 // ----------------------------------------------------------------------------- |
|
1089 // CTsFastSwapArea::SaveSelectedIndex |
|
1090 // ----------------------------------------------------------------------------- |
|
1091 // |
|
1092 void CTsFastSwapArea::SaveSelectedIndex() |
|
1093 { |
|
1094 iSavedSelectedIndex = SelectedIndex(); |
|
1095 } |
|
1096 |
|
1097 // ----------------------------------------------------------------------------- |
|
1098 // CTsFastSwapArea::RestoreSelectedIndex |
|
1099 // ----------------------------------------------------------------------------- |
|
1100 // |
|
1101 void CTsFastSwapArea::RestoreSelectedIndex() |
|
1102 { |
|
1103 iSavedSelectedIndex = KErrNotFound; |
|
1104 if ( GridItemCount() ) |
|
1105 { |
|
1106 // highlight second recent item (that has index 1) if possible |
|
1107 TInt highlightItem = 0; |
|
1108 TInt count = GridItemCount(); |
|
1109 while( highlightItem < count |
|
1110 && highlightItem < KItemToHighlight ) |
|
1111 { |
|
1112 ++highlightItem; |
|
1113 } |
|
1114 iSavedSelectedIndex = highlightItem - 1;//count from 0 |
|
1115 iGrid->SetCurrentDataIndex( iSavedSelectedIndex ); |
|
1116 } |
|
1117 } |
|
1118 |
|
1119 // ----------------------------------------------------------------------------- |
|
1120 // CTsFastSwapArea::ProcessCommandL |
|
1121 // Handle fsw popup commands |
|
1122 // ----------------------------------------------------------------------------- |
|
1123 // |
|
1124 void CTsFastSwapArea::ProcessCommandL( TInt aCommandId ) |
|
1125 { |
|
1126 static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL(); |
|
1127 switch ( aCommandId ) |
|
1128 { |
|
1129 case EFswCmdClose: |
|
1130 TryCloseAppL( iAppIndexForPopup ); |
|
1131 break; |
|
1132 |
|
1133 case EFswCmdCloseAll: |
|
1134 TryCloseAllL(); |
|
1135 break; |
|
1136 |
|
1137 case KErrCancel: |
|
1138 // popup dismisses automatically when tapping outside or when switching to other app |
|
1139 break; |
|
1140 } |
|
1141 } |
|
1142 |
|
1143 |
|
1144 // ----------------------------------------------------------------------------- |
|
1145 // CTsFastSwapArea::HandleCloseEventL |
|
1146 // ----------------------------------------------------------------------------- |
|
1147 // |
|
1148 void CTsFastSwapArea::HandleCloseEventL(TInt aItemIdx) |
|
1149 { |
|
1150 TryCloseAppL( aItemIdx ); |
|
1151 } |
|
1152 |
|
1153 |
|
1154 // ----------------------------------------------------------------------------- |
|
1155 // CTsFastSwapArea::HandleDeviceStateChanged |
|
1156 // ----------------------------------------------------------------------------- |
|
1157 // |
|
1158 void CTsFastSwapArea::HandleDeviceStateChanged( TChangeType aChangeType ) |
|
1159 { |
|
1160 if ( aChangeType == EDeviceType ) |
|
1161 { |
|
1162 CTsDeviceState::TDeviceType state = iDeviceState.DeviceType(); |
|
1163 switch ( state ) |
|
1164 { |
|
1165 case CTsDeviceState::EHybrid: |
|
1166 { |
|
1167 iGrid->SetGridBehaviour( CTsFastSwapGrid::EHybrid ); |
|
1168 } |
|
1169 break; |
|
1170 case CTsDeviceState::EFullTouch: |
|
1171 { |
|
1172 iGrid->SetGridBehaviour( CTsFastSwapGrid::ETouchOnly ); |
|
1173 } |
|
1174 break; |
|
1175 default: |
|
1176 break; |
|
1177 } |
|
1178 } |
|
1179 } |
|
1180 |
|
1181 |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // CTsFastSwapArea::TimerCompletedL |
|
1184 // ----------------------------------------------------------------------------- |
|
1185 // |
|
1186 void CTsFastSwapArea::TimerCompletedL( CTsFastSwapTimer* aSource ) |
|
1187 { |
|
1188 if(aSource == iHighlightTimer) |
|
1189 { |
|
1190 iTapEvent.iType = TPointerEvent::EButton1Up; |
|
1191 iGrid->HandlePointerEventL(iTapEvent); |
|
1192 } |
|
1193 else if(aSource == iRedrawTimer) |
|
1194 { |
|
1195 iGrid->MakeVisible(ETrue); |
|
1196 static_cast<CTsAppView*>(&iParent)->OrderFullWindowRedraw(); |
|
1197 } |
|
1198 else if( aSource == iUpdateGridTimer ) |
|
1199 { |
|
1200 UpdateGrid(ETrue, ETrue); |
|
1201 } |
|
1202 else if ( aSource == iOrientationSignalTimer ) |
|
1203 { |
|
1204 TInt currentOrientation = GetCurrentScreenOrientation(); |
|
1205 if ( currentOrientation != iPrevScreenOrientation ) |
|
1206 { |
|
1207 // Order layout change |
|
1208 static_cast<CAknAppUi*>(iCoeEnv->AppUi())->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch); |
|
1209 iRedrawTimer->Cancel(); |
|
1210 iRedrawTimer->After(KRedrawTime); |
|
1211 } |
|
1212 } |
|
1213 else if ( aSource == iLongTapAnimationTimer ) |
|
1214 { |
|
1215 if ( iLongTapAnimationRunning ) |
|
1216 { |
|
1217 CancelLongTapAnimation(); |
|
1218 } |
|
1219 else |
|
1220 { |
|
1221 static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL(); |
|
1222 if ( iLongTapAnimation ) |
|
1223 { |
|
1224 delete iLongTapAnimation; |
|
1225 iLongTapAnimation = NULL; |
|
1226 } |
|
1227 iLongTapAnimation = CAknLongTapAnimation::NewL(EFalse); |
|
1228 iLongTapAnimation->SetParent( this ); |
|
1229 iLongTapAnimation->ShowAnimationL( iTapEvent.iParentPosition.iX, |
|
1230 iTapEvent.iParentPosition.iY ); |
|
1231 iLongTapAnimationRunning = ETrue; |
|
1232 iLongTapAnimationTimer->Cancel(); |
|
1233 iLongTapAnimationTimer->After(KLongTapAnimationTimeout); |
|
1234 } |
|
1235 } |
|
1236 } |
|
1237 |
|
1238 |
|
1239 // ----------------------------------------------------------------------------- |
|
1240 // CTsFastSwapArea::PreCreatePopupL |
|
1241 // ----------------------------------------------------------------------------- |
|
1242 // |
|
1243 void CTsFastSwapArea::PreCreatePopupL() |
|
1244 { |
|
1245 if ( !iPopup ) |
|
1246 { |
|
1247 iPopup = CAknStylusPopUpMenu::NewL( this, Rect().iTl ); |
|
1248 HBufC* text = StringLoader::LoadLC( R_TS_FSW_CLOSE ); |
|
1249 iPopup->AddMenuItemL( *text, EFswCmdClose ); |
|
1250 CleanupStack::PopAndDestroy( text ); |
|
1251 text = StringLoader::LoadLC( R_TS_FSW_CLOSE_ALL ); |
|
1252 iPopup->AddMenuItemL( *text, EFswCmdCloseAll ); |
|
1253 CleanupStack::PopAndDestroy( text ); |
|
1254 } |
|
1255 } |
|
1256 |
|
1257 // ----------------------------------------------------------------------------- |
|
1258 // CTsFastSwapArea::ShowPopupL |
|
1259 // ----------------------------------------------------------------------------- |
|
1260 // |
|
1261 TBool CTsFastSwapArea::ShowPopupL( TInt aIndex, const TPoint& aPoint ) |
|
1262 { |
|
1263 TBool showPopUp(EFalse); |
|
1264 TBool showPopupItem; |
|
1265 // hide 'close' if app cannot be closed |
|
1266 showPopupItem = CanClose( aIndex ); |
|
1267 iPopup->SetItemDimmed( EFswCmdClose, !showPopupItem ); |
|
1268 showPopUp = showPopUp || showPopupItem; |
|
1269 // hide 'close all' if there are no applications to close. |
|
1270 showPopupItem = CanCloseAll( aIndex ); |
|
1271 iPopup->SetItemDimmed( EFswCmdCloseAll, !showPopupItem ); |
|
1272 showPopUp = showPopUp || showPopupItem; |
|
1273 |
|
1274 if(showPopUp) |
|
1275 { |
|
1276 static_cast<CTsAppUi*>(iEikonEnv->AppUi())->RequestPopUpL(); |
|
1277 // give feedback |
|
1278 LaunchPopupFeedback(); |
|
1279 // save index for later use & show popup |
|
1280 iAppIndexForPopup = aIndex; |
|
1281 iPopup->SetPosition( aPoint, CAknStylusPopUpMenu::EPositionTypeLeftBottom ); |
|
1282 iPopup->ShowMenu(); |
|
1283 } |
|
1284 return showPopUp; |
|
1285 } |
|
1286 |
|
1287 |
|
1288 // ----------------------------------------------------------------------------- |
|
1289 // CTsFastSwapArea::Count |
|
1290 // ----------------------------------------------------------------------------- |
|
1291 // |
|
1292 TInt CTsFastSwapArea::Count() const |
|
1293 { |
|
1294 return iArray.Count(); |
|
1295 } |
|
1296 |
|
1297 // ----------------------------------------------------------------------------- |
|
1298 // CTsFastSwapArea::SetDataChangeObserver |
|
1299 // ----------------------------------------------------------------------------- |
|
1300 // |
|
1301 void CTsFastSwapArea::SetDataChangeObserver( |
|
1302 MTsDataChangeObserver* aDcObserver ) |
|
1303 { |
|
1304 iDcObserver = aDcObserver; |
|
1305 } |
|
1306 |
|
1307 // ----------------------------------------------------------------------------- |
|
1308 // CTsFastSwapArea::NotifyChange |
|
1309 // ----------------------------------------------------------------------------- |
|
1310 // |
|
1311 void CTsFastSwapArea::NotifyChange() |
|
1312 { |
|
1313 if ( iDcObserver ) |
|
1314 { |
|
1315 iDcObserver->DataChanged( this, Count() ); |
|
1316 } |
|
1317 } |
|
1318 |
|
1319 // ----------------------------------------------------------------------------- |
|
1320 // CTsFastSwapArea::PreferredImageSize |
|
1321 // ----------------------------------------------------------------------------- |
|
1322 // |
|
1323 TSize CTsFastSwapArea::PreferredImageSize() |
|
1324 { |
|
1325 TAknLayoutRect gridImage; |
|
1326 TRAP_IGNORE( |
|
1327 RArray<TAknLayoutRect> rects; |
|
1328 CleanupClosePushL(rects); |
|
1329 rects.ReserveL(KLayoutItemCount); |
|
1330 GetFastSwapAreaRects(rects); |
|
1331 gridImage = rects[2]; |
|
1332 CleanupStack::PopAndDestroy(&rects); |
|
1333 ); |
|
1334 return gridImage.Rect().Size(); |
|
1335 } |
|
1336 |
|
1337 // ----------------------------------------------------------------------------- |
|
1338 // CTsFastSwapArea::GridItemCount |
|
1339 // ----------------------------------------------------------------------------- |
|
1340 // |
|
1341 TInt CTsFastSwapArea::GridItemCount() |
|
1342 { |
|
1343 return iGrid->Model()->ItemTextArray()->MdcaCount(); |
|
1344 } |
|
1345 |
|
1346 // ----------------------------------------------------------------------------- |
|
1347 // CTsFastSwapArea::HandleListBoxEventL |
|
1348 // ----------------------------------------------------------------------------- |
|
1349 // |
|
1350 void CTsFastSwapArea::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType) |
|
1351 { |
|
1352 if ( aListBox == iGrid ) |
|
1353 { |
|
1354 switch ( aEventType ) |
|
1355 { |
|
1356 case EEventEnterKeyPressed: |
|
1357 case EEventItemClicked: |
|
1358 case EEventItemSingleClicked: |
|
1359 { |
|
1360 SwitchToApp(SelectedIndex()); |
|
1361 } |
|
1362 break; |
|
1363 case EEventPenDownOnItem: |
|
1364 { |
|
1365 iGrid->ShowHighlight(); |
|
1366 } |
|
1367 break; |
|
1368 default: |
|
1369 break; |
|
1370 } |
|
1371 } |
|
1372 } |
|
1373 |
|
1374 // -------------------------------------------------------------------------- |
|
1375 // CTsFastSwapArea::CalculateSizePreserveRatio |
|
1376 // -------------------------------------------------------------------------- |
|
1377 // |
|
1378 TSize CTsFastSwapArea::CalculateSizePreserveRatio( |
|
1379 const TSize& aTargetAreaSize, |
|
1380 const TSize& aSourceSize ) |
|
1381 { |
|
1382 const TReal |
|
1383 resizedAspectRatio(aTargetAreaSize.iWidth/(TReal)aTargetAreaSize.iHeight); |
|
1384 const TReal |
|
1385 orginalAspectRatio(aSourceSize.iWidth/(TReal)aSourceSize.iHeight); |
|
1386 //this condition avoid empty margins ( bigger output ). to realy fit area change it |
|
1387 const TReal scaleFactor = |
|
1388 ( orginalAspectRatio > resizedAspectRatio ) ? |
|
1389 (aTargetAreaSize.iHeight /(TReal)aSourceSize.iHeight) ://scale by height |
|
1390 (aTargetAreaSize.iWidth /(TReal)aSourceSize.iWidth) ;//scale by width |
|
1391 return TSize(aSourceSize.iWidth * scaleFactor, aSourceSize.iHeight * scaleFactor); |
|
1392 } |
|
1393 |
|
1394 // -------------------------------------------------------------------------- |
|
1395 // CTsFastSwapArea::SelectNextItem |
|
1396 // -------------------------------------------------------------------------- |
|
1397 // |
|
1398 void CTsFastSwapArea::SelectNextItem() |
|
1399 { |
|
1400 iKeyEvent = ETrue; |
|
1401 TBool forceRedraw(ETrue); |
|
1402 TBool animate(ETrue); |
|
1403 TInt selectedItem = SelectedIndex(); |
|
1404 selectedItem++; |
|
1405 if ( selectedItem == GridItemCount() ) |
|
1406 { |
|
1407 // Last item is selected, move to first one |
|
1408 selectedItem = 0; |
|
1409 animate = EFalse; |
|
1410 } |
|
1411 iGrid->SetCurrentDataIndex(selectedItem); |
|
1412 UpdateGrid(forceRedraw, animate); |
|
1413 } |
|
1414 |
|
1415 |
|
1416 // -------------------------------------------------------------------------- |
|
1417 // CTsFastSwapArea::CenterItem |
|
1418 // -------------------------------------------------------------------------- |
|
1419 // |
|
1420 void CTsFastSwapArea::CenterItem(TInt aRedrawDelay) |
|
1421 { |
|
1422 if( iMaxItemsOnScreen < GridItemCount() ) |
|
1423 { |
|
1424 TInt visibleItem = ViewToVisibleItem( ViewPos() ); |
|
1425 if(iKeyEvent) |
|
1426 { |
|
1427 visibleItem = SelectedIndex(); |
|
1428 } |
|
1429 if(visibleItem != SelectedIndex()) |
|
1430 { |
|
1431 iGrid->SetCurrentDataIndex( visibleItem ); |
|
1432 iParent.DrawDeferred(); |
|
1433 iGrid->DrawDeferred(); |
|
1434 } |
|
1435 } |
|
1436 |
|
1437 // Check if view is outside of grid world |
|
1438 TPoint absViewPos = ViewPos(); |
|
1439 absViewPos.iX -= Rect().Width() / 2; |
|
1440 if( !iEvtHandler.IsPhysicsRunning() && |
|
1441 ( absViewPos.iX < 0 ||( absViewPos.iX + Rect().Width() > GridWorldSize().iWidth && GridItemCount() ) ) |
|
1442 ) |
|
1443 { |
|
1444 // View is outside of grid world - update view |
|
1445 iUpdateGridTimer->Cancel(); |
|
1446 iUpdateGridTimer->After(aRedrawDelay); |
|
1447 } |
|
1448 } |
|
1449 |
|
1450 // -------------------------------------------------------------------------- |
|
1451 // CTsFastSwapArea::GridWorldSize |
|
1452 // -------------------------------------------------------------------------- |
|
1453 // |
|
1454 TSize CTsFastSwapArea::GridWorldSize() |
|
1455 { |
|
1456 return TSize( GridItemCount() * iGridItemWidth + (GridItemCount() - 1) * iGridItemGap, Rect().Height() ); |
|
1457 } |
|
1458 |
|
1459 // -------------------------------------------------------------------------- |
|
1460 // CTsFastSwapArea::UpdateGrid |
|
1461 // -------------------------------------------------------------------------- |
|
1462 // |
|
1463 void CTsFastSwapArea::UpdateGrid( TBool aForceRedraw, TBool aAnimate ) |
|
1464 { |
|
1465 TPoint targetPoint = ItemViewPosition( SelectedIndex() ); |
|
1466 if ( aForceRedraw || targetPoint.iX != ViewPos().iX ) |
|
1467 { |
|
1468 if ( aAnimate ) |
|
1469 { |
|
1470 iEvtHandler.Animate( targetPoint ); |
|
1471 } |
|
1472 else |
|
1473 { |
|
1474 MoveOffset(targetPoint, ETrue); |
|
1475 iEvtHandler.StopAnimation(); |
|
1476 } |
|
1477 if ( aForceRedraw ) |
|
1478 { |
|
1479 iParent.DrawDeferred(); |
|
1480 iGrid->DrawNow(); |
|
1481 } |
|
1482 } |
|
1483 } |
|
1484 |
|
1485 // -------------------------------------------------------------------------- |
|
1486 // CTsFastSwapArea::HandleAppKey |
|
1487 // -------------------------------------------------------------------------- |
|
1488 // |
|
1489 void CTsFastSwapArea::HandleAppKey(TInt aType) |
|
1490 { |
|
1491 if ( iArray.Count() ) |
|
1492 { |
|
1493 if( aType == KAppKeyTypeShort ) |
|
1494 { |
|
1495 //SwitchToApp( KTsHomescreenUid ); |
|
1496 TRAP_IGNORE( iEikonEnv->EikAppUi()->HandleCommandL(EAknSoftkeyExit) ); |
|
1497 } |
|
1498 else if( aType == KAppKeyTypeLong ) |
|
1499 { |
|
1500 // Dismiss task switcher |
|
1501 TRAP_IGNORE( iEikonEnv->EikAppUi()->HandleCommandL(EAknSoftkeyExit) ); |
|
1502 } |
|
1503 } |
|
1504 else |
|
1505 { |
|
1506 TRAP_IGNORE( iEikonEnv->EikAppUi()->HandleCommandL(EAknSoftkeyExit) ); |
|
1507 } |
|
1508 } |
|
1509 |
|
1510 // -------------------------------------------------------------------------- |
|
1511 // CTsFastSwapArea::MoveOffset |
|
1512 // -------------------------------------------------------------------------- |
|
1513 // |
|
1514 void CTsFastSwapArea::MoveOffset(const TPoint& aPoint, TBool aDrawNow) |
|
1515 { |
|
1516 if( iHandlePointerCandidate ) |
|
1517 { |
|
1518 //pointer was pressed and it's being waiting for handling |
|
1519 return; |
|
1520 } |
|
1521 |
|
1522 //postpone center item request in case of being moved |
|
1523 if(iUpdateGridTimer->IsActive()) |
|
1524 { |
|
1525 iUpdateGridTimer->Cancel(); |
|
1526 iUpdateGridTimer->After(KUpdateGridTime); |
|
1527 } |
|
1528 |
|
1529 if ( aDrawNow ) |
|
1530 { |
|
1531 TInt currentXPos = aPoint.iX; |
|
1532 currentXPos -= Rect().Width() / 2; |
|
1533 TRect gridViewRect = Rect(); |
|
1534 gridViewRect.iTl.iX = -currentXPos; |
|
1535 // Take edge offset into account |
|
1536 gridViewRect.iTl.iX += Rect().iTl.iX; |
|
1537 if(GridItemCount() && GridItemCount() <= iMaxItemsOnScreen) |
|
1538 { |
|
1539 // Center view |
|
1540 gridViewRect.iTl.iX += ( Rect().Width() - GridItemCount() * iGridItemWidth ) / 2; |
|
1541 } |
|
1542 //iParent.DrawDeferred(); |
|
1543 iGrid->DrawDeferred(); |
|
1544 iGrid->SetRect( gridViewRect ); |
|
1545 iLogicalViewPosOffset = 0; |
|
1546 } |
|
1547 else |
|
1548 { |
|
1549 // Update logical view position |
|
1550 iLogicalViewPosOffset = aPoint.iX - ViewPos().iX; |
|
1551 } |
|
1552 } |
|
1553 |
|
1554 // -------------------------------------------------------------------------- |
|
1555 // CTsFastSwapArea::Tap |
|
1556 // -------------------------------------------------------------------------- |
|
1557 // |
|
1558 void CTsFastSwapArea::TapL(const TPoint& aPoint) |
|
1559 { |
|
1560 CancelLongTapAnimation(); |
|
1561 |
|
1562 if(!iHandlePointerCandidate) |
|
1563 { |
|
1564 return; |
|
1565 } |
|
1566 |
|
1567 if(Rect().Contains(aPoint) && iArray.Count()) |
|
1568 { |
|
1569 //provide tap pointer event to grid |
|
1570 iGrid->HandlePointerEventL(iTapEvent); |
|
1571 iHighlightTimer->Cancel(); |
|
1572 iHighlightTimer->After(KHighlighActivationTime); |
|
1573 } |
|
1574 else |
|
1575 { |
|
1576 //move task switcher to background |
|
1577 iEikonEnv->EikAppUi()->HandleCommandL(EAknSoftkeyExit); |
|
1578 } |
|
1579 iHandlePointerCandidate = EFalse; |
|
1580 } |
|
1581 |
|
1582 // -------------------------------------------------------------------------- |
|
1583 // CTsFastSwapArea::LongTap |
|
1584 // -------------------------------------------------------------------------- |
|
1585 // |
|
1586 void CTsFastSwapArea::LongTapL(const TPoint& aPoint) |
|
1587 { |
|
1588 CancelLongTapAnimation(); |
|
1589 |
|
1590 if(!iHandlePointerCandidate) |
|
1591 { |
|
1592 return; |
|
1593 } |
|
1594 |
|
1595 TInt index(KErrNotFound); |
|
1596 if( iGrid->GridView()->XYPosToItemIndex(aPoint,index) && iArray.Count() ) |
|
1597 { |
|
1598 iGrid->SetCurrentItemIndex(index); |
|
1599 SaveSelectedIndex(); |
|
1600 if ( !ShowPopupL(iSavedSelectedIndex, aPoint) ) |
|
1601 { |
|
1602 iActivateOnPointerRelease = aPoint; |
|
1603 } |
|
1604 iGrid->ShowHighlight(); |
|
1605 DrawNow(); |
|
1606 } |
|
1607 iHandlePointerCandidate = EFalse; |
|
1608 } |
|
1609 |
|
1610 // -------------------------------------------------------------------------- |
|
1611 // CTsFastSwapArea::DragL |
|
1612 // -------------------------------------------------------------------------- |
|
1613 // |
|
1614 void CTsFastSwapArea::DragL( |
|
1615 const MAknTouchGestureFwDragEvent& aEvent) |
|
1616 { |
|
1617 CancelLongTapAnimation(); |
|
1618 // Reset activation point |
|
1619 iActivateOnPointerRelease = TPoint(); |
|
1620 iHandlePointerCandidate = EFalse; |
|
1621 if( aEvent.State() == EAknTouchGestureFwStop) |
|
1622 { |
|
1623 CenterItem( KUpdateGridTime ); |
|
1624 } |
|
1625 |
|
1626 iGrid->HideHighlight(); |
|
1627 } |
|
1628 |
|
1629 // ----------------------------------------------------------------------------- |
|
1630 // CTsFastSwapArea::ViewSize |
|
1631 // ----------------------------------------------------------------------------- |
|
1632 // |
|
1633 TSize CTsFastSwapArea::ViewSize() |
|
1634 { |
|
1635 return TSize(Rect().Width(), Rect().Height()); |
|
1636 } |
|
1637 |
|
1638 // ----------------------------------------------------------------------------- |
|
1639 // CTsFastSwapArea::Stop |
|
1640 // ----------------------------------------------------------------------------- |
|
1641 // |
|
1642 void CTsFastSwapArea::Stop() |
|
1643 { |
|
1644 CenterItem( KUpdateGridTime ); |
|
1645 DrawDeferred(); |
|
1646 } |
|
1647 |
|
1648 // ----------------------------------------------------------------------------- |
|
1649 // CTsFastSwapArea::ViewSize |
|
1650 // ----------------------------------------------------------------------------- |
|
1651 // |
|
1652 TPoint CTsFastSwapArea::ViewPos() const |
|
1653 { |
|
1654 TPoint retVal; |
|
1655 retVal.iY = iGrid->Rect().iTl.iY + Rect().Height() / 2; |
|
1656 retVal.iX = - (iGrid->Rect().iTl.iX - Rect().iTl.iX) + Rect().Width() / 2 ; |
|
1657 TInt gridItemCount = iGrid->Model()->ItemTextArray()->MdcaCount(); |
|
1658 if(gridItemCount && gridItemCount <= iMaxItemsOnScreen) |
|
1659 { |
|
1660 // View centered |
|
1661 retVal.iX += ( Rect().Width() - gridItemCount * iGridItemWidth ) / 2; |
|
1662 } |
|
1663 retVal.iX += iLogicalViewPosOffset; |
|
1664 return retVal; |
|
1665 } |
|
1666 |
|
1667 // ----------------------------------------------------------------------------- |
|
1668 // CTsFastSwapArea::ItemPosition |
|
1669 // ----------------------------------------------------------------------------- |
|
1670 // |
|
1671 TPoint CTsFastSwapArea::ItemViewPosition( TInt aItemIdx ) |
|
1672 { |
|
1673 TPoint retVal = Rect().iTl; |
|
1674 if ( aItemIdx < 0 ) |
|
1675 { |
|
1676 // No items |
|
1677 retVal.iX = 0; |
|
1678 } |
|
1679 else if ( aItemIdx == 0 ) |
|
1680 { |
|
1681 // First item |
|
1682 if( AknLayoutUtils::LayoutMirrored() ) |
|
1683 { |
|
1684 if ( GridItemCount() > iMaxItemsOnScreen ) |
|
1685 { |
|
1686 retVal.iX = GridWorldSize().iWidth - Rect().Width(); |
|
1687 } |
|
1688 else |
|
1689 { |
|
1690 retVal.iX = 0; |
|
1691 } |
|
1692 } |
|
1693 else // normal layout |
|
1694 { |
|
1695 retVal.iX = 0; |
|
1696 } |
|
1697 } |
|
1698 else if ( aItemIdx == GridItemCount() - 1 ) |
|
1699 { |
|
1700 // Last item selected |
|
1701 if( AknLayoutUtils::LayoutMirrored() ) |
|
1702 { |
|
1703 retVal.iX = 0; |
|
1704 } |
|
1705 else // normal layout |
|
1706 { |
|
1707 if ( GridItemCount() > iMaxItemsOnScreen ) |
|
1708 { |
|
1709 retVal.iX = GridWorldSize().iWidth - Rect().Width(); |
|
1710 } |
|
1711 else |
|
1712 { |
|
1713 retVal.iX = 0; |
|
1714 } |
|
1715 } |
|
1716 } |
|
1717 else |
|
1718 { |
|
1719 // Middle item |
|
1720 TInt screenMiddleItemOffset = ( Rect().Width() - iGridItemWidth ) / 2; |
|
1721 if( AknLayoutUtils::LayoutMirrored() ) |
|
1722 { |
|
1723 retVal.iX = iGridItemWidth * ( GridItemCount() - 1 - aItemIdx ) - screenMiddleItemOffset; |
|
1724 retVal.iX += ( GridItemCount() - 1 - aItemIdx ) * iGridItemGap; |
|
1725 } |
|
1726 else // normal layout |
|
1727 { |
|
1728 retVal.iX = iGridItemWidth * aItemIdx - screenMiddleItemOffset; |
|
1729 retVal.iX += iGridItemGap * aItemIdx; |
|
1730 } |
|
1731 if ( retVal.iX < 0 ) |
|
1732 { |
|
1733 retVal.iX = 0; |
|
1734 } |
|
1735 else if ( retVal.iX + Rect().Width() > GridWorldSize().iWidth ) |
|
1736 { |
|
1737 retVal.iX = GridWorldSize().iWidth - Rect().Width(); |
|
1738 } |
|
1739 } |
|
1740 |
|
1741 // Return middle of the view rectangle |
|
1742 retVal.iX += Rect().Width() / 2; |
|
1743 |
|
1744 return retVal; |
|
1745 } |
|
1746 |
|
1747 // ----------------------------------------------------------------------------- |
|
1748 // CTsFastSwapArea::ViewToVisibleItem |
|
1749 // ----------------------------------------------------------------------------- |
|
1750 // |
|
1751 TInt CTsFastSwapArea::ViewToVisibleItem( const TPoint aViewPos ) |
|
1752 { |
|
1753 TInt retVal(0); |
|
1754 TPoint absViewPos = aViewPos; |
|
1755 absViewPos.iX -= Rect().Width() / 2; |
|
1756 if ( absViewPos.iX < 0 ) |
|
1757 { |
|
1758 if ( AknLayoutUtils::LayoutMirrored() ) |
|
1759 { |
|
1760 // View crossed left border of grid world rect, last item selected |
|
1761 retVal = GridItemCount() - 1; |
|
1762 } |
|
1763 else // normal layout |
|
1764 { |
|
1765 // View crossed left border of grid world rect, first item selected |
|
1766 retVal = 0; |
|
1767 } |
|
1768 } |
|
1769 else if ( absViewPos.iX + Rect().Width() > GridWorldSize().iWidth ) |
|
1770 { |
|
1771 if ( AknLayoutUtils::LayoutMirrored() ) |
|
1772 { |
|
1773 // View crossed right border of grid world rect, first item selected |
|
1774 retVal = 0; |
|
1775 } |
|
1776 else // normal layout |
|
1777 { |
|
1778 // View crossed right border of grid world rect, last item selected |
|
1779 retVal = GridItemCount() - 1; |
|
1780 } |
|
1781 } |
|
1782 else |
|
1783 { |
|
1784 TInt retItemPosX(0); |
|
1785 TInt offsetCheck = GridWorldSize().iWidth; |
|
1786 // View inside of grid world rect |
|
1787 for ( TInt i = 0 ; i < GridItemCount(); i++ ) |
|
1788 { |
|
1789 TInt itemPosX = ItemViewPosition( i ).iX; |
|
1790 TInt offset = aViewPos.iX - itemPosX; |
|
1791 if ( Abs( offset ) <= offsetCheck ) |
|
1792 { |
|
1793 offsetCheck = Abs( offset ); |
|
1794 retVal = i; |
|
1795 retItemPosX = itemPosX; |
|
1796 } |
|
1797 else |
|
1798 { |
|
1799 break; |
|
1800 } |
|
1801 } |
|
1802 // Check if item is fully visible. If not |
|
1803 // return next one if possible |
|
1804 if ( retItemPosX - iGridItemWidth / 2 < absViewPos.iX && |
|
1805 retVal + 1 < GridItemCount() ) |
|
1806 { |
|
1807 retVal++; |
|
1808 } |
|
1809 } |
|
1810 |
|
1811 return retVal; |
|
1812 } |
|
1813 |
|
1814 |
|
1815 // ----------------------------------------------------------------------------- |
|
1816 // CTsFastSwapArea::LaunchPopupFeedback |
|
1817 // ----------------------------------------------------------------------------- |
|
1818 // |
|
1819 void CTsFastSwapArea::LaunchPopupFeedback() |
|
1820 { |
|
1821 if ( AknLayoutUtils::PenEnabled() ) |
|
1822 { |
|
1823 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
1824 if ( feedback ) |
|
1825 { |
|
1826 TTouchLogicalFeedback fbLogicalType = ETouchFeedbackPopUp; |
|
1827 if ( CAknTransitionUtils::TransitionsEnabled( |
|
1828 AknTransEffect::EComponentTransitionsOff ) ) |
|
1829 { |
|
1830 fbLogicalType = ETouchFeedbackIncreasingPopUp; |
|
1831 } |
|
1832 feedback->InstantFeedback( this, |
|
1833 fbLogicalType, |
|
1834 ETouchFeedbackVibra, |
|
1835 TPointerEvent() ); |
|
1836 } |
|
1837 } |
|
1838 } |
|
1839 |
|
1840 |
|
1841 // ----------------------------------------------------------------------------- |
|
1842 // CTsFastSwapArea::GetCurrentScreenOrientation |
|
1843 // ----------------------------------------------------------------------------- |
|
1844 // |
|
1845 TInt CTsFastSwapArea::GetCurrentScreenOrientation() |
|
1846 { |
|
1847 TPixelsAndRotation availableRect; |
|
1848 iEikonEnv->ScreenDevice()->GetDefaultScreenSizeAndRotation(availableRect); |
|
1849 return availableRect.iPixelSize.iWidth > availableRect.iPixelSize.iHeight; |
|
1850 } |
|
1851 |
|
1852 |
|
1853 // ----------------------------------------------------------------------------- |
|
1854 // CTsFastSwapArea::GetVariety |
|
1855 // ----------------------------------------------------------------------------- |
|
1856 // |
|
1857 TBool CTsFastSwapArea::GetVariety( TInt& aVariety ) |
|
1858 { |
|
1859 aVariety = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0; |
|
1860 TBool foreground = static_cast<CTsAppUi*>(iEikonEnv->AppUi())->IsForeground(); |
|
1861 if ( foreground ) |
|
1862 { |
|
1863 TInt screenOrientation = GetCurrentScreenOrientation(); |
|
1864 if ( aVariety != screenOrientation ) |
|
1865 { |
|
1866 aVariety = screenOrientation; |
|
1867 return ETrue; |
|
1868 } |
|
1869 } |
|
1870 return EFalse; |
|
1871 } |
|
1872 |
|
1873 // ----------------------------------------------------------------------------- |
|
1874 // CTsFastSwapArea::IsAppClosing |
|
1875 // ----------------------------------------------------------------------------- |
|
1876 // |
|
1877 TBool CTsFastSwapArea::IsAppClosing( TInt aWgId ) |
|
1878 { |
|
1879 TBool retVal(EFalse); |
|
1880 if ( iIsClosing.Count() ) |
|
1881 { |
|
1882 TInt idx = iIsClosing.Find(aWgId); |
|
1883 retVal = idx != KErrNotFound; |
|
1884 if ( retVal ) |
|
1885 { |
|
1886 iIsClosing.Remove(idx); |
|
1887 } |
|
1888 else if ( iWidgetClosingCount ) |
|
1889 { |
|
1890 retVal = ETrue; |
|
1891 iWidgetClosingCount--; |
|
1892 } |
|
1893 } |
|
1894 return retVal; |
|
1895 } |
|
1896 |
|
1897 |
|
1898 // ----------------------------------------------------------------------------- |
|
1899 // CTsFastSwapArea::WgOnTaskList |
|
1900 // ----------------------------------------------------------------------------- |
|
1901 // |
|
1902 TBool CTsFastSwapArea::WgOnTaskList( TInt aWgId ) |
|
1903 { |
|
1904 TBool retVal(EFalse); |
|
1905 TInt appCount = iArray.Count(); |
|
1906 |
|
1907 TApaTaskList taskList( iEikonEnv->WsSession() ); |
|
1908 TApaTask task = taskList.FindApp( KTsHomescreenUid ); |
|
1909 TInt homescrWgId = task.WgId(); |
|
1910 |
|
1911 if ( iPrevAppCount != appCount ) |
|
1912 { |
|
1913 for ( TInt i = 0; i < iArray.Count(); i++ ) |
|
1914 { |
|
1915 TInt wgId = iArray[i]->WgId(); |
|
1916 if ( wgId == aWgId || |
|
1917 homescrWgId == aWgId ) |
|
1918 { |
|
1919 retVal = ETrue; |
|
1920 } |
|
1921 } |
|
1922 } |
|
1923 else if ( aWgId == homescrWgId ) |
|
1924 { |
|
1925 retVal = ETrue; |
|
1926 } |
|
1927 iPrevAppCount = appCount; |
|
1928 return retVal; |
|
1929 } |
|
1930 |
|
1931 // ----------------------------------------------------------------------------- |
|
1932 // CTsFastSwapArea::CancelLongTapAnimation |
|
1933 // ----------------------------------------------------------------------------- |
|
1934 // |
|
1935 void CTsFastSwapArea::CancelLongTapAnimation(TBool aDisablePopup) |
|
1936 { |
|
1937 iLongTapAnimationRunning = EFalse; |
|
1938 iLongTapAnimationTimer->Cancel(); |
|
1939 if ( iLongTapAnimation ) |
|
1940 { |
|
1941 iLongTapAnimation->HideAnimation(); |
|
1942 delete iLongTapAnimation; |
|
1943 iLongTapAnimation = NULL; |
|
1944 } |
|
1945 if( aDisablePopup ) |
|
1946 { |
|
1947 TRAP_IGNORE( |
|
1948 static_cast<CTsAppUi*>(iEikonEnv->AppUi())->DisablePopUpL() ); |
|
1949 } |
|
1950 } |
|
1951 |
|
1952 |
|
1953 // ----------------------------------------------------------------------------- |
|
1954 // CTsFastSwapArea::LongTapAnimForPos |
|
1955 // ----------------------------------------------------------------------------- |
|
1956 // |
|
1957 TBool CTsFastSwapArea::LongTapAnimForPos( const TPoint& aHitPoint ) |
|
1958 { |
|
1959 if ( Rect().Contains(aHitPoint) ) |
|
1960 { |
|
1961 TInt itemIdx; |
|
1962 TBool isItemHit = iGrid->GridView()->XYPosToItemIndex( aHitPoint, itemIdx ); |
|
1963 if ( isItemHit && ( CanClose( itemIdx ) || CanCloseAll( itemIdx ) ) ) |
|
1964 { |
|
1965 return ETrue; |
|
1966 } |
|
1967 } |
|
1968 return EFalse; |
|
1969 } |
|
1970 |
|
1971 // End of file |