2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 MpSearchForm.cpp
19 * @brief This is the implementation file for SearchForm class.
22 #include "MpSearchForm.h"
24 using namespace Tizen::Base;
25 using namespace Tizen::Base::Collection;
26 using namespace Tizen::Content;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Media;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
33 static const int H_SEARCH_BAR = 86;
34 static const int H_GROUP_NAME = 80;
35 static const int X_GAP = 16;
36 static const int SEARCH_FONT_SIZE = 50;
37 static const Tizen::Graphics::Color COLOR_GROUP_NAME_BG (127, 127, 127);
38 static const Tizen::Graphics::Color COLOR_GROUP_TEXT (255, 255, 255);
40 SearchForm::SearchForm(void)
41 : __pSearchTableView(null)
43 , __pNoContentTextLabel(null)
50 SearchForm::~SearchForm(void)
57 SearchForm::Initialize(void)
60 Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
66 SearchForm::OnInitializing(void)
69 GetHeader()->SetTitleText(ResourceManager::GetString("IDS_COM_BODY_SEARCH"));
71 __pSearchBar = new (std::nothrow) SearchBar();
72 __pSearchBar->Construct(Rectangle(0, 0, GetClientAreaBounds().width, H_SEARCH_BAR));
73 __pSearchBar->SetGuideText(ResourceManager::GetString("IDS_COM_BODY_SEARCH"));
74 __pSearchBar->AddSearchBarEventListener(*this);
75 __pSearchBar->AddTextEventListener(*this);
76 __pSearchBar->AddKeypadEventListener(*this);
77 // __pSearchBar->SetLowerCaseModeEnabled(true);
79 __pSearchTableView = new (std::nothrow) TableView();
80 __pSearchTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height - __pSearchBar->GetHeight()),
82 TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
84 __pSearchTableView->SetItemProvider(this);
85 __pSearchTableView->AddTableViewItemEventListener(*this);
86 __pSearchTableView->AddTouchEventListener(*this);
87 __pSearchTableView->AddScrollEventListener(*this);
88 __pSearchBar->SetContent(__pSearchTableView);
90 GetFooter()->SetBackButton();
91 SetFormBackEventListener(this);
93 AddControl(__pSearchBar);
95 __pPresentationModel = SearchPresentationModel::GetInstance();
102 SearchForm::OnTerminating(void)
104 AppLogDebug("ENTER");
105 __pSearchTableView->Destroy();
111 SearchForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source,
112 Tizen::Ui::Controls::SearchBarMode mode)
114 AppLogDebug("ENTER");
115 __pPresentationModel->RemoveSearchResult();
117 if (__pSearchTableView != null)
119 __pSearchTableView->UpdateTableView();
120 __pSearchTableView->ScrollToItem(INIT_VALUE);
121 __pSearchTableView->Invalidate(true);
127 SearchForm::OnSearchBarContentAreaResized(Tizen::Ui::Controls::SearchBar& source,
130 AppLogDebug("ENTER");
135 SearchForm::OnTextValueChanged(const Tizen::Ui::Control& source)
137 AppLogDebug("ENTER");
138 if (__pSearchBar->GetText().GetLength() != INIT_VALUE)
140 __pPresentationModel->InitializeContentList(__pSearchBar->GetText());
144 __pPresentationModel->RemoveSearchResult();
147 if (__pSearchTableView != null)
149 __pSearchTableView->UpdateTableView();
150 __pSearchTableView->ScrollToItem(INIT_VALUE);
151 __pSearchTableView->Invalidate(true);
157 SearchForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
159 AppLogDebug("ENTER");
164 SearchForm::OnKeypadActionPerformed(Tizen::Ui::Control& source,
165 Tizen::Ui::KeypadAction keypadAction)
167 AppLogDebug("ENTER");
168 if (keypadAction == KEYPAD_ACTION_SEARCH)
170 __pSearchBar->HideKeypad();
172 if (__pSearchBar->GetTextLength() != INIT_VALUE)
174 __pPresentationModel->InitializeContentList(__pSearchBar->GetText());
178 __pPresentationModel->RemoveSearchResult();
180 if (__pSearchTableView != null)
182 __pSearchTableView->UpdateTableView();
183 __pSearchTableView->ScrollToItem(INIT_VALUE);
184 __pSearchTableView->Invalidate(true);
191 SearchForm::OnKeypadClosed(Tizen::Ui::Control& source)
193 AppLogDebug("ENTER");
194 GetFooter()->SetShowState(true);
195 Rectangle clientBounds = GetClientAreaBounds();
196 __pSearchTableView->SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height - __pSearchBar->GetHeight()));
198 if (__pNoContentTextLabel != null && __pNoContentTextLabel->GetShowState())
200 __pNoContentTextLabel->SetBounds(X_GAP,(clientBounds.height - H_NO_CONTENT)/2,GetWidth() - (X_GAP * 2),H_NO_CONTENT);
206 SearchForm::OnKeypadOpened(Tizen::Ui::Control& source)
208 AppLogDebug("ENTER");
209 Rectangle clientBounds = GetClientAreaBounds();
210 __pSearchTableView->SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height - __pSearchBar->GetHeight()));
212 if (__pNoContentTextLabel != null && __pNoContentTextLabel->GetShowState())
214 //Rectangle(X_GAP, Y_GAP_NO_CONTENT, GetWidth() - (X_GAP * 2), H_NO_CONTENT)
215 __pNoContentTextLabel->SetBounds(Rectangle(X_GAP,(clientBounds.height - H_NO_CONTENT)/2,GetWidth() - (X_GAP * 2),H_NO_CONTENT));
221 SearchForm::OnKeypadWillOpen(Tizen::Ui::Control &source)
223 AppLogDebug("ENTER");
224 // GetFooter()->SetShowState(false);
229 SearchForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
231 Rectangle clientBounds = GetClientAreaBounds();
232 __pSearchTableView->SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height - __pSearchBar->GetHeight()));
234 if (__pNoContentTextLabel != null && __pNoContentTextLabel->GetShowState())
236 //Rectangle(X_GAP, Y_GAP_NO_CONTENT, GetWidth() - (X_GAP * 2), H_NO_CONTENT)
237 __pNoContentTextLabel->SetBounds(Rectangle(X_GAP,(clientBounds.height - H_NO_CONTENT)/2,GetWidth() - (X_GAP * 2),H_NO_CONTENT));
242 SearchForm::GetItemCount(void)
244 AppLogDebug("ENTER");
245 int contentCount = __pPresentationModel->GetTotalContentCount();
247 if ( __pNoContentTextLabel != null)
249 if (contentCount == 0)
251 __pNoContentTextLabel->SetShowState(true);
255 __pNoContentTextLabel->SetShowState(false);
264 Tizen::Ui::Controls::TableViewItem*
265 SearchForm::CreateItem(const int itemIndex, int itemWidth)
267 AppLogDebug("ENTER");
268 Label* pDividerLabel;
269 bool addDivider = true;
270 RelativeLayout layout;
273 ContentInformation* pContentInfo = null;
274 TableViewItem* pItem = new (std::nothrow) TableViewItem();
276 result r = pItem->Construct(layout, Dimension(itemWidth, H_GROUP_NAME), TABLE_VIEW_ANNEX_STYLE_NORMAL);
277 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
279 if (__pPresentationModel->GetArtistIndex() == itemIndex)
281 r = CreateGroupNameTableViewItem(*pItem, ResourceManager::GetString(L"IDS_MUSIC_TAB4_ARTISTS"));
282 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
287 else if (__pPresentationModel->GetAlbumIndex() == itemIndex)
289 r = CreateGroupNameTableViewItem(*pItem, ResourceManager::GetString(L"IDS_MUSIC_BODY_ALBUMS"));
290 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
295 else if (__pPresentationModel->GetSongIndex() == itemIndex)
297 r = CreateGroupNameTableViewItem(*pItem, ResourceManager::GetString(L"IDS_MUSIC_HEADER_SONGS"));
298 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
308 pItem = new (std::nothrow) TableViewItem();
309 r = pItem->Construct(Dimension(itemWidth, ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_NORMAL);
310 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
312 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
313 TryCatch(pContentInfo != null, delete pItem, "pContentInfo is null", GetErrorMessage(GetLastResult()));
315 if (itemIndex < __pPresentationModel->GetAlbumIndex())
317 Label* pArtistNameLabel = new (std::nothrow) Label();
318 pArtistNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, 0, W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT), pContentInfo->ArtistName);
319 pArtistNameLabel->SetTextColor(COLOR_MAIN_TEXT);
320 pArtistNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
321 pArtistNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
322 pItem->AddControl(pArtistNameLabel);
324 if (itemIndex == __pPresentationModel->GetAlbumIndex()-1)
329 else if (itemIndex < __pPresentationModel->GetSongIndex())
331 Label* pAlbumNameLabel = new (std::nothrow) Label();
332 pAlbumNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, 0, W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT / 2), pContentInfo->AlbumName);
333 pAlbumNameLabel->SetTextColor(COLOR_MAIN_TEXT);
334 pAlbumNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
335 pAlbumNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
337 Label* pArtistNameLabel = new (std::nothrow) Label();
338 pArtistNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, pAlbumNameLabel->GetHeight(), W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT / 2), pContentInfo->ArtistName);
339 pArtistNameLabel->SetTextColor(COLOR_SUB_TEXT);
340 pArtistNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
341 pArtistNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
343 pItem->AddControl(pAlbumNameLabel);
344 pItem->AddControl(pArtistNameLabel);
346 if (itemIndex == __pPresentationModel->GetSongIndex()-1)
353 Label* pSongNameLabel = new (std::nothrow) Label();
354 pSongNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, 0, W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT), pContentInfo->TitleName);
355 pSongNameLabel->SetTextColor(COLOR_MAIN_TEXT);
356 pSongNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
357 pSongNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
359 pItem->AddControl(pSongNameLabel);
361 if (itemIndex == __pPresentationModel->GetTotalContentCount()-1)
370 pDividerLabel = new (std::nothrow) Label();
371 pDividerLabel->Construct(FloatRectangle(0, ITEM_HEIGHT-SEARCH_ITEM_DIVIDER_HEIGHT, W_CLIENT_AREA,SEARCH_ITEM_DIVIDER_HEIGHT ), L"");
372 pDividerLabel->SetBackgroundColor(__pSearchTableView->GetItemDividerColor());
373 pItem->AddControl(pDividerLabel);
380 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
385 SearchForm::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
387 AppLogDebug("ENTER");
396 SearchForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
398 AppLogDebug("ENTER");
403 SearchForm::GetDefaultItemHeight(void)
405 AppLogDebug("ENTER");
411 SearchForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
413 Tizen::Ui::Controls::TableViewItem* pItem,
414 Tizen::Ui::Controls::TableViewItemStatus status)
416 AppLogDebug("ENTER");
417 if (status != TABLE_VIEW_ITEM_STATUS_SELECTED)
422 if (itemIndex == __pPresentationModel->GetArtistIndex()
423 || itemIndex == __pPresentationModel->GetAlbumIndex()
424 || itemIndex == __pPresentationModel->GetSongIndex())
426 __pSearchBar->HideKeypad();
431 ContentInformation* pContentInfo;
432 SceneManager* pSceneManager = SceneManager::GetInstance();
433 AppAssert(pSceneManager);
435 if (itemIndex < __pPresentationModel->GetAlbumIndex())
437 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
439 ArrayList* pData = new (std::nothrow) ArrayList();
441 pData->Add(*(new (std::nothrow) String(IDSCN_ARTIST_LIST)));
442 pData->Add(*(new (std::nothrow) String(pContentInfo->ArtistName)));
444 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ARTIST_CONTENT_LIST), pData);
446 else if (itemIndex < __pPresentationModel->GetSongIndex())
448 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
450 ArrayList* pData = new (std::nothrow) ArrayList();
452 pData->Add(*(new (std::nothrow) String(IDSCN_SEARCH)));
453 pData->Add(*(new (std::nothrow) String(pContentInfo->AlbumName)));
454 pData->Add(*(new (std::nothrow) Integer(itemIndex)));
456 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_CONTENT_LIST), pData);
460 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
461 ArrayList* pPath = new (std::nothrow) ArrayList();
463 pPath->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
465 ArrayList* pData = new (std::nothrow) ArrayList();
467 pData->Add(*(new (std::nothrow) String(MUSIC)));
468 pData->Add(*(new (std::nothrow) Integer(0)));
469 pData->Add(*(pPath));
471 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER), pData);
480 SearchForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView,
482 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
485 AppLogDebug("ENTER");
490 SearchForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
494 AppLogDebug("ENTER");
499 SearchForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
500 const Tizen::Ui::Scenes::SceneId& currentSceneId,
501 Tizen::Base::Collection::IList* pArgs)
503 AppLogDebug("ENTER");
504 if (__pSceneId == null)
506 __pSceneId = new (std::nothrow) String(previousSceneId);
509 if (__pPresentationModel->GetTotalContentCount() == 0)
511 if (__pNoContentTextLabel == null)
513 __pNoContentTextLabel = new (std::nothrow) Label();
514 __pNoContentTextLabel->Construct(Rectangle(X_GAP, Y_GAP_NO_CONTENT, GetWidth() - (X_GAP * 2), H_NO_CONTENT),
515 ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
516 __pNoContentTextLabel->SetTextConfig(SEARCH_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
517 AddControl(__pNoContentTextLabel);
521 __pNoContentTextLabel->SetShowState(true);
526 pArgs->RemoveAll(true);
530 if (__pSearchBar->GetMode() != SEARCH_BAR_MODE_INPUT)
532 __pSearchBar->SetMode(SEARCH_BAR_MODE_INPUT);
539 if (__pNoContentTextLabel->GetShowState() == false)
542 __pNoContentTextLabel->SetShowState(false);
547 pArgs->RemoveAll(true);
554 SearchForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
555 const Tizen::Ui::Scenes::SceneId& nextSceneId)
557 AppLogDebug("ENTER");
559 if (__pSearchBar != null)
561 __pSearchBar->HideKeypad();
564 // __pPresentationModel->RemoveSearchResult();
565 // __pSearchTableView->UpdateTableView();
567 // if (__pSearchBar->GetKeypadAction() == true)
569 // __pSearchBar->HideKeypad();
572 // __pSearchBar->RemoveSearchBarEventListener(*this);
573 // __pSearchBar->RemoveKeypadEventListener(*this);
575 // __pSearchTableView->RemoveTableViewItemEventListener(*this);
576 // __pSearchTableView->RemoveTouchEventListener(*this);
577 // __pSearchTableView->RemoveScrollEventListener(*this);
582 SearchForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
584 AppLogDebug("ENTER");
585 SceneManager* pSceneManager = SceneManager::GetInstance();
586 AppAssert(pSceneManager);
587 AppLogDebug("OnActionPerformed : %d", actionId);
592 SearchForm::CreateGroupNameTableViewItem(Tizen::Ui::Container& parent, const Tizen::Base::String& GroupName)
594 AppLogDebug("ENTER");
595 result r = E_SUCCESS;
597 Label* pGroupNameLabel = new (std::nothrow) Label();
598 pGroupNameLabel->Construct(Rectangle(0, 0, W_CLIENT_AREA, H_GROUP_NAME), L"");
599 pGroupNameLabel->SetBackgroundColor(COLOR_GROUP_NAME_BG);
600 pGroupNameLabel->SetTextColor(COLOR_GROUP_TEXT);
601 pGroupNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
602 pGroupNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
603 pGroupNameLabel->SetText(GroupName);
605 parent.AddControl(pGroupNameLabel);
612 SearchForm::MakeQuery(const Tizen::Base::String& WhereExpr, const Tizen::Base::String& SearchName)
614 AppLogDebug("ENTER");
615 if (WhereExpr == null || SearchName == null)
620 String StrMakeQuery = WhereExpr;
622 StrMakeQuery.Append(L" like '%");
623 StrMakeQuery.Append(SearchName);
624 StrMakeQuery.Append(L"%'");
626 AppLogDebug("MakeQuery : %ls", StrMakeQuery.GetPointer());
632 SearchForm::OnTouchDoublePressed (const Tizen::Ui::Control& source,
633 const Tizen::Graphics::Point& currentPosition,
634 const Tizen::Ui::TouchEventInfo& touchInfo)
636 AppLogDebug("ENTER");
641 SearchForm::OnTouchFocusIn (const Tizen::Ui::Control& source,
642 const Tizen::Graphics::Point& currentPosition,
643 const Tizen::Ui::TouchEventInfo& touchInfo)
645 AppLogDebug("ENTER");
650 SearchForm::OnTouchFocusOut (const Tizen::Ui::Control& source,
651 const Tizen::Graphics::Point& currentPosition,
652 const Tizen::Ui::TouchEventInfo& touchInfo)
654 AppLogDebug("ENTER");
659 SearchForm::OnTouchLongPressed (const Tizen::Ui::Control& source,
660 const Tizen::Graphics::Point& currentPosition,
661 const Tizen::Ui::TouchEventInfo& touchInfo)
663 AppLogDebug("ENTER");
668 SearchForm::OnTouchMoved (const Tizen::Ui::Control& source,
669 const Tizen::Graphics::Point& currentPosition,
670 const Tizen::Ui::TouchEventInfo& touchInfo)
672 AppLogDebug("ENTER");
677 SearchForm::OnTouchPressed (const Tizen::Ui::Control& source,
678 const Tizen::Graphics::Point& currentPosition,
679 const Tizen::Ui::TouchEventInfo& touchInfo)
681 AppLogDebug("ENTER");
686 SearchForm::OnTouchReleased (const Tizen::Ui::Control& source,
687 const Tizen::Graphics::Point& currentPosition,
688 const Tizen::Ui::TouchEventInfo& touchInfo)
690 AppLogDebug("ENTER");
695 SearchForm::OnScrollEndReached (Tizen::Ui::Control& source, Tizen::Ui::Controls::ScrollEndEvent type)
697 AppLogDebug( "ENTER");
698 AppLogDebug( "EXIT");
702 SearchForm::OnScrollPositionChanged (Tizen::Ui::Control& source, int scrollPos)
704 AppLogDebug( "ENTER");
705 AppLogDebug( "EXIT");
709 SearchForm::OnScrollStopped (Tizen::Ui::Control& source)
711 AppLogDebug( "ENTER");
712 AppLogDebug( "EXIT");
716 SearchForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
718 AppLogDebug("ENTER");
719 __pPresentationModel->RemoveSearchResult();
720 SceneManager* pSceneManager = SceneManager::GetInstance();
721 AppAssert(pSceneManager);
723 __pSearchTableView->SetItemProvider(static_cast<ITableViewItemProvider*>(null));
724 pSceneManager->GoForward(ForwardSceneTransition(__pSceneId->GetPointer(), SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY));
729 SearchForm::OnMusicContentUpdateCompleted(void)
731 AppLogDebug("ENTER");
732 if (__pSearchBar->GetText().GetLength() != INIT_VALUE)
734 __pPresentationModel->InitializeContentList(__pSearchBar->GetText());
738 __pPresentationModel->RemoveSearchResult();
741 if (__pSearchTableView != null)
743 __pSearchTableView->UpdateTableView();
744 __pSearchTableView->ScrollToItem(INIT_VALUE);