Skip to content

Commit b2a3fbe

Browse files
drchendsn5ft
authored andcommitted
[Switch] Create a base skeleton of the new MaterialSwitch package/class
PiperOrigin-RevId: 447532839
1 parent 6206ff5 commit b2a3fbe

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

lib/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def srcDirs = [
5858
'com/google/android/material/floatingactionbutton',
5959
'com/google/android/material/imageview',
6060
'com/google/android/material/internal',
61+
'com/google/android/material/materialswitch',
6162
'com/google/android/material/math',
6263
'com/google/android/material/menu',
6364
'com/google/android/material/motion',
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
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+
package com.google.android.material.materialswitch;
18+
19+
import com.google.android.material.R;
20+
21+
import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap;
22+
23+
import android.content.Context;
24+
import androidx.appcompat.widget.SwitchCompat;
25+
import android.util.AttributeSet;
26+
import androidx.annotation.NonNull;
27+
import androidx.annotation.Nullable;
28+
29+
/**
30+
* A class that creates a Material Themed Switch. This class is intended to provide a brand new
31+
* Switch design and replace the obsolete
32+
* {@link com.google.android.material.switchmaterial.SwitchMaterial} class.
33+
*/
34+
public class MaterialSwitch extends SwitchCompat {
35+
private static final int DEF_STYLE_RES = R.style.Widget_Material3_CompoundButton_MaterialSwitch;
36+
37+
public MaterialSwitch(@NonNull Context context) {
38+
this(context, null);
39+
}
40+
41+
public MaterialSwitch(@NonNull Context context, @Nullable AttributeSet attrs) {
42+
this(context, attrs, R.attr.materialSwitchStyle);
43+
}
44+
45+
public MaterialSwitch(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
46+
super(wrap(context, attrs, defStyleAttr, DEF_STYLE_RES), attrs, defStyleAttr);
47+
}
48+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<resources>
17+
<public name="materialSwitchStyle" type="attr"/>
18+
</resources>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<resources>
17+
<!-- Style to use for MaterialSwitch in the theme. -->
18+
<attr name="materialSwitchStyle" type="reference"/>
19+
</resources>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<resources>
17+
<style name="Widget.Material3.CompoundButton.MaterialSwitch" parent="Widget.AppCompat.CompoundButton.Switch"/>
18+
</resources>

0 commit comments

Comments
 (0)