3 // Copyright (c) 2012 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://www.tizenopensource.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.
18 #include "AppResourceId.h"
19 #include "FeatureManagerForm.h"
22 using namespace Tizen::App;
23 using namespace Tizen::Ui;
24 using namespace Tizen::Ui::Controls;
25 using namespace Tizen::Ui::Scenes;
26 using namespace Tizen::Base;
27 using namespace Tizen::Graphics;
29 FeatureManagerForm::FeatureManagerForm(void)
30 : __pIconListView(null)
35 FeatureManagerForm::~FeatureManagerForm(void)
40 FeatureManagerForm::Initialize(void)
42 Construct(FORM_STYLE_NORMAL| FORM_STYLE_HEADER| FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
44 SetFormBackEventListener(this);
50 FeatureManagerForm::OnInitializing(void)
52 Header* pHeader = GetHeader();
53 pHeader->SetTitleText(L"Delete Features");
54 if (!CreateMainList())
59 Footer* pFooter = GetFooter();
60 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
61 pFooter->SetBackButton();
63 FooterItem pFooterItemDelete;
64 pFooterItemDelete.Construct(ID_FOOTER_ITEM_DELETE);
65 pFooterItemDelete.SetText(L"Delete");
66 pFooter->AddItem(pFooterItemDelete);
67 pFooter->SetItemEnabled(0, false);
68 pFooter->AddActionEventListener(*this);
74 FeatureManagerForm::OnTerminating(void)
81 FeatureManagerForm::CreateMainList(void)
83 __pIconListView = new IconListView();
84 __pIconListView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
85 Dimension(GetClientAreaBounds().width - 100, 250), ICON_LIST_VIEW_STYLE_MARK, ICON_LIST_VIEW_SCROLL_DIRECTION_VERTICAL);
86 __pIconListView->SetItemProvider(*this);
87 __pIconListView->AddIconListViewItemEventListener(*this);
88 AddControl(*__pIconListView);
95 FeatureManagerForm::OnActionPerformed (const Tizen::Ui::Control &source, int actionId)
97 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
98 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
100 SceneManager* pSceneManager = SceneManager::GetInstance();
101 AppAssert(pSceneManager);
105 case ID_FOOTER_ITEM_DELETE:
107 for (int i = this->GetItemCount() - 1; i >= 0; i--)
109 if (__pIconListView->IsItemChecked(i))
111 pForm->GetFeatureManager()->DeleteFeature(i);
115 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT));
124 FeatureManagerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
126 SceneManager* pSceneManager = SceneManager::GetInstance();
127 AppAssert(pSceneManager);
128 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT));
133 FeatureManagerForm::GetItemCount(void)
135 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
136 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
140 if (pForm->GetFeatureManager())
142 return pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
150 FeatureManagerForm::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem* pItem)
157 Tizen::Ui::Controls::IconListViewItem*
158 FeatureManagerForm::CreateItem(int index)
160 IconListViewItem* pIconListViewItem = new IconListViewItem();
161 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
162 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
163 if (pForm->GetFeatureManager())
165 const Tizen::Uix::Vision::ImageFeatureInfo* pFeature = pForm->GetFeatureManager()->GetImageFeatureInfo(index);
166 if (pFeature == null)
168 return pIconListViewItem;
171 ByteBuffer* pByteBuffer = null;
172 pByteBuffer = pFeature->GetThumbnailN();
173 if (pByteBuffer == null)
177 int __thumbnailWidth = pFeature->GetThumbnailWidth();
178 int __thumbnailHeight = pFeature->GetThumbnailHeight();
179 unsigned char* ptr = const_cast<unsigned char*>(pByteBuffer->GetPointer());
180 unsigned char* end = ptr + __thumbnailWidth * __thumbnailHeight;
182 ByteBuffer imageBuffer;
183 imageBuffer.Construct(__thumbnailWidth * __thumbnailHeight * 4);
184 unsigned char* iptr = const_cast<unsigned char*>(imageBuffer.GetPointer());
186 for (;ptr < end; ++ptr)
194 Bitmap* pBitmap = new Bitmap();
195 pBitmap->Construct(imageBuffer, Dimension(__thumbnailWidth, __thumbnailHeight), BITMAP_PIXEL_FORMAT_R8G8B8A8);
197 //before this we should get name of the item
198 Tizen::Base::String name;
199 name.Format(80, L"%i: %ls", index, pFeature->GetDescription().GetPointer());
201 pIconListViewItem->Construct(*pBitmap, &name);
209 return pIconListViewItem;
213 FeatureManagerForm::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView &view, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
215 Footer* pFooter = GetFooter();
218 case ICON_LIST_VIEW_ITEM_CHECKED:
220 pFooter->SetItemEnabled(0, true);
224 case ICON_LIST_VIEW_ITEM_UNCHECKED:
226 pFooter->SetItemEnabled(0, false);
227 for (int i = this->GetItemCount() - 1; i >= 0; i--)
229 if (__pIconListView->IsItemChecked(i) && i != index)
231 pFooter->SetItemEnabled(0, true);
245 FeatureManagerForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
246 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
248 __pIconListView->ScrollToItem(0);
249 __pIconListView->UpdateList();
259 FeatureManagerForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
260 const Tizen::Ui::Scenes::SceneId& nextSceneId)