Новое в разработке на Java


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Новое в разработке на Java

  1. 1. Series 40 Java1
  2. 2. Touch and Type
  3. 3. Touch Gestures Single Tap Long Press Long Press Repeated Drag Drop Flick
  4. 4. Non Touch and Type MIDlets Standard LCDUI screens (Alert, Form, List, TextBox) Canvas • No pointerXXX methods  • Has ponterXXX methods ?
  5. 5. Inline/Native Aligned—TextField import com.nokia.mid.ui.LCDUIUtil; LCDUIUtil.setObjectTrait( textField,“nokia.ui.s40.item.substate”, new Boolean(true) );
  6. 6. Gesture API“To use platform specific defined touch gestures and align with the platform look and feel.”
  7. 7. Class Diagram
  8. 8. Usage – step 1• Create a GestureInteractiveZone// Create a GestureInteractiveZone for all Gesture TypesGestureInteractiveZone giz = new GestureInteractiveZone( GestureInteractiveZone.GESTURE_ALL );// set bounding rectangle of zone.giz.setRectangle( x, y, width, height);
  9. 9. Usage – step 2// Define a GestureListenerClass GestureCanvas extends Canvas implements GestureListener{ protected void paint(Graphics g) { … } public void gestureAction( Object container, GestureInteractiveZone zone, GestureEvent event) { ... }}
  10. 10. Usage – step 3• Register the GestureInteractiveZone with the GestureRegistrationManager// Register for Gesture events.Canvas canvas = new GestureCanvas();GestureRegistrationManager.register( canvas, giz );GestureRegistationManager.setListener( canvas, canvas );
  11. 11. Usage – gestureAction in more detailpublic void gestureAction( Object container, GestureInteractiveZone zone, GestureEvent event) { switch( event.getType() ) { case GestureInteractiveZone.GESTURE_TAP: ...; break; case GestureInteractiveZone.GESTURE_LONG_PRESS: case GestureInteractiveZone.GESTURE_LONG_PRESS_REPEATED: case GestureInteractiveZone.GESTURE_DRAG: case GestureInteractiveZone.GESTURE_DROP: case GestureInteractiveZone.GESTURE_FLICK: }}
  12. 12. GestureEvent details Methods int getType() int getStartX() int getStartY() int getDragDistanceX() int getDragDistanceY() float getFlickDirection() returns flick direction in radians int getFlickSpeed() int getFlickSpeedX() int getFlickSpeedY()
  13. 13. Flick Direction • getFlickDirection returns float which is the direction ( in radians )
  14. 14. Frame Animator API―To assist in providing decelerated animations in scrolling UI components.”
  15. 15. Class Diagram
  16. 16. Usage – step 1• Define a GestureListener as before and a FrameAnimatorListenerclass FrameAnimatorCanvas extends Canvas implements FrameAnimatorListener{ public void animate(FrameAnimator frameAnimator, short x, short y, short delta, short deltaX, short deltaY, boolean lastFrame) { . . . }}
  17. 17. Usage – step 2• Register your FrameAnimatorListenerframeAnimator = new FrameAnimator();frameAnimator.register(refX, refY, maxFps, maxPps, this);
  18. 18. More on maxFps and maxPps• maxFps is % of maximum supported frames per second.• maxPps is % of maximum supported pixels per second.• MIDlet gets default values though System properties.System.getProperty( “com.nokia.mid.ui.frameanimator.fps” );System.getProperty( “com.nokia.mid.ui.frameanimator.pps” );
  19. 19. Usage – step 3case GestureInteractiveZone.GESTURE_FLICK: frameAnimator.kineticScroll( event.getFlickSpeed(), FrameAnimator.FRAME_ANIMATOR_FREE_ANGLE, FrameAnimator.FRAME_ANIMATOR_FRICTION_MEDIUM, event.getFlickDirection() );
  20. 20. More InformationVisit Forum Nokia Website to Download SDK | http://forum.nokia.comVisit Forum Nokia Developer Library | http://library.forum.nokia.com
  21. 21. New extensions toLocation API
  22. 22. LocationUtil• The com.nokia.mid.location.LocationUtil class provides an extra mechanism for creating a LocationProvider.• This is an extension to the JSR-179 Location API, which provides the LocationProvider class. class LocationUtils { static LocationProvider LocationUtil.getLocationProvider( int[] preferedMethods, String parameters ); }• The parameters is for additional platform parameters, for now use null.
  23. 23. LocationUtil• The preferedMethods can be a combination of the following definitions of the JSR-179 Location class: MTA_ASSISTED MTA_UNASSISTED MTE_CELLID MTE_SATELLTITE MTE_SHORTRANGE MTY_NETWORKBASED MTY_TERMINALBASED
  24. 24. Cell-ID based location• A MIDlet can obtain approximate location by using the Cell-ID based method.• This method will send to a network based server the cell-id that the phone is connected to. This server will return the known location of that cell-id.• This enabled phones without built in GPS to obtain an approximate Location without requiring a separate Bluetooth GPS device.• Note using Cell-ID based location, the coordinates can vary from a few meters to hundreds of kilometers, depending on the local network deployment and on how much information the backend database has been able to collect for that area.
  25. 25. Cell-ID example code:• Example code:int[] methods = {(Location.MTA_ASSISTED | Location.MTE_CELLID | Location.MTY_NETWORKBASED)};LocationProvider lp = LocationUtil.getLocationProvider(methods, null);Location loc = lp.getLocation(-1);Coordinates coords = loc.getQualifiedCoordinates();double lat = coords.getLatitude();double lng = coords.getLongitude();
  26. 26. Location BasedServices Platform API
  27. 27. The Basics• The Location Based Services Platform is a non resident API.• Use it to include Maps and other location based services in your MIDlets.• Download LBSP.zip from FN [ http://forum.nokia.com/maps ]• This Zip files contains: • The API Javadocs • An Example MIDlet • LBSP.jar• The LBSP.jar implements the API using existing platform API.• This file needs to be included in your MIDlet projects that use this API.
  28. 28. Package overview• The API is divided into four packages. Package Description com.nokia.maps.comon Common classes needed by other packages including Address, ApplicationContext, GeoBoundingBox and GeoCoordinate. com.nokia.maps.map Map package contains classes needed to show and interact with map content and place objects on map. com.nokia.maps.routing Routing package contains classes to calculate route and access route data. PositioningManager provides an easy to get current location information based on GPS device or device cell information. com.nokia.maps.search Search package contains SearchManager for geocoding and reverse geocoding.
  29. 29. The minimal LBSP App• Displaying interactive map to the user is simple as creating MapCanvas instance and setting it as a current displayable:import com.nokia.maps.map.MapCanvas;/** * Minimal MIDP application to show map content to the user. */public class MapMIDlet extends MIDlet { /** * This method is called when the application is started and sets * MapCanvas as a current Displayable. */ protected void startApp() throws MIDletStateChangeException { Display display = Display.getDisplay(this); MapCanvas mapCanvas = new MapCanvas( display ); display.setCurrent(mapCanvas); }}
  30. 30. The minimal LBSP App (screen shots)
  31. 31. The minimal LBSP App (screen shots)
  32. 32. Map
  33. 33. Map Markers• A Marker can be added to a map with the following code:double lat = 51.3;double lng = 0.8;int size = 10;String s = “You are here!”;GeoCoordinate coord = new GeoCoordinate(lat, lng, 0 );MapFactory mapFactory = mapCanvas.getMapFactory();MapStandardMarker marker = mapFactory.createStandardMarker(coord, size, s);mapCanvas.getMapDisplay().addMapObject( marker );
  34. 34. Map Marker (screen shot)
  35. 35. Other Map Markers• The MapFactory class defines other types of Map Markers:MapMarker createMapMarker( GeoCoordinate coordinate, Image image );MapCircle createMapCircle( double radius, GeoCoordinate centre );MapRectangle createMapRectangle( GeoBoundingBox boundingBox );MapPolygon createMapPolygon( GeoCoordinate[] coordinates );MapPolyline createMapOptPolyline( GeoCoordinate[] coordinates );
  36. 36. Search Manager• Places can be searched for with the SearchManager.• You can also look up locations near a specified GeoCoordinate.// Get instance of SearchManagerSearchManager searchManager = SearchManager.getInstance();searchManager.setListener(this);// Look up locations based on a search stringsearchManager.geocode( “Germany,Berlin", null );// Or, get locations at specified GeoCoordinateGeoCoordinate coord = new GeoCoordinate(51.3, 0.8, 0 );searchManager.reverseGeocode( coord );
  37. 37. Routing• RouteManager provides access to Ovi routing service.• Calculating route requires at least two waypoints and wanted modes.• Modes are used to control route calculation features.// Create the waypointsGeoCoordinate start = new GeoCoordinate(51.3, 0.8, 0);GeoCoordinate end = new GeoCoordinate(55.0, 0.0, 0);WaypointParameterList waypoints = new WaypointParameterList();waypoints.addCoordinate(start);waypoints.addCoordinate(end);RouteManager rm = RouteManager.getInstance();rm.setListener(this);// Use default routing modeRoutingMode[] modes = { new RoutingMode() };rm.calculateRoute(waypoints, modes );
  38. 38. Route Listenerpublic void calculateRouteRequestFinished(RouteManager rm) { Route[] routes = rm.getRoutes(); Maneuver m = route[0].getFirstManeuver(); while( m != null ) { String s = m.getInstruction(); … m = m.getNextManeuver(); }}public void routeRequestError(RouteManager rm, Throwable error) { // handle error condition}public void routeResponseCleared(RouteManager rm) { // route cleared}
  39. 39. Routing Mode• A RoutingMode consists of: • A routing type. • A list of transport modes. • A list of routing options.public RoutingMode(int routingType, int[] transportModes, java.lang.String[] routingOptions);
  40. 40. Routing Types• The Routing Type must be one of the types defined in RoutingType.• These are static ints. RoutingType.DIRECT_DRIVE RoutingType.ECONOMIC RoutingType.FASTEST RoutingType.FASTEST_NOW RoutingType.SCENIC RoutingType.SHORTEST
  41. 41. Transport Modes• The following transport Modes are available. TransportMode.BICYCLE TransportMode.CAR TransportMode.PEDESTRIAN TransportMode.PUBLICTRANSPORT TransportMode.TRUCK
  42. 42. Routing Options• These are string constants defines in RoutingOptions. RoutingOptions.AVOID_BOATFERRY RoutingOptions.AVOID_DIRTROAD RoutingOptions.AVOID_MOTORWAY RoutingOptions.AVOID_PARK RoutingOptions.AVOID_PUBLICTRANSPORT RoutingOptions.AVOID_RAILFERRY RoutingOptions.AVOID_STAIRS RoutingOptions.AVOID_TOLLROAD RoutingOptions.AVOID_TUNNEL RoutingOptions.PREFER_HOVLANENOTE: HOVLANE = High occupancy vehicle lane.
  43. 43. Custom Display• So far the example used a MapCanvas which performs all the Map rendering.• The LBSP API also allows you to use the MapDisplay directly, to provide a greater control on how the Maps are rendered to the canvas.MapFactory mapFactory = MapFactory.createMapFactory( MapDisplayType.TILE_MAP, MapResolutionEnum.MAP_RESOLUTION_128_x_128, getWidth(), getHeight() );MapDisplay map = mapFactory.createMapDisplay();• Display Type can be either: TILE_MAP or VECTOR_MAP• Resolution can be either: 128 x 128 or 256 x 256
  44. 44. Using MapDisplay• You can then render the map on your own Canvas with renderMap(Graphics)protected void paint(Graphics g) { map.renderMap(g);}• Alternatively, you can render the map to an Image instead and then use that Image wherever you like.Image image = Image.createImage( width, height );Graphics g = image.getGraphics();map.renderMap(g);
  45. 45. Custom Display Screen shot
  46. 46. On-Line Resources: forum.nokia.com http://forum.nokia.com/Develop/Java http://forum.nokia.com/Develop/Web
  47. 47. On-Line Resources: forum.nokia.com http://forum.nokia.com/Maps
  48. 48. Thank you!