summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorCalvin Pan <calvinpan@google.com>2022-03-17 09:20:44 +0800
committerCalvin Pan <calvinpan@google.com>2022-03-21 23:43:02 +0800
commit969826576acda10d5e975e15d3322085dc6c1b0e (patch)
tree5c27d654cd6e98460ffddad7c9fa3e4af2076f93 /core/java
parent780ff7127a5d7b47c3346a33dc601a456b2efccb (diff)
Add subtitle in System language
Bug: 223090003 Test: Check the UI in per-app language selection page Change-Id: I647f678016461b557e9f6d5de459fd2dee789b0d
Diffstat (limited to 'core/java')
-rw-r--r--core/java/com/android/internal/app/LocalePickerWithRegion.java2
-rw-r--r--core/java/com/android/internal/app/SuggestedLocaleAdapter.java50
2 files changed, 35 insertions, 17 deletions
diff --git a/core/java/com/android/internal/app/LocalePickerWithRegion.java b/core/java/com/android/internal/app/LocalePickerWithRegion.java
index e5b33f9abd83..e7cb43e019ad 100644
--- a/core/java/com/android/internal/app/LocalePickerWithRegion.java
+++ b/core/java/com/android/internal/app/LocalePickerWithRegion.java
@@ -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;
diff --git a/core/java/com/android/internal/app/SuggestedLocaleAdapter.java b/core/java/com/android/internal/app/SuggestedLocaleAdapter.java
index 10855f488940..c3e7920ffc08 100644
--- a/core/java/com/android/internal/app/SuggestedLocaleAdapter.java
+++ b/core/java/com/android/internal/app/SuggestedLocaleAdapter.java
@@ -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