Loading core/java/com/android/internal/app/LocalePickerWithRegion.java +5 −4 Original line number Diff line number Diff line Loading @@ -158,16 +158,17 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O if (appCurrentLocale != null && !isForCountryMode) { mLocaleList.add(appCurrentLocale); } filterTheLanguagesNotSupportedInApp(context, appPackageName); mLocaleList = filterTheLanguagesNotSupportedInApp(context, appPackageName); if (!isForCountryMode) { mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo()); mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo(appCurrentLocale == null)); } } return true; } private void filterTheLanguagesNotSupportedInApp(Context context, String appPackageName) { private Set<LocaleStore.LocaleInfo> filterTheLanguagesNotSupportedInApp( Context context, String appPackageName) { ArrayList<Locale> supportedLocales = AppLocaleStore.getAppSupportedLocales(context, appPackageName); Loading @@ -181,7 +182,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O } Log.d(TAG, "mLocaleList after app-supported filter: " + filteredList.size()); mLocaleList = filteredList; return filteredList; } private void returnToParentFrame() { Loading core/java/com/android/internal/app/LocaleStore.java +4 −1 Original line number Diff line number Diff line Loading @@ -281,9 +281,12 @@ public class LocaleStore { * The "system default" is special case for per-app picker. Intentionally keep the locale * empty to let activity know "system default" been selected. */ public static LocaleInfo getSystemDefaultLocaleInfo() { public static LocaleInfo getSystemDefaultLocaleInfo(boolean hasAppLanguage) { LocaleInfo systemDefaultInfo = new LocaleInfo(""); systemDefaultInfo.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SYSTEM_LANGUAGE; if (hasAppLanguage) { systemDefaultInfo.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_CURRENT; } systemDefaultInfo.mIsTranslated = true; return systemDefaultInfo; } Loading core/java/com/android/internal/app/SuggestedLocaleAdapter.java +46 −21 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Filter; import android.widget.Filterable; import android.widget.FrameLayout; import android.widget.TextView; import com.android.internal.R; Loading Loading @@ -54,7 +55,11 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { private static final int TYPE_HEADER_ALL_OTHERS = 1; private static final int TYPE_LOCALE = 2; private static final int TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER = 3; private static final int TYPE_CURRENT_LOCALE = 4; private static final int MIN_REGIONS_FOR_SUGGESTIONS = 6; private static final int APP_LANGUAGE_PICKER_TYPE_COUNT = 5; private static final int SYSTEM_LANGUAGE_TYPE_COUNT = 3; private static final int SYSTEM_LANGUAGE_WITHOUT_HEADER_TYPE_COUNT = 1; private ArrayList<LocaleStore.LocaleInfo> mLocaleOptions; private ArrayList<LocaleStore.LocaleInfo> mOriginalLocaleOptions; Loading Loading @@ -93,7 +98,8 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { @Override public boolean isEnabled(int position) { return getItemViewType(position) == TYPE_LOCALE || getItemViewType(position) == TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER; || getItemViewType(position) == TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER || getItemViewType(position) == TYPE_CURRENT_LOCALE; } @Override Loading @@ -112,6 +118,9 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { if (item.isSystemLocale()) { return TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER; } if (item.isAppCurrentLocale()) { return TYPE_CURRENT_LOCALE; } return TYPE_LOCALE; } } Loading @@ -119,11 +128,13 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { @Override public int getViewTypeCount() { if (!TextUtils.isEmpty(mAppPackageName) && showHeaders()) { return 4; // Two headers and 1 for "System language" // Two headers, 1 "System language", 1 current locale return APP_LANGUAGE_PICKER_TYPE_COUNT; } else if (showHeaders()) { return 3; // Two headers in addition to the locales // Two headers in addition to the locales return SYSTEM_LANGUAGE_TYPE_COUNT; } else { return 1; // Locales items only return SYSTEM_LANGUAGE_WITHOUT_HEADER_TYPE_COUNT; // Locales items only } } Loading Loading @@ -204,12 +215,16 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { textView.setTextLocale( mDisplayLocale != null ? mDisplayLocale : Locale.getDefault()); break; case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER: if (!(convertView instanceof ViewGroup)) { if (((LocaleStore.LocaleInfo)getItem(position)).isAppCurrentLocale()) { convertView = mInflater.inflate( R.layout.app_language_picker_system_current, parent, false); } else { convertView = mInflater.inflate( R.layout.app_language_picker_system_default, parent, false); } } Locale defaultLocale = Locale.getDefault(); TextView title = convertView.findViewById(R.id.locale); Loading @@ -219,25 +234,20 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { subtitle.setText(defaultLocale.getDisplayName()); subtitle.setTextLocale(defaultLocale); break; case TYPE_CURRENT_LOCALE: if (!(convertView instanceof ViewGroup)) { convertView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); } updateTextView( convertView, convertView.findViewById(R.id.language_picker_item), position); break; default: // Covers both null, and "reusing" a wrong kind of view if (!(convertView instanceof ViewGroup)) { convertView = mInflater.inflate(R.layout.language_picker_item, parent, false); } TextView text = (TextView) convertView.findViewById(R.id.locale); LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); text.setText(item.getLabel(mCountryMode)); text.setTextLocale(item.getLocale()); text.setContentDescription(item.getContentDescription(mCountryMode)); if (mCountryMode) { int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent()); //noinspection ResourceType convertView.setLayoutDirection(layoutDir); text.setTextDirection(layoutDir == View.LAYOUT_DIRECTION_RTL ? View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR); } updateTextView(convertView, convertView.findViewById(R.id.locale), position); } return convertView; } Loading Loading @@ -348,4 +358,19 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { public Filter getFilter() { return new FilterByNativeAndUiNames(); } private void updateTextView(View convertView, TextView text, int position) { LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); text.setText(item.getLabel(mCountryMode)); text.setTextLocale(item.getLocale()); text.setContentDescription(item.getContentDescription(mCountryMode)); if (mCountryMode) { int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent()); //noinspection ResourceType convertView.setLayoutDirection(layoutDir); text.setTextDirection(layoutDir == View.LAYOUT_DIRECTION_RTL ? View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR); } } } core/res/res/drawable/ic_check_24dp.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <!-- ~ Copyright (C) 2022 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <path android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" android:fillColor="@android:color/white"/> </vector> core/res/res/layout/app_language_picker_current_locale_item.xml 0 → 100644 +44 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2022 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".8"> <include android:id="@+id/language_picker_item" layout="@layout/language_picker_item" /> </FrameLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".2" android:gravity="center" android:minHeight="?android:attr/listPreferredItemHeight"> <ImageView android:id="@+id/imageView" android:layout_width="24dp" android:layout_height="24dp" android:src="@drawable/ic_check_24dp" app:tint="#0F9D58"/> </LinearLayout> </LinearLayout> Loading
core/java/com/android/internal/app/LocalePickerWithRegion.java +5 −4 Original line number Diff line number Diff line Loading @@ -158,16 +158,17 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O if (appCurrentLocale != null && !isForCountryMode) { mLocaleList.add(appCurrentLocale); } filterTheLanguagesNotSupportedInApp(context, appPackageName); mLocaleList = filterTheLanguagesNotSupportedInApp(context, appPackageName); if (!isForCountryMode) { mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo()); mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo(appCurrentLocale == null)); } } return true; } private void filterTheLanguagesNotSupportedInApp(Context context, String appPackageName) { private Set<LocaleStore.LocaleInfo> filterTheLanguagesNotSupportedInApp( Context context, String appPackageName) { ArrayList<Locale> supportedLocales = AppLocaleStore.getAppSupportedLocales(context, appPackageName); Loading @@ -181,7 +182,7 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O } Log.d(TAG, "mLocaleList after app-supported filter: " + filteredList.size()); mLocaleList = filteredList; return filteredList; } private void returnToParentFrame() { Loading
core/java/com/android/internal/app/LocaleStore.java +4 −1 Original line number Diff line number Diff line Loading @@ -281,9 +281,12 @@ public class LocaleStore { * The "system default" is special case for per-app picker. Intentionally keep the locale * empty to let activity know "system default" been selected. */ public static LocaleInfo getSystemDefaultLocaleInfo() { public static LocaleInfo getSystemDefaultLocaleInfo(boolean hasAppLanguage) { LocaleInfo systemDefaultInfo = new LocaleInfo(""); systemDefaultInfo.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SYSTEM_LANGUAGE; if (hasAppLanguage) { systemDefaultInfo.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_CURRENT; } systemDefaultInfo.mIsTranslated = true; return systemDefaultInfo; } Loading
core/java/com/android/internal/app/SuggestedLocaleAdapter.java +46 −21 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Filter; import android.widget.Filterable; import android.widget.FrameLayout; import android.widget.TextView; import com.android.internal.R; Loading Loading @@ -54,7 +55,11 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { private static final int TYPE_HEADER_ALL_OTHERS = 1; private static final int TYPE_LOCALE = 2; private static final int TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER = 3; private static final int TYPE_CURRENT_LOCALE = 4; private static final int MIN_REGIONS_FOR_SUGGESTIONS = 6; private static final int APP_LANGUAGE_PICKER_TYPE_COUNT = 5; private static final int SYSTEM_LANGUAGE_TYPE_COUNT = 3; private static final int SYSTEM_LANGUAGE_WITHOUT_HEADER_TYPE_COUNT = 1; private ArrayList<LocaleStore.LocaleInfo> mLocaleOptions; private ArrayList<LocaleStore.LocaleInfo> mOriginalLocaleOptions; Loading Loading @@ -93,7 +98,8 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { @Override public boolean isEnabled(int position) { return getItemViewType(position) == TYPE_LOCALE || getItemViewType(position) == TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER; || getItemViewType(position) == TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER || getItemViewType(position) == TYPE_CURRENT_LOCALE; } @Override Loading @@ -112,6 +118,9 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { if (item.isSystemLocale()) { return TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER; } if (item.isAppCurrentLocale()) { return TYPE_CURRENT_LOCALE; } return TYPE_LOCALE; } } Loading @@ -119,11 +128,13 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { @Override public int getViewTypeCount() { if (!TextUtils.isEmpty(mAppPackageName) && showHeaders()) { return 4; // Two headers and 1 for "System language" // Two headers, 1 "System language", 1 current locale return APP_LANGUAGE_PICKER_TYPE_COUNT; } else if (showHeaders()) { return 3; // Two headers in addition to the locales // Two headers in addition to the locales return SYSTEM_LANGUAGE_TYPE_COUNT; } else { return 1; // Locales items only return SYSTEM_LANGUAGE_WITHOUT_HEADER_TYPE_COUNT; // Locales items only } } Loading Loading @@ -204,12 +215,16 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { textView.setTextLocale( mDisplayLocale != null ? mDisplayLocale : Locale.getDefault()); break; case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER: if (!(convertView instanceof ViewGroup)) { if (((LocaleStore.LocaleInfo)getItem(position)).isAppCurrentLocale()) { convertView = mInflater.inflate( R.layout.app_language_picker_system_current, parent, false); } else { convertView = mInflater.inflate( R.layout.app_language_picker_system_default, parent, false); } } Locale defaultLocale = Locale.getDefault(); TextView title = convertView.findViewById(R.id.locale); Loading @@ -219,25 +234,20 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { subtitle.setText(defaultLocale.getDisplayName()); subtitle.setTextLocale(defaultLocale); break; case TYPE_CURRENT_LOCALE: if (!(convertView instanceof ViewGroup)) { convertView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); } updateTextView( convertView, convertView.findViewById(R.id.language_picker_item), position); break; default: // Covers both null, and "reusing" a wrong kind of view if (!(convertView instanceof ViewGroup)) { convertView = mInflater.inflate(R.layout.language_picker_item, parent, false); } TextView text = (TextView) convertView.findViewById(R.id.locale); LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); text.setText(item.getLabel(mCountryMode)); text.setTextLocale(item.getLocale()); text.setContentDescription(item.getContentDescription(mCountryMode)); if (mCountryMode) { int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent()); //noinspection ResourceType convertView.setLayoutDirection(layoutDir); text.setTextDirection(layoutDir == View.LAYOUT_DIRECTION_RTL ? View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR); } updateTextView(convertView, convertView.findViewById(R.id.locale), position); } return convertView; } Loading Loading @@ -348,4 +358,19 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { public Filter getFilter() { return new FilterByNativeAndUiNames(); } private void updateTextView(View convertView, TextView text, int position) { LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); text.setText(item.getLabel(mCountryMode)); text.setTextLocale(item.getLocale()); text.setContentDescription(item.getContentDescription(mCountryMode)); if (mCountryMode) { int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent()); //noinspection ResourceType convertView.setLayoutDirection(layoutDir); text.setTextDirection(layoutDir == View.LAYOUT_DIRECTION_RTL ? View.TEXT_DIRECTION_RTL : View.TEXT_DIRECTION_LTR); } } }
core/res/res/drawable/ic_check_24dp.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <!-- ~ Copyright (C) 2022 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <path android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" android:fillColor="@android:color/white"/> </vector>
core/res/res/layout/app_language_picker_current_locale_item.xml 0 → 100644 +44 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2022 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".8"> <include android:id="@+id/language_picker_item" layout="@layout/language_picker_item" /> </FrameLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".2" android:gravity="center" android:minHeight="?android:attr/listPreferredItemHeight"> <ImageView android:id="@+id/imageView" android:layout_width="24dp" android:layout_height="24dp" android:src="@drawable/ic_check_24dp" app:tint="#0F9D58"/> </LinearLayout> </LinearLayout>