Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ba5d8e8 authored by Mihai Popa's avatar Mihai Popa
Browse files

[Magnifier-24] Add completion callback TestApi

The CL adds a TestApi callback mechanism which enables CTS tests to know
when magnifier operations have completed. This is required since
the magnifier is using an auxiliary thread (different from the main
thread) to do work.

Bug: 72041926
Test: atest CtsWidgetTestCases:android.widget.cts.MagnifierTest
Change-Id: I44f324297b63910d19d60bd7462e9aee8d8a4f3e
parent 8b789106
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1096,6 +1096,11 @@ package android.widget {
    method public android.graphics.Bitmap getContent();
    method public static android.graphics.PointF getMagnifierDefaultSize();
    method public android.graphics.Rect getWindowPositionOnScreen();
    method public void setOnOperationCompleteCallback(android.widget.Magnifier.Callback);
  }

  public static abstract interface Magnifier.Callback {
    method public abstract void onOperationComplete();
  }

  public class NumberPicker extends android.widget.LinearLayout {
+41 −2
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ public final class Magnifier {
            if (mWindow == null) {
                mWindow = new InternalPopupWindow(mView.getContext(), mView.getDisplay(),
                        getValidViewSurface(), mWindowWidth, mWindowHeight, mWindowElevation,
                        Handler.getMain() /* draw the magnifier on the UI thread */);
                        Handler.getMain() /* draw the magnifier on the UI thread */, mCallback);
            }
            performPixelCopy(startX, startY, true /* update window position */);
            mPrevPosInView.x = xPosInView;
@@ -331,6 +331,8 @@ public final class Magnifier {
        private final Runnable mMagnifierUpdater;
        // The handler where the magnifier updater jobs will be post'd.
        private final Handler mHandler;
        // The callback to be run after the next draw. Only used for testing.
        private Callback mCallback;

        // Members below describe the state of the magnifier. Reads/writes to them
        // have to be synchronized between the UI thread and the thread that handles
@@ -351,8 +353,9 @@ public final class Magnifier {
        InternalPopupWindow(final Context context, final Display display,
                final Surface parentSurface,
                final int width, final int height, final float elevation,
                final Handler handler) {
                final Handler handler, final Callback callback) {
            mDisplay = display;
            mCallback = callback;

            mContentWidth = width;
            mContentHeight = height;
@@ -535,6 +538,31 @@ public final class Magnifier {
            }

            mRenderer.draw(callback);
            if (mCallback != null) {
                mCallback.onOperationComplete();
            }
        }
    }

    // The rest of the file consists of test APIs.

    /**
     * See {@link #setOnOperationCompleteCallback(Callback)}.
     */
    @TestApi
    private Callback mCallback;

    /**
     * Sets a callback which will be invoked at the end of the next
     * {@link #show(float, float)} or {@link #update()} operation.
     *
     * @hide
     */
    @TestApi
    public void setOnOperationCompleteCallback(final Callback callback) {
        mCallback = callback;
        if (mWindow != null) {
            mWindow.mCallback = callback;
        }
    }

@@ -584,4 +612,15 @@ public final class Magnifier {
        size.y = resources.getDimension(com.android.internal.R.dimen.magnifier_height) / density;
        return size;
    }

    /**
     * @hide
     */
    @TestApi
    public interface Callback {
        /**
         * Callback called after the drawing for a magnifier update has happened.
         */
        void onOperationComplete();
    }
}