Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

ANDROID Drag Move bug on SmartGwt

$
0
0
Hi Isomorphic,

I am having a problem with dragmove event (touchmove conversion) on Android Smartphones.

I have a DrawPane with some DrawImage objects attached.

I am trying to rotate one of this drawimage while I drag and move over the drawpane. It works perfectly on all browsers (Firefox, IE, Chrome, Iphone safari,...) but in Android the drag move event is not fired.

Here is the code:

Code:


int lado=100;

DrawPane canvas = new DrawPane();
canvas.setWidth(lado);
canvas.setHeight(lado);
canvas.setCanDrag(true);
canvas.setCursor(Cursor.AUTO);
canvas.bringToFront();

       
       

final DrawImage compas = new DrawImage();
compas.setWidth(lado);
compas.setHeight(lado);
compas.setSrc("new/brujula.png");
compas.setTop(0);
compas.setLeft(0);
compas.setDrawPane(canvas);
compas.draw();
       
DrawImage flecha = new DrawImage();
       
flecha.setWidth(lado);
flecha.setHeight(lado);
flecha.setTop(0);
flecha.setLeft(0);
flecha.setSrc("new/flecha.png");
flecha.setDrawPane(canvas);
       
flecha.draw();
       

canvas.addDragStartHandler(new DragStartHandler() {
               
@Override
public void onDragStart(DragStartEvent event) {
        // TODO Auto-generated method stub
                       

                       
        final double startX = canvas.getAbsoluteLeft()+(lado/2);
        final double startY = canvas.getAbsoluteTop()+(lado/2);
                       
                       
        dragging = true;
        mouseMove = canvas.addDragMoveHandler(new DragMoveHandler() {
                               
                @Override
                public void onDragMove(DragMoveEvent event) {
                        // TODO Auto-generated method stub
                                       
                        try {                                       
                                               
                          double r = Math.atan2(event.getY()-startY,event.getX()-startX);

                        float rotation = (float) Math.toDegrees(r)+90;         

                        rotation = Math.round(rotation);
                                   
                        flecha.rotateTo((int)rotation);
                                   
                        if((int)rotation < 0)
                                valorRumbo = 360 + (int)rotation;
                        else
                                valorRumbo = (int)rotation;

                            } catch (Exception e) {

                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                        }
                                }
                        });
                }
               
        }); 
       
        canvas.addDragStopHandler(new DragStopHandler() {
               
                @Override
                public void onDragStop(DragStopEvent event) {
                        // TODO Auto-generated method stub
                       
       
                        if (dragging){
                          dragging = false;
                          mouseMove.removeHandler();
                      }
                        saveBoatDetail(participanteUser);
                }
        });

I have been working hard to solve it but no success.

I have found on the web that there is a bug on Android with touchmove event that says that this event only fires once on Android. The solution offered by the community is to use the preventdefault method on the touchstart event to force not to use the browser default event settings, so as to avoid this problem.

The problem is that I have checked that Smartgwt events extend the browserevent class so I think using this method would block the DragMove event.

I have used this code trying to use the preventdefault method on the event but no success:

Code:


                Event.addNativePreviewHandler(new NativePreviewHandler() {

                    @Override
                    public void onPreviewNativeEvent(NativePreviewEvent event) {
                   
                          if (event.getNativeEvent().getType() == BrowserEvents.TOUCHSTART)
                         
                          event.getNativeEvent().preventDefault(); //optional
                     
                    }
                });

Would you please tell me if there is a way to block the browser event settings (TouchMove event) on Smartgwt?

Thanks a lot and I am looking forward your news.

Cheers,

Pablo

Viewing all articles
Browse latest Browse all 4756

Trending Articles