Functions
The Gesture API contains the following functions, which are part of the kony.application Namespace.
Using the addGestureRecognizerForAllForms function, you can set a gesture recognizer for all the forms.
Syntax
kony.application.addGestureRecognizerForAllForms (gestureType, gestureConfigParams,onGestureClosure);
Input Parameters
gestureType [Number] - Mandatory
Indicates the type of gesture that must be detected on the widget. Following are the possible gestureType values:
- 1 – constants.GESTURE_TYPE_TAP
- 2 - constants.GESTURE_TYPE_SWIPE
- 3 – constants.GESTURE_TYPE_LONGPRESS
- 4 – constants.GESTURE_TYPE_PAN
- 5 – constants.GESTURE_TYPE_ROTATION (Not supported by Android platform)
- 6 - constants.GESTURE_TYPE_PINCH
gestureConfigParams [object] - Mandatory
Specifies a table that has the configuration parameters that are required to setup a gesture recognizer. The configuration parameters vary based on the type of the gesture.
Gesture Type | Configuration Parameter |
---|---|
TAP |
|
SWIPE |
|
LONGPRESS |
For example, {pressDuration:1} |
PAN |
|
ROTATION |
|
PINCH |
|
onGestureClosure [function] - Mandatory
Specifies the function that needs to be executed when a gesture is recognized. This function will be raised asynchronously and has the following signature:
onGestureClosure(widgetRef, gestureInfo, context)
Parameter | Description |
---|---|
widgetRef | specifies the handle to the widget on which the gesture was recognized. |
gestureInfo | Table with information about the gesture. The contents of this table vary based on the gesture type. |
context | Table with SegmentedUI row details. |
gestureInfo table has the following key-value pairs:
Key | Description |
---|---|
gestureType [number] | Indicates the gesture type |
gesturesetUpParams [object] | Specifies the set up parameters passed while adding the gesture recognizer |
gesturePosition [number] | Indicates the position where the gesture is recognized. Possible values are:
|
swipeDirection [number] | Indicates the direction of swipe. Direction is w.r.t the view and not device orientation. This parameter is applicable only if the gesture type is SWIPE. Possible values are:
|
gestureX [number] | specifies the X coordinate of the point (in pixels) where the gesture has occurred. The coordinate is relative to the widget coordinate system. |
gestureY [number] | specifies the Y coordinate of the point (in pixels) where the gesture has occurred. The coordinate is relative to the widget coordinate system. |
widgetWidth [number] | specifies the width of the widget (in pixels). |
widgetHeight [number] | specifies the height of the widget (in pixels). |
gestureState[number] | Indicates the gesture state. The gestureState is applicable only for continuous gestures like PAN, ROTATION, and PINCH.
|
rotation [number] | |
velocityX and velocityY | horizontal and vertical component of velocity expressed in points per second. (Applicable only for PAN gesture type) |
velocity [number] | velocity of pinch in scale per second. (Applicable only for Pinch gesture) |
scale [number] | scale factor relative to the points of the two touches in screen coordinates. |
translationX and translationY [number] | Cumulative distance as number. (Applicable only for PAN gesture type) |
context table has the following key-value pairs:
Key | Description |
---|---|
rowIndex [number] | Row index of the segment UI where gesture is recognized. (Applicable to gestures added to segUI rows) |
sectionIndex [number] | Section index of the segment UI where gesture is recognized. (Applicable to gestures added to segUI rows) |
Example
//Defining a function function formGesture(widgetID, gestureInfo) { var y = kony.type(gestureInfo); //expected value of y = table var z = kony.type(gestureInfo.gesturesetUpParams); //expected values of z = table var a = gestureInfo.gestureType; var b = gestureInfo.gesturesetUpParams; var c = gestureInfo.gesturePosition; var d = gestureInfo.gestureX; var e = gestureInfo.gestureY; var f = gestureInfo.widgetWidth; var g = gestureInfo.widgetHeight; kony.print("*******************************************"); if (kony.os.toNumber(gestureInfo.gestureType) == 2) { h = gestureInfo.swipeDirection; kony.print("swipe direction is: " + h); } else { h = ""; } if (kony.os.toNumber(a) == 1) { b1 = "fingers: " + gestureInfo.gesturesetUpParams.fingers; b2 = "taps: " + gestureInfo.gesturesetUpParams.taps; kony.print("" + b1 + "" + b2); } else if (kony.os.toNumber(a) == 2) { b1 = "fingers :" + gestureInfo.gesturesetUpParams.fingers; b2 = ""; kony.print("" + b1 + "" + b2); } else if (kony.os.toNumber(a) == 3) { b1 = "pressduration:" + gestureInfo.gesturesetUpParams pressDuration; b2 = ""; kony.print("" + b1 + "" + b2); } kony.print("widget id is: " + widgetID[id]); //will print the widgetID. //To print widgetID use widgetID.id kony.print("type of gestureInfo is: " + y); kony.print("type of gesturesetUpParams is: " + z); kony.print("gestureType is: " + a); //gestureType=1 or 2 or 3 kony.print("gesturesetUpParams is: " + b.fingers); /*gesturesetUpParams = { fingers = 1, taps = 1 } or { fingers = 1, taps = 2 } or { fingers = 1 } or { pressDuration = 1 }*/ kony.print("gesturePosition is: " + c); //gesturePosition=1 or 2 or 3 or .....9 kony.print("gestureX is: " + d); //ex: gestureX=30 kony.print("gestureY is: " + e); //ex: gestureY=100 kony.print("widgetWidth is: " + f); //ex: widgetWidth=320 kony.print("widgetHeight is: " + g); //ex: widgetHeight=28 //gesturePosition, gestureX, gestureY, widgetWidth, widgetHeight params are not applicable in android kony.print("*******************************************"); } function callbackSingleTapGesture() { var x = { fingers: 1, taps: 1 }; try { kony.application.addGestureRecognizerForAllForms(1, x, formGesture); } catch (err) { alert(typeof err); alert("error in function callbackSingleTapGesture: " + err.message); } }
Return Values
String - Reference to the gesture is returned.
Platform Availability
Available on all platforms except Desktop Web.
This method allows you to remove a specified gesture recognizer for all Forms.
Syntax
kony.application.removeGestureRecognizerForAllForms(uniqueIdentifier);
Input Parameters
Parameter | Description |
---|---|
uniqueIdentifier - Mandatory | Reference to the gesture. The reference to the gesture is returned by the setGestureRecognizerForAllForms. |
Example
function callbackClearLongPressGesture() { try { kony.application.removeGestureRecognizerForAllForms(uniqueidentifier); } catch (err) { alert(typeof err); alert("error in function callbackClearLongPressGesture: " + err.message); } }
Platform Availability
Available on all platforms except Desktop Web.