Skip to content

Commit

Permalink
[TIMOB-24317] Android: Focus area for view pinch event (#8757)
Browse files Browse the repository at this point in the history
* add pinch event properties

* extend more properties from ScaleGestureDetector

* docs

* Update View.yml

* Update TiC.java

* Update TiUIView.java

* Update View.yml
  • Loading branch information
HazemKhaled authored and hansemannn committed Jun 28, 2018
1 parent 965ffd5 commit d0a48c1
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 3 deletions.
55 changes: 55 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,61 @@ public class TiC
*/
public static final String EVENT_PROPERTY_SCALE = "scale";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_TIME = "time";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_FOCUS_X = "focusX";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_FOCUS_Y = "focusY";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_CURRENT_SPAN = "currentSpan";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_CURRENT_SPAN_X = "currentSpanX";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_CURRENT_SPAN_Y = "currentSpanY";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_PREVIOUS_SPAN = "previousSpan";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_PREVIOUS_SPAN_X = "previousSpanX";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_PREVIOUS_SPAN_Y = "previousSpanY";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_TIME_DELTA = "timeDelta";

/**
* @module.api
*/
public static final String EVENT_PROPERTY_IN_PROGRESS = "inProgress";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,18 @@ public boolean onScale(ScaleGestureDetector sgd)

if (didScale) {
KrollDict data = new KrollDict();
data.put(TiC.EVENT_PROPERTY_CURRENT_SPAN, sgd.getCurrentSpan());
data.put(TiC.EVENT_PROPERTY_CURRENT_SPAN_X, sgd.getCurrentSpanX());
data.put(TiC.EVENT_PROPERTY_CURRENT_SPAN_Y, sgd.getCurrentSpanY());
data.put(TiC.EVENT_PROPERTY_TIME, sgd.getEventTime());
data.put(TiC.EVENT_PROPERTY_FOCUS_X, sgd.getFocusX());
data.put(TiC.EVENT_PROPERTY_FOCUS_Y, sgd.getFocusY());
data.put(TiC.EVENT_PROPERTY_PREVIOUS_SPAN, sgd.getPreviousSpan());
data.put(TiC.EVENT_PROPERTY_PREVIOUS_SPAN_X, sgd.getPreviousSpanX());
data.put(TiC.EVENT_PROPERTY_PREVIOUS_SPAN_Y, sgd.getPreviousSpanY());
data.put(TiC.EVENT_PROPERTY_SCALE, sgd.getCurrentSpan() / startSpan);
data.put(TiC.EVENT_PROPERTY_TIME_DELTA, sgd.getTimeDelta());
data.put(TiC.EVENT_PROPERTY_IN_PROGRESS, sgd.isInProgress());
data.put(TiC.EVENT_PROPERTY_VELOCITY, (sgd.getScaleFactor() - 1.0f) / timeDelta * 1000);
data.put(TiC.EVENT_PROPERTY_SOURCE, proxy);

Expand Down
88 changes: 85 additions & 3 deletions apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ events:
- name: pinch
summary: Fired when the device detects a pinch gesture.
description: |
A pinch is a touch and expand or contract
with two fingers. The event occurs continuously until a finger is lifted again.
platforms: [iphone,ipad]
A pinch is a touch and expand or contract
with two fingers. The event occurs continuously until a finger is lifted again.
platforms: [iphone, ipad, android]
since: "1.8.0"
properties:
- name: scale
Expand All @@ -328,6 +328,88 @@ events:
- name: velocity
summary: The velocity of the pinch in scale factor per second.
type: Number

- name: time
summary: The event time of the current event being processed.
type: Number
since: "7.4.0"
platforms: [android]

- name: timeDelta
summary: |
The time difference in milliseconds between the previous accepted scaling event and the
current scaling event.
type: Number
since: "7.4.0"
platforms: [android]

- name: currentSpan
summary: |
The average distance between each of the pointers forming the gesture in progress through
the focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: currentSpanX
summary: |
The average X distance between each of the pointers forming the gesture in progress through
the focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: currentSpanY
summary: |
The average Y distance between each of the pointers forming the gesture in progress through
the focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: previousSpan
summary: |
The previous average distance between each of the pointers forming the gesture in progress through
the focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: previousSpanX
summary: |
The previous average X distance between each of the pointers forming the gesture in progress through
the focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: previousSpanY
summary: |
The previous average Y distance between each of the pointers forming the gesture in progress through
the focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: focusX
summary: |
The X coordinate of the current gesture's focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: focusY
summary: |
The Y coordinate of the current gesture's focal point.
type: Number
since: "7.4.0"
platforms: [android]

- name: inProgress
summary: Returns `true` if a scale gesture is in progress, `false` otherwise.
type: Number
since: "7.4.0"
platforms: [android]

- name: postlayout
summary: Fired when a layout cycle is finished.
Expand Down

0 comments on commit d0a48c1

Please sign in to comment.