Made following changes to Settings:

- Moved the Voice Input setting from Digital assistant app to Languages & input.
- Bundled Voice Input and Text-to-speech settings together under Speech
  category.

Bug: 218609449

Test: refactoring CL. Existing unit tests still pass.
Change-Id: I3107a410ed35685f5f1081cbe448b105b5c79c24
This commit is contained in:
Qi Cao
2022-01-27 14:51:35 -08:00
parent 0ee078d37a
commit 17ff2b25a5
8 changed files with 81 additions and 60 deletions

View File

@@ -4983,6 +4983,9 @@
<!-- Summary text for keyboards when no layout has been selected. [CHAR LIMIT=35] -->
<string name="default_keyboard_layout">Default</string>
<!-- Title for the 'Speech' preference category. [CHAR LIMIT=45] -->
<string name="speech_category_title">Speech</string>
<!-- On Languages & input settings screen, setting summary. Setting for mouse pointer speed. [CHAR LIMIT=35] -->
<string name="pointer_speed">Pointer speed</string>

View File

@@ -38,8 +38,6 @@
android:name="classname"
android:value="com.android.settings.applications.appinfo.AppLocaleDetails" />
</Preference>
</PreferenceCategory>
<PreferenceCategory
@@ -50,6 +48,7 @@
android:title="@string/virtual_keyboard_category"
android:fragment="com.android.settings.inputmethod.AvailableVirtualKeyboardFragment"
settings:keywords="@string/keywords_virtual_keyboard"/>
<Preference
android:key="physical_keyboard_pref"
android:title="@string/physical_keyboard_title"
@@ -57,6 +56,21 @@
android:fragment="com.android.settings.inputmethod.PhysicalKeyboardFragment"/>
</PreferenceCategory>
<PreferenceCategory
android:key="speech_category"
android:title="@string/speech_category_title">
<com.android.settings.widget.GearPreference
android:key="voice_input_settings"
android:title="@string/voice_input_settings_title"
android:fragment="com.android.settings.language.DefaultVoiceInputPicker" />
<Preference
android:key="tts_settings_summary"
android:title="@string/tts_settings_title"
android:fragment="com.android.settings.tts.TextToSpeechSettings"
settings:searchable="false"/>
</PreferenceCategory>
<PreferenceCategory
android:key="input_assistance_category"
android:title="@string/input_assistance">
@@ -79,20 +93,12 @@
</PreferenceCategory>
<PreferenceCategory
android:key="pointer_and_tts_category"
android:key="pointer_category"
android:layout="@layout/preference_category_no_label">
<com.android.settings.PointerSpeedPreference
android:key="pointer_speed"
android:title="@string/pointer_speed"
android:dialogTitle="@string/pointer_speed" />
<Preference
android:key="tts_settings_summary"
android:title="@string/tts_settings_title"
android:fragment="com.android.settings.tts.TextToSpeechSettings"
settings:searchable="false"/>
</PreferenceCategory>
<SwitchPreference

View File

@@ -49,11 +49,6 @@
android:title="@string/assist_flash_title"
android:summary="@string/assist_flash_summary" />
<com.android.settings.widget.GearPreference
android:key="voice_input_settings"
android:title="@string/voice_input_settings_title"
android:fragment="com.android.settings.applications.assist.DefaultVoiceInputPicker" />
<com.android.settingslib.widget.FooterPreference
android:key="manage_assist_footer"
android:title="@string/assist_footer"

View File

@@ -73,7 +73,6 @@ public class ManageAssist extends DashboardFragment {
controllers.add(new AssistContextPreferenceController(context, lifecycle));
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
controllers.add(new DefaultVoiceInputPreferenceController(context, lifecycle));
return controllers;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.applications.assist;
package com.android.settings.language;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
@@ -31,6 +31,7 @@ import com.android.settingslib.applications.DefaultAppInfo;
import java.util.ArrayList;
import java.util.List;
/** Controls the Voice Input setting. */
public class DefaultVoiceInputPicker extends DefaultAppPickerFragment {
private VoiceInputHelper mHelper;
@@ -76,7 +77,7 @@ public class DefaultVoiceInputPicker extends DefaultAppPickerFragment {
@Override
protected boolean setDefaultKey(String value) {
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
if (TextUtils.equals(value, info.key)) {
if (TextUtils.equals(value, info.mKey)) {
Settings.Secure.putString(getContext().getContentResolver(),
Settings.Secure.VOICE_RECOGNITION_SERVICE, value);
return true;
@@ -85,35 +86,38 @@ public class DefaultVoiceInputPicker extends DefaultAppPickerFragment {
return true;
}
/** Gets the current recognition service component. */
public static ComponentName getCurrentService(VoiceInputHelper helper) {
return helper.mCurrentRecognizer;
}
/** Stores the info of the Voice Input provider. */
public static class VoiceInputDefaultAppInfo extends DefaultAppInfo {
public VoiceInputHelper.BaseInfo mInfo;
public VoiceInputDefaultAppInfo(Context context, PackageManager pm, int userId,
VoiceInputHelper.BaseInfo info, boolean enabled) {
super(context, pm, userId, info.componentName, null /* summary */, enabled);
super(context, pm, userId, info.mComponentName, null /* summary */, enabled);
mInfo = info;
}
@Override
public String getKey() {
return mInfo.key;
return mInfo.mKey;
}
@Override
public CharSequence loadLabel() {
return mInfo.label;
return mInfo.mLabel;
}
/** Gets the setting intent. */
public Intent getSettingIntent() {
if (mInfo.settings == null) {
if (mInfo.mSettings == null) {
return null;
}
return new Intent(Intent.ACTION_MAIN).setComponent(mInfo.settings);
return new Intent(Intent.ACTION_MAIN).setComponent(mInfo.mSettings);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* 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.
@@ -14,13 +14,12 @@
* limitations under the License.
*/
package com.android.settings.applications.assist;
package com.android.settings.language;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.TextUtils;
import androidx.preference.Preference;
@@ -33,8 +32,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import java.util.List;
/** Controller of the Voice Input preference. */
public class DefaultVoiceInputPreferenceController extends DefaultAppPreferenceController
implements LifecycleObserver, OnResume, OnPause {
@@ -95,7 +93,7 @@ public class DefaultVoiceInputPreferenceController extends DefaultAppPreferenceC
}
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
if (TextUtils.equals(defaultKey, info.key)) {
if (TextUtils.equals(defaultKey, info.mKey)) {
return new DefaultVoiceInputPicker.VoiceInputDefaultAppInfo(mContext,
mPackageManager, mUserId, info, true /* enabled */);
}

View File

@@ -44,8 +44,9 @@ public class LanguageAndInputSettings extends DashboardFragment {
private static final String TAG = "LangAndInputSettings";
private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category";
private static final String KEY_SPEECH_CATEGORY = "speech_category";
private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary";
private static final String KEY_POINTER_AND_TTS_CATEGORY = "pointer_and_tts_category";
private static final String KEY_POINTER_CATEGORY = "pointer_category";
@Override
public int getMetricsCategory() {
@@ -98,15 +99,22 @@ public class LanguageAndInputSettings extends DashboardFragment {
Arrays.asList(virtualKeyboardPreferenceController,
physicalKeyboardPreferenceController)));
// Pointer and Tts
// Speech
final DefaultVoiceInputPreferenceController defaultVoiceInputPreferenceController =
new DefaultVoiceInputPreferenceController(context, lifecycle);
final TtsPreferenceController ttsPreferenceController =
new TtsPreferenceController(context, KEY_TEXT_TO_SPEECH);
controllers.add(defaultVoiceInputPreferenceController);
controllers.add(ttsPreferenceController);
controllers.add(new PreferenceCategoryController(context,
KEY_SPEECH_CATEGORY).setChildren(
Arrays.asList(defaultVoiceInputPreferenceController, ttsPreferenceController)));
// Pointer
final PointerSpeedController pointerController = new PointerSpeedController(context);
controllers.add(pointerController);
controllers.add(new PreferenceCategoryController(context,
KEY_POINTER_AND_TTS_CATEGORY).setChildren(
Arrays.asList(pointerController, ttsPreferenceController)));
KEY_POINTER_CATEGORY).setChildren(Arrays.asList(pointerController)));
// Input Assistance
controllers.add(new SpellCheckerPreferenceController(context));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.applications.assist;
package com.android.settings.language;
import android.content.ComponentName;
import android.content.Context;
@@ -39,40 +39,46 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/** Helper class of the Voice Input setting. */
public final class VoiceInputHelper {
static final String TAG = "VoiceInputHelper";
final Context mContext;
final List<ResolveInfo> mAvailableRecognition;
// TODO: Remove this superclass as we only have 1 class now (RecognizerInfo).
static public class BaseInfo implements Comparable {
public final ServiceInfo service;
public final ComponentName componentName;
public final String key;
public final ComponentName settings;
public final CharSequence label;
public final String labelStr;
public final CharSequence appLabel;
/**
* Base info of the Voice Input provider.
*
* TODO: Remove this superclass as we only have 1 class now (RecognizerInfo).
*/
public static class BaseInfo implements Comparable<BaseInfo> {
public final ServiceInfo mService;
public final ComponentName mComponentName;
public final String mKey;
public final ComponentName mSettings;
public final CharSequence mLabel;
public final String mLabelStr;
public final CharSequence mAppLabel;
public BaseInfo(PackageManager pm, ServiceInfo _service, String _settings) {
service = _service;
componentName = new ComponentName(_service.packageName, _service.name);
key = componentName.flattenToShortString();
settings = _settings != null
? new ComponentName(_service.packageName, _settings) : null;
label = _service.loadLabel(pm);
labelStr = label.toString();
appLabel = _service.applicationInfo.loadLabel(pm);
public BaseInfo(PackageManager pm, ServiceInfo service, String settings) {
mService = service;
mComponentName = new ComponentName(service.packageName, service.name);
mKey = mComponentName.flattenToShortString();
mSettings = settings != null
? new ComponentName(service.packageName, settings) : null;
mLabel = service.loadLabel(pm);
mLabelStr = mLabel.toString();
mAppLabel = service.applicationInfo.loadLabel(pm);
}
@Override
public int compareTo(Object another) {
return labelStr.compareTo(((BaseInfo) another).labelStr);
public int compareTo(BaseInfo another) {
return mLabelStr.compareTo(another.mLabelStr);
}
}
static public class RecognizerInfo extends BaseInfo {
/** Info of the speech recognizer (i.e. recognition service). */
public static class RecognizerInfo extends BaseInfo {
public final boolean mSelectableAsDefault;
public RecognizerInfo(PackageManager pm,
@@ -96,6 +102,7 @@ public final class VoiceInputHelper {
PackageManager.GET_META_DATA);
}
/** Draws the UI of the Voice Input picker page. */
public void buildUi() {
// Get the currently selected recognizer from the secure setting.
String currentSetting = Settings.Secure.getString(
@@ -120,8 +127,8 @@ public final class VoiceInputHelper {
try (XmlResourceParser parser = si.loadXmlMetaData(mContext.getPackageManager(),
RecognitionService.SERVICE_META_DATA)) {
if (parser == null) {
throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA +
" meta-data for " + si.packageName);
throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA
+ " meta-data for " + si.packageName);
}
Resources res = mContext.getPackageManager().getResourcesForApplication(
@@ -132,6 +139,7 @@ public final class VoiceInputHelper {
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
// Intentionally do nothing.
}
String nodeName = parser.getName();