93 this(context,
null,
null,
null,
null,
null);
98 this(context, attrs,
null,
null,
null,
null);
112 this(context, attrs, viewConfig,
null,
null,
null);
124 super(context, attrs);
134 locationWindow.removeBuildingListener(buildingListener);
135 locationWindow.removeSublocationChangeListener(sublocationChangeListener);
136 locationWindow.removeCameraListener(cameraListener);
137 super.onDetachedFromWindow();
141 private void setupUI() {
144 public void onActiveSublocationChanged(
int sublocationId) {
145 if (floorSelector !=
null) {
154 this::zoomOutPressed,
156 FrameLayout.LayoutParams zoomLp =
new FrameLayout.LayoutParams(
157 ViewGroup.LayoutParams.WRAP_CONTENT,
158 ViewGroup.LayoutParams.WRAP_CONTENT
160 zoomLp.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
161 addView(zoomControls, zoomLp);
164 this::followMePressed,
165 followMeButtonConfig);
166 FrameLayout.LayoutParams followLp =
new FrameLayout.LayoutParams(
167 ViewGroup.LayoutParams.WRAP_CONTENT,
168 ViewGroup.LayoutParams.WRAP_CONTENT
170 followLp.gravity = Gravity.END | Gravity.BOTTOM;
172 int rightPad = fmConfig.getMarginRight() > 0
173 ? dpToPx(fmConfig.getMarginRight())
174 : dpToPx((int) com.navigine.view.widgets.WidgetStyles.STANDARD_RIGHT_PADDING);
175 int bottomPad = fmConfig.getMarginBottom() > 0
176 ? dpToPx(fmConfig.getMarginBottom())
177 : dpToPx((
int) com.navigine.view.widgets.WidgetStyles.FOLLOW_ME_BOTTOM_PADDING);
178 followLp.setMargins(0, 0, rightPad, bottomPad);
179 addView(followMeButton, followLp);
183 floorSelectorConfig);
185 FrameLayout.LayoutParams lp =
new FrameLayout.LayoutParams(
186 ViewGroup.LayoutParams.WRAP_CONTENT,
187 ViewGroup.LayoutParams.WRAP_CONTENT
189 lp.gravity = Gravity.START | Gravity.TOP;
191 int leftPad = fsConfig.getMarginLeft() > 0
192 ? dpToPx(fsConfig.getMarginLeft())
193 : dpToPx((int) com.navigine.view.widgets.WidgetStyles.STANDARD_LEFT_PADDING);
194 int topPad = fsConfig.getMarginTop() > 0
195 ? dpToPx(fsConfig.getMarginTop())
196 : dpToPx((
int) com.navigine.view.widgets.WidgetStyles.FLOOR_SELECTOR_TOP_PADDING);
197 lp.setMargins(leftPad, topPad, 0, 0);
198 floorSelector.setVisibility(GONE);
200 addView(floorSelector, lp);
202 applyConfigVisibility();
206 public void onActiveBuildingFocused(
Building activeBuilding) {
207 if (floorSelector ==
null || activeBuilding ==
null) {
210 hideFloorSelectorOutsideBuildingFocus =
false;
211 List<FloorSelectorView.LevelInfo> floors =
new ArrayList<>();
213 if (sublocation ==
null) {
216 floors.add(
new FloorSelectorView.LevelInfo(sublocation.getLevelId(), sublocation.getId()));
218 floorSelector.setFloors(floors);
220 applyConfigVisibility();
224 public void onActiveBuildingLeft() {
225 if (floorSelector ==
null) {
228 hideFloorSelectorOutsideBuildingFocus =
true;
229 floorSelector.setFloors(
new ArrayList<>());
230 floorSelector.setVisibility(GONE);
231 applyConfigVisibility();
235 public void onActiveSublocationChanged(
int activeSublocationId) {
238 locationWindow.addBuildingListener(buildingListener);
240 userLocationLayer = NavigineSdk.getInstance().getUserLocationLayer(locationWindow);
241 userLocationLayer.setVisible(
true);
243 cameraListener =
new CameraListener() {
245 public void onCameraPositionChanged(CameraUpdateReason reason,
boolean finished) {
246 if (reason == CameraUpdateReason.APPLICATION) {
250 if (followMeButton !=
null && followMeButton.isFollowing()) {
251 userLocationLayer.resetAnchor();
252 followMeButton.updateAppearanceForFollowingState(
false);
256 locationWindow.addCameraListener(cameraListener);
261 private void zoomInPressed() {
262 float currentZoom = locationWindow.getZoomFactor();
263 locationWindow.setZoomFactor(currentZoom * (3.f / 2.f));
267 private void zoomOutPressed() {
268 float currentZoom = locationWindow.getZoomFactor();
269 locationWindow.setZoomFactor(currentZoom * (2.f / 3.f));
272 private void applyConfigVisibility() {
273 if (zoomControls !=
null) {
274 zoomControls.setVisibility((viewConfig.getVisibleWidgets() & DefaultNavigationViewConfig.WIDGET_ZOOM_CONTROLS) != 0 ? VISIBLE : GONE);
276 if (followMeButton !=
null) {
277 followMeButton.setVisibility((viewConfig.getVisibleWidgets() & DefaultNavigationViewConfig.WIDGET_FOLLOW_ME) != 0 ? VISIBLE : GONE);
279 if (floorSelector !=
null) {
280 boolean floorVisible = (viewConfig.getVisibleWidgets() & DefaultNavigationViewConfig.WIDGET_FLOOR_SELECTOR) != 0
281 && !hideFloorSelectorOutsideBuildingFocus
282 && floorSelector.getFloorsCount() > 1;
283 floorSelector.setVisibility(floorVisible ? VISIBLE : GONE);
287 private int dpToPx(
int dp) {
288 return (
int) (dp * getResources().getDisplayMetrics().density + 0.5f);
295 private void followMePressed(
boolean isFollowing) {
297 float centerX = getWidth() / 2f;
298 float centerY = getHeight() / 2f;
299 PointF anchorPoint =
new PointF(centerX, centerY);
300 userLocationLayer.setAnchor(anchorPoint);
302 userLocationLayer.resetAnchor();
310 if (newViewConfig !=
null) viewConfig = newViewConfig;
311 applyConfigVisibility();
329 if (newViewConfig !=
null) viewConfig = newViewConfig;
330 if (newZoomConfig !=
null) zoomControlsConfig = newZoomConfig;
331 if (newFollowMeConfig !=
null) followMeButtonConfig = newFollowMeConfig;
332 if (newFloorConfig !=
null) floorSelectorConfig = newFloorConfig;
333 applyConfigVisibility();
334 if (zoomControls !=
null) zoomControls.applyConfig(zoomControlsConfig);
335 if (floorSelector !=
null) floorSelector.applyConfig(floorSelectorConfig);
336 if (followMeButton !=
null) followMeButton.applyConfig(followMeButtonConfig);
365 private boolean hideFloorSelectorOutsideBuildingFocus =
true;