From: Jinkun Jang Date: Tue, 12 Mar 2013 17:12:26 +0000 (+0900) Subject: Tizen 2.1 base X-Git-Tag: 2.1b_release~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d86390d1fe7f7ef5dca22b0c41affe5ede713441;p=samples%2Fnative%2FPushClient.git Tizen 2.1 base --- diff --git a/LICENSE.Flora b/LICENSE.Flora new file mode 100644 index 0000000..9c95663 --- /dev/null +++ b/LICENSE.Flora @@ -0,0 +1,206 @@ +Flora License + +Version 1.0, May, 2012 + +http://floralicense.org/license/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Compatibility Definition Document +and passes the Compatibility Test Suite as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. + +You may add Your own attribution notices within Derivative Works +that You distribute, alongside or as an addendum to the NOTICE text +from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of +the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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://floralicense.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. + diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..4b8882d --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Flora License, Version 1. +Please, see the LICENSE.Flora file for Flora License terms and conditions. + diff --git a/description.xml b/description.xml new file mode 100755 index 0000000..f82b3f8 --- /dev/null +++ b/description.xml @@ -0,0 +1,9 @@ + + + + + PushClient + 1.0 + screenshot.png + The PushClient sample application demonstrates how you can use the Tizen push messaging service. + diff --git a/project/data/nofile.dummy b/project/data/nofile.dummy new file mode 100644 index 0000000..e69de29 diff --git a/project/inc/FormFactory.h b/project/inc/FormFactory.h new file mode 100755 index 0000000..4732840 --- /dev/null +++ b/project/inc/FormFactory.h @@ -0,0 +1,31 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 Tizen::Ui::Scenes::IFormFactory +{ +public: + FormFactory(); + virtual ~FormFactory(); + virtual Tizen::Ui::Controls::Form* CreateFormN(const Tizen::Base::String &formId, const Tizen::Ui::Scenes::SceneId &sceneId); +}; + +#endif // _FORM_FACTORY_H_ diff --git a/project/inc/MainForm.h b/project/inc/MainForm.h new file mode 100755 index 0000000..79b0554 --- /dev/null +++ b/project/inc/MainForm.h @@ -0,0 +1,62 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 _MAIN_FORM_H_ +#define _MAIN_FORM_H_ + +#include +#include +#include +#include + +class MainForm + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::IActionEventListener + , public Tizen::Messaging::IPushManagerListener + , public Tizen::Messaging::IPushEventListener +{ +public: + MainForm(void); + ~MainForm(void); + bool Initialize(void); + + virtual result OnInitializing(void); + virtual result OnTerminating(void); + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + void OnPushServiceRegistered(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg); + void OnPushServiceUnregistered(RequestId reqId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg); + void OnPushMessageReceived(const Tizen::Messaging::PushMessage& message); + void EnablePush(void); + void DisablePush(void); + bool IsInitialized(void); + +private: + void ShowPushMessage(const Tizen::Messaging::PushMessage& message); + void ShowText(const Tizen::Base::String& text); + void CheckSetting(void); + +private: + Tizen::Ui::Controls::Frame* __pFrame; + Tizen::Ui::Controls::Button* __pCheckButton; + Tizen::Ui::Controls::Button* __pClearButton; + Tizen::Ui::Controls::EditArea* __pEditArea; + Tizen::Messaging::PushManager* __pPushManager; + int __index; + bool __isInitialized; +}; + +#endif // _MAIN_FORM_H_ diff --git a/project/inc/PushClient.h b/project/inc/PushClient.h new file mode 100755 index 0000000..df4ff19 --- /dev/null +++ b/project/inc/PushClient.h @@ -0,0 +1,78 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 _PUSH_CLIENT_H_ +#define _PUSH_CLIENT_H_ + +#include +#include +#include +#include +#include +#include "MainForm.h" +#include "SettingForm.h" + +// [PushClient] application must inherit from Application class +// which provides basic features necessary to define an application. +class PushClient + : public Tizen::App::Application + , public Tizen::System::IScreenEventListener + , public Tizen::App::IAppControlProviderEventListener +{ +public: + // [PushClient] application must have a factory method that creates an instance of itself. + static Tizen::App::Application* CreateInstance(void); + + PushClient(void); + ~PushClient(void); + + // Called when the application is initializing. + virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry); + + // Called when the application is terminating. + virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false); + + // Called when the application's frame moves to the top of the screen. + virtual void OnForeground(void); + + // Called when this application's frame is moved from top of the screen to the background. + virtual void OnBackground(void); + + // Called when the system memory is not sufficient to run the application any further. + virtual void OnLowMemory(void); + + // Called when the battery level changes. + virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel); + + // Called when the screen turns on. + virtual void OnScreenOn (void); + + // Called when the screen turns off. + virtual void OnScreenOff (void); + + // Called when the application control request is received from the caller application. + virtual void OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData); + + void EnablePush(void); + void DisablePush(void); + bool IsInitialized(void); + + MainForm* __pMainForm; + SettingForm* __pSettingForm; +}; + +#endif // _PUSH_CLIENT_H_ diff --git a/project/inc/SettingForm.h b/project/inc/SettingForm.h new file mode 100755 index 0000000..b677fdb --- /dev/null +++ b/project/inc/SettingForm.h @@ -0,0 +1,49 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 _SETTING_FORM_H_ +#define _SETTING_FORM_H_ + +#include +#include +#include +#include + +class SettingForm + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::IActionEventListener +{ +public: + SettingForm(void); + ~SettingForm(void); + + bool Initialize(void); + virtual result OnInitializing(void); + virtual result OnTerminating(void); + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + bool GetSetting(void); + void UpdateSetting(bool value); + +private: + void CheckRegistry(void); + void UpdateRegistry(bool value); + +private: + Tizen::Ui::Controls::CheckButton* __pSettingButton; +}; + +#endif // _SETTING_FORM_H_ diff --git a/project/manifest.xml b/project/manifest.xml new file mode 100755 index 0000000..55fb300 --- /dev/null +++ b/project/manifest.xml @@ -0,0 +1,33 @@ + + + 208dv19d5n + 1.0.0 + C++App + + + + + + 2.0 + + http://tizen.org/privilege/push + + + + $(projectName) + + + + + mainmenu.png + DisplayNames + + + On + On + Off + On + + + + diff --git a/project/packaging/nofile.dummy b/project/packaging/nofile.dummy new file mode 100644 index 0000000..e69de29 diff --git a/project/res/eng-GB.xml b/project/res/eng-GB.xml new file mode 100755 index 0000000..3cdd122 --- /dev/null +++ b/project/res/eng-GB.xml @@ -0,0 +1,5 @@ + + + diff --git a/project/shared/data/nofile.dummy b/project/shared/data/nofile.dummy new file mode 100644 index 0000000..e69de29 diff --git a/project/shared/res/screen-density-xhigh/mainmenu.png b/project/shared/res/screen-density-xhigh/mainmenu.png new file mode 100644 index 0000000..983c883 Binary files /dev/null and b/project/shared/res/screen-density-xhigh/mainmenu.png differ diff --git a/project/shared/trusted/nofile.dummy b/project/shared/trusted/nofile.dummy new file mode 100644 index 0000000..e69de29 diff --git a/project/src/FormFactory.cpp b/project/src/FormFactory.cpp new file mode 100755 index 0000000..7c96c6b --- /dev/null +++ b/project/src/FormFactory.cpp @@ -0,0 +1,53 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 "SettingForm.h" + +using namespace Tizen::Ui::Scenes; +using namespace Tizen::Ui::Controls; + +FormFactory::FormFactory() { + // TODO Auto-generated constructor stub +} + +FormFactory::~FormFactory() { + // TODO Auto-generated destructor stub +} + +Form* +FormFactory::CreateFormN(const Tizen::Base::String &formId, const Tizen::Ui::Scenes::SceneId &sceneId) +{ + Form* pNewForm = null; + + if (formId == L"MainForm") + { + MainForm* pForm = new (std::nothrow) MainForm(); + pForm->Initialize(); + pNewForm = pForm; + } + else if (formId == L"SettingForm") + { + SettingForm* pForm = new (std::nothrow) SettingForm(); + pForm->Initialize(); + pNewForm = pForm; + } + + return pNewForm; +} diff --git a/project/src/MainForm.cpp b/project/src/MainForm.cpp new file mode 100755 index 0000000..c2dfac5 --- /dev/null +++ b/project/src/MainForm.cpp @@ -0,0 +1,393 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 +#include +#include "FormFactory.h" +#include "MainForm.h" +#include "PushClient.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Graphics; +using namespace Tizen::Locales; +using namespace Tizen::Messaging; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Scenes; + +const int ID_FOOTER_SETTING = 100; +const int ID_BUTTON_CHECK = 101; +const int ID_BUTTON_CLEAR = 102; +const int TEXT_AREA_LENGTH = 2000; + +MainForm::MainForm(void) + : __pFrame(null) + , __pCheckButton(null) + , __pClearButton(null) + , __pEditArea(null) + , __pPushManager(null) + , __index(0) + , __isInitialized(false) +{ +} + +MainForm::~MainForm(void) +{ +} + +bool +MainForm::Initialize(void) +{ + Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER); + + return true; +} + +result +MainForm::OnInitializing(void) +{ + result r = E_SUCCESS; + __pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); + PushClient* pApp = static_cast(Application::GetInstance()); + + Rectangle clientRect = GetClientAreaBounds(); + + Header* pHeader = GetHeader(); + if (pHeader != null) + { + pHeader->SetStyle(HEADER_STYLE_TITLE); + pHeader->SetName(L"MainForm"); + pHeader->SetTitleText(L"PushClient - Main"); + } + + Footer* pFooter = GetFooter(); + if (pFooter != null) + { + pFooter->SetStyle(FOOTER_STYLE_TAB); + + FooterItem footerItem1; + footerItem1.Construct(ID_FOOTER_SETTING); + footerItem1.SetText(L"Setting"); + pFooter->AddItem(footerItem1); + pFooter->AddActionEventListener(*this); + } + + __pCheckButton = new (std::nothrow) Button(); + __pCheckButton->Construct(Rectangle(20, 20, 210, 74), L"Check"); + __pCheckButton->SetActionId(ID_BUTTON_CHECK); + __pCheckButton->AddActionEventListener(*this); + + __pClearButton = new (std::nothrow) Button(); + __pClearButton->Construct(Rectangle(250, 20, 210, 74), L"Clear"); + __pClearButton->SetActionId(ID_BUTTON_CLEAR); + __pClearButton->AddActionEventListener(*this); + + __pEditArea = new (std::nothrow) EditArea(); + __pEditArea->Construct(Rectangle(10, 110, clientRect.width-20, clientRect.height-120), INPUT_STYLE_FULLSCREEN, TEXT_AREA_LENGTH); + __pEditArea->SetKeypadEnabled(false); + + AddControl(*__pCheckButton); + AddControl(*__pClearButton); + AddControl(*__pEditArea); + + __pPushManager = new (std::nothrow) PushManager(); + r = __pPushManager->Construct(*this, *this); + + if (r == E_SUCCESS) + { + __isInitialized = true; + + if (true == pApp->__pSettingForm->GetSetting()) + { + EnablePush(); + } + else + { + DisablePush(); + } + + Draw(); + } + else + { + AppLog("####### PushManager Construct is failed with result[%s]. #######", GetErrorMessage(r)); + + __isInitialized = false; + + String text(L"Push Service is unavailable.\n"); + ShowText(text); + } + + return E_SUCCESS; +} + +result +MainForm::OnTerminating(void) +{ + result r = E_SUCCESS; + + if (__pPushManager != null) + { + delete __pPushManager; + } + + return r; +} + +void +MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ + AppLog("####### OnActionPerformed called with ActionId(%d)! #######", actionId); + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + + switch(actionId) + { + case ID_FOOTER_SETTING: + { + AppLog("####### Switch to SettingForm. #######"); + + pSceneManager->GoForward(ForwardSceneTransition(L"SettingScene")); + } + break; + case ID_BUTTON_CHECK: + { + AppLog("####### Check unread messages. #######"); + + IList* pUnreadMessges = null; + IEnumerator* pEnum = null; + PushMessage* pPushMessage = null; + pUnreadMessges = __pPushManager->GetUnreadMessagesN(); + + if (pUnreadMessges) + { + if (0 == pUnreadMessges->GetCount()) + { + AppLog("####### Unread message is NOT found. #######"); + } + else + { + AppLog("####### [%d] unread messages are found. #######", pUnreadMessges->GetCount()); + + pEnum = pUnreadMessges->GetEnumeratorN(); + while (E_OUT_OF_RANGE != pEnum->MoveNext()) + { + pPushMessage = static_cast(pEnum->GetCurrent()); + ShowPushMessage(*pPushMessage); + } + delete pEnum; + + pUnreadMessges->RemoveAll(true); + } + delete pUnreadMessges; + } + } + break; + case ID_BUTTON_CLEAR: + { + AppLog("####### Clear the screen. #######"); + + __pEditArea->Clear(); + Draw(); + } + break; + default: + break; + } +} + +void +MainForm::OnPushServiceRegistered(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg) +{ + AppLog("####### OnPushServiceRegistered! #######"); + PushClient* pApp = static_cast(Application::GetInstance()); + if (r == E_SUCCESS) + { + // The registrationId may change in some cases. + // If the registrationId changes, the application should send the registrationId to the application server. + AppLog("####### Push registration is successful. #######"); + AppLog("####### registrationId = %S #######", registrationId.GetPointer()); + + String text(L"OnRegistered: reqId="); + text.Append(reqId); + text.Append(L" registrationId="); + text.Append(registrationId); + text.Append(L"\n\n"); + ShowText(text); + } + else + { + AppLog("####### Push registration is failed with result[%s]. #######", GetErrorMessage(r)); + + String text(L"OnRegistered: ERROR reqId="); + text.Append(reqId); + text.Append(L" result="); + text.Append(GetErrorMessage(r)); + text.Append(L"\n\n"); + ShowText(text); + + pApp->__pSettingForm->UpdateSetting(false); + } +} + +void +MainForm::OnPushServiceUnregistered(RequestId reqId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg) +{ + AppLog("####### OnPushServiceUnregistered! #######"); + PushClient* pApp = static_cast(Application::GetInstance()); + if (r == E_SUCCESS) + { + // The application should remove the registrationId from the application server. + AppLog("####### Push unregistration is successful. #######"); + + String text(L"OnUnregistered: OK reqId="); + text.Append(reqId); + text.Append(L"\n\n"); + ShowText(text); + } + else + { + AppLog("####### Push unregistration is failed with result[%s]. #######", GetErrorMessage(r)); + + String text(L"OnUnregistered: ERROR reqId="); + text.Append(reqId); + text.Append(L" result="); + text.Append(GetErrorMessage(r)); + text.Append(L"\n\n"); + ShowText(text); + pApp->__pSettingForm->UpdateSetting(true); + } +} + +void +MainForm::OnPushMessageReceived(const Tizen::Messaging::PushMessage& message) +{ + AppLog("####### OnPushMessageReceived! #######"); + + ShowPushMessage(message); +} + +void +MainForm::EnablePush(void) +{ + result r = E_SUCCESS; + RequestId reqId = INVALID_REQUEST_ID; + PushClient* pApp = static_cast(Application::GetInstance()); + AppLog("####### Call RegisterPushService(). #######", reqId); + + r = __pPushManager->RegisterPushService(reqId); + + if (r == E_SUCCESS) + { + AppLog("####### RegisterPushService: reqId[%d] #######", reqId); + + String text(L"Register: reqId="); + text.Append(reqId); + text.Append(L"\n\n"); + ShowText(text); + } + else + { + AppLog("####### RegisterPushService is failed with result[%s]. #######", GetErrorMessage(r)); + + pApp->__pSettingForm->UpdateSetting(false); + } +} + +void +MainForm::DisablePush(void) +{ + result r = E_SUCCESS; + RequestId reqId; + PushClient* pApp = static_cast(Application::GetInstance()); + r = __pPushManager->UnregisterPushService(reqId); + + if (r == E_SUCCESS) + { + AppLog("####### UnregisterPushService: reqId[%d] #######", reqId); + + String text(L"Unregister: reqId="); + text.Append(reqId); + text.Append(L"\n\n"); + ShowText(text); + } + else + { + AppLog("####### UnregisterPushService is failed with result[%s]. #######", GetErrorMessage(r)); + pApp->__pSettingForm->UpdateSetting(true); + } +} + +bool +MainForm::IsInitialized(void) +{ + return __isInitialized; +} + +void +MainForm::ShowPushMessage(const Tizen::Messaging::PushMessage& message) +{ + AppLog("####### Show a push message. #######"); + + LocaleManager localeManager; + localeManager.Construct(); + TimeZone timeZone = localeManager.GetSystemTimeZone(); + DateTime receivedTime; + receivedTime = message.GetReceivedTime(); + DateTime wallTime; + wallTime = timeZone.UtcTimeToWallTime(receivedTime); + + String index(L"Index: "); + index.Append(__index++); + index.Append(L"\n"); + + String time(L"Time: "); + time.Append(wallTime.ToString()); + time.Append(L"\n"); + + String payload(L"Message: "); + payload.Append(message.GetNotification().GetAppMessage()); + payload.Append(L"\n\n"); + + String text; + text.Append(index); + text.Append(time); + text.Append(payload); + ShowText(text); +} + +void +MainForm::ShowText(const Tizen::Base::String& text) +{ + int addedLength = text.GetLength(); + + if (addedLength > __pEditArea->GetRemainingLength()) + { + String temp; + temp.SetCapacity(TEXT_AREA_LENGTH); + __pEditArea->GetText().SubString(addedLength - __pEditArea->GetRemainingLength(), temp); + __pEditArea->Clear(); + __pEditArea->SetText(temp); + } + + __pEditArea->AppendText(text); + + Draw(); + +} + diff --git a/project/src/PushClient.cpp b/project/src/PushClient.cpp new file mode 100755 index 0000000..6744efb --- /dev/null +++ b/project/src/PushClient.cpp @@ -0,0 +1,173 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 "FormFactory.h" +#include "PushClient.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::System; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Scenes; + +PushClient::PushClient(void) + : __pMainForm(null) + , __pSettingForm(null) +{ +} + +PushClient::~PushClient(void) +{ +} + +Application* +PushClient::CreateInstance(void) +{ + // Create the instance through the constructor. + return new (std::nothrow) PushClient(); +} + +bool +PushClient::OnAppInitializing(AppRegistry& appRegistry) +{ + Frame* pAppFrame = new (std::nothrow) Frame(); + pAppFrame->Construct(); + AddFrame(*pAppFrame); + + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + static FormFactory formFactory; + + pSceneManager->RegisterFormFactory(formFactory); + pSceneManager->RegisterScene(L"SettingScene", L"SettingForm", L""); + pSceneManager->RegisterScene(L"MainScene", L"MainForm", L""); + + if (pSceneManager->GoForward(ForwardSceneTransition(L"SettingScene")) != E_SUCCESS) + { + return false; + } + + Scene* pScene = pSceneManager->GetCurrentScene(); + __pSettingForm = (SettingForm*)pScene->GetForm(); + + if(pSceneManager->GoForward(ForwardSceneTransition(L"MainScene")) != E_SUCCESS) + { + return false; + } + + pScene = pSceneManager->GetCurrentScene(); + __pMainForm = (MainForm*)pScene->GetForm(); + + AppControlProviderManager* pAppControlProviderManager = AppControlProviderManager::GetInstance(); + if (pAppControlProviderManager == null) + { + return false; + } + + if (pAppControlProviderManager->SetAppControlProviderEventListener(this) != E_SUCCESS) + { + return false; + } + + return true; +} + +bool +PushClient::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) +{ + return true; +} + +void +PushClient::OnForeground(void) +{ +} + +void +PushClient::OnBackground(void) +{ +} + +void +PushClient::OnLowMemory(void) +{ +} + +void +PushClient::OnBatteryLevelChanged(BatteryLevel batteryLevel) +{ +} + +void +PushClient::OnScreenOn (void) +{ +} + +void +PushClient::OnScreenOff (void) +{ +} + +void +PushClient::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData, const String* pMimeType, const IMap* pExtraData) +{ + String appDataKey(L"http://tizen.org/appcontrol/data/push/appdata"); + + if (pExtraData == null) + { + return; + } + + IMapEnumerator* pMapEnum = pExtraData->GetMapEnumeratorN(); + String* pKey = null; + String* pValue = null; + + if (pMapEnum != null) + { + while ((pMapEnum->MoveNext() == E_SUCCESS)) + { + pKey = dynamic_cast(pMapEnum->GetKey()); + pValue = dynamic_cast(pMapEnum->GetValue()); + + if (pKey->Equals(appDataKey)) + { + AppLog("####### Launched with appData. [%ls] #######", pValue->GetPointer()); + break; + } + } + + delete pMapEnum; + } +} + +void +PushClient::EnablePush(void) +{ + __pMainForm->EnablePush(); +} + +void +PushClient::DisablePush(void) +{ + __pMainForm->DisablePush(); +} + +bool +PushClient::IsInitialized(void) +{ + return __pMainForm->IsInitialized(); +} diff --git a/project/src/PushClientEntry.cpp b/project/src/PushClientEntry.cpp new file mode 100755 index 0000000..a2ee94a --- /dev/null +++ b/project/src/PushClientEntry.cpp @@ -0,0 +1,59 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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. +// +/** + * This file contains the Tizen application entry point. + */ +#include "PushClient.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +_EXPORT_ int OspMain(int argc, char *pArgv[]); + +/** + * The entry function of Tizen application called by the operating system. + */ +int +OspMain(int argc, char *pArgv[]) +{ + result r = E_SUCCESS; + + AppLog("Application started."); + ArrayList args; + args.Construct(); + for (int i = 0; i < argc; i++) + { + args.Add(*(new (std::nothrow) String(pArgv[i]))); + } + + r = Tizen::App::Application::Execute(PushClient::CreateInstance, &args); + TryLog(!IsFailed(r), "Application execution failed-[%s].", GetErrorMessage(r)); + + + args.RemoveAll(true); + AppLog("Application finished."); + + return static_cast(r); +} +#ifdef __cplusplus +} +#endif // __cplusplus diff --git a/project/src/SettingForm.cpp b/project/src/SettingForm.cpp new file mode 100755 index 0000000..2b3d55d --- /dev/null +++ b/project/src/SettingForm.cpp @@ -0,0 +1,228 @@ +// +// Tizen Native SDK +// Copyright (c) 2012-2013 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://floralicense.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 +#include "SettingForm.h" +#include "PushClient.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Io; +using namespace Tizen::Graphics; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Scenes; + +const int ID_FOOTER_MAIN = 201; +const int ID_BUTTON_CHECKED = 202; +const int ID_BUTTON_UNCHECKED = 203; +const int ID_BUTTON_SELECTED = 204; + +#define PUSH_CLIENT_REGISTRY_FILE L"setting.ini" +#define PUSH_CLIENT_REGISTRY_SETTING_SECTION L"Setting" +#define PUSH_CLIENT_REGISTRY_USE_PUSH_ENTRY L"UsePush" + +SettingForm::SettingForm(void) + : __pSettingButton(null) +{ +} + +SettingForm::~SettingForm(void) +{ +} + +bool +SettingForm::Initialize(void) +{ + Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER); + + return true; +} + +result +SettingForm::OnInitializing(void) +{ + result r = E_SUCCESS; + + Header* pHeader = GetHeader(); + if (pHeader != null) + { + pHeader->SetStyle(HEADER_STYLE_TITLE); + pHeader->SetName(L"SettingForm"); + pHeader->SetTitleText(L"PushClient - Setting"); + } + + Footer* pFooter = GetFooter(); + if (pFooter != null) + { + pFooter->SetStyle(FOOTER_STYLE_TAB); + + FooterItem footerItem1; + footerItem1.Construct(ID_FOOTER_MAIN); + footerItem1.SetText(L"Main"); + pFooter->AddItem(footerItem1); + pFooter->AddActionEventListener(*this); + } + + __pSettingButton = new (std::nothrow) CheckButton(); + __pSettingButton->Construct(Rectangle(20, 20, 440, 100), CHECK_BUTTON_STYLE_ONOFF_SLIDING, BACKGROUND_STYLE_DEFAULT, false, L"Use Push Notification"); + __pSettingButton->SetActionId(ID_BUTTON_CHECKED, ID_BUTTON_UNCHECKED, ID_BUTTON_SELECTED); + __pSettingButton->AddActionEventListener(*this); + + AddControl(*__pSettingButton); + + CheckRegistry(); + + return r; +} + +result +SettingForm::OnTerminating(void) +{ + result r = E_SUCCESS; + + return r; +} + +void +SettingForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ + AppLog("####### OnActionPerformed called with ActionId(%d)! #######", actionId); + + switch(actionId) + { + case ID_FOOTER_MAIN: + { + AppLog("####### Switch to MainForm. #######"); + SceneManager* pSceneManager = SceneManager::GetInstance(); + pSceneManager->GoForward(ForwardSceneTransition(L"MainScene")); + } + break; + case ID_BUTTON_CHECKED: + { + AppLog("####### Enable push notification service. #######"); + + PushClient* pApp = static_cast(Application::GetInstance()); + if (pApp->IsInitialized()) + { + UpdateSetting(true); + pApp->EnablePush(); + } + } + break; + case ID_BUTTON_UNCHECKED: + { + AppLog("####### Disable push notification service. #######"); + + PushClient* pApp = static_cast(Application::GetInstance()); + if (pApp->IsInitialized()) + { + UpdateSetting(false); + pApp->DisablePush(); + } + } + break; + default: + break; + } +} + +bool +SettingForm::GetSetting(void) +{ + return __pSettingButton->IsSelected(); +} + +void +SettingForm::UpdateSetting(bool value) +{ + UpdateRegistry(value); + + __pSettingButton->SetSelected(value); + + Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame(); + if (this == pFrame->GetCurrentForm()) + { + pFrame->Draw(); + } +} + +void +SettingForm::CheckRegistry(void) +{ + result r = E_SUCCESS; + Registry reg; + String regFile(PUSH_CLIENT_REGISTRY_FILE); + String section(PUSH_CLIENT_REGISTRY_SETTING_SECTION); + String entry(PUSH_CLIENT_REGISTRY_USE_PUSH_ENTRY); + + if (File::IsFileExist(Tizen::App::App::GetInstance()->GetAppDataPath() + regFile)) + { + int value; + + r = reg.Construct(Tizen::App::App::GetInstance()->GetAppDataPath() + regFile, false); + if (r != E_SUCCESS) + { + AppLog("Failed to Io::Registry::Construct()"); + return; + } + + reg.GetValue(section, entry, value); + + if (value) + { + UpdateSetting(true); + } + else + { + UpdateSetting(false); + } + } + else + { + r = reg.Construct(Tizen::App::App::GetInstance()->GetAppDataPath() + regFile, true); + if (r != E_SUCCESS) + { + AppLog("Failed to Io::Registry::Construct()"); + return; + } + reg.AddSection(section); + reg.AddValue(section, entry, (int)true); + reg.Flush(); + + UpdateSetting(true); + } +} + +void +SettingForm::UpdateRegistry(bool value) +{ + result r = E_SUCCESS; + Registry reg; + String regFile(PUSH_CLIENT_REGISTRY_FILE); + String section(PUSH_CLIENT_REGISTRY_SETTING_SECTION); + String entry(PUSH_CLIENT_REGISTRY_USE_PUSH_ENTRY); + + r = reg.Construct(Tizen::App::App::GetInstance()->GetAppDataPath() + regFile, false); + if (r != E_SUCCESS) + { + AppLog("Failed to Io::Registry::Construct()"); + return; + } + reg.SetValue(section, entry, (int)value); + reg.Flush(); +} diff --git a/sample.xml b/sample.xml new file mode 100755 index 0000000..cd0abfb --- /dev/null +++ b/sample.xml @@ -0,0 +1,37 @@ + + diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..7a43a82 Binary files /dev/null and b/screenshot.png differ