Wish B4XImageView Android Version Fix

Jack Cole

Well-Known Member
Licensed User
Longtime User
With Android v4, I get the following crash when using B4XImageView.

Fatal Exception: java.lang.RuntimeException: Method: setClipToOutline not found in: anywheresoftware.b4a.BALayout
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at mindware.minegames.b4ximageview._updateclip(b4ximageview.java:310)
at mindware.minegames.b4ximageview._update(b4ximageview.java:236)
at mindware.minegames.b4ximageview._setbitmap(b4ximageview.java:189)
at mindware.minegames.b4xmainpage._setbitmapandresize(b4xmainpage.java:5795)
at mindware.minegames.b4xmainpage$ResumableSub_ResponseGrid_AfterItemCreated.resume(b4xmainpage.java:4807)
at mindware.minegames.b4xmainpage._responsegrid_afteritemcreated(b4xmainpage.java:4778)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.keywords.Common$12.run(Common.java:1212)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)

This is fixable with the following modification to the B4XImageView.bas inside of the XUI Views library. I don't always remember to do this after B4A is updated and I end up finding the crashes later. Could you include this in the official code?

B4X:
Private Sub UpdateClip
    If mRound Then
        mBase.SetColorAndBorder(mBackgroundColor, 0, 0, Min(mBase.Width / 2, mBase.Height / 2))
    Else
        mBase.SetColorAndBorder(mBackgroundColor, 0, 0, mCornersRadius)
    End If
#if B4J
    Dim jo As JavaObject = mBase
    Dim shape As JavaObject
    If mRound Then
        Dim radius As Double = Min(mBase.Width / 2, mBase.Height / 2)
        Dim cx As Double = mBase.Width / 2
        Dim cy As Double = mBase.Height / 2
        shape.InitializeNewInstance("javafx.scene.shape.Circle", Array(cx, cy, radius))
    Else
        Dim cx As Double = mBase.Width
        Dim cy As Double = mBase.Height
        shape.InitializeNewInstance("javafx.scene.shape.Rectangle", Array(cx, cy))
        If mCornersRadius > 0 Then
            Dim d As Double = mCornersRadius
            shape.RunMethod("setArcHeight", Array(d))
            shape.RunMethod("setArcWidth", Array(d))
        End If
    End If
    jo.RunMethod("setClip", Array(shape))
#else if B4A
    Try
        Dim jo As JavaObject = mBase
        jo.RunMethod("setClipToOutline", Array(mRound Or mCornersRadius > 0))
    Catch
        'Log(LastException)
    End Try
#end if
End Sub
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
One thing I have been doing is pulling the code out from the XUI Views library and adding it directly to my project.
 

TILogistic

Expert
Licensed User
Longtime User
?
With Android v4, I get the following crash when using B4XImageView.
note:
2. In B4A the shape is based on the set background (as in B4i). We only need to call setClipToOuline. Note that it is available in Android 5+ (minSdkVersion=21).
 
Top