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

Commit 5fbfc532 authored by mincheli's avatar mincheli
Browse files

Update window magnifier UI when onConfigurationChanged. (1/n)

This change would update UI when the display size is changed.
In the later changes, we will handle the case for device orientation
changed or a physical display is updated. And we have to keep
the mafnification area unchanged when the UI is updated.

Bug: 144664540
Test: manual test
Change-Id: I7cfac77e1d74c709013c9ed07600051ee9a34097
parent 4c0487a1
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.accessibility;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;
@@ -35,10 +37,25 @@ public class WindowMagnification extends SystemUI {
    private WindowMagnificationController mWindowMagnificationController;
    private final Handler mHandler;

    private Configuration mLastConfiguration;

    @Inject
    public WindowMagnification(Context context, @Main Handler mainHandler) {
        super(context);
        mHandler = mainHandler;
        mLastConfiguration = new Configuration(context.getResources().getConfiguration());
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        final int configDiff = newConfig.diff(mLastConfiguration);
        if ((configDiff & ActivityInfo.CONFIG_DENSITY) == 0) {
            return;
        }
        mLastConfiguration.setTo(newConfig);
        if (mWindowMagnificationController != null) {
            mWindowMagnificationController.onConfigurationChanged(configDiff);
        }
    }

    @Override
+14 −2
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class WindowMagnificationController implements View.OnClickListener,
        if (mMirrorView != null) {
            return;
        }
        setInitialStartBounds();
        createOverlayWindow();
    }

@@ -178,9 +179,20 @@ public class WindowMagnificationController implements View.OnClickListener,
        }
    }

    private void createMirrorWindow() {
        setInitialStartBounds();
    /**
     * Called when the configuration has changed, and it updates window magnification UI.
     *
     * @param configDiff a bit mask of the differences between the configurations
     */
    void onConfigurationChanged(int configDiff) {
        // TODO(b/145780606): update toggle button UI.
        if (mMirrorView != null) {
            mWm.removeView(mMirrorView);
            createMirrorWindow();
        }
    }

    private void createMirrorWindow() {
        // The window should be the size the mirrored surface will be but also add room for the
        // border and the drag handle.
        int dragViewHeight = (int) mContext.getResources().getDimension(