Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e506112 authored by Anna Zhuravleva's avatar Anna Zhuravleva Committed by Android (Google) Code Review
Browse files

Merge "Support selected item state in Bilingual Adapter."

parents b71dac75 ca257686
Loading
Loading
Loading
Loading
+58 −1
Original line number Diff line number Diff line
@@ -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<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) {
@@ -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) {
+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
+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
+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
+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