• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.widget.TextView;
22 
23 import androidx.annotation.XmlRes;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.common.SettingsFragment;
27 import com.android.internal.app.LocaleStore;
28 
29 import java.util.Locale;
30 
31 /** Secondary screen for language selection, when a language has multiple locales. */
32 public class ChildLocalePickerFragment extends SettingsFragment {
33 
34     /**
35      * Creates a ChildLocalePickerFragment with the parent locale info included in the arguments.
36      */
newInstance(LocaleStore.LocaleInfo parentLocaleInfo)37     public static ChildLocalePickerFragment newInstance(LocaleStore.LocaleInfo parentLocaleInfo) {
38         Bundle bundle = new Bundle();
39         bundle.putSerializable(LocaleUtil.LOCALE_BUNDLE_KEY, parentLocaleInfo.getLocale());
40         ChildLocalePickerFragment fragment = new ChildLocalePickerFragment();
41         fragment.setArguments(bundle);
42         return fragment;
43     }
44 
45     private LanguageBasePreferenceController.LocaleSelectedListener mLocaleSelectedListener;
46     private LocaleStore.LocaleInfo mParentLocaleInfo;
47 
48     /**
49      * Allows the creator of ChildLocalePickerFragment to include a listener for when the child
50      * locale is selected.
51      */
registerChildLocaleSelectedListener( LanguageBasePreferenceController.LocaleSelectedListener listener)52     public void registerChildLocaleSelectedListener(
53             LanguageBasePreferenceController.LocaleSelectedListener listener) {
54         mLocaleSelectedListener = listener;
55     }
56 
57     @Override
onAttach(Context context)58     public void onAttach(Context context) {
59         super.onAttach(context);
60         Locale locale = (Locale) getArguments().getSerializable(LocaleUtil.LOCALE_BUNDLE_KEY);
61         mParentLocaleInfo = LocaleStore.getLocaleInfo(locale);
62         use(ChildLocalePickerPreferenceController.class,
63                 R.string.pk_child_locale_picker).setParentLocaleInfo(mParentLocaleInfo);
64         use(ChildLocalePickerPreferenceController.class,
65                 R.string.pk_child_locale_picker).setLocaleSelectedListener(
66                 mLocaleSelectedListener);
67     }
68 
69     @Override
onActivityCreated(Bundle savedInstanceState)70     public void onActivityCreated(Bundle savedInstanceState) {
71         super.onActivityCreated(savedInstanceState);
72 
73         TextView titleView = getActivity().findViewById(R.id.title);
74         titleView.setText(mParentLocaleInfo.getFullNameNative());
75     }
76 
77     @Override
78     @XmlRes
getPreferenceScreenResId()79     protected int getPreferenceScreenResId() {
80         return R.xml.child_locale_picker_fragment;
81     }
82 }
83