diff options
author | 2015-10-30 15:59:12 +0000 | |
---|---|---|
committer | 2015-10-30 15:59:12 +0000 | |
commit | f789ef7e381ea57a4f515fde470d40f93bc5f345 (patch) | |
tree | 0f19429a9d296f109e9acba0edb3de6147ab674c | |
parent | e86dc7687a05b45ad9176288eb496f146ecf6928 (diff) | |
parent | 5789c3e24f0963bfc85477bfbbfe93be88946024 (diff) |
Merge "Move AccessibilityUtils to SettingsLib"
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java b/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java new file mode 100644 index 000000000000..cf17ea5ebf1a --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 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.settingslib.accessibility; + +import android.content.ComponentName; +import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.provider.Settings; +import android.text.TextUtils; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +public class AccessibilityUtils { + public static final char ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR = ':'; + + final static TextUtils.SimpleStringSplitter sStringColonSplitter = + new TextUtils.SimpleStringSplitter(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR); + + /** + * @return the set of enabled accessibility services. If there are not services + * it returned the unmodifiable {@link Collections#emptySet()}. + */ + public static Set<ComponentName> getEnabledServicesFromSettings(Context context) { + final String enabledServicesSetting = Settings.Secure.getString( + context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); + if (enabledServicesSetting == null) { + return Collections.emptySet(); + } + + final Set<ComponentName> enabledServices = new HashSet<ComponentName>(); + final TextUtils.SimpleStringSplitter colonSplitter = sStringColonSplitter; + colonSplitter.setString(enabledServicesSetting); + + while (colonSplitter.hasNext()) { + final String componentNameString = colonSplitter.next(); + final ComponentName enabledService = ComponentName.unflattenFromString( + componentNameString); + if (enabledService != null) { + enabledServices.add(enabledService); + } + } + + return enabledServices; + } + + /** + * @return a localized version of the text resource specified by resId + */ + public static CharSequence getTextForLocale(Context context, Locale locale, int resId) { + final Resources res = context.getResources(); + final Configuration config = new Configuration(res.getConfiguration()); + config.setLocale(locale); + final Context langContext = context.createConfigurationContext(config); + return langContext.getText(resId); + } +} |