Subtitle popup as a separate view 51/59451/6
authorAgnieszka Janowicz <a.janowicz@samsung.com>
Mon, 15 Feb 2016 13:09:46 +0000 (14:09 +0100)
committerAgnieszka Janowicz <a.janowicz@samsung.com>
Tue, 16 Feb 2016 10:13:27 +0000 (11:13 +0100)
Change-Id: Id0437c8139fba9a8e988aaa9bfba32b20b3c4cfb
Signed-off-by: Agnieszka Janowicz <a.janowicz@samsung.com>
CMakeLists.txt
include/data/system/settings_language.h
include/define.h
include/view/system/view_subtitle.h [new file with mode: 0644]
res/settings.edc
res/view/common/popup_2btns.edc [moved from res/view/system/language.edc with 98% similarity]
src/data/system/settings_language.c
src/layout/layout_system.c
src/main.c
src/view/system/view_language.c
src/view/system/view_subtitle.c [new file with mode: 0644]

index e89d1b5..a06b684 100644 (file)
@@ -68,6 +68,7 @@ SET(SRCS
        src/view/system/view_wakeup_timer.c
        src/view/system/view_pincode.c
        src/view/system/view_language.c
+       src/view/system/view_subtitle.c
        src/view/system/view_location.c
        src/view/view_new_network.c
        src/common/utils.c
index e641a4c..c829778 100644 (file)
@@ -36,4 +36,11 @@ char *settings_language_get_language_locale_str(void);
 /* Gets current display language string. */
 char *settings_language_get_language_display_str(void);
 
+/* Sets current subtitle language */
+void settings_language_set_subtitle_language(settings_language_type lang_type);
+/* Gets current subtitle language ID */
+settings_language_type settings_language_get_subtitle_language_id(void);
+/* Gets current display subtitlelanguage string. */
+char *settings_language_get_subtitle_language_display_str(void);
+
 #endif /* __AIR_SETTINGS_WAKEUP_TIMER_H__ */
index 8b45a33..614220d 100644 (file)
@@ -33,6 +33,7 @@
 #define VIEW_WAKEUP_TIMER "VIEW_WAKEUP_TIMER"
 #define VIEW_SLEEP_TIMER "VIEW_SLEEP_TIMER"
 #define VIEW_LANGUAGE "VIEW_LANGUAGE"
+#define VIEW_SUBTITLE "VIEW_SUBTITLE"
 
 /* Layout ID */
 #define LAYOUT_ID_PICTURE "LAYOUT_ID_PICTURE"
@@ -52,7 +53,8 @@
 #define GRP_VIEW_NEW_NETWORK "grp.view.new_network"
 #define GRP_VIEW_WAKEUP_TIMER "grp.view.wakeup_timer"
 #define GRP_VIEW_SLEEP_TIMER "grp.view.sleep_timer"
-#define GRP_VIEW_LANGUAGE "grp.view.language"
+
+#define GRP_VIEW_POPUP_2BTNS "grp.view.popup_2btns"
 
 /* Part for EDC */
 #define PART_TOP_TITLE "part.top.title"
 #define STR_LANGUAGE "Language"
 #define STR_LOCATION "Location"
 #define STR_SLEEP_TIMER "Sleep timer"
+#define STR_SUBTITLE "Subtitle"
 
 /* Size */
 #define SIZE_STR 1024
diff --git a/include/view/system/view_subtitle.h b/include/view/system/view_subtitle.h
new file mode 100644 (file)
index 0000000..7bf6a4b
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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 __AIR_SETTINGS_VIEW_SUBTITLE_H__
+#define __AIR_SETTINGS_VIEW_SUBTITLE_H__
+
+view_class *view_subtitle_get_vclass(void);
+
+#endif /* __AIR_SETTINGS_VIEW_SUBTITLE_H__ */
index eeaf103..dca6e7d 100644 (file)
 collections {
        base_scale: APP_BASE_SCALE;
        #include "view/base.edc"
+       #include "view/common/popup_2btns.edc"
        #include "view/system/clock.edc"
        #include "view/system/sleep_timer.edc"
        #include "view/system/wakeup_timer.edc"
        #include "view/system/pin.edc"
-       #include "view/system/language.edc"
        #include "view/system/location.edc"
        #include "layout/picture.edc"
        #include "layout/channel.edc"
similarity index 98%
rename from res/view/system/language.edc
rename to res/view/common/popup_2btns.edc
index 8824b3b..9abfaf3 100644 (file)
@@ -1,5 +1,5 @@
 group {
-       name, GRP_VIEW_LANGUAGE;
+       name, GRP_VIEW_POPUP_2BTNS;
        parts {
                part {
                        name, "area";
index babce9e..888dff4 100644 (file)
@@ -91,3 +91,20 @@ char *settings_language_get_language_display_str(void)
 
        return strdup(name);
 }
+
+void settings_language_set_subtitle_language(settings_language_type lang_type)
+{
+       //@TODO: set subtitle language
+}
+
+settings_language_type settings_language_get_subtitle_language_id(void)
+{
+       //@TODO: get subtitle language
+       return LANG_TYPE_ENG;
+}
+
+char *settings_language_get_subtitle_language_display_str(void)
+{
+       //@TODO: get subtitle language and corresponding display string
+       return strdup("English");
+}
index ed0b87c..da5815b 100644 (file)
@@ -63,6 +63,7 @@ static char *_get_status(void *data, int id);
 static char *_get_clock_mode(void *data, int id);
 static char *_get_sleep_timer(void *data, int id);
 static char *_get_language(void *data, int id);
+static char *_get_subtitle(void *data, int id);
 static char *_get_location(void *data, int id);
 
 static void _selected(void *data, int id);
@@ -110,10 +111,10 @@ static struct menumgr_info menu_info[] = {
        },
        {
                .id = MENU_SUBTITLE,
-               .title = "Subtitile",
+               .title = STR_SUBTITLE,
                .style = STYLE_STATUS_BTN,
                .disabled = EINA_FALSE,
-               .status = _get_status,
+               .status = _get_subtitle,
                .selected = _selected,
        },
        {
@@ -162,6 +163,11 @@ static char *_get_language(void *data, int id)
        return settings_language_get_language_display_str();
 }
 
+static char *_get_subtitle(void *data, int id)
+{
+       return settings_language_get_subtitle_language_display_str();
+}
+
 static char *_get_location(void *data, int id)
 {
        char *country = NULL;
@@ -224,6 +230,10 @@ static void _selected(void *data, int id)
                        if (!viewmgr_show_view(VIEW_LANGUAGE))
                                _ERR("Push Language view failed.");
                                break;
+               case MENU_SUBTITLE:
+                       if (!viewmgr_show_view(VIEW_SUBTITLE))
+                               _ERR("Push Language view failed.");
+                               break;
                default:
                        _ERR("Invalid menu.");
        }
index cfb8a4d..2216310 100644 (file)
@@ -27,6 +27,7 @@
 #include "view/system/view_wakeup_timer.h"
 #include "view/system/view_pincode.h"
 #include "view/system/view_language.h"
+#include "view/system/view_subtitle.h"
 #include "data/system/settings_language.h"
 
 struct _appdata {
@@ -191,6 +192,11 @@ static bool _create_system_ui(void)
                return false;
        }
 
+       if (!viewmgr_add_view(view_subtitle_get_vclass(), NULL)) {
+               _ERR("Add view failed.");
+               return false;
+       }
+
        if (!viewmgr_add_view(view_location_get_vclass(), NULL)) {
                _ERR("Adding location view failed.");
                return false;
@@ -216,6 +222,9 @@ static void _destroy_system_ui(void)
        if (!viewmgr_remove_view(VIEW_LANGUAGE))
                _ERR("Remove language view failed.");
 
+       if (!viewmgr_remove_view(VIEW_SUBTITLE))
+               _ERR("Remove view failed.");
+
        if (!viewmgr_remove_view(VIEW_LOCATION))
                _ERR("Remove location view failed.");
 }
index 2ecf0aa..c9aca6b 100644 (file)
@@ -16,9 +16,6 @@
 
 #include <app.h>
 #include <Elementary.h>
-#include <system_settings.h>
-#include <utils_i18n.h>
-#include <vconf.h>
 
 #include "app_debug.h"
 #include "define.h"
@@ -100,7 +97,7 @@ static Evas_Object *_create(Evas_Object *win, void *data)
                return NULL;
        }
 
-       ly = utils_add_layout(priv->base, GRP_VIEW_LANGUAGE, EINA_FALSE);
+       ly = utils_add_layout(priv->base, GRP_VIEW_POPUP_2BTNS, EINA_FALSE);
        if (!ly) {
                _ERR("Add layout failed.");
                evas_object_del(priv->base);
@@ -113,6 +110,7 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        if (!_fill_popup_btns(priv, ly, LANG_TYPE_MAX, PART_POPUP_BUTTON_X,
                        language_option, EO_BTN_LANG_ENG)) {
                evas_object_del(priv->base);
+               free(priv);
                return NULL;
        }
 
diff --git a/src/view/system/view_subtitle.c b/src/view/system/view_subtitle.c
new file mode 100644 (file)
index 0000000..1db9fab
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * 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 <app.h>
+#include <Elementary.h>
+
+#include "app_debug.h"
+#include "define.h"
+#include "common/viewmgr.h"
+#include "common/inputmgr.h"
+#include "common/utils.h"
+#include "data/system/settings_language.h"
+#include "view/system/view_subtitle.h"
+
+#define STR_SUBTITLE_DES "Select language."
+#define PART_POPUP_BUTTON_X "part.popup.btn%d"
+#define PART_POPUP_BUTTON_MAX_L 24
+
+struct _priv {
+       Evas_Object *base;
+       Evas_Object *popup_btn[LANG_TYPE_MAX];
+};
+
+enum language_eo_type {
+       EO_BTN_LANG_ENG = 0,
+       EO_BTN_LANG_KOR
+};
+
+static void _clicked_cb(int id, void *data, Evas_Object *obj);
+static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
+       Evas_Event_Key_Down *ev);
+
+static char *subtitle_option[LANG_TYPE_MAX] = { "English", "Korean"};
+
+static input_handler handler = {
+       .key_down = _key_down_cb,
+       .clicked = _clicked_cb
+};
+
+static bool _fill_popup_btns(struct _priv *priv, Evas_Object *layout,
+       int btn_count, char *btn_part_x, char **btn_text, int first_btn_eo)
+{
+       Evas_Object *btn = NULL;
+       int i;
+
+       for(i = 0; i < btn_count; i++) {
+               char part_name[PART_POPUP_BUTTON_MAX_L] = {0, };
+               snprintf(part_name, sizeof(part_name), btn_part_x, i+1);
+
+               btn = utils_add_button(layout, part_name, NULL, btn_text[i]);
+               if (!btn) {
+                       _ERR("Add button failed.");
+                       return false;
+               }
+
+               priv->popup_btn[i] = btn;
+
+               inputmgr_add_callback(btn, first_btn_eo+i, &handler, priv);
+       }
+
+       return true;
+}
+
+static Evas_Object *_create(Evas_Object *win, void *data)
+{
+       struct _priv *priv = NULL;
+       Evas_Object *ly = NULL;
+
+       if (!win) {
+               _ERR("Get window object failed.");
+               return NULL;
+       }
+
+       priv = calloc(1, sizeof(struct _priv *));
+       if (!priv) {
+               _ERR("Calloc failed.");
+               return NULL;
+       }
+
+       priv->base = utils_add_popup(win, NULL, STR_SUBTITLE, NULL);
+       if (!priv->base) {
+               _ERR("Add popup failed");
+               free(priv);
+               return NULL;
+       }
+
+       ly = utils_add_layout(priv->base, GRP_VIEW_POPUP_2BTNS, EINA_FALSE);
+       if (!ly) {
+               _ERR("Add layout failed.");
+               evas_object_del(priv->base);
+               free(priv);
+               return NULL;
+       }
+
+       elm_object_part_text_set(ly, PART_POPUP_NAME, STR_SUBTITLE_DES);
+
+       if (!_fill_popup_btns(priv, ly, LANG_TYPE_MAX, PART_POPUP_BUTTON_X,
+                       subtitle_option, EO_BTN_LANG_ENG)) {
+               evas_object_del(priv->base);
+               free(priv);
+               return NULL;
+       }
+
+       elm_object_content_set(priv->base, ly);
+
+       if (!viewmgr_set_view_data(VIEW_SUBTITLE, priv)) {
+               _ERR("Set view data failed.");
+               evas_object_del(priv->base);
+               free(priv);
+               return NULL;
+       }
+
+       return priv->base;
+}
+
+static void _show(void *data)
+{
+       struct _priv *priv = (struct _priv *)data;
+       int lang_id = 0;
+
+       if (!priv) {
+               _ERR("Invalid parameter.");
+               return;
+       }
+
+       evas_object_show(priv->base);
+
+       /* Set Focus */
+       lang_id = settings_language_get_subtitle_language_id();
+
+       if(lang_id != LANG_TYPE_MAX)
+               elm_object_focus_set(priv->popup_btn[lang_id], EINA_TRUE);
+}
+
+static void _hide(void *data)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!priv) {
+               _ERR("Invalid parameter.");
+               return;
+       }
+
+       evas_object_hide(priv->base);
+}
+
+static void _destroy(void *data)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!priv) {
+               _ERR("Invalid parameter.");
+               return;
+       }
+
+       evas_object_del(priv->base);
+
+       free(priv);
+}
+
+static view_class _vclass = {
+       .view_id = VIEW_SUBTITLE,
+       .create = _create,
+       .show = _show,
+       .hide = _hide,
+       .destroy = _destroy
+};
+
+view_class *view_subtitle_get_vclass(void)
+{
+       return &_vclass;
+}
+
+static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!ev || !priv) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       if (!strcmp(ev->keyname, KEY_BACK))
+               viewmgr_pop_view();
+}
+
+static void _clicked_cb(int id, void *data, Evas_Object *obj)
+{
+       struct _priv *priv = (struct _priv *)data;
+
+       if (!priv || !obj) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       switch (id) {
+       case EO_BTN_LANG_ENG:
+               settings_language_set_subtitle_language(LANG_TYPE_ENG);
+               break;
+       case EO_BTN_LANG_KOR:
+               settings_language_set_subtitle_language(LANG_TYPE_KOR);
+               break;
+       default:
+               _ERR("Unhandled object type.");
+       }
+
+       viewmgr_pop_view();
+}