harmony 鸿蒙@ohos.deviceStatus.dragInteraction (Drag Interaction)

  • 2023-10-30
  • 浏览 (161)

@ohos.deviceStatus.dragInteraction (Drag Interaction)

The dragInteraction module provides the APIs to enable and disable listening for dragging status changes.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs provided by this module are system APIs.

Modules to Import

import dragInteraction from '@ohos.deviceStatus.dragInteraction'

DragState

Enumerates dragging states.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Name Value Description
MSG_DRAG_STATE_START 1 Dragging starts.
MSG_DRAG_STATE_STOP 2 Dragging is ended.
MSG_DRAG_STATE_CANCEL 3 Dragging is canceled.

Example

enum DragState {
    MSG_DRAG_STATE_START = 1,
    MSG_DRAG_STATE_STOP = 2,
    MSG_DRAG_STATE_CANCEL = 3
}

dragInteraction.on(‘drag’)

on(type: ‘drag’, callback: Callback<DragState>): void;

Enables listening for dragging status changes.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Parameters

Name Type Mandatory Description
type string Yes Event type. This field has a fixed value of drag.
callback Callback<DragState> Yes Callback used to return the dragging status.

Example

try {
  dragInteraction.on('drag', (data : DragState) => {
    console.log(`Drag interaction event: ${JSON.stringify(data)}`);
  });
} catch (error) {
  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

dragInteraction.off(‘drag’)

off(type: ‘drag’, callback?: Callback<DragState>): void;

Disables listening for dragging status changes.

System capability: SystemCapability.Msdp.DeviceStatus.Drag

Parameters

Name Type Mandatory Description
type string Yes Event type. This field has a fixed value of drag.
callback Callback<DragState> No Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.

Example

// Unregister a single callback.
function single_callback(event : DragState) {
  console.log(`Drag interaction event: ${JSON.stringify(event)}`);
  return false;
}
try {
  dragInteraction.on('drag', single_callback);
  dragInteraction.off("drag", single_callback);
} catch (error) {
  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// Unregister all callbacks.
function all_callback(event : DragState) {
  console.log(`Drag interaction event: ${JSON.stringify(event)}`);
  return false;
}
try {
  dragInteraction.on('drag', all_callback);
  dragInteraction.off("drag");
} catch (error) {
  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞