B4A Library SwitchButton

This is a wrap for this Github-project.
You need B4A V5.8+ to use this library.
You need B4A 6+ to use V1.5+ of this library.

New in V1.5
- The library is now available as aar file.
- I´ve added TextColor property


SwitchButton
Author:
DonManfred (wrapper)
Version: 2.1
  • SwitchButton
    Events:
    • onCheckedChanged (checked As Boolean)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • isDrawDebugRect As Boolean
    • isFadeBack As Boolean
    • performClick As Boolean
    • setText (onText As CharSequence, offText As CharSequence)
    • setThumbMargin (left As Float, top As Float, right As Float, bottom As Float)
    • setThumbSize (width As Float, height As Float)
    • toggleImmediately
    Properties:
    • AnimationDuration As Long
    • BackColor As ColorStateList
    • BackDrawable As Drawable
    • BackDrawableRes As String [write only]
    • BackMeasureRatio As Float
    • BackRadius As Float
    • BackSizeF As PointF [read only]
    • Background As Drawable
    • Checked As Boolean [write only]
    • CheckedImmediately As Boolean [write only]
    • Color As Int [write only]
    • DrawDebugRect As Boolean [write only]
    • Enabled As Boolean
    • FadeBack As Boolean [write only]
    • Height As Int
    • Left As Int
    • Parent As Object [read only]
    • Process As Float
    • Tag As Object
    • ThumbColor As ColorStateList
    • ThumbDrawable As Drawable
    • ThumbDrawableRes As String [write only]
    • ThumbHeight As Float [read only]
    • ThumbMargin As RectF [read only]
    • ThumbMarginRect As RectF [write only]
    • ThumbRadius As Float
    • ThumbSize2 As PointF [write only]
    • ThumbSizeF As PointF [read only]
    • ThumbWidth As Float [read only]
    • TintColor As Int
    • Top As Int
    • Visible As Boolean
    • Width As Int

B4X:
    SwitchButton1.ThumbDrawableRes = "flyme_thumb_drawable"
    SwitchButton1.BackDrawableRes = "flyme_back_drawable"
    SwitchButton2.BackDrawableRes = "ios_back_drawable"

    SwitchButton3.ThumbDrawableRes = "miui_thumb_drawable"
    SwitchButton3.BackDrawableRes = "miui_back_drawable"

    SwitchButton4.ThumbDrawableRes = "icon_github"
    SwitchButton5.ThumbDrawableRes = "ios_back_drawable"

Screenshot_20160402-132307.png
 

Attachments

  • SwitchButtonV1.0.0.zip
    19.4 KB · Views: 504
  • SwitchButtonV1.0.1.zip
    19.2 KB · Views: 524
  • SwitchButtonV1.5.zip
    33 KB · Views: 566
  • SwitchButtonV2.1.zip
    32.7 KB · Views: 665
  • SwitchButtonEx.zip
    26.4 KB · Views: 680
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
This is the content of the Resourcefolder.
There are just drawables. No other xml...
This Resource folder is right. In Resource that you have in example are present also folder value and color into Resource. This is conflict.
Now work :D
 

peacemaker

Expert
Licensed User
Longtime User
But ... it's impossible to get the current state of the switch ? If to use several switches - how to save the user selection ?

UPD: OK, a common extra map of values can be updated by events...
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
But ... it's impossible to get the current state of the switch ? If to use several switches - how to save the user selection ?

As i lost my source a few months ago i do not have the source so i cant answer this.
BUT i did a fast new wrap for it.

Try the version attached please
 

Attachments

  • SwitchButtonV2.0.zip
    32.6 KB · Views: 287
  • SwitchButtonEx.zip
    26.4 KB · Views: 325
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Try the version v.2.00 attached please

setThumbSize, performClick were removed :( why ?
"Checked" is with getter now, but no use to test, as above are removed :(((
 

peacemaker

Expert
Licensed User
Longtime User
v.2.1:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoSuchFieldError: No static field colorAccent of type I in class Lcom/kyleduo/switchbutton/R$attr; or its superclasses (declaration of 'com.kyleduo.switchbutton.R$attr' appears in base.apk)
 

peacemaker

Expert
Licensed User
Longtime User
Yes, seems AppCompat helped... THanks !
It needs to understand what this is...
 

Matteo Giorgini

Member
Licensed User
Hi DonManfred!
I would like to use your library on my project (v. 2.10).
I downloaded the sample, but on my project I don't use AppCompat. This is a problem because without this reference my APP crashes at start.
Can I use SwitchButton "without" AppCompat? How do I do?

Thanks in advance to replay.

Matteo
 
Top