--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ *******************************************************************************/
+/**
+ * @file tbt-motion-detection-view.c
+ * @brief shows motion detected and indicates the same on display
+ *
+ * @author Maneesha Karn (maneesha.k@samsung.com)
+ * @date August, 2017
+ * @bug no known bug
+ * @credit
+ *
+ */
+
+#include "utils/app_module_config.h"
+#ifdef TBT_MODULE_MOTION
+
+#include <Elementary.h>
+
+#include "utils/logger.h"
+#include "utils/config.h"
+#include "utils/ui-utils.h"
+#include "view/tbt-motion-detection-view.h"
+#include "view/tbt-common-view.h"
+
+
+enum
+{
+ ACTIVITY_TOOLBAR_ITEM_INDEX_STATIONARY = 0,
+ ACTIVITY_TOOLBAR_ITEM_INDEX_WALK,
+ ACTIVITY_TOOLBAR_ITEM_INDEX_RUN,
+ ACTIVITY_TOOLBAR_ITEM_INDEX_IN_VEHICLE,
+ ACTIVITY_TOOLBAR_ITEM_INDEX_COUNT_MAX
+} ACTIVITY_TOOLBAR_ITEM_INDEXS;
+
+
+struct _motion_detection_view
+{
+ common_view* view;
+ activity_h handle;
+ Evas_Object *start_detection_button;
+ Evas_Object *stop_detection_button;
+ Evas_Object *activity_image;
+ Evas_Object *activity_label;
+};
+
+static void _app_destroy_cb(void* this);
+static void _start_detection_button_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static void _stop_detection_button_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static char * _motion_get_activity_type(activity_type_e activity_type);
+static Evas_Object *add_control_layout(motion_detection_view *this, Evas_Object *parent);
+static void activity_recognition_callback_check_type(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void *user_data);
+static char *_activity_error(int activity_error);
+
+
+/**
+ * @function motion_detection_view_add
+ * @since_tizen 2.3
+ * @description Motion Detection View Add
+ * @parameter Evas_Object*: Evas Object Pointer, tbt_info*: Tbt Info Pointer, Elm_Object_Item*: Elm Object Item Pointer
+ * @return motion_detection_view*
+ */
+motion_detection_view *motion_detection_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item *item)
+{
+ RETVM_IF(NULL == navi, NULL, "navi is null");
+
+ int x,y,w,h;
+ evas_object_geometry_get(navi, &x, &y, &w, &h);
+ DBG("Dim: %d %d %d %d", x, y, w, h);
+
+ motion_detection_view *this = NULL;
+ this = calloc(1, sizeof(motion_detection_view));
+ RETVM_IF(!this, NULL, "calloc failed");
+
+ this->view = calloc(1, sizeof(common_view));
+ RETVM_IF(!this->view, NULL, "calloc failed");
+
+ tbt_info->layout_group = "motion_detection_viewer";
+ tbt_info->layout_file = get_edje_path("motion_detection_viewer.edj");
+
+ common_view_add(navi, tbt_info, item, this->view, _app_destroy_cb, this);
+
+ RETVM_IF(NULL == this->view, NULL, "navi is null");
+
+ this->activity_label = ui_utils_label_add(this->view->layout, "Activity Status");
+ RETVM_IF(NULL == this->activity_label, NULL, "Label is null");
+
+ elm_object_part_content_set(this->view->layout, "activity_text", this->activity_label);
+ ui_utils_label_set_text(this->activity_label, "Activity Status", "left");
+ const char *file_path;
+ file_path = get_resource_path(this->view->tbt_info->file_name);
+ this->activity_image = ui_utils_create_image(this->view->layout, file_path);
+
+ //int x,y,w,h;
+ evas_object_geometry_get(this->activity_image, &x, &y, &w, &h);
+ DBG("Dim: %d %d %d %d", x, y, w, h);
+
+ RETVM_IF(NULL == this->activity_image, false, "creation of layout elements failed");
+
+ elm_object_part_content_set(this->view->layout, "activity_image", this->activity_image);
+
+ Evas_Object *control = add_control_layout(this, this->view->layout);
+ elm_object_part_content_set(this->view->layout, "controlr_part", control);
+ evas_object_show(control);
+ return this;
+}
+
+
+
+
+/**
+ * @function _activity_error
+ * @since_tizen 3.0
+ * @description Return string name of Activity Error detected
+ * @parameter int activity_error
+ * @return static char *
+ */
+static char *_activity_error(int activity_error)
+{
+ char error[50];
+ switch(activity_error)
+ {
+ case ACTIVITY_ERROR_ALREADY_STARTED :
+ strcpy(error,"ACTIVITY_ERROR_ALREADY_STARTED");
+ break;
+ case ACTIVITY_ERROR_INVALID_OPERATION:
+ strcpy(error,"ACTIVITY_ERROR_INVALID_OPERATION");
+ break;
+ case ACTIVITY_ERROR_INVALID_PARAMETER:
+ strcpy(error,"ACTIVITY_ERROR_INVALID_PARAMETER");
+ break;
+ case ACTIVITY_ERROR_NOT_STARTED :
+ strcpy(error,"ACTIVITY_ERROR_NOT_STARTED");
+ break;
+ case ACTIVITY_ERROR_NOT_SUPPORTED :
+ strcpy(error,"ACTIVITY_ERROR_NOT_SUPPORTED");
+ break;
+ case ACTIVITY_ERROR_OPERATION_FAILED:
+ strcpy(error,"ACTIVITY_ERROR_OPERATION_FAILED");
+ break;
+ case ACTIVITY_ERROR_OUT_OF_MEMORY:
+ strcpy(error,"ACTIVITY_ERROR_OUT_OF_MEMORY");
+ break;
+ case ACTIVITY_ERROR_PERMISSION_DENIED:
+ strcpy(error,"ACTIVITY_ERROR_PERMISSION_DENIED");
+ break;
+ default:
+ strcpy(error, "Unrecognized Error");
+ }
+ return strdup(error);
+ }
+
+
+
+/**
+ * @function _motion_get_activity_type
+ * @since_tizen 3.0
+ * @description Return string name of Activity detected
+ * @parameter activity_type_e activity_type
+ * @return static char *
+ */
+static char * _motion_get_activity_type(activity_type_e activity_type)
+{
+ DBG("_motion_get_activity_type");
+ const int LEN = 100;
+ char string[LEN];
+ switch(activity_type)
+ {
+ case ACTIVITY_STATIONARY :
+ snprintf(string, LEN, "Activity Stationary");
+ DBG("ACTIVITY_STATIONARY ");
+ break;
+ case ACTIVITY_WALK:
+ snprintf(string, LEN, "Activity is Walking");
+ DBG("ACTIVITY_WALK");
+ break;
+ case ACTIVITY_RUN:
+ snprintf(string, LEN, "Activity is Running");
+ DBG("ACTIVITY_RUN");
+ break;
+ case ACTIVITY_IN_VEHICLE :
+ snprintf(string, LEN, "Activity is In Vehicle");
+ DBG("ACTIVITY_IN_VEHICLE ");
+ break;
+ default :
+ snprintf(string, LEN, "Unrecognized Activity");
+ DBG("Unrecognized Activity");
+ }
+ return strdup(string);
+}
+
+
+/**
+ * @function _start_detection_button_pressed_cb
+ * @since_tizen 3.0
+ * @description Callback called when an activity is detected
+ * @parameter void
+ * @return void *data, Evas_Object *obj, void *event_info
+ */
+static void _start_detection_button_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ DBG(" start_detection_button_pressed_cb ");
+
+ RETM_IF(NULL == data, "data is NULL");
+
+ motion_detection_view *this = NULL;
+ this = (motion_detection_view*)data;
+ RETM_IF(NULL == this, "view is NULL");
+ activity_type_e activity_type = ACTIVITY_STATIONARY;
+
+ int nRet = activity_start_recognition(this->handle, activity_type, activity_recognition_callback_check_type, this);
+
+ if(nRet != ACTIVITY_ERROR_NONE)
+ {
+ this->view->tbt_info->result = TBT_INFO_RESULT_NOT_SUPPORTED;
+ elm_genlist_item_update(this->view->item);
+ elm_naviframe_item_pop(this->view->navi);
+ activity_stop_recognition(this->handle);
+ activity_release(this->handle);
+ RETM_IF(nRet != ACTIVITY_ERROR_NONE, "activity_start_recognition failed for activity type = %s",_motion_get_activity_type(activity_type));
+ }
+}
+
+
+
+/**
+ * @function activity_recognition_callback_check_type
+ * @since_tizen 3.0
+ * @description To Check the activity type
+ * @parameter void
+ * @return activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void *user_data
+ */
+static void activity_recognition_callback_check_type(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void *user_data)
+{
+ char label[200]={'\0'};
+ DBG("activity_recognition_callback_check_type");
+ RETM_IF(NULL == user_data, "User data is NULL");
+ motion_detection_view *this = (motion_detection_view*)user_data;
+ snprintf(label, sizeof(label), "%s : %s" , "Activity Status is ", _motion_get_activity_type(activity));
+ ui_utils_label_set_text(this->activity_label, label, "left");
+ return;
+}
+
+
+
+/**
+ * @function _stop_detection_button_pressed_cb
+ * @since_tizen 3.0
+ * @description To handle stop detection button pressed event
+ * @parameter void
+ * @return void *data, Evas_Object *obj, void *event_info
+ */
+
+
+static void _stop_detection_button_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ DBG(" _stop_detection_button_pressed_cb ");
+ RETM_IF(NULL == data, "data is NULL");
+ motion_detection_view *this = NULL;
+ this = (motion_detection_view*)data;
+ RETM_IF(NULL == this, "view is NULL");
+ activity_stop_recognition(this->handle);
+ activity_release(this->handle);
+}
+
+
+/**
+ * @function add_control_layout
+ * @since_tizen 3.0
+ * @description To add buttons to the view
+ * @parameter void
+ * @return motion_detection_view *this, Evas_Object *parent
+ */
+
+static Evas_Object *add_control_layout(motion_detection_view *this, Evas_Object *parent)
+{
+ DBG("add_control_layout__");
+
+ RETVM_IF(NULL == this, NULL, "view is NULL");
+ RETVM_IF(NULL == parent, NULL, "parent is NULL");
+
+ Evas_Object *table = elm_table_add(parent);
+
+ evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(table);
+
+ this->start_detection_button = ui_utils_push_button_add(this, table, "Start Detection", _start_detection_button_pressed_cb);
+ RETVM_IF(NULL == this->start_detection_button, NULL, "this->start_detection_button is NULL");
+ elm_table_pack(table, this->start_detection_button, 0, 0, 1, 1);
+ this->stop_detection_button= ui_utils_push_button_add(this, table, "Stop Detection", _stop_detection_button_pressed_cb);
+ RETVM_IF(NULL == this->stop_detection_button, NULL, "this->stop_detection_button is NULL");
+ elm_table_pack(table, this->stop_detection_button, 1, 0, 1, 1);
+
+ return table;
+}
+
+
+/**
+ * @function _app_destroy_cb
+ * @since_tizen 2.3
+ * @description App Destroy Cb
+ * @parameter void*: Void Pointer
+ * @return static void
+ */
+static void _app_destroy_cb(void* this)
+{
+ RETM_IF(NULL == this, "data is NULL");
+
+ motion_detection_view *view = NULL;
+ view = (motion_detection_view*)this;
+ RETM_IF(NULL == view, "view is NULL");
+
+ SAFE_DELETE(view->view);
+ SAFE_DELETE(view);
+}
+
+#endif