now viewmgr support back/menu keys.
Change-Id: I579f8e9fbcbae647da83a8375c4d8c39a85a8828
src/efl/ui_view.cpp
src/efl/ui_viewmgr.cpp
src/efl/ui_key_listener.cpp
+ src/efl/mobile/ui_basic_controller.cpp
src/efl/mobile/ui_basic_view.cpp
src/efl/mobile/ui_basic_key_listener.cpp
+ src/efl/mobile/ui_basic_viewmgr.cpp
src/efl/example/main.cpp
)
toolbar = elm_toolbar_add(parent);
+ //FIXME: :( UI_View can set this style instead.
elm_object_style_set(toolbar, "tabbar_with_title");
elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
return toolbar;
}
+
Evas_Object*
create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad)
{
static void create_base_gui(appdata_s *ad)
{
//FIXME: Hide this creation.
- ad->viewmgr = new ui_viewmgr(PACKAGE);
+ ad->viewmgr = new ui_basic_viewmgr(PACKAGE);
create_page1(ad);
* limitations under the License.
*
*/
-class page1: public ui_controller
+class page1: public ui_basic_controller
{
private:
appdata_s *ad;
view->set_content(content, "Title");
}
+
+ bool menu()
+ {
+ LOGE("Menu!");
+ return true;
+ }
};
void create_page1(appdata_s *ad)
* limitations under the License.
*
*/
-class page2: public ui_controller
+class page2: public ui_basic_controller
{
private:
appdata_s *ad;
* limitations under the License.
*
*/
-class page3: public ui_controller
+class page3: public ui_basic_controller
{
private:
appdata_s *ad;
* limitations under the License.
*
*/
-class page4: public ui_controller
+class page4: public ui_basic_controller
{
private:
appdata_s *ad;
* limitations under the License.
*
*/
-class page5: public ui_controller
+class page5: public ui_basic_controller
{
private:
appdata_s *ad;
* limitations under the License.
*
*/
-class page6: public ui_controller
+class page6: public ui_basic_controller
{
private:
appdata_s *ad;
--- /dev/null
+/*
+ * Copyright (c) 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_viewmanager.h"
+
+using namespace efl_viewmgr;
+using namespace viewmgr;
+
+ui_basic_controller::~ui_basic_controller()
+{
+}
+
+bool ui_basic_controller::menu()
+{
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 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_BASIC_CONTROLLER_H
+#define UI_BASIC_CONTROLLER_H
+
+#include "../ui_viewmanager.h"
+
+namespace efl_viewmgr
+{
+class ui_basic_controller: public ui_controller
+{
+public:
+ virtual ~ui_basic_controller();
+ virtual bool menu();
+};
+}
+
+#endif /* UI_BASIC_CONTROLLER_H */
using namespace efl_viewmgr;
using namespace viewmgr;
-static const char *KEY_BACK = "XF86Back";
static const char *KEY_MENU = "XF86Menu";
enum ui_key_event_type
{
- UI_KEY_EVENT_BACK = 0,
UI_KEY_EVENT_MENU
};
{
}
-static void event_proc(ui_basic_key_listener *key_handler, Evas_Event_Key_Down *ev)
+void ui_basic_key_listener::extend_event_proc(ui_view *view, Evas_Event_Key_Down *ev)
{
- ui_key_event_type type;
-
- if (!strcmp(ev->keyname, KEY_BACK))
- type = UI_KEY_EVENT_BACK;
- else if (!strcmp(ev->keyname, KEY_MENU))
- type = UI_KEY_EVENT_MENU;
- else return;
-
- ui_viewmgr *viewmgr = key_handler->get_viewmgr();
- if (!viewmgr->is_activated()) return;
-
- //Get Top View
- ui_view *view = reinterpret_cast<ui_view *>(viewmgr->get_last_view());
- if (!view) return;
-
- //call events
- switch (type)
- {
- case UI_KEY_EVENT_BACK:
- //view->back();
- LOGE("BACK!");
- break;
- case UI_KEY_EVENT_MENU:
- //view->menu();
- LOGE("MENU!");
- break;
- }
-}
-
-bool ui_basic_key_listener::term()
-{
- evas_object_del(this->key_grabber);
- return true;
+ if (strcmp(ev->keyname, KEY_MENU)) return;
+ dynamic_cast<ui_basic_view *>(view)->menu();
}
bool ui_basic_key_listener::init()
{
- if (!this->viewmgr)
- {
- LOGE("No view manager??");
- return false;
- }
-
- Evas *e = evas_object_evas_get(this->viewmgr->get_window());
- if (!e)
- {
- LOGE("Failed to get Evas from window");
- return false;
- }
+ if (!ui_key_listener::init()) return false;
- Evas_Object *key_grab_rect = evas_object_rectangle_add(e);
- if (!key_grab_rect)
+ if (!evas_object_key_grab(this->key_grabber, KEY_MENU, 0, 0, EINA_FALSE))
{
- LOGE("Failed to create a key grabber rectangle");
+ LOGE("Failed to grab MENU KEY(%s)\n", KEY_MENU);
return false;
}
-
- evas_object_event_callback_add(key_grab_rect, EVAS_CALLBACK_KEY_UP,
- [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
- {
- Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event_info);
- ui_basic_key_listener *key_handler = static_cast<ui_basic_key_listener *>(data);
- event_proc(key_handler, ev);
- },
- this);
-
- if (!evas_object_key_grab(key_grab_rect, KEY_BACK, 0, 0, EINA_FALSE))
- {
- LOGE("Failed to grab BACK KEY(%s)\n", KEY_BACK);
- evas_object_del(key_grab_rect);
- return false;
- }
-
- if (!evas_object_key_grab(key_grab_rect, KEY_MENU, 0, 0, EINA_FALSE))
- {
- LOGE("Failed to grab MENU KEY(%s)\n", KEY_MENU);
- evas_object_del(key_grab_rect);
- return false;
- }
-
- this->key_grabber = key_grab_rect;
-
return true;
}
public:
ui_basic_key_listener(ui_viewmgr *viewmgr);
- bool init();
- bool term();
-
- ui_viewmgr *get_viewmgr() { return this->viewmgr; }
+ virtual bool init();
+ virtual void extend_event_proc(ui_view *view, Evas_Event_Key_Down *ev);
};
}
ui_view::set_content(NULL);
this->destroy_layout();
}
+
+void ui_basic_view::menu()
+{
+ if (!this->get_controller()) return;
+ (dynamic_cast<ui_basic_controller *>(this->get_controller()))->menu();
+}
bool set_title(const char *text);
bool set_tabbar(Evas_Object *toolbar);
+ virtual void menu();
+
virtual Evas_Object *get_base()
{
return this->layout;
--- /dev/null
+/*
+ * Copyright (c) 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_viewmanager.h"
+
+using namespace efl_viewmgr;
+using namespace viewmgr;
+
+ui_basic_viewmgr::ui_basic_viewmgr(const char *pkg)
+ : ui_viewmgr(pkg, new ui_basic_key_listener(this))
+{
+}
+
+ui_basic_viewmgr::~ui_basic_viewmgr()
+{
+}
--- /dev/null
+/*
+ * Copyright (c) 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_BASIC_VIEWMGR_H
+#define UI_BASIC_VIEWMGR_H
+
+#include <Elementary.h>
+#include "../ui_viewmanager.h"
+
+namespace efl_viewmgr
+{
+
+class ui_basic_view;
+
+class ui_basic_viewmgr: public ui_viewmgr
+{
+ friend class ui_basic_view;
+
+public:
+ ui_basic_viewmgr(const char *pkg);
+ virtual ~ui_basic_viewmgr();
+
+};
+}
+
+#endif /* UI_BASIC_VIEWMGR_H */
#endif
#define LOG_TAG "UI_VIEWMGR"
-#include "ui_basic_key_listener.h"
+#include "ui_basic_controller.h"
#include "ui_basic_view.h"
+#include "ui_basic_key_listener.h"
+#include "ui_basic_viewmgr.h"
virtual void pause() {}
virtual void resume() {}
virtual void destroy() {}
+
+ virtual bool back() { return true; }
};
}
static const char *KEY_BACK = "XF86Back";
-enum ui_key_event_type
-{
- UI_KEY_EVENT_BACK = 0,
-};
-
ui_key_listener::ui_key_listener(ui_viewmgr *viewmgr)
: viewmgr(viewmgr), key_grabber(NULL)
{
}
-static void event_proc(ui_key_listener *key_handler, Evas_Event_Key_Down *ev)
+static void event_proc(ui_key_listener *key_listener, Evas_Event_Key_Down *ev)
{
- ui_key_event_type type;
-
- if (!strcmp(ev->keyname, KEY_BACK))
- type = UI_KEY_EVENT_BACK;
- else return;
-
- ui_viewmgr *viewmgr = key_handler->get_viewmgr();
- if (!viewmgr->is_activated()) return;
-
- //Get Top View
- ui_view *view = reinterpret_cast<ui_view *>(viewmgr->get_last_view());
- if (!view) return;
-
- //call events
- switch (type)
- {
- case UI_KEY_EVENT_BACK:
- //view->back();
- LOGE("BACK!");
- break;
- }
+ //Only if view manager is activated
+ ui_viewmgr *viewmgr = key_listener->get_viewmgr();
+ if (!viewmgr->is_activated()) return;
+
+ //Get Top View
+ ui_view *view = dynamic_cast<ui_view *>(viewmgr->get_last_view());
+ if (!view) return;
+
+ key_listener->extend_event_proc(view, ev);
+
+ if (strcmp(ev->keyname, KEY_BACK)) return;
+
+ view->back();
}
bool ui_key_listener::term()
return false;
}
- evas_object_event_callback_add(key_grab_rect, EVAS_CALLBACK_KEY_UP,
- [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
- {
- Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event_info);
- ui_key_listener *key_handler = static_cast<ui_key_listener *>(data);
- event_proc(key_handler, ev);
- },
- this);
+ evas_object_event_callback_add(key_grab_rect, EVAS_CALLBACK_KEY_UP, [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
+ {
+ Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event_info);
+ ui_key_listener *key_listener = static_cast<ui_key_listener *>(data);
+ event_proc(key_listener, ev);
+ }, this);
if (!evas_object_key_grab(key_grab_rect, KEY_BACK, 0, 0, EINA_FALSE))
{
- LOGE("Failed to grab BACK KEY(%s)\n", KEY_BACK);
- evas_object_del(key_grab_rect);
- return false;
+ LOGE("Failed to grab BACK KEY(%s)\n", KEY_BACK);
+ evas_object_del(key_grab_rect);
+ return false;
}
this->key_grabber = key_grab_rect;
namespace efl_viewmgr
{
class ui_viewmgr;
+class ui_view;
class ui_key_listener
{
virtual bool init();
virtual bool term();
+ virtual void extend_event_proc(ui_view *view, Evas_Event_Key_Down *ev) {}
ui_viewmgr *get_viewmgr() { return this->viewmgr; }
};
viewmgr->set_indicator(indicator);
}
+
+void ui_view::back()
+{
+ if (this->get_controller())
+ {
+ if (!dynamic_cast<ui_controller *>(this->get_controller())->back())
+ {
+ return;
+ }
+ }
+ dynamic_cast<ui_viewmgr *>(this->get_viewmgr())->pop_view();
+}
virtual Evas_Object *set_content(Evas_Object *content);
virtual Evas_Object *get_base();
+ virtual void back();
+
void set_indicator(ui_view_indicator indicator);
protected:
return true;
}
-ui_viewmgr::ui_viewmgr(const char *pkg)
- : ui_viewmgr_interface(), key_listener(NULL)
+ui_viewmgr::ui_viewmgr(const char *pkg, ui_key_listener *key_listener)
+ : ui_viewmgr_interface(), key_listener(key_listener)
{
if (!pkg)
{
elm_win_autodel_set(this->win, EINA_TRUE);
- this->set_key_listener();
+ key_listener->init();
}
-ui_viewmgr::~ui_viewmgr()
+ui_viewmgr::ui_viewmgr(const char *pkg)
+ : ui_viewmgr(pkg, new ui_key_listener(this))
{
- this->key_listener->term();
}
-void ui_viewmgr::set_key_listener()
+ui_viewmgr::~ui_viewmgr()
{
- this->key_listener = new ui_key_listener(this);
- this->key_listener->init();
+ this->key_listener->term();
+ delete(this->key_listener);
}
bool ui_viewmgr::activate()
bool create_conformant(Evas_Object *win);
bool create_base_layout(Evas_Object *conform);
bool set_indicator(ui_view_indicator indicator);
- virtual void set_key_listener();
protected:
+ ui_viewmgr(const char *pkg, ui_key_listener *key_listener);
+
Evas_Object *get_base()
{
return this->layout;
}
/// Return a controller of this view.
- const ui_controller_interface* get_controller()
+ ui_controller_interface* get_controller()
{
return this->controller;
}