From c58098567568dc328e8fc7db9b7d240508b31771 Mon Sep 17 00:00:00 2001 From: Michal Pawluk Date: Thu, 3 Sep 2015 14:55:42 +0200 Subject: [PATCH] [SAMPLE APP][RESOURCE-MANAGER] Resource files handling section added Change-Id: Icde943e6f1a2b403c31f84a2b12824b635bac9c8 Signed-off-by: Michal Pawluk --- .../html/mobile_n/resource_manager_sd_mn.htm | 92 +++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/org.tizen.sampledescriptions/html/mobile_n/resource_manager_sd_mn.htm b/org.tizen.sampledescriptions/html/mobile_n/resource_manager_sd_mn.htm index 47e7129..0846fdc 100644 --- a/org.tizen.sampledescriptions/html/mobile_n/resource_manager_sd_mn.htm +++ b/org.tizen.sampledescriptions/html/mobile_n/resource_manager_sd_mn.htm @@ -130,7 +130,7 @@ In the application's source code, after the Resource Manager API is initialized, the relevant resource file's path is acquired using the app_resource_manager_get(app_resource_e type, const char *id, char **path) function, where @@ -343,6 +343,96 @@ bool model_finit(void) For __model_release_app_resource_manager() function's reference, see the Model section.

+

Resource files handling

+ +

+ Once the resources are defined using Resource Explorer and appropriate resource files are uploded to the destination folders, one can start using these files. + For the demonstration purpose, two scenarions were chosen: +

+

+ +

+ In the first case, there are 5 image files (each name is set to 'tizen.png') depicting the Tizen's logo with resolution label attached. Each of the images is stored in a different folder with respect to the + DPI setting: 'res/contents/LDPI', 'res/contents/MDPI', 'res/contents/HDPI', 'res/contents/XHDPI', 'res/contents/XXHDPI'. On application's startup, during the initialization procedure + (Application initialization section), the __controller_init_dpi() function is called, which obtains + the path to the relevant image based on the current screen's settings. The core function, performing described task is + model_get_app_resource() (for reference, see the Model section). +

+ +
+static void __controller_init_dpi(viewdata_s *vd)
+{
+   char *file_path = NULL;
+
+   /* Obtains the path to the 'tizen.png' file with respect to the current screen's settings. */
+   if (!model_get_app_resource(APP_RESOURCE_TYPE_IMAGE, "tizen.png", &file_path))
+      return;
+
+   /* The obtained image file is displayed. */
+   view_show_dpi_image(vd, file_path);
+   free(file_path);
+}
+
+ +

+ In the second case, there are 48 image files (each name is set to 'flag.png') depicting the national flags related to all supported languages. Each of the images is stored in a different folder: + 'res/contents/az_AZ', 'res/contents/ca_ES', ... , 'res/contents/zh_TW'. Once the user changes the current language (Settings application ➜ Language and input ➜ Display language), + the __ui_app_lang_changed() callback function is invoked (see the Application initialization section). + This callback function hooks APP_EVENT_LANGUAGE_CHANGED event. At the entry point of the + __ui_app_lang_changed() function, the current locale is obtained using + model_get_locale() function in order to be later set as a current language for the application + (elm_language_set()). Finally, the + controller_set_language() function is invoked, which is responsible for obtaining and displaying the language relevant image. +

+ +
+static void __ui_app_lang_changed(app_event_info_h event_info, void *user_data)
+{
+   appdata_s *ad = (appdata_s *)user_data;
+   char *locale = NULL;
+
+   /* Gets the current locale name. */
+   if (!model_get_locale(&locale))
+      return;
+
+   /* Sets the language for this application. */
+   elm_language_set(locale);
+
+   /* See the code snippet below. */
+   controller_set_language(&ad->view, locale);
+
+   free(locale);
+
+   return;
+}
+
+ +
+void controller_set_language(viewdata_s *vd, char *locale)
+{
+   char *file_path = NULL;
+
+   controller_log(DLOG_INFO, "Language set to: %s.", locale);
+
+   /* Obtains the path to the 'flag.png' file with respect to the current language's settings. */
+   if (!model_get_app_resource(APP_RESOURCE_TYPE_IMAGE, "flag.png", &file_path))
+      return;
+
+   /* The obtained image file is displayed. */
+   view_show_language_info(vd, locale, file_path);
+
+   if (file_path)
+      free(file_path);
+}
+
+ +

+ For all Model related functions, see the Model section. +

+

Model

-- 2.7.4