Implemented Selector control abstraction for TabNavigator. 94/82094/1
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 29 Jul 2016 06:19:12 +0000 (09:19 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 29 Jul 2016 12:45:40 +0000 (15:45 +0300)
Implemented Tabbar control. Implemented Selector interface in Hoversel.

Change-Id: I636d265d10a160e4ffd50c3d69e494ff2f85d9c3
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-apps-common/inc/Ui/Hoversel.h
lib-apps-common/inc/Ui/Selector.h [new file with mode: 0644]
lib-apps-common/inc/Ui/Tabbar.h [new file with mode: 0644]
lib-apps-common/src/Ui/Hoversel.cpp
lib-apps-common/src/Ui/Selector.cpp [new file with mode: 0644]
lib-apps-common/src/Ui/Tabbar.cpp [new file with mode: 0644]
lib-contacts/inc/Contacts/Input/ContactTypedFieldControl.h
lib-contacts/src/Contacts/Input/ContactTypedFieldControl.cpp

index 75155e1..31ddd75 100644 (file)
 #ifndef UI_HOVERSEL_H
 #define UI_HOVERSEL_H
 
-#include "Ui/Control.h"
-#include <functional>
+#include "Ui/Selector.h"
 
 namespace Ui
 {
-       class EXPORT_API Hoversel : public Control
+       class EXPORT_API Hoversel : public Selector
        {
        public:
                /**
-                * @brief Item selection callback.
-                * @param[in]   Item value
-                * @return Whether to display selected item in hoversel button automatically
+                * @brief Add item with text.
+                * @param[in]   text        Item text
+                * @param[in]   value       Item data
+                * @return Added item on success, otherwise nullptr.
+                * @see Selector::addItem()
                 */
-               typedef std::function<bool(int)> SelectedCallback;
+               Elm_Object_Item *addItem(const char *text, void *data);
 
                /**
-                * @brief Add item.
-                * @param[in]   text        Item text
-                * @param[in]   value       Item value which will be passed to SelectedCallback
-                * @return Added item on success, otherwise nullptr.
+                * @see Selector::addItem()
                 */
-               Elm_Object_Item *addItem(const char *text, int value);
+               virtual Elm_Object_Item *addItem(void *data) override;
 
                /**
                 * @brief Set text of currently selected item.
@@ -48,10 +46,9 @@ namespace Ui
                void setText(const char *text);
 
                /**
-                * @brief Set item selection callback.
-                * @param[in]   callback    Callback to be called after item was selected
+                * @see Selector::setSelectedItem()
                 */
-               void setSelectedCallback(SelectedCallback callback);
+               virtual void setSelectedItem(Elm_Object_Item *item) override;
 
        protected:
                virtual Evas_Object *onCreate(Evas_Object *parent) override;
@@ -61,8 +58,6 @@ namespace Ui
                static void onExpanded(void *data, Evas_Object *hoversel, void *eventInfo);
                static void onDismissed(void *data, Evas_Object *hoversel, void *eventInfo);
                static void onBackPressed(void *data, Evas_Object *hoversel, void *eventInfo);
-
-               SelectedCallback m_OnSelected;
        };
 }
 
diff --git a/lib-apps-common/inc/Ui/Selector.h b/lib-apps-common/inc/Ui/Selector.h
new file mode 100644 (file)
index 0000000..d55bae1
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 UI_SELECTOR_H
+#define UI_SELECTOR_H
+
+#include "Ui/Control.h"
+#include <functional>
+
+namespace Ui
+{
+       /**
+        * @brief Interface for controls that provide item selection functionality.
+        */
+       class EXPORT_API Selector : public Control
+       {
+       public:
+               /**
+                * @brief Item selection callback.
+                * @param[in]   Item data
+                * @return Whether to perform the default action if any.
+                */
+               typedef std::function<bool(void *)> SelectCallback;
+
+               /**
+                * @brief Add item.
+                * @param[in]   value   Item data which will be passed to SelectedCallback
+                * @return Added item on success, otherwise nullptr.
+                */
+               virtual Elm_Object_Item *addItem(void *data) = 0;
+
+               /**
+                * @brief Set whether selection is enabled.
+                * @param[in]   isEnabled   Whether selection is enabled
+                */
+               virtual void setSelectEnabled(bool isEnabled);
+
+               /**
+                * @brief Set which item is currently selected.
+                * @param[in]   item    Item to be selected
+                */
+               virtual void setSelectedItem(Elm_Object_Item *item) = 0;
+
+               /**
+                * @brief Set item selection callback.
+                * @param[in]   callback    Callback to be called after item was selected
+                */
+               void setSelectCallback(SelectCallback callback);
+
+       protected:
+               /**
+                * @brief Item selection callback.
+                * @param[in]   item    Selected item
+                */
+               bool onSelected(Elm_Object_Item *item);
+
+               SelectCallback m_OnSelected;
+       };
+}
+
+#endif /* UI_SELECTOR_H */
diff --git a/lib-apps-common/inc/Ui/Tabbar.h b/lib-apps-common/inc/Ui/Tabbar.h
new file mode 100644 (file)
index 0000000..b79a0f7
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 UI_TABBAR_H
+#define UI_TABBAR_H
+
+#include "Ui/Selector.h"
+
+namespace Ui
+{
+       /**
+        * @brief Selector control for switching between tabs.
+        */
+       class EXPORT_API Tabbar : public Selector
+       {
+       public:
+               /**
+                * @see Selector::addItem()
+                */
+               virtual Elm_Object_Item *addItem(void *data) override;
+
+               /**
+                * @see Selector::setSelectEnabled()
+                */
+               virtual void setSelectEnabled(bool isEnabled) override;
+
+               /**
+                * @see Selector::setSelectedItem()
+                */
+               virtual void setSelectedItem(Elm_Object_Item *item) override;
+
+       protected:
+               /**
+                * @see Control::onCreate()
+                */
+               virtual Evas_Object *onCreate(Evas_Object *parent) override;
+
+       private:
+               void onSelected(Evas_Object *tabbar, Elm_Object_Item *item);
+       };
+}
+
+#endif /* UI_TABBAR_H */
index 5069a31..4c5e7e5 100644 (file)
 
 using namespace Ui;
 
-Elm_Object_Item *Hoversel::addItem(const char *text, int value)
+Elm_Object_Item *Hoversel::addItem(const char *text, void *data)
 {
        Elm_Object_Item *item = elm_hoversel_item_add(getEvasObject(), text,
-                       nullptr, ELM_ICON_NONE, nullptr, (void *) (long) value);
+                       nullptr, ELM_ICON_NONE, nullptr, data);
        elm_object_item_text_translatable_set(item, EINA_TRUE);
        return item;
 }
 
+Elm_Object_Item *Hoversel::addItem(void *data)
+{
+       return addItem(nullptr, data);
+}
+
 void Hoversel::setText(const char *text)
 {
        elm_object_translatable_text_set(getEvasObject(), text);
 }
 
-void Hoversel::setSelectedCallback(SelectedCallback callback)
+void Hoversel::setSelectedItem(Elm_Object_Item *item)
 {
-       m_OnSelected = std::move(callback);
+       setText(elm_object_item_translatable_text_get(item));
 }
 
 Evas_Object *Hoversel::onCreate(Evas_Object *parent)
@@ -64,9 +69,8 @@ Evas_Object *Hoversel::onCreate(Evas_Object *parent)
 
 void Hoversel::onSelected(Evas_Object *hoversel, Elm_Object_Item *item)
 {
-       int value = (long) elm_object_item_data_get(item);
-       if (!m_OnSelected || m_OnSelected(value)) {
-               setText(elm_object_item_translatable_text_get(item));
+       if (Selector::onSelected(item)) {
+               setSelectedItem(item);
        }
 }
 
diff --git a/lib-apps-common/src/Ui/Selector.cpp b/lib-apps-common/src/Ui/Selector.cpp
new file mode 100644 (file)
index 0000000..83ad9ba
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Ui/Selector.h"
+
+using namespace Ui;
+
+void Selector::setSelectEnabled(bool isEnabled)
+{
+       elm_object_disabled_set(getEvasObject(), !isEnabled);
+}
+
+void Selector::setSelectCallback(SelectCallback callback)
+{
+       m_OnSelected = std::move(callback);
+}
+
+bool Selector::onSelected(Elm_Object_Item *item)
+{
+       void *data = elm_object_item_data_get(item);
+       return !m_OnSelected || m_OnSelected(data);
+}
diff --git a/lib-apps-common/src/Ui/Tabbar.cpp b/lib-apps-common/src/Ui/Tabbar.cpp
new file mode 100644 (file)
index 0000000..a9406b4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "Ui/Tabbar.h"
+#include "Utils/Callback.h"
+
+using namespace Ui;
+
+Elm_Object_Item *Tabbar::addItem(void *data)
+{
+       return elm_toolbar_item_append(getEvasObject(), nullptr, nullptr, nullptr, data);
+}
+
+void Tabbar::setSelectEnabled(bool isEnabled)
+{
+       elm_toolbar_select_mode_set(getEvasObject(),
+                       isEnabled ? ELM_OBJECT_SELECT_MODE_ALWAYS : ELM_OBJECT_SELECT_MODE_NONE);
+}
+
+void Tabbar::setSelectedItem(Elm_Object_Item *item)
+{
+       elm_toolbar_item_selected_set(item, EINA_TRUE);
+}
+
+Evas_Object *Tabbar::onCreate(Evas_Object *parent)
+{
+       Evas_Object *tabbar = elm_toolbar_add(parent);
+       elm_toolbar_shrink_mode_set(tabbar, ELM_TOOLBAR_SHRINK_EXPAND);
+       elm_toolbar_select_mode_set(tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
+       elm_toolbar_transverse_expanded_set(tabbar, EINA_TRUE);
+       evas_object_smart_callback_add(tabbar, "selected",
+                       (Evas_Smart_Cb) makeCallback(&Tabbar::onSelected), this);
+       return tabbar;
+}
+
+void Tabbar::onSelected(Evas_Object *tabbar, Elm_Object_Item *item)
+{
+       Selector::onSelected(item);
+}
index 643b173..da162dd 100644 (file)
@@ -44,7 +44,7 @@ namespace Contacts
 
                private:
                        virtual void onCreated() override;
-                       bool onSelected(int value);
+                       bool onSelected(void *data);
 
                        Model::ContactEnumField &m_TypeField;
                        Model::ContactTextField &m_LabelField;
index ee73652..a206417 100644 (file)
@@ -39,7 +39,7 @@ void ContactTypedFieldControl::onCreated()
 
        auto pairs = getEnumValueNames(EnumType(m_TypeField.getSubType()));
        for (auto &&pair : pairs) {
-               addItem(pair.name, pair.value);
+               addItem(pair.name, (void *) (long) pair.value);
 
                if (pair.value == currentValue) {
                        setText(pair.name);
@@ -50,12 +50,13 @@ void ContactTypedFieldControl::onCreated()
                setText(m_LabelField.getValue());
        }
 
-       setSelectedCallback(std::bind(&ContactTypedFieldControl::onSelected, this,
+       setSelectCallback(std::bind(&ContactTypedFieldControl::onSelected, this,
                        std::placeholders::_1));
 }
 
-bool ContactTypedFieldControl::onSelected(int value)
+bool ContactTypedFieldControl::onSelected(void *data)
 {
+       int value = (long) data;
        if (value == m_TypeField.getCustomValue()) {
                auto popup = new Ux::EditfieldPopup();
                popup->setStrings({