找回密码
 立即注册
查看: 2741|回复: 0

Tizen设备表情符号选择器输入小部件代码

[复制链接]
发表于 2015-8-23 21:17:07 | 显示全部楼层 |阅读模式
这个代码展示了如何创建一个表情符号选择器输入小部件。 首先定义回调方法。 然后,有_insert_emoticon_cb保存一个网格的主要逻辑——创建一个inwin可用的表情符号。 这个测试的emoticon_test方法创建基本的UI。
  1. //gengrid item class methods
  2. static char *_emoticon_label_get(void *data, Evas_Object *obj, const char *part) {
  3.         return strdup(data);
  4. }

  5. static Evas_Object *_emoticon_content_get(void *data, Evas_Object *obj, const char *part) {
  6.         if (strcmp(part, "elm.swallow.icon"))
  7.                 return NULL;
  8.         Evas_Object *o = elm_layout_add(obj);
  9.         if (!elm_layout_theme_set(o, "entry/emoticon", data, "default")) {

  10.                 return NULL;
  11.         }
  12.         return o;
  13. }

  14. static void _emoticon_del(void *data, Evas_Object *obj) {
  15.         free(data);
  16. }

  17. //called when user chooses emoticon
  18. static void _emoticon_selected_cb(void *data, Evas_Object *obj, void *event) {
  19.         appdata_s *ad = data;
  20.         Elm_Object_Item *gg_it = event;
  21.         char *emoticon = elm_object_item_data_get(gg_it);
  22.         char buf[512];
  23.         snprintf(buf, sizeof(buf), "<item size=64x64 vsize=full href=emoticon/%s></item>", emoticon);
  24.         elm_entry_entry_insert(ad->entry, buf);
  25.         elm_object_focus_set(ad->entry, EINA_TRUE);
  26.         evas_object_del(ad->inwin);

  27. }

  28. //create grid with available emoticons
  29. static Evas_Object *create_emoticon_grid(appdata_s *ad) {
  30.         Elm_Gengrid_Item_Class *gic;
  31.         gic = elm_gengrid_item_class_new();
  32.         gic->item_style = "default";
  33.         gic->func.text_get = _emoticon_label_get;
  34.         gic->func.content_get = _emoticon_content_get;
  35.         gic->func.del = _emoticon_del;
  36.         
  37.         char* theme = elm_theme_list_item_path_get("default", NULL);
  38.         if (!theme)
  39.                 return NULL;
  40.         
  41.         Eina_List *emos = edje_file_collection_list(theme);
  42.         free(theme);
  43.         if (!emos)
  44.                 return NULL;

  45.         Evas_Object *grid = elm_gengrid_add(ad->win);
  46.         elm_gengrid_item_size_set(grid, 64, 80);
  47.         evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  48.         evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);

  49.         Eina_List *item;
  50.         char* emoticon;
  51.         EINA_LIST_FOREACH(emos, item, emoticon)
  52.         {
  53.                 char name[512];
  54.                 if (strncmp(emoticon, "elm/entry/emoticon/", 19))
  55.                         continue;
  56.                 sscanf(emoticon, "elm/entry/emoticon/%[^/]/default", name);
  57.                 elm_gengrid_item_append(grid, gic, strdup(name), _emoticon_selected_cb, ad);
  58.         }

  59.         edje_file_collection_list_free(emos);
  60.         elm_gengrid_item_class_free(gic);
  61.         return grid;
  62. }

  63. //show inwin with emoticon list
  64. static void _insert_emoticon_cb(void *data, Evas_Object *obj, void *event) {
  65.         appdata_s *ad = data;
  66.         
  67.         Evas_Object *inwin = elm_win_inwin_add(ad->win);
  68.         evas_object_size_hint_weight_set(inwin, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  69.         evas_object_size_hint_align_set(inwin, EVAS_HINT_FILL, EVAS_HINT_FILL);
  70.         evas_object_show(inwin);
  71.         
  72.         Evas_Object *box = elm_box_add(ad->win);
  73.         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  74.         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
  75.         elm_win_inwin_content_set(inwin, box);
  76.         ad->inwin = inwin;
  77.         evas_object_show(box);
  78.         
  79.         Evas_Object *naviframe = elm_naviframe_add(ad->win);
  80.         evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  81.         evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL);
  82.         elm_box_pack_end(box, naviframe);
  83.         evas_object_show(naviframe);
  84.         
  85.         Evas_Object *grid = create_emoticon_grid(ad);
  86.         elm_naviframe_item_simple_push(naviframe, grid);
  87.         elm_naviframe_item_simple_promote(naviframe, grid);
  88. }

  89. //main test function(with editable entry and "insert emoticon" button
  90. static void emoticon_test(appdata_s *ad) {
  91.         Evas_Object *box = elm_box_add(ad->win);
  92.         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  93.         elm_win_resize_object_add(ad->win, box);
  94.         evas_object_show(box);

  95.         Evas_Object* entry = elm_entry_add(ad->win);
  96.         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  97.         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, 0.1);
  98.         elm_entry_entry_insert(entry, "sample text");

  99.         evas_object_show(entry);
  100.         elm_box_pack_end(box, entry);
  101.         ad->entry = entry;

  102.         Evas_Object *button = elm_button_add(ad->win);
  103.         elm_object_text_set(button, "Insert emoticon");
  104.         evas_object_show(button);
  105.         elm_box_pack_end(box, button);

  106.         evas_object_smart_callback_add(button, "clicked", _insert_emoticon_cb, ad);
  107. }
复制代码

欢迎来到泰泽网:http://www.tizennet.com/ 泰泽论坛:http://bbs.tizennet.com/ 好没有内涵哦,快到设置中更改这个无聊的签名吧!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|泰泽应用|泰泽论坛|泰泽网|小黑屋|Archiver|手机版|泰泽邮箱|泰泽网 ( 蜀ICP备13024062号-1 )

GMT+8, 2024-11-24 19:50 , Processed in 0.113905 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表