2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.accessibility;
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.content.res.Resources;
23 import android.provider.Settings;
24 import android.text.TextUtils.SimpleStringSplitter;
26 import java.util.Collections;
27 import java.util.HashSet;
28 import java.util.Locale;
32 * Utility methods used within accessibility settings.
34 class AccessibilityUtils {
36 * @return the set of enabled accessibility services
38 static Set<ComponentName> getEnabledServicesFromSettings(Context context) {
39 final String enabledServicesSetting = Settings.Secure.getString(
40 context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
41 if (enabledServicesSetting == null) {
42 return Collections.emptySet();
45 final Set<ComponentName> enabledServices = new HashSet<ComponentName>();
46 final SimpleStringSplitter colonSplitter = AccessibilitySettings.sStringColonSplitter;
47 colonSplitter.setString(enabledServicesSetting);
49 while (colonSplitter.hasNext()) {
50 final String componentNameString = colonSplitter.next();
51 final ComponentName enabledService = ComponentName.unflattenFromString(
53 if (enabledService != null) {
54 enabledServices.add(enabledService);
58 return enabledServices;
62 * @return a localized version of the text resource specified by resId
64 static CharSequence getTextForLocale(Context context, Locale locale, int resId) {
65 final Resources res = context.getResources();
66 final Configuration config = res.getConfiguration();
67 final Locale prevLocale = config.locale;
69 config.locale = locale;
70 res.updateConfiguration(config, null);
71 return res.getText(resId);
73 config.locale = prevLocale;
74 res.updateConfiguration(config, null);