Add subtitle in System language
Bug: 223090003 Test: Check the UI in per-app language selection page Change-Id: I647f678016461b557e9f6d5de459fd2dee789b0d
This commit is contained in:
@@ -47,7 +47,7 @@ import java.util.Set;
|
||||
* default locale.</p>
|
||||
*/
|
||||
public class LocalePickerWithRegion extends ListFragment implements SearchView.OnQueryTextListener {
|
||||
private static final String TAG = LocalePickerWithRegion.class.getSimpleName();;
|
||||
private static final String TAG = LocalePickerWithRegion.class.getSimpleName();
|
||||
private static final String PARENT_FRAGMENT_NAME = "localeListEditor";
|
||||
|
||||
private SuggestedLocaleAdapter mAdapter;
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -54,6 +53,7 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
||||
private static final int TYPE_HEADER_SUGGESTED = 0;
|
||||
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 MIN_REGIONS_FOR_SUGGESTIONS = 6;
|
||||
|
||||
private ArrayList<LocaleStore.LocaleInfo> mLocaleOptions;
|
||||
@@ -67,6 +67,10 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
||||
private Context mContextOverride = null;
|
||||
private String mAppPackageName;
|
||||
|
||||
public SuggestedLocaleAdapter(Set<LocaleStore.LocaleInfo> localeOptions, boolean countryMode) {
|
||||
this(localeOptions, countryMode, null);
|
||||
}
|
||||
|
||||
public SuggestedLocaleAdapter(Set<LocaleStore.LocaleInfo> localeOptions, boolean countryMode,
|
||||
String appPackageName) {
|
||||
mCountryMode = countryMode;
|
||||
@@ -88,7 +92,8 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItemViewType(position) == TYPE_LOCALE;
|
||||
return getItemViewType(position) == TYPE_LOCALE
|
||||
|| getItemViewType(position) == TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,13 +107,20 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
||||
if (position == mSuggestionCount + 1) {
|
||||
return TYPE_HEADER_ALL_OTHERS;
|
||||
}
|
||||
|
||||
LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position);
|
||||
if (item.isSystemLocale()) {
|
||||
return TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER;
|
||||
}
|
||||
return TYPE_LOCALE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
if (showHeaders()) {
|
||||
if (!TextUtils.isEmpty(mAppPackageName) && showHeaders()) {
|
||||
return 4; // Two headers and 1 for "System language"
|
||||
} else if (showHeaders()) {
|
||||
return 3; // Two headers in addition to the locales
|
||||
} else {
|
||||
return 1; // Locales items only
|
||||
@@ -192,6 +204,21 @@ 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);
|
||||
}
|
||||
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
TextView title = convertView.findViewById(R.id.locale);
|
||||
title.setText(R.string.system_locale_title);
|
||||
title.setTextLocale(defaultLocale);
|
||||
TextView subtitle = convertView.findViewById(R.id.system_locale_subtitle);
|
||||
subtitle.setText(defaultLocale.getDisplayName());
|
||||
subtitle.setTextLocale(defaultLocale);
|
||||
break;
|
||||
default:
|
||||
// Covers both null, and "reusing" a wrong kind of view
|
||||
if (!(convertView instanceof ViewGroup)) {
|
||||
@@ -200,20 +227,11 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable {
|
||||
|
||||
TextView text = (TextView) convertView.findViewById(R.id.locale);
|
||||
LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position);
|
||||
Locale layoutLocale;
|
||||
if (item.isSystemLocale()) {
|
||||
// show system default option
|
||||
text.setText(R.string.system_locale_title);
|
||||
text.setTextLocale(Locale.getDefault());
|
||||
layoutLocale = Locale.getDefault();
|
||||
} else {
|
||||
text.setText(item.getLabel(mCountryMode));
|
||||
text.setTextLocale(item.getLocale());
|
||||
text.setContentDescription(item.getContentDescription(mCountryMode));
|
||||
layoutLocale = item.getParent();
|
||||
}
|
||||
text.setText(item.getLabel(mCountryMode));
|
||||
text.setTextLocale(item.getLocale());
|
||||
text.setContentDescription(item.getContentDescription(mCountryMode));
|
||||
if (mCountryMode) {
|
||||
int layoutDir = TextUtils.getLayoutDirectionFromLocale(layoutLocale);
|
||||
int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent());
|
||||
//noinspection ResourceType
|
||||
convertView.setLayoutDirection(layoutDir);
|
||||
text.setTextDirection(layoutDir == View.LAYOUT_DIRECTION_RTL
|
||||
|
||||
42
core/res/res/layout/app_language_picker_system_default.xml
Normal file
42
core/res/res/layout/app_language_picker_system_default.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<!--
|
||||
~ 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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="8dp">
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/locale"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:textDirection="locale"
|
||||
android:layoutDirection="locale"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/system_locale_subtitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
@@ -4773,4 +4773,6 @@
|
||||
<java-symbol type="bool" name="config_notificationForceUserSetOnUpgrade" />
|
||||
|
||||
<java-symbol type="string" name="system_locale_title" />
|
||||
<java-symbol type="layout" name="app_language_picker_system_default" />
|
||||
<java-symbol type="id" name="system_locale_subtitle" />
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user