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

Commit 9d8030af authored by Jason Chang's avatar Jason Chang Committed by Automerger Merge Worker
Browse files

Merge "Integrate DisplayLayout for Tutorial window of One handed mode" into sc-dev am: 40c86a7b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14233151

Change-Id: Ia762ad444fd8d66ad6e559a4f24fbddfffc4adad
parents 2e08ce87 40c86a7b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
        OneHandedTimeoutHandler timeoutHandler = new OneHandedTimeoutHandler(mainExecutor);
        OneHandedState transitionState = new OneHandedState();
        OneHandedTutorialHandler tutorialHandler = new OneHandedTutorialHandler(context,
                windowManager, mainExecutor);
                displayLayout, windowManager, mainExecutor);
        OneHandedAnimationController animationController =
                new OneHandedAnimationController(context);
        OneHandedTouchHandler touchHandler = new OneHandedTouchHandler(timeoutHandler,
@@ -453,6 +453,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
        final DisplayLayout newDisplayLayout = mDisplayController.getDisplayLayout(displayId);
        mDisplayAreaOrganizer.setDisplayLayout(newDisplayLayout);
        mGestureHandler.onDisplayChanged(newDisplayLayout);
        mTutorialHandler.onDisplayChanged(newDisplayLayout);
    }

    private ContentObserver getObserver(Runnable onChangeRunnable) {
+28 −13
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull;

import com.android.wm.shell.R;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.ShellExecutor;

import java.io.PrintWriter;
@@ -50,9 +51,10 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
    private static final int MAX_TUTORIAL_SHOW_COUNT = 2;
    private final WindowManager mWindowManager;
    private final String mPackageName;
    private final Rect mDisplaySize;
    private final float mTutorialHeightRatio;

    private Context mContext;
    private Rect mDisplayBounds;
    private View mTutorialView;
    private ContentResolver mContentResolver;
    private boolean mCanShowTutorial;
@@ -94,23 +96,22 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        }
    };

    public OneHandedTutorialHandler(Context context, WindowManager windowManager,
            ShellExecutor mainExecutor) {
    public OneHandedTutorialHandler(Context context, DisplayLayout displayLayout,
            WindowManager windowManager, ShellExecutor mainExecutor) {
        mContext = context;
        mWindowManager = windowManager;
        mDisplaySize = windowManager.getCurrentWindowMetrics().getBounds();
        mPackageName = context.getPackageName();
        mContentResolver = context.getContentResolver();
        mCanShowTutorial = (Settings.Secure.getInt(mContentResolver,
                Settings.Secure.ONE_HANDED_TUTORIAL_SHOW_COUNT, 0) >= MAX_TUTORIAL_SHOW_COUNT)
                ? false : true;
        mIsOneHandedMode = false;
        final float offsetPercentageConfig = context.getResources().getFraction(
                R.fraction.config_one_handed_offset, 1, 1);
        final int sysPropPercentageConfig = SystemProperties.getInt(
                ONE_HANDED_MODE_OFFSET_PERCENTAGE, Math.round(offsetPercentageConfig * 100.0f));
        mTutorialAreaHeight = Math.round(
                mDisplaySize.height() * (sysPropPercentageConfig / 100.0f));
        mTutorialHeightRatio = sysPropPercentageConfig / 100.0f;
        onDisplayChanged(displayLayout);
        mCanShowTutorial = (Settings.Secure.getInt(mContentResolver,
                Settings.Secure.ONE_HANDED_TUTORIAL_SHOW_COUNT, 0) >= MAX_TUTORIAL_SHOW_COUNT)
                ? false : true;
        mIsOneHandedMode = false;

        mainExecutor.execute(() -> {
            recreateTutorialView(mContext);
@@ -131,6 +132,20 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        mTriggerState = ONE_HANDED_TRIGGER_STATE.UNSET;
    }

    /**
     * Called when onDisplayAdded() or onDisplayRemoved() callback
     * @param displayLayout The latest {@link DisplayLayout} representing current displayId
     */
    public void onDisplayChanged(DisplayLayout displayLayout) {
        // Ensure the mDisplayBounds is portrait, due to OHM only support on portrait
        if (displayLayout.height() > displayLayout.width()) {
            mDisplayBounds = new Rect(0, 0, displayLayout.width(), displayLayout.height());
        } else {
            mDisplayBounds = new Rect(0, 0, displayLayout.height(), displayLayout.width());
        }
        mTutorialAreaHeight = Math.round(mDisplayBounds.height() * mTutorialHeightRatio);
    }

    private void recreateTutorialView(Context context) {
        mTutorialView = LayoutInflater.from(context).inflate(R.layout.one_handed_tutorial,
                null);
@@ -190,7 +205,7 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
     */
    private WindowManager.LayoutParams getTutorialTargetLayoutParams() {
        final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                mDisplaySize.width(), mTutorialAreaHeight, 0, 0,
                mDisplayBounds.width(), mTutorialAreaHeight, 0, 0,
                WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
@@ -207,8 +222,8 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        pw.println(TAG + " states: ");
        pw.print(innerPrefix + "mTriggerState=");
        pw.println(mTriggerState);
        pw.print(innerPrefix + "mDisplaySize=");
        pw.println(mDisplaySize);
        pw.print(innerPrefix + "mDisplayBounds=");
        pw.println(mDisplayBounds);
        pw.print(innerPrefix + "mTutorialAreaHeight=");
        pw.println(mTutorialAreaHeight);
    }