1# 拖拽事件 2<!--Kit: ArkUI--> 3<!--Subsystem: ArkUI--> 4<!--Owner: @jiangtao92--> 5<!--Designer: @piggyguy--> 6<!--Tester: @songyanhong--> 7<!--Adviser: @HelloCrease--> 8 9ArkUI开发框架针对拖拽事件提供了[NODE_ON_PRE_DRAG](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype),[NODE_ON_DRAG_START](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype),[NODE_ON_DROP](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype),[NODE_ON_DRAG_ENTER](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype),[NODE_ON_DRAG_MOVE](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype),[NODE_ON_DRAG_LEAVE](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype),[NODE_ON_DRAG_END](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype)等组件事件,当拖拽在不同的阶段时会触发对应的组件事件,完成对应的数据处理操作,实现期望的拖拽交互能力。 10 11## 通用拖拽 12 13ArkUI提供了使用C和C++开发拖拽功能的能力,开发者可调用C API实现拖拽功能。以下以Image组件为例,详细介绍实现C API实现拖拽功能的基本步骤,以及在开发过程中需要注意的事项。 14 151. 组件拖拽设置。 16 17 获取[Node-API](../reference/apis-arkui/capi-native-interface-h.md#oh_arkui_getmoduleinterface),创建节点等操作均需通过Node-API完成。 18 19 ```cpp 20 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 21 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 22 ``` 23 24 创建Image节点,并设置draggable和其它相关属性。 25 26 ```cpp 27 auto image = nodeAPI->createNode(ARKUI_NODE_IMAGE); 28 ArkUI_AttributeItem NODE_IMAGE_SRC_Item = {.string = "/pages/common/1111.png"}; // 图片存放于pages/common文件夹 29 ArkUI_NumberValue imageWidthValue[] = {100}; 30 ArkUI_AttributeItem imageWidthItem = {imageWidthValue, 1}; 31 ArkUI_NumberValue imageHeightValue[] = {100}; 32 ArkUI_AttributeItem imageHeightItem = {imageHeightValue, 1}; 33 ArkUI_NumberValue marginValue[] = {20}; 34 ArkUI_AttributeItem marginItem = {marginValue, 1}; 35 nodeAPI->setAttribute(image, NODE_WIDTH, &imageWidthItem); 36 nodeAPI->setAttribute(image, NODE_HEIGHT, &imageHeightItem); 37 nodeAPI->setAttribute(image, NODE_IMAGE_SRC, &NODE_IMAGE_SRC_Item); 38 nodeAPI->setAttribute(image, NODE_MARGIN, &marginItem); 39 nodeAPI->registerNodeEvent(image, NODE_ON_DRAG_START, 1, nullptr); 40 auto returnValue1 = OH_ArkUI_SetNodeDraggable(image, true); 41 ``` 42 432. 自定义拖拽预览和背板图。 44 45 创建[pixelMap](../reference/apis-image-kit/capi-pixelmap-native-h.md#oh_pixelmapnative_createpixelmap),设置pixelMap的宽高等各项属性。设置Image节点的[dragPreviewOption](../reference/apis-arkui/capi-drag-and-drop-h.md#函数),可用于设置跟手图的圆角、角标等。 46 47 ```cpp 48 // 创建pixelMap 49 uint8_t data[960000]; 50 size_t dataSize = 960000; 51 for (int i = 0; i < dataSize; i++) { 52 data[i] = i + 1; 53 } 54 // 创建参数结构体实例,并设置参数 55 OH_Pixelmap_InitializationOptions *createOpts; 56 OH_PixelmapInitializationOptions_Create(&createOpts); 57 OH_PixelmapInitializationOptions_SetWidth(createOpts, 400); 58 OH_PixelmapInitializationOptions_SetHeight(createOpts, 600); 59 OH_PixelmapInitializationOptions_SetPixelFormat(createOpts, PIXEL_FORMAT_BGRA_8888); 60 OH_PixelmapInitializationOptions_SetAlphaType(createOpts, PIXELMAP_ALPHA_TYPE_UNKNOWN); 61 // 创建Pixelmap实例 62 OH_PixelmapNative *pixelmap = nullptr; 63 OH_PixelmapNative_CreatePixelmap(data, dataSize, createOpts, &pixelmap); 64 OH_PixelmapNative_Rotate(pixelmap, 45); 65 OH_PixelmapNative_Opacity(pixelmap, 0.1); 66 OH_PixelmapNative_Scale(pixelmap, 0.5, 1.0); 67 OH_PixelmapNative_Translate(pixelmap, 50.0, 10.0); 68 OH_ArkUI_SetNodeDragPreview(image, pixelmap); 69 auto *previewOptions = OH_ArkUI_CreateDragPreviewOption(); 70 auto returnValue2 = OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(previewOptions, true); 71 auto returnValue3 = OH_ArkUI_DragPreviewOption_SetBadgeNumber(previewOptions, 10); 72 auto returnValue4 = OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(previewOptions, true); 73 OH_ArkUI_SetNodeDragPreviewOption(image, previewOptions); 74 ``` 75 763. 设置相关事件。 77 78 C API的事件通过统一的回调来接收,当收到事件时通过[eventType](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype)进行区分。 79 80 ```cpp 81 nodeAPI->registerNodeEventReceiver([](ArkUI_NodeEvent *event) { 82 auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); 83 auto targetId = OH_ArkUI_NodeEvent_GetTargetId(event); 84 auto *dragEvent = OH_ArkUI_NodeEvent_GetDragEvent(event); 85 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 86 "targetId=%{public}d,eventType=%{public}d,", targetId, 87 eventType); 88 switch (eventType) { 89 case NODE_ON_CLICK: { 90 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 91 "ARKUI_NODE_BUTTON click! dragable"); 92 break; 93 } 94 case NODE_ON_PRE_DRAG: { 95 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", "NODE_ON_PRE_DRAG EventReceiver"); 96 break; 97 } 98 case NODE_ON_DRAG_START: { 99 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 100 "NODE_ON_DRAG_START EventReceiver"); 101 break; 102 } 103 case NODE_ON_DROP: { 104 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", "NODE_ON_DROP EventReceiver"); 105 break; 106 } 107 case NODE_ON_DRAG_ENTER: { 108 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 109 "NODE_ON_DRAG_ENTER EventReceiver"); 110 break; 111 } 112 case NODE_ON_DRAG_MOVE: { 113 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 114 "NODE_ON_DRAG_MOVE EventReceiver"); 115 break; 116 } 117 case NODE_ON_DRAG_LEAVE: { 118 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 119 "NODE_ON_DRAG_LEAVE EventReceiver"); 120 break; 121 } 122 case NODE_ON_DRAG_END: { 123 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", "NODE_ON_DRAG_END EventReceiver"); 124 break; 125 } 126 } 127 }); 128 ``` 129 1304. 处理NODE_ON_DRAG_START事件。 131 132 在NODE_ON_DRAG_START事件中,应用可以执行起拖阶段所需的操作,通常涉及处理起拖过程的数据。例如,创建UdmfRecord,将用于拖拽图片所需的数据 imageUri以fileUri类型添加到[UdmfRecord](../reference/apis-arkdata/capi-udmf-oh-udmfrecord.md)中,接着将UdmfRecord设置到[udmfData](../reference/apis-arkdata/capi-udmf-oh-udmfdata.md)中,最后将UdmfData设置到[DragEvent](../reference/apis-arkui/capi-arkui-nativemodule-arkui-dragevent.md)中。 133 134 ```cpp 135 case NODE_ON_DRAG_START: { 136 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 137 "NODE_ON_DRAG_START EventReceiver"); 138 OH_UdmfRecord *record = OH_UdmfRecord_Create(); 139 int returnValue; 140 OH_UdsFileUri *imageValue = OH_UdsFileUri_Create(); 141 returnValue = OH_UdsFileUri_SetFileUri(imageValue, "/pages/common/1111.png"); 142 returnValue = OH_UdmfRecord_AddFileUri(record, imageValue); 143 OH_UdmfData *data = OH_UdmfData_Create(); 144 returnValue = OH_UdmfData_AddRecord(data, record); 145 returnValue = OH_ArkUI_DragEvent_SetData(dragEvent, data); 146 break; 147 } 148 ``` 149 1505. 处理NODE_ON_DROP事件。 151 152 在NODE_ON_DROP事件中,应用可以执行与落入阶段相关的操作,通常需要获取拖拽过程中传递的数据。例如,引用<database/udmf/udmf_meta.h>头文件,获取[udmfData](../reference/apis-arkdata/capi-udmf-oh-udmfdata.md),判断是否存在所需的数据类型,从[UdmfRecord](../reference/apis-arkdata/capi-udmf-oh-udmfrecord.md)中提取相应的数据,最后销毁指针。 153 154 ```cpp 155 case NODE_ON_DROP: { 156 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 157 "NODE_ON_DRAG_START EventReceiver"); 158 // 获取UDMF data 159 int returnValue; 160 // 创建OH_UdmfData对象 161 OH_UdmfData *data = OH_UdmfData_Create(); 162 returnValue = OH_ArkUI_DragEvent_GetUdmfData(dragEvent, data); 163 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 164 "OH_ArkUI_DragEvent_GetUdmfData returnValue = %{public}d", returnValue); 165 // 判断OH_UdmfData是否有对应的类型 166 bool resultUdmf = OH_UdmfData_HasType(data, UDMF_META_GENERAL_FILE); 167 if (resultUdmf) { 168 // 获取OH_UdmfData的记录 169 unsigned int recordsCount = 0; 170 OH_UdmfRecord **records = OH_UdmfData_GetRecords(data, &recordsCount); 171 // 获取records中的元素 172 int returnStatus; 173 for (int i = 0; i < recordsCount; i++) { 174 // 从OH_UdmfRecord中获取文件类型数据 175 OH_UdsFileUri *imageValue = OH_UdsFileUri_Create(); 176 returnStatus = OH_UdmfRecord_GetFileUri(records[i], imageValue); 177 const char* fileUri = OH_UdsFileUri_GetFileUri(imageValue); 178 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 179 "dragTest OH_UdmfRecord_GetPlainText " 180 "returnStatus= %{public}d " 181 "fileUri= %{public}s", 182 returnStatus, fileUri); 183 // 使用结束后销毁指针 184 OH_UdsFileUri_Destroy(imageValue); 185 } 186 } else { 187 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 188 "OH_UdmfData_HasType not contain UDMF_META_GENERAL_FILE"); 189 } 190 break; 191 } 192 ``` 193 194## DragAction主动发起拖拽 195 196除了通用拖拽以外,ArkUI还提供了使用C API实现主动发起拖拽的能力。以下以文本拖拽为例,详细介绍实现C-API实现主动发起拖拽的基本步骤,以及在开发过程中需要注意的事项。 197 1981. 节点注册事件。 199 200 创建Button节点,设置按钮相关属性,同时需要注册[NODE_ON_TOUCH_INTERCEPT](../reference/apis-arkui/capi-native-node-h.md#arkui_nodeeventtype)事件。 201 202 ```cpp 203 // buttonTouch作为targetId,用于区分不同target的事件。 204 enum { 205 buttonTouch 206 }; 207 208 ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr; 209 OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI); 210 auto button = nodeAPI->createNode(ARKUI_NODE_BUTTON); 211 ArkUI_AttributeItem NODE_Button_SRC_Item = {.string = "button"}; 212 ArkUI_NumberValue buttonWidthValue[] = {200}; 213 ArkUI_AttributeItem buttonWidthItem = {buttonWidthValue, 1}; 214 ArkUI_NumberValue buttonHeightValue[] = {100}; 215 ArkUI_AttributeItem buttonHeightItem = {buttonHeightValue, 1}; 216 ArkUI_NumberValue marginValue[] = {20}; 217 ArkUI_AttributeItem marginItem = {marginValue, 1}; 218 nodeAPI->setAttribute(button, NODE_WIDTH, &buttonWidthItem); 219 nodeAPI->setAttribute(button, NODE_HEIGHT, &buttonHeightItem); 220 nodeAPI->setAttribute(button, NODE_MARGIN, &marginItem); 221 nodeAPI->setAttribute(button, NODE_BUTTON_LABEL, &NODE_Button_SRC_Item); 222 nodeAPI->registerNodeEvent(button, NODE_ON_TOUCH_INTERCEPT, buttonTouch, nullptr); 223 ``` 2242. 接收NODE_ON_TOUCH_INTERCEPT事件。 225 226 DragAction主动发起拖拽需通过事件触发,在NODE_ON_TOUCH_INTERCEPT事件中执行发起拖拽所需的操作,通过[targetId](../reference/apis-arkui/capi-native-node-h.md#oh_arkui_nodeevent_gettargetid)区分不同按钮触发的事件。 227 228 ```cpp 229 nodeAPI->registerNodeEventReceiver([](ArkUI_NodeEvent *event) { 230 auto eventType = OH_ArkUI_NodeEvent_GetEventType(event); 231 auto targetId = OH_ArkUI_NodeEvent_GetTargetId(event); 232 ArkUI_NodeHandle node = OH_ArkUI_NodeEvent_GetNodeHandle(event); 233 auto *dragEvent = OH_ArkUI_NodeEvent_GetDragEvent(event); 234 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 235 "targetId=%{public}d,eventType=%{public}d,", targetId, 236 eventType); 237 switch (eventType) { 238 case NODE_ON_TOUCH_INTERCEPT: { 239 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 240 "ARKUI_NODE_BUTTON touch intercept"); 241 break; 242 } 243 case NODE_ON_DROP: { 244 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", "NODE_ON_DROP EventReceiver"); 245 } 246 } 247 }); 248 ``` 2493. 起拖阶段设置。 250 251 在NODE_ON_TOUCH_INTERCEPT事件中,需要对DragAction进行相关设置。为了主动发起拖拽,需要创建[pixelMap](../reference/apis-image-kit/capi-pixelmap-native-h.md#oh_pixelmapnative_createpixelmap),设置[dragPreviewOption](../reference/apis-arkui/capi-drag-and-drop-h.md#函数)和跟手点,并将拖拽过程中的文本数据设置到DragAction中。 252 253 ```cpp 254 case NODE_ON_TOUCH_INTERCEPT: { 255 // 设置pixelMap 256 uint8_t data[960000]; 257 size_t dataSize = 960000; 258 for (int i = 0; i < dataSize; i++) { 259 data[i] = i + 1; 260 } 261 // 创建参数结构体实例,并设置参数 262 OH_Pixelmap_InitializationOptions *createOpts; 263 OH_PixelmapInitializationOptions_Create(&createOpts); 264 OH_PixelmapInitializationOptions_SetWidth(createOpts, 200); 265 OH_PixelmapInitializationOptions_SetHeight(createOpts, 300); 266 OH_PixelmapInitializationOptions_SetPixelFormat(createOpts, PIXEL_FORMAT_BGRA_8888); 267 OH_PixelmapInitializationOptions_SetAlphaType(createOpts, PIXELMAP_ALPHA_TYPE_UNKNOWN); 268 // 创建Pixelmap实例 269 OH_PixelmapNative *pixelmap = nullptr; 270 OH_PixelmapNative_CreatePixelmap(data, dataSize, createOpts, &pixelmap); 271 OH_PixelmapNative_Rotate(pixelmap, 90.0); 272 OH_PixelmapNative_Opacity(pixelmap, 0.2); 273 OH_PixelmapNative_Scale(pixelmap, 0.8, 1.0); 274 OH_PixelmapNative_Flip(pixelmap, true, true); 275 std::vector<OH_PixelmapNative *> pixelVector; 276 pixelVector.push_back(pixelmap); 277 int returnValue; 278 switch (targetId) { 279 case buttonTouch: { 280 // 创建DragAction 281 auto action1 = OH_ArkUI_CreateDragActionWithNode(node); 282 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 283 "OH_ArkUI_CreateDragActionWithNode returnValue = %{public}p", action1); 284 returnValue = 285 OH_ArkUI_DragAction_SetPixelMaps(action1, pixelVector.data(), pixelVector.size()); 286 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 287 "OH_ArkUI_DragAction_SetPixelMaps returnValue = %{public}d", returnValue); 288 // 设置DragPreviewOption 289 auto *previewOptions1 = OH_ArkUI_CreateDragPreviewOption(); 290 OH_ArkUI_DragPreviewOption_SetScaleMode( 291 previewOptions1, ArkUI_DragPreviewScaleMode::ARKUI_DRAG_PREVIEW_SCALE_DISABLED); 292 OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(previewOptions1, true); 293 OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(previewOptions1, true); 294 returnValue = OH_ArkUI_DragAction_SetDragPreviewOption(action1, previewOptions1); 295 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 296 "OH_ArkUI_DragAction_SetDragPreviewOption returnValue = %{public}d", 297 returnValue); 298 // 设置pointerId 299 returnValue = OH_ArkUI_DragAction_SetPointerId(action1, 0); // -1 0 10 300 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 301 "OH_ArkUI_DragAction_SetPointerId returnValue = %{public}d", returnValue); 302 // 设置touchPoint 303 returnValue = OH_ArkUI_DragAction_SetTouchPointX(action1, 200); // -1 0 200 304 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 305 "OH_ArkUI_DragAction_SetTouchPointX returnValue = %{public}d", returnValue); 306 returnValue = OH_ArkUI_DragAction_SetTouchPointY(action1, 200); // -1 0 200 307 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 308 "OH_ArkUI_DragAction_SetTouchPointY returnValue = %{public}d", returnValue); 309 // 设置unifiedData 310 // 创建OH_UdmfRecord对象 311 OH_UdmfRecord *record = OH_UdmfRecord_Create(); 312 // 向OH_UdmfRecord中添加纯文本类型数据 313 OH_UdsPlainText *plainText = OH_UdsPlainText_Create(); 314 int returnStatus; 315 OH_UdsPlainText_SetAbstract(plainText, "this is plainText Abstract example"); 316 OH_UdsPlainText_SetContent(plainText, "this is plainText Content example"); 317 returnStatus = OH_UdmfRecord_AddPlainText(record, plainText); 318 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 319 "dragTest OH_UdmfRecord_AddPlainText returnStatus = %{public}d", returnStatus); 320 // 创建OH_UdmfData对象 321 OH_UdmfData *data = OH_UdmfData_Create(); 322 // 向OH_UdmfData中添加OH_UdmfRecord 323 returnStatus = OH_UdmfData_AddRecord(data, record); 324 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 325 "dragTest OH_UdmfData_AddRecord returnStatus = %{public}d", returnStatus); 326 returnValue = OH_ArkUI_DragAction_SetData(action1, data); 327 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 328 "OH_ArkUI_DragAction_SetData returnValue = %{public}d", returnValue); 329 // startDrag 330 returnValue = OH_ArkUI_StartDrag(action1); 331 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 332 "OH_ArkUI_StartDrag returnValue = %{public}d", returnValue); 333 OH_ArkUI_DragAction_Dispose(action1); 334 } 335 } 336 } 337 ``` 3384. 处理NODE_ON_DROP事件。 339 340 在NODE_ON_DROP事件中,应用可以执行与落入阶段相关的操作。通常情况下,需要从DragEvent中获取拖拽过程中传递的数据,DragAction中的拖拽数据也需要通过DragEvent获取。 341 342 ```cpp 343 case NODE_ON_DROP: { 344 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", "NODE_ON_DROP EventReceiver"); 345 // 获取UDMF data 346 int returnValue; 347 // 创建OH_UdmfData对象 348 OH_UdmfData *data = OH_UdmfData_Create(); 349 returnValue = OH_ArkUI_DragEvent_GetUdmfData(dragEvent, data); 350 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 351 "OH_ArkUI_DragEvent_GetUdmfData returnValue = %{public}d", returnValue); 352 // 判断OH_UdmfData是否有对应的类型 353 bool resultUdmf = OH_UdmfData_HasType(data, UDMF_META_PLAIN_TEXT); 354 if (resultUdmf) { 355 // 获取OH_UdmfData的记录 356 unsigned int recordsCount = 0; 357 OH_UdmfRecord **records = OH_UdmfData_GetRecords(data, &recordsCount); 358 // 获取records中的元素 359 int returnStatus; 360 for (int i = 0; i < recordsCount; i++) { 361 // 从OH_UdmfRecord中获取纯文本类型数据 362 OH_UdsPlainText *plainTextValue = OH_UdsPlainText_Create(); 363 returnStatus = OH_UdmfRecord_GetPlainText(records[i], plainTextValue); 364 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 365 "dragTest OH_UdmfRecord_GetPlainText " 366 "returnStatus= %{public}d", 367 returnStatus); 368 auto getAbstract = OH_UdsPlainText_GetAbstract(plainTextValue); 369 auto getContent = OH_UdsPlainText_GetContent(plainTextValue); 370 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 371 "OH_UdsPlainText_GetAbstract = " 372 "%{public}s, OH_UdsPlainText_GetContent = " 373 "%{public}s", 374 getAbstract, getContent); 375 // 使用结束后销毁指针 376 OH_UdsPlainText_Destroy(plainTextValue); 377 } 378 } else { 379 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "dragTest", 380 "OH_UdmfData_HasType not contain UDMF_META_PLAIN_TEXT"); 381 } 382 OH_UdmfData_Destroy(data); 383 break; 384 } 385 ```