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

创建您的第一个Tizen移动本地应用的方法

[复制链接]
发表于 2015-4-24 14:45:21 | 显示全部楼层 |阅读模式
本教程演示了如何创建一个简单的HelloWorld应用程序。 学习本教程,帮助熟悉Tizen 本机应用程序开发过程以及使用Tizen SDK安装模拟器或目标设备上创建应用程序。
当你正在开发一个更复杂的应用程序中,您可以利用 工具包含在SDK为了缓解的任务创建的功能和设计应用程序的UI。
创建一个HelloWorld应用程序
  • 创建HelloWorld项目

    • 启动 Tizen IDE
    • 在IDE中创建应用程序项目
      在项目创建,使用基本Tizen项目模板:在 新的Tizen本地项目 窗口中,选择 模板>移动- <版本> > UI应用程序>基本UI应用程序
    • 定义 helloworld 为您的项目的名称并单击 完成

    图:创建HelloWorld项目

  • helloworld 项目中所示 Project Explorer 视图的IDE,默认内容 tizen-manifest.xml 配置文件以及其他几个项目文件,包括:

    • 公司inc 文件夹:应用程序头文件目录
    • Src 文件夹:C文件目录

  • 配置应用程序,并创建应用程序代码配置应用程序:

    • 设置项目属性通过修改tizen-manifest.xml 文件。
    • 实现的应用程序代码 helloworld.c 文件。

    编写应用程序时,请注意,Tizen本机API遵循下列基本原则:
    • 返回字符串的所有权
      所有字符串作为指针应该返回被调用者除所述释放。
      不是免费的内存可能会导致内存泄漏。 系统内存不足会引发系统低内存通知和一些应用程序可能被杀死。 作为一种启发式算法选择死亡的过程,它可以破坏系统。
      1. <font size="3">char *app_id_string = NULL;
      2. if(!app_get_id(&app_id_string))
      3. {
      4.    // Use app_id_string;
      5.    if(app_id_string != NULL)
      6.       free(app_id_string);
      7. }</font>
      复制代码
      处理
      处理提供了管理手段与之关联的一个实例。
      处理广泛应用于Tizen本机API原因ABI的兼容性。
      创建和销毁函数(创建/毁坏)提供为每个处理类型。
      他们不创建和销毁处理本身,但他们操作实例与一个给定的相关处理。
      这意味着一个句柄无效,直到相应的创建函数被调用和处理
      相应的破坏函数被调用后有效。 还访问器功能(getter / setter)
      访问的成员隐藏的结构被给定的处理。
      1. <font size="3">// Text message is represented by a handle
      2. messages_message_h sms_msg;

      3. // Create message and associate it with this handle
      4. messages_create_message(MESSAGES_TYPE_SMS, &sms_msg);

      5. // Destroy message
      6. messages_destroy_message(sms_msg);

      7. // Change the properties of the text message
      8. messages_set_text(sms_msg,"Hello, how are you?");
      9. messages_add_address (sms_msg,"01020157919", MESSAGE_RECIPIENT_TO);</font>
      复制代码


      • 异步函数调用一些Tizen本机API函数是异步的。
        开始一个异步函数处理并返回之前处理完成为止。 然而,有时一个人应该知道,当这个处理完成为止。 在这种情况下,等待处理完成通知应正确地执行。
      • 代码辅助Tizen IDE提供了API帮助和API悬停功能使写作内容在本地编辑器快速和有效的。
        按CTRL + SPACE编辑你的代码时看到api可用如下:
        图:代码协助


创建应用程序的UI与英语
英语是Tizen本机图形工具包。 本教程介绍英语而不是一个成熟的Tizen应用程序,因为它不使用Appcore。
创建应用程序界面:
  • 添加一个接口
    在本教程中,有以下练习:


    • 一个窗口持有一切
    • 一致,显示了虚拟键盘(Tizen指南要求的)
    • naviframe用于应用程序,显示多个屏幕通过他们的生活与他们之间来回转换(Tizen指南要求的)
    • 横框和

      • 一个标签的几行文本
      • 一个按钮

  • 添加一个应用程序骨架appcore重要的对象指针存储在以下数据结构。
    1. <font size="3">typedef struct appdata
    2. {
    3.    // All graphical objects here are pointers to the value of the type Evas_Object.
    4.    Evas_Object *win;
    5.    Evas_Object *conformant;
    6.    Evas_Object *naviframe;
    7. } appdata_s;</font>
    复制代码
    创建并初始化指针包含只有0 main() 功能。 同样的结构 app_event_callback_s 类型,它拥有app-core相关的回调。
    1. <font size="3">main(int argc, char *argv[])
    2. {
    3.    appdata_s *ad = {0,};
    4.    int ret = 0;
    5.    ui_app_lifecycle_callback_s event_callback = {0,};
    6.    app_event_handler_h handlers[5] = {NULL,};

    7.    event_callback.create = app_create;
    8.    event_callback.terminate = app_terminate;
    9.    event_callback.pause = app_pause;
    10.    event_callback.resume = app_resume;
    11.    event_callback.app_control = app_control;

    12.    ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
    13.    ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
    14.    ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
    15.    ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
    16.    ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
    17.    ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);

    18.    ret = ui_app_main(argc, argv, &event_callback, &ad);

    19.    return ret;
    20. }</font>
    复制代码
    注意: 有关Appcore的更多信息,请参阅 应用程序框架的教程
    创建GUI对象
    与创建GUI create_gui () 功能。 它接收一个指针来填写“广告”结构。
    创建函数和马克静态的,因为它是唯一可以从当前的编译单元(允许编译器产生更快和更小的代码)。

    在函数内部,创建一个窗口并设置其名称和标题“Hello World”。 添加一个回调在“删除请求”事件(当窗口被关闭)。

    1. <font size="3">static void
    2. create_gui(appdata_s *ad)
    3. {
    4.    // Create the window
    5.    ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
    6.    elm_win_conformant_set(ad->win, EINA_TRUE);

    7.    // Advertise which rotations are supported by the application; the
    8.    // device_orientation callback is used to do the actual rotation when
    9.    // the system detects the device's orientation has changed
    10.    if (elm_win_wm_rotation_supported_get(ad->win)) {
    11.       int rots[4] = { 0, 90, 180, 270 };
    12.       elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
    13.    }

    14.    // Add a callback on the "delete,request" event; it is emitted when
    15.    // the system closes the window
    16.    evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);

    17.    // Alternatively, elm_win_autodel_set() can be used to close
    18.    // the window (not the application) automatically
    19.    // with the Back button, for example
    20.    // elm_win_autodel_set(ad->win, EINA_TRUE);</font>
    复制代码
    首先符合走进窗口。 一切从现在开始创建。
    1. <font size="3">  // Create the conformant
    2.    ad->conformant = elm_conformant_add(ad->win);

    3.    // Set the conformant use as much horizontal and vertical space as
    4.    // possible, that is, expand in both directions
    5.    evas_object_size_hint_weight_set(ad->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

    6.    // Set the conformant as the resize object for the window:
    7.    // the window and the conformant grow together
    8.    // in proportion to each other
    9.    elm_win_resize_object_add(ad->win, ad->conformant);

    10.    // Show the conformant since all widgets are hidden by default
    11.    evas_object_show(ad->conformant);</font>
    复制代码
    naviframe是有用的应用程序显示多个屏幕:它使显示一个屏幕,切换到另一个地方,回到第一个(和做同样的和几个屏幕)。

    只有一个屏幕是建立:创建naviframe,把内部的一致性。
    1. <font size="3"> // Create the naviframe
    2.    ad->naviframe = elm_naviframe_add(ad->conformant);
    3.    elm_object_content_set(ad->conformant, ad->naviframe);

    4.    // Show the box
    5.    evas_object_show(ad->conformant);</font>
    复制代码
    盒子可能是最常见的容器,它安排一组小部件以垂直或水平的方式。
    1. <font size="3"> // Create the box
    2.    Evas_Object *box = elm_box_add(ad->naviframe);

    3.    // Set the box vertical
    4.    elm_box_horizontal_set(box, EINA_FALSE);

    5.    // The box expands when its contents need more space
    6.    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

    7.    // The box fills the available space
    8.    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);

    9.    // Add the box in the naviframe container
    10.    elm_naviframe_item_push(ad->naviframe, "Hello World", NULL, NULL, box, NULL);

    11.    // Show the box
    12.    evas_object_show(box);</font>
    复制代码
    标签保存文本格式化和到多个行。
    1. <font size="3">  // Create the label
    2.    Evas_Object *label = elm_label_add(box);
    3.    // The label expands when its contents need more space
    4.    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    5.    // The box fills the available space on the horizontal axis and is
    6.    // centered on the vertical axis (placed at 0.5 vertically, that is, in the
    7.    // middle)
    8.    evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.5);

    9.    // Set the text for the label and set formatting through the HTML tags:
    10.    // - "Hello World!" centered on the first line
    11.    // - skip a line
    12.    // - Add a longer text that does not fit on a single line but wraps at
    13.    //   the word boundaries
    14.    elm_object_text_set(label,
    15.          "<align=center>Hello World!</align><br>"
    16.          "<br>"
    17.          "<wrap = word>Clicking on the button below closes the application.</wrap>");

    18.    // Add the label at the end of the box
    19.    elm_box_pack_end(box, label);

    20.    // Show the label
    21.    evas_object_show(label);</font>
    复制代码
    最后一个部件是按钮。 当点击它退出应用程序。
    1. <font size="3"> // Create the button
    2.    Evas_Object *button = elm_button_add(box);

    3.    // The box expands when its contents need more space
    4.    evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

    5.    // The button fills the available space on the horizontal axis and is
    6.    // placed at the bottom of the vertical axis (1 is the end of the axis,
    7.    // the coordinates start at (0, 0) on the top-left corner
    8.    evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 1);

    9.    // Set the text for the button
    10.    elm_object_text_set(button, "Close!");

    11.    // Add a callback on the button for the "clicked" event; implementation of
    12.    // the callback is below
    13.    evas_object_smart_callback_add(button, "clicked", clicked_cb, NULL);

    14.    // Add the widget at the end of the box; since the axis starts in the top left
    15.    // corner and the box is vertical, the end of the box is below the label
    16.    elm_box_pack_end(box, button);

    17.    // Show the button
    18.    evas_object_show(button);</font>
    复制代码
    这是如何设置窗口显示在屏幕上的一切。
    1. <font size="3"> // Show window after the GUI is set up
    2.    evas_object_show(ad->win);
    3. }</font>
    复制代码
    4.退出GUI
    clicked_cb () 初等函数退出;函数的原型是常见的所有回调 evas_object_smart_callback_add ()。 把 clicked_cb () 以上功能 create_gui () 功能。
    更多细节的回调,请参阅 监控智能对象的事件指南。
    1. <font size="3">static void
    2. clicked_cb(void *user_data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
    3. {
    4.    elm_exit();
    5. }</font>
    复制代码



    • 构建和打包应用程序您已经完成了实现您的应用程序后,必须 构建它
      建立后,Tizen IDE自动包项目。

      运行和调试应用程序
      你可以在模拟器上运行的 HelloWorld 应用。

      下图显示了在仿真器上运行的小部件。


      以上文章有在线翻译生成,Tizen官方网站提供!


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 20:40 , Processed in 0.155099 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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