Heemin Seog | 455776a | 2018-11-07 16:07:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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.car.settings.language; |
| 18 | |
Heemin Seog | c9f9450 | 2018-12-18 10:23:14 -0800 | [diff] [blame] | 19 | import android.car.drivingstate.CarUxRestrictions; |
Heemin Seog | 455776a | 2018-11-07 16:07:46 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.os.Build; |
| 22 | |
| 23 | import com.android.car.settings.common.FragmentController; |
| 24 | import com.android.internal.app.LocaleStore; |
| 25 | |
| 26 | import java.util.Locale; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** Business logic for showing and acting on languages in the language settings screen. */ |
| 30 | public class LanguagePickerPreferenceController extends LanguageBasePreferenceController { |
| 31 | |
| 32 | public LanguagePickerPreferenceController(Context context, String preferenceKey, |
Heemin Seog | c9f9450 | 2018-12-18 10:23:14 -0800 | [diff] [blame] | 33 | FragmentController fragmentController, CarUxRestrictions uxRestrictions) { |
| 34 | super(context, preferenceKey, fragmentController, uxRestrictions); |
Heemin Seog | 455776a | 2018-11-07 16:07:46 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | @Override |
| 38 | protected LocalePreferenceProvider defineLocaleProvider() { |
| 39 | Set<LocaleStore.LocaleInfo> localeInfoSet = LocaleStore.getLevelLocales( |
Heemin Seog | c9f9450 | 2018-12-18 10:23:14 -0800 | [diff] [blame] | 40 | getContext(), |
Heemin Seog | 455776a | 2018-11-07 16:07:46 -0800 | [diff] [blame] | 41 | getExclusionSet(), |
| 42 | /* parent= */ null, |
| 43 | /* translatedOnly= */ true); |
| 44 | maybeAddPseudoLocale(localeInfoSet); |
| 45 | |
Heemin Seog | c9f9450 | 2018-12-18 10:23:14 -0800 | [diff] [blame] | 46 | return LocalePreferenceProvider.newInstance(getContext(), localeInfoSet, |
Heemin Seog | 455776a | 2018-11-07 16:07:46 -0800 | [diff] [blame] | 47 | /* parentLocale= */ null); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void handleLocaleWithChildren(LocaleStore.LocaleInfo parentLocaleInfo) { |
| 52 | ChildLocalePickerFragment fragment = ChildLocalePickerFragment.newInstance( |
| 53 | parentLocaleInfo); |
| 54 | fragment.registerChildLocaleSelectedListener( |
| 55 | localeInfo -> getFragmentController().goBack()); |
| 56 | getFragmentController().launchFragment(fragment); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Add a pseudo locale in debug build for testing RTL. |
| 61 | * |
| 62 | * @param localeInfos the set of {@link LocaleStore.LocaleInfo} to which the locale is added. |
| 63 | */ |
| 64 | private void maybeAddPseudoLocale(Set<LocaleStore.LocaleInfo> localeInfos) { |
| 65 | if (Build.IS_USERDEBUG) { |
| 66 | // The ar-XB pseudo-locale is RTL. |
| 67 | localeInfos.add(LocaleStore.getLocaleInfo(new Locale("ar", "XB"))); |
| 68 | } |
| 69 | } |
| 70 | } |