Refactor the design and improve the animations of Accessibility Floating Menu(2/n).

Actions of this change:
1) Support the changes of the dark theme and configurations including display size, rotation.

Bug: 227715451
Test: atest MenuViewTest
Change-Id: I986406b5144c538d87544964e1e1d835d139025b
This commit is contained in:
Peter Liang
2022-08-27 02:37:28 +08:00
parent fa717b43ad
commit 28665aa07f
5 changed files with 118 additions and 3 deletions

View File

@@ -20,4 +20,7 @@
<!-- Height of the background gradient behind the screenshot UI (taller in dark mode) -->
<dimen name="screenshot_bg_protection_height">375dp</dimen>
<!-- Accessibility floating menu -->
<dimen name="accessibility_floating_menu_stroke_width">1dp</dimen>
<dimen name="accessibility_floating_menu_stroke_inset">-2dp</dimen>
</resources>

View File

@@ -1323,8 +1323,8 @@
<!-- Accessibility floating menu -->
<dimen name="accessibility_floating_menu_elevation">3dp</dimen>
<dimen name="accessibility_floating_menu_stroke_width">1dp</dimen>
<dimen name="accessibility_floating_menu_stroke_inset">-2dp</dimen>
<dimen name="accessibility_floating_menu_stroke_width">0dp</dimen>
<dimen name="accessibility_floating_menu_stroke_inset">0dp</dimen>
<dimen name="accessibility_floating_menu_margin">16dp</dimen>
<dimen name="accessibility_floating_menu_small_padding">6dp</dimen>
<dimen name="accessibility_floating_menu_small_width_height">36dp</dimen>

View File

@@ -77,8 +77,14 @@ class MenuView extends FrameLayout {
}
private void onEdgeChanged() {
final int[] insets = mMenuViewAppearance.getMenuInsets();
getContainerViewInsetLayer().setLayerInset(INDEX_MENU_ITEM, insets[0], insets[1], insets[2],
insets[3]);
final GradientDrawable gradientDrawable = getContainerViewGradient();
gradientDrawable.setCornerRadii(mMenuViewAppearance.getMenuRadii());
gradientDrawable.setStroke(mMenuViewAppearance.getMenuStrokeWidth(),
mMenuViewAppearance.getMenuStrokeColor());
}
@SuppressLint("NotifyDataSetChanged")
@@ -104,7 +110,7 @@ class MenuView extends FrameLayout {
mMenuViewModel.unregisterContentObservers();
}
private void loadLayoutResources() {
void loadLayoutResources() {
mMenuViewAppearance.update();
setBackground(mMenuViewAppearance.getMenuBackground());

View File

@@ -20,6 +20,8 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import androidx.annotation.DimenRes;
import com.android.systemui.R;
/**
@@ -32,6 +34,9 @@ class MenuViewAppearance {
private int mSmallIconSize;
private int mSmallSingleRadius;
private int mSmallMultipleRadius;
private int mStrokeWidth;
private int mStrokeColor;
private int mInset;
private int mElevation;
private float[] mRadii;
private Drawable mBackgroundDrawable;
@@ -52,6 +57,9 @@ class MenuViewAppearance {
mSmallMultipleRadius = mRes.getDimensionPixelSize(
R.dimen.accessibility_floating_menu_small_multiple_radius);
mRadii = createRadii(getMenuRadius(mTargetFeaturesSize));
mStrokeWidth = mRes.getDimensionPixelSize(R.dimen.accessibility_floating_menu_stroke_width);
mStrokeColor = mRes.getColor(R.color.accessibility_floating_menu_stroke_dark);
mInset = mRes.getDimensionPixelSize(R.dimen.accessibility_floating_menu_stroke_inset);
mElevation = mRes.getDimensionPixelSize(R.dimen.accessibility_floating_menu_elevation);
final Drawable drawable =
mRes.getDrawable(R.drawable.accessibility_floating_menu_background);
@@ -80,11 +88,28 @@ class MenuViewAppearance {
return mSmallPadding;
}
int[] getMenuInsets() {
return new int[]{mInset, 0, 0, 0};
}
int getMenuStrokeWidth() {
return mStrokeWidth;
}
int getMenuStrokeColor() {
return mStrokeColor;
}
float[] getMenuRadii() {
return mRadii;
}
private int getMenuRadius(int itemCount) {
return getSmallSize(itemCount);
}
@DimenRes
private int getSmallSize(int itemCount) {
return itemCount > 1 ? mSmallMultipleRadius : mSmallSingleRadius;
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.accessibility.floatingmenu;
import static android.app.UiModeManager.MODE_NIGHT_YES;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.app.UiModeManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Tests for {@link MenuView}. */
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
@SmallTest
public class MenuViewTest extends SysuiTestCase {
private static final int INDEX_MENU_ITEM = 0;
private int mNightMode;
private UiModeManager mUiModeManager;
private MenuView mMenuView;
@Before
public void setUp() throws Exception {
mUiModeManager = mContext.getSystemService(UiModeManager.class);
mNightMode = mUiModeManager.getNightMode();
mUiModeManager.setNightMode(MODE_NIGHT_YES);
final MenuViewModel stubMenuViewModel = new MenuViewModel(mContext);
final MenuViewAppearance stubMenuViewAppearance = new MenuViewAppearance(mContext);
mMenuView = spy(new MenuView(mContext, stubMenuViewModel, stubMenuViewAppearance));
}
@Test
public void onConfigurationChanged_updateViewModel() {
mMenuView.onConfigurationChanged(/* newConfig= */ null);
verify(mMenuView).loadLayoutResources();
}
@Test
public void insetsOnDarkTheme_menuOnLeft_matchInsets() {
mMenuView.onConfigurationChanged(/* newConfig= */ null);
final InstantInsetLayerDrawable insetLayerDrawable =
(InstantInsetLayerDrawable) mMenuView.getBackground();
final boolean areInsetsMatched = insetLayerDrawable.getLayerInsetLeft(INDEX_MENU_ITEM) != 0
&& insetLayerDrawable.getLayerInsetRight(INDEX_MENU_ITEM) == 0;
assertThat(areInsetsMatched).isTrue();
}
@After
public void tearDown() throws Exception {
mUiModeManager.setNightMode(mNightMode);
}
}