Java Question MSCardView Library

thedesolatesoul

Expert
Licensed User
Longtime User
Tried to port the CardView library in the compatibility libraries, but unfortunately at some point I broke it and its not working anymore.

Basically, the android-support-v7-cardview.jar referenced a lot of resource files.
For this I used the method prescribed by @warwound to create an R.java class, and reference all the resource files here. All the other libraries I ported using this method work.

For e.g.
B4X:
 public static class dimen {
       public static int default_margin = BA.applicationContext.getResources().getIdentifier("default_margin", "dimen", BA.packageName);
       public static int default_margin_small = BA.applicationContext.getResources().getIdentifier("default_margin_small", "dimen", BA.packageName);
       public static final int cardview_compat_inset_shadow=BA.applicationContext.getResources().getIdentifier("cardview_compat_inset_shadow", "dimen", BA.packageName);
       public static final int cardview_default_radius=BA.applicationContext.getResources().getIdentifier("cardview_default_radius", "dimen", BA.packageName);
   }

but either the last update of the SDK or my changes at some level broke it and I keep getting the following:

B4X:
LogCat connected to: 42f7b903479d9f59
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Activity (main) Create, isFirst = true **
RadiusDimen:4.0
ElevDimen:4.0
** Activity (main) Resume **
java.lang.IllegalArgumentException: radius must be > 0
    at android.graphics.RadialGradient.<init>(RadialGradient.java:34)
    at android.support.v7.widget.RoundRectDrawableWithShadow.buildShadowCorners(RoundRectDrawableWithShadow.java:285)
    at android.support.v7.widget.RoundRectDrawableWithShadow.buildComponents(RoundRectDrawableWithShadow.java:307)
    at android.support.v7.widget.RoundRectDrawableWithShadow.draw(RoundRectDrawableWithShadow.java:209)
    at android.view.View.draw(View.java:13744)
    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    at android.view.View.getDisplayList(View.java:12710)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.View.draw(View.java:13483)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3169)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3039)
    at android.view.View.getDisplayList(View.java:12708)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.View.draw(View.java:13483)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3169)
    at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:870)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3039)
    at android.view.View.getDisplayList(View.java:12708)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.View.draw(View.java:13483)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3169)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3039)
    at android.view.View.draw(View.java:13762)
    at android.view.View.getDisplayList(View.java:12710)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.View.draw(View.java:13483)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3169)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3039)
    at android.view.View.getDisplayList(View.java:12708)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.View.draw(View.java:13483)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3169)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3039)
    at android.view.View.getDisplayList(View.java:12708)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.View.draw(View.java:13483)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3169)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3039)
    at android.view.View.draw(View.java:13762)
    at android.widget.FrameLayout.draw(FrameLayout.java:467)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2390)
    at android.view.View.getDisplayList(View.java:12710)
    at android.view.View.getDisplayList(View.java:12754)
    at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1144)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2271)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2143)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1954)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4470)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    at android.view.Choreographer.doFrame(Choreographer.java:525)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4898)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
    at dalvik.system.NativeStart.main(Native Method)
Message longer than Log limit (4000). Message was truncated.

I added the Eclipse project to the post.
I cant see what I am doing wrong as the radius is never zero.
 

Attachments

  • MSCardView.zip
    17.5 KB · Views: 371

thedesolatesoul

Expert
Licensed User
Longtime User
Not quite sure it is the same issue.
That issue is pointing out that a gradientRadius specified in terms of percent is not working, and as you said requires the view size to be set.
In this case, the cornerradius is set to a fixed value (2dp) or can be changed in the resource files.

I also thought maybe the view size isnt set yet, but actually, I create the view in Activity_Create and add it to the parent thus setting up the layout. And this error happens after Resume. I guess draw is just called onResume or later, but the size should have been set in create.

But you may be right, it must be related to something like this.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Yes I did.
I downloaded the source of the library, and added it to my wrapper to find out the issue.
The issue is with the use of obtainTypedArray when the attributes set passed to it is null. In B4A we are used to using the simpler constructor without any attributes.
I dont know what caused Google to design the library in this way, where without the attributeset being passed, it uses default values that actually dont work!
I am not yet sure of which approach I shall used i.e. whether use the google's source and modify it not to need any xml files at all, or to just reference the jar, and pass an attributeset to it. I prefer the first method where no xml is needed, but that is hard to update if google updates their library.
 
Top