Loading core/java/com/android/internal/app/SuggestedLocaleAdapter.java +68 −25 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.LinearLayout; import android.widget.TextView; import com.android.internal.R; Loading Loading @@ -104,6 +105,13 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { @Override public int getItemViewType(int position) { if (!showHeaders()) { LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); if (item.isSystemLocale()) { return TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER; } if (item.isAppCurrentLocale()) { return TYPE_CURRENT_LOCALE; } return TYPE_LOCALE; } else { if (position == 0) { Loading Loading @@ -193,15 +201,11 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { } int itemType = getItemViewType(position); View itemView = getNewViewIfNeeded(convertView, parent, itemType, position); switch (itemType) { case TYPE_HEADER_SUGGESTED: // intentional fallthrough case TYPE_HEADER_ALL_OTHERS: // Covers both null, and "reusing" a wrong kind of view if (!(convertView instanceof TextView)) { convertView = mInflater.inflate(R.layout.language_picker_section_header, parent, false); } TextView textView = (TextView) convertView; TextView textView = (TextView) itemView; if (itemType == TYPE_HEADER_SUGGESTED) { setTextTo(textView, R.string.language_picker_section_suggested); } else { Loading @@ -215,38 +219,77 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { mDisplayLocale != null ? mDisplayLocale : Locale.getDefault()); break; case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER: if (!(convertView instanceof ViewGroup)) { TextView title; if (((LocaleStore.LocaleInfo)getItem(position)).isAppCurrentLocale()) { convertView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); title = convertView.findViewById(R.id.language_picker_item); title = itemView.findViewById(R.id.language_picker_item); } else { title = itemView.findViewById(R.id.locale); } title.setText(R.string.system_locale_title); break; case TYPE_CURRENT_LOCALE: updateTextView(itemView, itemView.findViewById(R.id.language_picker_item), position); break; default: updateTextView(itemView, itemView.findViewById(R.id.locale), position); break; } return itemView; } /** Check if the old view can be reused, otherwise create a new one. */ private View getNewViewIfNeeded( View convertView, ViewGroup parent, int itemType, int position) { View updatedView = convertView; boolean shouldReuseView; switch (itemType) { case TYPE_HEADER_SUGGESTED: // intentional fallthrough case TYPE_HEADER_ALL_OTHERS: shouldReuseView = convertView instanceof TextView && convertView.findViewById(R.id.language_picker_header) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.language_picker_section_header, parent, false); } break; case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER: if (((LocaleStore.LocaleInfo) getItem(position)).isAppCurrentLocale()) { shouldReuseView = convertView instanceof LinearLayout && convertView.findViewById(R.id.language_picker_item) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); addStateDescriptionIntoCurrentLocaleItem(convertView); } } else { convertView = mInflater.inflate( shouldReuseView = convertView instanceof TextView && convertView.findViewById(R.id.locale) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.language_picker_item, parent, false); title = convertView.findViewById(R.id.locale); } title.setText(R.string.system_locale_title); } break; case TYPE_CURRENT_LOCALE: if (!(convertView instanceof ViewGroup)) { convertView = mInflater.inflate( shouldReuseView = convertView instanceof LinearLayout && convertView.findViewById(R.id.language_picker_item) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); addStateDescriptionIntoCurrentLocaleItem(convertView); } 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); shouldReuseView = convertView instanceof TextView && convertView.findViewById(R.id.locale) != null; if (!shouldReuseView) { updatedView = mInflater.inflate(R.layout.language_picker_item, parent, false); } updateTextView(convertView, convertView.findViewById(R.id.locale), position); break; } return convertView; return updatedView; } private boolean showHeaders() { Loading core/res/res/layout/language_picker_section_header.xml +1 −0 Original line number Diff line number Diff line Loading @@ -24,4 +24,5 @@ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:textColor="?android:attr/colorAccent" android:textStyle="bold" android:id="@+id/language_picker_header" tools:text="@string/language_picker_section_all"/> core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -4791,6 +4791,7 @@ <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" /> <java-symbol type="id" name="language_picker_header" /> <java-symbol type="dimen" name="status_bar_height_default" /> </resources> Loading
core/java/com/android/internal/app/SuggestedLocaleAdapter.java +68 −25 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.LinearLayout; import android.widget.TextView; import com.android.internal.R; Loading Loading @@ -104,6 +105,13 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { @Override public int getItemViewType(int position) { if (!showHeaders()) { LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); if (item.isSystemLocale()) { return TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER; } if (item.isAppCurrentLocale()) { return TYPE_CURRENT_LOCALE; } return TYPE_LOCALE; } else { if (position == 0) { Loading Loading @@ -193,15 +201,11 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { } int itemType = getItemViewType(position); View itemView = getNewViewIfNeeded(convertView, parent, itemType, position); switch (itemType) { case TYPE_HEADER_SUGGESTED: // intentional fallthrough case TYPE_HEADER_ALL_OTHERS: // Covers both null, and "reusing" a wrong kind of view if (!(convertView instanceof TextView)) { convertView = mInflater.inflate(R.layout.language_picker_section_header, parent, false); } TextView textView = (TextView) convertView; TextView textView = (TextView) itemView; if (itemType == TYPE_HEADER_SUGGESTED) { setTextTo(textView, R.string.language_picker_section_suggested); } else { Loading @@ -215,38 +219,77 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { mDisplayLocale != null ? mDisplayLocale : Locale.getDefault()); break; case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER: if (!(convertView instanceof ViewGroup)) { TextView title; if (((LocaleStore.LocaleInfo)getItem(position)).isAppCurrentLocale()) { convertView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); title = convertView.findViewById(R.id.language_picker_item); title = itemView.findViewById(R.id.language_picker_item); } else { title = itemView.findViewById(R.id.locale); } title.setText(R.string.system_locale_title); break; case TYPE_CURRENT_LOCALE: updateTextView(itemView, itemView.findViewById(R.id.language_picker_item), position); break; default: updateTextView(itemView, itemView.findViewById(R.id.locale), position); break; } return itemView; } /** Check if the old view can be reused, otherwise create a new one. */ private View getNewViewIfNeeded( View convertView, ViewGroup parent, int itemType, int position) { View updatedView = convertView; boolean shouldReuseView; switch (itemType) { case TYPE_HEADER_SUGGESTED: // intentional fallthrough case TYPE_HEADER_ALL_OTHERS: shouldReuseView = convertView instanceof TextView && convertView.findViewById(R.id.language_picker_header) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.language_picker_section_header, parent, false); } break; case TYPE_SYSTEM_LANGUAGE_FOR_APP_LANGUAGE_PICKER: if (((LocaleStore.LocaleInfo) getItem(position)).isAppCurrentLocale()) { shouldReuseView = convertView instanceof LinearLayout && convertView.findViewById(R.id.language_picker_item) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); addStateDescriptionIntoCurrentLocaleItem(convertView); } } else { convertView = mInflater.inflate( shouldReuseView = convertView instanceof TextView && convertView.findViewById(R.id.locale) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.language_picker_item, parent, false); title = convertView.findViewById(R.id.locale); } title.setText(R.string.system_locale_title); } break; case TYPE_CURRENT_LOCALE: if (!(convertView instanceof ViewGroup)) { convertView = mInflater.inflate( shouldReuseView = convertView instanceof LinearLayout && convertView.findViewById(R.id.language_picker_item) != null; if (!shouldReuseView) { updatedView = mInflater.inflate( R.layout.app_language_picker_current_locale_item, parent, false); addStateDescriptionIntoCurrentLocaleItem(convertView); } 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); shouldReuseView = convertView instanceof TextView && convertView.findViewById(R.id.locale) != null; if (!shouldReuseView) { updatedView = mInflater.inflate(R.layout.language_picker_item, parent, false); } updateTextView(convertView, convertView.findViewById(R.id.locale), position); break; } return convertView; return updatedView; } private boolean showHeaders() { Loading
core/res/res/layout/language_picker_section_header.xml +1 −0 Original line number Diff line number Diff line Loading @@ -24,4 +24,5 @@ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:textColor="?android:attr/colorAccent" android:textStyle="bold" android:id="@+id/language_picker_header" tools:text="@string/language_picker_section_all"/>
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -4791,6 +4791,7 @@ <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" /> <java-symbol type="id" name="language_picker_header" /> <java-symbol type="dimen" name="status_bar_height_default" /> </resources>