Tizen C

Iš Žinynas.
Jump to navigation Jump to search

Intro to C programming with EFL toolkit on Tizen[keisti]


Code sample[keisti]

#include "rssreader.h"

typedef struct appdata {
	Evas_Object *win;
	Evas_Object *conform;
	Evas_Object *naviframe;
	Evas_Object *label;
	Evas_Object *button;
} appdata_s;

static void
win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
{
	ui_app_exit();
}

static void
win_back_cb(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;
	/* Let window go to hide state. */
	elm_win_lower(ad->win);
}

static Evas_Object *
create_singlelines_editfield_layout(Evas_Object *parent) {
Evas_Object *editfield, *entry, *button, *buttonOk;

editfield = elm_layout_add(parent);
elm_layout_theme_set(editfield, "layout", "editfield", "singleline");
evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, 0.5);
evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND, 0.5);

entry = elm_entry_add(editfield);
elm_entry_single_line_set(entry, EINA_TRUE);
elm_entry_scrollable_set(entry, EINA_TRUE);
elm_object_part_text_set(entry, "elm.guide", "Enter Your Weight");
//evas_object_smart_callback_add(entry, "focused", editfield_focused_cb, editfield);
//evas_object_smart_callback_add(entry, "unfocused", editfield_unfocused_cb, editfield);
//evas_object_smart_callback_add(entry, "changed", editfield_changed_cb, editfield);
//evas_object_smart_callback_add(entry, "preedit,changed", editfield_changed_cb, editfield);
elm_object_part_content_set(editfield, "elm.swallow.content", entry);
//elm_object_part_content_set(editfield, "elm.swallow.button", button);
return editfield;
}


void
clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;
	Evas_Object *bg = elm_bg_add(ad->naviframe);
	elm_bg_color_set(bg,66,162,206);
	elm_naviframe_item_push(ad->naviframe, "second page", NULL, NULL, bg, NULL);
    dlog_print(DLOG_INFO, LOG_TAG, "Button clicked\n");
}


static void
create_base_gui(appdata_s *ad)
{
	/* Window */
	ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
	elm_win_autodel_set(ad->win, EINA_TRUE);

	if (elm_win_wm_rotation_supported_get(ad->win)) {
		int rots[4] = { 0, 90, 180, 270 };
		elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
	}

	evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
	eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);

	/* Conformant */
	ad->conform = elm_conformant_add(ad->win);
	elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
	elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
	evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_win_resize_object_add(ad->win, ad->conform);
	evas_object_show(ad->conform);

	ad->naviframe = elm_naviframe_add(ad->conform);
	elm_object_item_content_set(ad->conform, ad->naviframe);
	evas_object_show(ad->conform);

	/* box */
	Evas_Object *box = elm_box_add(ad->naviframe);
	elm_box_horizontal_set(box, EINA_FALSE);
	evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
    elm_naviframe_item_push(ad->naviframe, "First Page", NULL, NULL, box, NULL);
    evas_object_show(box);

    /*label   */
    Evas_Object *label = elm_label_add(box);
    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.5);
    elm_object_text_set(label,"<align=center>Hello Tizen!</align>");
    elm_box_pack_end(box,label);
    evas_object_show(label);

    Evas_Object *Button = elm_button_add(box);
	evas_object_size_hint_weight_set(Button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(Button, EVAS_HINT_FILL, 1);
	elm_object_text_set(Button,"Go!");
	evas_object_smart_callback_add(Button, "clicked", clicked_cb, ad);
	elm_box_pack_end(box,Button);
	evas_object_show(Button);


	//create_singlelines_editfield_layout(ad);
	//char const * const text = elm_entry_entry_get(create_singlelines_editfield_layout(ad)->field);
	/* Show window after base gui is set up */
	evas_object_show(ad->win);
}

static bool
app_create(void *data)
{
	/* Hook to take necessary actions before main event loop starts
		Initialize UI resources and application's data
		If this function returns true, the main loop of application starts
		If this function returns false, the application is terminated */
	appdata_s *ad = data;

	create_base_gui(ad);

	return true;
}

static void
app_control(app_control_h app_control, void *data)
{
	/* Handle the launch request. */
}

static void
app_pause(void *data)
{
	/* Take necessary actions when application becomes invisible. */
}

static void
app_resume(void *data)
{
	/* Take necessary actions when application becomes visible. */
}

static void
app_terminate(void *data)
{
	/* Release all resources. */
}

static void
ui_app_lang_changed(app_event_info_h event_info, void *user_data)
{
	/*APP_EVENT_LANGUAGE_CHANGED*/
	char *locale = NULL;
	system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
	elm_language_set(locale);
	free(locale);
	return;
}

static void
ui_app_orient_changed(app_event_info_h event_info, void *user_data)
{
	/*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
	return;
}

static void
ui_app_region_changed(app_event_info_h event_info, void *user_data)
{
	/*APP_EVENT_REGION_FORMAT_CHANGED*/
}

static void
ui_app_low_battery(app_event_info_h event_info, void *user_data)
{
	/*APP_EVENT_LOW_BATTERY*/
}

static void
ui_app_low_memory(app_event_info_h event_info, void *user_data)
{
	/*APP_EVENT_LOW_MEMORY*/
}

int
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[5] = {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], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
	ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
	ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
	ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
	ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
	ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);

	ret = ui_app_main(argc, argv, &event_callback, &ad);
	if (ret != APP_ERROR_NONE) {
		dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
	}

	return ret;
}