View: Make the favorite button to be toggled 77/46477/1 accepted/tizen/tv/20150821.130443 submit/tizen/20150821.101452
authorHyojung Jo <hj903.jo@samsung.com>
Fri, 21 Aug 2015 02:22:51 +0000 (11:22 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Fri, 21 Aug 2015 02:22:51 +0000 (11:22 +0900)
Change-Id: I6488a7fdfc7ff1455fc14203036796589fea3d21
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
include/define.h
include/view.h [new file with mode: 0644]
include/view_base.h [deleted file]
res/images/btn_menu_unlock_foc.png [new file with mode: 0644]
res/images/btn_menu_unlock_nor.png [new file with mode: 0644]
res/widget/button.edc
src/main.c
src/view/view_action_menu.c
src/view/view_base.c

index 8694cde587f36d3f38be252620b556c2828efb47..d2918fe7e29e18d30276a7485ca271a3c3c1f6e2 100644 (file)
@@ -69,6 +69,7 @@
 #define SIG_VISIBLE "visible"
 #define SIG_INVISIBLE "invisible"
 #define SIG_DISABLE "elm,state,disabled"
+#define SIG_TOGGLE "toggle"
 
 /* Signal Source */
 #define SRC_MYAPPS "source.myapps"
 #define ACTION_FAV_FOC_PNG "btn_menu_favorite_foc.png"
 #define ACTION_FAV_SEL_PNG "btn_menu_favorite_sel.png"
 #define ACTION_FAV_DIS_PNG "btn_menu_favorite_dis.png"
+#define ACTION_UNLOCK_NOR_PNG "btn_menu_unlock_nor.png"
+#define ACTION_UNLOCK_FOC_PNG "btn_menu_unlock_foc.png"
 #define ACTION_LOCK_NOR_PNG "btn_menu_lock_nor.png"
 #define ACTION_LOCK_FOC_PNG "btn_menu_lock_foc.png"
 #define ACTION_LOCK_SEL_PNG "btn_menu_lock_sel.png"
diff --git a/include/view.h b/include/view.h
new file mode 100644 (file)
index 0000000..8f72e9c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 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_APPS_VIEW_H__
+#define __AIR_APPS_VIEW_H__
+
+view_class *view_base_get_vclass(void);
+view_class *view_action_menu_get_vclass(void);
+
+enum update_type {
+       UPDATE_ID = 0,
+       UPDATE_FAVORITE,
+};
+
+#endif /* __AIR_APPS_VIEW_H__ */
diff --git a/include/view_base.h b/include/view_base.h
deleted file mode 100644 (file)
index 0afd592..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2015 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_APPS_VIEW_BASE_H__
-#define __AIR_APPS_VIEW_BASE_H__
-
-view_class *view_base_get_vclass(void);
-
-#endif /* __AIR_APPS_VIEW_BASE_H__ */
diff --git a/res/images/btn_menu_unlock_foc.png b/res/images/btn_menu_unlock_foc.png
new file mode 100644 (file)
index 0000000..8e35489
Binary files /dev/null and b/res/images/btn_menu_unlock_foc.png differ
diff --git a/res/images/btn_menu_unlock_nor.png b/res/images/btn_menu_unlock_nor.png
new file mode 100644 (file)
index 0000000..fb89ee9
Binary files /dev/null and b/res/images/btn_menu_unlock_nor.png differ
index 0b64902d6bcbc2a0c7ef7d72bf12d73f57414875..6790f23c1fb72b8d457eb3beddda55a7700305e1 100644 (file)
@@ -17,6 +17,7 @@
 #define STATE_NORMAL 0
 #define STATE_SELECTED 1
 #define STATE_DISABLE 2
+#define STATE_TOGGLE 3
 
 group {
        name, "elm/button/base/style.menu.button";
@@ -1140,11 +1141,23 @@ group {
                                fixed, 1 1;
                                min, 60 60;
                        }
+                       description {
+                               state, "default.toggle" 0.0;
+                               inherit, "default" 0.0;
+                               /* It will be fixed to another image later */
+                               image.normal, ACTION_FAV_NOR_PNG;
+                       }
                        description {
                                state, "focused" 0.0;
                                inherit, "default" 0.0;
                                image.normal, ACTION_FAV_FOC_PNG;
                        }
+                       description {
+                               state, "focused.toggle" 0.0;
+                               inherit, "default" 0.0;
+                               /* It will be fixed to another image later */
+                               image.normal, ACTION_FAV_FOC_PNG;
+                       }
                        description {
                                state, "selected" 0.0;
                                inherit, "default" 0.0;
@@ -1228,6 +1241,29 @@ group {
        }
 
        programs{
+               program {
+                       name, "load";
+                       signal, "load";
+                       source, "";
+                       script {
+                               set_int(cur_state, STATE_NORMAL);
+                       }
+               }
+
+               program {
+                       name, SIG_TOGGLE;
+                       signal, SIG_TOGGLE;
+                       source, SRC_ACTION_BTN;
+                       script {
+                               new state;
+                               state = get_int(cur_state);
+                               if (state == STATE_NORMAL) {
+                                       set_int(cur_state, STATE_TOGGLE);
+                                       set_state(PART:"part.icon", "default.toggle", 0.0);
+                               }
+                       }
+               }
+
                program {
                        name, SIG_FOCUSED;
                        signal, "elm,action,focus";
@@ -1235,8 +1271,11 @@ group {
                        script {
                                new state;
                                state = get_int(cur_state);
-                               if (state != STATE_DISABLE) {
-                                       set_int(cur_state, STATE_NORMAL);
+                               if (state == STATE_NORMAL) {
+                                       set_state(PART:"part.icon", "focused", 0.0);
+                                       run_program(PROGRAM:"focused,anim");
+                               } else if (state == STATE_TOGGLE) {
+                                       set_state(PART:"part.icon", "focused.toggle", 0.0);
                                        run_program(PROGRAM:"focused,anim");
                                }
                        }
@@ -1249,11 +1288,11 @@ group {
                        script {
                                new state;
                                state = get_int(cur_state);
-                               if (state == STATE_SELECTED) {
-                                       set_state(PART:"part.bg", "selected", 0.0);
-                                       set_state(PART:"elm.text", "selected", 0.0);
-                                       set_state(PART:"part.icon", "selected", 0.0);
+                               if (state == STATE_NORMAL) {
+                                       set_state(PART:"part.icon", "default", 0.0);
+                                       run_program(PROGRAM:"unfocused,anim");
                                } else if (state != STATE_DISABLE) {
+                                       set_state(PART:"part.icon", "default.toggle", 0.0);
                                        run_program(PROGRAM:"unfocused,anim");
                                }
                        }
@@ -1264,7 +1303,6 @@ group {
                        action, STATE_SET "focused" 0.0;
                        target, "part.bg";
                        target, "elm.text";
-                       target, "part.icon";
                        transition, TRANSITION_FOCUS;
                }
 
@@ -1273,7 +1311,6 @@ group {
                        action, STATE_SET "default" 0.0;
                        target, "part.bg";
                        target, "elm.text";
-                       target, "part.icon";
                        transition, TRANSITION_FOCUS;
                }
 
@@ -1284,11 +1321,12 @@ group {
                        script {
                                new state;
                                state = get_int(cur_state);
-                               if (state != STATE_DISABLE) {
-                                       set_int(cur_state, STATE_SELECTED);
-                                       set_state(PART:"part.bg", "selected", 0.0);
-                                       set_state(PART:"elm.text", "selected", 0.0);
-                                       set_state(PART:"part.icon", "selected", 0.0);
+                               if (state == STATE_NORMAL) {
+                                       set_int(cur_state, STATE_TOGGLE);
+                                       set_state(PART:"part.icon", "focused.toggle", 0.0);
+                               } else if (state == STATE_TOGGLE) {
+                                       set_int(cur_state, STATE_NORMAL);
+                                       set_state(PART:"part.icon", "focused", 0.0);
                                }
                        }
                }
@@ -1320,6 +1358,8 @@ group {
        inherit, "elm/button/base/style.action.menu.favorite.button";
        data.item, "focus_highlight" "on";
        images {
+               image, ACTION_UNLOCK_NOR_PNG COMP;
+               image, ACTION_UNLOCK_FOC_PNG COMP;
                image, ACTION_LOCK_NOR_PNG COMP;
                image, ACTION_LOCK_FOC_PNG COMP;
                image, ACTION_LOCK_SEL_PNG COMP;
@@ -1343,11 +1383,21 @@ group {
                                align, 0.5 0.5;
                                fixed, 1 1;
                                min, 60 60;
+                               image.normal, ACTION_UNLOCK_NOR_PNG;
+                       }
+                       description {
+                               state, "default.toggle" 0.0;
+                               inherit, "default" 0.0;
                                image.normal, ACTION_LOCK_NOR_PNG;
                        }
                        description {
                                state, "focused" 0.0;
                                inherit, "default" 0.0;
+                               image.normal, ACTION_UNLOCK_FOC_PNG;
+                       }
+                       description {
+                               state, "focused.toggle" 0.0;
+                               inherit, "default" 0.0;
                                image.normal, ACTION_LOCK_FOC_PNG;
                        }
                        description {
@@ -1394,11 +1444,21 @@ group {
                                min, 60 60;
                                image.normal, ACTION_UNINSTALL_NOR_PNG;
                        }
+                       description {
+                               state, "default.toggle" 0.0;
+                               inherit, "default" 0.0;
+                               image.normal, ACTION_UNINSTALL_NOR_PNG;
+                       }
                        description {
                                state, "focused" 0.0;
                                inherit, "default" 0.0;
                                image.normal, ACTION_UNINSTALL_FOC_PNG;
                        }
+                       description {
+                               state, "focused.toggle" 0.0;
+                               inherit, "default" 0.0;
+                               image.normal, ACTION_UNINSTALL_FOC_PNG;
+                       }
                        description {
                                state, "selected" 0.0;
                                inherit, "default" 0.0;
index 89a4668d1479e04776df1a0f50a23afdec88ba32..40bca6642721f5036ba4a162a1752bc8ab8442d8 100644 (file)
@@ -21,8 +21,7 @@
 
 #include "define.h"
 #include "utils.h"
-#include "view_base.h"
-#include "view_action_menu.h"
+#include "view.h"
 
 SET_TAG(PACKAGE);
 
index c339b2dfb944ecad1a87cbf08cceff0d42e320b5..a7ae121a78ab1b783f19a34c5aa9b81fddab25f0 100644 (file)
 #include <viewmgr.h>
 #include <inputmgr.h>
 #include <gridmgr.h>
+#include <app_contents.h>
 #include <app_debug.h>
 
 #include "define.h"
 #include "utils.h"
+#include "view.h"
 #include "data/app.h"
 #include "grid.h"
 
@@ -33,6 +35,7 @@ enum action_type {
 };
 
 struct _priv {
+       const char *appid;
        Evas_Object *win;
        Evas_Object *base;
        Evas_Object *grid;
@@ -47,6 +50,7 @@ struct _action_info {
        const char *title;
        const char *style;
        Eina_Bool disable;
+       Eina_Bool toggle;
 };
 
 static struct _action_info action_info[] = {
@@ -60,13 +64,15 @@ static struct _action_info action_info[] = {
                .id = BTN_LOCK,
                .title = STR_LOCK,
                .style = STYLE_ACTION_MENU_LOCK_BTN,
-               .disable = EINA_TRUE
+               .disable = EINA_TRUE,
+               .toggle = EINA_FALSE
        },
        {
                .id = BTN_UNINSTALL,
                .title = STR_UNINSTALL,
                .style = STYLE_ACTION_MENU_UNINSTALL_BTN,
-               .disable = EINA_TRUE
+               .disable = EINA_TRUE,
+               .toggle = EINA_FALSE
        }
 };
 
@@ -82,14 +88,39 @@ static void _mouse_move_cb(int id, void *data, Evas *e, Evas_Object *obj,
                elm_object_focus_set(obj, EINA_TRUE);
 }
 
-static void _favorite_selected(void *data, Evas_Object *obj)
+static void _livetv_selected(void *data, Evas_Object *obj)
 {
        /* It will be implemented later */
 }
 
-static void _livetv_selected(void *data, Evas_Object *obj)
+static void _favorite_selected(void *data, Evas_Object *obj)
 {
-       /* It will be implemented later */
+       struct _priv *priv;
+       int r;
+       bool isfavorite;
+
+       if (!data) {
+               _ERR("Invalid argument.");
+               return;
+       }
+       priv = data;
+
+       if (!priv->appid)
+               return;
+
+       r = app_contents_favorite_check(CONTENTS_APP, priv->appid, &isfavorite);
+       if (r != APP_CONTENTS_ERROR_NONE) {
+               _ERR("Favorite check failed.");
+               return;
+       }
+
+       r = app_contents_favorite_set(CONTENTS_APP, priv->appid, !isfavorite);
+       if (r != APP_CONTENTS_ERROR_NONE) {
+               _ERR("Favorite set failed.");
+               return;
+       }
+
+       elm_object_signal_emit(obj, SIG_SELECTED, SRC_ACTION_BTN);
 }
 
 static void _clicked_cb(int id, void *data, Evas_Object *obj)
@@ -242,7 +273,33 @@ static bool _draw_livetv_area(struct _priv *priv)
        return true;
 }
 
-static bool _draw_menu_area(struct _priv *priv)
+void _set_action_state(int idx, Evas_Object *btn, const char *appid)
+{
+       bool isfavorite;
+
+       if (!btn || !appid) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       if (action_info[idx].disable) {
+               elm_object_disabled_set(btn, EINA_TRUE);
+               return;
+       }
+
+       if (action_info[idx].id == BTN_FAVORITE) {
+               app_contents_favorite_check(CONTENTS_APP, appid, &isfavorite);
+               if (isfavorite)
+                       action_info[idx].toggle = EINA_TRUE;
+               else
+                       action_info[idx].toggle = EINA_FALSE;
+       }
+
+       if (action_info[idx].toggle)
+               elm_object_signal_emit(btn, SIG_TOGGLE, SRC_ACTION_BTN);
+}
+
+static bool _draw_action_area(struct _priv *priv)
 {
        Evas_Object *table, *btn;
        int i, row = 0, col = 0;
@@ -271,8 +328,7 @@ static bool _draw_menu_area(struct _priv *priv)
                inputmgr_add_callback(btn, action_info[i].id,
                                &_btn_input_handler, priv);
 
-               if (action_info[i].disable)
-                       elm_object_disabled_set(btn, EINA_TRUE);
+               _set_action_state(i, btn, priv->appid);
 
                col = i % SIZE_COL_MAX;
                row = i / SIZE_COL_MAX;
@@ -283,12 +339,16 @@ static bool _draw_menu_area(struct _priv *priv)
        }
 
        /* 'Favorite' can only be focused now. */
-       elm_object_focus_next_object_set(priv->menu_btn[0],
-                       priv->menu_btn[0], ELM_FOCUS_LEFT);
-       elm_object_focus_next_object_set(priv->menu_btn[0],
-                       priv->menu_btn[0], ELM_FOCUS_RIGHT);
+       elm_object_focus_next_object_set(priv->menu_btn[0], priv->menu_btn[0],
+                       ELM_FOCUS_LEFT);
+       elm_object_focus_next_object_set(priv->menu_btn[0], priv->menu_btn[0],
+                       ELM_FOCUS_RIGHT);
        elm_object_focus_next_object_set(priv->live_btn, priv->menu_btn[0],
                        ELM_FOCUS_DOWN);
+       elm_object_focus_next_object_set(priv->menu_btn[0], priv->grid,
+                       ELM_FOCUS_DOWN);
+       elm_object_focus_next_object_set(priv->grid, priv->menu_btn[0],
+                       ELM_FOCUS_UP);
 
        return true;
 }
@@ -302,7 +362,7 @@ static bool _draw_favorite_area(struct _priv *priv)
 
        priv->fav_list = get_app_favorite_list();
        if (!priv->fav_list) {
-               //emit no contents signal
+               /* FIXME: No content message will be displayed */
                return true;
        }
 
@@ -313,11 +373,8 @@ static bool _draw_favorite_area(struct _priv *priv)
 
        elm_object_part_content_set(priv->base, PART_FAVORITE, priv->grid);
 
-       elm_object_focus_next_object_set(priv->menu_btn[0], priv->grid,
-                       ELM_FOCUS_DOWN);
-       elm_object_focus_next_object_set(priv->grid, priv->menu_btn[0],
-                       ELM_FOCUS_UP);
-       elm_object_focus_next_object_set(priv->grid, priv->grid, ELM_FOCUS_LEFT);
+       elm_object_focus_next_object_set(priv->grid, priv->grid,
+                       ELM_FOCUS_LEFT);
 
        return true;
 }
@@ -357,27 +414,6 @@ static Evas_Object *_add_grid(struct _priv *priv)
        return grid;
 }
 
-static void _draw_view_content(struct _priv *priv)
-{
-       if (!priv) {
-               _ERR("Invalid argument.");
-               return;
-       }
-
-       if (!_draw_livetv_area(priv)) {
-               _ERR("Draw livetv area failed.");
-               return;
-       }
-
-       if (!_draw_menu_area(priv)) {
-               _ERR("Draw menu area failed.");
-               return;
-       }
-
-       if (!_draw_favorite_area(priv))
-               _ERR("Draw favorite area failed.");
-}
-
 static Evas_Object *_create(Evas_Object *win, void *data)
 {
        struct _priv *priv;
@@ -427,7 +463,8 @@ static Evas_Object *_create(Evas_Object *win, void *data)
                goto end;
        }
 
-       _draw_view_content(priv);
+       _draw_livetv_area(priv);
+       _draw_favorite_area(priv);
 
        return base;
 
@@ -446,7 +483,7 @@ static void _show(void *data)
                _ERR("Get data failed.");
                return;
        }
-       priv = (struct _priv *)data;
+       priv = data;
 
        if (priv->base)
                evas_object_show(priv->base);
@@ -462,12 +499,34 @@ static void _hide(void *data)
                _ERR("Get data failed.");
                return;
        }
-       priv = (struct _priv *)data;
+       priv = data;
 
        if (priv->base)
                evas_object_hide(priv->base);
 }
 
+static void _update(void *view_data, int update_type, void *data)
+{
+       struct _priv *priv;
+       struct app_data *adata;
+
+       if (!view_data) {
+               _ERR("Get data failed.");
+               return;
+       }
+       priv = view_data;
+
+       if (update_type == UPDATE_ID) {
+               if (!data)
+                       return;
+
+               adata = data;
+               priv->appid = get_app_id(adata);
+
+               _draw_action_area(priv);
+       }
+}
+
 static void _destroy(void *data)
 {
        struct _priv *priv;
@@ -476,7 +535,7 @@ static void _destroy(void *data)
                _ERR("Get data failed.");
                return;
        }
-       priv = (struct _priv *)data;
+       priv = data;
 
        if (priv->gmgr)
                gridmgr_destroy(priv->gmgr);
@@ -492,6 +551,7 @@ static view_class _vclass = {
        .create = _create,
        .show = _show,
        .hide = _hide,
+       .update = _update,
        .destroy = _destroy,
 };
 
index 4dde6970697b29267dc6e41c05070a146e4aa428..254f1e84940d42a19f7b78b187aaf62b2f7bea70 100644 (file)
@@ -25,7 +25,7 @@
 #include "define.h"
 #include "utils.h"
 #include "data/app.h"
-#include "view_base.h"
+#include "view.h"
 #include "grid.h"
 
 enum menu_type {
@@ -596,6 +596,7 @@ static void _grid_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
                Evas_Event_Key_Down *ev)
 {
        struct _priv *priv;
+       struct app_data *adata;
 
        if (!data || !ev) {
                _ERR("Invalid argument.");
@@ -604,14 +605,17 @@ static void _grid_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
        priv = data;
 
        if (!strcmp(ev->keyname, KEY_BACK)
-                       || !strcmp(ev->keyname, KEY_BACK_REMOTE))
+                       || !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
                elm_object_focus_set(priv->focused_menu, EINA_TRUE);
-       /* FIXME: The action menu is blocked temporarily. */
-       /*
-       else if (!strcmp(ev->keyname, KEY_MENU)
-                       || !strcmp(ev->keyname, KEY_MENU_REMOTE))
+       } else if (!strcmp(ev->keyname, KEY_MENU)
+                       || !strcmp(ev->keyname, KEY_MENU_REMOTE)) {
+               adata = elm_object_item_data_get(priv->focused_item);
+               if (!adata)
+                       return;
+
+               viewmgr_update_view(VIEW_ACTION_MENU, UPDATE_ID, adata);
                viewmgr_show_view(VIEW_ACTION_MENU);
-       */
+       }
 }
 
 static input_handler _menu_input_handler = {