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

Commit 0e1d8498 authored by Menghan Li's avatar Menghan Li Committed by Automerger Merge Worker
Browse files

Merge changes Ia0035222,I309ca48c into tm-dev am: 23074210

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17119800

Change-Id: Iac0e1425c02be70fea1a31a8c735743d1ba84dad
parents 3ae92de3 23074210
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -5554,11 +5554,27 @@
    <string name="accessibility_service_primary_switch_title">Use <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
    <!-- Used in the accessibility service settings to open the activity. [CHAR LIMIT=NONE] -->
    <string name="accessibility_service_primary_open_title">Open <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
    <!-- Used in the accessibility service settings to show quick settings tooltips for auto-added feature. [CHAR LIMIT=NONE] -->
    <!-- Used in the accessibility service settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
    <string name="accessibility_service_auto_added_qs_tooltips_content"><xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> added to Quick Settings. Swipe down to turn it on or off anytime.</string>
    <!-- Used in the accessibility service settings to show quick settings tooltips. [CHAR LIMIT=NONE] -->
    <!-- Used in the accessibility service settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
    <string name="accessibility_service_qs_tooltips_content">You can also add <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> to Quick Settings from the top of your screen</string>
    <!-- Used in the accessibility action for accessibility quick settings tooltips to dismiss. [CHAR LIMIT=NONE] -->
    <!-- Used in the color correction settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
    <string name="accessibility_color_correction_auto_added_qs_tooltip_content">Color correction added to Quick Settings. Swipe down to turn it on or off anytime.</string>
    <!-- Used in the color correction settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
    <string name="accessibility_color_correction_qs_tooltip_content">You can also add color correction to Quick Settings from the top of your screen</string>
    <!-- Used in the color inversion settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
    <string name="accessibility_color_inversion_auto_added_qs_tooltip_content">Color inversion added to Quick Settings. Swipe down to turn it on or off anytime.</string>
    <!-- Used in the color inversion settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
    <string name="accessibility_color_inversion_qs_tooltip_content">You can also add color inversion to Quick Settings from the top of your screen</string>
    <!-- Used in the reduce bright colors settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
    <string name="accessibility_reduce_bright_colors_auto_added_qs_tooltip_content">Extra dim added to Quick Settings. Swipe down to turn it on or off anytime.</string>
    <!-- Used in the reduce bright colors settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
    <string name="accessibility_reduce_bright_colors_qs_tooltip_content">You can also add extra dim to Quick Settings from the top of your screen</string>
    <!-- Used in the One-hand mode color to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
    <string name="accessibility_one_handed_mode_auto_added_qs_tooltip_content">One-handed mode added to Quick Settings. Swipe down to turn it on or off anytime.</string>
    <!-- Used in the One-hand mode settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
    <string name="accessibility_one_handed_mode_qs_tooltip_content">You can also add one-handed mode to Quick Settings from the top of your screen</string>
    <!-- Used in the accessibility action for accessibility quick settings tooltip to dismiss. [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_tooltips_dismiss">Dismiss</string>
    <!-- Intro for color correction settings screen to control turning on/off the feature entirely. [CHAR LIMIT=NONE] -->
    <string name="accessibility_daltonizer_about_intro_text" product="default">Adjust how colors display on your phone</string>
+124 −0
Original line number Diff line number Diff line
/*
 * 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.settings.accessibility;

import android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;

import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;

/** PrimarySwitchPreferenceController that shows quick settings tooltip on first use. */
public abstract class AccessibilityQuickSettingsPrimarySwitchPreferenceController
        extends TogglePreferenceController
        implements LifecycleObserver, OnCreate, OnSaveInstanceState {
    private static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
    private final Handler mHandler;
    private PrimarySwitchPreference mPreference;
    private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
    private boolean mNeedsQSTooltipReshow = false;

    /** Returns the accessibility tile component name. */
    abstract ComponentName getTileComponentName();

    /** Returns the accessibility tile tooltip content. */
    abstract CharSequence getTileTooltipContent();

    public AccessibilityQuickSettingsPrimarySwitchPreferenceController(Context context,
            String preferenceKey) {
        super(context, preferenceKey);
        mHandler = new Handler(context.getMainLooper());
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // Restore the tooltip.
        if (savedInstanceState != null) {
            if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
                mNeedsQSTooltipReshow = savedInstanceState.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW);
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        if (mTooltipWindow != null) {
            outState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, mTooltipWindow.isShowing());
        }
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
        if (mNeedsQSTooltipReshow) {
            mHandler.post(this::showQuickSettingsTooltipIfNeeded);
        }
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        if (isChecked) {
            showQuickSettingsTooltipIfNeeded();
        }
        return isChecked;
    }

    @Override
    public boolean isChecked() {
        return false;
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return R.string.menu_key_accessibility;
    }

    private void showQuickSettingsTooltipIfNeeded() {
        final ComponentName tileComponentName = getTileComponentName();
        if (tileComponentName == null) {
            // Returns if no tile service assigned.
            return;
        }

        if (!mNeedsQSTooltipReshow && AccessibilityQuickSettingUtils.hasValueInSharedPreferences(
                mContext, tileComponentName)) {
            // Returns if quick settings tooltip only show once.
            return;
        }

        mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(mContext);
        mTooltipWindow.setup(getTileTooltipContent(),
                R.drawable.accessibility_auto_added_qs_tooltips_illustration);
        mTooltipWindow.showAtTopCenter(mPreference.getSwitch());
        AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext, tileComponentName);
        mNeedsQSTooltipReshow = false;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
     * @param text text to be displayed
     * @param imageResId the resource ID of the image drawable
     */
    public void setup(String text, @DrawableRes int imageResId) {
    public void setup(CharSequence text, @DrawableRes int imageResId) {
        this.setup(text, imageResId, /* closeDelayTimeMillis= */ 0);
    }

@@ -94,7 +94,7 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
     * @param imageResId the resource ID of the image drawable
     * @param closeDelayTimeMillis how long the popup window be auto-closed
     */
    public void setup(String text, @DrawableRes int imageResId, long closeDelayTimeMillis) {
    public void setup(CharSequence text, @DrawableRes int imageResId, long closeDelayTimeMillis) {
        this.mCloseDelayTimeMillis = closeDelayTimeMillis;

        setBackgroundDrawable(new ColorDrawable(mContext.getColor(android.R.color.transparent)));
+7 −11
Original line number Diff line number Diff line
@@ -83,8 +83,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
    /** Returns the accessibility tile component name. */
    protected abstract ComponentName getTileComponentName();

    /** Returns the accessibility tile feature name. */
    protected abstract CharSequence getTileName();
    /** Returns the accessibility tile tooltip content. */
    protected abstract CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type);

    @Override
    public void onCreate(Bundle savedInstanceState) {
@@ -148,7 +148,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // Reshow tooltips when activity recreate, such as rotate device.
        // Reshow tooltip when activity recreate, such as rotate device.
        if (mNeedsQSTooltipReshow) {
            getView().post(this::showQuickSettingsTooltipIfNeeded);
        }
@@ -499,21 +499,17 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
            return;
        }

        final CharSequence tileName = getTileName();
        if (TextUtils.isEmpty(tileName)) {
            // Returns if no title of tile service assigned.
        final CharSequence content = getTileTooltipContent(mNeedsQSTooltipType);
        if (TextUtils.isEmpty(content)) {
            // Returns if no content of tile tooltip assigned.
            return;
        }

        final int titleResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
                ? R.string.accessibility_service_qs_tooltips_content
                : R.string.accessibility_service_auto_added_qs_tooltips_content;
        final String title = getString(titleResId, tileName);
        final int imageResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
                ? R.drawable.accessibility_qs_tooltips_illustration
                : R.drawable.accessibility_auto_added_qs_tooltips_illustration;
        mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
        mTooltipWindow.setup(title, imageResId);
        mTooltipWindow.setup(content, imageResId);
        mTooltipWindow.showAtTopCenter(getView());
        AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
                tileComponentName);
+12 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import androidx.annotation.Nullable;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.overlay.FeatureFactory;

import java.util.ArrayList;
@@ -128,12 +129,21 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
    }

    @Override
    CharSequence getTileName() {
    CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
        final ComponentName componentName = getTileComponentName();
        if (componentName == null) {
            return null;
        }
        return loadTileLabel(getPrefContext(), componentName);

        final CharSequence tileName = loadTileLabel(getPrefContext(), componentName);
        if (tileName == null) {
            return null;
        }

        final int titleResId = type == QuickSettingsTooltipType.GUIDE_TO_EDIT
                ? R.string.accessibility_service_qs_tooltips_content
                : R.string.accessibility_service_auto_added_qs_tooltips_content;
        return getString(titleResId, tileName);
    }

    @Override
Loading