Search in sources :

Example 1 with ApplicationContext

use of com.here.android.mpa.common.ApplicationContext 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 2 with ApplicationContext

use of com.here.android.mpa.common.ApplicationContext 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 3 with ApplicationContext

use of com.here.android.mpa.common.ApplicationContext 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 4 with ApplicationContext

use of com.here.android.mpa.common.ApplicationContext 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 5 with ApplicationContext

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

the class MainActivity method initSDK.

private void initSDK() {
    ApplicationContext appContext = new ApplicationContext(this);
    MapEngine.getInstance().init(appContext, new OnEngineInitListener() {

        @Override
        public void onEngineInitializationCompleted(Error error) {
            if (error == Error.NONE) {
                startPositioningManager();
                startNavigationManager();
                activateSpeedLimitFragment();
            } else {
                Log.e("MainActivity", " init error: " + error + ", " + error.getDetails(), error.getThrowable());
                new AlertDialog.Builder(MainActivity.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) {
                        MainActivity.this.finish();
                    }
                }).create().show();
            }
        }
    });
}
Also used : ApplicationContext(com.here.android.mpa.common.ApplicationContext) DialogInterface(android.content.DialogInterface) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener)

Aggregations

ApplicationContext (com.here.android.mpa.common.ApplicationContext)5 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)5 DialogInterface (android.content.DialogInterface)3 File (java.io.File)3 RemoteException (android.os.RemoteException)1 LocationDataSource (com.here.android.mpa.common.LocationDataSource)1 MapEngine (com.here.android.mpa.common.MapEngine)1 PositioningManager (com.here.android.mpa.common.PositioningManager)1 RoutingError (com.here.android.mpa.routing.RoutingError)1