MultiLingualSettingsFragment.java revision a715d7f6fd3b29e660d78f83815ebe75837f1436
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17package com.android.inputmethod.latin.settings; 18 19import android.content.Context; 20import android.content.SharedPreferences; 21import android.content.res.Resources; 22import android.os.Bundle; 23import android.preference.PreferenceScreen; 24import android.text.TextUtils; 25import android.view.inputmethod.InputMethodSubtype; 26 27import com.android.inputmethod.latin.R; 28import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils; 29import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; 30 31import java.util.ArrayList; 32 33/** 34 * "Multi lingual options" settings sub screen. 35 * 36 * This settings sub screen handles the following input preferences. 37 * - Language switch key 38 * - Switch to other input methods 39 * - Custom input styles 40 */ 41public final class MultiLingualSettingsFragment extends SubScreenFragment { 42 @Override 43 public void onCreate(final Bundle icicle) { 44 super.onCreate(icicle); 45 addPreferencesFromResource(R.xml.prefs_screen_multi_lingual); 46 47 final Context context = getActivity(); 48 49 // When we are called from the Settings application but we are not already running, some 50 // singleton and utility classes may not have been initialized. We have to call 51 // initialization method of these classes here. See {@link LatinIME#onCreate()}. 52 SubtypeLocaleUtils.init(context); 53 54 if (!Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS) { 55 removePreference(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY); 56 removePreference(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST); 57 } 58 } 59 60 @Override 61 public void onResume() { 62 super.onResume(); 63 updateCustomInputStylesSummary(); 64 } 65 66 private void updateCustomInputStylesSummary() { 67 final SharedPreferences prefs = getSharedPreferences(); 68 final Resources res = getResources(); 69 final PreferenceScreen customInputStyles = 70 (PreferenceScreen)findPreference(Settings.PREF_CUSTOM_INPUT_STYLES); 71 final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res); 72 final InputMethodSubtype[] subtypes = 73 AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype); 74 final ArrayList<String> subtypeNames = new ArrayList<>(); 75 for (final InputMethodSubtype subtype : subtypes) { 76 subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)); 77 } 78 // TODO: A delimiter of custom input styles should be localized. 79 customInputStyles.setSummary(TextUtils.join(", ", subtypeNames)); 80 } 81} 82