Merge "Fix sometimes couldn’t receive the configuration change callback after rotating."

This commit is contained in:
PETER LIANG
2023-01-05 08:07:28 +00:00
committed by Android (Google) Code Review
6 changed files with 74 additions and 36 deletions

View File

@@ -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);

View File

@@ -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(

View File

@@ -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);

View File

@@ -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;
@@ -73,12 +76,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();
@@ -93,6 +99,7 @@ class MenuMessageView extends LinearLayout implements
updateResources();
getContext().registerComponentCallbacks(this);
getViewTreeObserver().addOnComputeInternalInsetsListener(this);
}
@@ -100,6 +107,7 @@ class MenuMessageView extends LinearLayout implements
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
getContext().unregisterComponentCallbacks(this);
getViewTreeObserver().removeOnComputeInternalInsetsListener(this);
}

View File

@@ -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<AccessibilityTarget> 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;
}

View File

@@ -31,6 +31,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;
@@ -73,7 +74,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;
@@ -136,8 +137,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);
}
});
@@ -211,9 +212,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<AccessibilityTarget> newTargetFeatures) {
@@ -253,7 +259,7 @@ class MenuViewLayer extends FrameLayout implements
mMenuViewModel.getMigrationTooltipVisibilityData().observeForever(
mMigrationTooltipObserver);
mMessageView.setUndoListener(view -> undo());
mContext.registerComponentCallbacks(mDismissAnimationController);
getContext().registerComponentCallbacks(this);
}
@Override
@@ -268,7 +274,7 @@ class MenuViewLayer extends FrameLayout implements
mMenuViewModel.getMigrationTooltipVisibilityData().removeObserver(
mMigrationTooltipObserver);
mHandler.removeCallbacksAndMessages(/* token= */ null);
mContext.unregisterComponentCallbacks(mDismissAnimationController);
getContext().unregisterComponentCallbacks(this);
}
@Override