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 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");
110 SearchForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source,
111 Tizen::Ui::Controls::SearchBarMode mode)
113 AppLogDebug("ENTER");
114 __pPresentationModel->RemoveSearchResult();
116 if (__pSearchTableView != null)
118 __pSearchTableView->UpdateTableView();
119 __pSearchTableView->ScrollToItem(INIT_VALUE);
120 __pSearchTableView->Invalidate(true);
126 SearchForm::OnSearchBarContentAreaResized(Tizen::Ui::Controls::SearchBar& source,
129 AppLogDebug("ENTER");
134 SearchForm::OnTextValueChanged(const Tizen::Ui::Control& source)
136 AppLogDebug("ENTER");
137 if (__pSearchBar->GetText().GetLength() != INIT_VALUE)
139 __pPresentationModel->InitializeContentList(__pSearchBar->GetText());
143 __pPresentationModel->RemoveSearchResult();
145 if (__pSearchTableView != null)
147 __pSearchTableView->UpdateTableView();
148 __pSearchTableView->ScrollToItem(INIT_VALUE);
149 __pSearchTableView->Invalidate(true);
155 SearchForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
157 AppLogDebug("ENTER");
162 SearchForm::OnKeypadActionPerformed(Tizen::Ui::Control& source,
163 Tizen::Ui::KeypadAction keypadAction)
165 AppLogDebug("ENTER");
166 if (keypadAction == KEYPAD_ACTION_SEARCH)
168 __pSearchBar->HideKeypad();
169 if (__pSearchBar->GetText().GetLength() != INIT_VALUE)
171 __pPresentationModel->InitializeContentList(__pSearchBar->GetText());
175 __pPresentationModel->RemoveSearchResult();
177 if (__pSearchTableView != null)
179 __pSearchTableView->UpdateTableView();
180 __pSearchTableView->ScrollToItem(INIT_VALUE);
181 __pSearchTableView->Invalidate(true);
188 SearchForm::OnKeypadClosed(Tizen::Ui::Control& source)
190 AppLogDebug("ENTER");
191 GetFooter()->SetShowState(true);
192 Rectangle clientBounds = GetClientAreaBounds();
193 __pSearchTableView->SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height - __pSearchBar->GetHeight()));
198 SearchForm::OnKeypadOpened(Tizen::Ui::Control& source)
200 AppLogDebug("ENTER");
201 Rectangle clientBounds = GetClientAreaBounds();
202 __pSearchTableView->SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height - __pSearchBar->GetHeight()));
207 SearchForm::OnKeypadWillOpen(Tizen::Ui::Control &source)
209 AppLogDebug("ENTER");
210 // GetFooter()->SetShowState(false);
215 SearchForm::GetItemCount(void)
217 AppLogDebug("ENTER");
218 int contentCount = __pPresentationModel->GetTotalContentCount();
220 if ( __pNoContentTextLabel != null)
222 if (contentCount == 0)
224 __pNoContentTextLabel->SetShowState(true);
228 __pNoContentTextLabel->SetShowState(false);
237 Tizen::Ui::Controls::TableViewItem*
238 SearchForm::CreateItem(const int itemIndex, int itemWidth)
240 AppLogDebug("ENTER");
241 RelativeLayout layout;
244 ContentInformation* pContentInfo = null;
245 TableViewItem* pItem = new (std::nothrow) TableViewItem();
247 result r = pItem->Construct(layout, Dimension(itemWidth, H_GROUP_NAME), TABLE_VIEW_ANNEX_STYLE_NORMAL);
248 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
250 if (__pPresentationModel->GetArtistIndex() == itemIndex)
252 r = CreateGroupNameTableViewItem(*pItem, ResourceManager::GetString(L"IDS_MUSIC_BODY_ARTISTS"));
253 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
258 else if (__pPresentationModel->GetAlbumIndex() == itemIndex)
260 r = CreateGroupNameTableViewItem(*pItem, ResourceManager::GetString(L"IDS_MUSIC_BODY_ALBUMS"));
261 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
266 else if (__pPresentationModel->GetSongIndex() == itemIndex)
268 r = CreateGroupNameTableViewItem(*pItem, ResourceManager::GetString(L"IDS_MUSIC_HEADER_SONGS"));
269 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
279 pItem = new (std::nothrow) TableViewItem();
280 r = pItem->Construct(Dimension(itemWidth, ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_NORMAL);
281 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
283 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
284 TryCatch(pContentInfo != null, delete pItem, "pContentInfo is null", GetErrorMessage(GetLastResult()));
286 if (itemIndex < __pPresentationModel->GetAlbumIndex())
288 Label* pArtistNameLabel = new (std::nothrow) Label();
289 pArtistNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, 0, W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT), pContentInfo->ArtistName);
290 pArtistNameLabel->SetTextColor(COLOR_MAIN_TEXT);
291 pArtistNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
292 pArtistNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
293 pItem->AddControl(*pArtistNameLabel);
295 else if (itemIndex < __pPresentationModel->GetSongIndex())
297 Label* pAlbumNameLabel = new (std::nothrow) Label();
298 pAlbumNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, 0, W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT / 2), pContentInfo->AlbumName);
299 pAlbumNameLabel->SetTextColor(COLOR_MAIN_TEXT);
300 pAlbumNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
301 pAlbumNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
303 Label* pArtistNameLabel = new (std::nothrow) Label();
304 pArtistNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, pAlbumNameLabel->GetHeight(), W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT / 2), pContentInfo->ArtistName);
305 pArtistNameLabel->SetTextColor(COLOR_SUB_TEXT);
306 pArtistNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
307 pArtistNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
309 pItem->AddControl(*pAlbumNameLabel);
310 pItem->AddControl(*pArtistNameLabel);
314 Label* pSongNameLabel = new (std::nothrow) Label();
315 pSongNameLabel->Construct(Rectangle(X_GAP_THUMBNAIL, 0, W_CLIENT_AREA - X_GAP_THUMBNAIL, ITEM_HEIGHT), pContentInfo->TitleName);
316 pSongNameLabel->SetTextColor(COLOR_MAIN_TEXT);
317 pSongNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
318 pSongNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
320 pItem->AddControl(*pSongNameLabel);
328 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
334 SearchForm::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
336 AppLogDebug("ENTER");
345 SearchForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
347 AppLogDebug("ENTER");
352 SearchForm::GetDefaultItemHeight(void)
354 AppLogDebug("ENTER");
360 SearchForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
362 Tizen::Ui::Controls::TableViewItem* pItem,
363 Tizen::Ui::Controls::TableViewItemStatus status)
365 AppLogDebug("ENTER");
366 if (status != TABLE_VIEW_ITEM_STATUS_SELECTED)
371 if (itemIndex == __pPresentationModel->GetArtistIndex()
372 || itemIndex == __pPresentationModel->GetAlbumIndex()
373 || itemIndex == __pPresentationModel->GetSongIndex())
375 __pSearchBar->HideKeypad();
380 ContentInformation* pContentInfo;
381 SceneManager* pSceneManager = SceneManager::GetInstance();
382 AppAssert(pSceneManager);
384 if (itemIndex < __pPresentationModel->GetAlbumIndex())
386 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
388 ArrayList* pData = new (std::nothrow) ArrayList();
390 pData->Add(*(new (std::nothrow) String(IDSCN_ARTIST_LIST)));
391 pData->Add(*(new (std::nothrow) String(pContentInfo->ArtistName)));
393 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ARTIST_CONTENT_LIST), pData);
395 else if (itemIndex < __pPresentationModel->GetSongIndex())
397 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
399 ArrayList* pData = new (std::nothrow) ArrayList();
401 pData->Add(*(new (std::nothrow) String(IDSCN_SEARCH)));
402 pData->Add(*(new (std::nothrow) String(pContentInfo->AlbumName)));
403 pData->Add(*(new (std::nothrow) Integer(itemIndex)));
405 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_CONTENT_LIST), pData);
409 pContentInfo = __pPresentationModel->GetContentInfoN(itemIndex);
410 ArrayList* pPath = new (std::nothrow) ArrayList();
412 pPath->Add(*(new (std::nothrow) String(pContentInfo->ContentFilePath)));
414 ArrayList* pData = new (std::nothrow) ArrayList();
416 pData->Add(*(new (std::nothrow) String(MUSIC)));
417 pData->Add(*(new (std::nothrow) Integer(0)));
418 pData->Add(*(pPath));
420 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER), pData);
429 SearchForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView,
431 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
434 AppLogDebug("ENTER");
439 SearchForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
443 AppLogDebug("ENTER");
448 SearchForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
449 const Tizen::Ui::Scenes::SceneId& currentSceneId,
450 Tizen::Base::Collection::IList* pArgs)
452 AppLogDebug("ENTER");
453 if (__pSceneId == null)
455 __pSceneId = new (std::nothrow) String(previousSceneId);
458 if (__pPresentationModel->GetTotalContentCount() == 0)
460 if (__pNoContentTextLabel == null)
462 __pNoContentTextLabel = new (std::nothrow) Label();
463 __pNoContentTextLabel->Construct(Rectangle(X_GAP, Y_GAP_NO_CONTENT, GetWidth() - (X_GAP * 2), H_NO_CONTENT),
464 ResourceManager::GetString(L"IDS_COM_BODY_NO_ITEMS"));
465 __pNoContentTextLabel->SetTextConfig(SEARCH_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
466 AddControl(*__pNoContentTextLabel);
470 __pNoContentTextLabel->SetShowState(true);
475 pArgs->RemoveAll(true);
479 if (__pSearchBar->GetMode() != SEARCH_BAR_MODE_INPUT)
481 __pSearchBar->SetMode(SEARCH_BAR_MODE_INPUT);
488 if (__pNoContentTextLabel->GetShowState() == false)
491 __pNoContentTextLabel->SetShowState(false);
496 pArgs->RemoveAll(true);
503 SearchForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
504 const Tizen::Ui::Scenes::SceneId& nextSceneId)
506 AppLogDebug("ENTER");
507 /* if (__pSearchBar != null)
509 __pSearchBar->HideKeypad();
512 __pPresentationModel->RemoveSearchResult();
513 __pSearchTableView->UpdateTableView();
515 // if (__pSearchBar->GetKeypadAction() == true)
517 // __pSearchBar->HideKeypad();
520 // __pSearchBar->RemoveSearchBarEventListener(*this);
521 // __pSearchBar->RemoveKeypadEventListener(*this);
523 // __pSearchTableView->RemoveTableViewItemEventListener(*this);
524 // __pSearchTableView->RemoveTouchEventListener(*this);
525 // __pSearchTableView->RemoveScrollEventListener(*this);
530 SearchForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
532 AppLogDebug("ENTER");
533 SceneManager* pSceneManager = SceneManager::GetInstance();
534 AppAssert(pSceneManager);
535 AppLogDebug("OnActionPerformed : %d", actionId);
540 SearchForm::CreateGroupNameTableViewItem(Tizen::Ui::Container& parent, const Tizen::Base::String& GroupName)
542 AppLogDebug("ENTER");
543 result r = E_SUCCESS;
545 Label* pGroupNameLabel = new (std::nothrow) Label();
546 pGroupNameLabel->Construct(Rectangle(0, 0, W_CLIENT_AREA, H_GROUP_NAME), L"");
547 pGroupNameLabel->SetBackgroundColor(COLOR_GROUP_NAME_BG);
548 pGroupNameLabel->SetTextColor(COLOR_GROUP_TEXT);
549 pGroupNameLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
550 pGroupNameLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
551 pGroupNameLabel->SetText(GroupName);
553 parent.AddControl(*pGroupNameLabel);
560 SearchForm::MakeQuery(const Tizen::Base::String& WhereExpr, const Tizen::Base::String& SearchName)
562 AppLogDebug("ENTER");
563 if (WhereExpr == null || SearchName == null)
568 String StrMakeQuery = WhereExpr;
570 StrMakeQuery.Append(L" like '%");
571 StrMakeQuery.Append(SearchName);
572 StrMakeQuery.Append(L"%'");
574 AppLogDebug("MakeQuery : %ls", StrMakeQuery.GetPointer());
580 SearchForm::OnTouchDoublePressed (const Tizen::Ui::Control& source,
581 const Tizen::Graphics::Point& currentPosition,
582 const Tizen::Ui::TouchEventInfo& touchInfo)
584 AppLogDebug("ENTER");
589 SearchForm::OnTouchFocusIn (const Tizen::Ui::Control& source,
590 const Tizen::Graphics::Point& currentPosition,
591 const Tizen::Ui::TouchEventInfo& touchInfo)
593 AppLogDebug("ENTER");
598 SearchForm::OnTouchFocusOut (const Tizen::Ui::Control& source,
599 const Tizen::Graphics::Point& currentPosition,
600 const Tizen::Ui::TouchEventInfo& touchInfo)
602 AppLogDebug("ENTER");
607 SearchForm::OnTouchLongPressed (const Tizen::Ui::Control& source,
608 const Tizen::Graphics::Point& currentPosition,
609 const Tizen::Ui::TouchEventInfo& touchInfo)
611 AppLogDebug("ENTER");
616 SearchForm::OnTouchMoved (const Tizen::Ui::Control& source,
617 const Tizen::Graphics::Point& currentPosition,
618 const Tizen::Ui::TouchEventInfo& touchInfo)
620 AppLogDebug("ENTER");
625 SearchForm::OnTouchPressed (const Tizen::Ui::Control& source,
626 const Tizen::Graphics::Point& currentPosition,
627 const Tizen::Ui::TouchEventInfo& touchInfo)
629 AppLogDebug("ENTER");
634 SearchForm::OnTouchReleased (const Tizen::Ui::Control& source,
635 const Tizen::Graphics::Point& currentPosition,
636 const Tizen::Ui::TouchEventInfo& touchInfo)
638 AppLogDebug("ENTER");
643 SearchForm::OnScrollEndReached (Tizen::Ui::Control& source, Tizen::Ui::Controls::ScrollEndEvent type)
645 AppLogDebug( "ENTER");
646 AppLogDebug( "EXIT");
650 SearchForm::OnScrollPositionChanged (Tizen::Ui::Control& source, int scrollPos)
652 AppLogDebug( "ENTER");
653 AppLogDebug( "EXIT");
657 SearchForm::OnScrollStopped (Tizen::Ui::Control& source)
659 AppLogDebug( "ENTER");
660 AppLogDebug( "EXIT");
664 SearchForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
666 AppLogDebug("ENTER");
667 __pPresentationModel->RemoveSearchResult();
668 SceneManager* pSceneManager = SceneManager::GetInstance();
669 AppAssert(pSceneManager);
671 pSceneManager->GoForward(ForwardSceneTransition(__pSceneId->GetPointer(), SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY));