3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
20 #include <FShellLiveboxProviderInfo.h>
21 #include <FShellLiveboxManager.h>
22 #include <FShellLiveboxSizeInfo.h>
24 #include "LiveboxViewerMainForm.h"
25 #include "LiveboxViewerFormFactory.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::App;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33 using namespace Tizen::Ui::Scenes;
34 using namespace Tizen::Shell;
36 const int LIST_ITEM_ICON = 72;
37 const int LIST_ITEM_HEIGHT = 112;
38 const int LIST_ITEM_MARGIN_LEFT = 26;
39 const int LIST_ITEM_MARGIN_TOP = 32;
40 const int LIST_ITEM_TEXT_HEIGHT = 44;
42 LiveboxViewerMainForm::LiveboxViewerMainForm(void)
44 , __pLiveboxProviderList(null)
46 __pLiveboxProviderList = LiveboxManager::GetInstance()->GetLiveboxProviderInfoListN();
47 TryReturnVoid(__pLiveboxProviderList, "GetLiveboxListN returns null!!" );
49 __pLiveboxIconList = new ArrayList(SingleObjectDeleter);
50 __pLiveboxIconList->Construct();
51 for( int i = 0; i < __pLiveboxProviderList->GetCount(); i++)
53 LiveboxProviderInfo* pLiveboxProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(i) );
55 Tizen::Media::Image image;
56 result r = image.Construct();
57 Bitmap* pBmp = image.DecodeN(pLiveboxProviderInfo->GetIconPath(), BITMAP_PIXEL_FORMAT_ARGB8888);
59 __pLiveboxIconList->Add(pBmp);
63 LiveboxViewerMainForm::~LiveboxViewerMainForm(void)
68 LiveboxViewerMainForm::Initialize(void)
70 Construct(L"IDF_FORM");
76 LiveboxViewerMainForm::OnInitializing(void)
80 // Setup back event listener
81 SetFormBackEventListener(this);
83 if (!__pLiveboxProviderList)
85 AppLog("GetLiveboxListN returns null!!");
89 for(int i = 0; i < __pLiveboxProviderList->GetCount(); i++)
91 LiveboxProviderInfo* pLiveboxProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(i) );
93 IList* pSizeList = pLiveboxProviderInfo->GetSizeInfoListN();
94 if(pSizeList == null) continue;
95 AppLog("%ls, support (%d) sizes", pLiveboxProviderInfo->GetDisplayName().GetPointer(), pSizeList->GetCount() );
97 for(int j = 0; j < pSizeList->GetCount(); j ++)
99 LiveboxSizeInfo* pSizeInfo = dynamic_cast<LiveboxSizeInfo*>(pSizeList->GetAt(j) );
100 AppLog("(%d, %d)", pSizeInfo->GetSize().width, pSizeInfo->GetSize().height);
102 pSizeList->RemoveAll(true);
107 // Add your initialization code here
108 __pList = new (std::nothrow) ListView();
109 __pList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false);
110 __pList->SetItemProvider(*this);
111 __pList->AddListViewItemEventListener(*this);
112 AddControl(*__pList);
118 LiveboxViewerMainForm::OnTerminating(void)
120 result r = E_SUCCESS;
123 // Add your termination code here
124 if (__pLiveboxProviderList)
126 __pLiveboxProviderList->RemoveAll(true);
127 delete __pLiveboxProviderList;
130 if (__pLiveboxIconList)
132 __pLiveboxIconList->RemoveAll();
133 delete __pLiveboxIconList;
140 LiveboxViewerMainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 AppAssert(pSceneManager);
153 LiveboxViewerMainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
155 UiApp* pApp = UiApp::GetInstance();
161 LiveboxViewerMainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
162 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
165 // Add your scene activate code here
166 AppLog("OnSceneActivatedN");
170 LiveboxViewerMainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
171 const Tizen::Ui::Scenes::SceneId& nextSceneId)
174 // Add your scene deactivate code here
175 AppLog("OnSceneDeactivated");
179 LiveboxViewerMainForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
181 if(status == LIST_ITEM_STATUS_SELECTED)
183 __pSelectedProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
184 AppAssert(__pSelectedProviderInfo);
186 String configurationAppControlAppId = __pSelectedProviderInfo->GetConfigurationAppControlAppId();
187 if(!configurationAppControlAppId.IsEmpty())
189 StartConfigurationAppControl(__pSelectedProviderInfo->GetConfigurationAppControlAppId(), __pSelectedProviderInfo->GetName());
193 AppLog("%ls", __pSelectedProviderInfo->GetDisplayName().GetPointer());
194 GoLiveboxViewScene(__pSelectedProviderInfo->GetAppId(), __pSelectedProviderInfo->GetName(), L"");
200 LiveboxViewerMainForm::StartConfigurationAppControl(const Tizen::Base::String& appId, const Tizen::Base::String& providerName)
202 AppControl* pAc = AppManager::FindAppControlN( appId, L"http://tizen.org/appcontrol/operation/livebox/configuration");
205 String key = L"ProviderName";
206 String value = providerName;
207 extra.Add(&key, &value);
209 pAc->Start(null, null, &extra, this);
214 LiveboxViewerMainForm::GoLiveboxViewScene(const String& appId, const String& providerName, const String& userInfo)
216 ArrayList* pList = new (std::nothrow) ArrayList;
220 pList->Add(*(new (std::nothrow) String(appId) ));
221 pList->Add(*(new (std::nothrow) String(providerName) ));
222 pList->Add(*(new (std::nothrow) String(userInfo )) );
224 SceneManager* pSceneManager = SceneManager::GetInstance();
225 AppAssert(pSceneManager);
227 pSceneManager->GoForward(ForwardSceneTransition(VIEW_SCENE, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
228 __pSelectedProviderInfo = null;
232 LiveboxViewerMainForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView &listView, int index, Tizen::Ui::Controls::SweepDirection direction)
237 LiveboxViewerMainForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
242 LiveboxViewerMainForm::OnItemReordered(Tizen::Ui::Controls::ListView &view, int oldIndex, int newIndex)
247 LiveboxViewerMainForm::GetItemCount(void)
249 return __pLiveboxProviderList->GetCount();
252 Tizen::Ui::Controls::ListItemBase*
253 LiveboxViewerMainForm::CreateItem (int index, int itemWidth)
255 CustomItem* pItem = new (std::nothrow) CustomItem();
256 pItem->Construct(Tizen::Graphics::Dimension(itemWidth, LIST_ITEM_HEIGHT), LIST_ANNEX_STYLE_NORMAL);
258 Rectangle iconRect(LIST_ITEM_MARGIN_LEFT, LIST_ITEM_MARGIN_TOP/2, LIST_ITEM_ICON, LIST_ITEM_ICON);
259 int text_x = LIST_ITEM_ICON + LIST_ITEM_MARGIN_LEFT + 20;
260 Rectangle textRect(text_x, LIST_ITEM_MARGIN_TOP, GetClientAreaBounds().width - LIST_ITEM_MARGIN_LEFT - text_x, LIST_ITEM_TEXT_HEIGHT);
262 LiveboxProviderInfo* pProviderInfo = dynamic_cast<LiveboxProviderInfo*>(__pLiveboxProviderList->GetAt(index));
266 Bitmap* pBmp = dynamic_cast<Bitmap*>(__pLiveboxIconList->GetAt(index));
268 pItem->AddElement(iconRect, ID_FORMAT_BITMAP, *pBmp, null, null);
269 pItem->AddElement(textRect, ID_FORMAT_STRING, pProviderInfo->GetDisplayName()+" ("+pProviderInfo->GetAppId()+")", true);
276 LiveboxViewerMainForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase *pItem, int itemWidth)
284 LiveboxViewerMainForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId, AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
287 TryReturnVoid(__pSelectedProviderInfo, "__pSelectedProviderInfo should not be null!");
291 String userInfokey(L"UserInfo");
292 const String* pUserInfoValue = dynamic_cast<const String*>(pExtraData->GetValue(userInfokey) );
293 AppLog("%ls, %ls, %ls", appId.GetPointer(), operationId.GetPointer(), pUserInfoValue->GetPointer() );
295 GoLiveboxViewScene(__pSelectedProviderInfo->GetAppId(), __pSelectedProviderInfo->GetName(), *pUserInfoValue);