Loading core/java/com/android/internal/app/BilingualSuggestedLocaleAdapter.java +58 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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<LocaleStore.LocaleInfo> localeOptions, boolean countryMode, Locale secondaryLocale) { this(localeOptions, countryMode, secondaryLocale, false); } public BilingualSuggestedLocaleAdapter( Set<LocaleStore.LocaleInfo> localeOptions, boolean countryMode, Locale secondaryLocale, boolean showLastSelected) { super(localeOptions, countryMode); mSecondaryLocale = secondaryLocale; if (TextUtils.getLayoutDirectionFromLocale(secondaryLocale) == View.LAYOUT_DIRECTION_RTL) { Loading @@ -48,6 +60,7 @@ public class BilingualSuggestedLocaleAdapter extends SuggestedLocaleAdapter { } else { mSecondaryLocaleTextDir = View.TEXT_DIRECTION_LTR; } mShowSelection = showLastSelected; } @Override Loading Loading @@ -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) { Loading @@ -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) { Loading core/res/res/drawable/bilingual_language_item_selection_indicator.xml 0 → 100644 +7 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="@color/language_picker_item_selected_indicator" android:pathData="M9.55,18l-5.7,-5.7 1.425,-1.425L9.55,15.15l9.175,-9.175L20.15,7.4z"/> </vector> No newline at end of file core/res/res/drawable/language_picker_item_bg_selected.xml 0 → 100644 +17 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="-5dp" android:right="-5dp" android:top="-5dp"> <shape android:shape="rectangle" > <solid android:color="@color/language_picker_item_selected_bg" /> <stroke android:width="2dp" android:color="@color/language_picker_item_selected_stroke" /> </shape> </item> </layer-list> No newline at end of file core/res/res/drawable/language_picker_item_text_color2_selector.xml 0 → 100644 +6 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/language_picker_item_text_color_secondary_selected" /> <item android:color="@color/language_picker_item_text_color_secondary" /> </selector> No newline at end of file core/res/res/drawable/language_picker_item_text_color_selector.xml 0 → 100644 +6 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/language_picker_item_text_color_selected" /> <item android:color="@color/language_picker_item_text_color" /> </selector> No newline at end of file Loading
core/java/com/android/internal/app/BilingualSuggestedLocaleAdapter.java +58 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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<LocaleStore.LocaleInfo> localeOptions, boolean countryMode, Locale secondaryLocale) { this(localeOptions, countryMode, secondaryLocale, false); } public BilingualSuggestedLocaleAdapter( Set<LocaleStore.LocaleInfo> localeOptions, boolean countryMode, Locale secondaryLocale, boolean showLastSelected) { super(localeOptions, countryMode); mSecondaryLocale = secondaryLocale; if (TextUtils.getLayoutDirectionFromLocale(secondaryLocale) == View.LAYOUT_DIRECTION_RTL) { Loading @@ -48,6 +60,7 @@ public class BilingualSuggestedLocaleAdapter extends SuggestedLocaleAdapter { } else { mSecondaryLocaleTextDir = View.TEXT_DIRECTION_LTR; } mShowSelection = showLastSelected; } @Override Loading Loading @@ -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) { Loading @@ -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) { Loading
core/res/res/drawable/bilingual_language_item_selection_indicator.xml 0 → 100644 +7 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="@color/language_picker_item_selected_indicator" android:pathData="M9.55,18l-5.7,-5.7 1.425,-1.425L9.55,15.15l9.175,-9.175L20.15,7.4z"/> </vector> No newline at end of file
core/res/res/drawable/language_picker_item_bg_selected.xml 0 → 100644 +17 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:bottom="-5dp" android:right="-5dp" android:top="-5dp"> <shape android:shape="rectangle" > <solid android:color="@color/language_picker_item_selected_bg" /> <stroke android:width="2dp" android:color="@color/language_picker_item_selected_stroke" /> </shape> </item> </layer-list> No newline at end of file
core/res/res/drawable/language_picker_item_text_color2_selector.xml 0 → 100644 +6 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/language_picker_item_text_color_secondary_selected" /> <item android:color="@color/language_picker_item_text_color_secondary" /> </selector> No newline at end of file
core/res/res/drawable/language_picker_item_text_color_selector.xml 0 → 100644 +6 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/language_picker_item_text_color_selected" /> <item android:color="@color/language_picker_item_text_color" /> </selector> No newline at end of file