blob: fd6d9d428c5fda42bf3617f1c71c923809116de7 [file] [log] [blame]
Heemin Seog455776a2018-11-07 16:07:46 -08001/*
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
17package com.android.car.settings.language;
18
Heemin Seogc9f94502018-12-18 10:23:14 -080019import android.car.drivingstate.CarUxRestrictions;
Heemin Seog455776a2018-11-07 16:07:46 -080020import android.content.Context;
21import android.os.Build;
22
23import com.android.car.settings.common.FragmentController;
24import com.android.internal.app.LocaleStore;
25
26import java.util.Locale;
27import java.util.Set;
28
29/** Business logic for showing and acting on languages in the language settings screen. */
30public class LanguagePickerPreferenceController extends LanguageBasePreferenceController {
31
32 public LanguagePickerPreferenceController(Context context, String preferenceKey,
Heemin Seogc9f94502018-12-18 10:23:14 -080033 FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
34 super(context, preferenceKey, fragmentController, uxRestrictions);
Heemin Seog455776a2018-11-07 16:07:46 -080035 }
36
37 @Override
38 protected LocalePreferenceProvider defineLocaleProvider() {
39 Set<LocaleStore.LocaleInfo> localeInfoSet = LocaleStore.getLevelLocales(
Heemin Seogc9f94502018-12-18 10:23:14 -080040 getContext(),
Heemin Seog455776a2018-11-07 16:07:46 -080041 getExclusionSet(),
42 /* parent= */ null,
43 /* translatedOnly= */ true);
44 maybeAddPseudoLocale(localeInfoSet);
45
Heemin Seogc9f94502018-12-18 10:23:14 -080046 return LocalePreferenceProvider.newInstance(getContext(), localeInfoSet,
Heemin Seog455776a2018-11-07 16:07:46 -080047 /* 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}