Skip to content

Commit 1414f9e

Browse files
drchendsn5ft
authored andcommitted
[Switch] Add thumb and track drawables for the new switch design
PiperOrigin-RevId: 448253424
1 parent 467a2c9 commit 1414f9e

17 files changed

+595
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2022 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
18+
<!-- State Disabled, Unchecked -->
19+
<item
20+
android:alpha="@dimen/material_emphasis_disabled"
21+
android:color="?attr/colorOnSurface"
22+
android:state_enabled="false" android:state_checked="false"/>
23+
24+
<!-- State Disabled, Checked -->
25+
<item
26+
android:alpha="@dimen/material_emphasis_disabled"
27+
android:color="?attr/colorSurface"
28+
android:state_enabled="false" android:state_checked="true"/>
29+
30+
<!-- State Checked, Pressed -->
31+
<item android:color="?attr/colorPrimaryContainer" android:state_checked="true" android:state_pressed="true"/>
32+
33+
<!-- State Checked -->
34+
<item android:color="?attr/colorOnPrimary" android:state_checked="true"/>
35+
36+
<!-- State Unchecked, Pressed -->
37+
<item android:color="?attr/colorOnSurfaceVariant" android:state_pressed="true"/>
38+
39+
<!-- State Unchecked -->
40+
<item android:color="?attr/colorOutline"/>
41+
</selector>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2022 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
18+
<item android:alpha="@dimen/material_emphasis_disabled_background"
19+
android:color="?attr/colorSurfaceVariant"
20+
android:state_enabled="false" android:state_checked="false"/>
21+
<item android:alpha="@dimen/material_emphasis_disabled_background"
22+
android:color="?attr/colorOnSurface"
23+
android:state_enabled="false" android:state_checked="true"/>
24+
<item android:color="?attr/colorPrimary" android:state_checked="true"/>
25+
<item android:color="?attr/colorSurfaceVariant"/>
26+
</selector>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<animated-selector
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:width="@dimen/mtrl_switch_thumb_size"
21+
android:height="@dimen/mtrl_switch_thumb_size"
22+
tools:ignore="NewApi">
23+
24+
<item
25+
android:id="@+id/pressed"
26+
android:drawable="@drawable/mtrl_switch_thumb_pressed"
27+
android:state_pressed="true" />
28+
29+
<item
30+
android:id="@+id/checked"
31+
android:drawable="@drawable/mtrl_switch_thumb_checked"
32+
android:state_checked="true" />
33+
34+
<item
35+
android:id="@+id/unchecked"
36+
android:drawable="@drawable/mtrl_switch_thumb_unchecked" />
37+
38+
<transition
39+
android:fromId="@+id/pressed"
40+
android:toId="@+id/checked"
41+
android:drawable="@drawable/mtrl_switch_thumb_pressed_checked" />
42+
43+
<transition
44+
android:fromId="@+id/pressed"
45+
android:toId="@+id/unchecked"
46+
android:drawable="@drawable/mtrl_switch_thumb_pressed_unchecked" />
47+
48+
<transition
49+
android:fromId="@+id/checked"
50+
android:toId="@+id/pressed"
51+
android:drawable="@drawable/mtrl_switch_thumb_checked_pressed" />
52+
53+
<transition
54+
android:fromId="@+id/checked"
55+
android:toId="@+id/unchecked"
56+
android:drawable="@drawable/mtrl_switch_thumb_checked_unchecked" />
57+
58+
<transition
59+
android:fromId="@+id/unchecked"
60+
android:toId="@+id/pressed"
61+
android:drawable="@drawable/mtrl_switch_thumb_unchecked_pressed" />
62+
63+
<transition
64+
android:fromId="@+id/unchecked"
65+
android:toId="@+id/checked"
66+
android:drawable="@drawable/mtrl_switch_thumb_unchecked_checked" />
67+
68+
</animated-selector>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:width="@dimen/mtrl_switch_thumb_size"
20+
android:height="@dimen/mtrl_switch_thumb_size"
21+
android:viewportHeight="@integer/mtrl_switch_thumb_viewport_size"
22+
android:viewportWidth="@integer/mtrl_switch_thumb_viewport_size"
23+
tools:ignore="NewApi">
24+
25+
<group
26+
android:name="@string/mtrl_switch_thumb_group_name"
27+
android:pivotX="@integer/mtrl_switch_thumb_viewport_center_coordinate"
28+
android:pivotY="@integer/mtrl_switch_thumb_viewport_center_coordinate">
29+
<path
30+
android:name="@string/mtrl_switch_thumb_path_name"
31+
android:fillColor="#FFFFFFFF"
32+
android:pathData="@string/mtrl_switch_thumb_path_checked" />
33+
</group>
34+
35+
</vector>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:aapt="http://schemas.android.com/aapt"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:drawable="@drawable/mtrl_switch_thumb_checked"
21+
tools:ignore="NewApi">
22+
23+
<target android:name="@string/mtrl_switch_thumb_path_name">
24+
<aapt:attr name="android:animation">
25+
<objectAnimator
26+
android:duration="@integer/mtrl_switch_thumb_pressed_duration"
27+
android:interpolator="@android:interpolator/accelerate_decelerate"
28+
android:propertyName="pathData"
29+
android:valueFrom="@string/mtrl_switch_thumb_path_checked"
30+
android:valueTo="@string/mtrl_switch_thumb_path_pressed"
31+
android:valueType="pathType" />
32+
</aapt:attr>
33+
</target>
34+
</animated-vector>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:aapt="http://schemas.android.com/aapt"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:drawable="@drawable/mtrl_switch_thumb_checked"
21+
tools:ignore="NewApi">
22+
23+
<target android:name="@string/mtrl_switch_thumb_path_name">
24+
<aapt:attr name="android:animation">
25+
<objectAnimator
26+
android:duration="@integer/mtrl_switch_thumb_pre_morphing_duration"
27+
android:interpolator="@android:interpolator/accelerate_decelerate"
28+
android:propertyName="pathData"
29+
android:valueFrom="@string/mtrl_switch_thumb_path_checked"
30+
android:valueTo="@string/mtrl_switch_thumb_path_morphing"
31+
android:valueType="pathType" />
32+
</aapt:attr>
33+
</target>
34+
<target android:name="@string/mtrl_switch_thumb_path_name">
35+
<aapt:attr name="android:animation">
36+
<objectAnimator
37+
android:startOffset="@integer/mtrl_switch_thumb_pre_morphing_duration"
38+
android:duration="@integer/mtrl_switch_thumb_post_morphing_duration"
39+
android:interpolator="@android:interpolator/accelerate_decelerate"
40+
android:propertyName="pathData"
41+
android:valueFrom="@string/mtrl_switch_thumb_path_morphing"
42+
android:valueTo="@string/mtrl_switch_thumb_path_unchecked"
43+
android:valueType="pathType" />
44+
</aapt:attr>
45+
</target>
46+
</animated-vector>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:width="@dimen/mtrl_switch_thumb_size"
20+
android:height="@dimen/mtrl_switch_thumb_size"
21+
android:viewportHeight="@integer/mtrl_switch_thumb_viewport_size"
22+
android:viewportWidth="@integer/mtrl_switch_thumb_viewport_size"
23+
tools:ignore="NewApi">
24+
25+
<group
26+
android:name="@string/mtrl_switch_thumb_group_name"
27+
android:pivotX="@integer/mtrl_switch_thumb_viewport_center_coordinate"
28+
android:pivotY="@integer/mtrl_switch_thumb_viewport_center_coordinate">
29+
<path
30+
android:name="@string/mtrl_switch_thumb_path_name"
31+
android:fillColor="#ffffffff"
32+
android:pathData="@string/mtrl_switch_thumb_path_pressed" />
33+
</group>
34+
35+
</vector>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:aapt="http://schemas.android.com/aapt"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:drawable="@drawable/mtrl_switch_thumb_pressed"
21+
tools:ignore="NewApi">
22+
23+
<target android:name="@string/mtrl_switch_thumb_path_name">
24+
<aapt:attr name="android:animation">
25+
<objectAnimator
26+
android:duration="@integer/mtrl_switch_thumb_pressed_duration"
27+
android:interpolator="@android:interpolator/accelerate_decelerate"
28+
android:propertyName="pathData"
29+
android:valueFrom="@string/mtrl_switch_thumb_path_pressed"
30+
android:valueTo="@string/mtrl_switch_thumb_path_checked"
31+
android:valueType="pathType" />
32+
</aapt:attr>
33+
</target>
34+
</animated-vector>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:aapt="http://schemas.android.com/aapt"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:drawable="@drawable/mtrl_switch_thumb_pressed"
21+
tools:ignore="NewApi">
22+
23+
<target android:name="@string/mtrl_switch_thumb_path_name">
24+
<aapt:attr name="android:animation">
25+
<objectAnimator
26+
android:duration="@integer/mtrl_switch_thumb_pressed_duration"
27+
android:interpolator="@android:interpolator/accelerate_decelerate"
28+
android:propertyName="pathData"
29+
android:valueFrom="@string/mtrl_switch_thumb_path_pressed"
30+
android:valueTo="@string/mtrl_switch_thumb_path_unchecked"
31+
android:valueType="pathType" />
32+
</aapt:attr>
33+
</target>
34+
</animated-vector>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:width="@dimen/mtrl_switch_thumb_size"
20+
android:height="@dimen/mtrl_switch_thumb_size"
21+
android:viewportHeight="@integer/mtrl_switch_thumb_viewport_size"
22+
android:viewportWidth="@integer/mtrl_switch_thumb_viewport_size"
23+
tools:ignore="NewApi">
24+
25+
<group
26+
android:name="@string/mtrl_switch_thumb_group_name"
27+
android:pivotX="@integer/mtrl_switch_thumb_viewport_center_coordinate"
28+
android:pivotY="@integer/mtrl_switch_thumb_viewport_center_coordinate">
29+
<path
30+
android:name="@string/mtrl_switch_thumb_path_name"
31+
android:fillColor="#FFFFFFFF"
32+
android:pathData="@string/mtrl_switch_thumb_path_unchecked" />
33+
</group>
34+
35+
</vector>

0 commit comments

Comments
 (0)