B4A Library FaceOffToggleButton

This is a wrap for this Github Project.

FaceOffToggleButtonAnimation.gif


FaceOffToggleButton
Author:
DonManfred (wrapper)
Version: 1
  • FaceOffToggleButton
    Events:
    • onStateChange (process As Float, state As String)
    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)
    • isChecked As Boolean
    • isDraggable As Boolean
    • isMoveToSameStateCallListener As Boolean
    • performClick As Boolean
    • setChecked2 (checked As Boolean, callListener As Boolean)
    • setCheckedImmediately2 (checked As Boolean, callListener As Boolean)
    • toggle
    • toggle2 (callListener As Boolean)
    • toggleImmediately
    • toggleImmediately2 (callListener As Boolean)
    Properties:
    • Background As Drawable
    • BackgroundColor As Int
    • Checked As Boolean [write only]
    • CheckedImmediately As Boolean [write only]
    • Color As Int [write only]
    • ColorChangeType As ColorChangeType
    • Draggable As Boolean [write only]
    • Duration As Int
    • Enabled As Boolean
    • FaceMargin As Float
    • FaceRadius As Float
    • Height As Int
    • Left As Int
    • LeftBackgroundColor As Int
    • LeftEyeColor As Int
    • LeftFaceColor As Int
    • LeftMouthColor As Int
    • MoveToSameStateCallListener As Boolean [write only]
    • Parent As Object [read only]
    • RightBackgroundColor As Int
    • RightEyeColor As Int
    • RightFaceColor As Int
    • RightMouthColor As Int
    • Tag As Object
    • Top As Int
    • TouchMoveRatioValue As Float
    • Visible As Boolean
    • Width As Int
    • WidthRadiusRatio As Float

Requirement:
- B4A 5.8+
- Android API 21+
 

Attachments

  • FaceOffToggleButtonEx.zip
    9.1 KB · Views: 507
  • FaceOffToggleButtonV1.0.zip
    20.8 KB · Views: 502
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
Hi @DonManfred

It worked on Android 5 but crash on Android 4.4.2 ??

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
java.lang.NoSuchMethodError: android.graphics.Canvas.drawOval
    at com.nightonke.faceofftogglebutton.FaceOffToggleButton.onDraw(FaceOffToggleButton.java:390)
    at android.view.View.draw(View.java:14788)
    at android.view.View.getDisplayList(View.java:13655)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2476)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2300)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1929)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1043)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    at android.view.Choreographer.doFrame(Choreographer.java:544)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
    at dalvik.system.NativeStart.main(Native Method)
 

DonManfred

Expert
Licensed User
Longtime User

susu

Well-Known Member
Licensed User
Longtime User
I tried Android jar v22 but it didn't work.
 

Johan Schoeman

Expert
Licensed User
Longtime User
drawoval is added in api 21

So, 21 is the minimum api you need to use.
I had a similar issue in one of my wrappers and solved it with this code snippet that I found on Stackoverflow

B4X:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
// Do something for Lollipop and above versions
canvas.drawOval(left, top, right, bottom, mBoxPaint);
} else{
// do something for phones running an SDK before Lollipop
RectF mRectF = new RectF(left,top,right,bottom);
canvas.drawOval(mRectF, mBoxPaint);
}
 

MohammadNew

Active Member
Licensed User
Longtime User
nice library,

but how to use it

this code for ToggleButton

If ToggleButton1.Checked = True Then
ToastMessageShow("ON",True)
Else
ToastMessageShow("OFF",True)
End If
 

MohammadNew

Active Member
Licensed User
Longtime User
Sub FaceOffToggleButton1_onStateChange(process As Float,state As String)
Log($"onStateChange(${process},${state})"$)

If FaceOffToggleButton1.isChecked = True Then
ToastMessageShow("ON",True)
Else
ToastMessageShow("OFF",True)
End If

End Sub

does not work ??? the toastmessage show OFF

could you give me example please
 
Last edited:

josnav

Member
Licensed User
Longtime User
API 23 and the same error!!


Hi @DonManfred

It worked on Android 5 but crash on Android 4.4.2 ??

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
lib:Raising.. faceswitch_onstatechange()
java.lang.NoSuchMethodError: android.graphics.Canvas.drawOval
    at com.nightonke.faceofftogglebutton.FaceOffToggleButton.onDraw(FaceOffToggleButton.java:390)
    at android.view.View.draw(View.java:14788)
    at android.view.View.getDisplayList(View.java:13655)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3108)
    at android.view.View.getDisplayList(View.java:13593)
    at android.view.View.getDisplayList(View.java:13697)
    at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2476)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2300)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1929)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1043)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    at android.view.Choreographer.doFrame(Choreographer.java:544)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
    at dalvik.system.NativeStart.main(Native Method)
 

MolsonB

Member
Licensed User
Longtime User
Is there a way in the event to catch if it was a human that clicked the button vs the system. (Ie, when Activity_Resume sets the position of the switch, it fires the event). Would be nice to know who fired off the event.

Little clean up for the logs, "lib:Raising.. tgenable_onstatechange()" gets repeated as the button moves. Probably just needs to be commented out in the library?
 
Top