Fan Zhang | 22d42d5 | 2016-11-03 13:29:06 -0700 | [diff] [blame] | 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.content.Context; |
| 20 | import android.support.v7.preference.Preference; |
| 21 | |
Tony Mantler | 1d583e1 | 2017-06-13 13:09:25 -0700 | [diff] [blame] | 22 | import com.android.settings.core.PreferenceControllerMixin; |
Fan Zhang | 22d42d5 | 2016-11-03 13:29:06 -0700 | [diff] [blame] | 23 | import com.android.settings.overlay.FeatureFactory; |
Tony Mantler | 1d583e1 | 2017-06-13 13:09:25 -0700 | [diff] [blame] | 24 | import com.android.settingslib.core.AbstractPreferenceController; |
Fan Zhang | 22d42d5 | 2016-11-03 13:29:06 -0700 | [diff] [blame] | 25 | |
Fan Zhang | 231986a | 2017-10-10 13:53:32 -0700 | [diff] [blame] | 26 | import java.util.List; |
| 27 | |
Tony Mantler | 1d583e1 | 2017-06-13 13:09:25 -0700 | [diff] [blame] | 28 | public class PhoneLanguagePreferenceController extends AbstractPreferenceController |
| 29 | implements PreferenceControllerMixin { |
Fan Zhang | 22d42d5 | 2016-11-03 13:29:06 -0700 | [diff] [blame] | 30 | |
| 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 Zhang | 22d42d5 | 2016-11-03 13:29:06 -0700 | [diff] [blame] | 43 | 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 Zhang | 231986a | 2017-10-10 13:53:32 -0700 | [diff] [blame] | 53 | 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 Zhang | 22d42d5 | 2016-11-03 13:29:06 -0700 | [diff] [blame] | 60 | public String getPreferenceKey() { |
| 61 | return KEY_PHONE_LANGUAGE; |
| 62 | } |
| 63 | } |