Implement sample template for mobile
[apps/native/sample/sample-core-components.git] / rule / mobile / project / src / main.c.tccr
1 |R| /*
2 |R|  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
3 |R|  *
4 |R|  * Licensed under the Apache License, Version 2.0 (the "License");
5 |R|  * you may not use this file except in compliance with the License.
6 |R|  * You may obtain a copy of the License at
7 |R|  *
8 |R|  * http://www.apache.org/licenses/LICENSE-2.0
9 |R|  *
10 |R|  * Unless required by applicable law or agreed to in writing, software
11 |R|  * distributed under the License is distributed on an "AS IS" BASIS,
12 |R|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |R|  * See the License for the specific language governing permissions and
14 |R|  * limitations under the License.
15 |R|  */
16
17 |R| #include "$(appName).h"
18 #include "view.h"
19 #include "data.h"
20
21 /*
22  * @brief Hook to take necessary actions before main event loop starts
23  * Initialize UI resources and application's data
24  * If this function returns true, the main loop of application starts
25  * If this function returns false, the application is terminated
26  */
27 static bool app_create(void *user_data)
28 {
29         return true;
30 }
31
32 /*
33  * @brief This callback function is called when another application
34  * sends the launch request to the application
35  */
36 |R| static void app_control(app_control_h app_control, void *user_data)
37 |R| {
38         /* Handle the launch request. */
39 |R| }
40
41 /*
42  * @brief This callback function is called each time
43  * the application is completely obscured by another application
44  * and becomes invisible to the user
45  */
46 |R| static void app_pause(void *user_data)
47 |R| {
48         /* Take necessary actions when application becomes invisible. */
49 |R| }
50
51 /*
52  * @brief This callback function is called each time
53  * the application becomes visible to the user
54  */
55 |R| static void app_resume(void *user_data)
56 |R| {
57         /* Take necessary actions when application becomes visible. */
58 |R| }
59
60 /*
61  * @brief This callback function is called once after the main loop of the application exits
62  */
63 |R| static void app_terminate(void *user_data)
64 |R| {
65         /* Release all resources. */
66 |R| }
67
68 /*
69  * @brief This function will be called when the language is changed
70  */
71 |R| static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
72 |R| {
73         /*APP_EVENT_LANGUAGE_CHANGED*/
74 |R|     char *locale = NULL;
75
76 |R|     system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
77
78 |R|     if (locale != NULL) {
79 |R|             elm_language_set(locale);
80 |R|             free(locale);
81 |R|     }
82 |R|     return;
83 |R| }
84
85 /*
86  * @brief Main function of the application
87  */
88 |R| int main(int argc, char *argv[])
89 |R| {
90 |R|     int ret;
91
92         ui_app_lifecycle_callback_s event_callback = {0, };
93 |R|     app_event_handler_h handlers[5] = {NULL, };
94
95 |R|     event_callback.create = app_create;
96 |R|     event_callback.terminate = app_terminate;
97 |R|     event_callback.pause = app_pause;
98 |R|     event_callback.resume = app_resume;
99 |R|     event_callback.app_control = app_control;
100
101 |R|     /*
102 |R|      * If you want to handling more events,
103 |R|      * Please check the application lifecycle guide
104 |R|      */
105         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
106
107         ret = ui_app_main(argc, argv, &event_callback, NULL);
108 |R|     if (ret != APP_ERROR_NONE) {
109         dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
110 |R|     }
111
112 |R|     return ret;
113 |R| }