Developer Guide

Tutorial: Touch events on AR Contents in CraftAR

icon Date Developer Guide

icon Date Dec 17, 2020

icon author Catchoom Team

icon folder , , ,

This section applies only to the Augmented Reality SDK v4 +. For earlier versions of the Augmented Reality SDK, check out the section below

In case you’re not familiar with AR Contents, we suggest you to read the article Overview of Augmented Reality Contents in CraftAR

Touch events in AR contents are triggered when a user touches the screen interacting with the content. We classify these interactions as:

  • Touch in: Movement into a content of an AR Item (swipe into the content)
  • Touch out : A movement out of a content of an AR Item (swipe out of the content)
  • Touch down: A content has been pressed
  • Touch up: A press was released (user stopped touching the screen), when the user was touching this content

Touch events on Android

In order to handle the touch events in Android, you just need to set the OnTouchEventListener to the CraftAR SDK instance as follows:

You can also handle the click event individually by setting the OnContentClickListener:

Touch events on iOS

Once you have the protocol and the delegate set up, you just need to implement the method to receive the events when the screen is touched over some contents:

This section applies only to the Augmented Reality SDK v3 or earlier. For the Augmented Reality SDK v4 or newer, check out the section above

There are certain applications, such as interactive catalogues, where the user is interested in interacting with augmented reality experiences.

This article describes how to listen to touch events on customized AR Contents. In order to customize contents, you’ll need to follow the steps described in the Tutorial: Customize AR Contents.

In case you’re not familiar with AR Contents, we suggest you to read the article Overview of Augmented Reality Contents in CraftAR

Touch events in AR contents are triggered when a user touches the screen interacting with the content. We classify these interactions as:

  • Touch in: Movement into a content of an AR Item (swipe into the content)
  • Touch out : A movement out of a content of an AR Item (swipe out of the content)
  • Touch down: A content has been pressed
  • Touch up: A press was released (user stopped touching the screen), when the user was touching this content

Touch events on Android

In order to handle the touch events in Android, extend the specific CraftARTrackingContent class and provide a OnTouchEventListener. In the following example, we extend the ImageButton class:

Handling click events directly

The CraftAR Augmented Reality SDK for Android also provides an interface to handle click events directly. Click events are triggered when a user performs a touch-down in a content, followed by a touch-up inside the same content.

In order to add a listener for the click events in any type of ARContent, set an OnContentClickListener for that content:

Handling click events on AR Buttons

AR Buttons have a predefined action for click events. If the button has an associated URL, the SDK will launch a browser that opens that URL. You can specify this URL using the ‘Action URL’ field in the CraftAR Creator, or by using the ‘hyperlink_url’ field of the contents in the Management API. By setting a content click listener to a button, that button will no longer open the web browser.

Touch events on iOS

In order to handle the touch events on iOS, it is necessary to extend the specific CraftARTrackingContent (or all of them). In the following example, we extend the ImageButton class:

Don’t forget to call super in your implementation:

Related Posts in Developer Guide