B4J Question Customview not working (I need some help)

Marc De Loose

Member
Licensed User
Longtime User
Hi,

I some of you could shed some light on this:

In short Line 57 fires an error (java.lang.class exeption)

I know its me. I am just returning to coding and seem to have forgotten everything.

The code below is a customview (XIU) module.
Everything works without the line 57 : mBase.SetBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"))



xRotateKnob:
'Events declarations
#Event: Click
#Event: LongClick
#Event: CheckedChange(Checked As Boolean)
#RaisesSynchronousEvents: Click
#RaisesSynchronousEvents: LongClick
#RaisesSynchronousEvents: CheckedChange

#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color

Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Private xui As XUI 'ignore
Public Tag As Object


Private mLeft, mTop, mWidth, mHeight As Int

Private mParent As B4XView

End Sub

Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback




Log ("Initialize")
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
'we use a Dummy obkect to get the Tag property and the Parent.
Private mDummy As B4XView
mDummy = Base
mLeft = mDummy.Left
mTop = mDummy.Top
mWidth = mDummy.Width
mHeight = mDummy.Height

Tag = mDummy.Tag

' mBackgroundColor = xui.PaintOrColorToColor(Props.Get("BackgroundColor"))

'we create a new mBase object to get the Touch event
mBase = xui.CreatePanel("mBase")

mParent = mDummy.Parent
mParent.AddView(mBase, mLeft, mTop, mWidth, mHeight)
mBase.Tag = Me

mBase.SetBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"))
'mBase.Visible=True
'we remove the mDumm / Base object, no more needed
mDummy.RemoveViewFromParent

Log ("DesignerCreateView")
InitClass
End Sub



Private Sub InitClass


End Sub


Private Sub mBase_Touch (Action As Int, X As Float, Y As Float)
Select Action
Case mBase.TOUCH_ACTION_DOWN
Log("Action DOWN")

Case mBase.TOUCH_ACTION_UP
Log ("Action UP")

Case mBase.TOUCH_ACTION_MOVE
Log ("Action MOVE: X,Y =" & X & "," & Y )

End Select
End Sub


Private Sub Base_Resize (Width As Double, Height As Double)

End Sub
 

Alexander Stolte

Expert
Licensed User
Longtime User
Upvote 0

Marc De Loose

Member
Licensed User
Longtime User
A panel is a panel and not an imageview. You cannot assign an image to a panel.
Does this look alright? It is working but that does not mean its the correct way.


xRotateKnob:
'Events declarations
#Event: Click
#Event: LongClick
#Event: CheckedChange(Checked As Boolean)
#RaisesSynchronousEvents: Click
#RaisesSynchronousEvents: LongClick
#RaisesSynchronousEvents: CheckedChange

#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color
#DesignerProperty: Key: ImageViewProperties, DisplayName: ImageView Properties, FieldType: Boolean, DefaultValue: True, Description: Test test

Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Public mBase As B4XView
    Public mKnob As B4XView

    'Type PositionData2 (PressedX As Int, PressedY As Int, Angle As Float )

    Private xui As XUI 'ignore
    Public Tag As Object
    Private fx As JFX
  
    Private mLeft, mTop, mWidth, mHeight As Int

    Private mParent As B4XView

End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
  

  
  
    Log ("Initialize")
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    'we use a Dummy obkect to get the Tag property and the Parent.
    Private mDummy As B4XView
    mDummy = Base
    mLeft = mDummy.Left
    mTop = mDummy.Top
    mWidth = mDummy.Width
    mHeight = mDummy.Height

    Tag = mDummy.Tag

    ' mBackgroundColor = xui.PaintOrColorToColor(Props.Get("BackgroundColor"))

    'we create a new mBase object to get the Touch event
    mBase = xui.CreatePanel("mBase")

    mParent = mDummy.Parent
    mParent.AddView(mBase, mLeft, mTop, mWidth, mHeight)
    mBase.Tag = Me

    Dim pd As PositionData
    pd.PressedX=0
    pd.PressedY=0
    pd.Angle=0
  
    Dim imgv As ImageView
    imgv.Initialize("imgv")
    mBase.AddView(imgv,0,0,mWidth,mHeight)
    mKnob = imgv
    'mKnob.SetBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"))
    mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), 0))
    mKnob.Tag=pd
  
    'we remove the mDumm / Base object, no more needed
    mDummy.RemoveViewFromParent
  
    Log ("DesignerCreateView")
    InitClass
End Sub


Sub RotateBitmap (bmp As B4XBitmap, Degrees As Float) As B4XBitmap
    Dim cvs As B4XCanvas
    Dim panel As B4XView = xui.CreatePanel("")
    panel.SetLayoutAnimated(0, 0, 0, bmp.Width, bmp.Height)
    cvs.Initialize(panel)
    cvs.DrawBitmapRotated(bmp, cvs.TargetRect, Degrees)
    cvs.Invalidate
    Dim b As B4XBitmap = cvs.CreateBitmap
    cvs.Release
    'Log("2: " & Degrees)
    Return b
End Sub

Private Sub InitClass


End Sub


Private Sub mBase_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case mBase.TOUCH_ACTION_DOWN
            Log("Action DOWN")
            'Dim view As B4XView = Sender
            Dim pd As PositionData  = mKnob.Tag
            pd.PressedX = X
            pd.PressedY = Y
            mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), pd.Angle Mod 360))
            mKnob.Tag = pd
            Log("PRESS: " & pd.Angle)
          
        Case mBase.TOUCH_ACTION_UP
            Log ("Action UP")
            'Dim view As B4XView = Sender
            Dim pd As PositionData = mKnob.Tag

            pd.Angle= pd.Angle+(X-pd.PressedX) Mod 360
            mKnob.Tag = pd
            mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), pd.Angle Mod 360))
            Log("RELEA: " & pd.Angle)
        Case mBase.TOUCH_ACTION_MOVE
            Dim pd As PositionData = mKnob.Tag
            Dim ParentX As Int = X
            Dim ParentY As Int = Y
            'pd.Angle=pd.Angle+(ParentX-pd.PressedX)
            'Log("2: " & Value)
            mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), pd.Angle+(ParentX-pd.PressedX) Mod 360))

            Log ("Action MOVE: X,Y =" & X & "," & Y )
          
    End Select
End Sub


Private Sub Base_Resize (Width As Double, Height As Double)
 
End Sub
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Does this look alright?
Yes.

I write my own sub for the initialization of an imageview so that I can create several with little code:
B4X:
Dim xiv As B4XView = CreateImageView("")

Private Sub CreateImageView(EventName As String) As B4XView
    Dim iv As ImageView
    iv.Initialize(EventName)
    Return iv
End Sub
 
Upvote 0

Marc De Loose

Member
Licensed User
Longtime User
THX
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…