diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java index 777d10c7acfd0..6d54d389a38da 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java @@ -182,9 +182,9 @@ public class AccessibilityFloatingMenuController implements if (mFloatingMenu == null) { if (mFeatureFlags.isEnabled(A11Y_FLOATING_MENU_FLING_SPRING_ANIMATIONS)) { final Display defaultDisplay = mDisplayManager.getDisplay(DEFAULT_DISPLAY); - mFloatingMenu = new MenuViewLayerController( - mContext.createWindowContext(defaultDisplay, - TYPE_NAVIGATION_BAR_PANEL, /* options= */ null), mWindowManager, + final Context windowContext = mContext.createWindowContext(defaultDisplay, + TYPE_NAVIGATION_BAR_PANEL, /* options= */ null); + mFloatingMenu = new MenuViewLayerController(windowContext, mWindowManager, mAccessibilityManager); } else { mFloatingMenu = new AccessibilityFloatingMenu(mContext); diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/DismissAnimationController.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/DismissAnimationController.java index ee048e1a02d3e..c2bc1408274f7 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/DismissAnimationController.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/DismissAnimationController.java @@ -19,8 +19,6 @@ package com.android.systemui.accessibility.floatingmenu; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; -import android.content.ComponentCallbacks; -import android.content.res.Configuration; import android.view.MotionEvent; import androidx.annotation.NonNull; @@ -34,7 +32,7 @@ import com.android.wm.shell.common.magnetictarget.MagnetizedObject; * Controls the interaction between {@link MagnetizedObject} and * {@link MagnetizedObject.MagneticTarget}. */ -class DismissAnimationController implements ComponentCallbacks { +class DismissAnimationController { private static final float COMPLETELY_OPAQUE = 1.0f; private static final float COMPLETELY_TRANSPARENT = 0.0f; private static final float CIRCLE_VIEW_DEFAULT_SCALE = 1.0f; @@ -105,16 +103,6 @@ class DismissAnimationController implements ComponentCallbacks { mMagnetizedObject.addTarget(magneticTarget); } - @Override - public void onConfigurationChanged(@NonNull Configuration newConfig) { - updateResources(); - } - - @Override - public void onLowMemory() { - // Do nothing - } - void showDismissView(boolean show) { if (show) { mDismissView.show(); @@ -165,7 +153,7 @@ class DismissAnimationController implements ComponentCallbacks { } } - private void updateResources() { + void updateResources() { final float maxDismissSize = mDismissView.getResources().getDimensionPixelSize( R.dimen.dismiss_circle_size); mMinDismissSize = mDismissView.getResources().getDimensionPixelSize( diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java index 440053450d2f2..5ec024ebc917d 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuEduTooltipView.java @@ -21,6 +21,7 @@ import static android.view.View.MeasureSpec.AT_MOST; import static android.view.View.MeasureSpec.UNSPECIFIED; import android.annotation.SuppressLint; +import android.content.ComponentCallbacks; import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; @@ -48,7 +49,7 @@ import com.android.systemui.recents.TriangleShape; * . It's just shown on the left or right of the anchor view. */ @SuppressLint("ViewConstructor") -class MenuEduTooltipView extends FrameLayout { +class MenuEduTooltipView extends FrameLayout implements ComponentCallbacks { private int mFontSize; private int mTextViewMargin; private int mTextViewPadding; @@ -73,9 +74,7 @@ class MenuEduTooltipView extends FrameLayout { } @Override - protected void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - + public void onConfigurationChanged(@NonNull Configuration newConfig) { updateResources(); updateMessageView(); updateArrowView(); @@ -83,6 +82,25 @@ class MenuEduTooltipView extends FrameLayout { updateLocationAndVisibility(); } + @Override + public void onLowMemory() { + // Do nothing. + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + + getContext().registerComponentCallbacks(this); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + + getContext().unregisterComponentCallbacks(this); + } + void show(CharSequence message) { mMessageView.setText(message); diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuMessageView.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuMessageView.java index 9875ad06f1ed5..be29f72edb045 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuMessageView.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuMessageView.java @@ -20,6 +20,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_PX; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import android.annotation.IntDef; +import android.content.ComponentCallbacks; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Configuration; @@ -33,6 +34,8 @@ import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.NonNull; + import com.android.settingslib.Utils; import com.android.systemui.R; @@ -44,7 +47,7 @@ import java.lang.annotation.RetentionPolicy; * the {@link MenuView}. */ class MenuMessageView extends LinearLayout implements - ViewTreeObserver.OnComputeInternalInsetsListener { + ViewTreeObserver.OnComputeInternalInsetsListener, ComponentCallbacks { private final TextView mTextView; private final Button mUndoButton; @@ -72,12 +75,15 @@ class MenuMessageView extends LinearLayout implements } @Override - protected void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - + public void onConfigurationChanged(@NonNull Configuration newConfig) { updateResources(); } + @Override + public void onLowMemory() { + // Do nothing. + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -92,6 +98,7 @@ class MenuMessageView extends LinearLayout implements updateResources(); + getContext().registerComponentCallbacks(this); getViewTreeObserver().addOnComputeInternalInsetsListener(this); } @@ -99,6 +106,7 @@ class MenuMessageView extends LinearLayout implements protected void onDetachedFromWindow() { super.onDetachedFromWindow(); + getContext().unregisterComponentCallbacks(this); getViewTreeObserver().removeOnComputeInternalInsetsListener(this); } diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java index 986aa51ecce1a..f35ee37200336 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuView.java @@ -19,6 +19,7 @@ package com.android.systemui.accessibility.floatingmenu; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import android.annotation.SuppressLint; +import android.content.ComponentCallbacks; import android.content.Context; import android.content.res.Configuration; import android.graphics.PointF; @@ -46,7 +47,7 @@ import java.util.List; */ @SuppressLint("ViewConstructor") class MenuView extends FrameLayout implements - ViewTreeObserver.OnComputeInternalInsetsListener { + ViewTreeObserver.OnComputeInternalInsetsListener, ComponentCallbacks { private static final int INDEX_MENU_ITEM = 0; private final List mTargetFeatures = new ArrayList<>(); private final AccessibilityTargetAdapter mAdapter; @@ -106,14 +107,31 @@ class MenuView extends FrameLayout implements } @Override - protected void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - + public void onConfigurationChanged(@NonNull Configuration newConfig) { loadLayoutResources(); mTargetFeaturesView.setOverScrollMode(mMenuViewAppearance.getMenuScrollMode()); } + @Override + public void onLowMemory() { + // Do nothing. + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + + getContext().registerComponentCallbacks(this); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + + getContext().unregisterComponentCallbacks(this); + } + void setOnTargetFeaturesChangeListener(OnTargetFeaturesChangeListener listener) { mFeaturesChangeListener = listener; } diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java index 6f5b39cc7d56c..039133a12ed1f 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/MenuViewLayer.java @@ -30,6 +30,7 @@ import android.accessibilityservice.AccessibilityServiceInfo; import android.annotation.IntDef; import android.annotation.StringDef; import android.annotation.SuppressLint; +import android.content.ComponentCallbacks; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; @@ -74,7 +75,7 @@ import java.util.Optional; */ @SuppressLint("ViewConstructor") class MenuViewLayer extends FrameLayout implements - ViewTreeObserver.OnComputeInternalInsetsListener, View.OnClickListener { + ViewTreeObserver.OnComputeInternalInsetsListener, View.OnClickListener, ComponentCallbacks { private static final int SHOW_MESSAGE_DELAY_MS = 3000; private final WindowManager mWindowManager; @@ -137,8 +138,8 @@ class MenuViewLayer extends FrameLayout implements AccessibilityServiceInfo.FEEDBACK_ALL_MASK); serviceInfoList.forEach(info -> { if (getAccessibilityServiceFragmentType(info) == INVISIBLE_TOGGLE) { - setAccessibilityServiceState(mContext, info.getComponentName(), /* enabled= */ - false); + setAccessibilityServiceState(getContext(), + info.getComponentName(), /* enabled= */ false); } }); @@ -209,9 +210,14 @@ class MenuViewLayer extends FrameLayout implements } @Override - protected void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); + public void onConfigurationChanged(@NonNull Configuration newConfig) { mDismissView.updateResources(); + mDismissAnimationController.updateResources(); + } + + @Override + public void onLowMemory() { + // Do nothing. } private String getMessageText(List newTargetFeatures) { @@ -246,7 +252,7 @@ class MenuViewLayer extends FrameLayout implements mMenuViewModel.getMigrationTooltipVisibilityData().observeForever( mMigrationTooltipObserver); mMessageView.setUndoListener(view -> undo()); - mContext.registerComponentCallbacks(mDismissAnimationController); + getContext().registerComponentCallbacks(this); } @Override @@ -261,7 +267,7 @@ class MenuViewLayer extends FrameLayout implements mMenuViewModel.getMigrationTooltipVisibilityData().removeObserver( mMigrationTooltipObserver); mHandler.removeCallbacksAndMessages(/* token= */ null); - mContext.unregisterComponentCallbacks(mDismissAnimationController); + getContext().unregisterComponentCallbacks(this); } @Override