2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file HmHomeForm.cpp
19 * @brief Keeps implementation of Main Form of the application
25 #include <FUiAnimations.h>
26 #include "HmApplicationUtils.h"
27 #include "HmHomeForm.h"
28 #include "HmHomeItemInfo.h"
29 #include "HmProgressPanel.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Animations;
39 using namespace Tizen::Ui::Controls;
41 HomeForm::HomeForm(void)
42 : __isEditEnabled(false)
43 , __isLanguageChanged(false)
44 , __pPageControl(null)
46 , __pHomePresentationModel(null)
47 , __pProgressPanel(null)
48 , __pBackgroundBitmap(null)
49 , __pSettingsBitmap(null)
50 , __pSettingsPressedBitmap(null)
51 , __pBackgroundLabel(null)
52 , __pSettingsPanel(null)
56 HomeForm::~HomeForm(void)
58 SettingInfo::RemoveSettingEventListener(*this);
60 if (__pHomePresentationModel != null)
62 __pHomePresentationModel->SetHomePackageEventListener(null);
63 delete __pHomePresentationModel;
66 if (__pBackgroundBitmap != null)
68 delete __pBackgroundBitmap;
69 __pBackgroundBitmap = null;
72 if (__pSettingsBitmap != null)
74 delete __pSettingsBitmap;
77 if (__pSettingsPressedBitmap != null)
79 delete __pSettingsPressedBitmap;
84 HomeForm::Initialize(void)
86 Construct(L"IDL_FORM");
91 HomeForm::InitializePageControls(HomePresentationModel* pPresentationModel)
95 if (__pHomePresentationModel == null)
98 IconListView* pIconListView = null;
99 __pHomePresentationModel = pPresentationModel;
100 __pHomePresentationModel->SetHomePackageEventListener(this);
102 pageCount = __pHomePresentationModel->GetPageCount();
104 while (__pPageControl->GetPageCount() < pageCount)
106 __pPageControl->AddPage();
109 for (int iconListCount = 0; iconListCount < __pPageControl->GetIconLists()->GetCount(); iconListCount++)
111 pIconListView = static_cast<IconListView*>(__pPageControl->GetIconLists()->GetAt(iconListCount));
112 pIconListView->UpdateList();
116 if (__pProgressPanel != null)
118 //return value ignored as this is just for showing wait cursor and should not disturb application flow
119 __pProgressPanel->StopAnimation();
128 HomeForm::UpdatePage(ArrayList* pPageList)
130 ArrayList* pIconLists = __pPageControl->GetIconLists();
132 for (int updateCount = 0; updateCount < pPageList->GetCount(); updateCount++)
134 IconListView* pIconList = null;
135 int pageNumber = static_cast<Integer*>(pPageList->GetAt(updateCount))->ToInt();
137 if ((pageNumber) == pIconLists->GetCount() + 1)
139 __pPageControl->AddPage();
142 pIconList = static_cast<IconListView*>(pIconLists->GetAt(pageNumber - 1));
144 if (pIconList != null)
146 pIconList->UpdateList();
153 HomeForm::OnInitializing(void)
155 result r = E_SUCCESS;
156 String wallPaperPath;
157 Rectangle clientRectangle = GetClientAreaBounds();
158 Rectangle markerRect = GetBounds();
159 Rectangle pageRect = GetBounds();
160 Label* pSettingLabel = null;
161 Label* pDoneLabel = null;
162 __pSettingsPanel = static_cast<Panel*>(GetControl(L"IDC_SETTING_PANEL"));
163 __pSettingsPanel->SetBounds(X_SETTING_PANEL, Y_SETTING_PANEL, W_SETTING_PANEL, H_SETTING_PANEL);
164 __pSettingsPanel->SetBackgroundColor(Color(0, 0, 0, 0));
166 SetControlAlwaysOnTop(*__pSettingsPanel, true);
167 r = SettingInfo::GetValue(SETTINGS_KEY_WALLPAPER, wallPaperPath);
169 if (!wallPaperPath.IsEmpty())
171 __pBackgroundBitmap = ApplicationUtils::GetBitmapN(wallPaperPath);
175 __pBackgroundBitmap = ApplicationUtils::GetResourceBitmapN(IDB_BACKGROUND_IMAGE);
178 SettingInfo::GetValue(SETTINGS_KEY_LANGUAGE, __currentLanguage);
179 r = SettingInfo::AddSettingEventListener(*this);
181 if (__pBackgroundBitmap != null)
183 clientRectangle.x = clientRectangle.y = 0;
184 __pBackgroundLabel = static_cast<Label*>(GetControl(L"IDC_BACKGROUND_LABEL"));
185 __pBackgroundLabel->SetBounds(clientRectangle);
186 __pBackgroundLabel->SetBackgroundBitmap(*__pBackgroundBitmap);
189 pDoneLabel = static_cast<Label*>(__pSettingsPanel->GetControl(L"IDC_DONE_LABEL"));
190 pDoneLabel->SetShowState(false);
191 pDoneLabel->AddTouchEventListener(*this);
192 pSettingLabel = static_cast<Label*>(__pSettingsPanel->GetControl(L"IDC_SETTING_LABEL"));
193 pSettingLabel->AddTouchEventListener(*this);
194 __pSettingsPanel->SetControlAlwaysOnTop(*pSettingLabel, true);
196 clientRectangle.x = clientRectangle.y = 0;
197 __pProgressPanel = new (std::nothrow) ProgressPanel();
198 r = __pProgressPanel->Construct(clientRectangle);
199 r = AddControl(*__pProgressPanel);
200 //return value egnored as this is just for showing wait curser and should not disturb app flow
201 __pProgressPanel->StartAnimation();
203 clientRectangle = __pSettingsPanel->GetBounds();
204 markerRect = GetClientAreaBounds();
205 markerRect.height = H_PAGE_MARKER;
207 markerRect.x = X_MARKER_POSITION; //rect.x + rect.width + 2;
208 markerRect.width -= (2 * W_MARKER_OFFSET);
209 __pPageMarker = new (std::nothrow) CustomPageMarker();
210 r = __pPageMarker->Construct(markerRect, 1);
211 TryCatch(r == E_SUCCESS, delete __pPageMarker;
212 __pPageMarker = null, "__pPageMarker->Construct failed with error %s", GetErrorMessage(r));
213 __pPageMarker->SetSelectedBubble(1);
214 __pPageMarker->SetPageMarkerEventListener(this);
215 r = AddControl(*__pPageMarker);
216 TryCatch(r == E_SUCCESS, delete __pPageMarker;
217 __pPageMarker = null, "AddControl failed");
219 pageRect = GetClientAreaBounds();
220 pageRect.y = markerRect.height;
222 pageRect.height -= markerRect.height;
224 __pPageControl = new (std::nothrow) CustomPageControl();
225 r = __pPageControl->Construct(pageRect, 1, pageRect.width);
226 TryCatch(r == E_SUCCESS, delete __pPageControl;
227 __pPageControl = null, "__pPageMarker->Construct failed with error %s", GetErrorMessage(r));
228 __pPageControl->SetMaxNumberOfIcons(MAX_ICONS_PER_PAGE);
229 __pPageControl->SetPageControlEventListener(this);
230 __pPageControl->SetPageControlItemProvider(this);
231 r = AddControl(*__pPageControl);
232 TryCatch(r == E_SUCCESS, delete __pPageControl;
233 __pPageControl = null, "AddControl failed");
239 if (__pPageControl != null)
241 delete __pPageControl;
242 __pPageControl = null;
245 if (__pPageMarker != null)
247 delete __pPageMarker;
248 __pPageMarker = null;
255 HomeForm::OnTerminating(void)
257 __pHomePresentationModel->UpdatePageData();
262 HomeForm::OnSettingChanged(String& key)
265 if (key.CompareTo(SETTINGS_KEY_WALLPAPER) == 0)
267 result r = E_SUCCESS;
268 String wallPaperPath;
270 r = SettingInfo::GetValue(SETTINGS_KEY_WALLPAPER, wallPaperPath);
272 if (!wallPaperPath.IsEmpty() && r == E_SUCCESS)
274 if (__pBackgroundBitmap != null)
276 delete __pBackgroundBitmap;
277 __pBackgroundBitmap = null;
280 __pBackgroundBitmap = ApplicationUtils::GetBitmapN(wallPaperPath);
282 if (__pBackgroundBitmap != null)
284 __pBackgroundLabel->SetBackgroundBitmap(*__pBackgroundBitmap);
285 __pBackgroundLabel->Invalidate(false);
289 else if (key.CompareTo(SETTINGS_KEY_LANGUAGE) == 0)
292 SettingInfo::GetValue(SETTINGS_KEY_LANGUAGE, selectedLang);
294 if (selectedLang.CompareTo(__currentLanguage) != 0)
296 __currentLanguage = selectedLang;
297 __isLanguageChanged = true;
298 __pHomePresentationModel->LanguageChanged();
300 if (UiApp::GetInstance()->GetAppUiState() != APP_UI_STATE_BACKGROUND)
302 ArrayList* pIconLists = null;
303 Label* pDoneLabel = static_cast<Label*>(__pSettingsPanel->GetControl(L"IDC_DONE_LABEL"));
305 if (pDoneLabel != null)
308 ApplicationUtils::GetStringResource(L"IDS_COM_POP_DONE", doneString);
309 pDoneLabel->SetText(doneString);
310 pDoneLabel->Invalidate(false);
313 pIconLists = __pPageControl->GetIconLists();
315 if (pIconLists != null)
317 for (int iconListCount = 0; iconListCount < pIconLists->GetCount(); iconListCount++)
319 IconListView* pIconListView = static_cast<IconListView*>(pIconLists->GetAt(iconListCount));
322 pIconListView->UpdateList();
335 HomeForm::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
337 if (source.GetName().CompareTo(L"IDC_SETTING_LABEL") == 0
338 || source.GetName().CompareTo(L"IDC_DONE_LABEL") == 0)
340 Label* pDoneLabel = null;
341 Label* pSettingLabel = null;
342 ControlAnimator* pDoneAnimator = null;
343 ControlAnimator* pSettingLabelAnimator = null;
344 Bitmap* pBitmap = null;
345 Point settingPosition(0, 0);
347 __isEditEnabled = !__isEditEnabled;
348 __pPageControl->ToggleEditMode();
349 pDoneLabel = static_cast<Label*>(__pSettingsPanel->GetControl(L"IDC_DONE_LABEL"));
350 pDoneAnimator = pDoneLabel->GetControlAnimator();
351 pDoneAnimator->SetShowState(__isEditEnabled);
352 pSettingLabel = static_cast<Label*>(__pSettingsPanel->GetControl(L"IDC_SETTING_LABEL"));
353 pSettingLabelAnimator = pSettingLabel->GetControlAnimator();
354 settingPosition = pSettingLabel->GetPosition();
358 settingPosition.x = 0;
362 settingPosition.x = X_SETTING_PANEL_PRESSED_OFFSET;
367 Canvas* pCanvas = null;
368 Rectangle settingRectangle = __pSettingsPanel->GetBounds();
370 int sizeOffset = SIZE_SETTING_LABEL_OFFSET;
372 if (__pSettingsPressedBitmap == null)
374 __pSettingsPressedBitmap = ApplicationUtils::GetResourceBitmapN(IDB_SETTING_BUTTON_PRESSED);
376 pBitmap = __pSettingsPressedBitmap;
378 settingRectangle.x = pointOffset;
379 settingRectangle.y = pointOffset;
380 settingRectangle.width -= sizeOffset;
381 settingRectangle.height -= sizeOffset;
383 pCanvas = __pSettingsPanel->GetCanvasN();
387 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
389 pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
390 pCanvas->SetLineWidth(1);
391 pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK));
392 pCanvas->DrawRectangle(settingRectangle);
393 pCanvas->SetForegroundColor(COLOR_SETTING_BOUNDARY_INNER);
395 pointOffset = sizeOffset;
396 sizeOffset = 2 * SIZE_SETTING_LABEL_OFFSET;
397 settingRectangle.x = pointOffset;
398 settingRectangle.y = pointOffset;
399 settingRectangle.width -= sizeOffset;
400 settingRectangle.height -= sizeOffset;
401 pCanvas->DrawRectangle(settingRectangle);
403 pointOffset = sizeOffset;
404 settingRectangle.x = pointOffset;
405 settingRectangle.y = pointOffset;
406 settingRectangle.width -= sizeOffset;
407 settingRectangle.height -= sizeOffset;
408 pCanvas->FillRectangle(Color::GetColor(COLOR_ID_BLACK), settingRectangle);
414 Canvas* pCanvas = null;
416 if (__pSettingsBitmap == null)
418 __pSettingsBitmap = ApplicationUtils::GetResourceBitmapN(IDB_SETTING_BUTTON_PRESSED);
421 pBitmap = __pSettingsBitmap;
422 pCanvas = __pSettingsPanel->GetCanvasN();
426 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
432 pSettingLabel->SetBackgroundBitmap(*pBitmap);
433 pSettingLabel->Invalidate(false);
434 pSettingLabelAnimator->SetPosition(settingPosition);
435 settingPosition.x += pSettingLabel->GetSize().width;
436 pDoneAnimator->SetPosition(settingPosition);
441 HomeForm::OnPageSwept(int pageNumber)
445 __pPageMarker->SetSelectedBubble(pageNumber);
452 HomeForm::OnPageAdded(int pageNumber)
454 // adds a new bubble and sets the newly added page as the current page
455 if (__pPageMarker != null)
457 __pPageMarker->AddBubble();
464 HomeForm::OnPageRemoved(int pageNumber)
466 if (__pPageMarker != null)
468 __pPageMarker->RemoveBubble(pageNumber);
475 HomeForm::OnMarkerBubbleMoved(int bubbleNumber)
477 if (bubbleNumber > 0)
479 __pPageMarker->SetSelectedBubble(bubbleNumber);
480 __pPageControl->SetPageSelected(bubbleNumber);
487 HomeForm::OnInstallationCompleted(const HomeItemInfo& pItemInfo)
489 ArrayList* pIconViews = null;
493 if (__pHomePresentationModel->GetPageCount() > __pPageControl->GetPageCount())
495 //__pPageControl->SetAppInfoList(__pDataModel->GetApplicationsList());
497 if (IsFailed(__pPageControl->AddPage()))
503 pIconViews = __pPageControl->GetIconLists();
505 if (pIconViews != null)
507 IconListView* pListView = null;
508 pItemInfo.GetPositionInHomeScreen(pageNumber, position);
509 pListView = static_cast<IconListView*>(pIconViews->GetAt(pageNumber - 1));
511 if (pListView != null)
513 pListView->UpdateList();
521 HomeForm::OnAppUninstallRequested(HomeItemInfo* pItemInfo)
523 if (__pProgressPanel != null)
525 __pProgressPanel->StartAnimation();
532 HomeForm::OnUnInstallationCompleted(const HomeItemInfo& pItemInfo)
534 if (__pHomePresentationModel != null)
538 IconListView* pIconList = null;
539 ArrayList* pIconLists = __pPageControl->GetIconLists();
541 if (__pProgressPanel != null)
543 __pProgressPanel->StopAnimation();
546 pItemInfo.GetPositionInHomeScreen(pageNumber, appIndex);
547 pIconList = static_cast<IconListView*>(pIconLists->GetAt(pageNumber - 1));
549 if (pIconList != null)
551 pIconList->UpdateList();
559 HomeForm::OnUpdatePageRequestedN(Tizen::Base::Collection::ArrayList* pPageList)
561 if (pPageList != null)
563 UpdatePage(pPageList);
564 pPageList->RemoveAll(true);
571 // from IPageControlItemProvider
573 HomeForm::GetPageCount(void)
577 if (__pHomePresentationModel != null)
579 pageCount = __pHomePresentationModel->GetPageCount();
585 HomeForm::GetItemCount(int pageNumber)
589 if (__pHomePresentationModel != null)
591 itemCount = __pHomePresentationModel->GetItemCount(pageNumber);
593 // if(itemCount == 0)
595 // if(pageNumber > 1)
597 // __pPageControl->MarkPageToDelete(pageNumber);
606 HomeForm::GetItem(int pageNumber, int index)
608 HomeItemInfo* itemInfo = null;
610 if (__pHomePresentationModel != null)
612 itemInfo = __pHomePresentationModel->GetItem(pageNumber, index);
619 HomeForm::RearrangeItems(HomeItemInfo* pMovedAppInfo, int newPageNumber, int newIndex)
621 __pHomePresentationModel->RearrangeItems(pMovedAppInfo, newPageNumber, newIndex);
626 HomeForm::UpdateAllPages(void)
628 if (__isLanguageChanged)
630 Label* pDoneLabel = static_cast<Label*>(__pSettingsPanel->GetControl(L"IDC_DONE_LABEL"));
632 if (pDoneLabel != null)
635 ApplicationUtils::GetStringResource(L"IDS_COM_POP_DONE", doneString);
636 pDoneLabel->SetText(doneString);
637 pDoneLabel->Invalidate(false);
640 if (__pPageControl != null)
642 ArrayList* pIconLists = __pPageControl->GetIconLists();
644 if (pIconLists != null)
646 for (int iconListCount = 0; iconListCount < pIconLists->GetCount(); iconListCount++)
648 IconListView* pIconListView = static_cast<IconListView*>(pIconLists->GetAt(iconListCount));
651 pIconListView->UpdateList();
657 __isLanguageChanged = false;