1 /* 2 * Copyright (C) 2016 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 17 package com.android.settings.language; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 22 import androidx.preference.Preference; 23 24 import com.android.settings.R; 25 import com.android.settings.core.PreferenceControllerMixin; 26 import com.android.settings.core.SubSettingLauncher; 27 import com.android.settings.localepicker.LocaleListEditor; 28 import com.android.settings.overlay.FeatureFactory; 29 import com.android.settingslib.core.AbstractPreferenceController; 30 31 import java.util.List; 32 33 public class PhoneLanguagePreferenceController extends AbstractPreferenceController 34 implements PreferenceControllerMixin { 35 36 private static final String KEY_PHONE_LANGUAGE = "phone_language"; 37 PhoneLanguagePreferenceController(Context context)38 public PhoneLanguagePreferenceController(Context context) { 39 super(context); 40 } 41 42 @Override isAvailable()43 public boolean isAvailable() { 44 return mContext.getResources().getBoolean(R.bool.config_show_phone_language) 45 && mContext.getAssets().getLocales().length > 1; 46 } 47 48 @Override updateState(Preference preference)49 public void updateState(Preference preference) { 50 if (preference == null) { 51 return; 52 } 53 final String localeNames = FeatureFactory.getFactory(mContext) 54 .getLocaleFeatureProvider().getLocaleNames(); 55 preference.setSummary(localeNames); 56 } 57 58 @Override updateNonIndexableKeys(List<String> keys)59 public void updateNonIndexableKeys(List<String> keys) { 60 // No index needed, because this pref has the same name as the parent page. Indexing it will 61 // make search page look like there are duplicate result, creating confusion. 62 keys.add(getPreferenceKey()); 63 } 64 65 @Override getPreferenceKey()66 public String getPreferenceKey() { 67 return KEY_PHONE_LANGUAGE; 68 } 69 70 @Override handlePreferenceTreeClick(Preference preference)71 public boolean handlePreferenceTreeClick(Preference preference) { 72 if (!KEY_PHONE_LANGUAGE.equals(preference.getKey())) { 73 return false; 74 } 75 new SubSettingLauncher(mContext) 76 .setDestination(LocaleListEditor.class.getName()) 77 .setSourceMetricsCategory(SettingsEnums.SETTINGS_LANGUAGE_CATEGORY) 78 .setTitleRes(R.string.language_picker_title) 79 .launch(); 80 return true; 81 } 82 83 } 84