Add accessibility shortcuts fragment in a11y settings

Accessibility settings category restructure, add accessibility shortcuts
fragment for related accessibility services.

Bug: 174829936
Test: atest AccessibilityShortcutsFragmentTest, atest AccessibilitySettingsTest
Change-Id: I9706906863872bc60d31eae54bbf3a35d70e812e
This commit is contained in:
Ben Chung
2021-01-21 17:24:41 +08:00
parent f969007c44
commit e66e641980
6 changed files with 163 additions and 9 deletions

View File

@@ -5254,6 +5254,8 @@
<string name="accessibility_summary_state_stopped">Not working. Tap for info.</string>
<!-- Accessibility service's description when enabled but not running (like maybe it crashed). -->
<string name="accessibility_description_state_stopped">This service is malfunctioning.</string>
<!-- Title for the accessibility shortcuts settings page. [CHAR LIMIT=50] -->
<string name="accessibility_shortcuts_settings_title">Accessibility shortcuts</string>
<!-- Title for the preference to show a tile for a particular feature in the Quick Settings pane. [CHAR LIMIT=NONE] -->
<string name="enable_quick_setting">Show in Quick Settings</string>

View File

@@ -29,15 +29,7 @@
<PreferenceCategory
android:key="screen_reader_category"
android:persistent="false"
android:title="@string/screen_reader_category_title">
<Preference
android:fragment="com.android.settings.tts.TextToSpeechSettings"
android:key="tts_settings_preference"
android:persistent="false"
android:title="@string/tts_settings_title"
settings:controller="com.android.settings.language.TtsPreferenceController"/>
</PreferenceCategory>
android:title="@string/screen_reader_category_title"/>
<PreferenceCategory
android:key="display_category"
@@ -129,6 +121,25 @@
</PreferenceCategory>
<!-- TODO(b/174829936): Add title for shortcuts settings category. -->
<PreferenceCategory android:persistent="false">
<Preference
android:fragment="com.android.settings.accessibility.ShortcutsSettingsFragment"
android:key="accessibility_shortcuts_preference_screen"
android:persistent="false"
android:title="@string/accessibility_shortcuts_settings_title"
settings:searchable="true"/>
<Preference
android:fragment="com.android.settings.tts.TextToSpeechSettings"
android:key="tts_settings_preference"
android:persistent="false"
android:title="@string/tts_settings_title"
settings:controller="com.android.settings.language.TtsPreferenceController"/>
</PreferenceCategory>
<PreferenceCategory
android:key="experimental_category"
android:persistent="false"

View File

@@ -0,0 +1,30 @@
<?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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="accessibility_shortcuts_settings"
android:persistent="false"
android:title="@string/accessibility_shortcuts_settings_title">
<SwitchPreference
android:key="accessibility_shortcut_preference"
android:persistent="false"
android:title="@string/accessibility_shortcut_service_on_lock_screen_title"
android:summary="@string/accessibility_shortcut_description"
settings:controller="com.android.settings.accessibility.AccessibilityShortcutPreferenceController"/>
</PreferenceScreen>

View File

@@ -372,6 +372,9 @@ public class AccessibilitySettings extends DashboardFragment {
} else {
getPreferenceScreen().addPreference(downloadedServicesCategory);
}
// Hide screen reader category if it is empty.
updatePreferenceCategoryVisibility(CATEGORY_SCREEN_READER);
}
private List<RestrictedPreference> getInstalledAccessibilityList(Context context) {
@@ -452,6 +455,16 @@ public class AccessibilitySettings extends DashboardFragment {
}
}
/**
* Updates the visibility of a category according to its child preference count.
*
* @param categoryKey The key of the category which needs to check
*/
private void updatePreferenceCategoryVisibility(String categoryKey) {
final PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);
category.setVisible(category.getPreferenceCount() != 0);
}
/**
* Updates preferences related to system configurations.
*/

View File

@@ -0,0 +1,48 @@
/*
* 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.
*/
package com.android.settings.accessibility;
import android.app.settings.SettingsEnums;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
/** Accessibility settings for accessibility shortcuts. */
public class ShortcutsSettingsFragment extends DashboardFragment {
private static final String TAG = "ShortcutsSettingsFragment";
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_SHORTCUTS_SETTINGS;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_shortcuts_settings;
}
@Override
protected String getLogTag() {
return TAG;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.accessibility_shortcuts_settings);
}

View File

@@ -0,0 +1,50 @@
/*
* 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.
*/
package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.testutils.XmlTestUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import java.util.List;
/** Tests for {@link ShortcutsSettingsFragment}. */
@RunWith(RobolectricTestRunner.class)
public class ShortcutsSettingsFragmentTest {
private Context mContext = ApplicationProvider.getApplicationContext();
@Test
public void getNonIndexableKeys_existInXmlLayout() {
final List<String> niks = ShortcutsSettingsFragment.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
final List<String> keys =
XmlTestUtils.getKeysFromPreferenceXml(mContext,
R.xml.accessibility_shortcuts_settings);
assertThat(keys).containsAtLeastElementsIn(niks);
}
}