50 super(context, attrs);
56 locationManager.removeLocationListener(locationListener);
57 locationWindow.removeSublocationChangeListener(sublocationChangeListener);
59 super.onDetachedFromWindow();
63 private void setupUI() {
66 public void onActiveSublocationChanged(
int sublocationId) {
67 floorSelector.setSublocationId(sublocationId);
72 ZoomControls zoomControls =
new ZoomControls(getContext(),
74 this::zoomOutPressed);
75 FrameLayout.LayoutParams zoomLp =
new FrameLayout.LayoutParams(
76 ViewGroup.LayoutParams.WRAP_CONTENT,
77 ViewGroup.LayoutParams.WRAP_CONTENT
79 zoomLp.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
80 addView(zoomControls, zoomLp);
82 followMeButton =
new FollowMeButton(getContext(),
83 this::followMePressed);
84 FrameLayout.LayoutParams followLp =
new FrameLayout.LayoutParams(
85 ViewGroup.LayoutParams.WRAP_CONTENT,
86 ViewGroup.LayoutParams.WRAP_CONTENT
88 followLp.gravity = Gravity.END | Gravity.BOTTOM;
89 followLp.setMargins(0, 0, dpToPx((
int) com.navigine.view.widgets.WidgetStyles.STANDARD_RIGHT_PADDING),
90 dpToPx((
int) com.navigine.view.widgets.WidgetStyles.FOLLOW_ME_BOTTOM_PADDING));
91 addView(followMeButton, followLp);
93 floorSelector =
new FloorSelectorView(getContext(),
96 FrameLayout.LayoutParams lp =
new FrameLayout.LayoutParams(
97 ViewGroup.LayoutParams.WRAP_CONTENT,
98 ViewGroup.LayoutParams.WRAP_CONTENT
100 lp.gravity = Gravity.START | Gravity.TOP;
101 lp.setMargins(dpToPx((
int) com.navigine.view.widgets.WidgetStyles.STANDARD_LEFT_PADDING),
102 dpToPx((
int) com.navigine.view.widgets.WidgetStyles.FLOOR_SELECTOR_TOP_PADDING), 0, 0);
103 floorSelector.setVisibility(GONE);
105 addView(floorSelector, lp);
110 public void onLocationLoaded(
Location location) {
111 if (location !=
null) {
112 floorSelector.setVisibility(VISIBLE);
116 List<FloorSelectorView.LevelInfo> floors =
new ArrayList<>();
117 for(Sublocation sublocation : location.getSublocations()) {
118 floors.add(
new FloorSelectorView.LevelInfo(sublocation.getLevelId(), sublocation.getId()));
121 floorSelector.setFloors(floors);
125 public void onLocationFailed(
int i, Error error) {
129 public void onLocationUploaded(
int locationId) {
133 locationManager.addLocationListener(locationListener);
135 userLocationLayer = NavigineSdk.getInstance().getUserLocationLayer(
locationWindow);
136 userLocationLayer.setVisible(
true);
138 cameraListener =
new CameraListener() {
140 public void onCameraPositionChanged(CameraUpdateReason reason,
boolean finished) {
141 if (reason == CameraUpdateReason.APPLICATION) {
145 if (followMeButton !=
null && followMeButton.isFollowing()) {
146 userLocationLayer.resetAnchor();
147 followMeButton.updateAppearanceForFollowingState(
false);
156 private void zoomInPressed() {
162 private void zoomOutPressed() {
167 private int dpToPx(
int dp) {
168 return (
int) (dp * getResources().getDisplayMetrics().density + 0.5f);
175 private void followMePressed(
boolean isFollowing) {
177 float centerX = getWidth() / 2f;
178 float centerY = getHeight() / 2f;
179 PointF anchorPoint =
new PointF(centerX, centerY);
180 userLocationLayer.setAnchor(anchorPoint);
182 userLocationLayer.resetAnchor();
186 private FloorSelectorView floorSelector;
187 private LocationManager locationManager;
188 private LocationListener locationListener;
189 private SublocationChangeListener sublocationChangeListener;
190 private UserLocationLayer userLocationLayer;
191 private CameraListener cameraListener;
192 private FollowMeButton followMeButton;