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

Commit 610c0142 authored by Peter_Liang's avatar Peter_Liang
Browse files

Add the new migration tooltip for accessibility floating menu.(1/n)

Goal:
If users have been using the accessibility button in android R, after the device is upgraded from android R to S, the system will pop up the tooltip at the first boot to show the information about the Accessibility button was replaced with the floating menu.

Patch Action:
1. Create the tooltip view
2. Create new secure settings  key for migration tooltip

Bug: 175365399
Test: atest AccessibilityFloatingMenuViewTest AccessibilityFloatingMenuTest AccessibilityFloatingMenuTooltipViewTest
Change-Id: I50b792efcbb631778a668e967fd727806a3f3df4
parent 0c6aa86e
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -4919,6 +4919,15 @@ public class SettingsProvider extends ContentProvider {
                                    String.valueOf(defAccessibilityButtonMode), /* tag= */
                                    null, /* makeDefault= */ true,
                                    SettingsState.SYSTEM_PACKAGE_NAME);

                            if (hasValueInA11yButtonTargets(secureSettings)) {
                                secureSettings.insertSettingLocked(
                                        Secure.ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT,
                                        /* enabled */ "1",
                                        /* tag= */ null,
                                        /* makeDefault= */ false,
                                        SettingsState.SYSTEM_PACKAGE_NAME);
                            }
                        }
                    }

@@ -5145,13 +5154,21 @@ public class SettingsProvider extends ContentProvider {
        }

        private boolean isAccessibilityButtonInNavigationBarOn(SettingsState secureSettings) {
            final boolean hasValueInA11yBtnTargets = !TextUtils.isEmpty(
                    secureSettings.getSettingLocked(
                            Secure.ACCESSIBILITY_BUTTON_TARGETS).getValue());
            return hasValueInA11yButtonTargets(secureSettings) && !isGestureNavigateEnabled();
        }

        private boolean isGestureNavigateEnabled() {
            final int navigationMode = getContext().getResources().getInteger(
                    com.android.internal.R.integer.config_navBarInteractionMode);
            return navigationMode == NAV_BAR_MODE_GESTURAL;
        }

        private boolean hasValueInA11yButtonTargets(SettingsState secureSettings) {
            final Setting a11yButtonTargetsSettings =
                    secureSettings.getSettingLocked(Secure.ACCESSIBILITY_BUTTON_TARGETS);

            return hasValueInA11yBtnTargets && (navigationMode != NAV_BAR_MODE_GESTURAL);
            return !a11yButtonTargetsSettings.isNull()
                    && !TextUtils.isEmpty(a11yButtonTargetsSettings.getValue());
        }
    }
}
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2021 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.
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
       android:shape="rectangle">
    <solid android:color="?androidprv:attr/colorAccentPrimary" />
    <corners android:radius="@dimen/accessibility_floating_tooltip_text_corner_radius" />
</shape>
+43 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2021 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.
-->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tooltip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:padding="@dimen/accessibility_floating_tooltip_padding"
        android:background="@drawable/accessibility_floating_tooltip_background"
        android:textColor="@android:color/black"
        android:textColorLink="@android:color/black"
        android:text="@string/accessibility_floating_button_migration_tooltip"
        android:textSize="@dimen/accessibility_floating_tooltip_font_size"/>

    <View
        android:id="@+id/arrow"
        android:layout_width="@dimen/accessibility_floating_tooltip_arrow_width"
        android:layout_height="@dimen/accessibility_floating_tooltip_arrow_height"
        android:layout_marginLeft="@dimen/accessibility_floating_tooltip_arrow_margin"
        android:layout_gravity="center_vertical"/>
</LinearLayout>
+9 −0
Original line number Diff line number Diff line
@@ -1442,6 +1442,15 @@
    <dimen name="accessibility_floating_menu_large_single_radius">33dp</dimen>
    <dimen name="accessibility_floating_menu_large_multiple_radius">35dp</dimen>

    <dimen name="accessibility_floating_tooltip_arrow_width">8dp</dimen>
    <dimen name="accessibility_floating_tooltip_arrow_height">16dp</dimen>
    <dimen name="accessibility_floating_tooltip_arrow_margin">-2dp</dimen>
    <dimen name="accessibility_floating_tooltip_arrow_corner_radius">2dp</dimen>
    <dimen name="accessibility_floating_tooltip_text_corner_radius">8dp</dimen>
    <dimen name="accessibility_floating_tooltip_margin">16dp</dimen>
    <dimen name="accessibility_floating_tooltip_padding">16dp</dimen>
    <dimen name="accessibility_floating_tooltip_font_size">14sp</dimen>

    <dimen name="rounded_slider_height">48dp</dimen>
    <!-- rounded_slider_height / 2 -->
    <dimen name="rounded_slider_corner_radius">24dp</dimen>
+26 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.accessibility.floatingmenu;

import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_FADE_ENABLED;
import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_ICON_TYPE;
import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT;
import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY;
import static android.provider.Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
@@ -39,10 +40,12 @@ import com.android.internal.annotations.VisibleForTesting;
 * Contains logic for an accessibility floating menu view.
 */
public class AccessibilityFloatingMenu implements IAccessibilityFloatingMenu {
    private static final int DEFAULT_FADE_EFFECT_ENABLED = 1;
    private static final int DEFAULT_FADE_EFFECT_IS_ENABLED = 1;
    private static final int DEFAULT_MIGRATION_TOOLTIP_PROMPT_IS_DISABLED = 0;
    private static final float DEFAULT_OPACITY_VALUE = 0.55f;
    private final Context mContext;
    private final AccessibilityFloatingMenuView mMenuView;
    private final MigrationTooltipView mMigrationTooltipView;
    private final Handler mHandler = new Handler(Looper.getMainLooper());

    private final ContentObserver mContentObserver =
@@ -86,6 +89,7 @@ public class AccessibilityFloatingMenu implements IAccessibilityFloatingMenu {
    AccessibilityFloatingMenu(Context context, AccessibilityFloatingMenuView menuView) {
        mContext = context;
        mMenuView = menuView;
        mMigrationTooltipView = new MigrationTooltipView(mContext, mMenuView);
    }

    @Override
@@ -106,6 +110,8 @@ public class AccessibilityFloatingMenu implements IAccessibilityFloatingMenu {
        mMenuView.setSizeType(getSizeType(mContext));
        mMenuView.setShapeType(getShapeType(mContext));

        showMigrationTooltipIfNecessary();

        registerContentObservers();
    }

@@ -116,14 +122,32 @@ public class AccessibilityFloatingMenu implements IAccessibilityFloatingMenu {
        }

        mMenuView.hide();
        mMigrationTooltipView.hide();

        unregisterContentObservers();
    }

    // Migration tooltip was the android S feature. It's just used on the Android version from R
    // to S. In addition, it only shows once.
    private void showMigrationTooltipIfNecessary() {
        if (isMigrationTooltipPromptEnabled(mContext)) {
            mMigrationTooltipView.show();

            Settings.Secure.putInt(mContext.getContentResolver(),
                    ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT, /* disabled */ 0);
        }
    }

    private static boolean isMigrationTooltipPromptEnabled(Context context) {
        return Settings.Secure.getInt(
                context.getContentResolver(), ACCESSIBILITY_FLOATING_MENU_MIGRATION_TOOLTIP_PROMPT,
                DEFAULT_MIGRATION_TOOLTIP_PROMPT_IS_DISABLED) == /* enabled */ 1;
    }

    private static boolean isFadeEffectEnabled(Context context) {
        return Settings.Secure.getInt(
                context.getContentResolver(), ACCESSIBILITY_FLOATING_MENU_FADE_ENABLED,
                DEFAULT_FADE_EFFECT_ENABLED) == /* enable */ 1;
                DEFAULT_FADE_EFFECT_IS_ENABLED) == /* enabled */ 1;
    }

    private static float getOpacityValue(Context context) {
Loading