comparison android/dw.cpp @ 2561:f28d7d0ca5ed

Android: Attempt at implementing updating the container after insertion. I am trying to use notifyDataSetChanged() in our DWContainerAdapter class. This is called via _dw_container_refresh() and containerRefresh() however it does not seem to be working yet.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 18 May 2021 22:48:33 +0000
parents 3da35cd91ca7
children 4427af56eebe
comparison
equal deleted inserted replaced
2560:3da35cd91ca7 2561:f28d7d0ca5ed
3122 int rowstart = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_rowstart")); 3122 int rowstart = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_rowstart"));
3123 3123
3124 dw_container_change_item(handle, column, row + rowstart, data); 3124 dw_container_change_item(handle, column, row + rowstart, data);
3125 } 3125 }
3126 3126
3127 /* 3127 /* Internal version that doesn't update the list immediately */
3128 * Changes an existing item in specified row and column to the given data. 3128 void API _dw_container_change_item(HWND handle, int column, int row, void *data)
3129 * Parameters:
3130 * handle: Handle to the container window (widget).
3131 * column: Zero based column of data being set.
3132 * row: Zero based row of data being set.
3133 * data: Pointer to the data to be added.
3134 */
3135 void API dw_container_change_item(HWND handle, int column, int row, void *data)
3136 { 3129 {
3137 JNIEnv *env; 3130 JNIEnv *env;
3138 3131
3139 if(handle && data && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 3132 if(handle && data && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3140 { 3133 {
3187 } 3180 }
3188 // TODO: Handle DATE and TIME 3181 // TODO: Handle DATE and TIME
3189 } 3182 }
3190 } 3183 }
3191 3184
3185 /* Notify that the data changed, causing the container to refresh */
3186 void _dw_container_refresh(HWND handle)
3187 {
3188 JNIEnv *env;
3189
3190 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3191 {
3192 // First get the class that contains the method you need to call
3193 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3194 // Get the method that you want to call
3195 jmethodID containerRefresh = env->GetMethodID(clazz, "containerRefresh",
3196 "(Landroid/widget/ListView;)V");
3197 // Call the method on the object
3198 env->CallVoidMethod(_dw_obj, containerRefresh, handle);
3199 _dw_jni_check_exception(env);
3200 }
3201 }
3202
3192 /* 3203 /*
3193 * Changes an existing item in specified row and column to the given data. 3204 * Changes an existing item in specified row and column to the given data.
3194 * Parameters: 3205 * Parameters:
3195 * handle: Handle to the container window (widget). 3206 * handle: Handle to the container window (widget).
3196 * column: Zero based column of data being set. 3207 * column: Zero based column of data being set.
3197 * row: Zero based row of data being set. 3208 * row: Zero based row of data being set.
3198 * data: Pointer to the data to be added. 3209 * data: Pointer to the data to be added.
3199 */ 3210 */
3211 void API dw_container_change_item(HWND handle, int column, int row, void *data)
3212 {
3213 _dw_container_change_item(handle, column, row, data);
3214 _dw_container_refresh(handle);
3215 }
3216
3217 /*
3218 * Changes an existing item in specified row and column to the given data.
3219 * Parameters:
3220 * handle: Handle to the container window (widget).
3221 * column: Zero based column of data being set.
3222 * row: Zero based row of data being set.
3223 * data: Pointer to the data to be added.
3224 */
3200 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) 3225 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data)
3201 { 3226 {
3202 dw_container_change_item(handle, column + 2, row, data); 3227 _dw_container_change_item(handle, column + 2, row, data);
3228 _dw_container_refresh(handle);
3203 } 3229 }
3204 3230
3205 /* 3231 /*
3206 * Changes an item in specified row and column to the given data. 3232 * Changes an item in specified row and column to the given data.
3207 * Parameters: 3233 * Parameters:
3211 * row: Zero based row of data being set. 3237 * row: Zero based row of data being set.
3212 * data: Pointer to the data to be added. 3238 * data: Pointer to the data to be added.
3213 */ 3239 */
3214 void API dw_filesystem_change_file(HWND handle, int row, const char *filename, HICN icon) 3240 void API dw_filesystem_change_file(HWND handle, int row, const char *filename, HICN icon)
3215 { 3241 {
3216 dw_container_change_item(handle, 0, row, (void *)&icon); 3242 _dw_container_change_item(handle, 0, row, (void *)&icon);
3217 dw_container_change_item(handle, 1, row, (void *)&filename); 3243 _dw_container_change_item(handle, 1, row, (void *)&filename);
3244 _dw_container_refresh(handle);
3218 } 3245 }
3219 3246
3220 /* 3247 /*
3221 * Sets an item in specified row and column to the given data. 3248 * Sets an item in specified row and column to the given data.
3222 * Parameters: 3249 * Parameters:
3412 JNIEnv *env; 3439 JNIEnv *env;
3413 3440
3414 if(pointer && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 3441 if(pointer && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3415 env->DeleteWeakGlobalRef((jobject)pointer); 3442 env->DeleteWeakGlobalRef((jobject)pointer);
3416 dw_window_set_data(handle, "_dw_rowstart", NULL); 3443 dw_window_set_data(handle, "_dw_rowstart", NULL);
3444 _dw_container_refresh(handle);
3417 } 3445 }
3418 3446
3419 /* 3447 /*
3420 * Removes all rows from a container. 3448 * Removes all rows from a container.
3421 * Parameters: 3449 * Parameters:
3434 jmethodID containerClear = env->GetMethodID(clazz, "containerClear", 3462 jmethodID containerClear = env->GetMethodID(clazz, "containerClear",
3435 "(Landroid/widget/ListView;)V"); 3463 "(Landroid/widget/ListView;)V");
3436 // Call the method on the object 3464 // Call the method on the object
3437 env->CallVoidMethod(_dw_obj, containerClear, handle); 3465 env->CallVoidMethod(_dw_obj, containerClear, handle);
3438 _dw_jni_check_exception(env); 3466 _dw_jni_check_exception(env);
3467 _dw_container_refresh(handle);
3439 } 3468 }
3440 } 3469 }
3441 3470
3442 /* 3471 /*
3443 * Removes the first x rows from a container. 3472 * Removes the first x rows from a container.
3457 jmethodID containerDelete = env->GetMethodID(clazz, "containerDelete", 3486 jmethodID containerDelete = env->GetMethodID(clazz, "containerDelete",
3458 "(Landroid/widget/ListView;I)V"); 3487 "(Landroid/widget/ListView;I)V");
3459 // Call the method on the object 3488 // Call the method on the object
3460 env->CallVoidMethod(_dw_obj, containerDelete, handle, rowcount); 3489 env->CallVoidMethod(_dw_obj, containerDelete, handle, rowcount);
3461 _dw_jni_check_exception(env); 3490 _dw_jni_check_exception(env);
3491 _dw_container_refresh(handle);
3462 } 3492 }
3463 } 3493 }
3464 3494
3465 /* 3495 /*
3466 * Scrolls container up or down. 3496 * Scrolls container up or down.