--- /dev/null
+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.
+
--- /dev/null
+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.
+
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/xsl" href="../../../../description.xsl"?>
+
+<Overview version="0.17.1">
+ <SampleName> PushClient </SampleName>
+ <SampleVersion>1.0</SampleVersion>
+ <Preview>screenshot.png</Preview>
+ <Description>The PushClient sample application demonstrates how you can use the Tizen push messaging service.</Description>
+</Overview>
--- /dev/null
+//
+// 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 <FUiScenesIFormFactory.h>
+
+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_
--- /dev/null
+//
+// 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 <new>
+#include <FBase.h>
+#include <FMessaging.h>
+#include <FUi.h>
+
+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_
--- /dev/null
+//
+// 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 <new>
+#include <FApp.h>
+#include <FBase.h>
+#include <FSystem.h>
+#include <FUi.h>
+#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_
--- /dev/null
+//\r
+// Tizen Native SDK\r
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Flora License, Version 1.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://floralicense.org/license/\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an AS IS BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef _SETTING_FORM_H_\r
+#define _SETTING_FORM_H_\r
+\r
+#include <new>\r
+#include <FApp.h>\r
+#include <FBase.h>\r
+#include <FUi.h>\r
+\r
+class SettingForm\r
+ : public Tizen::Ui::Controls::Form\r
+ , public Tizen::Ui::IActionEventListener\r
+{\r
+public:\r
+ SettingForm(void);\r
+ ~SettingForm(void);\r
+\r
+ bool Initialize(void);\r
+ virtual result OnInitializing(void);\r
+ virtual result OnTerminating(void);\r
+ virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);\r
+ bool GetSetting(void);\r
+ void UpdateSetting(bool value);\r
+\r
+private:\r
+ void CheckRegistry(void);\r
+ void UpdateRegistry(bool value);\r
+\r
+private:\r
+ Tizen::Ui::Controls::CheckButton* __pSettingButton;\r
+};\r
+\r
+#endif // _SETTING_FORM_H_\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/12/manifest">
+ <Id>208dv19d5n</Id>
+ <Version>1.0.0</Version>
+ <Type>C++App</Type>
+ <Author/>
+ <Descriptions/>
+ <Url/>
+ <DeviceProfile/>
+ <Apps>
+ <ApiVersion>2.0</ApiVersion>
+ <Privileges>
+ <Privilege>http://tizen.org/privilege/push</Privilege>
+ </Privileges>
+ <UiApp Main="True" Name="$(projectName)" MenuIconVisible="True" >
+ <DisplayNames>
+ <DisplayName Locale="eng-GB">$(projectName)</DisplayName>
+ </DisplayNames>
+ <UiScalability CoordinateSystem="Logical" BaseScreenSize="Normal" LogicalCoordinate="480" />
+ <UiTheme SystemTheme="White"/>
+ <Icons>
+ <Icon Section="MainMenu" Type="Xhigh">mainmenu.png</Icon>
+ </Icons>DisplayNames
+ <LaunchConditions/>
+ <Notifications>
+ <Notification DisplayName="Ticker">On</Notification>
+ <Notification DisplayName="Sound">On</Notification>
+ <Notification DisplayName="Contents">Off</Notification>
+ <Notification DisplayName="Badge">On</Notification>
+ </Notifications>
+ </UiApp>
+ </Apps>
+</Manifest>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+<!--\r
+ This XML file was automatically generated by UiBuilder - do not modify by hand.\r
+-->\r
+<string_table Bversion="2.0.0.v20110223" Dversion="20100701"/>\r
--- /dev/null
+//
+// 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 <FUi.h>
+#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;
+}
--- /dev/null
+//
+// 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 <FApp.h>
+#include <FLocales.h>
+#include <FShell.h>
+#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<PushClient*>(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<PushMessage*>(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<PushClient*>(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<PushClient*>(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<PushClient*>(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<PushClient*>(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();
+
+}
+
--- /dev/null
+//
+// 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<String*>(pMapEnum->GetKey());
+ pValue = dynamic_cast<String*>(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();
+}
--- /dev/null
+//\r
+// Tizen Native SDK\r
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Flora License, Version 1.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://floralicense.org/license/\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an AS IS BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+/**\r
+ * This file contains the Tizen application entry point.\r
+ */\r
+#include "PushClient.h"\r
+\r
+using namespace Tizen::Base;\r
+using namespace Tizen::Base::Collection;\r
+\r
+#ifdef __cplusplus\r
+extern "C"\r
+{\r
+#endif // __cplusplus\r
+\r
+_EXPORT_ int OspMain(int argc, char *pArgv[]);\r
+\r
+/**\r
+ * The entry function of Tizen application called by the operating system.\r
+ */\r
+int\r
+OspMain(int argc, char *pArgv[])\r
+{\r
+ result r = E_SUCCESS;\r
+\r
+ AppLog("Application started.");\r
+ ArrayList args;\r
+ args.Construct();\r
+ for (int i = 0; i < argc; i++)\r
+ {\r
+ args.Add(*(new (std::nothrow) String(pArgv[i])));\r
+ }\r
+\r
+ r = Tizen::App::Application::Execute(PushClient::CreateInstance, &args);\r
+ TryLog(!IsFailed(r), "Application execution failed-[%s].", GetErrorMessage(r));\r
+\r
+\r
+ args.RemoveAll(true);\r
+ AppLog("Application finished.");\r
+\r
+ return static_cast<int>(r);\r
+}\r
+#ifdef __cplusplus\r
+}\r
+#endif // __cplusplus\r
--- /dev/null
+//
+// 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 <FIo.h>
+#include <FAppApp.h>
+#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<PushClient*>(Application::GetInstance());
+ if (pApp->IsInitialized())
+ {
+ UpdateSetting(true);
+ pApp->EnablePush();
+ }
+ }
+ break;
+ case ID_BUTTON_UNCHECKED:
+ {
+ AppLog("####### Disable push notification service. #######");
+
+ PushClient* pApp = static_cast<PushClient*>(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();
+}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<template>
+
+ <slp-property>
+ <property-group>
+ <sample-name>PushClient</sample-name>
+ <category>Sample</category>
+ <sdk-version>1.00</sdk-version>
+ <project-type>org.tizen.nativecpp.buildArtefactType.app</project-type>
+ <sample-description>description.xml</sample-description>
+ </property-group>
+ </slp-property>
+
+ <process type="org.tizen.nativeappcommon.TizenCopyFolder">
+ <simple name="projectName" value="$(projectName)"/>
+ <simple name="folderPath" value="project"/>
+ <complex-array name="replaceableFiles">
+ <element>
+ <simple name="sourcePath" value="manifest.xml"/>
+ <simple name="targetPath" value="manifest.xml"/>
+ <simple name="replaceable" value = "true"/>
+ </element>
+ </complex-array>
+ </process>
+ <process type="org.tizen.nativecpp.SetDefaultFrameworks">
+ <simple name="projectName" value="$(projectName)"/>
+ <complex-array name="frameworkList">
+ <element>
+ <simple name="framework" value="osp"/>
+ </element>
+ <element>
+ <simple name="framework" value="osp-compat"/>
+ </element>
+ </complex-array>
+ </process>
+
+</template>