Commit 8832352f authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android] ChipView applies state changes to sub labels

The chip view needs to react to certain state changes with changed text
colors. Since the secondary label is added lazily, it needs to check for
these states explicitly.

Once views that are part of the hierarchy they will receive most of the
state changes (e.g. a setSelected on ChipView will apply to both
TextViews).
For some reason, setEnabled wasn't applied to children by default but it
is strictly necessary in order to automatically select the correct text
appearance.

Additional fix: ensure there is an appropriate disabled state color.
Screenshots are in the linked bug.

Bug: 989960
Change-Id: Ic63d09f22c22af485d060d03d6ba6c20ef233bf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771613
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691070}
parent 40c1badd
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="@dimen/default_disabled_alpha"
android:color="@color/chip_text_color_selected"
android:state_selected="true" android:state_enabled="false"/>
<item android:alpha="@dimen/default_disabled_alpha"
android:color="@color/chip_text_color_default" android:state_enabled="false" />
<item android:color="@color/chip_text_color_selected" android:state_selected="true" /> <item android:color="@color/chip_text_color_selected" android:state_selected="true" />
<item android:color="@color/chip_text_color_default" /> <item android:color="@color/chip_text_color_default" />
</selector> </selector>
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
--> -->
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="@dimen/default_disabled_alpha"
android:color="@color/chip_text_color_selected"
android:state_selected="true" android:state_enabled="false" />
<item android:alpha="@dimen/default_disabled_alpha"
android:color="@color/chip_text_color_secondary_default" android:state_enabled="false" />
<item android:color="@color/chip_text_color_selected" android:state_selected="true" /> <item android:color="@color/chip_text_color_selected" android:state_selected="true" />
<item android:color="@color/chip_text_color_secondary_default" /> <item android:color="@color/chip_text_color_secondary_default" />
</selector> </selector>
...@@ -99,6 +99,18 @@ public class ChipView extends LinearLayout { ...@@ -99,6 +99,18 @@ public class ChipView extends LinearLayout {
} }
} }
/**
* Unlike setSelected, setEnabled doesn't properly propagate the new state to its subcomponents.
* Enforce this so ColorStateLists used for the text appearance apply as intended.
* @param enabled The new enabled state for the chip view and the TextViews owned by it.
*/
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
getPrimaryTextView().setEnabled(enabled);
if (mSecondaryText != null) mSecondaryText.setEnabled(enabled);
}
/** /**
* Sets the icon at the start of the chip view. * Sets the icon at the start of the chip view.
* @param icon The resource id pointing to the icon. * @param icon The resource id pointing to the icon.
...@@ -142,6 +154,10 @@ public class ChipView extends LinearLayout { ...@@ -142,6 +154,10 @@ public class ChipView extends LinearLayout {
mSecondaryText = mSecondaryText =
new TextView(new ContextThemeWrapper(getContext(), R.style.ChipTextView)); new TextView(new ContextThemeWrapper(getContext(), R.style.ChipTextView));
ApiCompatibilityUtils.setTextAppearance(mSecondaryText, mSecondaryTextAppearanceId); ApiCompatibilityUtils.setTextAppearance(mSecondaryText, mSecondaryTextAppearanceId);
// Ensure that basic state changes are aligned with the ChipView. They update
// automatically once the view is part of the hierarchy.
mSecondaryText.setSelected(isSelected());
mSecondaryText.setEnabled(isEnabled());
addView(mSecondaryText); addView(mSecondaryText);
} }
return mSecondaryText; return mSecondaryText;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment