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

Commit c6e7e2b9 authored by Roy Chou's avatar Roy Chou
Browse files

chore(#MagnificationThumbnail): rename thumbNail to thumbnail

Rename thumbNail to thumbnail to make camelcase consistency in magnification.

Bug: 278646377
Test: pass the make
      atest FullScreenMagnificationControllerTest
      atest MagnificationThumbnailTest
Change-Id: Iaf1ecb67e7ece8e63310afe830e410d0c23b3bdc
parent eaab4f25
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -597,14 +597,14 @@ public class FullScreenMagnificationController implements
        @GuardedBy("mLock")
        void updateThumbnail(float scale, float centerX, float centerY) {
            if (mMagnificationThumbnail != null) {
                mMagnificationThumbnail.updateThumbNail(scale, centerX, centerY);
                mMagnificationThumbnail.updateThumbnail(scale, centerX, centerY);
            }
        }

        @GuardedBy("mLock")
        void refreshThumbnail(float scale, float centerX, float centerY) {
            if (mMagnificationThumbnail != null) {
                mMagnificationThumbnail.setThumbNailBounds(
                mMagnificationThumbnail.setThumbnailBounds(
                        mMagnificationBounds,
                        scale,
                        centerX,
@@ -616,7 +616,7 @@ public class FullScreenMagnificationController implements
        @GuardedBy("mLock")
        void hideThumbnail() {
            if (mMagnificationThumbnail != null) {
                mMagnificationThumbnail.hideThumbNail();
                mMagnificationThumbnail.hideThumbnail();
            }
        }

+36 −36
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class MagnificationThumbnail {
    @VisibleForTesting
    public final FrameLayout mThumbnailLayout;

    private final View mThumbNailView;
    private final View mThumbnailView;
    private int mThumbnailWidth;
    private int mThumbnailHeight;

@@ -68,7 +68,7 @@ public class MagnificationThumbnail {
    private static final float ASPECT_RATIO = 14f;
    private static final float BG_ASPECT_RATIO = ASPECT_RATIO / 2f;

    private ObjectAnimator mThumbNailAnimator;
    private ObjectAnimator mThumbnailAnimator;
    private boolean mIsFadingIn;

    /**
@@ -81,7 +81,7 @@ public class MagnificationThumbnail {
        mWindowBounds =  mWindowManager.getCurrentWindowMetrics().getBounds();
        mThumbnailLayout = (FrameLayout) LayoutInflater.from(mContext)
                .inflate(R.layout.thumbnail_background_view, /* root: */ null);
        mThumbNailView =
        mThumbnailView =
                mThumbnailLayout.findViewById(R.id.accessibility_magnification_thumbnail_view);
        mBackgroundParams = createLayoutParams();
        mThumbnailWidth = 0;
@@ -94,15 +94,15 @@ public class MagnificationThumbnail {
     * @param currentBounds the current magnification bounds
     */
    @AnyThread
    public void setThumbNailBounds(Rect currentBounds, float scale, float centerX, float centerY) {
    public void setThumbnailBounds(Rect currentBounds, float scale, float centerX, float centerY) {
        if (DEBUG) {
            Log.d(LOG_TAG, "setThumbNailBounds " + currentBounds);
            Log.d(LOG_TAG, "setThumbnailBounds " + currentBounds);
        }
        mHandler.post(() -> {
            mWindowBounds = currentBounds;
            setBackgroundBounds();
            if (mVisible) {
                updateThumbNailMainThread(scale, centerX, centerY);
                updateThumbnailMainThread(scale, centerX, centerY);
            }
        });
    }
@@ -120,9 +120,9 @@ public class MagnificationThumbnail {
    }

    @MainThread
    private void showThumbNail() {
    private void showThumbnail() {
        if (DEBUG) {
            Log.d(LOG_TAG, "showThumbNail " + mVisible);
            Log.d(LOG_TAG, "showThumbnail " + mVisible);
        }
        animateThumbnail(true);
    }
@@ -131,14 +131,14 @@ public class MagnificationThumbnail {
     * Hides thumbnail and removes the view from the window when finished animating.
     */
    @AnyThread
    public void hideThumbNail() {
        mHandler.post(this::hideThumbNailMainThread);
    public void hideThumbnail() {
        mHandler.post(this::hideThumbnailMainThread);
    }

    @MainThread
    private void hideThumbNailMainThread() {
    private void hideThumbnailMainThread() {
        if (DEBUG) {
            Log.d(LOG_TAG, "hideThumbNail " + mVisible);
            Log.d(LOG_TAG, "hideThumbnail " + mVisible);
        }
        if (mVisible) {
            animateThumbnail(false);
@@ -159,14 +159,14 @@ public class MagnificationThumbnail {
                        + " fadeIn: " + fadeIn
                        + " mVisible: " + mVisible
                        + " isFadingIn: " + mIsFadingIn
                        + " isRunning: " + mThumbNailAnimator
                        + " isRunning: " + mThumbnailAnimator
            );
        }

        // Reset countdown to hide automatically
        mHandler.removeCallbacks(this::hideThumbNailMainThread);
        mHandler.removeCallbacks(this::hideThumbnailMainThread);
        if (fadeIn) {
            mHandler.postDelayed(this::hideThumbNailMainThread, LINGER_DURATION_MS);
            mHandler.postDelayed(this::hideThumbnailMainThread, LINGER_DURATION_MS);
        }

        if (fadeIn == mIsFadingIn) {
@@ -179,18 +179,18 @@ public class MagnificationThumbnail {
            mVisible = true;
        }

        if (mThumbNailAnimator != null) {
            mThumbNailAnimator.cancel();
        if (mThumbnailAnimator != null) {
            mThumbnailAnimator.cancel();
        }
        mThumbNailAnimator = ObjectAnimator.ofFloat(
        mThumbnailAnimator = ObjectAnimator.ofFloat(
                mThumbnailLayout,
                "alpha",
                fadeIn ? 1f : 0f
        );
        mThumbNailAnimator.setDuration(
        mThumbnailAnimator.setDuration(
                fadeIn ? FADE_IN_ANIMATION_DURATION_MS : FADE_OUT_ANIMATION_DURATION_MS
        );
        mThumbNailAnimator.addListener(new Animator.AnimatorListener() {
        mThumbnailAnimator.addListener(new Animator.AnimatorListener() {
            private boolean mIsCancelled;

            @Override
@@ -235,7 +235,7 @@ public class MagnificationThumbnail {
            }
        });

        mThumbNailAnimator.start();
        mThumbnailAnimator.start();
    }

    /**
@@ -250,32 +250,32 @@ public class MagnificationThumbnail {
     *                of the viewport, or {@link Float#NaN} to leave unchanged
     */
    @AnyThread
    public void updateThumbNail(float scale, float centerX, float centerY) {
        mHandler.post(() -> updateThumbNailMainThread(scale, centerX, centerY));
    public void updateThumbnail(float scale, float centerX, float centerY) {
        mHandler.post(() -> updateThumbnailMainThread(scale, centerX, centerY));
    }

    @MainThread
    private void updateThumbNailMainThread(float scale, float centerX, float centerY) {
    private void updateThumbnailMainThread(float scale, float centerX, float centerY) {
        // Restart the fadeout countdown (or show if it's hidden)
        showThumbNail();
        showThumbnail();

        var scaleDown = Float.isNaN(scale) ? mThumbNailView.getScaleX() : 1f / scale;
        var scaleDown = Float.isNaN(scale) ? mThumbnailView.getScaleX() : 1f / scale;
        if (!Float.isNaN(scale)) {
            mThumbNailView.setScaleX(scaleDown);
            mThumbNailView.setScaleY(scaleDown);
            mThumbnailView.setScaleX(scaleDown);
            mThumbnailView.setScaleY(scaleDown);
        }
        float thumbnailWidth;
        float thumbnailHeight;
        if (mThumbNailView.getWidth() == 0 || mThumbNailView.getHeight() == 0) {
        if (mThumbnailView.getWidth() == 0 || mThumbnailView.getHeight() == 0) {
            // if the thumbnail view size is not updated correctly, we just use the cached values.
            thumbnailWidth = mThumbnailWidth;
            thumbnailHeight = mThumbnailHeight;
        } else {
            thumbnailWidth = mThumbNailView.getWidth();
            thumbnailHeight = mThumbNailView.getHeight();
            thumbnailWidth = mThumbnailView.getWidth();
            thumbnailHeight = mThumbnailView.getHeight();
        }
        if (!Float.isNaN(centerX)) {
            var padding = mThumbNailView.getPaddingTop();
            var padding = mThumbnailView.getPaddingTop();
            var ratio = 1f / BG_ASPECT_RATIO;
            var centerXScaled = centerX * ratio - (thumbnailWidth / 2f + padding);
            var centerYScaled = centerY * ratio - (thumbnailHeight / 2f + padding);
@@ -283,15 +283,15 @@ public class MagnificationThumbnail {
            if (DEBUG) {
                Log.d(
                        LOG_TAG,
                        "updateThumbNail centerXScaled : " + centerXScaled
                        "updateThumbnail centerXScaled : " + centerXScaled
                                + " centerYScaled : " + centerYScaled
                                + " getTranslationX : " + mThumbNailView.getTranslationX()
                                + " getTranslationX : " + mThumbnailView.getTranslationX()
                                + " ratio : " + ratio
                );
            }

            mThumbNailView.setTranslationX(centerXScaled);
            mThumbNailView.setTranslationY(centerYScaled);
            mThumbnailView.setTranslationX(centerXScaled);
            mThumbnailView.setTranslationY(centerYScaled);
        }
    }

+3 −3
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ public class FullScreenMagnificationControllerTest {
        assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_0));
        assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_1));

        verify(mMockThumbnail, times(2)).hideThumbNail();
        verify(mMockThumbnail, times(2)).hideThumbnail();
    }

    @Test
@@ -540,7 +540,7 @@ public class FullScreenMagnificationControllerTest {

        // The first time is triggered when the thumbnail is just created.
        // The second time is triggered when the magnification region changed.
        verify(mMockThumbnail, times(2)).setThumbNailBounds(
        verify(mMockThumbnail, times(2)).setThumbnailBounds(
                any(), anyFloat(), anyFloat(), anyFloat());
    }

@@ -912,7 +912,7 @@ public class FullScreenMagnificationControllerTest {
        verifyNoMoreInteractions(mMockWindowManager);

        verify(mMockThumbnail)
                .updateThumbNail(eq(scale), eq(startCenter.x), eq(startCenter.y));
                .updateThumbnail(eq(scale), eq(startCenter.x), eq(startCenter.y));
    }

    @Test
+12 −12
Original line number Diff line number Diff line
@@ -66,14 +66,14 @@ public class MagnificationThumbnailTest {

    @Test
    public void updateThumbnailShows() {
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbNail(
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
        ));
        idle();

        runOnMainSync(() -> mMagnificationThumbnail.updateThumbNail(
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2.2f,
                /* centerX= */ 15,
                /* centerY= */ 50
@@ -86,7 +86,7 @@ public class MagnificationThumbnailTest {

    @Test
    public void updateThumbnailLingersThenHidesAfterTimeout() throws InterruptedException {
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbNail(
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
@@ -103,14 +103,14 @@ public class MagnificationThumbnailTest {

    @Test
    public void hideThumbnailRemoves() throws InterruptedException {
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbNail(
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
        ));
        idle();

        runOnMainSync(() -> mMagnificationThumbnail.hideThumbNail());
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbnail());
        idle();

        // Wait for the fade out animation
@@ -122,10 +122,10 @@ public class MagnificationThumbnailTest {

    @Test
    public void hideShowHideShowHideRemoves() throws InterruptedException {
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbNail());
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbnail());
        idle();

        runOnMainSync(() -> mMagnificationThumbnail.updateThumbNail(
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
@@ -135,17 +135,17 @@ public class MagnificationThumbnailTest {
        // Wait for the fade in animation
        Thread.sleep(200L);

        runOnMainSync(() -> mMagnificationThumbnail.hideThumbNail());
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbnail());
        idle();

        runOnMainSync(() -> mMagnificationThumbnail.updateThumbNail(
        runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
                /* scale=   */ 2f,
                /* centerX= */ 5,
                /* centerY= */ 10
        ));
        idle();

        runOnMainSync(() -> mMagnificationThumbnail.hideThumbNail());
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbnail());
        idle();


@@ -158,7 +158,7 @@ public class MagnificationThumbnailTest {

    @Test
    public void hideWithoutShowDoesNothing() throws InterruptedException {
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbNail());
        runOnMainSync(() -> mMagnificationThumbnail.hideThumbnail());
        idle();

        // Wait for the fade out animation
@@ -172,7 +172,7 @@ public class MagnificationThumbnailTest {

    @Test
    public void whenHidden_setBoundsDoesNotShow() throws InterruptedException {
        runOnMainSync(() -> mMagnificationThumbnail.setThumbNailBounds(
        runOnMainSync(() -> mMagnificationThumbnail.setThumbnailBounds(
                new Rect(),
                /* scale=   */ 2f,
                /* centerX= */ 5,