Anti-Misoperation Mechanism for Buttons

Last Updated on : 2025-05-26 02:48:53download

This anti-misoperation feature prevents accidental triggering of reset buttons to avoid user experience issues.

Check support for anti-misoperation feature

Initialization

private var manager: PreventAccidentalTouchManager? = null
manager = PreventAccidentalTouchManager(deviceId)

API description

abstract fun isSupportPreventAccidentalTouch(callback: IThingResultCallback<Boolean>)

Parameters

Parameter Description
callback The callback function.

Example

manager?.isSupportPreventAccidentalTouch(object : IThingResultCallback<Boolean>{
            override fun onSuccess(result: Boolean?) {

            }

            override fun onError(errorCode: String?, errorMessage: String?) {

            }
        })

Add a listener

You need to add a listener to get the anti-misoperation status. The added listener will return the current status of the anti-misoperation switch in real time. The return value true means the anti-misoperation mode is enabled, and false means the anti-misoperation mode is disabled.

API description

abstract fun addStatusListener(listener: PreventAccidentalTouchStatusListener)

Parameters

Parameter Description
listener The listener for the anti-misoperation status.

Example

private val mPreventAccidentalTouchStatusListener: PreventAccidentalTouchStatusListener =
        object : PreventAccidentalTouchStatusListener {
            override fun onStatusUpdate(status: Boolean) {

            }
        }
manager?.addStatusListener(mPreventAccidentalTouchStatusListener)

Remove a listener

API description

abstract fun removeStatusListener(listener: PreventAccidentalTouchStatusListener)

Parameters

Parameter Description
listener The listener for the anti-misoperation status.

Example

override fun onDestroy() {
        manager?.removeStatusListener(mPreventAccidentalTouchStatusListener)
        super.onDestroy()
    }

Get the anti-misoperation status

API description

abstract fun getPreventAccidentalTouchStatus()

You need to add a listener to get the anti-misoperation status. The added listener will return the current status of the anti-misoperation switch in real time. The return value true means the anti-misoperation mode is enabled, and false means the anti-misoperation mode is disabled.

Example

manager?.let { preventAccidentalTouchManager ->
            preventAccidentalTouchManager.getPreventAccidentalTouchStatus()
}

Set the anti-misoperation status

API description

abstract fun updatePreventAccidentalTouchStatus(status:Boolean)

You need to add a listener to get the anti-misoperation status. The added listener will return the current status of the anti-misoperation switch in real time. The return value true means the anti-misoperation mode is enabled, and false means the anti-misoperation mode is disabled.

Parameters

Parameter Description
status The status.
  • true: The anti-misoperation mode is enabled.
  • false: The anti-misoperation mode is disabled.

Example

manager?.updatePreventAccidentalTouchStatus(isChecked)