I am having issues wrapping a map rendering code into a B4A library. I have looked all over the forum and I have made some progress but I am approaching a deadline and need to be pointed in the right directions.
I can raise events when the user touches the view however I can't get the view render/update itself. I read about multithreading and the renderer running in a seperate thread however I don't have much experience with this and it is a fairly complicated code I need some guidance with this.
*code snippet for my ViewWrapper
@ShortName("Viewport2DView")
@Events(values={"Touch(f1() as float, f2() As float, id() as Int,action as Int )"})
public class Viewport2DView extends ViewWrapper<osas.track24.intermaphics.Viewport2DView> {
private BA ba;
private String eventName;
private Handler mHandler = new Handler();
private GestureDetector detector;
public void Initialize(BA pBA, String EventName) {
eventName = EventName.toLowerCase(BA.cul);
ba = pBA;
innerInitialize(pBA, EventName.toLowerCase(BA.cul), false);
}
@Hide
public void innerInitialize(BA pBA, String pEventName, boolean pKeepOldObject) {
if (!pKeepOldObject) {
setObject(new osas.track24.intermaphics.Viewport2DView(pBA.context));
detector = new GestureDetector(getObject(), mHandler);
detector.setOnDoubleTapListener(getObject());
super.innerInitialize(pBA, pEventName, pKeepOldObject);
getObject().setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
detector.onTouchEvent(event);
int count = event.getPointerCount();
float[] x = new float [count];
float[] y = new float [count];
int[] id = new int[count];
for (int i = 0; i < count; ++i) {
x = event.getX(i);
y = event.getY(i);
id = event.getPointerId(i);
}
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
ba.raiseEvent(this, eventName + "_touch",x,y,id,MotionEvent.ACTION_POINTER_DOWN);
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
ba.raiseEvent(this, eventName + "_touch",x,y,id,MotionEvent.ACTION_POINTER_UP);
case MotionEvent.ACTION_MOVE:
ba.raiseEvent(this, eventName + "_touch",x,y,id,MotionEvent.ACTION_MOVE);
}
return true;
//
}
});
}
}
public void setController(Controller c) {
getObject().setController(c);
mHandler.postDelayed(updateTimeTask, getObject().getTick());
}
I have attached a demo of the application I am attempting to wrap.
I want to be able to have this library incorporated within my B4A application and have the view respond to touches (zoom in and out, maybe draw circles on the view)
I would appreciate any tip and help right now I have been stuck banging my head on this for a week.
I can raise events when the user touches the view however I can't get the view render/update itself. I read about multithreading and the renderer running in a seperate thread however I don't have much experience with this and it is a fairly complicated code I need some guidance with this.
*code snippet for my ViewWrapper
@ShortName("Viewport2DView")
@Events(values={"Touch(f1() as float, f2() As float, id() as Int,action as Int )"})
public class Viewport2DView extends ViewWrapper<osas.track24.intermaphics.Viewport2DView> {
private BA ba;
private String eventName;
private Handler mHandler = new Handler();
private GestureDetector detector;
public void Initialize(BA pBA, String EventName) {
eventName = EventName.toLowerCase(BA.cul);
ba = pBA;
innerInitialize(pBA, EventName.toLowerCase(BA.cul), false);
}
@Hide
public void innerInitialize(BA pBA, String pEventName, boolean pKeepOldObject) {
if (!pKeepOldObject) {
setObject(new osas.track24.intermaphics.Viewport2DView(pBA.context));
detector = new GestureDetector(getObject(), mHandler);
detector.setOnDoubleTapListener(getObject());
super.innerInitialize(pBA, pEventName, pKeepOldObject);
getObject().setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
detector.onTouchEvent(event);
int count = event.getPointerCount();
float[] x = new float [count];
float[] y = new float [count];
int[] id = new int[count];
for (int i = 0; i < count; ++i) {
x = event.getX(i);
y = event.getY(i);
id = event.getPointerId(i);
}
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
ba.raiseEvent(this, eventName + "_touch",x,y,id,MotionEvent.ACTION_POINTER_DOWN);
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
ba.raiseEvent(this, eventName + "_touch",x,y,id,MotionEvent.ACTION_POINTER_UP);
case MotionEvent.ACTION_MOVE:
ba.raiseEvent(this, eventName + "_touch",x,y,id,MotionEvent.ACTION_MOVE);
}
return true;
//
}
});
}
}
public void setController(Controller c) {
getObject().setController(c);
mHandler.postDelayed(updateTimeTask, getObject().getTick());
}
I have attached a demo of the application I am attempting to wrap.
I want to be able to have this library incorporated within my B4A application and have the view respond to touches (zoom in and out, maybe draw circles on the view)
I would appreciate any tip and help right now I have been stuck banging my head on this for a week.