|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of CGlxZoomControl |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "glxzoomcontrol.h" |
|
22 |
|
23 // INCLUDES |
|
24 #include <data_caging_path_literals.hrh> |
|
25 #include <eikbtgpc.h> //For CEikButtonGroupContainer |
|
26 #include <ExifRead.h> |
|
27 |
|
28 //Alf Headers |
|
29 #include <alf/alfviewportlayout.h> // For CAlfViewPortLayout |
|
30 #include <alf/alfimagevisual.h> // For CAlfImageVisual |
|
31 #include <alf/alfcontrolgroup.h> // For CAlfControlGroup |
|
32 #include <alf/alfdisplay.h> // For CAlfDisplay |
|
33 #include <alf/alfroster.h> // For CAlfRoster |
|
34 #include <alf/alfutil.h> // For AlfUtil |
|
35 // Antariksh |
|
36 #include <mul/imulsliderwidget.h> // For Slider Widget |
|
37 #include <mul/mulevent.h> // For Slider events |
|
38 |
|
39 #include <gesturehelper.h> |
|
40 #include <e32math.h> |
|
41 |
|
42 using namespace GestureHelper; |
|
43 |
|
44 //Gallery Headers |
|
45 #include <glxuiutility.h> |
|
46 #include <glxattributecontext.h> |
|
47 #include <glxtracer.h> // For Tracer |
|
48 #include <glxlog.h> // For Log |
|
49 #include <glxtexturemanager.h> // For Creating Texture |
|
50 #include <glxuistd.h> // For Fetch Context Priority |
|
51 #include <mglxmedialist.h> // For MGlxMediaList |
|
52 #include <mglxuicommandhandler.h> // For MGlxUiCommandHandler |
|
53 |
|
54 #include "glxtv.h" // for CGlxTv |
|
55 // LOCAL CONSTANTS AND MACROS |
|
56 const TReal KGlxOpacityOpaque = 1.0; |
|
57 const TInt KGlxMaxExifSize = 0x10000; |
|
58 const TReal KGlxOpacityTransparent = 0.0; |
|
59 //zoom delay for animation while hdmi cable, |
|
60 //is connected and zoom is initiated |
|
61 const TInt KHDMIZoomDelay = 250000; |
|
62 //Zoom level for the animation , assuming the innitial level is 1. |
|
63 const TReal KGlxZoomLevel = 1.5; |
|
64 |
|
65 const TInt KGlxDecodingThreshold = 3000000; // pixels |
|
66 |
|
67 |
|
68 // ============================ MEMBER FUNCTIONS =============================== |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CGlxZoomControl::CGlxZoomControl |
|
72 // C++ default constructor can NOT contain any code, that might leave. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CGlxZoomControl::CGlxZoomControl(MGlxUiCommandHandler& aCommandHandler, |
|
76 MGlxMediaList& aMediaList,CEikButtonGroupContainer& aZoomBackKeys, |
|
77 IMulSliderWidget& aSliderWidget, GestureHelper::CGestureHelper* aGestureHelper) : |
|
78 iMediaList(aMediaList), iGestureHelper(aGestureHelper), |
|
79 iZoomSliderWidget(aSliderWidget), iZoomBackKey(&aZoomBackKeys), |
|
80 iCommandHandler(aCommandHandler) |
|
81 { |
|
82 TRACER("CGlxZoomControl::CGlxZoomControl"); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CGlxZoomControl::ConstructL |
|
87 // Symbian 2nd phase constructor can leave. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CGlxZoomControl::ConstructL() |
|
91 { |
|
92 TRACER("CGlxZoomControl::ConstructL()"); |
|
93 iAttributeContext = CGlxDefaultAttributeContext::NewL(); |
|
94 iAttributeContext->AddAttributeL(KGlxMediaGeneralDimensions); |
|
95 iMediaList.AddContextL( iAttributeContext, KGlxFetchContextPriorityLow ); |
|
96 iUiUtility = CGlxUiUtility::UtilityL(); |
|
97 iEnv = iUiUtility->Env(); |
|
98 iDisplay = iUiUtility->Display(); |
|
99 iTextureMgr = &iUiUtility->GlxTextureManager(); |
|
100 iScreenSize = ScreenSize(); |
|
101 |
|
102 iDisplay->SetVisibleArea(TRect(TPoint(0,0),iScreenSize)); |
|
103 CAlfControl::ConstructL(*iEnv); |
|
104 |
|
105 //Func creating black background and visual that has to zoomed |
|
106 CreateZoomVisualL(); |
|
107 |
|
108 iControlGroup = &iEnv->NewControlGroupL(0x119); |
|
109 iControlGroup->AppendL(this); |
|
110 |
|
111 iDisplay->Roster().ShowL( *iControlGroup); |
|
112 |
|
113 // Hide the Zoom at the construction |
|
114 ShowZoom(EFalse); |
|
115 iZoomActive = EFalse; |
|
116 |
|
117 //To know if HDMi cable is connected. |
|
118 iGlxTvOut = CGlxTv::NewL(*this); |
|
119 iTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
120 iGPUMemMonitor = CGlxRelaseGPUMemory::NewL(*this); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // ScreenSize : gets the screensize, Note that , this is not stored in member variable as |
|
125 // Screen rect can change based on orientation |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TSize CGlxZoomControl::ScreenSize() |
|
129 { |
|
130 TRACER("CGlxZoomControl::ScreenSize()"); |
|
131 return AlfUtil::ScreenSize(); |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // ShowZoom |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CGlxZoomControl::ShowZoom(TBool aShow) |
|
139 { |
|
140 TRACER("CGlxZoomControl::ShowZoom()"); |
|
141 if (aShow) |
|
142 { |
|
143 iViewPort->SetOpacity(KGlxOpacityOpaque); |
|
144 iGestureHelper->AddObserver(this); |
|
145 } |
|
146 else |
|
147 { |
|
148 iViewPort->SetOpacity(KGlxOpacityTransparent); |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CreateZoomVisual |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CGlxZoomControl::CreateZoomVisualL() |
|
157 { |
|
158 TRACER("CGlxZoomControl::CreateZoomVisualL()"); |
|
159 |
|
160 CAlfTexture *blackoutTexture = &(iTextureMgr->CreateFlatColourTextureL(KRgbBlack)); |
|
161 CleanupStack::PushL(blackoutTexture); |
|
162 |
|
163 iViewPort = CAlfViewportLayout::AddNewL(*this); |
|
164 //Create the Image visual ,which holds the texture,which is complete black in color |
|
165 CAlfImageVisual *blackoutImageVisual = CAlfImageVisual::AddNewL(*this,iViewPort); |
|
166 CleanupStack::PushL(blackoutImageVisual); |
|
167 |
|
168 // Visual is larger than the screen to deal with control transformations that |
|
169 // may show areas usually outside the normal screen coordinates |
|
170 TInt16 blackImageSize =(iScreenSize.iWidth > iScreenSize.iHeight) ?iScreenSize.iWidth:iScreenSize.iHeight; |
|
171 blackoutImageVisual->SetImage(TAlfImage(*blackoutTexture)); |
|
172 blackoutImageVisual->SetFlag(EAlfVisualFlagManualLayout); |
|
173 blackoutImageVisual->SetSize(TAlfRealSize(blackImageSize, blackImageSize)); |
|
174 blackoutImageVisual->SetPos(TAlfRealPoint(0, 0)); |
|
175 CleanupStack::Pop(blackoutImageVisual); |
|
176 CleanupStack::Pop(blackoutTexture); |
|
177 |
|
178 // VisualLayoutUpdated |
|
179 // Enable scrolling of the Viewport. |
|
180 // The content area of a layout can be thought to be larger than the real visible size. |
|
181 // Scrolling changes which portion of the layout’s content is actually visible at the moment. |
|
182 iViewPort->SetFlag(EAlfVisualFlagLayoutUpdateNotification); |
|
183 iViewPort->SetVirtualSize(TAlfRealSize(iScreenSize.iWidth,iScreenSize.iHeight), 0); |
|
184 iViewPort->SetViewportSize(TAlfRealSize(iScreenSize.iWidth,iScreenSize.iHeight), 0); |
|
185 iViewPort->SetViewportPos(TAlfRealPoint(0,0), 0); |
|
186 iViewPort->SetClipping(EFalse); |
|
187 iViewPort->SetOrigin( EAlfVisualHOriginLeft, EAlfVisualVOriginTop ); |
|
188 |
|
189 //Enable scrolling of the Viewport. |
|
190 //The content area of a layout can be thought to be larger than the real visible size. |
|
191 //Scrolling changes which portion of the layout’s content is actually visible at the moment. |
|
192 iViewPort->EnableScrollingL(); |
|
193 iViewPort->EnableTransformationL(); |
|
194 |
|
195 iImageVisual = CAlfImageVisual::AddNewL(*this,iViewPort); |
|
196 iImageVisual->SetScaleMode(CAlfImageVisual::EScaleFitInside); |
|
197 |
|
198 iEventHandler = CGlxZoomPanEventHandler::NewL(*this); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CGlxZoomControl::NewL |
|
203 // Two-phased constructor. |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C CGlxZoomControl* CGlxZoomControl::NewL( |
|
207 MGlxUiCommandHandler& aCommandHandler, |
|
208 MGlxMediaList& aMediaList,CEikButtonGroupContainer& aZoomKeys, |
|
209 IMulSliderWidget& aSliderWidget, GestureHelper::CGestureHelper* aGestureHelper) |
|
210 { |
|
211 TRACER("CGlxZoomControl::NewL"); |
|
212 CGlxZoomControl* self = new (ELeave) CGlxZoomControl(aCommandHandler, |
|
213 aMediaList,aZoomKeys,aSliderWidget,aGestureHelper); |
|
214 |
|
215 CleanupStack::PushL(self); |
|
216 self->ConstructL(); |
|
217 |
|
218 CleanupStack::Pop(self); |
|
219 return self; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // Destructor |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 CGlxZoomControl::~CGlxZoomControl() |
|
227 { |
|
228 TRACER("CGlxZoomControl::~CGlxZoomControl()"); |
|
229 if(iTimer->IsActive()) |
|
230 { |
|
231 iTimer->Cancel(); |
|
232 } |
|
233 delete iTimer; |
|
234 |
|
235 if(iGPUMemMonitor) |
|
236 { |
|
237 delete iGPUMemMonitor; |
|
238 } |
|
239 |
|
240 if(iGlxTvOut) |
|
241 { |
|
242 delete iGlxTvOut; |
|
243 } |
|
244 |
|
245 if(iEventHandler) |
|
246 { |
|
247 delete iEventHandler; |
|
248 iEventHandler = NULL ; |
|
249 } |
|
250 |
|
251 if(iViewPort) |
|
252 { |
|
253 iViewPort->RemoveAndDestroyAllD(); |
|
254 iViewPort = NULL; |
|
255 } |
|
256 iMediaList.RemoveContext(iAttributeContext); |
|
257 delete iAttributeContext; |
|
258 if(iImageTexture) |
|
259 { |
|
260 delete iImageTexture; |
|
261 iImageTexture=NULL; |
|
262 } |
|
263 iDisplay->Roster().Hide(*iControlGroup); |
|
264 if ( iControlGroup ) |
|
265 { |
|
266 iControlGroup->Remove(this); |
|
267 iEnv->DeleteControlGroup(0x119); |
|
268 iControlGroup = NULL; |
|
269 } |
|
270 if ( iUiUtility ) |
|
271 { |
|
272 iUiUtility->Close(); |
|
273 } |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // ActivateL:Activates the Zoom Control,set the image visual ,do the initial setup |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 EXPORT_C void CGlxZoomControl::ActivateL(TInt aInitialZoomRatio, TZoomStartMode aStartMode, |
|
281 TInt aFocusIndex, TGlxMedia& aItem, TPoint* aZoomFocus,TBool aViewingMode) |
|
282 { |
|
283 TRACER("CGlxZoomControl::ActivateL()"); |
|
284 |
|
285 //Request to release GPU mem parallelly |
|
286 iGPUMemMonitor->RequestMemory(EFalse); |
|
287 |
|
288 if ( !iZoomActive ) |
|
289 { |
|
290 //To Retrive the image details |
|
291 TMPXAttribute thumbNailAttribute(0,0); |
|
292 |
|
293 TGlxIdSpaceId idspace = iMediaList.IdSpaceId( aFocusIndex ); |
|
294 //Get the texture Created in fullscreen View. |
|
295 iImageTexture = &(iTextureMgr->CreateNewTextureForMediaL( |
|
296 ScreenSize(),aItem, idspace, this )); |
|
297 iImageVisual->SetImage(*iImageTexture); |
|
298 |
|
299 if(iGlxTvOut->IsHDMIConnected()&& !aViewingMode ) |
|
300 { |
|
301 StartZoomAnimation(aStartMode); |
|
302 } |
|
303 else |
|
304 { |
|
305 ShowZoom(ETrue); |
|
306 iZoomSliderWidget.AddEventHandler(*this); |
|
307 iZoomSliderWidget.SetHandleKeyEvent(EFalse); |
|
308 iZoomSliderModel = (IMulSliderModel*) iZoomSliderWidget.model(); |
|
309 |
|
310 if(iZoomSliderWidget.IsHidden()) |
|
311 { |
|
312 iEventHandler->SetZoomUiState(EUiOff); |
|
313 } |
|
314 else |
|
315 { |
|
316 iEventHandler->SetZoomUiState(EUiOn); |
|
317 } |
|
318 // Get size, return value tells us if it was available |
|
319 //We need this Value to calculate the size of the visual/Layout corresponding to the Zoom factor |
|
320 TSize imageSize; |
|
321 aItem.GetDimensions( imageSize ); |
|
322 TSize maxVirtualImageSize = imageSize; |
|
323 |
|
324 if (KGlxDecodingThreshold < (imageSize.iWidth * imageSize.iHeight)) |
|
325 { |
|
326 TReal areaRatio = TReal(imageSize.iWidth*imageSize.iHeight)/KGlxDecodingThreshold ; |
|
327 |
|
328 TReal sideRatio; |
|
329 Math::Sqrt(sideRatio, areaRatio); |
|
330 |
|
331 maxVirtualImageSize.iHeight = imageSize.iHeight / sideRatio ; |
|
332 maxVirtualImageSize.iWidth = imageSize.iWidth / sideRatio ; |
|
333 } |
|
334 |
|
335 // Now since our maximum size possible is 3 MP. all our zoom percentages will be relative to it. |
|
336 // So our initial zoom ratio will be different and cnsequently our minimum slider value too will change. |
|
337 |
|
338 |
|
339 GLX_LOG_INFO1("ActivateZoomControlL: Slider MaxRange = %d ", iZoomSliderModel->MaxRange() ); |
|
340 GLX_LOG_INFO1("ActivateZoomControlL: Slider MinRange = %d ", iZoomSliderModel->MinRange() ); |
|
341 GLX_LOG_INFO1("ActivateZoomControlL: Slider PrimaryValue= %d", iZoomSliderModel->PrimaryValue() ); |
|
342 |
|
343 iEventHandler->SetZoomActivated(ETrue); |
|
344 if (aStartMode == EZoomStartSlider) |
|
345 { |
|
346 iEventHandler->ActivateZoom(aInitialZoomRatio, |
|
347 maxVirtualImageSize, |
|
348 aStartMode, |
|
349 iZoomSliderModel->MinRange(), |
|
350 iZoomSliderModel->MaxRange(), |
|
351 aZoomFocus); |
|
352 } |
|
353 else |
|
354 { |
|
355 iEventHandler->ActivateZoom(aInitialZoomRatio, |
|
356 maxVirtualImageSize, |
|
357 aStartMode, |
|
358 iZoomSliderModel->MinRange(), |
|
359 iZoomSliderModel->MaxRange(), |
|
360 aZoomFocus); |
|
361 } |
|
362 TRAP_IGNORE(iImageTexture = |
|
363 &(iTextureMgr->CreateZoomedTextureL(aItem,thumbNailAttribute,idspace,this))); |
|
364 |
|
365 //This is for handling the alaram interrupt events,that causes the phone to freeze. |
|
366 CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current(); |
|
367 if (NULL != cba) |
|
368 { |
|
369 if (cba->IsVisible()) |
|
370 { |
|
371 cba->ActivateL(); |
|
372 } |
|
373 } |
|
374 } |
|
375 // Now the zoom activation process is complete. |
|
376 // Now is when truly zoom is active. |
|
377 iZoomActive = ETrue; |
|
378 } |
|
379 } |
|
380 // --------------------------------------------------------------------------- |
|
381 // StartZoomAnimation |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 void CGlxZoomControl::StartZoomAnimation(TZoomStartMode aStartMode) |
|
385 { |
|
386 TRACER("CGlxZoomControl::StartZoomAnimation()"); |
|
387 iZoomIn = ETrue; |
|
388 //Set zoom visible but not enable the gesturehelper events |
|
389 iViewPort->SetOpacity(KGlxOpacityOpaque); |
|
390 TAlfTimedValue timedvalue; |
|
391 //using KGlxOpacityOpaque for the value 1 , assuming the initial zoom level as 1. |
|
392 timedvalue.SetValueNow(KGlxOpacityOpaque); |
|
393 timedvalue.SetTarget(KGlxZoomLevel,KHDMIZoomDelay/1000); |
|
394 iImageVisual->SetScale(timedvalue); |
|
395 |
|
396 //If zoom is not done using pinch, zoom out with the rubber effect |
|
397 //Else wait for the gesture helper event for zooming out. |
|
398 if(aStartMode != EZoomStartPinch) |
|
399 { |
|
400 iTimer->Cancel(); |
|
401 iTimer->Start(KHDMIZoomDelay,KHDMIZoomDelay,TCallBack( TimeOut,this )); |
|
402 } |
|
403 else |
|
404 { |
|
405 iGestureHelper->AddObserver(this); |
|
406 } |
|
407 } |
|
408 // --------------------------------------------------------------------------- |
|
409 // TimeOut |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 TInt CGlxZoomControl::TimeOut(TAny* aSelf) |
|
413 { |
|
414 TRACER("CGlxZoomControl::TimeOut"); |
|
415 if(aSelf) |
|
416 { |
|
417 CGlxZoomControl* self = static_cast <CGlxZoomControl*> (aSelf); |
|
418 self->ActivateFullscreen(); |
|
419 } |
|
420 return KErrNone; |
|
421 } |
|
422 // --------------------------------------------------------------------------- |
|
423 // ActivateZoomAnimation |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 void CGlxZoomControl::ActivateFullscreen() |
|
427 { |
|
428 TRACER("CGlxZoomControl::ActivateFullscreen"); |
|
429 if(iZoomIn) |
|
430 { |
|
431 iZoomIn = EFalse; |
|
432 TAlfTimedValue timedvalue; |
|
433 timedvalue.SetValueNow(KGlxZoomLevel); |
|
434 timedvalue.SetTarget(KGlxOpacityOpaque,KHDMIZoomDelay/1000); |
|
435 iImageVisual->SetScale(timedvalue); |
|
436 } |
|
437 else |
|
438 { |
|
439 if(iTimer->IsActive()) |
|
440 { |
|
441 iTimer->Cancel(); |
|
442 } |
|
443 //once the animation is done come back to fullscreen. |
|
444 HandleZoomOutL(KGlxZoomOutCommand); |
|
445 } |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------------- |
|
449 // Deactivate:Remove the screen furniture ,cancel the timers if any |
|
450 // ---------------------------------------------------------------------------------- |
|
451 // |
|
452 EXPORT_C void CGlxZoomControl::Deactivate() |
|
453 { |
|
454 TRACER("CGlxZoomControl::Deactivate()"); |
|
455 if (iZoomActive) |
|
456 { |
|
457 if (iTimer->IsActive()) |
|
458 { |
|
459 iTimer->Cancel(); |
|
460 } |
|
461 iZoomSliderWidget.RemoveEventHandler(*this); |
|
462 iZoomBackKey->MakeVisible(EFalse); |
|
463 iTextureMgr->RemoveZoomList(); |
|
464 |
|
465 iImageVisual->SetImage(*iImageTexture); |
|
466 iEventHandler->DeactivateZoom(); |
|
467 CleanUpVisual(); |
|
468 |
|
469 iZoomActive = EFalse; |
|
470 iEventHandler->SetZoomActivated(EFalse); |
|
471 } |
|
472 // Hide the Zoom View |
|
473 ShowZoom(EFalse); |
|
474 } |
|
475 |
|
476 // ----------------------------------------------------------------------------------- |
|
477 // HandleZoomForegroundEventL:Zoom Foreground event handling function |
|
478 // ---------------------------------------------------------------------------------- |
|
479 // |
|
480 EXPORT_C void CGlxZoomControl::HandleZoomForegroundEvent(TBool aForeground) |
|
481 { |
|
482 TRACER("CGlxZoomControl::HandleZoomForegroundEventL()"); |
|
483 |
|
484 if (!aForeground) |
|
485 { |
|
486 ShowUi(EFalse); |
|
487 iEventHandler->CancelZoomPanTimer(); |
|
488 iEventHandler->CancelUITimer(); |
|
489 iEventHandler->CancelAnimationTimer(); |
|
490 } |
|
491 else |
|
492 { |
|
493 iGPUMemMonitor->RequestMemory(); |
|
494 } |
|
495 } |
|
496 |
|
497 // ----------------------------------------------------------------------------- |
|
498 // CleanUpVisual:reset the values of the variables. |
|
499 // ----------------------------------------------------------------------------- |
|
500 // |
|
501 void CGlxZoomControl::CleanUpVisual() |
|
502 { |
|
503 TRACER("CGlxZoomControl::CleanUpVisual() "); |
|
504 } |
|
505 // ----------------------------------------------------------------------------- |
|
506 // Activated |
|
507 // ----------------------------------------------------------------------------- |
|
508 // |
|
509 EXPORT_C TBool CGlxZoomControl::Activated() |
|
510 { |
|
511 TRACER("CGlxZoomControl::Activated"); |
|
512 return iZoomActive; |
|
513 } |
|
514 |
|
515 // ----------------------------------------------------------------------------- |
|
516 // OfferEventL |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 TBool CGlxZoomControl::OfferEventL(const TAlfEvent &aEvent) |
|
520 { |
|
521 TRACER("CGlxZoomControl::OfferEventL()"); |
|
522 |
|
523 GLX_LOG_INFO1("OfferEventL 2: iZoomEnabled = %d ", iZoomActive ); |
|
524 // All the events related to the keys and pointers will be coming to this offerevent |
|
525 return iEventHandler->HandleEventL(aEvent) ; |
|
526 } |
|
527 |
|
528 |
|
529 // ----------------------------------------------------------------------------- |
|
530 // offerEvent |
|
531 // ----------------------------------------------------------------------------- |
|
532 // |
|
533 AlfEventStatus CGlxZoomControl::offerEvent( CAlfWidgetControl& /*aControl*/, |
|
534 const TAlfEvent& aEvent) |
|
535 { |
|
536 TRACER("CGlxZoomControl::OfferEvent( CAlfWidgetControl& /*aControl*/)"); |
|
537 // All the events which are related to slider widget will be coming |
|
538 // to this offerevent. |
|
539 AlfEventStatus eventStatus = EEventNotHandled; |
|
540 |
|
541 TBool consumed = iEventHandler->HandleEvent(aEvent); |
|
542 if ( consumed ) |
|
543 { |
|
544 eventStatus = EEventConsumed; |
|
545 } |
|
546 |
|
547 return eventStatus; |
|
548 } |
|
549 |
|
550 |
|
551 // ----------------------------------------------------------------------------- |
|
552 // TextureContentChangedL |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 void CGlxZoomControl::TextureContentChangedL( TBool /*aHasContent*/ , CAlfTexture* aNewTexture) |
|
556 { |
|
557 TRACER("CGlxZoomControl::TextureContentChangedL "); |
|
558 //if both the textures are null that means we do not have memory to |
|
559 //decode and show anything. So try and check if the fullscreen texture |
|
560 //is created by now if not then go to fullscreen view. |
|
561 |
|
562 if(NULL == aNewTexture ) |
|
563 { |
|
564 if(NULL == iImageTexture) |
|
565 { |
|
566 TSize TextureSize = ScreenSize(); |
|
567 TInt focus = iMediaList.FocusIndex(); |
|
568 TGlxMedia item = iMediaList.Item( focus ); |
|
569 TGlxIdSpaceId idspace = iMediaList.IdSpaceId( focus ); |
|
570 |
|
571 CAlfTexture* newTexture = NULL; |
|
572 //Get the texture Created in fullscreen View. |
|
573 TRAPD(errtexture, newTexture = &(iTextureMgr->CreateNewTextureForMediaL( |
|
574 TextureSize,item, idspace, this ))); |
|
575 |
|
576 if(errtexture != KErrNone) |
|
577 { |
|
578 GLX_LOG_INFO( "CGlxTextureManagerImpl::HandleBitmapDecodedL::CreateNewTextureForMediaL Failed"); |
|
579 //Exit zoom and goto fullscreen |
|
580 HandleZoomOutL(KGlxZoomOutCommand); |
|
581 } |
|
582 else |
|
583 { |
|
584 //show the fullscreen texture. |
|
585 iImageTexture = newTexture; |
|
586 iImageVisual->SetImage( *iImageTexture ); |
|
587 } |
|
588 } |
|
589 else |
|
590 { |
|
591 //show the existing first level decoded image texture in case second level |
|
592 //decoding fails |
|
593 iImageVisual->SetImage( *iImageTexture ); |
|
594 } |
|
595 } |
|
596 else |
|
597 { |
|
598 iImageTexture = aNewTexture; |
|
599 iImageVisual->SetImage( *iImageTexture ); |
|
600 } |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // VisualLayoutUpdated:updates the co-ordinates when phone is tilted |
|
605 // ----------------------------------------------------------------------------- |
|
606 // |
|
607 void CGlxZoomControl::VisualLayoutUpdated(CAlfVisual& aVisual) |
|
608 { |
|
609 TRACER("CGlxZoomControl::VisualLayoutUpdated "); |
|
610 // Callback comes to this function when there is a resolution change |
|
611 |
|
612 if(iGlxTvOut->IsHDMIConnected()) |
|
613 { |
|
614 return; |
|
615 } |
|
616 |
|
617 TRect rect; |
|
618 rect = AlfUtil::ScreenSize(); |
|
619 if ( (rect.Width() != iScreenSize.iWidth) && ( rect.Height() != iScreenSize.iHeight)) |
|
620 { |
|
621 //notify slider about Orientation Change |
|
622 iZoomSliderWidget.ContainerLayout().Owner().VisualLayoutUpdated(aVisual); |
|
623 //when the Phone is tilted,Height becomes the width and vice versa. So update with the new dimensions |
|
624 iScreenSize.iWidth = rect.Width(); |
|
625 iScreenSize.iHeight = rect.Height(); |
|
626 iDisplay->SetVisibleArea(TRect(TPoint(0,0),iScreenSize)); |
|
627 |
|
628 //[TODO]: Use the Maths engine ro arrive at this figure (virtual and viewport sizes). else there might be problems in fringe conditions |
|
629 iViewPort->SetVirtualSize(TAlfRealSize(iScreenSize.iWidth,iScreenSize.iHeight), 0); |
|
630 iViewPort->SetViewportSize(TAlfRealSize(iScreenSize.iWidth,iScreenSize.iHeight), 0); |
|
631 if(Activated()) |
|
632 { |
|
633 iEventHandler->OrientationChanged(rect); |
|
634 } |
|
635 iCommandHandler.HandleCommandL(KGlxZoomOrientationChange, this); |
|
636 } |
|
637 } |
|
638 |
|
639 // --------------------------------------------------------------------------- |
|
640 // ShowUi |
|
641 // --------------------------------------------------------------------------- |
|
642 // |
|
643 void CGlxZoomControl::ShowUi(TBool aShow) |
|
644 { |
|
645 TRACER("CGlxZoomControl::ShowUi "); |
|
646 |
|
647 if (aShow) |
|
648 { |
|
649 iEventHandler->SetZoomUiState(EUiOn); |
|
650 } |
|
651 else |
|
652 { |
|
653 iEventHandler->SetZoomUiState(EUiOff); |
|
654 } |
|
655 |
|
656 iZoomBackKey->MakeVisible( aShow ); |
|
657 iZoomSliderWidget.ShowWidget( aShow, 0 ); |
|
658 } |
|
659 |
|
660 // --------------------------------------------------------------------------- |
|
661 // From IAlfWidgetEventHandler.. |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 bool CGlxZoomControl::accept( CAlfWidgetControl& /*aControl*/, |
|
665 const TAlfEvent& /*aEvent*/) const |
|
666 { |
|
667 TRACER("CGlxZoomControl::accept "); |
|
668 return ETrue; |
|
669 } |
|
670 |
|
671 // --------------------------------------------------------------------------- |
|
672 // From IAlfWidgetEventHandler.. |
|
673 // --------------------------------------------------------------------------- |
|
674 // |
|
675 void CGlxZoomControl::setEventHandlerData( |
|
676 const AlfWidgetEventHandlerInitData& /*aData*/) |
|
677 { |
|
678 TRACER("CGlxZoomControl::setEventHandlerData "); |
|
679 } |
|
680 // --------------------------------------------------------------------------- |
|
681 // From IAlfWidgetEventHandler.. |
|
682 // --------------------------------------------------------------------------- |
|
683 // |
|
684 |
|
685 AlfWidgetEventHandlerInitData* CGlxZoomControl::eventHandlerData() |
|
686 { |
|
687 TRACER("CGlxZoomControl::eventHandlerData "); |
|
688 return NULL; |
|
689 } |
|
690 // --------------------------------------------------------------------------- |
|
691 // From IAlfWidgetEventHandler. |
|
692 // --------------------------------------------------------------------------- |
|
693 // |
|
694 |
|
695 void CGlxZoomControl::setActiveStates( unsigned int /*aStates*/ ) |
|
696 { |
|
697 TRACER("CGlxZoomControl::setActiveStates "); |
|
698 } |
|
699 // --------------------------------------------------------------------------- |
|
700 // From IAlfWidgetEventHandler. |
|
701 // --------------------------------------------------------------------------- |
|
702 // |
|
703 |
|
704 IAlfInterfaceBase* CGlxZoomControl::makeInterface( const IfId& /*aType*/ ) |
|
705 { |
|
706 TRACER("CGlxZoomControl::makeInterface Enter/Exit"); |
|
707 return NULL; |
|
708 } |
|
709 //---------------------------------------------------------------------------------- |
|
710 // eventHandlerType |
|
711 //---------------------------------------------------------------------------------- |
|
712 // |
|
713 IAlfWidgetEventHandler::AlfEventHandlerType CGlxZoomControl::eventHandlerType() |
|
714 { |
|
715 TRACER("CGlxZoomControl::eventHandlerType Enter/Exit"); |
|
716 return IAlfWidgetEventHandler::ELogicalEventHandler; |
|
717 } |
|
718 |
|
719 //---------------------------------------------------------------------------------- |
|
720 // eventExecutionPhase |
|
721 //---------------------------------------------------------------------------------- |
|
722 // |
|
723 IAlfWidgetEventHandler::AlfEventHandlerExecutionPhase CGlxZoomControl::eventExecutionPhase() |
|
724 { |
|
725 TRACER("CGlxZoomControl::eventExecutionPhase Enter/Exit"); |
|
726 return EBubblingPhaseEventHandler; |
|
727 } |
|
728 |
|
729 //---------------------------------------------------------------------------------- |
|
730 // GetOrientationL: to retreive orientation from the exif tags in the file |
|
731 //---------------------------------------------------------------------------------- |
|
732 // |
|
733 TUint16 CGlxZoomControl::GetOrientationL(const TDesC& aFileName) |
|
734 { |
|
735 TRACER("CGlxZoomControl::GetOrientationL()"); |
|
736 //Get Exif Metadata and the orientation tag from the file first |
|
737 RFs fs; |
|
738 CleanupClosePushL(fs); |
|
739 User::LeaveIfError(fs.Connect()); |
|
740 |
|
741 RFile file; |
|
742 CleanupClosePushL(file); |
|
743 User::LeaveIfError(file.Open(fs, |
|
744 aFileName, EFileRead)); |
|
745 |
|
746 TInt size; |
|
747 User::LeaveIfError(file.Size(size)); |
|
748 if ( KGlxMaxExifSize < size ) |
|
749 { |
|
750 size = KGlxMaxExifSize; |
|
751 } |
|
752 TUint16 orientation = 0; |
|
753 HBufC8* exifData = HBufC8::NewLC(size); |
|
754 TPtr8 ptr(exifData->Des()); |
|
755 User::LeaveIfError(file.Read(ptr)); |
|
756 CExifRead* exifReader = NULL; |
|
757 TRAPD(exifErr,exifReader = CExifRead::NewL(*exifData, CExifRead::ENoJpeg)); |
|
758 if(exifErr == KErrNone) |
|
759 { |
|
760 CleanupStack::PushL(exifReader); |
|
761 |
|
762 TInt readErr = exifReader->GetOrientation(orientation); |
|
763 if(readErr != KErrNone) |
|
764 { |
|
765 orientation = 0; |
|
766 } |
|
767 CleanupStack::PopAndDestroy(exifReader); |
|
768 } |
|
769 CleanupStack::PopAndDestroy(exifData); |
|
770 //Close and pop file Session |
|
771 CleanupStack::PopAndDestroy(&file); |
|
772 CleanupStack::PopAndDestroy(&fs); |
|
773 return orientation; |
|
774 |
|
775 } |
|
776 |
|
777 // ----------------------------------------------------------------------------- |
|
778 // UpdateViewPort |
|
779 // ----------------------------------------------------------------------------- |
|
780 // |
|
781 void CGlxZoomControl::UpdateViewPort(TPoint& aViewPortTopLeft, |
|
782 TInt aTransitionTime, |
|
783 TSize *apViewPortDimension, |
|
784 TInt aPrimarySliderRatio) |
|
785 { |
|
786 TRACER("void CGlxZoomControl::UpdateViewPort"); |
|
787 |
|
788 iViewPort->SetViewportPos(aViewPortTopLeft,aTransitionTime); |
|
789 |
|
790 if (apViewPortDimension) |
|
791 { |
|
792 iViewPort->SetVirtualSize(*apViewPortDimension,0); |
|
793 } |
|
794 |
|
795 if(aPrimarySliderRatio >= 0) |
|
796 { |
|
797 iZoomSliderModel->SetPrimaryValue(aPrimarySliderRatio); |
|
798 } |
|
799 |
|
800 GLX_LOG_INFO1(" CGlxZoomControl::UpdateViewPort aPrimarySliderRatio = [%d]", aPrimarySliderRatio); |
|
801 |
|
802 } |
|
803 |
|
804 // ----------------------------------------------------------------------------- |
|
805 // HandleShowUi |
|
806 // ----------------------------------------------------------------------------- |
|
807 // |
|
808 void CGlxZoomControl::HandleShowUi( TBool aShow) |
|
809 { |
|
810 TRACER("void CGlxZoomControl::HandleShowUi"); |
|
811 ShowUi(aShow); |
|
812 } |
|
813 |
|
814 |
|
815 |
|
816 // ----------------------------------------------------------------------------- |
|
817 // HandleSetViewPort |
|
818 // ----------------------------------------------------------------------------- |
|
819 // |
|
820 void CGlxZoomControl::HandleViewPortParametersChanged(TPoint& aViewPortTopLeft , |
|
821 TInt aTransitionTime , |
|
822 TSize *apViewPortDimension , |
|
823 TInt aPrimarySliderLevel ) |
|
824 { |
|
825 TRACER("void CGlxZoomControl::HandleSetViewPort"); |
|
826 UpdateViewPort(aViewPortTopLeft, aTransitionTime, apViewPortDimension, |
|
827 aPrimarySliderLevel); |
|
828 } |
|
829 |
|
830 // ----------------------------------------------------------------------------- |
|
831 // HandleZoomOut |
|
832 // ----------------------------------------------------------------------------- |
|
833 // |
|
834 void CGlxZoomControl::HandleZoomOutL(TInt aCommandId) |
|
835 { |
|
836 TRACER("void CGlxZoomControl::HandleZoomOut"); |
|
837 iCommandHandler.HandleCommandL(aCommandId, this); |
|
838 } |
|
839 |
|
840 |
|
841 // ----------------------------------------------------------------------------- |
|
842 // HandleHDMIGestureReleased |
|
843 // ----------------------------------------------------------------------------- |
|
844 // |
|
845 void CGlxZoomControl::HandleHDMIGestureReleased() |
|
846 { |
|
847 TRACER("void CGlxZoomControl::HandlePinchReleased"); |
|
848 if ( iGlxTvOut->IsHDMIConnected() && iZoomActive) |
|
849 { |
|
850 //On HDMI pinch release, zoom out to fullscreen |
|
851 GLX_LOG_INFO("_PHOTOS_LOG_: void CGlxZoomControl::HandlePinchReleased Start ZoomOut"); |
|
852 iTimer->Cancel(); |
|
853 iTimer->Start(KHDMIZoomDelay,KHDMIZoomDelay,TCallBack( TimeOut,this )); |
|
854 } |
|
855 } |
|
856 |
|
857 // ----------------------------------------------------------------------------- |
|
858 // HandlePointerEventsL |
|
859 // ----------------------------------------------------------------------------- |
|
860 // |
|
861 TBool CGlxZoomControl::HandlePointerEventsL(const TAlfEvent &aEvent) |
|
862 { |
|
863 TRACER("void CGlxZoomControl::HandlePointerEventsL"); |
|
864 |
|
865 return iGestureHelper->OfferEventL(aEvent); |
|
866 |
|
867 } |
|
868 |
|
869 // ----------------------------------------------------------------------------- |
|
870 // HandleGestureL |
|
871 // ----------------------------------------------------------------------------- |
|
872 // |
|
873 void CGlxZoomControl::HandleGestureL( const GestureHelper::MGestureEvent& aEvent ) |
|
874 { |
|
875 TRACER("void CGlxZoomControl::HandleGestureL"); |
|
876 |
|
877 TGestureCode code = aEvent.Code(MGestureEvent::EAxisBoth); |
|
878 GLX_LOG_INFO1("_PHOTOS_LOG_: void CGlxZoomControl::HandleGestureL Code : %d", code); |
|
879 |
|
880 //In HDMI pinch mode we will handle only released gesture |
|
881 //to zoom out the image to fullscreeen. |
|
882 if( iGlxTvOut->IsHDMIConnected() ) |
|
883 { |
|
884 if(code == EGestureReleased) |
|
885 { |
|
886 HandleHDMIGestureReleased(); |
|
887 } |
|
888 } |
|
889 else |
|
890 { |
|
891 // Todo: This switch should go into the event handler. |
|
892 switch (code) |
|
893 { |
|
894 case EGestureDrag: |
|
895 if (aEvent.Visual() == iImageVisual) |
|
896 { |
|
897 iEventHandler->HandleDragEvent(aEvent); |
|
898 } |
|
899 break; |
|
900 case EGestureTap: |
|
901 iEventHandler->HandleSingleTap(aEvent); |
|
902 break; |
|
903 case EGesturePinch: |
|
904 iEventHandler->HandlePinchEventL(aEvent); |
|
905 break; |
|
906 case EGestureDoubleTap: |
|
907 if (aEvent.Visual() == iImageVisual) |
|
908 { |
|
909 iEventHandler->HandleDoubleTap(aEvent); |
|
910 } |
|
911 break; |
|
912 case EGestureReleased: |
|
913 iEventHandler->HandleGestureReleased(aEvent); |
|
914 break; |
|
915 default : |
|
916 break; |
|
917 } |
|
918 } |
|
919 iEventHandler->SetPreviousEventCode(code); |
|
920 } |
|
921 |
|
922 // ----------------------------------------------------------------------------- |
|
923 // HandleTvStatusChangedL |
|
924 // ----------------------------------------------------------------------------- |
|
925 void CGlxZoomControl::HandleTvStatusChangedL( TTvChangeType aChangeType ) |
|
926 { |
|
927 TRACER("CGlxZoomControl::HandleTvStatusChangedL()"); |
|
928 if ( aChangeType == ETvConnectionChanged ) |
|
929 { |
|
930 if ( iGlxTvOut->IsHDMIConnected() && iZoomActive) |
|
931 { |
|
932 //initialise all the zoom values to full-screen when hdmi is connected. |
|
933 if(iEventHandler) |
|
934 { |
|
935 iEventHandler->ZoomToMinimumL(); |
|
936 } |
|
937 } |
|
938 } |
|
939 } |
|
940 |
|
941 // --------------------------------------------------------------------------- |
|
942 // ZoomUiState |
|
943 // --------------------------------------------------------------------------- |
|
944 // |
|
945 EXPORT_C TUiState CGlxZoomControl::ZoomUiState() |
|
946 { |
|
947 TRACER("CGlxZoomControl::ZoomUiState"); |
|
948 return iEventHandler->ZoomUiState(); |
|
949 } |
|
950 |
|
951 // --------------------------------------------------------------------------- |
|
952 // HandleGoomMemoryReleased |
|
953 // Callback from memMonitor CGlxRelaseGPUMemory |
|
954 // --------------------------------------------------------------------------- |
|
955 // |
|
956 void CGlxZoomControl::HandleGoomMemoryReleased(TInt aStatus) |
|
957 { |
|
958 TRACER("CGlxZoomControl::HandleGoomMemoryReleased"); |
|
959 if (aStatus == KErrNone) |
|
960 { |
|
961 //Refeed the textures if we are coming back to foreground from background |
|
962 //To Retrive the image details |
|
963 TMPXAttribute thumbNailAttribute(0, 0); |
|
964 TInt focusIndex = iMediaList.FocusIndex(); |
|
965 TGlxIdSpaceId idspace = iMediaList.IdSpaceId(focusIndex); |
|
966 //Get the texture Created in fullscreen View. |
|
967 TGlxMedia item = iMediaList.Item(focusIndex); |
|
968 |
|
969 // if we already have the decoded zoomed image bitmap use the texture corresponding to that. |
|
970 // Else make do with the fullscreen texture till that happens. |
|
971 TRAP_IGNORE(iImageTexture = |
|
972 iTextureMgr->CreateZoomedTextureL()); |
|
973 |
|
974 if (NULL == iImageTexture) |
|
975 { |
|
976 TRAP_IGNORE(iImageTexture = &(iTextureMgr->CreateNewTextureForMediaL( |
|
977 ScreenSize(), item, idspace, this))) |
|
978 } |
|
979 |
|
980 if (NULL != iImageTexture) |
|
981 { |
|
982 iImageVisual->SetImage(*iImageTexture); |
|
983 return; |
|
984 } |
|
985 } |
|
986 |
|
987 // No GPU Memory, return back to Fullscreenview |
|
988 ActivateFullscreen(); |
|
989 } |
|
990 // End of File |