Java Question Returning Value on BA.RaiseEvent method

walterf25

Expert
Licensed User
Longtime User
Hi All, i'm trying to wrap a library and on one of the listeners for one of the properties i have the need to return an integer value, I was wondering if this is possible with any of the BA.RaiseEvent methods, if not is there any other way to accomplish this.

Below is the java portion of the code that i'm trying to accomplish this task.

B4X:
series1.setValueDependentColor(new ValueDependentColor<DataPoint>() {
                            @Override
                            public int get(DataPoint data) {
                                BA.Log("data.getx(): " + data.getX() + " " + "data.getY(): " + data.getY());
                                return Color.rgb((int) data.getX()*255/4, (int) Math.abs(data.getY()*255/6), 100);
                            }
                        });
As you can see the value returned is an Integer (color), but i would like to have the ability to customize the value returned, i would like to expose a method something like this:
B4X:
Sub bar_SetColor(xdata as Double, ydata as Double) As Int
Return RGB(xdata*255/4, Abs(ydata*255/6, 100)
End Sub

And Basically pass the color value to the return value of the listener on the first code snippet above.

So the final Java code would probably look something like this:

B4X:
series1.setValueDependentColor(new ValueDependentColor<DataPoint>() {
                            @Override
                            public int get(DataPoint data) {
                                BA.Log("data.getx(): " + data.getX() + " " + "data.getY(): " + data.getY());
int color;
color = BA.RaiseEvent(null, EventName + "_setcolor", New Object[]{data.getX(), data.getY()});
                                return color;
                            }
                        })

Can this be done?

Thanks all,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Yes. ba.raiseEvent returns the value returned from the event sub.

You should however make sure that the value is not null before you cast it to an int. It will be null if the event cannot be raised for some reason.
Hi @Erel thanks for your help, i was able to make it work just as you suggested, however because the listener gets called every time the user zooms in or out on the view (GraphView) things seem to slow down a lot, I can see the Event being raised but for some reason there is a huge lag, any ideas why this is and how to get around that?

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Have you tested it in release mode? How frequently is it called?
In Release mode it works as expected, is it slow in Debug mode because of the debug engine, any way to make it work the same in debug and release mode?

Thanks,
Walter
 
Top