Skip to content

Commit 9ea77fc

Browse files
author
Jeff Brown
committed
Avoid calling into JNI if not needed.
Short-circuit a few MotionEvent JNI calls in simple cases. Change-Id: I6c97c06b5a5fd203a423dc88f428637b9dec71ae
1 parent e67ca42 commit 9ea77fc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

core/java/android/view/MotionEvent.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,14 +1654,22 @@ public final void recycle() {
16541654
}
16551655
}
16561656
}
1657-
1657+
16581658
/**
1659-
* Scales down the coordination of this event by the given scale.
1659+
* Applies a scale factor to all points within this event.
1660+
*
1661+
* This method is used to adjust touch events to simulate different density
1662+
* displays for compatibility mode. The values returned by {@link #getRawX()},
1663+
* {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
1664+
* are also affected by the scale factor.
16601665
*
1666+
* @param scale The scale factor to apply.
16611667
* @hide
16621668
*/
16631669
public final void scale(float scale) {
1664-
nativeScale(mNativePtr, scale);
1670+
if (scale != 1.0f) {
1671+
nativeScale(mNativePtr, scale);
1672+
}
16651673
}
16661674

16671675
/** {@inheritDoc} */
@@ -2631,7 +2639,9 @@ public final void setAction(int action) {
26312639
* @param deltaY Amount to add to the current Y coordinate of the event.
26322640
*/
26332641
public final void offsetLocation(float deltaX, float deltaY) {
2634-
nativeOffsetLocation(mNativePtr, deltaX, deltaY);
2642+
if (deltaX != 0.0f || deltaY != 0.0f) {
2643+
nativeOffsetLocation(mNativePtr, deltaX, deltaY);
2644+
}
26352645
}
26362646

26372647
/**
@@ -2644,7 +2654,7 @@ public final void offsetLocation(float deltaX, float deltaY) {
26442654
public final void setLocation(float x, float y) {
26452655
float oldX = getX();
26462656
float oldY = getY();
2647-
nativeOffsetLocation(mNativePtr, x - oldX, y - oldY);
2657+
offsetLocation(x - oldX, y - oldY);
26482658
}
26492659

26502660
/**

0 commit comments

Comments
 (0)