From 0d79434937b93f0ef23c7401733d77d0236324b7 Mon Sep 17 00:00:00 2001 From: Woowon Date: Thu, 25 Oct 2012 18:03:22 +0900 Subject: [PATCH] Applied Scene manager on NfcMemoTag Change-Id: I95d7d606ee521f83c9d1dd036ffd43fe1f15432c --- project/inc/FormFactory.h | 34 +++++++++++++ project/inc/MainForm.h | 6 ++- project/inc/ReadForm.h | 9 ++++ project/inc/WriteForm.h | 1 - project/src/FormFactory.cpp | 67 ++++++++++++++++++++++++++ project/src/MainForm.cpp | 115 ++++++++++++++------------------------------ project/src/NfcMemoTag.cpp | 28 ++++++----- project/src/ReadForm.cpp | 53 ++++++++++++++++---- project/src/WriteForm.cpp | 47 ++++++------------ 9 files changed, 224 insertions(+), 136 deletions(-) create mode 100644 project/inc/FormFactory.h create mode 100644 project/src/FormFactory.cpp diff --git a/project/inc/FormFactory.h b/project/inc/FormFactory.h new file mode 100644 index 0000000..cb3e042 --- /dev/null +++ b/project/inc/FormFactory.h @@ -0,0 +1,34 @@ +// +// Tizen C++ SDK +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.tizenopensource.org/license +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef _FORM_FACTORY_H_ +#define _FORM_FACTORY_H_ + +#include + +class FormFactory: + public Osp::Ui::Scenes::IFormFactory +{ + +public: + FormFactory(); + virtual ~FormFactory(); + + virtual Osp::Ui::Controls::Form* CreateFormN(const Osp::Base::String &formId, const Osp::Ui::Scenes::SceneId &sceneId); +}; + +#endif // _FORM_FACTORY_H_ diff --git a/project/inc/MainForm.h b/project/inc/MainForm.h index 65a7b85..6f70b10 100644 --- a/project/inc/MainForm.h +++ b/project/inc/MainForm.h @@ -31,6 +31,7 @@ class MainForm , public Osp::Net::Nfc::INfcTagDiscoveryEventListener , public Osp::Net::Nfc::INdefMessageDiscoveryEventListener , public Osp::Net::Nfc::INdefTagConnectionListener + , public Osp::Ui::Scenes::ISceneEventListener { public: @@ -44,7 +45,6 @@ public: void LoadReadForm(Osp::Net::Nfc::NdefMessage* pMsg); void LoadWriteForm(void); virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId); - void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs); virtual void OnNfcActivated(result r); virtual void OnNfcDeactivated(result r); virtual void OnNfcTagDetectedN(Osp::Net::Nfc::TagConnection* pConnection); @@ -52,6 +52,10 @@ public: virtual void OnNdefMessageDetectedN(Osp::Net::Nfc::NdefMessage* pMessage); virtual void OnNdefReadCompletedN(Osp::Net::Nfc::NdefMessage* pMessage, result r); virtual void OnNdefWriteCompleted(result r); + virtual void OnSceneActivatedN(const Osp::Ui::Scenes::SceneId& previousSceneId, + const Osp::Ui::Scenes::SceneId& currentSceneId, Osp::Base::Collection::IList* pArgs); + virtual void OnSceneDeactivated(const Osp::Ui::Scenes::SceneId& currentSceneId, + const Osp::Ui::Scenes::SceneId& nextSceneId); void WriteData(Osp::Net::Nfc::NdefMessage* input); public: diff --git a/project/inc/ReadForm.h b/project/inc/ReadForm.h index ece8ead..a127225 100644 --- a/project/inc/ReadForm.h +++ b/project/inc/ReadForm.h @@ -27,6 +27,7 @@ class ReadForm : public Osp::Ui::Controls::Form , public Osp::Ui::Controls::IFormBackEventListener , public Osp::Ui::IActionEventListener + , public Osp::Ui::Scenes::ISceneEventListener { public: @@ -38,9 +39,17 @@ public: Osp::Base::String* GetTextPayloadN(const Osp::Base::ByteBuffer* data, Osp::Base::String ndefRecordName); virtual result OnInitializing(void); virtual result OnTerminating(void); + virtual void OnSceneActivatedN(const Osp::Ui::Scenes::SceneId& previousSceneId, + const Osp::Ui::Scenes::SceneId& currentSceneId, Osp::Base::Collection::IList* pArgs); + virtual void OnSceneDeactivated(const Osp::Ui::Scenes::SceneId& currentSceneId, + const Osp::Ui::Scenes::SceneId& nextSceneId); virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId); + virtual void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs); virtual void OnFormBackRequested(Osp::Ui::Controls::Form& source); +public: + static const RequestId REQUEST_UPDATE = 200; + private: Osp::Graphics::Bitmap* __pLeftItemBitmap; Osp::Graphics::Bitmap* __pRightItemBitmap; diff --git a/project/inc/WriteForm.h b/project/inc/WriteForm.h index 9a209e0..24e61c8 100644 --- a/project/inc/WriteForm.h +++ b/project/inc/WriteForm.h @@ -33,7 +33,6 @@ public: virtual ~WriteForm(void); bool Initialize(void); - void SetupControls(void); virtual result OnInitializing(void); virtual result OnTerminating(void); virtual void OnActionPerformed(const Control& source, int actionId); diff --git a/project/src/FormFactory.cpp b/project/src/FormFactory.cpp new file mode 100644 index 0000000..6149431 --- /dev/null +++ b/project/src/FormFactory.cpp @@ -0,0 +1,67 @@ +// +// Tizen C++ SDK +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.tizenopensource.org/license +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include +#include "FormFactory.h" +#include "MainForm.h" +#include "ReadForm.h" +#include "WriteForm.h" + +using namespace Osp::Ui::Controls; +using namespace Osp::Ui::Scenes; + +FormFactory::FormFactory() { + // TODO Auto-generated constructor stub + +} + +FormFactory::~FormFactory() { + // TODO Auto-generated destructor stub +} + +Form* +FormFactory::CreateFormN(const Osp::Base::String &formId, const Osp::Ui::Scenes::SceneId &sceneId) +{ + Form* pNewForm = null; + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + + if (formId == L"MainForm") + { + MainForm* pForm = new (std::nothrow) MainForm(); + pForm->Initialize(); + pSceneManager->AddSceneEventListener(sceneId, *pForm); + pNewForm = pForm; + } + else if (formId == L"ReadForm") + { + ReadForm* pForm = new (std::nothrow) ReadForm(); + pForm->Initialize(); + pSceneManager->AddSceneEventListener(sceneId, *pForm); + pNewForm = pForm; + } + else if (formId == L"WriteForm") + { + WriteForm* pForm = new (std::nothrow) WriteForm(); + pForm->Initialize(); + pNewForm = pForm; + } + + return pNewForm; +} + + diff --git a/project/src/MainForm.cpp b/project/src/MainForm.cpp index 4ce1295..bea0c1e 100644 --- a/project/src/MainForm.cpp +++ b/project/src/MainForm.cpp @@ -22,9 +22,11 @@ #include "MainForm.h" using namespace Osp::Base; +using namespace Osp::Base::Collection; using namespace Osp::Base::Utility; using namespace Osp::Ui; using namespace Osp::Ui::Controls; +using namespace Osp::Ui::Scenes; using namespace Osp::App; using namespace Osp::Net::Nfc; using namespace Osp::Graphics; @@ -165,41 +167,30 @@ MainForm::OnTerminating(void) void MainForm::LoadReadForm(NdefMessage* pMsg) { + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + ArrayList* pParams = null; + pParams = new (std::nothrow) ArrayList(); + pParams->Add(*pMsg); - Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); - - if (pFrame->GetCurrentForm() == __pReadForm) + if(pSceneManager->GetCurrentSceneId() != "ReadScene") { - AppLog("Removing old read form"); - pFrame->RemoveControl(*__pReadForm); - __pReadForm = null; + pSceneManager->GoForward(ForwardSceneTransition(L"ReadScene"), pParams); + } + else + { + Form* pReadForm = pSceneManager->GetCurrentScene()->GetForm(); + pReadForm->SendUserEvent(ReadForm::REQUEST_UPDATE, pParams); } - - __pReadForm = new (std::nothrow) ReadForm(); - __pReadForm->Initialize(); - pFrame->AddControl(*__pReadForm); - pFrame->SetCurrentForm(*__pReadForm); - pFrame->RequestRedraw(); - __pReadForm->SetupData(pMsg); - __pReadForm->UpdateRecord(); - pMsg->RemoveAllRecords(true); - delete pMsg; } void MainForm::LoadWriteForm() { + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); - __pWriteForm = new (std::nothrow) WriteForm(); - __pWriteForm->Initialize(); - // Add the form to the frame - - Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); - pFrame->AddControl(*__pWriteForm); - pFrame->SetCurrentForm(*__pWriteForm); - pFrame->RequestRedraw(); - __pWriteForm->SetupControls(); - + pSceneManager->GoForward(ForwardSceneTransition(L"WriteScene")); } void @@ -235,7 +226,6 @@ MainForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId) case ID_WRITE_MEMO: AppLog("Write Memo Button Clicked"); LoadWriteForm(); - break; case ID_READ_MEMO: @@ -262,55 +252,6 @@ MainForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId) } void -MainForm::OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs) -{ - Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); - Form* pFormLast = pFrame->GetCurrentForm(); - Form* pForm = null; - - switch (requestId) - { - case REQUEST_MAINFORM: - pForm = static_cast< Form* >(pFrame->GetControl("WriteForm")); - - if (pForm != null) - { - AppLog("There was write form open, so lets go there"); - } - else - { - pForm = this; - } - pFrame->SetCurrentForm(*pForm); - pForm->Draw(); - if (pFormLast != this) - pFrame->RemoveControl(*pFormLast); - - if (pFormLast == __pReadForm) - { - __pReadForm = null; - } - if (pFormLast == __pWriteForm) - { - __pWriteForm = null; - } - break; - - case REQUEST_WRITEDATA: - WriteData((NdefMessage*) pArgs->GetAt(0)); - pFrame->SetCurrentForm(*this); - Draw(); - if (pFormLast != this) - pFrame->RemoveControl(*pFormLast); - delete pArgs; - break; - - default: - break; - } -} - -void MainForm::OnNfcActivated(result r) { //indication from framework when NFC is activated with result of event. @@ -421,11 +362,8 @@ void MainForm::OnNdefMessageDetectedN(Osp::Net::Nfc::NdefMessage* pMessage) { //Indication from frame work for message received from Tag. - AppLog("Some message detected"); LoadReadForm(pMessage); - - } void @@ -445,7 +383,6 @@ MainForm::OnNdefReadCompletedN(Osp::Net::Nfc::NdefMessage* pMessage, result r) // Call ShowAndWait - draw, show itself and process events int modalResult = 0; messageBox.ShowAndWait(modalResult); - } } @@ -490,6 +427,24 @@ MainForm::OnNdefWriteCompleted(result r) } void +MainForm::OnSceneActivatedN(const Osp::Ui::Scenes::SceneId& previousSceneId, + const Osp::Ui::Scenes::SceneId& currentSceneId, Osp::Base::Collection::IList* pArgs) +{ + if(pArgs) + { + WriteData((NdefMessage*) pArgs->GetAt(0)); + delete pArgs; + } +} + +void +MainForm::OnSceneDeactivated(const Osp::Ui::Scenes::SceneId& currentSceneId, + const Osp::Ui::Scenes::SceneId& nextSceneId) +{ + +} + +void MainForm::WriteData(NdefMessage* pMsg) { if (__pNdefTagConnection == null) diff --git a/project/src/NfcMemoTag.cpp b/project/src/NfcMemoTag.cpp index 84d4045..8c37d53 100644 --- a/project/src/NfcMemoTag.cpp +++ b/project/src/NfcMemoTag.cpp @@ -18,12 +18,14 @@ #include #include "NfcMemoTag.h" #include "MainForm.h" +#include "FormFactory.h" using namespace Osp::App; using namespace Osp::Base; using namespace Osp::System; using namespace Osp::Ui; using namespace Osp::Ui::Controls; +using namespace Osp::Ui::Scenes; NfcMemoTag::NfcMemoTag() { @@ -54,19 +56,21 @@ NfcMemoTag::OnAppInitializing(AppRegistry& appRegistry) //PowerManager::SetScreenEventListener(*this); // Create a form - MainForm* pMainForm = new (std::nothrow) MainForm(); - pMainForm->Initialize(); - - // Add the form to the frame Frame* pFrame = GetAppFrame()->GetFrame(); - pFrame->AddControl(*pMainForm); - - // Set the current form - pFrame->SetCurrentForm(*pMainForm); - - // Draw and Show the form - pMainForm->Draw(); - + AddFrame(*pFrame); + + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + static FormFactory formFactory; + pSceneManager->RegisterFormFactory(formFactory); + pSceneManager->RegisterScene(L"MainScene", L"MainForm", L""); + pSceneManager->RegisterScene(L"ReadScene", L"ReadForm", L""); + pSceneManager->RegisterScene(L"WriteScene", L"WriteForm", L""); + + if (pSceneManager->GoForward(ForwardSceneTransition(L"MainScene")) != E_SUCCESS) + { + return false; + } return true; } diff --git a/project/src/ReadForm.cpp b/project/src/ReadForm.cpp index db42175..335c7f0 100644 --- a/project/src/ReadForm.cpp +++ b/project/src/ReadForm.cpp @@ -26,6 +26,7 @@ using namespace Osp::Base; using namespace Osp::Base::Utility; using namespace Osp::Ui; using namespace Osp::Ui::Controls; +using namespace Osp::Ui::Scenes; using namespace Osp::Graphics; using namespace Osp::Media; using namespace Osp::App; @@ -380,6 +381,25 @@ ReadForm::OnTerminating(void) } void +ReadForm::OnSceneActivatedN(const Osp::Ui::Scenes::SceneId& previousSceneId, + const Osp::Ui::Scenes::SceneId& currentSceneId, Osp::Base::Collection::IList* pArgs) +{ + SetupData((NdefMessage*) pArgs->GetAt(0)); + UpdateRecord(); + RequestRedraw(); + + pArgs->RemoveAll(true); + delete pArgs; +} + +void +ReadForm::OnSceneDeactivated(const Osp::Ui::Scenes::SceneId& currentSceneId, + const Osp::Ui::Scenes::SceneId& nextSceneId) +{ + +} + +void ReadForm::OnActionPerformed(const Control& source, int actionId) { switch (actionId) @@ -401,17 +421,30 @@ ReadForm::OnActionPerformed(const Control& source, int actionId) } void -ReadForm::OnFormBackRequested(Osp::Ui::Controls::Form& source) +ReadForm::OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs) { - Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); - MainForm* pMainFrm = static_cast< MainForm* >(pFrame->GetControl(L"MainForm")); - AppLog("Back Button Pressed"); - if (pMainFrm != null) - { - pMainFrm->SendUserEvent(MainForm::REQUEST_MAINFORM, null); - } - else + switch (requestId) { - AppLog("pMainFrm is null"); + case REQUEST_UPDATE: + + SetupData((NdefMessage*) pArgs->GetAt(0)); + UpdateRecord(); + RequestRedraw(); + + pArgs->RemoveAll(true); + delete pArgs; + break; + + default: + break; } } + +void +ReadForm::OnFormBackRequested(Osp::Ui::Controls::Form& source) +{ + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + + pSceneManager->GoBackward(BackwardSceneTransition()); +} diff --git a/project/src/WriteForm.cpp b/project/src/WriteForm.cpp index f46559c..42eb0bc 100644 --- a/project/src/WriteForm.cpp +++ b/project/src/WriteForm.cpp @@ -23,8 +23,10 @@ #include using namespace Osp::Base; +using namespace Osp::Base::Collection; using namespace Osp::Ui; using namespace Osp::Ui::Controls; +using namespace Osp::Ui::Scenes; using namespace Osp::App; using namespace Osp::Graphics; using namespace Osp::Text; @@ -48,13 +50,6 @@ WriteForm::Initialize(void) return true; } -void -WriteForm::SetupControls(void) -{ - __pPayloadField->SetFocus(); - __pPayloadField->ShowKeypad(); -} - result WriteForm::OnInitializing(void) { @@ -73,6 +68,8 @@ WriteForm::OnInitializing(void) r = __pPayloadField->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_RIGHT, L"Cancel", ID_WRITE_BACK); __pPayloadField->AddActionEventListener(*this); } + __pPayloadField->SetFocus(); + __pPayloadField->ShowKeypad(); return r; } @@ -89,36 +86,30 @@ WriteForm::OnTerminating(void) void WriteForm::OnFormBackRequested(Osp::Ui::Controls::Form& source) { - Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); - MainForm* pMainFrm = static_cast< MainForm* >(pFrame->GetControl(L"MainForm")); - AppLog("Back Button Pressed"); - if (pMainFrm != null) - { - pMainFrm->SendUserEvent(MainForm::REQUEST_MAINFORM, null); - } - else - { - AppLog("pMainFrm is null"); - } + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + + pSceneManager->GoBackward(BackwardSceneTransition()); } void WriteForm::OnActionPerformed(const Control& source, int actionId) { - Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); - MainForm* pMainFrm = static_cast< MainForm* >(pFrame->GetControl(L"MainForm")); + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + switch (actionId) { case ID_WRITE: if (__pPayloadField->GetTextLength() >= 0) { - Osp::Base::Collection::ArrayList* pParams; + ArrayList* pParams = null; AppLog("Write Button Pressed"); NdefMessage* pMsg = MakeTextRecordN(__pPayloadField->GetText()); - pParams = new (std::nothrow) Osp::Base::Collection::ArrayList(); + pParams = new (std::nothrow) ArrayList(); pParams->Add(*pMsg); - pMainFrm->SendUserEvent(MainForm::REQUEST_WRITEDATA, pParams); + pSceneManager->GoBackward(BackwardSceneTransition(), pParams); } else { @@ -128,15 +119,7 @@ WriteForm::OnActionPerformed(const Control& source, int actionId) break; case ID_WRITE_BACK: - AppLog("Back Button Pressed"); - if (pMainFrm != null) - { - pMainFrm->SendUserEvent(MainForm::REQUEST_MAINFORM, null); - } - else - { - AppLog("pMainFrm is null"); - } + pSceneManager->GoBackward(BackwardSceneTransition()); break; default: -- 2.7.4