Update Date N time on ui ?

Technical | Application Development | patash | 1 month | 4 Replies | 910 Views

*

patash

  • ****
  • 491
  • 5165 Points
  • Tizen is better than iOS.
Update Date N time on ui ?
« On:August 23, 2015, 08:18:59 AM »
Is there a way to update time on ui ? i mean a callback that will receive when time is updated in minutes.
Ex: 19:28
OR will it require to use a timer to get the current time to display ?


Cheers,
Ashish



*

Praveen Chikkappaiah

  • **
  • 34
  • 305 Points
    • View Website
Re: Update Date N time on ui ?
« Reply #1 On:August 24, 2015, 11:07:16 AM »
Hi Ashish,
If I am right in understanding your query, then you need a callback to inform/notify your app when the system time changes.
If thats the requirement then you can use this :

void _time_changed_cb (system_settings_key_e key, void *user_data)
{
        printf("THIS IS CALLED BY USER APPLICATION WHEN THE SYSTEM TIME CHANGES \n");
   time_t raw_time;
   struct tm* time_info = NULL;

   time(&raw_time);
   time_info = localtime(&raw_time);
   printf("Current time: %d:%s%d", time_info->tm_hour, time_info->tm_min<10? "0" : "", time_info->tm_min);

}

// Registering a callback function
system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_TIME_CHANGED, _time_changed_cb, NULL);

/* After your use you can deregister the cb */

// Deregistering a callback function
system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_TIME_CHANGED);

Hope this helps.

Cheers,
Praveen C

*

patash

  • ****
  • 491
  • 5165 Points
  • Tizen is better than iOS.
Re: Update Date N time on ui ?
« Reply #2 On:August 24, 2015, 03:37:37 PM »
Hi Praveen,
Firstly i will thanks for providing a solution.
Although i would also like to apologize as i failed to correctly convey my problem.
As i am looking for displaying time and when the system time changes from 11:21 to 11:22 the callback will notify. OR else i will have to use a timer and read the time at a certain interval.
To be very precise, My need is to display a clock on my screen and update it every minute rather. Seconds does not matter.


Cheers,
Ashish

*

Praveen Chikkappaiah

  • **
  • 34
  • 305 Points
    • View Website
Re: Update Date N time on ui ?
« Reply #3 On:August 24, 2015, 05:25:14 PM »
Hi Ashish,
A rather simple & easy way would be to maintain a timer internally by your app.

However if you wish that Tizen system let you know on the next minute change then you can schedule an alarm.

Step 1:
get the current time using alarm_get_current_time  Ref: https://developer.tizen.org/dev-guide/2.3.0/org.tizen.native.mobile.apireference/group__CAPI__ALARM__MODULE.html#ga51ae8c54400644399e0f06f64172dbc5

Step 2:
Schedule the alarm to notify you the next minute change by incrementing the minute value by 1 in the tm data structure obtained by step 1. Use the api alarm_schedule_at_date Ref: https://developer.tizen.org/dev-guide/2.3.0/org.tizen.native.mobile.apireference/group__CAPI__ALARM__MODULE.html#ga41b39954a4c3208e542ffd648a489064

Step 3:
Tizen System will notify/alarm you on the next minute change and you can take appropriate action like updating UI etc.

Cheers,
Praveen C

*

patash

  • ****
  • 491
  • 5165 Points
  • Tizen is better than iOS.
Re: Update Date N time on ui ?
« Reply #4 On:August 24, 2015, 05:36:15 PM »
Thanks again
I will implement a timer. Since it is simple way.

Ashish

Tags:
 


Facebook Comments