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

Commit 6b896df3 authored by David Liu's avatar David Liu
Browse files

[Settingslib] Add SettingsSpinner item selected highlight

Bug: 394697765, 396786547
Test: manul
Flag: com.android.settingslib.widget.theme.flags.is_expressive_design_enabled
Change-Id: I319c254d47ad37ffbad65182daf12fcf4b71883c
parent dd1064d1
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -14,10 +14,8 @@
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Highlight the selected item -->
  <item android:state_activated="true" android:color="@color/settingslib_materialColorPrimaryContainer"/>
  <!-- default color for other states -->
  <item android:color="@color/settingslib_materialColorSurfaceContainerLow"/>
    <item android:state_activated="true" android:drawable="@drawable/settings_expressive_spinner_dropdown_item_selected"/>
</selector>
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2025 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
  <item>
    <shape android:shape="rectangle">
      <solid
          android:color="@color/settingslib_materialColorPrimaryContainer" />
      <corners
          android:radius="@dimen/settingslib_expressive_radius_large2" />
    </shape>
  </item>
</ripple>
+21 −6
Original line number Diff line number Diff line
@@ -11,11 +11,26 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/SettingsSpinnerDropdown.Expressive">
  <ImageView
      android:id="@android:id/icon"
      android:layout_width="@dimen/settingslib_expressive_space_small3"
      android:layout_height="@dimen/settingslib_expressive_space_small3"
      android:importantForAccessibility="no"
      android:src="@drawable/settingslib_expressive_icon_check"
      android:tint="@color/settingslib_spinner_dropdown_color"
      android:layout_gravity="center_vertical"
      android:layout_marginEnd="@dimen/settingslib_expressive_space_extrasmall4"
      android:scaleType="centerInside"/>

  <TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@android:id/text1"
    style="@style/SettingsSpinnerDropdown.Expressive"
      style="@style/SettingsSpinnerDropdownText"
      android:gravity="center_vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:filterTouchesWhenObscured="true"/>
</LinearLayout>
+15 −6
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2025 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<resources>
    <style name="SettingsSpinnerTitleBar.Expressive">
        <item name="android:textAppearance">@style/TextAppearance.SettingsLib.LabelLarge</item>
@@ -21,22 +25,27 @@
        <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small1</item>
        <item name="android:paddingVertical">@dimen/settingslib_expressive_space_extrasmall5</item>
    </style>

    <style name="SettingsSpinnerTitleBar.Expressive.Large">
        <item name="android:textAppearance">@style/TextAppearance.SettingsLib.TitleMedium</item>
        <item name="android:minHeight">@dimen/settingslib_expressive_space_medium5</item>
        <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small4</item>
        <item name="android:paddingVertical">@dimen/settingslib_expressive_space_small1</item>
    </style>

    <style name="SettingsSpinnerDropdown.Expressive">
        <item name="android:background">@drawable/settings_expressive_spinner_dropdown_background</item>
        <item name="android:minHeight">@dimen/spinner_dropdown_height</item>
        <item name="android:paddingStart">@dimen/settingslib_expressive_space_extrasmall4</item>
        <item name="android:paddingEnd">@dimen/settingslib_expressive_space_extrasmall4</item>
        <item name="android:paddingTop">@dimen/settingslib_expressive_space_extrasmall7</item>
        <item name="android:paddingBottom">@dimen/settingslib_expressive_space_extrasmall7</item>
    </style>

    <style name="SettingsSpinnerDropdownText">
        <item name="android:textAppearance">@style/TextAppearance.SettingsLib.LabelLarge</item>
        <item name="android:textColor">@color/settingslib_spinner_dropdown_color</item>
        <item name="android:background">@color/settingslib_spinner_dropdown_item_bg_color</item>
        <item name="android:maxLines">1</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:minHeight">@dimen/spinner_dropdown_height</item>
        <item name="android:paddingStart">@dimen/settingslib_expressive_space_small1</item>
        <item name="android:paddingEnd">@dimen/settingslib_expressive_space_small1</item>
        <item name="android:paddingTop">@dimen/settingslib_expressive_space_extrasmall4</item>
        <item name="android:paddingBottom">@dimen/settingslib_expressive_space_extrasmall4</item>
    </style>
</resources>
+28 −0
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.settingslib.widget.SettingsSpinnerPreference.Style;
import com.android.settingslib.widget.spinner.R;

@@ -38,6 +42,7 @@ public class SettingsSpinnerAdapter<T> extends ArrayAdapter<T> {
    private static final int DEFAULT_EXPRESSIVE_DROPDOWN_RESOURCE =
            R.layout.settings_expressvie_spinner_dropdown_view;
    private final LayoutInflater mDefaultInflater;
    private int mSelectedPosition = -1;

    /**
     * Constructs a new SettingsSpinnerAdapter with the given context.
@@ -53,6 +58,29 @@ public class SettingsSpinnerAdapter<T> extends ArrayAdapter<T> {
        mDefaultInflater = LayoutInflater.from(context);
    }

    @Override
    public View getDropDownView(
            int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view;
        if (convertView == null) {
            view =
                    mDefaultInflater.inflate(
                            getDropdownResource(getContext()), parent, false /* attachToRoot */);
        } else {
            view = convertView;
        }
        TextView textView = view.findViewById(android.R.id.text1);
        ImageView iconView = view.findViewById(android.R.id.icon);
        iconView.setVisibility((position == mSelectedPosition) ? View.VISIBLE : View.GONE);
        String item = (String) getItem(position);
        textView.setText(item);
        return view;
    }

    public void setSelectedPosition(int pos) {
        mSelectedPosition = pos;
    }

    public SettingsSpinnerAdapter(Context context, SettingsSpinnerPreference.Style style) {
        super(context, getDefaultResource(context, style));

Loading