Merge "Revert "Fix mPositionInWindow to not use global coords"" into sc-dev
This commit is contained in:
@@ -21,10 +21,13 @@ import static java.util.Objects.requireNonNull;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.UiThread;
|
import android.annotation.UiThread;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.CancellationSignal;
|
import android.os.CancellationSignal;
|
||||||
|
|
||||||
|
import com.android.internal.util.FastMath;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -40,7 +43,8 @@ public final class ScrollCaptureTarget {
|
|||||||
private final int mHint;
|
private final int mHint;
|
||||||
private Rect mScrollBounds;
|
private Rect mScrollBounds;
|
||||||
|
|
||||||
private final int[] mTmpIntArr = new int[2];
|
private final float[] mTmpFloatArr = new float[2];
|
||||||
|
private final Matrix mMatrixViewLocalToWindow = new Matrix();
|
||||||
|
|
||||||
public ScrollCaptureTarget(@NonNull View scrollTarget, @NonNull Rect localVisibleRect,
|
public ScrollCaptureTarget(@NonNull View scrollTarget, @NonNull Rect localVisibleRect,
|
||||||
@NonNull Point positionInWindow, @NonNull ScrollCaptureCallback callback) {
|
@NonNull Point positionInWindow, @NonNull ScrollCaptureCallback callback) {
|
||||||
@@ -113,15 +117,28 @@ public final class ScrollCaptureTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void zero(float[] pointArray) {
|
||||||
|
pointArray[0] = 0;
|
||||||
|
pointArray[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void roundIntoPoint(Point pointObj, float[] pointArray) {
|
||||||
|
pointObj.x = FastMath.round(pointArray[0]);
|
||||||
|
pointObj.y = FastMath.round(pointArray[1]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh the local visible bounds and its offset within the window, based on the current
|
* Refresh the local visible bounds and it's offset within the window, based on the current
|
||||||
* state of the {@code containing view}.
|
* state of the {@code containing view}.
|
||||||
*/
|
*/
|
||||||
@UiThread
|
@UiThread
|
||||||
public void updatePositionInWindow() {
|
public void updatePositionInWindow() {
|
||||||
mContainingView.getLocationInWindow(mTmpIntArr);
|
mMatrixViewLocalToWindow.reset();
|
||||||
mPositionInWindow.x = mTmpIntArr[0];
|
mContainingView.transformMatrixToGlobal(mMatrixViewLocalToWindow);
|
||||||
mPositionInWindow.y = mTmpIntArr[1];
|
|
||||||
|
zero(mTmpFloatArr);
|
||||||
|
mMatrixViewLocalToWindow.mapPoints(mTmpFloatArr);
|
||||||
|
roundIntoPoint(mPositionInWindow, mTmpFloatArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
Reference in New Issue
Block a user