Change selector to a popup window. 49/48049/1
authorshoum.chen@samsung.com <shoum.chen@samsung.com>
Fri, 11 Sep 2015 01:50:51 +0000 (09:50 +0800)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 11 Sep 2015 10:45:52 +0000 (19:45 +0900)
Change-Id: Ic01afeceb2f1b5a59b1012fe16048df5d9556984
Signed-off-by: shoum.chen@samsung.com <shoum.chen@samsung.com>
im_setting_list/CMakeLists.txt
im_setting_list/input_method_setting_list_popup_view.cpp [new file with mode: 0644]
im_setting_list/input_method_setting_list_popup_view.h [new file with mode: 0644]
im_setting_list/input_method_setting_list_ui.cpp

index 51d4a022a12c49cd093676dc7f266757bb83b42f..09945513e58b411659ff1f010c977af20b2d5e2b 100644 (file)
@@ -3,6 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 SET(SRC_LIST
     input_method_setting_list_ui.cpp
     input_method_setting_list.cpp
+    input_method_setting_list_popup_view.cpp
 )
 
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
diff --git a/im_setting_list/input_method_setting_list_popup_view.cpp b/im_setting_list/input_method_setting_list_popup_view.cpp
new file mode 100644 (file)
index 0000000..13e09b8
--- /dev/null
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2014 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 "input_method_setting_list.h"
+#include "input_method_setting_list_ui.h"
+#include "input_method_setting_list_popup_view.h"
+#include <string>
+#include <efl_extension.h>
+#include <vector>
+#include <isf_control.h>
+#include <algorithm>
+
+#define IM_SETTING_LIST_POPUP_VIEW_TITLE          dgettext(PACKAGE, "IDS_ST_HEADER_DEFAULT_KEYBOARD_ABB")
+#define IM_SETTING_SELECT_KEYBOARD                dgettext(PACKAGE, "IDS_IME_BODY_SELECT_KEYBOARD")
+
+static std::vector<ime_info_s>      g_active_ime_info_list;
+static Elm_Genlist_Item_Class       *itc_im_list = NULL;
+static Evas_Object                  *group_radio = NULL;
+static int                          g_active_ime_id = -1;
+
+typedef struct {
+    void        *data;
+    Evas_Object *popup;
+    int         index;
+}sel_cb_data;
+
+class ime_info_compare
+{
+    public:
+    bool operator()(const ime_info_s &first, const ime_info_s &sec)
+    {
+        return (strcasecmp(first.label, sec.label) < 0);
+    }
+};
+
+static void im_setting_list_sort_ime_info(std::vector<ime_info_s> &preinstall, std::vector<ime_info_s> &user)
+{
+    std::sort(preinstall.begin(), preinstall.end(), ime_info_compare());
+    std::sort(user.begin(), user.end(), ime_info_compare());
+    for(unsigned int i=0; i<preinstall.size(); ++i)
+    {
+        g_active_ime_info_list.push_back(preinstall[i]);
+    }
+    for(unsigned int i=0; i<user.size(); ++i)
+    {
+        g_active_ime_info_list.push_back(user[i]);
+    }
+}
+
+static void im_setting_list_load_active_ime_info(void)
+{
+    std::vector<ime_info_s>      active_ime_info_list_preinstall;
+    std::vector<ime_info_s>      active_ime_info_list_user;
+    g_active_ime_info_list.clear();
+    char *active_ime_appid = NULL;
+    isf_control_get_active_ime(&active_ime_appid);
+    ime_info_s *info = NULL;
+    int cnt = isf_control_get_all_ime_info(&info);
+    if (info)
+    {
+        for(int i=0; i<cnt; ++i)
+        {
+            SECURE_LOGD("%s %s %d %d %d", info[i].appid, info[i].label, info[i].is_enabled, info[i].is_preinstalled, info[i].has_option);
+            if (info[i].is_enabled && info[i].is_preinstalled)
+            {
+                active_ime_info_list_preinstall.push_back(info[i]);
+            }
+            else if (info[i].is_enabled)
+            {
+                active_ime_info_list_user.push_back(info[i]);
+            }
+        }
+        free(info);
+    }
+
+    im_setting_list_sort_ime_info(active_ime_info_list_preinstall, active_ime_info_list_user);
+    for(unsigned int i=0; i<g_active_ime_info_list.size(); ++i)
+    {
+        if (active_ime_appid && (!strcmp(active_ime_appid, g_active_ime_info_list[i].appid)))
+        {
+            g_active_ime_id = i;
+        }
+    }
+
+    if (active_ime_appid)
+    {
+        free(active_ime_appid);
+    }
+}
+
+static void im_setting_list_radio_change_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    /*save the checked ime*/
+    int index = (int)data;
+    if (index < 0 || index >= (int)g_active_ime_info_list.size()) {
+        LOGW("Wrong value. index : %d, g_active_ime_info_list.size () : %d\n", index, g_active_ime_info_list.size());
+        return;
+    }
+}
+
+static void im_setting_list_update_radio_state(Elm_Object_Item *item, Evas_Object *obj, int index)
+{
+    if (index < 0 || index >= (int)g_active_ime_info_list.size()) {
+        LOGW("Wrong value. index : %d, g_active_ime_info_list.size () : %d\n", index, g_active_ime_info_list.size());
+        return;
+    }
+
+    if (item && obj) {
+        elm_genlist_item_selected_set (item, EINA_FALSE);
+        /* Update check button */
+        Evas_Object *radio = elm_object_item_part_content_get (item, "elm.icon.right");
+        if (radio == NULL) {
+            radio = elm_object_item_part_content_get (item, "elm.icon");
+        }
+        evas_object_data_set (radio, "parent_genlist", obj);
+        elm_radio_value_set(radio, index);
+        isf_control_set_active_ime(g_active_ime_info_list[index].appid);
+    }
+}
+
+static void im_setting_list_ime_sel_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    sel_cb_data * cb_data = (sel_cb_data *)data;
+    int index = cb_data->index;
+    Evas_Object *popup = (Evas_Object *)cb_data->popup;
+
+    Elm_Object_Item *item = (Elm_Object_Item *)event_info;
+    if (!item){
+        delete cb_data;
+        return;
+    }
+    im_setting_list_update_radio_state(item, obj, index);
+    im_setting_list_update_window(cb_data->data);
+
+    evas_object_del(popup);
+    delete cb_data;
+}
+
+static Evas_Object *im_setting_list_genlist_create(Evas_Object* parent)
+{
+    Evas_Object *genlist = elm_genlist_add(parent);
+    elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+    elm_genlist_homogeneous_set (genlist, EINA_TRUE);
+    evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+    evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+    elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
+    evas_object_show(genlist);
+    return genlist;
+}
+
+static char *im_setting_list_genlist_item_label_get(void *data, Evas_Object *obj, const char *part)
+{
+    int index = (int)(data);
+    if (index < 0 || index >= (int)g_active_ime_info_list.size()) {
+        LOGW("Wrong value. index : %d, g_active_ime_info_list.size () : %d\n", index, g_active_ime_info_list.size());
+        return NULL;
+    }
+
+    if (!strcmp(part, "elm.text") ||
+        !strcmp(part, "elm.text.main") ||
+        !strcmp(part, "elm.text.main.left")) {
+        return strdup(g_active_ime_info_list[index].label);
+    }
+
+    return NULL;
+}
+
+static Evas_Object *im_setting_list_genlist_item_icon_get(void *data, Evas_Object *obj, const char *part)
+{
+    int index = (int)(data);
+    if (!strcmp(part, "elm.swallow.end") ||
+        !strcmp(part, "elm.icon.2")) {
+        Evas_Object *bx = elm_box_add(obj);
+        Evas_Object *radio = elm_radio_add(obj);
+        elm_object_style_set (radio, "list");
+        elm_radio_state_value_set(radio, index);
+        elm_radio_group_add(radio, group_radio);
+        evas_object_show(radio);
+        evas_object_smart_callback_add(radio, "changed", im_setting_list_radio_change_cb, (void *) (index));
+        elm_box_pack_end(bx, radio);
+
+        //for adjust UI
+        Evas_Object *label = elm_label_add(obj);
+        elm_object_text_set(label, "   ");
+        elm_box_pack_end(bx, label);
+        elm_box_horizontal_set(bx, EINA_TRUE);
+        evas_object_show(label);
+        return bx;
+    }
+    return NULL;
+}
+
+static void im_setting_list_genlist_item_class_create(void)
+{
+    itc_im_list = elm_genlist_item_class_new();
+    if (itc_im_list) {
+        itc_im_list->item_style = "1line";
+        itc_im_list->func.text_get = im_setting_list_genlist_item_label_get;
+        itc_im_list->func.content_get = im_setting_list_genlist_item_icon_get;
+        itc_im_list->func.state_get = NULL;
+        itc_im_list->func.del = NULL;
+    }
+}
+
+static Evas_Object *im_setting_list_list_create(Evas_Object *parent, void *data)
+{
+    im_setting_list_genlist_item_class_create();
+    Evas_Object *genlist = NULL;
+    genlist = im_setting_list_genlist_create(parent);
+    unsigned int i = 0;
+
+    /* keyboard list */
+    for (i = 0; i < g_active_ime_info_list.size(); i++) {
+        sel_cb_data *cb_data = new sel_cb_data;
+        cb_data->data = data;
+        cb_data->popup = parent;
+        cb_data->index = i;
+        elm_genlist_item_append(genlist,
+            itc_im_list,
+            (void *)(i),
+            NULL,
+            ELM_GENLIST_ITEM_NONE,
+            im_setting_list_ime_sel_cb,
+            (void *)(cb_data));
+    }
+    elm_radio_value_set(group_radio, g_active_ime_id);
+
+    return genlist;
+}
+
+static Evas_Object *im_setting_list_naviframe_create(Evas_Object* parent)
+{
+    Evas_Object *naviframe = elm_naviframe_add(parent);
+    elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_TRUE);
+    eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
+    evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+    evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL);
+    elm_object_part_content_set(parent, "elm.swallow.content", naviframe);
+    evas_object_show(naviframe);
+    return naviframe;
+}
+
+static void
+im_setting_list_popup_block_clicked_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
+{
+    evas_object_del(obj);
+}
+
+static void im_setting_list_popup_view_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    Evas_Object *popup = (Evas_Object *)data;
+    eext_object_event_callback_del(obj, EEXT_CALLBACK_BACK, im_setting_list_popup_view_back_cb);
+    evas_object_del(popup);
+}
+
+static Evas_Object *im_setting_list_popup_create(Evas_Object *parentWin, void *data)
+{
+    if (NULL == group_radio)
+    {
+        group_radio = elm_radio_add(parentWin);
+        elm_radio_state_value_set(group_radio, -1);
+    }
+
+    Evas_Object *popup = elm_popup_add(parentWin);
+    elm_popup_align_set (popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+    evas_object_smart_callback_add(popup, "block,clicked", im_setting_list_popup_block_clicked_cb, NULL);
+    elm_object_part_text_set(popup, "title,text", IM_SETTING_LIST_POPUP_VIEW_TITLE);
+    elm_object_style_set(popup, "theme_bg");
+    eext_object_event_callback_add (popup, EEXT_CALLBACK_BACK, im_setting_list_popup_view_back_cb, popup);
+
+    Evas_Object *genlist = im_setting_list_list_create(popup, data);
+    elm_object_content_set(popup, genlist);
+    evas_object_show(popup);
+    return popup;
+}
+
+void
+im_setting_list_popup_view_create(Evas_Object *parentWin, void *data)
+{
+    if (!parentWin)
+        return;
+    im_setting_list_load_active_ime_info();
+    im_setting_list_popup_create(parentWin, data);
+}
diff --git a/im_setting_list/input_method_setting_list_popup_view.h b/im_setting_list/input_method_setting_list_popup_view.h
new file mode 100644 (file)
index 0000000..9f4baac
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014 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 __INPUTMETHOD_SETTING_LIST_POPUP_VIEW_H
+#define __INPUTMETHOD_SETTING_LIST_POPUP_VIEW_H
+#include <Elementary.h>
+
+void im_setting_list_popup_view_create(Evas_Object *parentWin, void *data);
+
+#endif /* __INPUTMETHOD_SETTING_LIST_POPUP_VIEW_H */
+
index f1854d3323ed319be1615b74d2f2f075b42d6a90..6f0bdfdaa4eaf820524265ba56e00c5abb0c7c0b 100644 (file)
@@ -15,6 +15,7 @@
  *
  */
 #include "input_method_setting_list.h"
+#include "input_method_setting_list_popup_view.h"
 #include <string>
 #include <app.h>
 #include <efl_extension.h>
@@ -411,9 +412,11 @@ static void im_setting_list_item_sel_cb(void *data, Evas_Object *obj, void *even
 
 static void im_setting_list_set_default_keyboard_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
 {
+    appdata *ad = (appdata *)data;
     Elm_Object_Item *item = (Elm_Object_Item *)event_info;
     elm_genlist_item_selected_set (item, EINA_FALSE);
-    im_setting_list_show_ime_selector(data);
+//    im_setting_list_show_ime_selector(data);
+    im_setting_list_popup_view_create(ad->win, data);
 }
 
 static void im_setting_list_keyboard_setting_item_sel_cb(void *data, Evas_Object *obj, void *event_info)