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

Commit 28a10589 authored by Ryan Lin's avatar Ryan Lin Committed by Android (Google) Code Review
Browse files

Merge changes Ic12d6d90,Iecd5e1bc

* changes:
  Implement transitn animation while switching the mode
  Change magnification animation callback (2/2)
parents f50b1540 379e238c
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.accessibility;

/**
 * A callback for magnification animation result.
 * @hide
 */

 oneway interface IRemoteMagnificationAnimationCallback {

    /**
     * Called when the animation is finished or interrupted during animating.
     *
     * @param success {@code true} if animating successfully with given spec or the spec did not
     *                change. Otherwise {@code false}
     */
    void onResult(boolean success);
}
+6 −5
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ package android.view.accessibility;

import android.graphics.PointF;
import android.graphics.Rect;
import android.os.RemoteCallback;
import android.view.accessibility.IWindowMagnificationConnectionCallback;
import android.view.accessibility.IRemoteMagnificationAnimationCallback;

/**
 * Interface for interaction between {@link AccessibilityManagerService}
@@ -38,10 +38,10 @@ oneway interface IWindowMagnificationConnection {
     *                or {@link Float#NaN} to leave unchanged.
     * @param centerY the screen-relative Y coordinate around which to center,
     *                or {@link Float#NaN} to leave unchanged.
     * @param endCallback The callback called when the animation is completed.
     * @param callback The callback called when the animation is completed or interrupted.
     */
    void enableWindowMagnification(int displayId, float scale, float centerX, float centerY,
        in RemoteCallback endCallback);
        in IRemoteMagnificationAnimationCallback callback);

    /**
     * Sets the scale of the window magnifier on specified display.
@@ -55,9 +55,10 @@ oneway interface IWindowMagnificationConnection {
     * Disables window magnification on specified display with animation.
     *
     * @param displayId The logical display id.
     * @param endCallback The callback called when the animation is completed.
     * @param callback The callback called when the animation is completed or interrupted.
     */
    void disableWindowMagnification(int displayId, in RemoteCallback endCallback);
    void disableWindowMagnification(int displayId,
        in IRemoteMagnificationAnimationCallback callback);

    /**
     * Moves the window magnifier on the specified display. It has no effect while animating.
+11 −10
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Handler;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.util.Log;
import android.view.SurfaceControl;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IRemoteMagnificationAnimationCallback;
import android.view.accessibility.IWindowMagnificationConnection;
import android.view.accessibility.IWindowMagnificationConnectionCallback;

@@ -101,10 +101,10 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall

    @MainThread
    void enableWindowMagnification(int displayId, float scale, float centerX, float centerY,
            @Nullable RemoteCallback endCallback) {
            @Nullable IRemoteMagnificationAnimationCallback callback) {
        //TODO: b/144080869 support multi-display.
        mWindowMagnificationAnimationController.enableWindowMagnification(scale, centerX, centerY,
                endCallback != null ? () -> endCallback.sendResult(null) : null);
                callback);
    }

    @MainThread
@@ -120,10 +120,10 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
    }

    @MainThread
    void disableWindowMagnification(int displayId, @Nullable RemoteCallback endCallback) {
    void disableWindowMagnification(int displayId,
            @Nullable IRemoteMagnificationAnimationCallback callback) {
        //TODO: b/144080869 support multi-display.
        mWindowMagnificationAnimationController.deleteWindowMagnification(
                endCallback != null ? () -> endCallback.sendResult(null) : null);
        mWindowMagnificationAnimationController.deleteWindowMagnification(callback);
    }

    @Override
@@ -182,10 +182,10 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall

        @Override
        public void enableWindowMagnification(int displayId, float scale, float centerX,
                float centerY, RemoteCallback remoteCallback) {
                float centerY, IRemoteMagnificationAnimationCallback callback) {
            mHandler.post(
                    () -> mWindowMagnification.enableWindowMagnification(displayId, scale, centerX,
                            centerY, remoteCallback));
                            centerY, callback));
        }

        @Override
@@ -194,9 +194,10 @@ public class WindowMagnification extends SystemUI implements WindowMagnifierCall
        }

        @Override
        public void disableWindowMagnification(int displayId, RemoteCallback remoteCallback) {
        public void disableWindowMagnification(int displayId,
                IRemoteMagnificationAnimationCallback callback) {
            mHandler.post(() -> mWindowMagnification.disableWindowMagnification(displayId,
                    remoteCallback));
                    callback));
        }

        @Override
+31 −17
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
import android.os.RemoteException;
import android.util.Log;
import android.view.accessibility.IRemoteMagnificationAnimationCallback;
import android.view.animation.AccelerateInterpolator;

import com.android.internal.annotations.VisibleForTesting;
@@ -38,7 +40,7 @@ import java.lang.annotation.RetentionPolicy;
class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUpdateListener,
        Animator.AnimatorListener {

    private static final String TAG = "WindowMagnificationBridge";
    private static final String TAG = "WindowMagnificationAnimationController";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    @Retention(RetentionPolicy.SOURCE)
@@ -61,7 +63,7 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
    private final Context mContext;
    // Called when the animation is ended successfully without cancelling or mStartSpec and
    // mEndSpec are equal.
    private Runnable mAnimationEndCallback;
    private IRemoteMagnificationAnimationCallback mAnimationCallback;
    // The flag to ignore the animation end callback.
    private boolean mEndAnimationCanceled = false;
    @MagnificationState
@@ -93,14 +95,16 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
     *                or {@link Float#NaN} to leave unchanged.
     * @param centerY The screen-relative Y coordinate around which to center,
     *                or {@link Float#NaN} to leave unchanged.
     * @param animationEndCallback Called when the transition is complete or the given arguments
     *                      are as same as current values.
     * @param animationCallback Called when the transition is complete, the given arguments
     *                          are as same as current values, or the transition is interrupted
     *                          due to the new transition request.
     *
     * @see #onAnimationUpdate(ValueAnimator)
     */
    void enableWindowMagnification(float scale, float centerX, float centerY,
            @Nullable Runnable animationEndCallback) {
        mAnimationEndCallback = animationEndCallback;
            @Nullable IRemoteMagnificationAnimationCallback animationCallback) {
        sendAnimationCallback(false);
        mAnimationCallback = animationCallback;
        setupEnableAnimationSpecs(scale, centerX, centerY);
        if (mEndSpec.equals(mStartSpec)) {
            if (mState == STATE_DISABLED) {
@@ -108,7 +112,7 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
            } else if (mState == STATE_ENABLING || mState == STATE_DISABLING) {
                mValueAnimator.cancel();
            }
            sendCallbackIfNeeded();
            sendAnimationCallback(true);
            setState(STATE_ENABLED);
        } else {
            if (mState == STATE_DISABLING) {
@@ -160,14 +164,17 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
     * Wraps {@link WindowMagnificationController#deleteWindowMagnification()}} with transition
     * animation. If the window magnification is enabling, it runs the animation in reverse.
     *
     * @param animationEndCallback Called when the transition is complete or the window
     *                    magnification is disabled already.
     * @param animationCallback Called when the transition is complete, the given arguments
     *                          are as same as current values, or the transition is interrupted
     *                          due to the new transition request.
     */
    void deleteWindowMagnification(@Nullable Runnable animationEndCallback) {
        mAnimationEndCallback = animationEndCallback;
    void deleteWindowMagnification(
            @Nullable IRemoteMagnificationAnimationCallback animationCallback) {
        sendAnimationCallback(false);
        mAnimationCallback = animationCallback;
        if (mState == STATE_DISABLED || mState == STATE_DISABLING) {
            if (mState == STATE_DISABLED) {
                sendCallbackIfNeeded();
                sendAnimationCallback(true);
            }
            return;
        }
@@ -220,7 +227,7 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
        } else {
            setState(STATE_ENABLED);
        }
        sendCallbackIfNeeded();
        sendAnimationCallback(true);
    }

    @Override
@@ -236,10 +243,17 @@ class WindowMagnificationAnimationController implements ValueAnimator.AnimatorUp
    public void onAnimationRepeat(Animator animation) {
    }

    private void sendCallbackIfNeeded() {
        if (mAnimationEndCallback != null) {
            mAnimationEndCallback.run();
            mAnimationEndCallback = null;
    private void sendAnimationCallback(boolean success) {
        if (mAnimationCallback != null) {
            try {
                mAnimationCallback.onResult(success);
                if (DEBUG) {
                    Log.d(TAG, "sendAnimationCallback success = " + success);
                }
            } catch (RemoteException e) {
                Log.w(TAG, "sendAnimationCallback failed : " + e);
            }
            mAnimationCallback = null;
        }
    }

+7 −15
Original line number Diff line number Diff line
@@ -23,13 +23,13 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Display;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IRemoteMagnificationAnimationCallback;
import android.view.accessibility.IWindowMagnificationConnection;
import android.view.accessibility.IWindowMagnificationConnectionCallback;

@@ -41,7 +41,6 @@ import com.android.systemui.statusbar.CommandQueue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -66,8 +65,7 @@ public class IWindowMagnificationConnectionTest extends SysuiTestCase {
    @Mock
    private ModeSwitchesController mModeSwitchesController;
    @Mock
    private RemoteCallback mRemoteCallback;
    private ArgumentCaptor<Runnable> mRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
    private IRemoteMagnificationAnimationCallback mAnimationCallback;
    private IWindowMagnificationConnection mIWindowMagnificationConnection;
    private WindowMagnification mWindowMagnification;

@@ -92,22 +90,21 @@ public class IWindowMagnificationConnectionTest extends SysuiTestCase {
    @Test
    public void enableWindowMagnification_passThrough() throws RemoteException {
        mIWindowMagnificationConnection.enableWindowMagnification(TEST_DISPLAY, 3.0f, Float.NaN,
                Float.NaN, mRemoteCallback);
                Float.NaN, mAnimationCallback);
        waitForIdleSync();

        verify(mWindowMagnificationAnimationController).enableWindowMagnification(eq(3.0f),
                eq(Float.NaN), eq(Float.NaN), mRunnableCaptor.capture());
        verifyRunnableWrapsRemoteCallback(mRunnableCaptor.getValue());
                eq(Float.NaN), eq(Float.NaN), eq(mAnimationCallback));
    }

    @Test
    public void disableWindowMagnification_deleteWindowMagnification() throws RemoteException {
        mIWindowMagnificationConnection.disableWindowMagnification(TEST_DISPLAY, mRemoteCallback);
        mIWindowMagnificationConnection.disableWindowMagnification(TEST_DISPLAY,
                mAnimationCallback);
        waitForIdleSync();

        verify(mWindowMagnificationAnimationController).deleteWindowMagnification(
                mRunnableCaptor.capture());
        verifyRunnableWrapsRemoteCallback(mRunnableCaptor.getValue());
                mAnimationCallback);
    }

    @Test
@@ -143,10 +140,5 @@ public class IWindowMagnificationConnectionTest extends SysuiTestCase {

        verify(mModeSwitchesController).removeButton(TEST_DISPLAY);
    }

    private void verifyRunnableWrapsRemoteCallback(Runnable runnable) {
        runnable.run();
        verify(mRemoteCallback).sendResult(null);
    }
}
Loading