Android Question How can I call Paint.setStrokeCap?

NeoTechni

Well-Known Member
Licensed User
Longtime User
https://developer.android.com/refer...html#setStrokeCap(android.graphics.Paint.Cap)

This page shows it's a valid method for the paint object, so I tried

B4X:
'CapType: 0=Butt, 1=Round, 2=Square (assumed)
Sub setStrokeCap(BG As Canvas, CapType As Int)
   Dim r As Reflector
  r.Target = BG
  r.Target = r.GetField("paint")
  r.RunMethod2("setStrokeCap", CapType, "java.lang.int")
End Sub

but I got:


Also, I'm assuming the values of the enum. Is there a way to get the real values?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there a way to get the real values?
enums do not have any "other" value.

B4X:
Dim paint As JavaObject = BG
paint = BG.GetField("paint") 'this line will fail in older versions of B4A. If it happens then you should use Reflector to get the paint and then set it to a JavaObject variable.
paint.RunMethod("setStrokeCap", Array("ROUND"))
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
B4X:
'CapType: 0=Butt, 1=Round, 2=Square
Sub setStrokeCap(BG As Canvas, CapType As Int)
   Dim paint As JavaObject = BG, CapName As String
   Select Case CapType
     Case 0: CapName = "BUTT"
     Case 1: CapName = "ROUND"
     Case 2: CapName = "SQUARE"
   End Select
   paint = paint.GetField("paint") 'this line will fail in older versions of B4A. If it happens then you should use Reflector to get the paint and then set it to a JavaObject variable.
   paint.RunMethod("setStrokeCap", Array(CapName))
End Sub
What I used.

Thank you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…