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