Hi there,
I am a newbie with B4X. I worked with canvas object with several languages before.
I have problem when I try to use canvas inside of a custom view.
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
How I should use safely canvas object inside a customview ?
I am a newbie with B4X. I worked with canvas object with several languages before.
I have problem when I try to use canvas inside of a custom view.
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
How I should use safely canvas object inside a customview ?
B4X:
'Custom View class
#DesignerProperty: Key: propSpacing, DisplayName: Spacing, FieldType: Int, DefaultValue: 5, Description: General spacing
#DesignerProperty: Key: propBackground, DisplayName: Background, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: General background
#DesignerProperty: Key: propGraphFrameBackground, DisplayName: FrameBackground, FieldType: Color, DefaultValue: 0xFF00B6FF, Description: Graph frame background
#DesignerProperty: Key: propGraphBackground, DisplayName: Background, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Graph background
#DesignerProperty: Key: propLevelColor, DisplayName: Level color, FieldType: Color, DefaultValue: 0xFF00DD19, Description: Level background
#DesignerProperty: Key: propLineColor, DisplayName: Line color, FieldType: Color, DefaultValue: 0xFF333333, Description: Line color
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Private mBase As Panel
Private Const DefaultColorConstant As Int = -984833 'ignore
Private dataMap As Map
Private canvas As Canvas
Private gPanel As Panel
Private locked As Boolean = False
Public dataSum As Float = 0
Private propSpacing As Int
Private propBackground As Int
Private propGraphFrameBackground As Int
Private propGraphBackground As Int
Private propLevelColor As Int
Private propLineColor As Int
Private gLabel As Label
End Sub
Public Sub lock
locked=True
End Sub
Public Sub unlock(aUpdateLayout As Boolean)
locked=False
If (aUpdateLayout=True) Then
updateCanvas
End If
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
gPanel.Initialize("")
canvas.Initialize(gPanel)
End Sub
Public Sub itemCount As Int
Return dataMap.Size
End Sub
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, propS As Map)
dataMap.Initialize
mBase = Base
mBase.Tag = Me
Sleep(0)
mBase.LoadLayout("layChartGraph")
Sleep(0)
propSpacing=propS.Get("propSpacing")
propBackground=propS.Get("propBackground")
propGraphFrameBackground=propS.Get("propGraphFrameBackground")
propGraphBackground=propS.Get("propGraphBackground")
propLevelColor=propS.Get("propLevelColor")
propLineColor=propS.Get("propLineColor")
End Sub
Public Sub GetBase As Panel
Return mBase
End Sub
Public Sub addItem(aLabel As String,aValue As Float)
dataMap.Put(aLabel,aValue)
dataSum=dataSum+aValue
updateCanvas
End Sub
Public Sub removeItem(aLabel As String)
If (dataMap.ContainsKey(aLabel)) Then
Dim val As Float = dataMap.Get(aLabel)
dataMap.Remove(aLabel)
dataSum=dataSum-val
End If
updateCanvas
End Sub
Public Sub AddToParent(Parent As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)
mBase.Initialize("mbase")
Parent.AddView(mBase,Left,Top,Width,Height)
End Sub
Public Sub updateCanvas
If (locked=False) Then
mBase.Color=propBackground
gPanel.Color=propGraphFrameBackground
Dim tR As Rect
tR.Initialize(5dip,5dip,100dip,40dip)
canvas.DrawRect(tR,0xFF444444,False,1)
End If
End Sub