This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <declare-styleable name="CustomSwitch"> | |
| <attr name="switch_type" format="enum"> | |
| <enum name="vanilla" value="1" /> | |
| <enum name="small" value="2" /> | |
| <enum name="big" value="3" /> | |
| <enum name="pill" value="4" /> | |
| </attr> | |
| <attr name="anim_text" format="boolean" /> | |
| <attr name="manual" format="boolean" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <com.molidev8.customswitchsamples.view.customSwitch.CustomSwitch | |
| android:id="@+id/myCustomSwitch" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| app:anim_text="true" | |
| app:manual="true" | |
| app:text="Bluetooth" | |
| app:switch_type="pill" | |
| app:textVisible="true" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomSwitch : ConstraintLayout { | |
| private lateinit var manager: CustomSwitchManager | |
| constructor(context: Context) : super(context) | |
| constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | |
| readAttrs(attrs) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomSwitchThumbPill : CustomSwitchManager { | |
| private lateinit var binding: CustomSwitchThumbPillBinding | |
| override fun initView( | |
| context: Context, | |
| viewGroup: ViewGroup, | |
| animText: Boolean, | |
| manual: Boolean, | |
| textVisible: Boolean, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomSwitch : ConstraintLayout { | |
| private lateinit var manager: CustomSwitchManager | |
| constructor(context: Context) : super(context) | |
| constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | |
| readAttrs(attrs) | |
| } | |
| constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object CustomSwitchFactory { | |
| fun build(type: CustomSwitchType): CustomSwitchManager = when (type) { | |
| CustomSwitchType.CustomThumbBigSwitch -> CustomSwitchThumbBig() | |
| CustomSwitchType.CustomThumbSmallSwitch -> CustomSwitchThumbSmall() | |
| CustomSwitchType.CustomTrackPillSwitch -> CustomSwitchThumbPill() | |
| CustomSwitchType.Vanilla -> CustomSwitchVanilla() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sealed class CustomSwitchType { | |
| object Vanilla : CustomSwitchType() | |
| object CustomThumbSmallSwitch : CustomSwitchType() | |
| object CustomThumbBigSwitch : CustomSwitchType() | |
| object CustomTrackPillSwitch : CustomSwitchType() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface CustomSwitchManager { | |
| fun initView( | |
| context: Context, | |
| viewGroup: ViewGroup, | |
| animText: Boolean, | |
| manual: Boolean, | |
| textVisible: Boolean, | |
| text: String | |
| ) | |
| fun setAnimText(shouldAnim: Boolean) |
OlderNewer