diff --git a/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml b/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml index dc54caf0f14aa..0190aad2d0ef2 100644 --- a/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml +++ b/libs/WindowManager/Shell/res/layout/one_handed_tutorial.xml @@ -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" diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java index 11c11f44a7813..02bcf13ebb7e8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java @@ -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); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java index 5a3c38b09ec6c..05e2064d394d6 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java @@ -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); + }); + } } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java index 492130bebb30e..d577d215faa14 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedTutorialHandler.java @@ -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(); + } } diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index ec61db5913247..9a58a3e38c8e2 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -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