×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    How to disable long click event on touch screen phone?

    I develop map app on Canvas with commands as main menu. And when I long click on canvas it opens commands as floating menu. How to disable this?

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: How to disable long click event on touch screen phone?

    Hi noksi and welcome to Nokia's discussion boards,

    Which API are you using for creating your map application? Is it the Nokia Maps API for Java ME, or is it some other external API?
    Can you provide a code sample, or code snippet of what you are trying to do?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    Re: How to disable long click event on touch screen phone?

    I use some map SDK which isn't Nokia maps(www.nutiteq.com). Like I said I have one canvas, and on that canvas I add several commands. All commands are created like private Command findMe = new Command("Find me", Command.ITEM, 0); only for exit command private Command exit = new Command("Exit", Command.EXIT, 0); I add this commands and it's all OK but on Nokia touch screen phone when I long click on canvas it start to handle this event and after second or two it opens context menu. I want to disable this because I have some POI on map and it's hard to click on this POI because you must be quick otherwise it will start to handle long click event not POI click event.

    When I add only two commands then they are on two soft key, and there isn't context menu when I long click. With 3 and more commands it always shows this commands when I long click. I try with some jad values but I think there isn't jad values for this. If you don't understand where is my problem I will upload some screen capture with context menu. I read a lot on Nokia site and find that on canvas commands has this default behavior but I can't find how to disable this.

  4. #4
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    125

    Re: How to disable long click event on touch screen phone?

    Hi,

    Are you working on Symbian 5ed with eSWT ? If yes, I had posted this :

    http://www.developer.nokia.com/Commu...WT-and-Tactile

    Thanks
    Last edited by frasene; 2011-11-28 at 21:08.

  5. #5
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: How to disable long click event on touch screen phone?

    Hi noksi,

    I created a small application with Nutiteq's Maps for Series 40 Touch and Type devices, where tapping (short press) zooms out and long pressing, zooms in. I didn't get the context menu interfere with my long pressing. This is the code I used:

    Mapper.java:
    Code:
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
     
    import com.nutiteq.log.Log;
     
    public class Mapper extends MIDlet {
     
        public static Mapper instance;
        private MapScreen screen;
     
        public Mapper() {
            instance = this;
        }
     
        protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
            screen = null;
            instance.notifyDestroyed();
            instance = null;
        }
     
        protected void pauseApp() {
     
        }
     
        protected void startApp() throws MIDletStateChangeException {
            Log.enableAll();
            if (screen == null) {
              screen = new MapScreen();
            }
            Display.getDisplay(this).setCurrent(screen);
            screen.repaint();
        }
    }

    MapScreen.java:
    Code:
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.midlet.MIDletStateChangeException;
     
    import com.nutiteq.MapComponent;
    import com.nutiteq.components.WgsPoint;
    import com.nutiteq.controls.MGMapsKeysHandler;
    import com.nutiteq.listeners.MapListener;
     
    import com.nokia.mid.ui.gestures.GestureEvent;
    import com.nokia.mid.ui.gestures.GestureInteractiveZone;
    import com.nokia.mid.ui.gestures.GestureListener;
    import com.nokia.mid.ui.gestures.GestureRegistrationManager;
    public class MapScreen extends Canvas implements CommandListener, MapListener, GestureListener {
        public static MapScreen instance;
        private final MapComponent map;
        private final Command exit = new Command("Exit", Command.EXIT, 0);
        private final Command but1 = new Command("Item1", Command.ITEM,1);
        private final Command but2 = new Command("Item2", Command.ITEM,2);
        private final Command but3 = new Command("Item3", Command.ITEM,3);
        private final Command but4 = new Command("Item4", Command.ITEM,4);
        public MapScreen() {
            instance = this;
     
            // 1. initialize map object, also set initial location and zoom
            // Note that default map source will be OpenStreetMap (Mapnik tiles)
            map = new MapComponent("Your_LICENSE_KEY_HERE", Mapper.instance, getWidth(),
                    getHeight(), new WgsPoint(24.764580, 59.437420), 10);
     
            // 2. define keycode handler for keypresses.
            // We use a default set (arrows and 2468 for moving, # for zoom in, *
            // for zoom out)
            // you can define own keys instead of this
            MGMapsKeysHandler keyHandler = new MGMapsKeysHandler();
            map.setControlKeysHandler(keyHandler);
     
            // 3. set this class to listen map events: needRepaint, mapMoved and
            // mapClicked
            map.setMapListener(this);
     
            // 4. show default location pointer
            map.showDefaultCursor();
     
            // 5. start mapping threads and tasks in the library
            map.startMapping();
     
            // add Exit command to the midlet menu
            addCommand(exit);
            addCommand(but1);
            addCommand(but2);
            addCommand(but3);
            addCommand(but4);
            setCommandListener(this);
            GestureInteractiveZone giz = new GestureInteractiveZone( GestureInteractiveZone.GESTURE_ALL );
            
            GestureRegistrationManager.register(this,giz);
            GestureRegistrationManager.setListener(this, this);
        }
     
        protected void paint(Graphics g) {
            // 6. define to repaint of map
        	com.nutiteq.wrappers.Graphics graphicsWrapper = new com.nutiteq.wrappers.Graphics(g);
        	map.paint(graphicsWrapper);
        }
     
        // 7. Forward keypressing events to library using following methods
        protected void keyPressed(final int keyCode) {
        	System.out.println(keyCode);
            map.keyPressed(keyCode);
        }
     
        protected void keyReleased(final int keyCode) {
            map.keyReleased(keyCode);
        }
     
        protected void keyRepeated(final int keyCode) {
            map.keyRepeated(keyCode);
        }
     
        // Basic handler for Midlet menu action
        public void commandAction(Command c, Displayable d) {
     
            if (c == exit) {
       // 8. stop mapping properly before terminating Midlet.
       // NB! do not forget it, otherwise RMS cache index is not updated
                map.stopMapping();
                try {
                    Mapper.instance.destroyApp(true);
                } catch (final MIDletStateChangeException ignore) {
                }
            }
        }
     
        // 9. Handlers for MapListener
        public void mapClicked(WgsPoint pnt) {
        }
     
        public void mapMoved() {
        }
     
        public void needRepaint(boolean downloadReady) {
            // 10. This repaint call is mandatory, otherwise map is not refreshed!
            repaint();
        }
    
    	public void gestureAction(Object container,
    			GestureInteractiveZone gestureInteractiveZone,
    			GestureEvent gestureEvent) {
    		if(gestureEvent.getType()==GestureInteractiveZone.GESTURE_LONG_PRESS)
    		{
    			map.keyPressed(35);
    		}
    		if(gestureEvent.getType()==GestureInteractiveZone.GESTURE_TAP)
    		{
    			map.keyPressed(42);
    		}
    	}
     
    }
    Which device and platform are you using? Could you provide a full code sample?
    Last edited by skalogir; 2011-11-30 at 07:23.

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    Re: How to disable long click event on touch screen phone?

    I use Nokia X6 and also try on some other Nokia phones. On phone with resistive touch screen it's almost imposible to click on place if context menu opens. You must be very quick, it's not problem for me but for average user this must be disabled.

    I didn't use GestureListener and never heard for this listener. If you don't use this listener then it will open context menu. What should I add to my project some Nokia lib, because eclipse can't recognize imports for gestures. And on non Nokia phone(J2ME) does this code work or it will crash? Thanks for your answer.

    If you try this code:
    Code:
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    import com.nutiteq.MapComponent;
    import com.nutiteq.components.WgsPoint;
    import com.nutiteq.controls.MGMapsKeysHandler;
    import com.nutiteq.listeners.MapListener;
    import com.nutiteq.ui.DefaultCursor;
    
    public class MapScreen extends Canvas implements CommandListener, MapListener {
    
    	public static MapScreen instance;
    
    	private final MapComponent map;
    
    	private final Command exit = new Command("Exit", Command.EXIT, 0);
    	private final Command but1 = new Command("Item1", Command.ITEM, 1);
    	private final Command but2 = new Command("Item2", Command.ITEM, 2);
    	private final Command but3 = new Command("Item3", Command.ITEM, 3);
    	private final Command but4 = new Command("Item4", Command.ITEM, 4);
    
    	private com.nutiteq.wrappers.Graphics graphicsWrapper;
    
    	public MapScreen() {
    		instance = this;
    
    		map = new MapComponent(
    				"LICENCE",
    				Mapper.instance, getWidth(), getHeight(), new WgsPoint(
    						20.466027, 44.810537), 12);
    
    		MGMapsKeysHandler keyHandler = new MGMapsKeysHandler();
    		map.setControlKeysHandler(keyHandler);
    
    		map.setMapListener(this);
    
    		map.showZoomLevelIndicator(true);
    
    		if (hasPointerEvents()) {
    			setFullScreenMode(false);
    
    			map.setTouchClickTolerance(25);
    			map.showDefaultOnScreenZoomControls();
    		} else {
    			setFullScreenMode(true);
    
    			map.setCursor(new DefaultCursor(0xFFFF0000));
    		}
    
    		map.startMapping();
    
    		addCommand(exit);
    		addCommand(but1);
    		addCommand(but2);
    		addCommand(but3);
    		addCommand(but4);
    		setCommandListener(this);
    
    	}
    
    	protected void paint(Graphics g) {
    		if (graphicsWrapper == null)
    			graphicsWrapper = new com.nutiteq.wrappers.Graphics(g);
    
    		map.paint(graphicsWrapper);
    	}
    
    	protected void keyPressed(final int keyCode) {
    		map.keyPressed(keyCode);
    	}
    
    	protected void keyReleased(final int keyCode) {
    		map.keyReleased(keyCode);
    	}
    
    	protected void keyRepeated(final int keyCode) {
    		map.keyRepeated(keyCode);
    	}
    
    	protected void pointerPressed(int x, int y) {
    		map.pointerPressed(x, y);
    	}
    
    	protected void pointerDragged(int x, int y) {
    		map.pointerDragged(x, y);
    	}
    
    	protected void pointerReleased(int x, int y) {
    		map.pointerReleased(x, y);
    	}
    
    	public void commandAction(Command c, Displayable d) {
    
    		if (c == exit) {
    			map.stopMapping();
    			try {
    				Mapper.instance.destroyApp(true);
    			} catch (final MIDletStateChangeException ignore) {
    			}
    		}
    	}
    
    	public void mapClicked(WgsPoint pnt) {
    	}
    
    	public void mapMoved() {
    	}
    
    	public void needRepaint(boolean downloadReady) {
    		repaint();
    	}
    
    }
    then you will see context menu on touch screen phone. http://imageshack.us/photo/my-images/256/scr000084.png/

    Also I want backlight to be always turned on when my app is running. I do this with this code:
    Code:
    Timer backlight = new Timer();
    backlight.schedule(new TimerTask() {
    public void run() {
    	Display.getDisplay(Mapper.instance).flashBacklight(1);
    	}
    }, 0, 10000);
    and this works, but probably isn't best solution.
    Last edited by noksi; 2011-11-30 at 15:45.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: How to disable long click event on touch screen phone?

    Hi All,
    I am also facing the same issue.
    It becomes a serious issue for me.
    Please help me how to disable this pop up for Option's commands with long keypress on canvas.

    Please guide me...

    Thanks & Regards,
    Ajit

  8. #8
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: How to disable long click event on touch screen phone?

    Thanks for sharing your code.

    Regarding your fist problem of getting the pop up menu with the commands when you long press, you can use this code instead:
    Code:
    	private final Command exit = new Command("Exit", Command.EXIT, 0);
    	private final Command but1 = new Command("Item1", Command.SCREEN, 1);
    	private final Command but2 = new Command("Item2", Command.SCREEN, 2);
    	private final Command but3 = new Command("Item3", Command.SCREEN, 3);
    	private final Command but4 = new Command("Item4", Command.SCREEN, 4);
    Regarding setting the screen's light always on, you can use this code:

    Code:
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    import com.nokia.mid.ui.DeviceControl;
    import com.nutiteq.MapComponent;
    import com.nutiteq.components.WgsPoint;
    import com.nutiteq.controls.MGMapsKeysHandler;
    import com.nutiteq.listeners.MapListener;
    import com.nutiteq.ui.DefaultCursor;
    
    public class MapScreen extends Canvas implements CommandListener, MapListener,Runnable {
    
    	public static MapScreen instance;
    
    	private final MapComponent map;
    
    	private final Command exit = new Command("Exit", Command.EXIT, 0);
    	private final Command but1 = new Command("Item1", Command.SCREEN, 1);
    	private final Command but2 = new Command("Item2", Command.SCREEN, 2);
    	private final Command but3 = new Command("Item3", Command.SCREEN, 3);
    	private final Command but4 = new Command("Item4", Command.SCREEN, 4);
    
    	private com.nutiteq.wrappers.Graphics graphicsWrapper;
    	Thread thread;
    	
    	public MapScreen() {
    		instance = this;
    
    		map = new MapComponent(
    				"YOUR LICENCE HERE",
    				Mapper.instance, getWidth(), getHeight(), new WgsPoint(
    						20.466027, 44.810537), 12);
    
    		MGMapsKeysHandler keyHandler = new MGMapsKeysHandler();
    		map.setControlKeysHandler(keyHandler);
    
    		map.setMapListener(this);
    
    		map.showZoomLevelIndicator(true);
    
    		if (hasPointerEvents()) {
    			setFullScreenMode(false);
    
    			map.setTouchClickTolerance(25);
    			map.showDefaultOnScreenZoomControls();
    		} else {
    			setFullScreenMode(true);
    
    			map.setCursor(new DefaultCursor(0xFFFF0000));
    		}
    
    		map.startMapping();
    
    		addCommand(exit);
    		addCommand(but1);
    		addCommand(but2);
    		addCommand(but3);
    		addCommand(but4);
    		setCommandListener(this);
    		thread=new Thread(this);
    		thread.start();
    
    	}
    
    	protected void paint(Graphics g) {
    		if (graphicsWrapper == null)
    			graphicsWrapper = new com.nutiteq.wrappers.Graphics(g);
    
    		map.paint(graphicsWrapper);
    	}
    
    	protected void keyPressed(final int keyCode) {
    		map.keyPressed(keyCode);
    	}
    
    	protected void keyReleased(final int keyCode) {
    		map.keyReleased(keyCode);
    	}
    
    	protected void keyRepeated(final int keyCode) {
    		map.keyRepeated(keyCode);
    	}
    
    	protected void pointerPressed(int x, int y) {
    		map.pointerPressed(x, y);
    	}
    
    	protected void pointerDragged(int x, int y) {
    		map.pointerDragged(x, y);
    	}
    
    	protected void pointerReleased(int x, int y) {
    		map.pointerReleased(x, y);
    	}
    
    	public void commandAction(Command c, Displayable d) {
    
    		if (c == exit) {
    			map.stopMapping();
    			try {
    				Mapper.instance.destroyApp(true);
    			} catch (final MIDletStateChangeException ignore) {
    			}
    		}
    	}
    
    	public void mapClicked(WgsPoint pnt) {
    	}
    
    	public void mapMoved() {
    	}
    
    	public void needRepaint(boolean downloadReady) {
    		repaint();
    	}
    
    	  public void run() {
    		    while(true) {
    		      DeviceControl.resetUserInactivityTime();   // reseting all user inactivity timers
    		      try {
    		        Thread.sleep(4000);   // minimum screen saver timeout in UI is 5 seconds
    		      } catch (InterruptedException e) {
    		      }
    		    }
    		  }
    
    }
    more about this here:
    http://library.developer.nokia.com/i...67FACB836.html

    The Gesture API is indeed for Series 40 Touch and Type devices, so you cannot really use it on your Symbian device, and you are most likely using a Symbian SDK, that's why eclipse cannot recognize the code. Generally speaking, when it comes to making your touch application as much compatible as possible, high-level UI components are platform specific, and they should be preferred, while low-level UI components are device-specific.

    You can read more about this here:
    http://library.developer.nokia.com/i...1AFFB65F3.html

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    Re: How to disable long click event on touch screen phone?

    Thanks. I am 100% sure that I try with SCREEN commands but it didn't work or probably I made some mistake. Now everything is fine. Thanks again.

Similar Threads

  1. calling a widget screen from a click event.
    By kathir.s in forum [Archived] Beginning Qt
    Replies: 1
    Last Post: 2011-09-27, 16:22
  2. Touch/Click event over QVideoWidget
    By roguel6 in forum Qt
    Replies: 4
    Last Post: 2011-01-21, 15:46
  3. Replies: 5
    Last Post: 2009-11-06, 11:13
  4. Image click Event in mobiles without touch screen
    By swarna.nokia in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2009-06-16, 14:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×