From: Igor Olshevskyi Date: Thu, 2 Feb 2017 15:48:33 +0000 (+0200) Subject: TizenRefApp-7996 [MomentBar] Implement common WatchApp class X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_dev;p=profile%2Fwearable%2Fapps%2Fnative%2Findicator-win.git TizenRefApp-7996 [MomentBar] Implement common WatchApp class Change-Id: Ia1fbed8b9f51445db24902a0a72f24eb990d053e --- diff --git a/common/inc/appfw/WatchApp.h b/common/inc/appfw/WatchApp.h new file mode 100644 index 0000000..54afac8 --- /dev/null +++ b/common/inc/appfw/WatchApp.h @@ -0,0 +1,64 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (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 __MBAR_COMMON_WATCH_APP_H__ +#define __MBAR_COMMON_WATCH_APP_H__ + +#include + +#include "appfw/IInstanceContext.h" + +namespace com { + class IInstanceManager; + class IInstance; + + class WatchApp: + public IInstanceContext, + private NonCopyable { + public: + WatchApp(IInstanceManager &instanceMngr); + virtual ~WatchApp(); + + int run(int argc, char* argv[]); + + /* IInstanceContext */ + + AppType getAppType() const final; + void exitApp() const final; + Evas_Object *getWindow() const final; + void getWindowSize(int &w, int &h) const final; + + private: + bool onCreate(int w, int h); + void onTerminate(); + void onPause(); + void onResume(); + void onAppControl(app_control_h appControl); + void onTimeTick(watch_time_h watchTime); + void omAmbientTick(watch_time_h watchTime); + void omAmbientChanged(bool ambientMode); + + private: + IInstanceManager &m_instanceMngr; + IInstance *m_instance; + Evas_Object *m_window; + int m_winW; + int m_winH; + }; + +} + +#endif /* __MBAR_COMMON_WATCH_APP_H__ */ diff --git a/common/src/appfw/WatchApp.cpp b/common/src/appfw/WatchApp.cpp new file mode 100644 index 0000000..09c2d94 --- /dev/null +++ b/common/src/appfw/WatchApp.cpp @@ -0,0 +1,191 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (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 "appfw/WatchApp.h" + +#include +#include + +#include "appfw/IInstanceManager.h" +#include "appfw/IInstanceAppControlExt.h" +#include "appfw/IInstanceWatchExt.h" +#include "appfw/SystemEventProvider.h" +#include "../Debug.h" + +namespace com { + + namespace { + using CreateCb = CallbackAlt; + using TerminateCb = CallbackAlt; + using PauseCb = CallbackAlt; + using ResumeCb = CallbackAlt; + using AppControlCb = CallbackAlt; + using TimeTickCb = CallbackAlt; + using AmbientTickCb = CallbackAlt; + using AmbientChangedCb = CallbackAlt; + } + + WatchApp::WatchApp(IInstanceManager &instanceMngr): + m_instanceMngr(instanceMngr), + m_instance(nullptr), + m_window(nullptr), + m_winW(0), + m_winH(0) + { + } + + WatchApp::~WatchApp() + { + if (m_instance) + delete m_instance; + } + + int WatchApp::run(int argc, char* argv[]) + { + Variant varTemp; + const auto appParams = m_instanceMngr.getAppParams(); + + varTemp = appParams.get(AppParam::BASE_SCALE); + if (varTemp != Variant::Type::FLOAT) { + ELOG("Base scale does not set"); + } else { + elm_app_base_scale_set(varTemp.toFloat()); + } + + ISystemEventProviderUPtr eventProvider(new SystemEventProvider( + &watch_app_add_event_handler, + &watch_app_remove_event_handler)); + m_instanceMngr.setSystemEventProvider(std::move(eventProvider)); + + watch_app_lifecycle_callback_s wlcc = { 0, }; + wlcc.create = CreateCb::make(); + wlcc.terminate = TerminateCb::make(); + wlcc.pause = PauseCb::make(); + wlcc.resume = ResumeCb::make(); + wlcc.app_control = AppControlCb::make(); + wlcc.time_tick = TimeTickCb::make(); + wlcc.ambient_tick = AmbientTickCb::make(); + wlcc.ambient_changed = AmbientChangedCb::make(); + + int ret = watch_app_main(argc, argv, &wlcc, this); + if (ret != APP_ERROR_NONE) { + ELOG("watch_app_main() failed. ret[%d]", ret); + } + return ret; + } + + Evas_Object *WatchApp::getWindow() const + { + return m_window; + } + + void WatchApp::getWindowSize(int &w, int &h) const + { + w = m_winW; + h = m_winH; + } + + AppType WatchApp::getAppType() const + { + return AppType::WATCH; + } + + void WatchApp::exitApp() const + { + watch_app_exit(); + } + + bool WatchApp::onCreate(int w, int h) + { + int ret = watch_app_get_elm_win(&m_window); + RETVM_IF(ret != APP_ERROR_NONE || !m_window, false, + "watch_app_get_elm_win() failed. ret[%d]", ret); + + m_winW = w; + m_winH = h; + + m_instance = m_instanceMngr.createInstance(); + RETVM_IF(!m_instance, nullptr, "Create instance failed"); + + if (!m_instance->onCreate(this)) { + ELOG("Widget instance onCreate() failed"); + delete m_instance; + return false; + } + return true; + } + + void WatchApp::onTerminate() + { + if (m_instance) { + m_instance->onDestroy(); + } else { + ELOG("Instance is NULL"); + } + + delete m_instance; + m_instance = nullptr; + } + + void WatchApp::onPause() + { + RETM_IF(!m_instance, "Instance is NULL"); + m_instance->onPause(); + } + + void WatchApp::onResume() + { + RETM_IF(!m_instance, "Instance is NULL"); + m_instance->onResume(); + } + + void WatchApp::onAppControl(app_control_h appControl) + { + RETM_IF(!m_instance, "Instance is NULL"); + auto instance = dynamic_cast(m_instance); + if (instance) { + instance->onAppControl(appControl); + } + } + + void WatchApp::onTimeTick(watch_time_h watchTime) + { + RETM_IF(!m_instance, "Instance is NULL"); + auto instance = dynamic_cast(m_instance); + if (instance) { + instance->onTimeTick(watchTime); + } + } + + void WatchApp::omAmbientTick(watch_time_h watchTime) + { + RETM_IF(!m_instance, "Instance is NULL"); + auto instance = dynamic_cast(m_instance); + if (instance) { + instance->onAmbientTick(watchTime); + } + } + + void WatchApp::omAmbientChanged(bool ambientMode) + { + RETM_IF(!m_instance, "Instance is NULL"); + auto instance = dynamic_cast(m_instance); + if (instance) { + instance->onAmbientChanged(ambientMode); + } + } + +} /* namespace common */