Search in sources :

Example 6 with OnEngineInitListener

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

the class BasicPositioningActivity method initializeMapsAndPositioning.

/**
 * Initializes HERE Maps and HERE Positioning. Called after permission check.
 */
private void initializeMapsAndPositioning() {
    setContentView(R.layout.activity_main);
    mLocationInfo = (TextView) findViewById(R.id.textViewLocationInfo);
    mapFragment = getMapFragment();
    mapFragment.setRetainInstance(false);
    mapFragment.init(new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
            if (error == OnEngineInitListener.Error.NONE) {
                map = mapFragment.getMap();
                map.setCenter(new GeoCoordinate(61.497961, 23.763606, 0.0), Map.Animation.NONE);
                map.setZoomLevel(map.getMaxZoomLevel() - 1);
                map.addTransformListener(BasicPositioningActivity.this);
                mPositioningManager = PositioningManager.getInstance();
                mHereLocation = LocationDataSourceHERE.getInstance(new StatusListener() {

                    @Override
                    public void onOfflineModeChanged(boolean offline) {
                    // called when offline mode changes
                    }

                    @Override
                    public void onAirplaneModeEnabled() {
                    // called when airplane mode is enabled
                    }

                    @Override
                    public void onWifiScansDisabled() {
                    // called when Wi-Fi scans are disabled
                    }

                    @Override
                    public void onBluetoothDisabled() {
                    // called when Bluetooth is disabled
                    }

                    @Override
                    public void onCellDisabled() {
                    // called when Cell radios are switch off
                    }

                    @Override
                    public void onGnssLocationDisabled() {
                    // called when GPS positioning is disabled
                    }

                    @Override
                    public void onNetworkLocationDisabled() {
                    // called when network positioning is disabled
                    }

                    @Override
                    public void onServiceError(ServiceError serviceError) {
                    // called on HERE service error
                    }

                    @Override
                    public void onPositioningError(PositioningError positioningError) {
                    // called when positioning fails
                    }

                    @Override
                    @SuppressWarnings("deprecation")
                    public void onWifiIndoorPositioningNotAvailable() {
                    // called when running on Android 9.0 (Pie) or newer
                    }

                    @Override
                    public void onWifiIndoorPositioningDegraded() {
                    // called when running on Android 9.0 (Pie) or newer
                    }
                });
                if (mHereLocation == null) {
                    Toast.makeText(BasicPositioningActivity.this, "LocationDataSourceHERE.getInstance(): failed, exiting", Toast.LENGTH_LONG).show();
                    finish();
                }
                mPositioningManager.setDataSource(mHereLocation);
                mPositioningManager.addListener(new WeakReference<PositioningManager.OnPositionChangedListener>(BasicPositioningActivity.this));
                // start position updates, accepting GPS, network or indoor positions
                if (mPositioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK_INDOOR)) {
                    mapFragment.getPositionIndicator().setVisible(true);
                } else {
                    Toast.makeText(BasicPositioningActivity.this, "PositioningManager.start: failed, exiting", Toast.LENGTH_LONG).show();
                    finish();
                }
            } else {
                new AlertDialog.Builder(BasicPositioningActivity.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) {
                        finish();
                    }
                }).create().show();
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) WeakReference(java.lang.ref.WeakReference) PositioningManager(com.here.android.mpa.common.PositioningManager) StatusListener(com.here.android.positioning.StatusListener)

Example 7 with OnEngineInitListener

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

the class MainView method initMapEngine.

private void initMapEngine() {
    // 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);
    /*
         * Even though we don't display a map view in this application, in order to access any
         * services that HERE Android SDK provides, the MapEngine must be initialized as the
         * prerequisite.
         */
    MapEngine.getInstance().init(new ApplicationContext(m_activity), new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error != Error.NONE) {
                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();
            } else {
                Toast.makeText(m_activity, "Map Engine initialized without error", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : ApplicationContext(com.here.android.mpa.common.ApplicationContext) DialogInterface(android.content.DialogInterface) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) File(java.io.File)

Example 8 with OnEngineInitListener

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

the class MapListView method initMapEngine.

private void initMapEngine() {
    // 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);
    MapEngine.getInstance().init(new ApplicationContext(m_activity), new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error == Error.NONE) {
                /*
                     * Similar to other HERE Android SDK objects, the MapLoader can only be
                     * instantiated after the MapEngine has been initialized successfully.
                     */
                getMapPackages();
            } else {
                Log.e(TAG, "Failed to initialize MapEngine: " + error);
                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 : ApplicationContext(com.here.android.mpa.common.ApplicationContext) DialogInterface(android.content.DialogInterface) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) File(java.io.File)

Example 9 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);
                        m_map.setZoomLevel(13.2);
                        // Show position indicator and accuracy aura
                        m_mapFragment.getPositionIndicator().setVisible(true).setAccuracyIndicatorVisible(true);
                        // Start the positioning manager
                        PositioningManager.getInstance().start(PositioningManager.LocationMethod.GPS_NETWORK);
                        // Create Map NLP object to control voice operations
                        // Pass Activity as a Context!!!
                        m_nlp = Nlp.getInstance();
                        m_myAsr = new MyASR(m_activity.getApplicationContext());
                        m_nlp.init(m_activity, m_mapFragment, null, m_myAsr, m_nlpListener);
                    } 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 10 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);
                        m_map.setZoomLevel(13.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)

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