Update pointer fill option backgrounds for color contrast and touch

target size.

Fix: 374885995
Fix: 374886964
Test: Manual.
Flag: EXEMPT Bugfix.
Change-Id: Ibf09bfae4a93868ac3605748854ccaaa10847eb6
This commit is contained in:
Pat Manning
2024-12-03 13:56:28 +00:00
parent 554684444a
commit b50acbfeea
7 changed files with 304 additions and 139 deletions

View File

@@ -14,15 +14,217 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="@dimen/pointer_fill_style_circle_offset"
android:insetLeft="@dimen/pointer_fill_style_circle_offset"
android:insetRight="@dimen/pointer_fill_style_circle_offset"
android:insetTop="@dimen/pointer_fill_style_circle_offset">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" >
<item
android:state_hovered="true"
android:state_selected="true">
<layer-list>
<item
android:top="@dimen/pointer_fill_style_circle_background_outline_offset"
android:left="@dimen/pointer_fill_style_circle_background_outline_offset"
android:bottom="@dimen/pointer_fill_style_circle_background_outline_offset"
android:right="@dimen/pointer_fill_style_circle_background_outline_offset">
<shape android:shape="rectangle">
<corners
android:radius="@dimen/pointer_fill_style_circle_background_corner_radius" />
<size
android:width="@dimen/pointer_fill_style_circle_background_outer_diameter_less_stroke"
android:height="@dimen/pointer_fill_style_circle_background_outer_diameter_less_stroke" />
<stroke
android:width="@dimen/pointer_fill_style_circle_background_selected_outline_stroke"
android:color="@androidprv:color/materialColorSecondary" />
</shape>
</item>
<item
android:top="@dimen/pointer_fill_style_circle_background_offset"
android:left="@dimen/pointer_fill_style_circle_background_offset"
android:bottom="@dimen/pointer_fill_style_circle_background_offset"
android:right="@dimen/pointer_fill_style_circle_background_offset">
<shape android:shape="rectangle">
<corners android:radius="@dimen/pointer_fill_style_circle_background_corner_inner_radius" />
<size
android:width="@dimen/pointer_fill_style_circle_background_outer_diameter_selected"
android:height="@dimen/pointer_fill_style_circle_background_outer_diameter_selected" />
<solid
android:color="@color/pointer_fill_hovered_color" />
</shape>
</item>
<item
android:id="@+id/tintableCircleHoveredSelected"
android:top="@dimen/pointer_fill_style_circle_offset_selected"
android:left="@dimen/pointer_fill_style_circle_offset_selected"
android:bottom="@dimen/pointer_fill_style_circle_offset_selected"
android:right="@dimen/pointer_fill_style_circle_offset_selected">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_inner_diameter"
android:height="@dimen/pointer_fill_style_circle_inner_diameter" />
android:width="@dimen/pointer_fill_style_circle_diameter"
android:height="@dimen/pointer_fill_style_circle_diameter" />
<solid android:color="@android:color/white" />
</shape>
</inset>
</item>
<item
android:top="@dimen/pointer_fill_style_circle_outline_offset_selected"
android:left="@dimen/pointer_fill_style_circle_outline_offset_selected"
android:bottom="@dimen/pointer_fill_style_circle_outline_offset_selected"
android:right="@dimen/pointer_fill_style_circle_outline_offset_selected">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_outline_diameter"
android:height="@dimen/pointer_fill_style_circle_outline_diameter" />
<stroke
android:width="@dimen/pointer_fill_style_circle_outline_stroke"
android:color="@android:color/white" />
</shape>
</item>
<item android:gravity="center"
android:width="@dimen/pointer_fill_style_checkmark_size"
android:height="@dimen/pointer_fill_style_checkmark_size"
android:drawable="@drawable/pointer_fill_check_24dp" />
</layer-list>
</item>
<item android:state_selected="true">
<layer-list>
<item
android:top="@dimen/pointer_fill_style_circle_background_outline_offset"
android:left="@dimen/pointer_fill_style_circle_background_outline_offset"
android:bottom="@dimen/pointer_fill_style_circle_background_outline_offset"
android:right="@dimen/pointer_fill_style_circle_background_outline_offset">
<shape android:shape="rectangle">
<corners android:radius="@dimen/pointer_fill_style_circle_background_corner_radius" />
<size
android:width="@dimen/pointer_fill_style_circle_background_outer_diameter_less_stroke"
android:height="@dimen/pointer_fill_style_circle_background_outer_diameter_less_stroke" />
<stroke
android:width="@dimen/pointer_fill_style_circle_background_selected_outline_stroke"
android:color="@androidprv:color/materialColorSecondary" />
</shape>
</item>
<item
android:top="@dimen/pointer_fill_style_circle_background_offset"
android:left="@dimen/pointer_fill_style_circle_background_offset"
android:bottom="@dimen/pointer_fill_style_circle_background_offset"
android:right="@dimen/pointer_fill_style_circle_background_offset">
<shape android:shape="rectangle">
<corners android:radius="@dimen/pointer_fill_style_circle_background_corner_inner_radius" />
<size
android:width="@dimen/pointer_fill_style_circle_background_outer_diameter_selected"
android:height="@dimen/pointer_fill_style_circle_background_outer_diameter_selected" />
<solid android:color="@androidprv:color/materialColorSurfaceBright" />
</shape>
</item>
<item
android:id="@+id/tintableCircleSelected"
android:top="@dimen/pointer_fill_style_circle_offset_selected"
android:left="@dimen/pointer_fill_style_circle_offset_selected"
android:bottom="@dimen/pointer_fill_style_circle_offset_selected"
android:right="@dimen/pointer_fill_style_circle_offset_selected">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_diameter"
android:height="@dimen/pointer_fill_style_circle_diameter" />
<solid android:color="@android:color/white" />
</shape>
</item>
<item
android:top="@dimen/pointer_fill_style_circle_outline_offset_selected"
android:left="@dimen/pointer_fill_style_circle_outline_offset_selected"
android:bottom="@dimen/pointer_fill_style_circle_outline_offset_selected"
android:right="@dimen/pointer_fill_style_circle_outline_offset_selected">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_outline_diameter"
android:height="@dimen/pointer_fill_style_circle_outline_diameter" />
<stroke
android:width="@dimen/pointer_fill_style_circle_outline_stroke"
android:color="@android:color/white" />
</shape>
</item>
<item
android:gravity="center"
android:width="@dimen/pointer_fill_style_checkmark_size"
android:height="@dimen/pointer_fill_style_checkmark_size"
android:drawable="@drawable/pointer_fill_check_24dp" />
</layer-list>
</item>
<item android:state_hovered="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/pointer_fill_style_circle_background_corner_radius" />
<size
android:width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:height="@dimen/pointer_fill_style_circle_background_outer_diameter" />
<solid android:color="@color/pointer_fill_hovered_color" />
</shape>
</item>
<item
android:id="@+id/tintableCircleHovered"
android:top="@dimen/pointer_fill_style_circle_offset"
android:left="@dimen/pointer_fill_style_circle_offset"
android:bottom="@dimen/pointer_fill_style_circle_offset"
android:right="@dimen/pointer_fill_style_circle_offset">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_diameter"
android:height="@dimen/pointer_fill_style_circle_diameter" />
<solid android:color="@android:color/white" />
</shape>
</item>
<item
android:top="@dimen/pointer_fill_style_circle_outline_offset"
android:left="@dimen/pointer_fill_style_circle_outline_offset"
android:bottom="@dimen/pointer_fill_style_circle_outline_offset"
android:right="@dimen/pointer_fill_style_circle_outline_offset">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_outline_diameter"
android:height="@dimen/pointer_fill_style_circle_outline_diameter" />
<stroke
android:width="@dimen/pointer_fill_style_circle_outline_stroke"
android:color="@android:color/white" />
</shape>
</item>
</layer-list>
</item>
<item><!-- default state -->
<layer-list>
<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/pointer_fill_style_circle_background_corner_radius" />
<size
android:width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:height="@dimen/pointer_fill_style_circle_background_outer_diameter" />
<solid android:color="@androidprv:color/materialColorSurfaceBright" />
</shape>
</item>
<item
android:id="@+id/tintableCircleDefault"
android:top="@dimen/pointer_fill_style_circle_offset"
android:left="@dimen/pointer_fill_style_circle_offset"
android:bottom="@dimen/pointer_fill_style_circle_offset"
android:right="@dimen/pointer_fill_style_circle_offset">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_diameter"
android:height="@dimen/pointer_fill_style_circle_diameter" />
<solid android:color="@android:color/white" />
</shape>
</item>
<item
android:top="@dimen/pointer_fill_style_circle_outline_offset"
android:left="@dimen/pointer_fill_style_circle_outline_offset"
android:bottom="@dimen/pointer_fill_style_circle_outline_offset"
android:right="@dimen/pointer_fill_style_circle_outline_offset">
<shape android:shape="oval">
<size
android:width="@dimen/pointer_fill_style_circle_outline_diameter"
android:height="@dimen/pointer_fill_style_circle_outline_diameter" />
<stroke
android:width="@dimen/pointer_fill_style_circle_outline_stroke"
android:color="@android:color/white" />
</shape>
</item>
</layer-list>
</item>
</selector>

View File

@@ -1,67 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 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_selected="true" android:state_hovered="true">
<layer-list>
<item>
<shape android:shape="oval">
<size android:width="@dimen/pointer_fill_style_circle_hover_selected_diameter"
android:height="@dimen/pointer_fill_style_circle_hover_selected_diameter" />
<stroke android:width="@dimen/pointer_fill_style_shape_hovered_stroke"
android:color="@color/pointer_fill_outline_color" />
</shape>
</item>
<item
android:top="@dimen/pointer_fill_style_checkmark_hovered_padding"
android:left="@dimen/pointer_fill_style_checkmark_hovered_padding"
android:bottom="@dimen/pointer_fill_style_checkmark_hovered_padding"
android:right="@dimen/pointer_fill_style_checkmark_hovered_padding"
android:drawable="@drawable/pointer_fill_check_24dp" />
</layer-list>
</item>
<item android:state_selected="true">
<layer-list>
<item>
<inset android:insetTop="@dimen/pointer_fill_style_circle_selected_offset"
android:insetLeft="@dimen/pointer_fill_style_circle_selected_offset"
android:insetBottom="@dimen/pointer_fill_style_circle_selected_offset"
android:insetRight="@dimen/pointer_fill_style_circle_selected_offset">
<shape android:shape="oval">
<size android:width="@dimen/pointer_fill_style_circle_selected_diameter"
android:height="@dimen/pointer_fill_style_circle_selected_diameter" />
<stroke android:width="@dimen/pointer_fill_style_shape_selected_stroke"
android:color="@color/pointer_fill_outline_color" />
</shape>
</inset>
</item>
<item
android:top="@dimen/pointer_fill_style_checkmark_selected_padding"
android:left="@dimen/pointer_fill_style_checkmark_selected_padding"
android:bottom="@dimen/pointer_fill_style_checkmark_selected_padding"
android:right="@dimen/pointer_fill_style_checkmark_selected_padding"
android:drawable="@drawable/pointer_fill_check_24dp" />
</layer-list>
</item>
<item android:state_hovered="true">
<shape android:shape="oval">
<size android:width="@dimen/pointer_fill_style_circle_hover_diameter"
android:height="@dimen/pointer_fill_style_circle_hover_diameter" />
<stroke android:width="@dimen/pointer_fill_style_shape_hovered_stroke"
android:color="@color/pointer_fill_outline_color" />
</shape>
</item>
</selector>

View File

@@ -42,7 +42,6 @@
android:layout_height="@dimen/pointer_fill_container_height"
android:layout_marginBottom="@dimen/pointer_fill_style_circle_padding"
android:layout_marginTop="@dimen/pointer_fill_style_circle_padding"
android:background="@drawable/pointer_icon_fill_container_background"
android:gravity="center"
android:paddingTop="@dimen/pointer_fill_style_container_padding"
android:paddingBottom="@dimen/pointer_fill_style_container_padding">
@@ -53,19 +52,18 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="4" />
android:layout_weight="1" />
<ImageView
android:id="@+id/button_black"
android:layout_width="@dimen/pointer_fill_style_circle_diameter"
android:layout_width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:layout_weight="0"
android:layout_height="@dimen/pointer_fill_style_circle_diameter"
android:layout_height="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:adjustViewBounds="true"
android:maxWidth="@dimen/pointer_fill_style_circle_diameter"
android:maxWidth="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:contentDescription="@string/pointer_fill_style_black_button"
android:scaleType="center"
android:background="@drawable/pointer_icon_fill_color_background"
android:src="@drawable/pointer_icon_fill_color_foreground" />
android:src="@drawable/pointer_icon_fill_color_background" />
<View
android:layout_width="0dp"
@@ -73,19 +71,18 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="3" />
android:layout_weight="1" />
<ImageView
android:id="@+id/button_green"
android:layout_width="@dimen/pointer_fill_style_circle_diameter"
android:layout_width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:layout_weight="0"
android:layout_height="@dimen/pointer_fill_style_circle_diameter"
android:layout_height="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:adjustViewBounds="true"
android:maxWidth="@dimen/pointer_fill_style_circle_diameter"
android:maxWidth="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:contentDescription="@string/pointer_fill_style_green_button"
android:scaleType="center"
android:background="@drawable/pointer_icon_fill_color_background"
android:src="@drawable/pointer_icon_fill_color_foreground" />
android:src="@drawable/pointer_icon_fill_color_background" />
<View
android:layout_width="0dp"
@@ -93,19 +90,18 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="3" />
android:layout_weight="1" />
<ImageView
android:id="@+id/button_red"
android:layout_width="@dimen/pointer_fill_style_circle_diameter"
android:layout_width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:layout_weight="0"
android:layout_height="@dimen/pointer_fill_style_circle_diameter"
android:layout_height="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:adjustViewBounds="true"
android:maxWidth="@dimen/pointer_fill_style_circle_diameter"
android:maxWidth="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:contentDescription="@string/pointer_fill_style_red_button"
android:scaleType="center"
android:background="@drawable/pointer_icon_fill_color_background"
android:src="@drawable/pointer_icon_fill_color_foreground" />
android:src="@drawable/pointer_icon_fill_color_background" />
<View
android:layout_width="0dp"
@@ -113,19 +109,18 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="3" />
android:layout_weight="1" />
<ImageView
android:id="@+id/button_pink"
android:layout_width="@dimen/pointer_fill_style_circle_diameter"
android:layout_width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:layout_weight="0"
android:layout_height="@dimen/pointer_fill_style_circle_diameter"
android:layout_height="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:adjustViewBounds="true"
android:maxWidth="@dimen/pointer_fill_style_circle_diameter"
android:maxWidth="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:contentDescription="@string/pointer_fill_style_pink_button"
android:scaleType="center"
android:background="@drawable/pointer_icon_fill_color_background"
android:src="@drawable/pointer_icon_fill_color_foreground" />
android:src="@drawable/pointer_icon_fill_color_background" />
<View
android:layout_width="0dp"
@@ -133,19 +128,18 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="3" />
android:layout_weight="1" />
<ImageView
android:id="@+id/button_blue"
android:layout_width="@dimen/pointer_fill_style_circle_diameter"
android:layout_width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:layout_weight="0"
android:layout_height="@dimen/pointer_fill_style_circle_diameter"
android:layout_height="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:adjustViewBounds="true"
android:maxWidth="@dimen/pointer_fill_style_circle_diameter"
android:maxWidth="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:contentDescription="@string/pointer_fill_style_blue_button"
android:scaleType="center"
android:background="@drawable/pointer_icon_fill_color_background"
android:src="@drawable/pointer_icon_fill_color_foreground" />
android:src="@drawable/pointer_icon_fill_color_background" />
<View
android:layout_width="0dp"
@@ -153,19 +147,18 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="3" />
android:layout_weight="1" />
<ImageView
android:id="@+id/button_purple"
android:layout_width="@dimen/pointer_fill_style_circle_diameter"
android:layout_width="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:layout_weight="0"
android:layout_height="@dimen/pointer_fill_style_circle_diameter"
android:layout_height="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:adjustViewBounds="true"
android:maxWidth="@dimen/pointer_fill_style_circle_diameter"
android:maxWidth="@dimen/pointer_fill_style_circle_background_outer_diameter"
android:contentDescription="@string/pointer_fill_style_purple_button"
android:scaleType="center"
android:background="@drawable/pointer_icon_fill_color_background"
android:src="@drawable/pointer_icon_fill_color_foreground" />
android:src="@drawable/pointer_icon_fill_color_background" />
<View
android:layout_width="0dp"
@@ -173,7 +166,7 @@
android:focusable="false"
android:clickable="false"
android:importantForAccessibility="no"
android:layout_weight="4" />
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

View File

@@ -77,8 +77,8 @@
<!-- Switch bar disabled state color-->
<color name="switch_bar_state_disabled_color">#1FE3E3E3</color>
<!-- Pointer fill color setting outline color-->
<color name="pointer_fill_outline_color">#FFFFFF</color>
<!-- Pointer fill color setting, fill selector's background color on hover. -->
<color name="pointer_fill_hovered_color">#3E373C</color>
<!-- Connected displays -->
<color name="display_topology_background_color">@color/settingslib_color_charcoal</color>

View File

@@ -219,8 +219,8 @@
<!-- Switch bar disabled state color-->
<color name="switch_bar_state_disabled_color">#1F1F1F1F</color>
<!-- Pointer fill color setting outline color-->
<color name="pointer_fill_outline_color">#000000</color>
<!-- Pointer fill color setting, fill selector's background color on hover. -->
<color name="pointer_fill_hovered_color">#1C201A1E</color>
<!-- Connected displays -->
<color name="display_topology_background_color">@color/settingslib_color_grey100</color>

View File

@@ -180,21 +180,28 @@
<dimen name="keyboard_picker_text_size">16sp</dimen>
<!-- Pointer -->
<dimen name="pointer_fill_container_height">88dp</dimen>
<dimen name="pointer_fill_container_max_width">448dp</dimen>
<dimen name="pointer_fill_container_height">80dp</dimen>
<dimen name="pointer_fill_container_max_width">468dp</dimen>
<dimen name="pointer_fill_style_container_padding">32dp</dimen>
<dimen name="pointer_fill_style_circle_diameter">56dp</dimen>
<dimen name="pointer_fill_style_circle_hover_selected_diameter">52dp</dimen>
<dimen name="pointer_fill_style_circle_hover_diameter">56dp</dimen>
<dimen name="pointer_fill_style_circle_selected_diameter">50dp</dimen>
<dimen name="pointer_fill_style_circle_inner_diameter">40dp</dimen>
<dimen name="pointer_fill_style_circle_offset">8dp</dimen>
<dimen name="pointer_fill_style_target_width">64dp</dimen>
<dimen name="pointer_fill_style_circle_diameter">39dp</dimen>
<dimen name="pointer_fill_style_circle_outline_diameter">39.5dp</dimen>
<dimen name="pointer_fill_style_circle_background_corner_radius">20dp</dimen>
<dimen name="pointer_fill_style_circle_background_corner_inner_radius">16dp</dimen>
<dimen name="pointer_fill_style_circle_background_outer_diameter">64dp</dimen>
<dimen name="pointer_fill_style_circle_background_outer_diameter_less_stroke">62dp</dimen>
<dimen name="pointer_fill_style_circle_background_outer_diameter_selected">52dp</dimen>
<dimen name="pointer_fill_style_circle_background_outline_offset">1dp</dimen>
<dimen name="pointer_fill_style_circle_offset">12.5dp</dimen>
<dimen name="pointer_fill_style_circle_offset_selected">13.25dp</dimen>
<dimen name="pointer_fill_style_circle_outline_offset">12.25dp</dimen>
<dimen name="pointer_fill_style_circle_outline_offset_selected">13dp</dimen>
<dimen name="pointer_fill_style_circle_background_offset">7dp</dimen>
<dimen name="pointer_fill_style_circle_outline_stroke">1dp</dimen>
<dimen name="pointer_fill_style_circle_background_selected_outline_stroke">2dp</dimen>
<dimen name="pointer_fill_style_circle_padding">16dp</dimen>
<dimen name="pointer_fill_style_circle_selected_offset">3dp</dimen>
<dimen name="pointer_fill_style_checkmark_selected_padding">14dp</dimen>
<dimen name="pointer_fill_style_checkmark_hovered_padding">17dp</dimen>
<dimen name="pointer_fill_style_shape_selected_stroke">2dp</dimen>
<dimen name="pointer_fill_style_shape_hovered_stroke">4dp</dimen>
<dimen name="pointer_fill_style_checkmark_selected_padding">16dp</dimen>
<dimen name="pointer_fill_style_checkmark_size">24dp</dimen>
<dimen name="pointer_stroke_style_padding">8dp</dimen>
<dimen name="pointer_stroke_style_text_padding">21dp</dimen>
<dimen name="pointer_scale_padding">8dp</dimen>

View File

@@ -25,6 +25,9 @@ import static android.view.PointerIcon.POINTER_ICON_VECTOR_STYLE_FILL_RED;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.StateListDrawable;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.PointerIcon;
@@ -41,6 +44,11 @@ import com.android.settings.R;
public class PointerFillStylePreference extends Preference {
private static final int[] STATE_HOVERED_SELECTED =
new int[]{android.R.attr.state_hovered, android.R.attr.state_selected};
private static final int[] STATE_SELECTED = new int[]{android.R.attr.state_selected};
private static final int[] STATE_HOVERED = new int[]{android.R.attr.state_hovered};
private static final int[] STATE_DEFAULT = new int[]{};
@Nullable private LinearLayout mButtonHolder;
@@ -82,11 +90,7 @@ public class PointerFillStylePreference extends Preference {
if (button == null) {
return;
}
int[] attrs = {com.android.internal.R.attr.pointerIconVectorFill};
try (TypedArray ta = getContext().obtainStyledAttributes(
PointerIcon.vectorFillStyleToResource(style), attrs)) {
button.getBackground().setTint(ta.getColor(0, Color.BLACK));
}
tintButtonByStyle(button, style);
button.setOnClickListener(
(v) -> {
getPreferenceDataStore().putInt(Settings.System.POINTER_FILL_STYLE, style);
@@ -96,6 +100,32 @@ public class PointerFillStylePreference extends Preference {
button.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_ARROW));
}
private void tintButtonByStyle(ImageView button, int style) {
int[] attrs = {com.android.internal.R.attr.pointerIconVectorFill};
try (TypedArray ta = getContext().obtainStyledAttributes(
PointerIcon.vectorFillStyleToResource(style), attrs)) {
// Index 0, as there is only one attribute returned here.
int color = ta.getColor(/* index= */ 0, Color.BLACK);
StateListDrawable stateListDrawable = (StateListDrawable) button.getDrawable();
tintDrawableByLayerId(stateListDrawable, STATE_HOVERED_SELECTED,
R.id.tintableCircleHoveredSelected, color);
tintDrawableByLayerId(stateListDrawable, STATE_SELECTED, R.id.tintableCircleSelected,
color);
tintDrawableByLayerId(stateListDrawable, STATE_HOVERED, R.id.tintableCircleHovered,
color);
tintDrawableByLayerId(stateListDrawable, STATE_DEFAULT, R.id.tintableCircleDefault,
color);
}
}
private void tintDrawableByLayerId(StateListDrawable stateListDrawable, int[] stateSet,
int layerId, int color) {
int index = stateListDrawable.findStateDrawableIndex(stateSet);
LayerDrawable layerDrawable = (LayerDrawable) stateListDrawable.getStateDrawable(index);
Drawable drawable = layerDrawable.findDrawableByLayerId(layerId);
drawable.setTint(color);
}
private void setButtonChecked(int id) {
if (mButtonHolder == null) {
return;