-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMapFragmentView.java
More file actions
85 lines (74 loc) · 3.64 KB
/
Copy pathMapFragmentView.java
File metadata and controls
85 lines (74 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.ibm.avatarchatbot;
import com.here.android.mpa.common.GeoCoordinate;
import com.here.android.mpa.common.OnEngineInitListener;
import com.here.android.mpa.mapping.Map;
import com.here.android.mpa.mapping.AndroidXMapFragment;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import java.io.File;
/**
* This class encapsulates the properties and functionality of the Map view.
*/
public class MapFragmentView {
private AndroidXMapFragment m_mapFragment;
private AppCompatActivity m_activity;
private Map m_map;
public MapFragmentView(AppCompatActivity activity) {
m_activity = activity;
initMapFragment();
}
private AndroidXMapFragment getMapFragment() {
return (AndroidXMapFragment) m_activity.getSupportFragmentManager().findFragmentById(R.id.mapfragment);
}
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();
/*
* Map center can be set to a desired location at this point.
* It also can be set to the current location ,which needs to be delivered by the PositioningManager.
* Please refer to the user guide for how to get the real-time location.
*/
m_map.setCenter(new GeoCoordinate(49.258576, -123.008268), Map.Animation.NONE);
} 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();
}
}
});
}
}
}