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. If there are not services
37 * it returned the unmodifiable {@link Collections#emptySet()}.
39 static Set<ComponentName> getEnabledServicesFromSettings(Context context) {
40 final String enabledServicesSetting = Settings.Secure.getString(
41 context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
42 if (enabledServicesSetting == null) {
43 return Collections.emptySet();
46 final Set<ComponentName> enabledServices = new HashSet<ComponentName>();
47 final SimpleStringSplitter colonSplitter = AccessibilitySettings.sStringColonSplitter;
48 colonSplitter.setString(enabledServicesSetting);
50 while (colonSplitter.hasNext()) {
51 final String componentNameString = colonSplitter.next();
52 final ComponentName enabledService = ComponentName.unflattenFromString(
54 if (enabledService != null) {
55 enabledServices.add(enabledService);
59 return enabledServices;
63 * @return a localized version of the text resource specified by resId
65 static CharSequence getTextForLocale(Context context, Locale locale, int resId) {
66 final Resources res = context.getResources();
67 final Configuration config = res.getConfiguration();
68 final Locale prevLocale = config.locale;
70 config.locale = locale;
71 res.updateConfiguration(config, null);
72 return res.getText(resId);
74 config.locale = prevLocale;
75 res.updateConfiguration(config, null);