密西西比河 发表于 2015-4-24 14:45:21

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

本教程演示了如何创建一个简单的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遵循下列基本原则:

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

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

// Destroy message
messages_destroy_message(sms_msg);

// Change the properties of the text message
messages_set_text(sms_msg,"Hello, how are you?");
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重要的对象指针存储在以下数据结构。
<font size="3">typedef struct appdata
{
   // All graphical objects here are pointers to the value of the type Evas_Object.
   Evas_Object *win;
   Evas_Object *conformant;
   Evas_Object *naviframe;
} appdata_s;</font>创建并初始化指针包含只有0 main() 功能。 同样的结构 app_event_callback_s 类型,它拥有app-core相关的回调。
<font size="3">main(int argc, char *argv[])
{
   appdata_s *ad = {0,};
   int ret = 0;
   ui_app_lifecycle_callback_s event_callback = {0,};
   app_event_handler_h handlers = {NULL,};

   event_callback.create = app_create;
   event_callback.terminate = app_terminate;
   event_callback.pause = app_pause;
   event_callback.resume = app_resume;
   event_callback.app_control = app_control;

   ui_app_add_event_handler(&handlers, APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
   ui_app_add_event_handler(&handlers, APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
   ui_app_add_event_handler(&handlers, APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
   ui_app_add_event_handler(&handlers, APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
   ui_app_add_event_handler(&handlers, APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
   ui_app_remove_event_handler(handlers);

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

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

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

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

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

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

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

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

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

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

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

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

   // Set the box vertical
   elm_box_horizontal_set(box, EINA_FALSE);

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

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

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

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

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

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

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

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

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

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

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

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

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



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

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

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

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

页: [1]
查看完整版本: 创建您的第一个Tizen移动本地应用的方法