# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1662900188 0 # Node ID 469e5748c8a59dddc18eb21f663cffd898cb8dc7 # Parent df16bb0a11b20d04bf429bd61788ada1c852b91a Android: In preparation for the container mode changes... I needed to implement localized date handling. I had skipped that code previous since I couldn't use the C locale code I use on other platforms since Android NDK is always US_EN. Plus since we only previously displayed one column, that code would never need to be run. diff -r df16bb0a11b2 -r 469e5748c8a5 android/DWindows.kt --- a/android/DWindows.kt Sun Sep 11 08:15:13 2022 +0000 +++ b/android/DWindows.kt Sun Sep 11 12:43:08 2022 +0000 @@ -32,6 +32,7 @@ import android.text.InputFilter import android.text.InputFilter.LengthFilter import android.text.InputType +import android.text.format.DateFormat import android.text.method.PasswordTransformationMethod import android.util.* import android.util.Base64 @@ -62,6 +63,8 @@ import com.google.android.material.tabs.TabLayout.OnTabSelectedListener import com.google.android.material.tabs.TabLayoutMediator import java.io.* +import java.text.ParseException +import java.text.SimpleDateFormat import java.util.* import java.util.concurrent.locks.ReentrantLock import java.util.zip.ZipEntry @@ -5113,7 +5116,7 @@ } } - fun containerChangeItemInt(cont: ListView, column: Int, row: Int, num: Int) + fun containerChangeItemInt(cont: ListView, column: Int, row: Int, num: Long) { waitOnUiThread { val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter @@ -5122,6 +5125,71 @@ } } + fun timeString(num: Int): String + { + if(num > 0 && num < 60) { + if(num > 9) + return num.toString() + else + return "0" + num.toString() + } + return "01" + } + + fun yearString(year: Int): String + { + if(year < 100) + { + if(year < 70) + return "19" + year.toString() + else + return "20" + year.toString() + } + if(year in 1901..2199) + return year.toString() + val calendar = Calendar.getInstance() + val thisyear = calendar[Calendar.YEAR] + return thisyear.toString() + } + + fun containerChangeItemDate(cont: ListView, column: Int, row: Int, year: Int, month: Int, day: Int) + { + waitOnUiThread { + val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter + val dateString = timeString(day) + "/" + timeString(month) + "/" + yearString(year) + val sdf = SimpleDateFormat("dd/MM/yyyy") + var date: Date? = null + var s = dateString + try { + date = sdf.parse(dateString) + val dateFormat = DateFormat.getDateFormat(this) + s = dateFormat.format(date) + } catch (e: ParseException) { + // handle exception here ! + } + adapter.model.setRowAndColumn(row, column, s) + } + } + + fun containerChangeItemTime(cont: ListView, column: Int, row: Int, hour: Int, minute: Int, second: Int) + { + waitOnUiThread { + val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter + val timeStr = timeString(hour) + ":" + timeString(minute) + ":" + timeString(second) + val sdf = SimpleDateFormat("hh:mm:ss") + var date: Date? = null + var s = timeStr + try { + date = sdf.parse(timeStr) + val timeFormat = DateFormat.getTimeFormat(this) + s = timeFormat.format(date) + } catch (e: ParseException) { + // handle exception here ! + } + adapter.model.setRowAndColumn(row, column, s) + } + } + fun containerChangeRowData(cont: ListView, row: Int, data: Long) { waitOnUiThread { diff -r df16bb0a11b2 -r 469e5748c8a5 android/dw.cpp --- a/android/dw.cpp Sun Sep 11 08:15:13 2022 +0000 +++ b/android/dw.cpp Sun Sep 11 12:43:08 2022 +0000 @@ -3729,10 +3729,10 @@ // 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 containerNew = env->GetMethodID(clazz, "containerAddColumn", + jmethodID containerAddColumn = env->GetMethodID(clazz, "containerAddColumn", "(Landroid/widget/ListView;Ljava/lang/String;I)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, containerNew, handle, jstr, (int)flags[z]); + env->CallVoidMethod(_dw_obj, containerAddColumn, handle, jstr, (int)flags[z]); if(_dw_jni_check_exception(env)) retval = DW_ERROR_GENERAL; env->DeleteLocalRef(jstr); @@ -3864,12 +3864,37 @@ jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID containerChangeItem = env->GetMethodID(clazz, "containerChangeItemInt", - "(Landroid/widget/ListView;III)V"); + "(Landroid/widget/ListView;IIJ)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, (int)num); + env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, (jlong)num); _dw_jni_check_exception(env); } - // TODO: Handle DATE and TIME + else if((columntype & DW_CFA_DATE)) + { + CDATE cdate = *((CDATE *)data); + // 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 containerChangeItem = env->GetMethodID(clazz, "containerChangeItemDate", + "(Landroid/widget/ListView;IIIII)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, + (jint)cdate.year, (jint)cdate.month, (jint)cdate.day); + _dw_jni_check_exception(env); + } + else if((columntype & DW_CFA_TIME)) + { + CTIME ctime = *((CTIME *)data); + // 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 containerChangeItem = env->GetMethodID(clazz, "containerChangeItemTime", + "(Landroid/widget/ListView;IIIII)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, containerChangeItem, handle, column, row, + (jint)ctime.hours, (jint)ctime.minutes, (jint)ctime.seconds); + _dw_jni_check_exception(env); + } } }