So I thought I should post my version of the RippleView port.
Feel free to jd-gui the code, I didnt have time to test it (on its own).
The reason I rewrote it:
- I wasnt 100% satisfied with Erel's implementation, Informatix was closer to what I wanted but still not quite.
- The RippleView.java file was modified in a way that it broke compatibility with any Java lib that depends on this lib, so I had to rewrite it anyway.
So this is an export from a larger project but I wanted to demonstrate how it should work when building a view hierarchy.
Normally to put a button 'b' on a panel 'spanel' :
spanel.AddView(b, 10dip,200dip, 100%x - 20dip, 48dip)
Now trying to add a Ripple, with Informatix's/Erel's port:
spanel.AddView(b, 10dip,200dip, 100%x - 20dip, 48dip)
Dim rv As RippleView
rv.Initialize(b, Colors.Red, 200, True)
Now looking at this code it is not really apparent what happened, unless you *know* what happens in the library.
The view hierarchy is not apparent at all, i.e. the parent of b is now rv, and the parent of rv is spanel.
So what I did was to add a Panel in the RippleView and use that to add the views
While this may be fraught with problems, as the panel can have multiple views (in this case it is supposed to have only one)
The code looks like this:
Dim rv As MSMaterialRipple
rv.Initialize
spanel.AddView(rv, 10dip,200dip, 100%x - 20dip, 48dip)
rv.Panel.AddView(b, 0dip,0dip, r.Width, r.Height)
rv.SetDuration(50)
rv.SetupChildViewEvents(b)
So the view hierarchy is immediately apparent, i.e. rv is added to spanel, b is added to rv.
Issues with this implementation:
- Is there slowness due to adding another view layer on top? I dont know, maybe.
- The ChildView is now a view inside the panel, so I was not receiving touch and click events on it. I had to add another method to re-setup the childview so it can receive events. Why another method? Because I could not afford to break the original code, as the same implementation needs to work even when NOT using a panel. So you need to call SetupChildViewEvents before your view can receive events.