blob: e7b0c72036c9c8942700891421ac938fcc1c6ee3 [file] [log] [blame]
Fan Zhang22d42d52016-11-03 13:29:06 -07001/*
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
17package com.android.settings.language;
18
19import android.content.Context;
20import android.support.v7.preference.Preference;
21
Tony Mantler1d583e12017-06-13 13:09:25 -070022import com.android.settings.core.PreferenceControllerMixin;
Fan Zhang22d42d52016-11-03 13:29:06 -070023import com.android.settings.overlay.FeatureFactory;
Tony Mantler1d583e12017-06-13 13:09:25 -070024import com.android.settingslib.core.AbstractPreferenceController;
Fan Zhang22d42d52016-11-03 13:29:06 -070025
Fan Zhang231986a2017-10-10 13:53:32 -070026import java.util.List;
27
Tony Mantler1d583e12017-06-13 13:09:25 -070028public class PhoneLanguagePreferenceController extends AbstractPreferenceController
29 implements PreferenceControllerMixin {
Fan Zhang22d42d52016-11-03 13:29:06 -070030
31 private static final String KEY_PHONE_LANGUAGE = "phone_language";
32
33 public PhoneLanguagePreferenceController(Context context) {
34 super(context);
35 }
36
37 @Override
38 public boolean isAvailable() {
39 return mContext.getAssets().getLocales().length > 1;
40 }
41
42 @Override
Fan Zhang22d42d52016-11-03 13:29:06 -070043 public void updateState(Preference preference) {
44 if (preference == null) {
45 return;
46 }
47 final String localeNames = FeatureFactory.getFactory(mContext)
48 .getLocaleFeatureProvider().getLocaleNames();
49 preference.setSummary(localeNames);
50 }
51
52 @Override
Fan Zhang231986a2017-10-10 13:53:32 -070053 public void updateNonIndexableKeys(List<String> keys) {
54 // No index needed, because this pref has the same name as the parent page. Indexing it will
55 // make search page look like there are duplicate result, creating confusion.
56 keys.add(getPreferenceKey());
57 }
58
59 @Override
Fan Zhang22d42d52016-11-03 13:29:06 -070060 public String getPreferenceKey() {
61 return KEY_PHONE_LANGUAGE;
62 }
63}