Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[patch] Java client improvements

alex
2010-03-02
2012-12-10
  • alex
    alex
    2010-03-02

    Hello!

    I use Windows Mobile touchscreen device. I didn't like that I have to click a button on screen to select it and then I must click it again to get it pressed. Also I didn't like lists behavior - it was hard to scroll. So, here is the patch.

    diff -ruN anyremote-j2me-client-4.19/src/CanvasScreen.java anyremote-j2me-client-4.19.new/src/CanvasScreen.java
    -- anyremote-j2me-client-4.19/src/CanvasScreen.java    2010-02-11 10:46:39.000000000 +0200                   
    +++ anyremote-j2me-client-4.19.new/src/CanvasScreen.java        2010-03-02 16:26:06.000000000 +0200           
    @@ -51,6 +51,8 @@                                                                                             
                                                                                                                  
            static final int TICKER_CYCLE   = 50;                                                                 
                                                                                                                  
    +       static final long DRAG_TIMEOUT  = 100;                                                                
    +                                                                                                             
             Graphics       gr;                                                                                   
             int            scr;                                                                                  
             int            CW;                                                                                   
    @@ -68,8 +70,9 @@                                                                                             
             WinManager     wm;                                                                                   
             Controller     controller;                                                                           
                                                                                                                  
    -        int     px;                                                                                          
    -        int     py;                                                                                          
    +        int     px,dx;                                                                                       
    +        int     py,dy;                                                                                       
    +        long   pressTime = 0;                                                                                
                                                                                                                  
            CanvasConsumer currentScreen;                                                                         
                                                                                                                  
    @@ -576,21 +579,42 @@                                                                                         
            }                                                                                                     
                                                                                                                  
            protected void pointerPressed(int x, int y) {                                                         
    +               dx = x;                                                                                       
    +               dy = y;                                                                                       
                    px = x;                                                                                       
                     py = y;                                                                                      
    -               currentScreen.pointerPressed(x,y);                                                            
    +                pressTime = System.currentTimeMillis();                                                      
            }                                                                                                     
                                                                                                                  
            protected void pointerReleased(int x, int y) {                                                        
    +               long now = System.currentTimeMillis();                                                        
    +                                                                                                             
    +               if (now - pressTime < DRAG_TIMEOUT)                                                           
    +                   currentScreen.pointerPressed(x,y);                                                        
    +                                                                                                             
                    currentScreen.pointerReleased(x,y);                                                           
    +                                                                                                             
    +               pressTime = 0;                                                                                
                     px = -1;                                                                                     
                     py = -1;                                                                                     
            }                                                                                                     
                                                                                                                  
            protected void pointerDragged(int x, int y) {
    -               currentScreen.pointerDragged(x,y);
    -               px = x;
    -                py = y;
    +               int Dx = dx - x;
    +               int Dy = dy - y;
    +               dx = x;
    +               dy = y;
    +               long now = System.currentTimeMillis();
    +
    +               if (pressTime <= 0) return;
    +
    +               if (now - pressTime < DRAG_TIMEOUT) return;
    +
    +               if (Math.abs(Dy) < 2) {
    +                   currentScreen.pointerPressed(x,y);
    +               } else {
    +                   currentScreen.pointerDragged(px-Dx,py-Dy);
    +               }
            }

            public void commandAction(Command cmd, Displayable d) {
    diff -ruN anyremote-j2me-client-4.19/src/ControlForm.java anyremote-j2me-client-4.19.new/src/ControlForm.java
    -- anyremote-j2me-client-4.19/src/ControlForm.java     2010-02-15 19:07:15.000000000 +0200
    +++ anyremote-j2me-client-4.19.new/src/ControlForm.java 2010-03-02 17:10:12.000000000 +0200
    @@ -932,7 +932,6 @@
                    int ic = getButton(x,y);

                    if (ic >= 0 && curIcon != ic) {
    -                       skipPress = true;
                            curIcon = ic;
                            drawScreen();
                    }

     
  • Mike
    Mike
    2010-03-04

    Thanks!
    i'm going to integrate patch to v4.20

     
  • alex
    alex
    2010-03-04

    Please wait! I just found that this patch alters fundamental ControlForm behavior.

     
  • Mike
    Mike
    2010-03-05

    >I just found that this patch alters fundamental ControlForm behavior.
    Which one ?

     
  • alex
    alex
    2010-03-05

    Which one ?

    I was not able to drag cursor over buttons. I already found the problem. ControlForm needs original drag algorithm. I wrote a patch that works but I have some problems with coding style.

    To differ between classes that need original drag algorithm and classes that need new algorithm I can use a class property or class method. ControlForm, ListForm, etc implements Canvas Consumer interface.

    If I use class property, I have to use an abstract class to define it for all classes:

    interface ICanvasConsumer {
    ...
    }
    public abstract class CanvasConsumer implements ICanvasConsumer {
            public static boolean CLASSIC_DRAG = false;
    }
    

    And I have to rewrote all classes definition to similar:

    public class ControlForm extends CanvasConsumer {
    ...
    }
    

    and so on.

    If I use class method, changes to interface CanvasConsumer and classes that implement CanvasConsumer will be minimal:

    public interface CanvasConsumer {
     public void useClassicDrag();
    ...
    }
    

    Then I define this method only in ControlForm class. But when I call this method I have to check for it existence with try {} catch {} in CanvasScreen.pointerDragged() . Or I can define that method in all classes, but I think it's not rational.

    Which way is closer to the whole coding style of anyRemote java client?

     
  • Mike
    Mike
    2010-03-05

    IMHO the question is not coding _style_, but the size of resulting *jar file :-)

     
  • alex
    alex
    2010-03-05

    I got it :) And I've forgot about performance. The second way is slower.
    And here goes the patch

    diff -ruN anyremote-j2me-client-4.19/src/CanvasConsumer.java anyremote-j2me-client-4.19.new/src/CanvasConsumer.java
    --- anyremote-j2me-client-4.19/src/CanvasConsumer.java  2010-02-11 10:46:28.000000000 +0200                        
    +++ anyremote-j2me-client-4.19.new/src/CanvasConsumer.java      2010-03-03 16:13:24.000000000 +0200                
    @@ -23,7 +23,7 @@                                                                                                  
     import javax.microedition.lcdui.Command;                                                                          
     import javax.microedition.lcdui.Displayable;                                                                      
                                                                                                                       
    -public interface CanvasConsumer {                                                                                 
    +interface ICanvasConsumer {                                                                                       
                                                                                                                       
             void showScreen();                                                                                        
            void hideScreen();                                                                                         
    @@ -44,6 +44,10 @@                                                                                                 
            static final int FIRST    = 1;                                                                             
            static final int INTERMED = 2;                                                                             
            static final int LAST     = 3;                                                                             
    -                                                                                                                  
    +                                                                                                                  
            public void setData(Vector chunk, int stage);                                                              
     }                                                                                                                 
    +                                                                                                                  
    +public abstract class CanvasConsumer implements ICanvasConsumer {                                                 
    +       public static boolean CLASSIC_DRAG = false;                                                                
    +}                                                                                                                 
    diff -ruN anyremote-j2me-client-4.19/src/CanvasScreen.java anyremote-j2me-client-4.19.new/src/CanvasScreen.java    
    --- anyremote-j2me-client-4.19/src/CanvasScreen.java    2010-02-11 10:46:39.000000000 +0200                        
    +++ anyremote-j2me-client-4.19.new/src/CanvasScreen.java        2010-03-05 13:56:53.000000000 +0200                
    @@ -51,6 +51,8 @@                                                                                                  
                                                                                                                       
            static final int TICKER_CYCLE   = 50;                                                                      
                                                                                                                       
    +       static final long DRAG_TIMEOUT  = 100;                                                                     
    +                                                                                                                  
             Graphics       gr;                                                                                        
             int            scr;                                                                                       
             int            CW;                                                                                        
    @@ -68,8 +70,9 @@                                                                                                  
             WinManager     wm;                                                                                        
             Controller     controller;                                                                                
                                                                                                                       
    -        int     px;                                                                                               
    -        int     py;                                                                                               
    +        int     px,dx;                                                                                            
    +        int     py,dy;                                                                                            
    +        long   pressTime = 0;                                                                                     
                                                                                                                       
            CanvasConsumer currentScreen;                                                                              
                                                                                                                       
    @@ -576,21 +579,46 @@                                                                                              
            }                                                                                                          
                                                                                                                       
            protected void pointerPressed(int x, int y) {                                                              
    +               dx = x;                                                                                            
    +               dy = y;                                                                                            
                    px = x;                                                                                            
                     py = y;                                                                                           
    -               currentScreen.pointerPressed(x,y);                                                                 
    +                pressTime = System.currentTimeMillis();                                                           
            }                                                                                                          
                                                                                                                       
            protected void pointerReleased(int x, int y) {                                                             
    +               long now = System.currentTimeMillis();                                                             
    +                                                                                                                  
    +               if (now - pressTime < DRAG_TIMEOUT)                                                                
    +                   currentScreen.pointerPressed(x,y);                                                             
    +                                                                                                                  
                    currentScreen.pointerReleased(x,y);                                                                
    +                                                                                                                  
    +               pressTime = 0;                                                                                     
                     px = -1;                                                                                          
                     py = -1;                                                                                          
            }                                                                                                          
                                                                                                                       
            protected void pointerDragged(int x, int y) {                                                              
    -               currentScreen.pointerDragged(x,y);                                                                 
    -               px = x;                                                                                            
    -                py = y;                                                                                           
    +               int Dx = dx - x;                                                                                   
    +               int Dy = dy - y;                                                                                   
    +               dx = x;                                                                                            
    +               dy = y;                                                                                            
    +               long now = System.currentTimeMillis();                                                             
    +                                                                                                                  
    +               if (pressTime <= 0) return;                                                                        
    +                                                                                                                  
    +               if (now - pressTime < DRAG_TIMEOUT) return;                                                        
    +                                                                                                                  
    +               if (Math.abs(Dy) < 2) {                                                                            
    +                   currentScreen.pointerPressed(x,y);                                                             
    +               } else {                                                                                           
    +                   if (!currentScreen.CLASSIC_DRAG) {                                                             
    +                       x = px-Dx;                                                                                 
    +                       y = py-Dy;                                                                                 
    +                   }                                                                                              
    +                      currentScreen.pointerDragged(x,y);                                                          
    +               }                                                                                                  
            }                                                                                                          
                                                                                                                       
            public void commandAction(Command cmd, Displayable d) {                                                    
    diff -ruN anyremote-j2me-client-4.19/src/ControlForm.java anyremote-j2me-client-4.19.new/src/ControlForm.java      
    --- anyremote-j2me-client-4.19/src/ControlForm.java     2010-02-15 19:07:15.000000000 +0200                        
    +++ anyremote-j2me-client-4.19.new/src/ControlForm.java 2010-03-03 16:13:00.000000000 +0200                        
    @@ -27,7 +27,7 @@                                                                                                  
     import javax.microedition.lcdui.Font;                                                                             
     import javax.microedition.lcdui.Displayable;                                                                      
                                                                                                                       
    -public class ControlForm implements CanvasConsumer {                                                              
    +public class ControlForm extends CanvasConsumer {                                                                 
                                                                                                                       
            Controller      controller;                                                                                
                                                                                                                       
    @@ -94,6 +94,7 @@                                                                                                  
                                                                                                                       
            public ControlForm(Controller ctl) {                                                                       
                    //System.out.println("ControlForm --------------------");                                          
    +               CLASSIC_DRAG = true;                                                                               
                    controller  = ctl;                                                                                 
                                                                                                                       
                     useJoystick = true;                                                                               
    @@ -906,12 +907,10 @@                                                                                              
                                                                                                                       
            public void pointerReleased(int x, int y) {                                                                
                    //System.out.println("ControlForm.pointerReleased "+x+" "+y);                                      
    -               if (skipPress) {                                                                                   
    -                       skipPress = false;                                                                         
    -                       return;                                                                                    
    -               }                                                                                                  
                    int ic = getButton(x,y);                                                                           
    +                                                                                                                  
                    if (ic >= 0) {                                                                                     
    +                       curIcon = ic;                                                                              
                            int kcode = num2key(ic);                                                                   
                            if (kcode >= 0) {                                                                          
                                                                                                                       
    @@ -932,7 +931,6 @@                                                                                                
                    int ic = getButton(x,y);                                                                           
                                                                                                                       
                    if (ic >= 0 && curIcon != ic) {                                                                    
    -                       skipPress = true;                                                                          
                            curIcon = ic;                                                                              
                            drawScreen();                                                                              
                    }                                                                                                  
    diff -ruN anyremote-j2me-client-4.19/src/FileManager.java anyremote-j2me-client-4.19.new/src/FileManager.java      
    --- anyremote-j2me-client-4.19/src/FileManager.java     2010-02-11 10:46:56.000000000 +0200                        
    +++ anyremote-j2me-client-4.19.new/src/FileManager.java 2010-03-03 16:09:17.000000000 +0200                        
    @@ -26,7 +26,7 @@                                                                                                  
     import javax.microedition.lcdui.Graphics;                                                                         
     import javax.microedition.lcdui.Font;                                                                             
                                                                                                                       
    -public class FileManager implements CanvasConsumer  {                                                             
    +public class FileManager extends CanvasConsumer  {                                                                
            Controller  controller;                                                                                    
                                                                                                                       
            Command     cd;                                                                                            
    diff -ruN anyremote-j2me-client-4.19/src/ListForm.java anyremote-j2me-client-4.19.new/src/ListForm.java            
    --- anyremote-j2me-client-4.19/src/ListForm.java        2010-02-11 10:47:04.000000000 +0200                        
    +++ anyremote-j2me-client-4.19.new/src/ListForm.java    2010-03-03 16:09:22.000000000 +0200                        
    @@ -27,7 +27,7 @@
     import javax.microedition.lcdui.Font;
     import javax.microedition.lcdui.Graphics;
    -public class ListForm implements CanvasConsumer  {
    +public class ListForm extends CanvasConsumer  {
            Controller  controller;
             String      caption;
    diff -ruN anyremote-j2me-client-4.19/src/TextScreen.java anyremote-j2me-client-4.19.new/src/TextScreen.java
    --- anyremote-j2me-client-4.19/src/TextScreen.java      2010-02-11 10:47:15.000000000 +0200
    +++ anyremote-j2me-client-4.19.new/src/TextScreen.java  2010-03-03 16:09:30.000000000 +0200
    @@ -26,7 +26,7 @@
     import javax.microedition.lcdui.Graphics;
     import javax.microedition.lcdui.Font;
    -public class TextScreen implements CanvasConsumer {
    +public class TextScreen extends CanvasConsumer {
            static final int ADD     = 1;
            static final int REPLACE = 2;
    diff -ruN anyremote-j2me-client-4.19/src/WinManager.java anyremote-j2me-client-4.19.new/src/WinManager.java
    --- anyremote-j2me-client-4.19/src/WinManager.java      2010-02-15 18:54:55.000000000 +0200
    +++ anyremote-j2me-client-4.19.new/src/WinManager.java  2010-03-03 16:09:33.000000000 +0200
    @@ -30,7 +30,7 @@
     import javax.microedition.lcdui.Image;
     import javax.microedition.lcdui.Displayable;
    -public class WinManager implements CanvasConsumer {
    +public class WinManager extends CanvasConsumer {
            Controller      controller;
            Command         back;
    
     
  • Mike
    Mike
    2010-03-05

    Thank You for fixing that.
    Unfortunalely the latest version works a bit strange with a lists
    (i did not have touchscreen device and test it under Sun WTK)
    Also, please, send the following mails to anyremote at mail.ru directly.