Search in sources :

Example 21 with OnEngineInitListener

use of com.here.android.mpa.common.OnEngineInitListener in project here-android-sdk-examples by heremaps.

the class MapFragmentView method initMapFragment.

private void initMapFragment() {
    /* Locate the mapFragment UI element */
    m_mapFragment = getMapFragment();
    // This will use external storage to save map cache data, it is also possible to set
    // private app's path
    String path = new File(m_activity.getExternalFilesDir(null), ".here-map-data").getAbsolutePath();
    // This method will throw IllegalArgumentException if provided path is not writable
    com.here.android.mpa.common.MapSettings.setDiskCacheRootPath(path);
    if (m_mapFragment != null) {
        /* Initialize the AndroidXMapFragment, results will be given via the called back. */
        m_mapFragment.init(new OnEngineInitListener() {

            @Override
            public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                if (error == Error.NONE) {
                    /*
                         * If no error returned from map fragment initialization, the map will be
                         * rendered on screen at this moment.Further actions on map can be provided
                         * by calling Map APIs.
                         */
                    m_map = m_mapFragment.getMap();
                    /*
                         * Set the map center to Berlin Germany.
                         */
                    m_map.setCenter(new GeoCoordinate(52.500556, 13.398889, 0.0), Map.Animation.NONE);
                    /* Set the zoom level. */
                    m_map.setZoomLevel(8);
                } else {
                    new AlertDialog.Builder(m_activity).setMessage("Error : " + error.name() + "\n\n" + error.getDetails()).setTitle(R.string.engine_init_error).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            m_activity.finish();
                        }
                    }).create().show();
                }
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) File(java.io.File)

Example 22 with OnEngineInitListener

use of com.here.android.mpa.common.OnEngineInitListener in project here-android-sdk-examples by heremaps.

the class MapFragmentView method initMapFragment.

private void initMapFragment() {
    /* Locate the mapFragment UI element */
    m_mapFragment = getMapFragment();
    // This will use external storage to save map cache data, it is also possible to set
    // private app's path
    String path = new File(m_activity.getExternalFilesDir(null), ".here-map-data").getAbsolutePath();
    // This method will throw IllegalArgumentException if provided path is not writable
    com.here.android.mpa.common.MapSettings.setDiskCacheRootPath(path);
    if (m_mapFragment != null) {
        /* Initialize the AndroidXMapFragment, results will be given via the called back. */
        m_mapFragment.init(new OnEngineInitListener() {

            @Override
            public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                if (error == Error.NONE) {
                    /*
                     * If no error returned from map fragment initialization, the map will be
                     * rendered on screen at this moment.Further actions on map can be provided
                     * by calling Map APIs.
                     */
                    m_map = m_mapFragment.getMap();
                    /* create an image to mark coordinate when tap event happens */
                    m_marker_image = new Image();
                    try {
                        m_marker_image.setImageResource(R.drawable.marker);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    m_mapFragment.getMapGesture().addOnGestureListener(new MapGesture.OnGestureListener() {

                        @Override
                        public void onPanStart() {
                            showMsg("onPanStart");
                        }

                        @Override
                        public void onPanEnd() {
                            /* show toast message for onPanEnd gesture callback */
                            showMsg("onPanEnd");
                        }

                        @Override
                        public void onMultiFingerManipulationStart() {
                        }

                        @Override
                        public void onMultiFingerManipulationEnd() {
                        }

                        @Override
                        public boolean onMapObjectsSelected(List<ViewObject> list) {
                            return false;
                        }

                        @Override
                        public boolean onTapEvent(PointF pointF) {
                            /* show toast message for onPanEnd gesture callback */
                            showMsg("onTapEvent");
                            /*
                                     * add map screen marker at coordinates of gesture. if map
                                     * screen marker already exists, change to new coordinate
                                     */
                            if (m_tap_marker == null) {
                                m_tap_marker = new MapScreenMarker(pointF, m_marker_image);
                                m_map.addMapObject(m_tap_marker);
                            } else {
                                m_tap_marker.setScreenCoordinate(pointF);
                            }
                            return false;
                        }

                        @Override
                        public boolean onDoubleTapEvent(PointF pointF) {
                            return false;
                        }

                        @Override
                        public void onPinchLocked() {
                        }

                        @Override
                        public boolean onPinchZoomEvent(float v, PointF pointF) {
                            return false;
                        }

                        @Override
                        public void onRotateLocked() {
                        }

                        @Override
                        public boolean onRotateEvent(float v) {
                            /* show toast message for onRotateEvent gesture callback */
                            showMsg("onRotateEvent");
                            return false;
                        }

                        @Override
                        public boolean onTiltEvent(float v) {
                            return false;
                        }

                        @Override
                        public boolean onLongPressEvent(PointF pointF) {
                            return false;
                        }

                        @Override
                        public void onLongPressRelease() {
                        }

                        @Override
                        public boolean onTwoFingerTapEvent(PointF pointF) {
                            return false;
                        }
                    }, 0, false);
                } else {
                    new AlertDialog.Builder(m_activity).setMessage("Error : " + error.name() + "\n\n" + error.getDetails()).setTitle(R.string.engine_init_error).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            m_activity.finish();
                        }
                    }).create().show();
                }
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) PointF(android.graphics.PointF) IOException(java.io.IOException) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) Image(com.here.android.mpa.common.Image) MapScreenMarker(com.here.android.mpa.mapping.MapScreenMarker) List(java.util.List) File(java.io.File)

Aggregations

OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)22 DialogInterface (android.content.DialogInterface)16 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)16 File (java.io.File)14 ApplicationContext (com.here.android.mpa.common.ApplicationContext)5 ApplicationInfo (android.content.pm.ApplicationInfo)4 PackageManager (android.content.pm.PackageManager)4 Bundle (android.os.Bundle)4 PositioningManager (com.here.android.mpa.common.PositioningManager)3 VenueServiceListener (com.here.android.mpa.venues3d.VenueService.VenueServiceListener)2 PointF (android.graphics.PointF)1 RemoteException (android.os.RemoteException)1 View (android.view.View)1 Image (com.here.android.mpa.common.Image)1 LocationDataSource (com.here.android.mpa.common.LocationDataSource)1 MapEngine (com.here.android.mpa.common.MapEngine)1 MapScreenMarker (com.here.android.mpa.mapping.MapScreenMarker)1 OnMapRenderListener (com.here.android.mpa.mapping.OnMapRenderListener)1 PositionIndicator (com.here.android.mpa.mapping.PositionIndicator)1 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)1