72 private boolean cameraListenerRegistered;
84 this(context,
null,
null,
null,
null,
null);
89 this(context, attrs,
null,
null,
null,
null);
103 this(context, attrs, viewConfig,
null,
null,
null);
115 super(context, attrs,
120 installFollowMeAndUserLocation();
124 private void installFollowMeAndUserLocation() {
126 this::followMePressed,
127 followMeButtonConfig);
128 FrameLayout.LayoutParams followLp =
new FrameLayout.LayoutParams(
129 ViewGroup.LayoutParams.WRAP_CONTENT,
130 ViewGroup.LayoutParams.WRAP_CONTENT
132 followLp.gravity = Gravity.END | Gravity.BOTTOM;
133 addView(followMeButton, followLp);
148 if (followMeButton !=
null && followMeButton.
isFollowing()) {
154 registerCameraListener();
157 private void registerCameraListener() {
158 if (cameraListenerRegistered || locationWindow ==
null || cameraListener ==
null) {
161 locationWindow.addCameraListener(cameraListener);
162 cameraListenerRegistered =
true;
165 private void unregisterCameraListener() {
166 if (!cameraListenerRegistered || locationWindow ==
null || cameraListener ==
null) {
169 locationWindow.removeCameraListener(cameraListener);
170 cameraListenerRegistered =
false;
175 super.applyConfigVisibility();
176 if (followMeButton !=
null) {
177 followMeButton.setVisibility(
185 super.applyWidgetLayoutParams();
186 if (followMeButton !=
null) {
187 FrameLayout.LayoutParams followLp = (FrameLayout.LayoutParams) followMeButton.getLayoutParams();
188 if (followLp ==
null) {
189 followLp =
new FrameLayout.LayoutParams(
190 ViewGroup.LayoutParams.WRAP_CONTENT,
191 ViewGroup.LayoutParams.WRAP_CONTENT);
193 followLp.gravity = Gravity.END | Gravity.BOTTOM;
197 : dpToPx((
int) com.navigine.view.widgets.WidgetStyles.STANDARD_RIGHT_PADDING);
200 : dpToPx((
int) com.navigine.view.widgets.WidgetStyles.FOLLOW_ME_BOTTOM_PADDING);
201 followLp.setMargins(0, 0, rightPad, bottomPad);
202 followMeButton.setLayoutParams(followLp);
210 private void followMePressed(
boolean isFollowing) {
213 final float density = getResources().getDisplayMetrics().density;
214 float centerX = getWidth() * density / 2f;
215 float centerY = getHeight() * density / 2f;
216 PointF anchorPoint =
new PointF(centerX, centerY);
217 userLocationLayer.
setAnchor(anchorPoint);
227 super.setViewConfig(newViewConfig);
245 if (newFollowMeConfig !=
null) followMeButtonConfig = newFollowMeConfig;
246 super.setConfig(newViewConfig, newZoomConfig, newFloorConfig);
247 if (followMeButton !=
null) followMeButton.applyConfig(followMeButtonConfig);
265 super.onAttachedToWindow();
266 registerCameraListener();
271 unregisterCameraListener();
272 super.onDetachedFromWindow();