{
public:
/**
+ * @brief Called when the navigator is about to navigate away
+ * from it's last remaining page.
+ * @return Whether to navigate from the last page.
+ */
+ typedef std::function<bool()> LastPageCallback;
+
+ /**
* @return Currently displayed page.
*/
virtual NavigatorPage *getCurrentPage() const = 0;
*/
bool navigateFrom(View *view);
+ /**
+ * @brief Set last page callback.
+ * @param[in] callback Last page navigation callback.
+ */
+ void setLastPageCallback(LastPageCallback callback);
+
+ /**
+ * @brief Unset last page callback.
+ */
+ void unsetLastPageCallback();
+
protected:
Navigator(NavigatorType type);
NavigatorType m_Type;
size_t m_PageCount;
+ LastPageCallback m_OnLastPage;
};
}
class EXPORT_API Window : public Control
{
public:
- /**
- * @brief Called when "back" button was pressed and wasn't handled by any view.
- * @return true to lower the window, otherwise false.
- */
- typedef std::function<bool()> BackCallback;
-
Window();
/**
Evas_Object *getBaseLayout() const;
/**
- * @brief Set "back" button callback.
- * @param[in] callback "back" button callback
- */
- void setBackCallback(BackCallback callback);
-
- /**
- * @brief Unset "back" button callback.
- */
- void unsetBackCallback();
-
- /**
* @brief Attach main View to be displayed in the Window.
* @param[in] view Window main View
*/
Evas_Object *m_Conform;
Evas_Object *m_Layout;
View *m_MainView;
- BackCallback m_OnBackPressed;
};
}
}
if (getPageCount() == 1) {
- NavigatorPage *page = getPage();
- if (page) {
- page->close();
- return true;
+ if (!m_OnLastPage || m_OnLastPage()) {
+ NavigatorPage *page = getPage();
+ if (page) {
+ page->close();
+ return true;
+ }
}
return false;
return true;
}
+void Navigator::setLastPageCallback(LastPageCallback callback)
+{
+ m_OnLastPage = std::move(callback);
+}
+
+void Navigator::unsetLastPageCallback()
+{
+ m_OnLastPage = nullptr;
+}
+
void Navigator::notifyNavigation(NavigatorPage *page, bool isCurrent)
{
if (page) {
return m_Layout;
}
-void Window::setBackCallback(BackCallback callback)
-{
- m_OnBackPressed = std::move(callback);
-}
-
-void Window::unsetBackCallback()
-{
- m_OnBackPressed = nullptr;
-}
-
void Window::attachView(View *view)
{
m_MainView = view;
void Window::onBackPressed(Evas_Object *obj, void *eventInfo)
{
if (!m_MainView || m_MainView->onBackPressed()) {
- if (!m_OnBackPressed || m_OnBackPressed()) {
- elm_win_lower(getEvasObject());
- }
+ elm_win_lower(getEvasObject());
}
}
public:
MainApp();
- /**
- * @return Application main Window
- */
- Ui::Window *getWindow() const;
-
- /**
- * @return Application main Navigator
- */
- Ui::Navigator *getNavigator() const;
-
private:
virtual bool onCreate() override;
virtual void onAppControl(app_control_h request) override;
#define OPERATION_CONTROLLER_H
#include <app_control.h>
+#include <Evas.h>
+
+namespace Ui
+{
+ class Navigator;
+ class Window;
+}
enum Operation
{
OperationPick = 1 << 5
};
-class MainApp;
-
/**
* @brief Handles operations requested through App Control
*/
/**
* @brief Create operation controller
- * @param[in] application Main application instance
+ * @param[in] window Main application Window
+ * @param[in] navigator Main application Navigator
*/
- void create(MainApp *application);
+ void create(Ui::Window *window, Ui::Navigator *navigator);
/**
* @brief Request the controller to handle the operation
/**
* @brief Create operation controller
* @param[in] supportedOperations Supported operations mask
+ * @param[in] isMinimizable Whether application can be minimized
* @see Operation
*/
- OperationController(int supportedOperations);
+ OperationController(int supportedOperations, bool isMinimizable = false);
+
+ /**
+ * @return Main application Window
+ */
+ Ui::Window *getWindow() const;
/**
- * @return Main application instance
+ * @return Main application Navigator
*/
- MainApp *getApplication() const;
+ Ui::Navigator *getNavigator() const;
/**
* @return Last received request
virtual void onRequest(Operation operation, app_control_h request) = 0;
private:
+ static void onWindowLowered(void *data, Evas_Object *obj, void *eventInfo);
+
int m_SupportedOperations;
- MainApp *m_Application;
app_control_h m_Request;
+ bool m_IsMinimizable;
+
+ Ui::Window *m_Window;
+ Ui::Navigator *m_Navigator;
};
#endif /* OPERATION_CONTROLLER_H */
{
public:
OperationEditController();
- virtual ~OperationEditController() override;
private:
virtual void onRequest(Operation operation, app_control_h request);
- virtual void onCreate() override;
Ui::View *createInputView(int personId);
{
public:
OperationPickController();
- virtual ~OperationPickController();
private:
- virtual void onCreate() override;
virtual void onRequest(Operation operation, app_control_h request) override;
bool onSelected(Contacts::SelectResults results);
static Contacts::ResultType getResultType(app_control_h request);
static const char *getResultTypeString(Contacts::ResultType resultType);
- Ui::Navigator *m_Navigator;
Contacts::SelectMode m_SelectMode;
Contacts::ResultType m_ResultType;
};
{
public:
OperationViewController();
- virtual ~OperationViewController();
private:
- virtual void onCreate();
virtual void onRequest(Operation operation, app_control_h request);
};
{
}
-Ui::Window *MainApp::getWindow() const
-{
- return m_Window;
-}
-
-Ui::Navigator *MainApp::getNavigator() const
-{
- return m_Navigator;
-}
-
bool MainApp::onCreate()
{
int err = contacts_connect();
}
if (m_Controller) {
- m_Controller->create(this);
+ m_Controller->create(m_Window, m_Navigator);
}
}
*/
#include "OperationController.h"
+#include "Ui/Navigator.h"
+#include "Ui/Window.h"
+#include <app.h>
#include <string.h>
-OperationController::OperationController(int supportedOperations)
- : m_SupportedOperations(supportedOperations), m_Application(nullptr), m_Request(nullptr)
+OperationController::OperationController(int supportedOperations, bool isMinimizable)
+ : m_SupportedOperations(supportedOperations), m_Request(nullptr), m_IsMinimizable(isMinimizable),
+ m_Window(nullptr), m_Navigator(nullptr)
{
}
OperationController::~OperationController()
{
app_control_destroy(m_Request);
+
+ if (!m_IsMinimizable) {
+ m_Navigator->unsetLastPageCallback();
+ evas_object_smart_callback_del_full(m_Window->getEvasObject(),
+ "iconified", &OperationController::onWindowLowered, this);
+ }
}
-void OperationController::create(MainApp *application)
+void OperationController::create(Ui::Window *window, Ui::Navigator *navigator)
{
- m_Application = application;
+ m_Window = window;
+ m_Navigator = navigator;
+
+ if (!m_IsMinimizable) {
+ m_Navigator->setLastPageCallback([] {
+ ui_app_exit();
+ return true;
+ });
+ }
+
onCreate();
}
{
app_control_destroy(m_Request);
app_control_clone(&m_Request, request);
+
+ if (!m_IsMinimizable) {
+ app_control_launch_mode_e launchMode = APP_CONTROL_LAUNCH_MODE_SINGLE;
+ app_control_get_launch_mode(m_Request, &launchMode);
+
+ if (launchMode == APP_CONTROL_LAUNCH_MODE_SINGLE) {
+ evas_object_smart_callback_add(m_Window->getEvasObject(),
+ "iconified", &OperationController::onWindowLowered, this);
+ }
+ }
+
onRequest(operation, m_Request);
}
return OperationDefault;
}
-MainApp *OperationController::getApplication() const
+Ui::Window *OperationController::getWindow() const
+{
+ return m_Window;
+}
+
+Ui::Navigator *OperationController::getNavigator() const
{
- return m_Application;
+ return m_Navigator;
}
app_control_h OperationController::getRequest() const
app_control_reply_to_launch_request(reply, m_Request, APP_CONTROL_RESULT_FAILED);
app_control_destroy(reply);
}
+
+void OperationController::onWindowLowered(void *data, Evas_Object *obj, void *eventInfo)
+{
+ ui_app_exit();
+}
#define PREFERENCE_KEY_LAST_TAB "last_tab"
OperationDefaultController::OperationDefaultController()
- : OperationController(OperationDefault | OperationDial),
+ : OperationController(OperationDefault | OperationDial, true),
m_Navigator(nullptr), m_Tabs{nullptr}
{
}
void OperationDefaultController::onCreate()
{
- Ui::Navigator *mainNavigator = getApplication()->getNavigator();
m_Navigator = new Ui::TabView();
- mainNavigator->navigateTo(m_Navigator);
+ getNavigator()->navigateTo(m_Navigator);
m_Tabs[TabDialer] = new Phone::Dialer::DialerView();
m_Tabs[TabLogs] = new Logs::List::LogsView();
#include "App/AppControlRequest.h"
#include "Ui/Navigator.h"
-#include "Ui/Window.h"
#include <string>
{
}
-OperationEditController::~OperationEditController()
-{
- getApplication()->getWindow()->unsetBackCallback();
-}
-
-void OperationEditController::onCreate()
-{
- getApplication()->getWindow()->setBackCallback([] {
- ui_app_exit();
- return true;
- });
-}
-
void OperationEditController::onRequest(Operation operation, app_control_h request)
{
Ui::View *view = nullptr;
view = createInputView(personId);
}
- getApplication()->getNavigator()->navigateTo(view);
+ getNavigator()->navigateTo(view);
}
Ui::View *OperationEditController::createInputView(int personId)
bool OperationEditController::onSelectResult(SelectResults results)
{
Ui::View *view = createInputView(results.begin()->value.id);
- getApplication()->getNavigator()->navigateTo(view);
+ getNavigator()->navigateTo(view);
return true;
}
app_control_add_extra_data(reply, APP_CONTROL_DATA_ID, std::to_string(personId).c_str());
app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
app_control_destroy(reply);
-
- ui_app_exit();
}
#include "App/AppControlRequest.h"
#include "Ui/Navigator.h"
-#include "Ui/Window.h"
#include <vector>
OperationPickController::OperationPickController()
: OperationController(OperationPick),
- m_Navigator(nullptr),
m_SelectMode(SelectSingle), m_ResultType(ResultPerson)
{
}
-OperationPickController::~OperationPickController()
-{
- getApplication()->getWindow()->unsetBackCallback();
-}
-
-void OperationPickController::onCreate()
-{
- m_Navigator = getApplication()->getNavigator();
- getApplication()->getWindow()->setBackCallback([] {
- ui_app_exit();
- return true;
- });
-}
-
void OperationPickController::onRequest(Operation operation, app_control_h request)
{
m_SelectMode = getSelectMode(request);
int limit = App::getIntExtraData(request, APP_CONTROL_DATA_TOTAL_COUNT);
Chooser *chooser = new Chooser(m_SelectMode, m_ResultType, limit);
chooser->setSelectCallback(std::bind(&OperationPickController::onSelected, this, _1));
- m_Navigator->navigateTo(chooser);
+ getNavigator()->navigateTo(chooser);
}
bool OperationPickController::onSelected(SelectResults results)
app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
app_control_destroy(reply);
- ui_app_exit();
return true;
}
#include "App/AppControlRequest.h"
#include "Ui/Navigator.h"
-#include "Ui/Window.h"
#include <string.h>
{
}
-OperationViewController::~OperationViewController()
-{
- getApplication()->getWindow()->unsetBackCallback();
-}
-
-void OperationViewController::onCreate()
-{
- getApplication()->getWindow()->setBackCallback([] {
- ui_app_exit();
- return true;
- });
-}
-
void OperationViewController::onRequest(Operation operation, app_control_h request)
{
Ui::View *view = nullptr;
free(mime);
if (view) {
- getApplication()->getNavigator()->navigateTo(view);
+ getNavigator()->navigateTo(view);
} else {
ui_app_exit();
}