2 #include <unique_ptr.h>
3 #include <FShellLiveboxView.h>
4 #include <FShellLiveboxManager.h>
5 #include <FShellLiveboxProviderInfo.h>
6 #include <FShellLiveboxSizeInfo.h>
9 using namespace Tizen::Base;
10 using namespace Tizen::Base::Collection;
11 using namespace Tizen::Graphics;
12 using namespace Tizen::Ui;
13 using namespace Tizen::Ui::Controls;
14 using namespace Tizen::Ui::Scenes;
15 using namespace Tizen::Shell;
17 const int CONTEXT_MENU_X = 100;
18 const int CONTEXT_MENU_Y = 200;
20 const int VIEW_Y = 50;
21 const int VIEW_WIDTH = 172;
22 const int VIEW_HEIGHT = 172;
24 ViewForm::ViewForm(void)
25 : __pLiveboxView(null)
26 , __pContextMenu(null)
27 , __pSizeInfoList(null)
31 ViewForm::~ViewForm(void)
36 ViewForm::Initialize()
38 Form::Construct(L"IDF_VIEW_FORM");
44 ViewForm::OnInitializing(void)
48 // TODO: Add your initialization code here
49 SetFormBackEventListener(this);
50 Footer* pFooter = GetFooter();
51 pFooter->AddActionEventListener(*this);
56 ViewForm::OnTerminating(void)
60 // TODO: Add your termination code here
61 delete __pContextMenu;
64 __pSizeInfoList->RemoveAll(true);
65 delete __pSizeInfoList;
72 ViewForm::CreateLiveboxView(const Tizen::Base::String& appId, const Tizen::Base::String& providerName)
74 __pLiveboxView = new LiveboxView();
77 __pLiveboxView->Construct(appId, providerName, Rectangle(VIEW_X, VIEW_Y, VIEW_WIDTH, VIEW_HEIGHT));
78 AddControl(*__pLiveboxView);
81 __pContextMenu = new (std::nothrow) ContextMenu();
82 __pContextMenu->Construct(Point(CONTEXT_MENU_X, CONTEXT_MENU_Y), CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD);
84 std::unique_ptr<LiveboxProviderInfo> pProviderInfo(LiveboxManager::GetInstance()->GetLiveboxProviderInfoN(appId, providerName ));
85 TryReturnVoid(pProviderInfo.get(), "pProviderInfo is null!!");
87 __pSizeInfoList = pProviderInfo->GetSizeInfosN();
90 for(int i = 0; i < __pSizeInfoList->GetCount(); i ++)
92 LiveboxSizeInfo* pSizeInfo = dynamic_cast<LiveboxSizeInfo*>(__pSizeInfoList->GetAt(i) );
95 AppLog("pSizeInfo is null");
98 AppLog("(%d, %d)", pSizeInfo->GetSize().width, pSizeInfo->GetSize().height);
101 size.Format(255, L"%dx%d", pSizeInfo->GetSize().width, pSizeInfo->GetSize().height);
103 __pContextMenu->AddItem(size, i);
107 Rectangle formBounds = GetBounds();
108 Rectangle contextMenuBounds = __pContextMenu->GetBounds();
109 Point anchor = __pContextMenu->GetAnchorPosition();
110 anchor.y = formBounds.height - contextMenuBounds.height;
112 AppLog("(%d %d %d %d) (%d %d)", contextMenuBounds.x, contextMenuBounds.y, contextMenuBounds.width, contextMenuBounds.height, anchor.x, anchor.y);
114 __pContextMenu->SetAnchorPosition(anchor);
116 __pContextMenu->AddActionEventListener(*this);
120 ViewForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
122 AppLog("(%d)", actionId);
124 if (actionId == ID_FOOTER_ITEM1)
126 if (__pContextMenu && (__pContextMenu->GetItemCount() > 0))
128 __pContextMenu->SetShowState(true);
129 __pContextMenu->Show();
134 LiveboxSizeInfo* pSizeInfo = null;
137 pSizeInfo = dynamic_cast<LiveboxSizeInfo*>(__pSizeInfoList->GetAt(actionId) );
138 TryReturnVoid(pSizeInfo, "pSizeInfo is null!!");
143 __pLiveboxView->SetSize(pSizeInfo->GetSize());
149 ViewForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
151 SceneManager* pSceneManager = SceneManager::GetInstance();
152 AppAssert(pSceneManager);
153 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
157 ViewForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
159 if (pArgs && (pArgs->GetCount() > 0))
161 String* pAppId = dynamic_cast<String*>(pArgs->GetAt(0));
162 String* pLiveboxProviderName = dynamic_cast<String*>(pArgs->GetAt(1));
163 if (pAppId != null && pLiveboxProviderName != null)
165 AppLog("%ls", pAppId->GetPointer());
167 Header* pHeader = GetHeader();
168 pHeader->SetTitleText(*pAppId);
170 CreateLiveboxView(*pAppId, *pLiveboxProviderName);
173 pArgs->RemoveAll(true);
179 ViewForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
183 RemoveControl(*__pLiveboxView);
184 __pLiveboxView = null;