behalf. It comes from the <xliff:g id="voice_input_service_app_name">%s</xliff:g>
application. Enable the use of this service?</string>
- <!-- Text-To-Speech (TTS) settings --><skip />
- <!-- Name of the TTS package as listed by the package manager. -->
- <string name="tts_settings">Text-to-speech settings</string>
- <!-- TTS option item name in the main settings screen -->
- <string name="tts_settings_title">Text-to-speech output</string>
- <!-- On main TTS Settings screen, title for toggle used to force use of default TTS settings -->
- <string name="use_default_tts_settings_title">Always use my settings</string>
- <!-- On main TTS Settings screen, summary for toggle used to force use of default TTS settings -->
- <string name="use_default_tts_settings_summary">Default settings below override app settings</string>
- <!-- On main TTS Settings screen, section header for default TTS settings -->
- <string name="tts_default_settings_section">Default settings</string>
- <!-- On main TTS Settings screen, in default settings section, setting default synthesis engine for synthesized voice -->
- <string name="tts_default_synth_title">Default engine</string>
- <!-- On main TTS Settings screen, summary for default synthesis engine for synthesized voice -->
- <string name="tts_default_synth_summary">Set the speech synthesis engine to be used for spoken text</string>
- <!-- On main TTS Settings screen, in default settings section, setting default speech rate for synthesized voice -->
- <string name="tts_default_rate_title">Speech rate</string>
- <!-- On main TTS Settings screen, summary for default speech rate for synthesized voice -->
- <string name="tts_default_rate_summary">Speed at which the text is spoken</string>
- <!-- On main TTS Settings screen, in default settings section, setting default pitch for synthesized voice -->
- <string name="tts_default_pitch_title">Pitch</string>
- <!-- On main TTS Settings screen, summary for default pitch for synthesized voice -->
- <string name="tts_default_pitch_summary">Affects the tone of the spoken text</string>
-
- <!-- On main TTS Settings screen, in default settings section, setting default language for synthesized voice -->
- <string name="tts_default_lang_title">Language</string>
- <!-- Entry in the TTS engine language/locale picker, when selected will try to default to the system language [CHAR LIMIT=50] -->
- <string name="tts_lang_use_system">Use system language</string>
- <!-- On main TTS Settings screen, language summary if it can't default to system language [CHAR LIMIT=50] -->
- <string name="tts_lang_not_selected">Language not selected</string>
- <!-- On main TTS Settings screen, summary for default language for synthesized voice -->
- <string name="tts_default_lang_summary">Sets the language-specific voice for the spoken text</string>
- <!-- On main TTS Settings screen, triggers playback of an example of speech synthesis -->
- <string name="tts_play_example_title">Listen to an example</string>
- <!-- On main TTS Settings screen, summary for triggering playback of an example of speech synthesis -->
- <string name="tts_play_example_summary">Play a short demonstration of speech synthesis</string>
- <!-- On main TTS Settings screen, click to install required speech synthesis data -->
- <string name="tts_install_data_title">Install voice data</string>
- <!-- On main TTS Settings screen, summary for click to install required speech synthesis data -->
- <string name="tts_install_data_summary">Install the voice data required for speech synthesis</string>
- <!-- On main TTS Settings screen, summary for when required speech synthesis data alrady installed on SD card -->
- <string name="tts_data_installed_summary">Voices required for speech synthesis already properly installed</string>
- <!-- Text spoken by the TTS engine when TTS settings (other than language) have been changed -->
- <string name="tts_settings_changed_demo">Your settings have changed. This is an example of how they sound.</string>
- <!-- Error screen when a selected TTS engine can't run because it's missing components -->
- <string name="tts_engine_error">The engine you chose can\u2019t run.</string>
- <!-- Button text for error screen when a selected TTS engine can't run because it's missing components -->
- <string name="tts_engine_error_config">Configure</string>
- <!-- Button text for error screen when a selected TTS engine can't run because it's missing components -->
- <string name="tts_engine_error_reselect">Choose another engine</string>
- <!-- Warning message about security implications of enabling a TTS engine, displayed as a dialog
- message when the user selects to enable an engine. -->
- <string name="tts_engine_security_warning">This speech synthesis engine may be able to collect
- all the text that will be spoken, including personal data like passwords and credit
- card numbers. It comes from the <xliff:g id="tts_plugin_engine_name">%s</xliff:g> engine.
- Enable the use of this speech synthesis engine?</string>
- <!-- Warning message about required internet conectivity for TTS synthesis, displayed as a dialog
- message when the user selects to play an example for network only locale and there's no internet connectivity. -->
- <string name="tts_engine_network_required">This language requires a working network connection for text-to-speech output.</string>
- <!-- Text spoken by the TTS engine as an example if the engine doesn't provide sample text [CHAR LIMIT=100] -->
- <string name="tts_default_sample_string">This is an example of speech synthesis</string>
- <!-- On main TTS Settings screen, title of a field explaining current TTS engine status for
- current default language [CHAR LIMIT=50] -->
- <string name="tts_status_title">Default language status</string>
- <!-- On main TTS Settings screen, current TTS engine status for the current default language,
- selected language is fully supported by the engine [CHAR LIMIT=150]-->
- <string name="tts_status_ok"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> is fully supported</string>
- <!-- On main TTS Settings screen, current TTS engine status for the current default language,
- selected language is supported by the engine only if there's a working network connection [CHAR LIMIT=150] -->
- <string name="tts_status_requires_network"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> requires network connection</string>
- <!-- On main TTS Settings screen, current TTS engine status for the current default language,
- selected language is not supported by the engine [CHAR LIMIT=150] -->
- <string name="tts_status_not_supported"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> is not supported</string>
- <!-- On main TTS Settings screen, current TTS engine status for the current default language,
- tts engine is queried for status [CHAR LIMIT=150] -->
- <string name="tts_status_checking">Checking...</string>
- <!-- On main TTS Settings screen, text for divider under which all TTS engines are listed -->
- <string name="tts_engines_section">Engines</string>
- <!-- On main TTS Settings screen, text preceded by the TTS engine name, clicking this button will launch the engine settings -->
- <string name="tts_engine_name_settings"><xliff:g id="tts_plugin_engine_name">%s</xliff:g> settings</string>
- <!-- On main TTS Settings screen, text preceded by the TTS engine name to indicate the engine can be used by the user -->
- <string name="tts_engine_name_is_enabled_summary"><xliff:g id="tts_plugin_engine_name">%s</xliff:g> is enabled</string>
- <!-- On main TTS Settings screen, text preceded by the TTS engine name to indicate the engine cannot be used by the user -->
- <string name="tts_engine_name_is_disabled_summary"><xliff:g id="tts_plugin_engine_name">%s</xliff:g> is disabled</string>
- <!-- On the main TTS settings screen, text for a divider under which
- the engine specific settings and the "engine install data" option
- are listed [CHAR LIMIT=30]-->
- <string name="tts_engine_settings_section">Engine settings</string>
- <!-- Title for a preference in the main TTS settings screen, which
- launches the settings screen for a given TTS engine when clicked
- [CHAR LIMIT=30]-->
- <string name="tts_engine_settings_title">Settings for <xliff:g id="tts_engine_name">%s</xliff:g></string>
- <!-- On Pico TTS Settings screen, text to mark the section for the various languages and voices that are available -->
- <string name="pico_languages_and_voices">Languages and voices</string>
- <!-- On Pico TTS Settings screen, text to mark a voice as installed -->
- <string name="pico_installed">Installed</string>
- <!-- On Pico TTS Settings screen, text to mark a voice as not installed -->
- <string name="pico_not_installed">Not installed</string>
- <!-- On Pico TTS Settings screen, summary text to indicate that a voice is female -->
- <string name="pico_voice_summary_female">Female</string>
- <!-- On Pico TTS Settings screen, summary text to indicate that a voice is male -->
- <string name="pico_voice_summary_male">Male</string>
- <!-- [CHAR LIMIT=33] Notification title that appears when the installation of a new TTS engine completed -->
- <string name="tts_notif_engine_install_title">Speech synthesis engine installed</string>
- <!-- [CHAR LIMIT=30] Notification message that appears after the user has installed a new TTS engine,
- to warn the user that this engine cannot be used before the checkbox for that engine
- in TTS settings is checked. -->
- <string name="tts_notif_engine_install_message">Enable new engine before use.</string>
- <!-- [CHAR LIMIT=150] Text for screen readers / accessibility programs for
- the image that launches the TTS engine settings when clicked. -->
- <string name="tts_engine_settings_button">Launch engine settings</string>
- <!-- [CHAR LIMIT=50] The text for the settings section that users to set a
- preferred text to speech engine -->
- <string name="tts_engine_preference_section_title">Preferred engine</string>
- <!-- [CHAR LIMIT=50] Title of the settings section that displays general preferences
- that are applicable to all engines, such as the speech rate -->
- <string name="tts_general_section_title">General</string>
-
<!-- Power Control Widget -->
<string name="gadget_title">Power control</string>
<string name="gadget_toggle_wifi">Updating Wi\u2011Fi setting</string>
import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
import com.android.settingslib.accessibility.AccessibilityUtils;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
public class ToggleAccessibilityServicePreferenceFragment
extends ToggleFeaturePreferenceFragment implements DialogInterface.OnClickListener {
@Override
public void onPreferenceToggled(String preferenceKey, boolean enabled) {
- // Parse the enabled services.
- Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(
- getActivity());
-
- if (enabledServices == (Set<?>) Collections.emptySet()) {
- enabledServices = new HashSet<ComponentName>();
- }
-
- // Determine enabled services and accessibility state.
ComponentName toggledService = ComponentName.unflattenFromString(preferenceKey);
- boolean accessibilityEnabled = false;
- if (enabled) {
- enabledServices.add(toggledService);
- // Enabling at least one service enables accessibility.
- accessibilityEnabled = true;
- } else {
- enabledServices.remove(toggledService);
- // Check how many enabled and installed services are present.
- Set<ComponentName> installedServices = AccessibilitySettings.sInstalledServices;
- for (ComponentName enabledService : enabledServices) {
- if (installedServices.contains(enabledService)) {
- // Disabling the last service disables accessibility.
- accessibilityEnabled = true;
- break;
- }
- }
- }
-
- // Update the enabled services setting.
- StringBuilder enabledServicesBuilder = new StringBuilder();
- // Keep the enabled services even if they are not installed since we
- // have no way to know whether the application restore process has
- // completed. In general the system should be responsible for the
- // clean up not settings.
- for (ComponentName enabledService : enabledServices) {
- enabledServicesBuilder.append(enabledService.flattenToString());
- enabledServicesBuilder.append(
- AccessibilityUtils.ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR);
- }
- final int enabledServicesBuilderLength = enabledServicesBuilder.length();
- if (enabledServicesBuilderLength > 0) {
- enabledServicesBuilder.deleteCharAt(enabledServicesBuilderLength - 1);
- }
- Settings.Secure.putString(getContentResolver(),
- Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
- enabledServicesBuilder.toString());
-
- // Update accessibility enabled.
- Settings.Secure.putInt(getContentResolver(),
- Settings.Secure.ACCESSIBILITY_ENABLED, accessibilityEnabled ? 1 : 0);
+ AccessibilityUtils.setAccessibilityServiceState(getActivity(), toggledService, enabled);
}
// IMPORTANT: Refresh the info since there are dynamically changing