Search in sources :

Example 1 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 = (MapFragment) m_activity.getFragmentManager().findFragmentById(R.id.mapfragment);
    // Set path of isolated disk cache
    String diskCacheRoot = Environment.getExternalStorageDirectory().getPath() + File.separator + ".isolated-here-maps";
    // Retrieve intent name from manifest
    String intentName = "";
    try {
        ApplicationInfo ai = m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        intentName = bundle.getString("INTENT_NAME");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(this.getClass().toString(), "Failed to find intent name, NameNotFound: " + e.getMessage());
    }
    boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(diskCacheRoot, intentName);
    if (!success) {
    // Setting the isolated disk cache was not successful, please check if the path is valid and
    // ensure that it does not match the default location
    // (getExternalStorageDirectory()/.here-maps).
    // Also, ensure the provided intent name does not match the default intent name.
    } else {
        if (m_mapFragment != null) {
            /* Initialize the MapFragment, results will be given via the called back. */
            m_mapFragment.init(new OnEngineInitListener() {

                @Override
                public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                    if (error == Error.NONE) {
                        m_map = m_mapFragment.getMap();
                        m_map.setCenter(new GeoCoordinate(49.259149, -123.008555), Map.Animation.NONE);
                        // Put this call in Map.onTransformListener if the animation(Linear/Bow)
                        // is used in setCenter()
                        m_map.setZoomLevel(13.2);
                        /*
                         * Get the NavigationManager instance.It is responsible for providing voice
                         * and visual instructions while driving and walking
                         */
                        m_navigationManager = NavigationManager.getInstance();
                    } else {
                        Toast.makeText(m_activity, "ERROR: Cannot initialize Map with error " + error, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

Example 2 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 = (MapFragment) m_activity.getFragmentManager().findFragmentById(R.id.mapfragment);
    // Set path of isolated disk cache
    String diskCacheRoot = Environment.getExternalStorageDirectory().getPath() + File.separator + ".isolated-here-maps";
    // Retrieve intent name from manifest
    String intentName = "";
    try {
        ApplicationInfo ai = m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        intentName = bundle.getString("INTENT_NAME");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(this.getClass().toString(), "Failed to find intent name, NameNotFound: " + e.getMessage());
    }
    boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath(diskCacheRoot, intentName);
    if (!success) {
    // Setting the isolated disk cache was not successful, please check if the path is valid and
    // ensure that it does not match the default location
    // (getExternalStorageDirectory()/.here-maps).
    // Also, ensure the provided intent name does not match the default intent name.
    } else {
        if (m_mapFragment != null) {
            /* Initialize the MapFragment, results will be given via the called back. */
            m_mapFragment.init(new OnEngineInitListener() {

                @Override
                public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                    if (error == Error.NONE) {
                        /* get the map object */
                        m_map = m_mapFragment.getMap();
                        /*
                         * Set the map center to the 4350 Still Creek Dr Burnaby BC (no animation).
                         */
                        m_map.setCenter(new GeoCoordinate(49.259149, -123.008555, 0.0), Map.Animation.NONE);
                        /* Set the zoom level to the average between min and max zoom level. */
                        m_map.setZoomLevel((m_map.getMaxZoomLevel() + m_map.getMinZoomLevel()) / 2);
                    } else {
                        Toast.makeText(m_activity, "ERROR: Cannot initialize Map with error " + error, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

Example 3 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() {
    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) {
        ApplicationContext applicationContext = new ApplicationContext(m_activity);
        applicationContext.setDiskCacheSize(CACHE_SIZE);
        /* Initialize the AndroidXMapFragment, results will be given via the called back. */
        m_mapFragment.init(applicationContext, new OnEngineInitListener() {

            @Override
            public void onEngineInitializationCompleted(Error error) {
                if (error == OnEngineInitListener.Error.NONE) {
                    m_map = m_mapFragment.getMap();
                    if (m_progressBar.getVisibility() == View.VISIBLE) {
                        boolean b = true;
                    }
                    setOptionType(OptionType.MAP_BOUNDING_BOX);
                } else {
                    Toast.makeText(m_activity, m_activity.getText(R.string.error_occurred) + error.toString(), Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
Also used : ApplicationContext(com.here.android.mpa.common.ApplicationContext) RoutingError(com.here.android.mpa.routing.RoutingError) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) File(java.io.File)

Example 4 with OnEngineInitListener

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

the class PositioningService method initMapEngine.

/**
 * Initialize HERE SDK map engine.
 */
private void initMapEngine() {
    if (MapEngine.isInitialized()) {
        return;
    }
    final MapEngine engine = MapEngine.getInstance();
    engine.init(new ApplicationContext(getApplicationContext()), new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error == OnEngineInitListener.Error.NONE) {
                mNotificationUtils.updateNotification(R.drawable.ic_paused, R.string.notificationTitle, R.string.notificationMapEngineReady);
                if (mListener != null) {
                    try {
                        mListener.onEngineIntialized();
                    } catch (RemoteException ex) {
                    // ignored
                    }
                }
                final PositioningManager posManager = PositioningManager.getInstance();
                final LocationDataSource hereLocation = LocationDataSourceHERE.getInstance();
                if (hereLocation == null) {
                    Log.e(TAG, "initMapEngine: failed to instantiate HERE location");
                    return;
                }
                posManager.setDataSource(hereLocation);
            } else {
                Log.e(TAG, "initMapEngine: MapEngine.init failed: " + error.getDetails());
            }
        }
    });
}
Also used : MapEngine(com.here.android.mpa.common.MapEngine) ApplicationContext(com.here.android.mpa.common.ApplicationContext) PositioningManager(com.here.android.mpa.common.PositioningManager) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) RemoteException(android.os.RemoteException) LocationDataSource(com.here.android.mpa.common.LocationDataSource)

Example 5 with OnEngineInitListener

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

the class BasicVenueActivity method startVenueMaps.

/**
 * Initializes HERE Venue Maps. Called after permission check.
 */
private void startVenueMaps() {
    Log.v(TAG, "InitializeVenueMaps");
    mActivity = this;
    mVenueMapFragment = getMapFragment();
    mLocationInfo = (TextView) findViewById(R.id.textViewLocationInfo);
    mVenueMapFragment.init(new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error == Error.NONE) {
                Log.v(TAG, "InitializeVenueMaps: OnEngineInitializationCompleted");
                mVenueService = mVenueMapFragment.getVenueService();
                mRoutingController = mVenueMapFragment.getRoutingController();
                if (mRoutingController != null) {
                    mRoutingController.addListener(BasicVenueActivity.this);
                }
                // Setting venue service content based on menu option
                if (!mPrivateVenues) {
                    // Public only
                    setVenueServiceContent(false, false);
                } else {
                    // Private + public
                    setVenueServiceContent(true, true);
                }
            } else {
                new AlertDialog.Builder(BasicVenueActivity.this).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) {
                        BasicVenueActivity.this.finish();
                    }
                }).create().show();
            }
        }
    }, new VenueServiceListener() {

        @Override
        public void onInitializationCompleted(VenueService.InitStatus result) {
            Log.v(TAG, "VenueServiceListener: OnInitializationCompleted with result: %s", result);
            switch(result) {
                case IN_PROGRESS:
                    Log.v(TAG, "Initialization of venue service is in progress...");
                    Toast.makeText(BasicVenueActivity.this, "Initialization of venue service is in progress...", Toast.LENGTH_SHORT).show();
                    break;
                case OFFLINE_SUCCESS:
                case ONLINE_SUCCESS:
                    // Adding venue listener to map fragment
                    mVenueMapFragment.addListener(mActivity);
                    // Set animations on for floor change and venue entering
                    mVenueMapFragment.setFloorChangingAnimation(true);
                    mVenueMapFragment.setVenueEnteringAnimation(true);
                    // Ask notification when venue visible; this notification is
                    // part of VenueMapFragment.VenueListener
                    mVenueMapFragment.setVenuesInViewportCallback(true);
                    // Add Gesture Listener for map fragment
                    mVenueMapFragment.getMapGesture().addOnGestureListener(mActivity, 0, false);
                    // retrieve a reference of the map from the map fragment
                    mMap = mVenueMapFragment.getMap();
                    mMap.addTransformListener(mActivity);
                    mMap.setZoomLevel(mMap.getMaxZoomLevel() - 3);
                    // Create floors controller widget
                    mFloorsControllerWidget = new FloorsControllerWidget(mActivity, mVenueMapFragment, (ListView) findViewById(R.id.floorListView), R.layout.floor_item, R.id.floorName, R.id.floorGroundSep);
                    // Start of Position Updates
                    try {
                        startPositionUpdates();
                        mVenueMapFragment.getPositionIndicator().setVisible(true);
                    } catch (Exception ex) {
                        Log.w(TAG, "startPositionUpdates: Could not register for location updates: %s", Log.getStackTraceString(ex));
                    }
                    if (mLastMapCenter == null) {
                        mMap.setCenter(new GeoCoordinate(61.497961, 23.763606, 0.0), Map.Animation.NONE);
                    } else {
                        mMap.setCenter(mLastMapCenter, Map.Animation.NONE);
                    }
                    break;
            }
        }
    });
}
Also used : VenueServiceListener(com.here.android.mpa.venues3d.VenueService.VenueServiceListener) DialogInterface(android.content.DialogInterface) VenueService(com.here.android.mpa.venues3d.VenueService) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

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