3198472c2d516a6bcb69ddf62c7f772ec695ff6f
[apps/native/sample/DynamicBoxViewer.git] / project / src / LiveboxViewerMainForm.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FApp.h>
19 #include <FShellLiveboxProviderInfo.h>
20 #include <FShellLiveboxManager.h>
21 #include <FShellLiveboxSizeInfo.h>
22
23 #include "LiveboxViewerMainForm.h"
24 #include "LiveboxViewerFormFactory.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::App;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
33 using namespace Tizen::Shell;
34
35 const int LIST_ITEM_HEIGHT = 112;
36 const int LIST_ITEM_MARGIN_LEFT = 26;
37 const int LIST_ITEM_MARGIN_TOP = 32;
38 const int LIST_ITEM_TEXT_HEIGHT = 44;
39
40 LiveboxViewerMainForm::LiveboxViewerMainForm(void)
41         : __pList(null)
42         , __pLiveboxProviderList(null)
43 {
44         __pLiveboxProviderList = LiveboxManager::GetInstance()->GetLiveboxProviderInfoListN();
45         TryReturnVoid(__pLiveboxProviderList, "GetLiveboxListN returns null!!" );
46
47         AppLog("All livebox count (%d)", __pLiveboxProviderList->GetCount() );
48 }
49
50 LiveboxViewerMainForm::~LiveboxViewerMainForm(void)
51 {
52 }
53
54 bool
55 LiveboxViewerMainForm::Initialize(void)
56 {
57         Construct(L"IDF_FORM");
58
59         return true;
60 }
61
62 result
63 LiveboxViewerMainForm::OnInitializing(void)
64 {
65         result r = E_SUCCESS;
66
67         // Setup back event listener
68         SetFormBackEventListener(this);
69
70         if (!__pLiveboxProviderList)
71         {
72                 AppLog("GetLiveboxListN returns null!!");
73                 return E_SUCCESS;
74         }
75
76         for(int i = 0; i < __pLiveboxProviderList->GetCount(); i++)
77         {
78                 LiveboxProviderInfo* pLiveboxProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(i) );
79
80                 IList* pSizeList = pLiveboxProviderInfo->GetSizeInfoListN();
81                 if(pSizeList == null) continue;
82                 AppLog("%ls, support (%d) sizes", pLiveboxProviderInfo->GetDisplayName().GetPointer(), pSizeList->GetCount() );
83
84                 for(int j = 0; j < pSizeList->GetCount(); j ++)
85                 {
86                         LiveboxSizeInfo* pSizeInfo = dynamic_cast<LiveboxSizeInfo*>(pSizeList->GetAt(j) );
87                         AppLog("(%d, %d)", pSizeInfo->GetSize().width, pSizeInfo->GetSize().height);
88                 }
89                 pSizeList->RemoveAll(true);
90                 delete pSizeList;
91         }
92         
93         // TODO:
94         // Add your initialization code here
95         __pList = new (std::nothrow) ListView();
96         __pList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false);
97         __pList->SetItemProvider(*this);
98         __pList->AddListViewItemEventListener(*this);
99         AddControl(*__pList);
100
101         return r;
102 }
103
104 result
105 LiveboxViewerMainForm::OnTerminating(void)
106 {
107         result r = E_SUCCESS;
108
109         // TODO:
110         // Add your termination code here
111         if (__pLiveboxProviderList)
112         {
113                 __pLiveboxProviderList->RemoveAll(true);
114                 delete __pLiveboxProviderList;
115         }
116
117         return r;
118 }
119
120 void
121 LiveboxViewerMainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
122 {
123         SceneManager* pSceneManager = SceneManager::GetInstance();
124         AppAssert(pSceneManager);
125
126         switch(actionId)
127         {
128         default:
129                 break;
130         }
131 }
132
133 void
134 LiveboxViewerMainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
135 {
136         UiApp* pApp = UiApp::GetInstance();
137         AppAssert(pApp);
138         pApp->Terminate();
139 }
140
141 void
142 LiveboxViewerMainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
143                                                                                   const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
144 {
145         // TODO:
146         // Add your scene activate code here
147         AppLog("OnSceneActivatedN");
148 }
149
150 void
151 LiveboxViewerMainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
152                                                                                    const Tizen::Ui::Scenes::SceneId& nextSceneId)
153 {
154         // TODO:
155         // Add your scene deactivate code here
156         AppLog("OnSceneDeactivated");
157 }
158
159 void
160 LiveboxViewerMainForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
161 {
162         SceneManager* pSceneManager = SceneManager::GetInstance();
163         AppAssert(pSceneManager);
164
165         if(status == LIST_ITEM_STATUS_SELECTED)
166         {
167                 ArrayList* pList = new (std::nothrow) ArrayList;
168                 AppAssert(pList);
169                 pList->Construct();
170
171                 LiveboxProviderInfo* pProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
172                 AppAssert(pProviderInfo);
173
174                 AppLog("Display name (%ls)", pProviderInfo->GetDisplayName().GetPointer());
175                 AppLog("AppId (%ls)", pProviderInfo->GetAppId().GetPointer());
176                 AppLog("Name (%ls)", pProviderInfo->GetName().GetPointer());
177
178                 pList->Add(*(new (std::nothrow) String( pProviderInfo->GetDisplayName())));
179                 pList->Add(*(new (std::nothrow) String( pProviderInfo->GetAppId()) ));
180                 pList->Add(*(new (std::nothrow) String( pProviderInfo->GetName()) ));
181
182                 pSceneManager->GoForward(ForwardSceneTransition(VIEW_SCENE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
183         }
184 }
185
186 void
187 LiveboxViewerMainForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView &listView, int index, Tizen::Ui::Controls::SweepDirection direction)
188 {
189 }
190
191 void
192 LiveboxViewerMainForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
193 {
194 }
195
196 void
197 LiveboxViewerMainForm::OnItemReordered(Tizen::Ui::Controls::ListView &view, int oldIndex, int newIndex)
198 {
199 }
200
201 int
202 LiveboxViewerMainForm::GetItemCount(void)
203 {
204         return __pLiveboxProviderList->GetCount();
205 }
206
207 Tizen::Ui::Controls::ListItemBase*
208 LiveboxViewerMainForm::CreateItem (int index, int itemWidth)
209 {
210         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
211         
212         CustomItem* pItem = new (std::nothrow) CustomItem();
213         pItem->Construct(Tizen::Graphics::Dimension(itemWidth, LIST_ITEM_HEIGHT), style);
214         
215         Rectangle itemRect(LIST_ITEM_MARGIN_LEFT, LIST_ITEM_MARGIN_TOP, GetClientAreaBounds().width - (LIST_ITEM_MARGIN_LEFT * 2), LIST_ITEM_TEXT_HEIGHT);
216         
217         LiveboxProviderInfo* pProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
218         if (pProviderInfo)
219         {
220                 String itemTitle(pProviderInfo->GetDisplayName());
221
222                 AppLog("Item title (%ls)", itemTitle.GetPointer());
223
224                 pItem->AddElement(itemRect, ID_FORMAT_STRING, itemTitle, true);
225         }
226
227         return pItem;
228 }
229
230 bool
231 LiveboxViewerMainForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase *pItem, int itemWidth)
232 {
233         delete pItem;
234         return true;
235 }