Showing popup when accessory was disconnected 25/144725/8
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Thu, 17 Aug 2017 08:38:23 +0000 (10:38 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 22 Aug 2017 09:55:09 +0000 (11:55 +0200)
If exists mapping between accessory and switch popup message
with proper statement is being shown.

Change-Id: I8ae3dc3f80703793898c301e9829900ab7b0f069

res/po/en_US.po
src/AccessoriesSwitchProvider.cpp
src/AccessoriesSwitchProvider.hpp
src/CompositeSwitchProvider.cpp
src/CompositeSwitchProvider.hpp
src/SwitchManager.cpp
src/SwitchManager.hpp
src/SwitchProvider.hpp

index 571a7dc5d5deaa61162cd1f9b71d834ddf2ab613..d6a17d9c05bc5bf7e53816f88f1ae996b587271f 100644 (file)
@@ -399,6 +399,11 @@ msgstr "Camera"
 msgid "IDS_SWITCH_PROVIDER_DESCRIPTION_CameraSwitchProvider"
 msgstr "Set your device to detect the movement of your head, eyes, and mouth."
 
+msgid "IDS_SWITCH_PROVIDER_AccessoryDisconnected_Header"
+msgstr "Accessory disconnected"
+
+msgid "IDS_SWITCH_PROVIDER_AccessoryDisconnected_Content"
+msgstr "Check your accessory connection. If you want to stop using Universal switch, press the Power key and the Volume up key at the same time."
 
 # SWITCHES - CameraSwitchProvider
 
@@ -422,4 +427,3 @@ msgstr "Turn head left"
 
 msgid "IDS_SWITCH_NAME_CameraSwitchProvider_turnHeadRight"
 msgstr "Turn head right"
-
index ef877b15b763a6ab84630fb0417c0ad55280b247..8041dc2794089aed18293aeac5668fd3fee0fb18 100644 (file)
@@ -680,6 +680,12 @@ AccessoriesSwitchProvider::AccessoriesSwitchProvider()
 
        keyDownHandler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, keyDownCb, this);
        keyUpHandler = ecore_event_handler_add(ECORE_EVENT_KEY_UP, keyUpCb, this);
+
+       // Due to platform restrictions, vconf key used below is being set to 'true' only if hardware keyboard (either usb or bluetooth) started to input data
+       onDisconnectionHandler = VConfSingleton::instance().registerKeyChangedCb<bool>("memory/isf/hw_keyboard_input_detected", [this](bool x) {
+               if (!x)
+                       notify(shared_from_this());
+       });
 }
 
 AccessoriesSwitchProvider::~AccessoriesSwitchProvider()
index f6233e8cb85b81399697102e9f448985b0b974e7..8cbb45c8405cf28d9e0c007447707ba50a398be3 100644 (file)
@@ -10,7 +10,7 @@
 #include <string>
 #include <memory>
 
-class AccessoriesSwitchProvider : public SwitchProvider
+class AccessoriesSwitchProvider : public SwitchProvider, public std::enable_shared_from_this<AccessoriesSwitchProvider>
 {
 public:
        AccessoriesSwitchProvider();
@@ -24,8 +24,11 @@ private:
        static Eina_Bool keyUpCb(void *data, int type, void *ev);
 
        const std::set<std::string> keys;
+
        Ecore_Event_Handler *keyDownHandler;
        Ecore_Event_Handler *keyUpHandler;
+       VConfInterface::CallbackHandle onDisconnectionHandler;
+
        std::string currentKeyId;
        std::string prevKeyId;
 };
index 41eb48eda440da3ead45774cd2a61499cbc866a1..981a65120cdb1a11309945f57b2dd8745bee3842 100644 (file)
@@ -26,8 +26,8 @@ std::shared_ptr<Switch> CompositeSwitchProvider::findSwitchById(const std::strin
        }
 
        return nullptr;
-}
 
+}
 void CompositeSwitchProvider::add(std::shared_ptr<SwitchProvider> provider)
 {
        providers.push_back(provider);
@@ -60,6 +60,19 @@ void CompositeSwitchProvider::detach(const Observer<Switch> *observer, const Swi
                p->detach(observer, item);
 }
 
+void CompositeSwitchProvider::attach(std::weak_ptr<Observer<SwitchProvider>> observer, std::shared_ptr<Condition<SwitchProvider>> cond)
+{
+       for (auto &p : providers) {
+               p->attach(observer, cond);
+       }
+}
+
+void CompositeSwitchProvider::detach(const Observer<SwitchProvider> *observer, const SwitchProvider *item)
+{
+       for (auto &p : providers)
+               p->detach(observer, item);
+}
+
 std::shared_ptr<SwitchProvider> CompositeSwitchProvider::getProviderById(const std::string &id) const
 {
        for (auto &provider : providers) {
index e67ff7a4f7554164884b0f0ed4599268a6527a9e..ab16195db5c27f325ec3d9c03cc8b6abbab52306 100644 (file)
@@ -20,6 +20,9 @@ public:
        void attach(std::weak_ptr<Observer<Switch>> observer, std::shared_ptr<Condition<Switch>> cond) override;
        void detach(const Observer<Switch> *observer, const Switch *item) override;
 
+       void attach(std::weak_ptr<Observer<SwitchProvider>> observer, std::shared_ptr<Condition<SwitchProvider>> cond) override;
+       void detach(const Observer<SwitchProvider> *observer, const SwitchProvider *item) override;
+
 private:
        std::vector<std::shared_ptr<SwitchProvider>> providers;
 };
index cc8fdf44614c3ca70245e75ce4e4ceb122131429..589f740f713d2832450bbf26c22547cdd921fbaf 100644 (file)
@@ -1,8 +1,12 @@
 #include "SwitchManager.hpp"
 
+#include <Elementary.h>
+#include <efl_extension.h>
+
 #include "ConditionAll.hpp"
 #include "ConditionEqual.hpp"
 #include "UIActivity.hpp"
+#include "Window.hpp"
 
 SwitchManager::SwitchManager(const std::shared_ptr<SwitchProvider> &provider,
                                                         const std::shared_ptr<Configuration> &configuration,
@@ -14,8 +18,11 @@ SwitchManager::SwitchManager(const std::shared_ptr<SwitchProvider> &provider,
 
 void SwitchManager::initialize()
 {
-       auto cond = std::unique_ptr<Condition<SwitchConfigurationItem>>(new ConditionAll<SwitchConfigurationItem>);
-       configuration->attach(shared_from_this(), std::move(cond));
+       auto condCI = std::shared_ptr<Condition<SwitchConfigurationItem>>(new ConditionAll<SwitchConfigurationItem>);
+       configuration->attach(shared_from_this(), std::move(condCI));
+
+       auto condSP = std::shared_ptr<Condition<SwitchProvider>>(new ConditionAll<SwitchProvider>);
+       switchProvider->attach(shared_from_this(), std::move(condSP));
 
        auto confItems = configuration->findAll();
 
@@ -24,8 +31,8 @@ void SwitchManager::initialize()
                if (!sw)
                        continue;
 
-               auto cond = std::unique_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
-               switchProvider->attach(shared_from_this(), std::move(cond));
+               auto condS = std::shared_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
+               switchProvider->attach(shared_from_this(), std::move(condS));
        }
 }
 
@@ -39,7 +46,7 @@ void SwitchManager::update(const std::shared_ptr<SwitchConfigurationItem> &item)
                if (!sw)
                        return;
 
-               auto cond = std::unique_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
+               auto cond = std::shared_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
                switchProvider->attach(shared_from_this(), std::move(cond));
 
                break;
@@ -78,6 +85,21 @@ void SwitchManager::update(const std::shared_ptr<ActivityChangeRequest> &request
        changeActivity(request);
 }
 
+void SwitchManager::update(const std::shared_ptr<SwitchProvider> &provider)
+{
+       DEBUG("notified with provider: %s", provider->getId().c_str());
+
+       auto confItems = configuration->findAll();
+
+       for (auto &item : confItems) {
+               auto sw = provider->findSwitchById(item->getSwitchId());
+               if (sw) {
+                       onDisconnection();
+                       return;
+               }
+       }
+}
+
 void SwitchManager::setActivityProvider(const std::shared_ptr<SwitchProvider> &provider)
 {
        switchProvider = provider;
@@ -93,6 +115,54 @@ void SwitchManager::setActivityFactory(const std::shared_ptr<ActivityFactory> &f
        activityFactory = factory;
 }
 
+static void windowDeleterCb(void *data, Evas_Object *obj, void *event_info)
+{
+       evas_object_del(obj);
+}
+
+static void onButtonClickCb(void *data, Evas_Object *obj, void *event_info)
+{
+       auto window = static_cast<Evas_Object *>(data);
+       evas_object_del(window);
+}
+
+void SwitchManager::onDisconnection()
+{
+       auto windowHandler = elm_win_add(NULL, "universal-switch-popup", ELM_WIN_NOTIFICATION);
+       if (!windowHandler) {
+               ERROR("Window cannot be created");
+               exit(1);
+       }
+
+       efl_util_set_notification_window_level(windowHandler, EFL_UTIL_NOTIFICATION_LEVEL_2);
+       elm_win_override_set(windowHandler, EINA_TRUE);
+       elm_win_alpha_set(windowHandler, EINA_TRUE);
+
+       int screenWidth = 0;
+       int screenHeight = 0;
+
+       elm_win_screen_size_get(windowHandler, NULL, NULL, &screenWidth, &screenHeight);
+       evas_object_resize(windowHandler, screenWidth, screenHeight);
+       evas_object_show(windowHandler);
+
+       auto popup = elm_popup_add(windowHandler);
+       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
+       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       elm_object_part_text_set(popup, "title,text", _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Header"));
+       elm_object_text_set(popup, _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Content"));
+
+       eext_object_event_callback_add(windowHandler, EEXT_CALLBACK_BACK, windowDeleterCb, NULL);
+       evas_object_smart_callback_add(windowHandler, "dismissed", windowDeleterCb, NULL);
+       evas_object_smart_callback_add(windowHandler, "block,clicked", windowDeleterCb, NULL);
+
+       auto btn = elm_button_add(popup);
+       elm_object_style_set(btn, "bottom");
+       elm_object_text_set(btn, "OK");
+       elm_object_part_content_set(popup, "button1", btn);
+       evas_object_smart_callback_add(btn, "clicked", onButtonClickCb, windowHandler);
+       evas_object_show(popup);
+}
+
 void SwitchManager::changeActivity(const std::shared_ptr<ActivityChangeRequest> &request)
 {
        ASSERT(request, "request is not initialized");
index 57004a68f5deac65c08854f5f31ef24654783f4c..1824d0226ac17cfbb5b5ce5ed64bf34ac5591a91 100644 (file)
 #include <memory>
 #include <stack>
 
-class SwitchManager : public SwitchConfigurationItemObserver, public SwitchObserver, public std::enable_shared_from_this<SwitchManager>, public ActivityChangeRequestObserver
+class SwitchManager : public SwitchConfigurationItemObserver, public SwitchObserver, public std::enable_shared_from_this<SwitchManager>, public ActivityChangeRequestObserver, public Observer<SwitchProvider>
 {
 public:
        void update(const std::shared_ptr<SwitchConfigurationItem> &item) override;
        void update(const std::shared_ptr<Switch> &item) override;
        void update(const std::shared_ptr<ActivityChangeRequest> &request) override;
+       void update(const std::shared_ptr<SwitchProvider> &provider) override;
 
        template<class A>
        static std::shared_ptr<A> create(const std::shared_ptr<SwitchProvider> &provider,
@@ -34,6 +35,8 @@ public:
        void setConfiguration(const std::shared_ptr<Configuration> &configuration);
        void setActivityFactory(const std::shared_ptr<ActivityFactory> &factory);
 
+       void onDisconnection();
+
 protected:
        SwitchManager(const std::shared_ptr<SwitchProvider> &provider,
                                  const std::shared_ptr<Configuration> &configuration,
index a93fe5c95f34b5571317357e37f64923a02123e7..869f18d1c0a75b2a98fb64428fd5a74a259a1cd0 100644 (file)
 #include <vector>
 #include <memory>
 
-class SwitchProvider : public Subject<Switch>
+class SwitchProvider : public Subject<Switch>, public Subject<SwitchProvider>
 {
 public:
+       using Subject<Switch>::attach;
+       using Subject<Switch>::detach;
+       using Subject<Switch>::notify;
+       using Subject<SwitchProvider>::attach;
+       using Subject<SwitchProvider>::detach;
+       using Subject<SwitchProvider>::notify;
        using SwitchCollection = std::vector<std::shared_ptr<Switch>>;
 
        SwitchProvider(const std::string &id);