diff --git a/core/java/com/android/internal/app/BilingualSuggestedLocaleAdapter.java b/core/java/com/android/internal/app/BilingualSuggestedLocaleAdapter.java index d2cb30e2363e9..833d88c9350b1 100644 --- a/core/java/com/android/internal/app/BilingualSuggestedLocaleAdapter.java +++ b/core/java/com/android/internal/app/BilingualSuggestedLocaleAdapter.java @@ -20,6 +20,8 @@ import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import com.android.internal.R; @@ -36,11 +38,21 @@ public class BilingualSuggestedLocaleAdapter extends SuggestedLocaleAdapter { private final Locale mSecondaryLocale; private final int mSecondaryLocaleTextDir; + private final boolean mShowSelection; + private LocaleStore.LocaleInfo mSelectedLocaleInfo; public BilingualSuggestedLocaleAdapter( Set localeOptions, boolean countryMode, Locale secondaryLocale) { + this(localeOptions, countryMode, secondaryLocale, false); + } + + public BilingualSuggestedLocaleAdapter( + Set localeOptions, + boolean countryMode, + Locale secondaryLocale, + boolean showLastSelected) { super(localeOptions, countryMode); mSecondaryLocale = secondaryLocale; if (TextUtils.getLayoutDirectionFromLocale(secondaryLocale) == View.LAYOUT_DIRECTION_RTL) { @@ -48,6 +60,7 @@ public class BilingualSuggestedLocaleAdapter extends SuggestedLocaleAdapter { } else { mSecondaryLocaleTextDir = View.TEXT_DIRECTION_LTR; } + mShowSelection = showLastSelected; } @Override @@ -90,11 +103,55 @@ public class BilingualSuggestedLocaleAdapter extends SuggestedLocaleAdapter { } LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); + if (mShowSelection) { + setItemState(isSelectedLocaleInfo(item), convertView); + } setLocaleToListItem(convertView, item); } return convertView; } + /** + * Set locale info as selected. Selected info can be the only one. Passing null would result to + * nothing is selected. + */ + public void setSelectedLocaleInfo(LocaleStore.LocaleInfo info) { + mSelectedLocaleInfo = info; + notifyDataSetChanged(); + } + + /** Return selected locale info. */ + public LocaleStore.LocaleInfo getSelectedLocaleInfo() { + return mSelectedLocaleInfo; + } + + private boolean isSelectedLocaleInfo(LocaleStore.LocaleInfo item) { + return item != null + && mSelectedLocaleInfo != null + && item.getId().equals(mSelectedLocaleInfo.getId()); + } + + private void setItemState(boolean selected, View itemView) { + RelativeLayout background = (RelativeLayout) itemView; + ImageView indicator = itemView.findViewById(R.id.indicator); + TextView textNative = itemView.findViewById(R.id.locale_native); + TextView textSecondary = itemView.findViewById(R.id.locale_secondary); + + if (indicator == null || textNative == null || textSecondary == null) { + return; + } + + textNative.setSelected(selected); + textSecondary.setSelected(selected); + if (selected) { + background.setBackgroundResource(R.drawable.language_picker_item_bg_selected); + indicator.setVisibility(View.VISIBLE); + } else { + background.setBackgroundResource(0); + indicator.setVisibility(View.GONE); + } + } + private void setHeaderText( TextView textView, int languageStringResourceId, int regionStringResourceId) { if (mCountryMode) { @@ -114,7 +171,7 @@ public class BilingualSuggestedLocaleAdapter extends SuggestedLocaleAdapter { textNative.setTextLocale(localeInfo.getLocale()); textNative.setContentDescription(localeInfo.getContentDescription(mCountryMode)); - TextView textSecondary = (TextView) itemView.findViewById(R.id.locale_secondary); + TextView textSecondary = itemView.findViewById(R.id.locale_secondary); textSecondary.setText(localeInfo.getLocale().getDisplayLanguage(mSecondaryLocale)); textSecondary.setTextDirection(mSecondaryLocaleTextDir); if (mCountryMode) { diff --git a/core/res/res/drawable/bilingual_language_item_selection_indicator.xml b/core/res/res/drawable/bilingual_language_item_selection_indicator.xml new file mode 100644 index 0000000000000..78f26cc1dce43 --- /dev/null +++ b/core/res/res/drawable/bilingual_language_item_selection_indicator.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/core/res/res/drawable/language_picker_item_bg_selected.xml b/core/res/res/drawable/language_picker_item_bg_selected.xml new file mode 100644 index 0000000000000..ef9a8e78cd101 --- /dev/null +++ b/core/res/res/drawable/language_picker_item_bg_selected.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/res/res/drawable/language_picker_item_text_color2_selector.xml b/core/res/res/drawable/language_picker_item_text_color2_selector.xml new file mode 100644 index 0000000000000..624ae2924f950 --- /dev/null +++ b/core/res/res/drawable/language_picker_item_text_color2_selector.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/core/res/res/drawable/language_picker_item_text_color_selector.xml b/core/res/res/drawable/language_picker_item_text_color_selector.xml new file mode 100644 index 0000000000000..8d419f8f33260 --- /dev/null +++ b/core/res/res/drawable/language_picker_item_text_color_selector.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/core/res/res/layout/language_picker_bilingual_item.xml b/core/res/res/layout/language_picker_bilingual_item.xml index f56dda9fd1dbe..def0cccf38ae0 100644 --- a/core/res/res/layout/language_picker_bilingual_item.xml +++ b/core/res/res/layout/language_picker_bilingual_item.xml @@ -1,20 +1,27 @@ - + + + android:orientation="vertical" + > @@ -23,9 +30,20 @@ android:id="@+id/locale_secondary" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="@color/language_picker_item_text_color_secondary" + android:textColor="@drawable/language_picker_item_text_color2_selector" android:textSize="16sp" android:textAppearance="?android:attr/textAppearanceListItem" /> + - \ No newline at end of file + + \ No newline at end of file diff --git a/core/res/res/values-night/colors.xml b/core/res/res/values-night/colors.xml index 88171ce368f9f..d3f998fb70cf8 100644 --- a/core/res/res/values-night/colors.xml +++ b/core/res/res/values-night/colors.xml @@ -41,6 +41,11 @@ #F1F3F4 #BDC1C6 + #202124 + #202124 + #202124 + #92B3F2 + #185ABC #2E3132 diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml index 8b1b46d1b3969..77d7c43cd3d29 100644 --- a/core/res/res/values/colors.xml +++ b/core/res/res/values/colors.xml @@ -451,6 +451,11 @@ #202124 #5F6368 + #202124 + #5F6368 + #4285F4 + #E8F0FE + #4C8DF6 #F7F9FA diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 00dab0416af12..01c8e968194b0 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -97,10 +97,12 @@ + + @@ -3126,6 +3128,12 @@ + + + + + +