diff options
7 files changed, 172 insertions, 26 deletions
diff --git a/core/java/com/android/internal/app/LocalePickerWithRegion.java b/core/java/com/android/internal/app/LocalePickerWithRegion.java index 52c74cf81508..b81bd479c807 100644 --- a/core/java/com/android/internal/app/LocalePickerWithRegion.java +++ b/core/java/com/android/internal/app/LocalePickerWithRegion.java @@ -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); @@ -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() { diff --git a/core/java/com/android/internal/app/LocaleStore.java b/core/java/com/android/internal/app/LocaleStore.java index cea8eaa3ee7f..eb11b9b8b138 100644 --- a/core/java/com/android/internal/app/LocaleStore.java +++ b/core/java/com/android/internal/app/LocaleStore.java @@ -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; } diff --git a/core/java/com/android/internal/app/SuggestedLocaleAdapter.java b/core/java/com/android/internal/app/SuggestedLocaleAdapter.java index 2eb104ed215a..68b8968fe399 100644 --- a/core/java/com/android/internal/app/SuggestedLocaleAdapter.java +++ b/core/java/com/android/internal/app/SuggestedLocaleAdapter.java @@ -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; @@ -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; @@ -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 @@ -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; } } @@ -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 } } @@ -204,11 +215,15 @@ 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)) { - convertView = mInflater.inflate( - R.layout.app_language_picker_system_default, parent, false); + 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(); @@ -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; } @@ -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); + } + } } diff --git a/core/res/res/drawable/ic_check_24dp.xml b/core/res/res/drawable/ic_check_24dp.xml new file mode 100644 index 000000000000..a0e21ff2826e --- /dev/null +++ b/core/res/res/drawable/ic_check_24dp.xml @@ -0,0 +1,24 @@ +<!-- + ~ 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> diff --git a/core/res/res/layout/app_language_picker_current_locale_item.xml b/core/res/res/layout/app_language_picker_current_locale_item.xml new file mode 100644 index 000000000000..bf6d9639791a --- /dev/null +++ b/core/res/res/layout/app_language_picker_current_locale_item.xml @@ -0,0 +1,44 @@ +<?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> diff --git a/core/res/res/layout/app_language_picker_system_current.xml b/core/res/res/layout/app_language_picker_system_current.xml new file mode 100644 index 000000000000..341ee2528671 --- /dev/null +++ b/core/res/res/layout/app_language_picker_system_current.xml @@ -0,0 +1,45 @@ +<!-- + ~ 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/system_language_view" + layout="@layout/app_language_picker_system_default" /> + </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> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index dd69fa0bebb2..776d3dafe8c0 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -4754,7 +4754,11 @@ <java-symbol type="drawable" name="ic_swap_horiz" /> <java-symbol type="bool" name="config_notificationForceUserSetOnUpgrade" /> + <!-- For app language picker --> <java-symbol type="string" name="system_locale_title" /> <java-symbol type="layout" name="app_language_picker_system_default" /> + <java-symbol type="layout" name="app_language_picker_system_current" /> + <java-symbol type="layout" name="app_language_picker_current_locale_item" /> <java-symbol type="id" name="system_locale_subtitle" /> + <java-symbol type="id" name="language_picker_item" /> </resources> |