This file contains 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) |
This file contains 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 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 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 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 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 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 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 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
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_checked="true"> | |
<shape android:shape="rectangle"> | |
<solid android:color="@color/blue_300" /> | |
<corners android:radius="40dp" /> | |
<size android:width="48dp" android:height="24dp" /> | |
</shape> | |
</item> | |
<item android:state_checked="false"> |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_checked="true"> | |
<shape android:shape="rectangle"> | |
<corners android:radius="20dp" /> | |
<solid android:color="@color/blue_800" /> | |
<size android:width="24dp" android:height="24dp" /> | |
<stroke android:width="4dp" android:color="@android:color/transparent" /> | |
</shape> | |
</item> |
NewerOlder