1 /* 2 * Copyright (C) 2013 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.accessibility; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.preference.ListPreference; 22 import android.util.AttributeSet; 23 24 import com.android.internal.app.LocalePicker; 25 import com.android.settings.R; 26 27 import java.text.Collator; 28 import java.util.Arrays; 29 import java.util.List; 30 import java.util.Locale; 31 32 /** 33 * List preference that allows the user to pick a locale from the list of 34 * supported device locales. 35 */ 36 public class LocalePreference extends ListPreference { LocalePreference(Context context, AttributeSet attrs)37 public LocalePreference(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 init(context); 40 } 41 LocalePreference(Context context)42 public LocalePreference(Context context) { 43 super(context); 44 init(context); 45 } 46 init(Context context)47 public void init(Context context) { 48 List<LocalePicker.LocaleInfo> locales = LocalePicker.getAllAssetLocales(context, 49 false /* in developer mode */); 50 51 final int finalSize = locales.size(); 52 final CharSequence[] entries = new CharSequence[finalSize + 1]; 53 final CharSequence[] entryValues = new CharSequence[finalSize + 1]; 54 entries[0] = context.getResources().getString(R.string.locale_default); 55 entryValues[0] = ""; 56 57 for (int i = 0; i < finalSize; i++) { 58 final LocalePicker.LocaleInfo info = locales.get(i); 59 entries[i + 1] = info.toString(); 60 entryValues[i + 1] = info.getLocale().toString(); 61 } 62 63 setEntries(entries); 64 setEntryValues(entryValues); 65 } 66 } 67