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.
19 #include "AppResourceId.h"
21 #include "FileManagerForm.h"
22 #include "GeneratePanel.h"
23 #include "UpdatePanel.h"
25 using namespace Tizen::Base;
26 using namespace Tizen::App;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Ui;
29 using namespace Tizen::Ui::Controls;
30 using namespace Tizen::Ui::Scenes;
32 static const String SAMPLE_TITLE = L"IMAGE FEATURE MANAGER";
34 MainForm::MainForm(void)
35 : __headerTitle(SAMPLE_TITLE)
36 , __pRadioGroupMode(null)
37 , __pFeatureManager(null)
38 , __pMessagePopup(null)
39 , __pMessageLabel(null)
43 MainForm::~MainForm(void)
45 if (__pFeatureManager)
47 delete __pFeatureManager;
49 delete __pMessagePopup;
53 MainForm::Initialize(void)
60 MainForm::OnInitializing(void)
64 SetFormBackEventListener(this);
66 CheckButton* pCheckButton = null;
68 __pRadioGroupMode = new RadioGroup();
69 __pRadioGroupMode->Construct();
71 pCheckButton = static_cast<CheckButton*>(GetControl(IDC_UPDATE_MODE_BUTTON, true));
74 pCheckButton->AddActionEventListener(*this);
75 pCheckButton->SetActionId(ID_BUTTON_UPDATE_MODE, 0, 0);
76 __pRadioGroupMode->Add(*pCheckButton);
79 pCheckButton = static_cast<CheckButton*>(GetControl(IDC_GENERATION_MODE_BUTTON, true));
83 pCheckButton->SetSelected(true);
84 pCheckButton->AddActionEventListener(*this);
85 pCheckButton->SetActionId(ID_BUTTON_GENERATE_MODE, 0, 0);
86 __pRadioGroupMode->Add(*pCheckButton);
89 Footer* pFooter = GetFooter();
90 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
91 pFooter->SetBackButton();
93 FooterItem pFooterItemSend;
94 pFooterItemSend.Construct(ID_FOOTER_ITEM_GENERATE);
95 pFooterItemSend.SetText(L"Generate");
96 pFooter->AddItem(pFooterItemSend);
97 pFooter->AddActionEventListener(*this);
100 __dbGen.SetListener(this);
102 __pFeatureManager = new Tizen::Uix::Vision::ImageFeatureManager();
103 __pFeatureManager->Construct();
105 __pMessagePopup = new Popup();
106 __pMessagePopup->Construct(IDC_MESSAGE_POPUP);
107 __pMessageLabel = static_cast<Label*>(__pMessagePopup->GetControl(IDC_LABEL_MASSEGE_TEXT, true));
109 __pContextMenu = new ContextMenu();
110 __pContextMenu->Construct(Point(50, 1200), CONTEXT_MENU_STYLE_LIST);
112 __pContextMenu->AddItem(L"Add Features", ID_CONTEXT_MENU_ADD);
113 __pContextMenu->AddItem(L"Delete Features", ID_CONTEXT_MENU_DELETE);
114 __pContextMenu->AddActionEventListener(*this);
116 Button* pButton = static_cast<Button*>(__pMessagePopup->GetControl(IDC_BUTTON_MESSAGE_CLOSE, true));
119 pButton->AddActionEventListener(*this);
120 pButton->SetActionId(ID_BUTTON_CLOSE_RESULTS);
127 MainForm::OnTerminating(void)
129 result r = E_SUCCESS;
134 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
136 SceneManager* pSceneManager = SceneManager::GetInstance();
137 AppAssert(pSceneManager);
141 case ID_BUTTON_GENERATE_MODE:
144 Footer* pFooter = GetFooter();
145 pFooter->RemoveAllItems();
146 pFooter->RemoveAllButtons();
149 FooterItem pFooterItemGenerate;
150 pFooterItemGenerate.Construct(ID_FOOTER_ITEM_GENERATE);
151 pFooterItemGenerate.SetText(L"Generate");
152 pFooter->AddItem(pFooterItemGenerate);
154 pFooter->SetBackButton();
155 pFooter->AddActionEventListener(*this);
157 __pFeatureManager->DeleteAllFeatures();
158 pSceneManager->GoForward(
159 ForwardSceneTransition("GenerationModeScene",
160 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
161 SCENE_HISTORY_OPTION_NO_HISTORY,
162 SCENE_DESTROY_OPTION_KEEP), null);
165 case ID_BUTTON_UPDATE_MODE:
167 Footer* pFooter = GetFooter();
168 pFooter->RemoveAllItems();
169 pFooter->RemoveAllButtons();
171 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
172 Tizen::Graphics::Bitmap* pNormalIcon = pAppResource->GetBitmapN(L"00_more_icon_normal.png");
173 Tizen::Graphics::Bitmap* pPressedIcon = pAppResource->GetBitmapN(L"00_more_icon_pressed.png");
174 Tizen::Graphics::Bitmap* pDisabledIcon = pAppResource->GetBitmapN(L"00_more_icon_disabled.png");
176 ButtonItem buttonItem;
177 buttonItem.Construct(BUTTON_ITEM_STYLE_ICON, ID_FOOTER_ITEM_SHOW_MENU);
178 buttonItem.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pNormalIcon);
179 buttonItem.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pPressedIcon);
180 buttonItem.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pDisabledIcon);
182 pFooter->SetButton(BUTTON_POSITION_LEFT, buttonItem);
184 FooterItem pFooterItemUpdate;
185 pFooterItemUpdate.Construct(ID_FOOTER_ITEM_UPDATE);
186 pFooterItemUpdate.SetText(L"Update");
187 pFooter->AddItem(pFooterItemUpdate);
189 pFooter->SetBackButton();
190 pFooter->AddActionEventListener(*this);
192 __pFeatureManager->DeleteAllFeatures();
193 pSceneManager->GoForward(
194 ForwardSceneTransition("UpdateModeScene",
195 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
196 SCENE_HISTORY_OPTION_NO_HISTORY,
197 SCENE_DESTROY_OPTION_KEEP), null);
200 case ID_BUTTON_CLOSE_RESULTS:
201 __pMessagePopup->SetShowState(false);
204 case ID_FOOTER_ITEM_GENERATE:
206 Panel* pPanel = static_cast<Panel*>(this->GetControl(IDC_GENERATION_MODE_PANEL, true));
209 pPanel->SendUserEvent(GeneratePanel::REQUEST_GENERATE_FEATURE_SET, null);
213 case ID_FOOTER_ITEM_UPDATE:
215 Panel* pPanel = static_cast<Panel*>(this->GetControl(IDC_UPDATE_MODE_PANEL, true));
218 pPanel->SendUserEvent(UpdatePanel::REQUEST_UPDATE, null);
222 case ID_FOOTER_ITEM_SHOW_MENU:
224 __pContextMenu->SetShowState(true);
225 __pContextMenu->Show();
228 case ID_CONTEXT_MENU_ADD:
230 Panel* pPanel = static_cast<Panel*>(this->GetControl(IDC_UPDATE_MODE_PANEL, true));
233 pPanel->SendUserEvent(UpdatePanel::REQUEST_ADD, null);
237 case ID_CONTEXT_MENU_DELETE:
239 Panel* pPanel = static_cast<Panel*>(this->GetControl(IDC_UPDATE_MODE_PANEL, true));
242 pPanel->SendUserEvent(UpdatePanel::REQUEST_DELETE, null);
252 MainForm::AppendImageFolder(const Tizen::Base::String& imPath, IFeatureSetGeneratorListener* listener)
254 if (listener != null)
256 __dbGen.SetListener(listener);
260 __dbGen.SetListener(this);
262 __dbGen.SetImagePath(imPath);
263 __dbGen.SetFeatureManager(__pFeatureManager);
264 this->SetEnabled(false);
269 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
271 UiApp* pApp = UiApp::GetInstance();
277 MainForm::OnSceneActivatedN(
278 const Tizen::Ui::Scenes::SceneId& previousSceneId,
279 const Tizen::Ui::Scenes::SceneId& currentSceneId,
280 Tizen::Base::Collection::IList* pArgs)
285 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
286 const Tizen::Ui::Scenes::SceneId& nextSceneId)
291 MainForm::OnImageProcessed(int imNo, int total)
294 SceneManager* pSceneManager = SceneManager::GetInstance();
295 AppAssert(pSceneManager);
297 if (pSceneManager->GetCurrentSceneId() == "GenerationModeScene")
299 __headerTitle = "Generating... ";
301 else if (pSceneManager->GetCurrentSceneId() == "UpdateModeScene")
303 __headerTitle = "Updating... ";
306 __headerTitle.Append(Integer(imNo).ToString());
307 __headerTitle.Append('/');
308 __headerTitle.Append(Integer(total).ToString());
313 MainForm::OnFinish(void)
315 SendUserEvent(REQUEST_RESULT, 0);
319 MainForm::OnDraw(void)
321 Header* pHeader = GetHeader();
322 pHeader->SetTitleText(__headerTitle);
327 MainForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
333 __dbGen.GetResults(__resInfo);
334 this->SetEnabled(true);
335 this->RequestRedraw(true);
336 __headerTitle = SAMPLE_TITLE;
337 if (__resInfo.appendTime > 0)
339 if (__resInfo.appendedObjectsNumber != 0)
341 __pMessageLabel->SetText(
342 "\nTotal time: " + Integer(__resInfo.appendTime).ToString() + "ms" +
343 "\nAverage time: " + Integer(__resInfo.appendTime / __resInfo.appendedObjectsNumber).ToString() + " ms" +
344 "\nAdded images: " + Integer(__resInfo.appendedObjectsNumber).ToString() +
345 "\nRejected files: " + Integer(__resInfo.rejectedObjectsNumber).ToString() +
346 "\nTotal files count: " + Integer(__resInfo.totalObjectsNumber).ToString()
351 __pMessageLabel->SetText(
352 "\nTotal time: " + Integer(__resInfo.appendTime).ToString() + "ms" +
353 "\nAdded images: " + Integer(__resInfo.appendedObjectsNumber).ToString() +
354 "\nRejected files: " + Integer(__resInfo.rejectedObjectsNumber).ToString() +
355 "\nTotal files count: " + Integer(__resInfo.totalObjectsNumber).ToString()
359 __pMessagePopup->SetShowState(true);
360 __pMessagePopup->Show();
369 Tizen::Uix::Vision::ImageFeatureManager*
370 MainForm::GetFeatureManager(void)
372 return __pFeatureManager;