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

Commit d0a24a6a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix The education UI above one-handed mode isn't localized and Display...

Merge "Fix The education UI above one-handed mode isn't localized and Display size changes" into sc-dev am: 9801436e

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ife71d71bffbd3f9c9a3fa70ff716814dd51042e5
parents c4e9e79d 9801436e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_marginBottom="0dp"
        android:layout_marginStart="86dp"
        android:layout_marginEnd="86dp"
        android:layout_marginStart="46dp"
        android:layout_marginEnd="46dp"
        android:gravity="center_horizontal"
        android:fontFamily="roboto-regular"
        android:text="@string/one_handed_tutorial_description"
+6 −3
Original line number Diff line number Diff line
@@ -16,13 +16,11 @@

package com.android.wm.shell.onehanded;

import androidx.annotation.NonNull;
import android.content.res.Configuration;

import com.android.wm.shell.common.annotations.ExternalThread;
import com.android.wm.shell.onehanded.OneHandedGestureHandler.OneHandedGestureEventCallback;

import java.io.PrintWriter;

/**
 * Interface to engage one handed feature.
 */
@@ -69,4 +67,9 @@ public interface OneHanded {
     * 3 button navigation mode only
     */
    void registerGestureCallback(OneHandedGestureEventCallback callback);

    /**
     * Receive onConfigurationChanged() events
     */
    void onConfigChanged(Configuration newConfig);
}
+18 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.om.IOverlayManager;
import android.content.om.OverlayInfo;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.graphics.Point;
import android.os.Handler;
@@ -472,6 +473,16 @@ public class OneHandedController {
        }
    }

    private void onConfigChanged(Configuration newConfig) {
        if (mTutorialHandler != null) {
            if (!mIsOneHandedEnabled
                    || newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                return;
            }
            mTutorialHandler.onConfigurationChanged(newConfig);
        }
    }

    public void dump(@NonNull PrintWriter pw) {
        final String innerPrefix = "  ";
        pw.println(TAG + "states: ");
@@ -565,5 +576,12 @@ public class OneHandedController {
                OneHandedController.this.registerGestureCallback(callback);
            });
        }

        @Override
        public void onConfigChanged(Configuration newConfig) {
            mMainExecutor.execute(() -> {
                OneHandedController.this.onConfigChanged(newConfig);
            });
        }
    }
}
+31 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.onehanded;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
@@ -55,12 +56,14 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
    private final AccessibilityManager mAccessibilityManager;
    private final String mPackageName;

    private Context mContext;
    private View mTutorialView;
    private Point mDisplaySize = new Point();
    private ContentResolver mContentResolver;
    private boolean mCanShowTutorial;
    private String mStartOneHandedDescription;
    private String mStopOneHandedDescription;
    private boolean mIsOneHandedMode;

    private enum ONE_HANDED_TRIGGER_STATE {
        UNSET, ENTERING, EXITING
@@ -92,13 +95,14 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
                mTriggerState = (startValue.top == 0)
                        ? ONE_HANDED_TRIGGER_STATE.ENTERING : ONE_HANDED_TRIGGER_STATE.EXITING;
                if (mCanShowTutorial && mTriggerState == ONE_HANDED_TRIGGER_STATE.ENTERING) {
                    createTutorialTarget();
                    attachTurtorialTarget();
                }
            }
        }
    };

    public OneHandedTutorialHandler(Context context, ShellExecutor mainExecutor) {
        mContext = context;
        context.getDisplay().getRealSize(mDisplaySize);
        mPackageName = context.getPackageName();
        mContentResolver = context.getContentResolver();
@@ -113,6 +117,7 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        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(
@@ -120,11 +125,7 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        mTutorialAreaHeight = Math.round(mDisplaySize.y * (sysPropPercentageConfig / 100.0f));

        mainExecutor.execute(() -> {
            mTutorialView = LayoutInflater.from(context).inflate(R.layout.one_handed_tutorial,
                    null);
            mTargetViewContainer = new FrameLayout(context);
            mTargetViewContainer.setClipChildren(false);
            mTargetViewContainer.addView(mTutorialView);
            recreateTutorialView(mContext);
        });
    }

@@ -144,10 +145,20 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        mTriggerState = ONE_HANDED_TRIGGER_STATE.UNSET;
    }

    private void recreateTutorialView(Context context) {
        mTutorialView = LayoutInflater.from(context).inflate(R.layout.one_handed_tutorial,
                null);
        mTargetViewContainer = new FrameLayout(context);
        mTargetViewContainer.setClipChildren(false);
        mTargetViewContainer.addView(mTutorialView);
        mTargetViewContainer.setVisibility(mIsOneHandedMode ? View.VISIBLE : View.GONE);
    }

    private void updateFinished(int visible, float finalPosition) {
        if (!canShowTutorial()) {
            return;
        }
        mIsOneHandedMode = (finalPosition == 0f) ? true : false;
        mTargetViewContainer.setVisibility(visible);
        mTargetViewContainer.setTranslationY(finalPosition);
    }
@@ -176,7 +187,7 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
     * Adds the tutorial target view to the WindowManager and update its layout, so it's ready
     * to be animated in.
     */
    private void createTutorialTarget() {
    private void attachTurtorialTarget() {
        if (!mTargetViewContainer.isAttachedToWindow()) {
            try {
                mWindowManager.addView(mTargetViewContainer, getTutorialTargetLayoutParams());
@@ -242,4 +253,17 @@ public class OneHandedTutorialHandler implements OneHandedTransitionCallback {
        mTargetViewContainer.setTransitionGroup(true);
        mTargetViewContainer.setTranslationY(value - mTargetViewContainer.getHeight());
    }

    /**
     * onConfigurationChanged events for updating tutorial text.
     * @param newConfig
     */
    public void onConfigurationChanged(Configuration newConfig) {
        if (!mCanShowTutorial) {
            return;
        }
        removeTutorialFromWindowManager();
        recreateTutorialView(mContext.createConfigurationContext(newConfig));
        attachTurtorialTarget();
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -315,6 +315,13 @@ public final class WMShell extends SystemUI
                }
            }
        });

        mConfigurationController.addCallback(new ConfigurationController.ConfigurationListener() {
            @Override
            public void onConfigChanged(Configuration newConfig) {
                oneHanded.onConfigChanged(newConfig);
            }
        });
    }

    @VisibleForTesting