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