Mercurial > dwindows
changeset 2523:82cdb3ad7c25
Android: Implement the calendar widget using CalendarView.
For some reason it is not actually displaying the correct date.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 09 May 2021 21:17:32 +0000 |
parents | 66c490aa719d |
children | d5c3c573c74e |
files | android/DWindows.kt android/dw.cpp |
diffstat | 2 files changed, 84 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/android/DWindows.kt Sun May 09 19:27:23 2021 +0000 +++ b/android/DWindows.kt Sun May 09 21:17:32 2021 +0000 @@ -1487,6 +1487,34 @@ return retval } + fun calendarNew(cid: Int): CalendarView? + { + var calendar: CalendarView? = null + + waitOnUiThread { + calendar = CalendarView(this) + } + + return calendar + } + + fun calendarSetDate(calendar: CalendarView, date: Long) + { + waitOnUiThread { + calendar.setDate(date, true, true) + } + } + + fun calendarGetDate(calendar: CalendarView): Long + { + var date: Long = 0 + + waitOnUiThread { + date = calendar.date + } + return date + } + fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer { // creating timer task, timer
--- a/android/dw.cpp Sun May 09 19:27:23 2021 +0000 +++ b/android/dw.cpp Sun May 09 21:17:32 2021 +0000 @@ -3238,6 +3238,19 @@ */ HWND API dw_calendar_new(ULONG cid) { + JNIEnv *env; + + if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID calendarNew = env->GetMethodID(clazz, "calendarNew", + "(I)Landroid/widget/CalendarView;"); + // Call the method on the object + jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, calendarNew, (int)cid)); + return result; + } return 0; } @@ -3249,6 +3262,27 @@ */ void API dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + time_t date; + struct tm ts = {0}; + + // Convert to Unix time + ts.tm_year = year - 1900; + ts.tm_mon = month; + ts.tm_mday = day; + date = mktime(&ts); + + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID calendarSetDate = env->GetMethodID(clazz, "calendarSetDate", + "(Landroid/widget/CalendarView;J)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, calendarSetDate, handle, (jlong)date); + } } /* @@ -3261,6 +3295,28 @@ */ void API dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + time_t date; + struct tm ts; + + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID calendarGetDate = env->GetMethodID(clazz, "calendarGetDate", + "(Landroid/widget/CalendarView;)J"); + // Call the method on the object + date = (time_t)env->CallLongMethod(_dw_obj, calendarGetDate, handle); + ts = *localtime(&date); + if(year) + *year = ts.tm_year + 1900; + if(month) + *month = ts.tm_mon; + if(day) + *day = ts.tm_mday; + } } /*