ImageViewer

This example MIDlet shows you how to use the features of the FileConnection API (FC API) to navigate the device file system and access files. The features are demonstrated in the context of a basic image viewer MIDlet, which implements a file browser for navigating the device file system and selecting images to view on the device screen.

ImageViewer on touch and type platform

ImageViewer on full touch platform

To optimize the ImageViewer MIDlet for the full touch UI:

  1. Add orientation support for text writing in landscape mode

    Modify the ImageCanvas class.

    /** 
     *  Orientation is supported for Java Runtime 2.0.0 for Series 40 onwards. 
     *  Registers the orientation listener. Applications that need information about events related 
     *  to display orientation changes need to register with Orientation to get notifications of the events.
     */
    Orientation.addOrientationListener(this);
      
    /**  
     * Orientation is supported for Java Runtime 2.0.0 for Series 40 onwards. 
     * Called when display's orientation has changed. 
     */
     public void displayOrientationChanged( int newDisplayOrientation ){
                /** Change MIDlet UI orientation */
                Orientation.setAppOrientation(newDisplayOrientation );        
    }
    
  2. Add pinch effect with zooming

    /**
     * Initializes gestures and set it to receive gesture events
     */
    public void initializeGesture() {
    
    	/** Set the listener to register events for ImageCanvas (this,) and register the GestureListener for the UI element (,this) */
    	GestureRegistrationManager.setListener(this, this);
    
    	/** Create an interactive zone and set it to receive taps */
    	GestureInteractiveZone myGestureZone = new GestureInteractiveZone(GestureInteractiveZone.GESTURE_PINCH);
    
    	/** Set the interactive zone to also receive other events */
    	//myGestureZone.setGestures(GestureInteractiveZone.GESTURE_ALL);
    
    	/** Set the location (relative to the container) and size of the interactive zone: */
    	myGestureZone.setRectangle(0, 0, getWidth(), getHeight());
    
    	/** Register the interactive zone for GestureCanvas (this) */
    	GestureRegistrationManager.register(this, myGestureZone);
    }	
    
    /** 
     * Defines the gestureAction method for the class. This method is called every time a gesture event occurs 
     * for a UI element that uses GestureListener. The method is called with all the information related to the gesture event.
     */
    public void gestureAction(Object arg0, GestureInteractiveZone arg1,GestureEvent gestureEvent) {
    
    	switch (gestureEvent.getType()) {
    
    	/**
    	 * This gesture event is supported from Java Runtime 2.0.0 for Series 40 onwards.
    	 * Receives pinch events and check the pinch distance change to scale the current image.
    	 */
    	case GestureInteractiveZone.GESTURE_PINCH:
    		if (gestureEvent.getPinchDistanceChange() < 0) {
    			scaleImage(-0.1f);
    		} else if (gestureEvent.getPinchDistanceChange() > 0) {
    			scaleImage(0.1f);
    		}
    		repaint();
    		break;
    
    	default:
    		break;
    	}
    	
    }
    
  3. Remove openkeypad from the action commands

            if (System.getProperty("com.nokia.keyboard.type").equals("None")) {
                VirtualKeyboard.hideOpenKeypadCommand(true);
            }
    

Download ImageViewer