Add hover and pressed states to notification expand button
Fixes: 283804869 Test: manual Change-Id: I3c1959579f06575ca70e1cf95e24e5721e11fb06
This commit is contained in:
@@ -21,6 +21,8 @@ import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.RemotableViewMethod;
|
||||
import android.view.View;
|
||||
@@ -42,7 +44,7 @@ import java.util.Locale;
|
||||
@RemoteViews.RemoteView
|
||||
public class NotificationExpandButton extends FrameLayout {
|
||||
|
||||
private View mPillView;
|
||||
private Drawable mPillDrawable;
|
||||
private TextView mNumberView;
|
||||
private ImageView mIconView;
|
||||
private boolean mExpanded;
|
||||
@@ -73,7 +75,10 @@ public class NotificationExpandButton extends FrameLayout {
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mPillView = findViewById(R.id.expand_button_pill);
|
||||
|
||||
final View pillView = findViewById(R.id.expand_button_pill);
|
||||
final LayerDrawable layeredPill = (LayerDrawable) pillView.getBackground();
|
||||
mPillDrawable = layeredPill.findDrawableByLayerId(R.id.expand_button_pill_colorized_layer);
|
||||
mNumberView = findViewById(R.id.expand_button_number);
|
||||
mIconView = findViewById(R.id.expand_button_icon);
|
||||
}
|
||||
@@ -156,7 +161,7 @@ public class NotificationExpandButton extends FrameLayout {
|
||||
private void updateColors() {
|
||||
if (shouldShowNumber()) {
|
||||
if (mHighlightPillColor != 0) {
|
||||
mPillView.setBackgroundTintList(ColorStateList.valueOf(mHighlightPillColor));
|
||||
mPillDrawable.setTintList(ColorStateList.valueOf(mHighlightPillColor));
|
||||
}
|
||||
mIconView.setColorFilter(mHighlightTextColor);
|
||||
if (mHighlightTextColor != 0) {
|
||||
@@ -164,7 +169,7 @@ public class NotificationExpandButton extends FrameLayout {
|
||||
}
|
||||
} else {
|
||||
if (mDefaultPillColor != 0) {
|
||||
mPillView.setBackgroundTintList(ColorStateList.valueOf(mDefaultPillColor));
|
||||
mPillDrawable.setTintList(ColorStateList.valueOf(mDefaultPillColor));
|
||||
}
|
||||
mIconView.setColorFilter(mDefaultTextColor);
|
||||
if (mDefaultTextColor != 0) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
~ Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:color="@android:color/system_on_surface_dark" android:alpha="0.06"/>
|
||||
<item android:state_hovered="true" android:color="@android:color/system_on_surface_dark" android:alpha="0.03"/>
|
||||
<item android:color="@android:color/system_on_surface_dark" android:alpha="0.00"/>
|
||||
</selector>
|
||||
21
core/res/res/color/notification_expand_button_state_tint.xml
Normal file
21
core/res/res/color/notification_expand_button_state_tint.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
~ Copyright (C) 2023 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:color="@android:color/system_on_surface_light" android:alpha="0.12"/>
|
||||
<item android:state_hovered="true" android:color="@android:color/system_on_surface_light" android:alpha="0.08"/>
|
||||
<item android:color="@android:color/system_on_surface_light" android:alpha="0.00"/>
|
||||
</selector>
|
||||
@@ -13,7 +13,17 @@
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="@dimen/notification_expand_button_pill_height" />
|
||||
<solid android:color="@android:color/white" />
|
||||
</shape>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/expand_button_pill_colorized_layer">
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="@dimen/notification_expand_button_pill_height" />
|
||||
<solid android:color="@android:color/white" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="@dimen/notification_expand_button_pill_height" />
|
||||
<solid android:color="@color/notification_expand_button_state_tint" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -34,6 +34,7 @@
|
||||
android:background="@drawable/expand_button_pill_bg"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:duplicateParentState="true"
|
||||
>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -3050,6 +3050,7 @@
|
||||
<java-symbol type="id" name="header_text_secondary" />
|
||||
<java-symbol type="id" name="expand_button" />
|
||||
<java-symbol type="id" name="expand_button_pill" />
|
||||
<java-symbol type="id" name="expand_button_pill_colorized_layer" />
|
||||
<java-symbol type="id" name="expand_button_number" />
|
||||
<java-symbol type="id" name="expand_button_icon" />
|
||||
<java-symbol type="id" name="alternate_expand_target" />
|
||||
|
||||
Reference in New Issue
Block a user